소스 검색

support/testing: add pv runtime test

Signed-off-by: Julien Olivain <ju.o@free.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
(cherry picked from commit 8c5e4be97c8083589665420e438d8b43515b3a00)
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Julien Olivain 11 달 전
부모
커밋
df341bd347
2개의 변경된 파일58개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      DEVELOPERS
  2. 57 0
      support/testing/tests/package/test_pv.py

+ 1 - 0
DEVELOPERS

@@ -1940,6 +1940,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

+ 57 - 0
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%"))