* [Buildroot] [PATCH 1/1] support/testing: add pv runtime test
@ 2024-08-24 14:19 Julien Olivain
2024-09-14 18:05 ` Thomas Petazzoni via buildroot
2024-10-03 14:57 ` Peter Korsgaard
0 siblings, 2 replies; 3+ messages in thread
From: Julien Olivain @ 2024-08-24 14:19 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/7657843473
---
DEVELOPERS | 1 +
support/testing/tests/package/test_pv.py | 57 ++++++++++++++++++++++++
2 files changed, 58 insertions(+)
create mode 100644 support/testing/tests/package/test_pv.py
diff --git a/DEVELOPERS b/DEVELOPERS
index 426590d5c5..419c3e75ec 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1937,6 +1937,7 @@ F: support/testing/tests/package/test_pciutils.py
F: support/testing/tests/package/test_perftest.py
F: support/testing/tests/package/test_pigz.py
F: support/testing/tests/package/test_postgresql.py
+F: support/testing/tests/package/test_pv.py
F: support/testing/tests/package/test_python_distro.py
F: support/testing/tests/package/test_python_gnupg.py
F: support/testing/tests/package/test_python_hkdf.py
diff --git a/support/testing/tests/package/test_pv.py b/support/testing/tests/package/test_pv.py
new file mode 100644
index 0000000000..cfa3c29392
--- /dev/null
+++ b/support/testing/tests/package/test_pv.py
@@ -0,0 +1,57 @@
+import os
+
+import infra.basetest
+
+
+class TestPv(infra.basetest.BRTest):
+ config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+ """
+ BR2_PACKAGE_PV=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.
+ self.assertRunOk("pv --version")
+
+ # We check that "pv" works like the "cat" command. We print a
+ # message on its standard input and redirect its output to a
+ # file. We also force the pv terminal width to 80, since
+ # "infra.emulator" is setting a large width to prevent
+ # line wrapping.
+ msg = "Hello Buildroot!"
+ out_file = "/tmp/out.txt"
+ cmd = f"echo '{msg}' | pv -w80 > {out_file}"
+ self.assertRunOk(cmd)
+
+ # We check the pv output file contains exactly our message.
+ cmd = f"cat {out_file}"
+ out, ret = self.emulator.run(cmd)
+ self.assertEqual(ret, 0)
+ self.assertEqual(out[0], msg)
+
+ # Finally, we check that "pv" correctly shows a progress
+ # bar. We print few lines, one per second into "pv" setup in
+ # line mode. We check the last pv status line contains the
+ # correct count and a "100%" string that shows completion.
+ lines = 5
+ print_ln_cmd = f"( for X in $(seq {lines}) ; do echo $X ; sleep 1 ; done )"
+ cmd = f"{print_ln_cmd} | pv -s{lines} -l -w80 > /dev/null"
+ out, ret = self.emulator.run(cmd, timeout=10)
+ self.assertEqual(ret, 0)
+ # pv updates status may contain extra spaces, and is updated
+ # with carriage return characters. We strip lines and filter
+ # out empty remaining lines, to make sure we get the last
+ # meaningful status line.
+ pv_out = [ln.strip() for ln in out]
+ pv_out = [ln for ln in pv_out if ln]
+ last_line = pv_out[-1]
+ self.assertTrue(last_line.startswith(str(lines)))
+ self.assertTrue(last_line.endswith("100%"))
--
2.46.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-03 14:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-24 14:19 [Buildroot] [PATCH 1/1] support/testing: add pv runtime test Julien Olivain
2024-09-14 18:05 ` Thomas Petazzoni via buildroot
2024-10-03 14:57 ` Peter Korsgaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox