All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] support/testing: add a "file" package runtime test
@ 2024-01-12 20:49 Julien Olivain
  2024-01-21  9:38 ` Yann E. MORIN
  0 siblings, 1 reply; 2+ messages in thread
From: Julien Olivain @ 2024-01-12 20:49 UTC (permalink / raw)
  To: buildroot; +Cc: Julien Olivain

Signed-off-by: Julien Olivain <ju.o@free.fr>
---
 DEVELOPERS                                 |  1 +
 support/testing/tests/package/test_file.py | 81 ++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 support/testing/tests/package/test_file.py

diff --git a/DEVELOPERS b/DEVELOPERS
index 94a89c63d5..8179974097 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1765,6 +1765,7 @@ F:	support/testing/tests/package/test_compressor_base.py
 F:	support/testing/tests/package/test_ddrescue.py
 F:	support/testing/tests/package/test_ddrescue/
 F:	support/testing/tests/package/test_dos2unix.py
+F:	support/testing/tests/package/test_file.py
 F:	support/testing/tests/package/test_fluidsynth.py
 F:	support/testing/tests/package/test_fluidsynth/
 F:	support/testing/tests/package/test_gawk.py
diff --git a/support/testing/tests/package/test_file.py b/support/testing/tests/package/test_file.py
new file mode 100644
index 0000000000..686fa52d72
--- /dev/null
+++ b/support/testing/tests/package/test_file.py
@@ -0,0 +1,81 @@
+import os
+
+import infra.basetest
+
+
+class TestFile(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_PACKAGE_FILE=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def generate_test_data(self):
+        cmd = "echo 'Hello Buildroot!' > file.txt"
+        self.assertRunOk(cmd)
+
+        cmd = "gzip -k file.txt"
+        self.assertRunOk(cmd)
+
+        cmd = "ln -s file.txt link.txt"
+        self.assertRunOk(cmd)
+
+        cmd = "echo 'void main(void) { printf(\"hello\\nBuildroot!\"); }' > file.c"
+        self.assertRunOk(cmd)
+
+        cmd = "echo -e '#!/bin/sh\necho Hello Buildroot' > file.sh"
+        self.assertRunOk(cmd)
+
+        cmd = "echo -e '"
+        cmd += "#!/usr/bin/env python3\nprint(\"Hello Buildroot!\")'"
+        cmd += " > file.py"
+        self.assertRunOk(cmd)
+
+        cmd = "dd if=/dev/urandom of=file.bin bs=1k count=4"
+        self.assertRunOk(cmd)
+
+    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()
+
+        self.assertRunOk("file --version")
+
+        self.generate_test_data()
+
+        tests = [
+            ["file.txt", "ASCII text"],
+            ["file.txt.gz", "gzip compressed data"],
+            ["file.c", "C source"],
+            ["file.sh", "POSIX shell script"],
+            ["file.py", "Python script"],
+            ["file.bin", "data"],
+            ["/usr/share/misc/magic.mgc", "magic binary file for file"],
+            ["/usr/bin/file", "ELF"],
+            ["/dev/zero", "character special"],
+            ["/", "directory"]
+        ]
+        for test_file, expected_type in tests:
+            cmd = f"file '{test_file}' | grep -F '{expected_type}'"
+            self.assertRunOk(cmd)
+
+        tests = [
+            ["file.txt", "text/plain"],
+            ["file.txt.gz", "application/gzip"],
+            ["file.bin", "application/octet-stream"],
+        ]
+        for test_file, expected_type in tests:
+            cmd = f"file -i '{test_file}' | grep -F '{expected_type}'"
+            self.assertRunOk(cmd)
+
+        cmd = "file -h link.txt | grep -F 'symbolic link'"
+        self.assertRunOk(cmd)
+
+        cmd = "file -L link.txt | grep -F 'ASCII text'"
+        self.assertRunOk(cmd)
+
+        cmd = "file -z file.txt.gz | grep -F 'ASCII text'"
+        self.assertRunOk(cmd)
-- 
2.43.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-01-21  9:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12 20:49 [Buildroot] [PATCH 1/1] support/testing: add a "file" package runtime test Julien Olivain
2024-01-21  9:38 ` Yann E. MORIN

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.