From 5d1a9b07c0f293fb78f626df5ca5022db7c7df04 Mon Sep 17 00:00:00 2001 From: Fengwei Tan Date: Sat, 12 Sep 2026 17:24:12 +0800 Subject: [PATCH] support/testing: add FLAT stack size test case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an infrastructure test case to verify that the per-package _FLAT_STACKSIZE variable correctly configures the stack size in the generated FLAT binary header. Signed-off-by: Fengwei Tan Signed-off-by: Thomas Petazzoni (cherry picked from commit 0bf452504516ab28233226ab531eaa2194d98558) Signed-off-by: Raphaël Mélotte --- DEVELOPERS | 3 +++ .../br2-external/flat-stacksize/Config.in | 1 + .../br2-external/flat-stacksize/external.desc | 1 + .../br2-external/flat-stacksize/external.mk | 1 + .../package/flat-stacksize-test/Config.in | 7 +++++ .../package/flat-stacksize-test/Makefile | 15 +++++++++++ .../flat-stacksize-test.mk | 22 +++++++++++++++ .../package/flat-stacksize-test/main.c | 3 +++ .../testing/tests/core/test_flat_stacksize.py | 27 +++++++++++++++++++ 9 files changed, 80 insertions(+) create mode 100644 support/testing/tests/core/br2-external/flat-stacksize/Config.in create mode 100644 support/testing/tests/core/br2-external/flat-stacksize/external.desc create mode 100644 support/testing/tests/core/br2-external/flat-stacksize/external.mk create mode 100644 support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Config.in create mode 100644 support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Makefile create mode 100644 support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/flat-stacksize-test.mk create mode 100644 support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/main.c create mode 100644 support/testing/tests/core/test_flat_stacksize.py diff --git a/DEVELOPERS b/DEVELOPERS index 727ebe7007..a408fd7bb6 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1074,6 +1074,9 @@ F: configs/freescale_imx6ullevk_defconfig N: Falco Hyfing F: package/python-pymodbus/ +N: Fengwei Tan +F: support/testing/tests/core/test_flat_stacksize.py + N: Fiona Klute F: package/*/S* F: package/panel-mipi-dbi-firmware/ diff --git a/support/testing/tests/core/br2-external/flat-stacksize/Config.in b/support/testing/tests/core/br2-external/flat-stacksize/Config.in new file mode 100644 index 0000000000..cdb4e9f057 --- /dev/null +++ b/support/testing/tests/core/br2-external/flat-stacksize/Config.in @@ -0,0 +1 @@ +source "$BR2_EXTERNAL_FLAT_STACKSIZE_PATH/package/flat-stacksize-test/Config.in" diff --git a/support/testing/tests/core/br2-external/flat-stacksize/external.desc b/support/testing/tests/core/br2-external/flat-stacksize/external.desc new file mode 100644 index 0000000000..f9c1a745e0 --- /dev/null +++ b/support/testing/tests/core/br2-external/flat-stacksize/external.desc @@ -0,0 +1 @@ +name: FLAT_STACKSIZE diff --git a/support/testing/tests/core/br2-external/flat-stacksize/external.mk b/support/testing/tests/core/br2-external/flat-stacksize/external.mk new file mode 100644 index 0000000000..82900bf036 --- /dev/null +++ b/support/testing/tests/core/br2-external/flat-stacksize/external.mk @@ -0,0 +1 @@ +include $(sort $(wildcard $(BR2_EXTERNAL_FLAT_STACKSIZE_PATH)/package/*/*.mk)) diff --git a/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Config.in b/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Config.in new file mode 100644 index 0000000000..67cf9964f5 --- /dev/null +++ b/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Config.in @@ -0,0 +1,7 @@ +config BR2_PACKAGE_FLAT_STACKSIZE_TEST + bool "flat-stacksize-test" + depends on BR2_BINFMT_FLAT && !BR2_USE_MMU + help + Package for testing the $(PKG)_FLAT_STACKSIZE variable, which + defines the stack size of an application built into the + FLAT binary format. diff --git a/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Makefile b/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Makefile new file mode 100644 index 0000000000..dc7681bf56 --- /dev/null +++ b/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Makefile @@ -0,0 +1,15 @@ +O ?= $(CURDIR) + +CANONICAL_O := $(shell mkdir -p $(O) >/dev/null 2>&1)$(realpath $(O)) + +TARGET := $(CANONICAL_O)/flat_stacksize_test + +all: $(TARGET) + +$(TARGET): main.c + $(CC) $(CFLAGS) -o $@ main.c + +clean: + rm -f $(TARGET) + +.PHONY: all clean diff --git a/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/flat-stacksize-test.mk b/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/flat-stacksize-test.mk new file mode 100644 index 0000000000..64695ad2dc --- /dev/null +++ b/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/flat-stacksize-test.mk @@ -0,0 +1,22 @@ +################################################################################ +# +# flat-stacksize-test +# +################################################################################ + +# Define a stack size that is different from the default FLAT +# stack size (4096 bytes). +FLAT_STACKSIZE_TEST_FLAT_STACKSIZE = 8192 + +define FLAT_STACKSIZE_TEST_BUILD_CMDS + $(TARGET_MAKE_ENV) $(MAKE) \ + -C $(FLAT_STACKSIZE_TEST_PKGDIR) O=$(@D) \ + $(TARGET_CONFIGURE_OPTS) +endef + +define FLAT_STACKSIZE_TEST_INSTALL_TARGET_CMDS + $(INSTALL) -D -m 0755 $(@D)/flat_stacksize_test \ + $(TARGET_DIR)/usr/bin/flat_stacksize_test +endef + +$(eval $(generic-package)) diff --git a/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/main.c b/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/main.c new file mode 100644 index 0000000000..9b6bdc2ec2 --- /dev/null +++ b/support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/main.c @@ -0,0 +1,3 @@ +int main(void) { + return 0; +} diff --git a/support/testing/tests/core/test_flat_stacksize.py b/support/testing/tests/core/test_flat_stacksize.py new file mode 100644 index 0000000000..ab41fadbc8 --- /dev/null +++ b/support/testing/tests/core/test_flat_stacksize.py @@ -0,0 +1,27 @@ +import os + +import infra.basetest + + +class TestFlatStackSize(infra.basetest.BRTest): + br2_external = [infra.filepath("tests/core/br2-external/flat-stacksize")] + config = """ + BR2_arm=y + BR2_cortex_m4=y + BR2_TOOLCHAIN_EXTERNAL=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y + BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV7M_UCLIBC_STABLE=y + # BR2_TARGET_ROOTFS_TAR is not set + BR2_PACKAGE_FLAT_STACKSIZE_TEST=y + """ + + def test_run(self): + binary = os.path.join( + self.builddir, "target", "usr", "bin", "flat_stacksize_test" + ) + self.assertTrue(os.path.exists(binary)) + + # Check the FLAT binary header really carries the stack size + # declared by the package (8192 = 0x2000). + out = infra.run_cmd_on_host(self.builddir, ["arm-linux-flthdr", binary]) + self.assertIn("Stack Size: 0x2000\n", out)