From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([209.51.188.92]:54762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpjcT-0002ez-LV for qemu-devel@nongnu.org; Fri, 01 Feb 2019 19:57:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpjcM-0003h1-Us for qemu-devel@nongnu.org; Fri, 01 Feb 2019 19:57:12 -0500 From: Cleber Rosa Date: Fri, 1 Feb 2019 19:56:02 -0500 Message-Id: <20190202005610.24048-13-crosa@redhat.com> In-Reply-To: <20190202005610.24048-1-crosa@redhat.com> References: <20190202005610.24048-1-crosa@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 12/20] Boot Linux Console Test: refactor the console watcher into utility method List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Aleksandar Markovic , Caio Carrara , Wainer dos Santos Moschetta , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Eduardo Habkost , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Cornelia Huck , Cleber Rosa , Aleksandar Rikalo , Aurelien Jarno , Fam Zheng , qemu-s390x@nongnu.org, Stefan Markovic This introduces a utility method that monitors the console device and looks for either a message that signals the test success or failure. Reviewed-by: Caio Carrara Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Cleber Rosa --- tests/acceptance/boot_linux_console.py | 30 ++++++++++++++++++-------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/bo= ot_linux_console.py index fa721a7355..e2ef43e7ce 100644 --- a/tests/acceptance/boot_linux_console.py +++ b/tests/acceptance/boot_linux_console.py @@ -25,6 +25,25 @@ class BootLinuxConsole(Test): =20 KERNEL_COMMON_COMMAND_LINE =3D 'printk.time=3D0 ' =20 + def wait_for_console_pattern(self, success_message, + failure_message=3D'Kernel panic - not s= yncing'): + """ + Waits for messages to appear on the console, while logging the c= ontent + + :param success_message: if this message appears, test succeeds + :param failure_message: if this message appears, test fails + """ + console =3D self.vm.console_socket.makefile() + console_logger =3D logging.getLogger('console') + while True: + msg =3D console.readline() + console_logger.debug(msg.strip()) + if success_message in msg: + break + if failure_message in msg: + fail =3D 'Failure message found in console: %s' % failur= e_message + self.fail(fail) + def test_x86_64_pc(self): """ :avocado: tags=3Darch:x86_64 @@ -41,12 +60,5 @@ class BootLinuxConsole(Test): self.vm.add_args('-kernel', kernel_path, '-append', kernel_command_line) self.vm.launch() - console =3D self.vm.console_socket.makefile() - console_logger =3D logging.getLogger('console') - while True: - msg =3D console.readline() - console_logger.debug(msg.strip()) - if 'Kernel command line: %s' % kernel_command_line in msg: - break - if 'Kernel panic - not syncing' in msg: - self.fail("Kernel panic reached") + console_pattern =3D 'Kernel command line: %s' % kernel_command_l= ine + self.wait_for_console_pattern(console_pattern) --=20 2.20.1