[Buildroot] [PATCH v5 3/3] support/testing/tests/package/test_nu.py: New runtime test

Sebastian Weyer sebastian.weyer at smile.fr
Wed Mar 8 08:53:53 UTC 2023


Load sample script support/testing/tests/package/sample_nu.nu onto the
target and verify proper execution by nushell

Signed-off-by: Sebastian Weyer <sebastian.weyer at smile.fr>
---
 DEVELOPERS                                 |  2 +
 support/testing/tests/package/sample_nu.nu |  6 ++
 support/testing/tests/package/test_nu.py   | 65 ++++++++++++++++++++++
 3 files changed, 73 insertions(+)
 create mode 100644 support/testing/tests/package/sample_nu.nu
 create mode 100644 support/testing/tests/package/test_nu.py

diff --git a/DEVELOPERS b/DEVELOPERS
index 4577f20b22..726cd73af7 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -2552,6 +2552,8 @@ F:	package/ripgrep/
 
 N:  Sebastian Weyer <sebastian.weyer at smile.fr>
 F:	package/nushell/
+F:	support/testing/tests/package/test_nu.py
+F:	support/testing/tests/package/sample_nu.nu
 
 N:	Sébastien Szymanski <sebastien.szymanski at armadeus.com>
 F:	package/mmc-utils/
diff --git a/support/testing/tests/package/sample_nu.nu b/support/testing/tests/package/sample_nu.nu
new file mode 100644
index 0000000000..8904b29933
--- /dev/null
+++ b/support/testing/tests/package/sample_nu.nu
@@ -0,0 +1,6 @@
+# myscript.nu
+def greet [name] {
+  ["hello" $name]
+}
+
+greet "world"
diff --git a/support/testing/tests/package/test_nu.py b/support/testing/tests/package/test_nu.py
new file mode 100644
index 0000000000..b7ca52038d
--- /dev/null
+++ b/support/testing/tests/package/test_nu.py
@@ -0,0 +1,65 @@
+import os
+
+import infra.basetest
+
+class TestNuBase(infra.basetest.BRTest):
+    # infra.basetest.BASIC_TOOLCHAIN_CONFIG cannot be used as it doesn't
+    # support a host rustc which is necessary for nushell
+    config = \
+        """
+        BR2_arm=y
+        BR2_cortex_a9=y
+        BR2_ARM_ENABLE_NEON=y
+        BR2_ARM_ENABLE_VFP=y
+        BR2_TOOLCHAIN_EXTERNAL=y
+        BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
+        BR2_SYSTEM_DHCP="eth0"
+        BR2_PACKAGE_NUSHELL=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        """
+
+    def login(self):
+        img = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv7",
+                           kernel="builtin",
+                           options=["-initrd",img])
+        self.emulator.login()
+
+# load a scipt on the target and check if it is executed correctly by nu
+class TestNu(TestNuBase):
+    config_sample_scripts = \
+        """
+        BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
+        BR2_ROOTFS_POST_SCRIPT_ARGS="{}"
+        """.format(infra.filepath("tests/package/copy-sample-script-to-target.sh"),
+                   "{sample_scripts}")
+
+    #simple hello world script found in the nushell doc
+    sample_scripts = ["tests/package/sample_nu.nu"]
+
+    timeout = -1
+    interpreter = "nu"
+
+    def __init__(self, names):
+        """Add the scripts to the target in build time."""
+        super(TestNuBase, self).__init__(names)
+        scripts = [infra.filepath(s) for s in self.sample_scripts]
+        self.config += self.config_sample_scripts.format(sample_scripts=" ".join(scripts))
+
+    def check_sample_scripts_exist(self):
+        """Check the scripts were really added to the image."""
+        scripts = [os.path.basename(s) for s in self.sample_scripts]
+        cmd = "md5sum " + " ".join(scripts)
+        _, exit_code = self.emulator.run(cmd)
+        self.assertEqual(exit_code, 0)
+
+    def run_sample_scripts(self):
+        """Run each script previously added to the image."""
+        for script in self.sample_scripts:
+            cmd = self.interpreter + " " + os.path.basename(script)
+            self.assertRunOk(cmd, timeout=self.timeout)
+
+    def test_run(self):
+        self.login()
+        self.check_sample_scripts_exist()
+        self.run_sample_scripts()
-- 
2.25.1




More information about the buildroot mailing list