From fc942d50334d7fa831f0d47d46aa013f6f26ef5d Mon Sep 17 00:00:00 2001 From: Julien Olivain Date: Fri, 8 Sep 2023 22:55:38 +0200 Subject: [PATCH] support/testing/tests/package/test_screen.py: new runtime test Signed-off-by: Julien Olivain Signed-off-by: Thomas Petazzoni --- DEVELOPERS | 1 + support/testing/tests/package/test_screen.py | 61 ++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 support/testing/tests/package/test_screen.py diff --git a/DEVELOPERS b/DEVELOPERS index a7410d61fa..a0e2dcca27 100644 --- a/DEVELOPERS +++ b/DEVELOPERS @@ -1768,6 +1768,7 @@ F: support/testing/tests/package/test_python_pyalsa.py F: support/testing/tests/package/test_python_spake2.py F: support/testing/tests/package/test_rdma_core.py F: support/testing/tests/package/test_rdma_core/ +F: support/testing/tests/package/test_screen.py F: support/testing/tests/package/test_stress_ng.py F: support/testing/tests/package/test_weston.py F: support/testing/tests/package/test_weston/ diff --git a/support/testing/tests/package/test_screen.py b/support/testing/tests/package/test_screen.py new file mode 100644 index 0000000000..b6264d34df --- /dev/null +++ b/support/testing/tests/package/test_screen.py @@ -0,0 +1,61 @@ +import os + +import infra.basetest + + +class TestScreen(infra.basetest.BRTest): + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_PACKAGE_SCREEN=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() + + session_name = "BuildrootSession" + message = "HelloBuildroot" + screen_dump = "screen.dump.txt" + + # Check the program can execute + self.assertRunOk("screen --version") + + # There is no "screen" running yet. Listing sessions is + # expected to fail. + _, exit_code = self.emulator.run("screen -ls") + self.assertNotEqual(exit_code, 0) + + # We now start a detached and named session. + self.assertRunOk(f"screen -dmS {session_name}") + + # Since we are supposed to have a running session, it should + # appear in the list. + output, exit_code = self.emulator.run("screen -ls") + self.assertEqual(exit_code, 0) + self.assertIn(session_name, "\n".join(output)) + + # We send an exec command to print a message in the "screen" + # display running in background. + cmd = f"screen -S {session_name} -X exec printf {message}" + self.assertRunOk(cmd) + + # We request a hardcopy of this "screen" display. + cmd = f"screen -S {session_name} -X hardcopy {screen_dump}" + self.assertRunOk(cmd) + + # The dump file is supposed to contain our message. + self.assertRunOk(f"grep -Fo '{message}' {screen_dump}") + + # We request "screen" to quit... + cmd = f"screen -S {session_name} -X quit" + self.assertRunOk(cmd) + + # Since the session is supposed to be terminated, listing + # sessions is expected to fail (again). + _, exit_code = self.emulator.run("screen -ls") + self.assertNotEqual(exit_code, 0)