diff mbox series

[1/1] support/testing: add make runtime test

Message ID 20240220220720.166829-1-ju.o@free.fr
State New
Headers show
Series [1/1] support/testing: add make runtime test | expand

Commit Message

Julien Olivain Feb. 20, 2024, 10:07 p.m. UTC
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
 DEVELOPERS                                    |  2 +
 support/testing/tests/package/test_make.py    | 82 +++++++++++++++++++
 .../test_make/rootfs-overlay/root/Makefile    | 23 ++++++
 3 files changed, 107 insertions(+)
 create mode 100644 support/testing/tests/package/test_make.py
 create mode 100644 support/testing/tests/package/test_make/rootfs-overlay/root/Makefile
diff mbox series

Patch

diff --git a/DEVELOPERS b/DEVELOPERS
index f0e16af1623..6c8d07d4761 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1815,6 +1815,8 @@  F:	support/testing/tests/package/test_lzip.py
 F:	support/testing/tests/package/test_lsof.py
 F:	support/testing/tests/package/test_lz4.py
 F:	support/testing/tests/package/test_lzop.py
+F:	support/testing/tests/package/test_make.py
+F:	support/testing/tests/package/test_make/
 F:	support/testing/tests/package/test_mdadm.py
 F:	support/testing/tests/package/test_mdadm/
 F:	support/testing/tests/package/test_micropython.py
diff --git a/support/testing/tests/package/test_make.py b/support/testing/tests/package/test_make.py
new file mode 100644
index 00000000000..d549cca37d8
--- /dev/null
+++ b/support/testing/tests/package/test_make.py
@@ -0,0 +1,82 @@ 
+import os
+
+import infra.basetest
+
+
+class TestMake(infra.basetest.BRTest):
+    rootfs_overlay = \
+        infra.filepath("tests/package/test_make/rootfs-overlay")
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        f"""
+        BR2_PACKAGE_MAKE=y
+        BR2_ROOTFS_OVERLAY="{rootfs_overlay}"
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def gen_expected_str(self, count):
+        """Return the expected string generated by the test Makefile"""
+        return "".join(map(lambda x: str(x), range(1,count+1)))
+
+    def test_run(self):
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv5",
+                           kernel="builtin",
+                           options=["-initrd", cpio_file])
+        self.emulator.login()
+
+        # Check the program can execute.
+        self.assertRunOk("make --version")
+
+        # We touch the Makefile to set its modification time to the
+        # current system time. This is to avoid warnings from Make
+        # about having files with timestamps in the future. This is
+        # because the minimal system running in the emulator might not
+        # set the clock to the real time, and the Makefile has a
+        # correct timestamp from the build host (which is likely at
+        # the correct time).
+        self.assertRunOk("touch Makefile")
+
+        # We test the "message" target and check we get the expected
+        # string.
+        out, ret = self.emulator.run("make message")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], "Hello Buildroot!")
+
+        # We redo the same test, this time by passing a new message
+        # with a variable.
+        msg = "This is Another Message..."
+        out, ret = self.emulator.run(f"make message MESSAGE='{msg}'")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], msg)
+
+        # We run a simple "make" invocation, using the defaults.
+        self.assertRunOk("make")
+
+        # We check the generated output contains the expected string.
+        expected_str = self.gen_expected_str(10)
+        out, ret = self.emulator.run("cat output.txt")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], expected_str)
+
+        # Clean the previous invocation.
+        self.assertRunOk("make clean")
+
+        # We check a output generated file is no longer present.
+        self.assertRunOk("test ! -e output.txt")
+
+        # We run an invocation with a larger COUNT value. GNU Make
+        # version 4.4 introduced the --shuffle option, which shuffle
+        # rules. We use it with a constant seed, in order to have a
+        # stable reshuffling in all test runs. We also include in this
+        # execution a request for parallel jobs.
+        count = 50
+        seed = 123456
+        self.assertRunOk(f"make -j10 --shuffle={seed} COUNT={count}")
+
+        # Despite the pseudo-randomization in the previous invocation,
+        # the expected output should be correctly ordered.
+        expected_str = self.gen_expected_str(count)
+        out, ret = self.emulator.run("cat output.txt")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], expected_str)
diff --git a/support/testing/tests/package/test_make/rootfs-overlay/root/Makefile b/support/testing/tests/package/test_make/rootfs-overlay/root/Makefile
new file mode 100644
index 00000000000..7ac86945a5e
--- /dev/null
+++ b/support/testing/tests/package/test_make/rootfs-overlay/root/Makefile
@@ -0,0 +1,23 @@ 
+MESSAGE ?= "Hello Buildroot!"
+COUNT ?= 10
+
+LIST = $(shell seq $(COUNT))
+INPUTS = $(addsuffix .in.txt,$(LIST))
+OUTPUT = output.txt
+
+.PHONY: all
+all: $(OUTPUT)
+
+.PHONY: clean
+clean:
+	$(RM) $(OUTPUT) *.in.txt
+
+.PHONY: message
+message:
+	@echo $(MESSAGE)
+
+%.in.txt:
+	echo $(subst .in.txt,,$@) > $@
+
+$(OUTPUT): $(INPUTS)
+	(cat $? | tr -d '\n' ; echo) > $@