Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] support/testing: add which runtime test
@ 2024-08-24 16:25 Julien Olivain
  2024-08-26 16:49 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: Julien Olivain @ 2024-08-24 16:25 UTC (permalink / raw)
  To: buildroot; +Cc: Julien Olivain

Signed-off-by: Julien Olivain <ju.o@free.fr>
---
Patch tested in:
https://gitlab.com/jolivain/buildroot/-/jobs/7658080298
---
 DEVELOPERS                                  |  1 +
 support/testing/tests/package/test_which.py | 53 +++++++++++++++++++++
 2 files changed, 54 insertions(+)
 create mode 100644 support/testing/tests/package/test_which.py

diff --git a/DEVELOPERS b/DEVELOPERS
index 426590d5c5..4431927f0b 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1972,6 +1972,7 @@ F:	support/testing/tests/package/test_usbutils/
 F:	support/testing/tests/package/test_vorbis_tools.py
 F:	support/testing/tests/package/test_weston.py
 F:	support/testing/tests/package/test_weston/
+F:	support/testing/tests/package/test_which.py
 F:	support/testing/tests/package/test_wine.py
 F:	support/testing/tests/package/test_xfsprogs.py
 F:	support/testing/tests/package/test_xfsprogs/
diff --git a/support/testing/tests/package/test_which.py b/support/testing/tests/package/test_which.py
new file mode 100644
index 0000000000..38f528aa7f
--- /dev/null
+++ b/support/testing/tests/package/test_which.py
@@ -0,0 +1,53 @@
+import os
+
+import infra.basetest
+
+
+class TestWhich(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
+        BR2_PACKAGE_WHICH=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    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()
+
+        # We check the program can run. This also checks we are using
+        # the actual GNU which, since the BusyBox implementation does
+        # not accept this option.
+        self.assertRunOk("which --version")
+
+        # We check the primary usage is working.
+        out, ret = self.emulator.run("which sh")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], "/bin/sh")
+
+        alias_name = "buildoot_test_alias"
+
+        # We check "which" returns an error when the program is not
+        # found.
+        _, ret = self.emulator.run(f"which {alias_name}")
+        self.assertNotEqual(ret, 0)
+
+        # We define a shell alias.
+        alias_cmd = "/bin/true"
+        alias_def = f"{alias_name}='{alias_cmd}'"
+        self.assertRunOk(f"alias {alias_def}")
+
+        # We check our alias definition actually works, just by
+        # invoking it (since it's aliased to "true").
+        self.assertRunOk(alias_name)
+
+        # We check "which" is able to read aliases from the shell.
+        cmd = f"alias | which -i {alias_name}"
+        out, ret = self.emulator.run(cmd)
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], alias_def)
+        self.assertEqual(out[1].strip(), alias_cmd)
-- 
2.46.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-26 16:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-24 16:25 [Buildroot] [PATCH 1/1] support/testing: add which runtime test Julien Olivain
2024-08-26 16:49 ` Thomas Petazzoni via buildroot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox