Skip to contentSkip to conversation

support/testing: add FLAT stack size test case

PATCH Applied Fengwei Tan 2 participants 3 messages Sep 12 – Sep 25

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 support/testing: add FLAT stack size test case

Add an infrastructure test case to verify that the per-package <PKG>_FLAT_STACKSIZE variable correctly configures the stack size in the generated FLAT binary header.

---
As we discussed in [1], this patch adds a simple test case to verify that $(PKG)_FLAT_STACKSIZE works as expected.

I have also pushed this patch to GitLab CI, and the test job passed successfully [2].

[1] https://lore.kernel.org/buildroot/SY8P300MB0041233A165784A8729859B2F8A32@SY8P300MB0041.AUSP300.PROD.OUTLOOK.COM/
[2] https://gitlab.com/tfx2001/buildroot/-/jobs/16053520032

Changes in v2:
- No code changes. Settled on the FLAT header inspection approach as a
lightweight solution, since no feedback was received on the RFC version
- Link to RFC: https://lore.kernel.org/buildroot/SY8P300MB0041166E9B5D56A3796BD3D6F8A12@SY8P300MB0041.AUSP300.PROD.OUTLOOK.COM/

---
 DEVELOPERS                                         |  3 +++
 .../core/br2-external/flat-stacksize/Config.in     |  1 +
 .../core/br2-external/flat-stacksize/external.desc |  1 +
 .../core/br2-external/flat-stacksize/external.mk   |  1 +
 .../package/flat-stacksize-test/Config.in          |  7 ++++++
 .../package/flat-stacksize-test/Makefile           | 15 ++++++++++++
 .../flat-stacksize-test/flat-stacksize-test.mk     | 22 ++++++++++++++++++
 .../package/flat-stacksize-test/main.c             |  3 +++
 support/testing/tests/core/test_flat_stacksize.py  | 27 ++++++++++++++++++++++
 9 files changed, 80 insertions(+)
DEVELOPERS +3 -0
index 97eb2d9cac..ed59f11309 100644
@@ -1124,6 +1124,9 @@ F:	configs/freescale_imx6ullevk_defconfig
 N:	Falco Hyfing <[email protected]>
 F:	package/python-pymodbus/
 
+N:	Fengwei Tan <[email protected]>
+F:	support/testing/tests/core/test_flat_stacksize.py
+
 N:	Fiona Klute <[email protected]>
 F:	package/*/S*
 F:	package/panel-mipi-dbi-firmware/
support/testing/tests/core/br2-external/flat-stacksize/Config.in new file +1 -0
new file mode 100644
index 0000000000..cdb4e9f057
@@ -0,0 +1 @@
+source "$BR2_EXTERNAL_FLAT_STACKSIZE_PATH/package/flat-stacksize-test/Config.in"
support/testing/tests/core/br2-external/flat-stacksize/external.desc new file +1 -0
new file mode 100644
index 0000000000..f9c1a745e0
@@ -0,0 +1 @@
+name: FLAT_STACKSIZE
support/testing/tests/core/br2-external/flat-stacksize/external.mk new file +1 -0
new file mode 100644
index 0000000000..82900bf036
@@ -0,0 +1 @@
+include $(sort $(wildcard $(BR2_EXTERNAL_FLAT_STACKSIZE_PATH)/package/*/*.mk))
support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Config.in new file +7 -0
new file mode 100644
index 0000000000..67cf9964f5
@@ -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.
support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Makefile new file +15 -0
new file mode 100644
index 0000000000..dc7681bf56
@@ -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
support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/flat-stacksize-test.mk new file +22 -0
new file mode 100644
index 0000000000..64695ad2dc
@@ -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))
support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/main.c new file +3 -0
new file mode 100644
index 0000000000..9b6bdc2ec2
@@ -0,0 +1,3 @@
+int main(void) {
+    return 0;
+}
support/testing/tests/core/test_flat_stacksize.py new file +27 -0
new file mode 100644
index 0000000000..ab41fadbc8
@@ -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)

---
base-commit: 9a1c11c9971b454b3b38c4eb111ac5e42a15cf1c
change-id: 20260912-flat-stacksize-test-793fe88e43bb

Best regards,

Signature · 6 lines
Fengwei Tan <[email protected]>

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 5 lines · Fengwei Tan

Add an infrastructure test case to verify that the per-package <PKG>_FLAT_STACKSIZE variable correctly configures the stack size in the generated FLAT binary header.

Applied to master, thanks!

Best regards,

Thomas Petazzoni

Signature · 7 lines
Thomas Petazzoni, co-owner and CEO, Bootlin
Embedded Linux and Kernel engineering and training
https://bootlin.com
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
In reply to Fengwei Tan

In reply of:

Quoted 5 lines

Add an infrastructure test case to verify that the per-package <PKG>_FLAT_STACKSIZE variable correctly configures the stack size in the generated FLAT binary header.

Applied to 2025.02.x, 2026.08.x. Thanks

Quoted 164 lines

---
As we discussed in [1], this patch adds a simple test case to verify that $(PKG)_FLAT_STACKSIZE works as expected.

I have also pushed this patch to GitLab CI, and the test job passed successfully [2].

[1] https://lore.kernel.org/buildroot/SY8P300MB0041233A165784A8729859B2F8A32@SY8P300MB0041.AUSP300.PROD.OUTLOOK.COM/
[2] https://gitlab.com/tfx2001/buildroot/-/jobs/16053520032

Changes in v2:
- No code changes. Settled on the FLAT header inspection approach as a
lightweight solution, since no feedback was received on the RFC version
- Link to RFC: https://lore.kernel.org/buildroot/SY8P300MB0041166E9B5D56A3796BD3D6F8A12@SY8P300MB0041.AUSP300.PROD.OUTLOOK.COM/

---
 DEVELOPERS                                         |  3 +++
 .../core/br2-external/flat-stacksize/Config.in     |  1 +
 .../core/br2-external/flat-stacksize/external.desc |  1 +
 .../core/br2-external/flat-stacksize/external.mk   |  1 +
 .../package/flat-stacksize-test/Config.in          |  7 ++++++
 .../package/flat-stacksize-test/Makefile           | 15 ++++++++++++
 .../flat-stacksize-test/flat-stacksize-test.mk     | 22 ++++++++++++++++++
 .../package/flat-stacksize-test/main.c             |  3 +++
 support/testing/tests/core/test_flat_stacksize.py  | 27 ++++++++++++++++++++++
 9 files changed, 80 insertions(+)

---
base-commit: 9a1c11c9971b454b3b38c4eb111ac5e42a15cf1c
change-id: 20260912-flat-stacksize-test-793fe88e43bb

Best regards,

Signature · 1 line
Fengwei Tan <[email protected]>
DEVELOPERS +3 -0
index 97eb2d9cac..ed59f11309 100644
@@ -1124,6 +1124,9 @@ F:	configs/freescale_imx6ullevk_defconfig
 N:	Falco Hyfing <[email protected]>
 F:	package/python-pymodbus/
 
+N:	Fengwei Tan <[email protected]>
+F:	support/testing/tests/core/test_flat_stacksize.py
+
 N:	Fiona Klute <[email protected]>
 F:	package/*/S*
 F:	package/panel-mipi-dbi-firmware/
support/testing/tests/core/br2-external/flat-stacksize/Config.in new file +1 -0
new file mode 100644
index 0000000000..cdb4e9f057
@@ -0,0 +1 @@
+source "$BR2_EXTERNAL_FLAT_STACKSIZE_PATH/package/flat-stacksize-test/Config.in"
support/testing/tests/core/br2-external/flat-stacksize/external.desc new file +1 -0
new file mode 100644
index 0000000000..f9c1a745e0
@@ -0,0 +1 @@
+name: FLAT_STACKSIZE
support/testing/tests/core/br2-external/flat-stacksize/external.mk new file +1 -0
new file mode 100644
index 0000000000..82900bf036
@@ -0,0 +1 @@
+include $(sort $(wildcard $(BR2_EXTERNAL_FLAT_STACKSIZE_PATH)/package/*/*.mk))
support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Config.in new file +7 -0
new file mode 100644
index 0000000000..67cf9964f5
@@ -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.
support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/Makefile new file +15 -0
new file mode 100644
index 0000000000..dc7681bf56
@@ -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
support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/flat-stacksize-test.mk new file +22 -0
new file mode 100644
index 0000000000..64695ad2dc
@@ -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))
support/testing/tests/core/br2-external/flat-stacksize/package/flat-stacksize-test/main.c new file +3 -0
new file mode 100644
index 0000000000..9b6bdc2ec2
@@ -0,0 +1,3 @@
+int main(void) {
+    return 0;
+}
support/testing/tests/core/test_flat_stacksize.py new file +17 -0
new file mode 100644
index 0000000000..ab41fadbc8
@@ -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
+        """
+

support/testing/tests/core/test_flat_stacksize.py line 27

Quoted 10 lines
support/testing/tests/core/test_flat_stacksize.py new file +10 -0
+    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)

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot