[Qemu-devel] [PATCH v2 1/6] tests/acceptance: Add test that runs NetBSD 4.0 installer on PRep/40p

Philippe Mathieu-Daudé posted 6 patches 6 years, 1 month ago
There is a newer version of this series
[Qemu-devel] [PATCH v2 1/6] tests/acceptance: Add test that runs NetBSD 4.0 installer on PRep/40p
Posted by Philippe Mathieu-Daudé 6 years, 1 month ago
As of this commit, NetBSD 4.0 is very old. However it is enough to
test the PRep/40p machine.

User case from:
http://mail-index.netbsd.org/port-prep/2017/04/11/msg000112.html

Reviewed-by: Hervé Poussineau <hpoussin@reactos.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
Installers after 4.0 doesn't work anymore, not sure if this is a
problem from the QEMU model or from NetBSD.
---
 MAINTAINERS                      |  1 +
 tests/acceptance/ppc_prep_40p.py | 63 ++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+)
 create mode 100644 tests/acceptance/ppc_prep_40p.py

diff --git a/MAINTAINERS b/MAINTAINERS
index 50eaf005f4..ce809c7dee 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1068,6 +1068,7 @@ F: hw/timer/m48t59-isa.c
 F: include/hw/isa/pc87312.h
 F: include/hw/timer/m48t59.h
 F: pc-bios/ppc_rom.bin
+F: tests/acceptance/machine_ppc_prep_40p.py
 
 sPAPR
 M: David Gibson <david@gibson.dropbear.id.au>
diff --git a/tests/acceptance/ppc_prep_40p.py b/tests/acceptance/ppc_prep_40p.py
new file mode 100644
index 0000000000..53f2d2ecf0
--- /dev/null
+++ b/tests/acceptance/ppc_prep_40p.py
@@ -0,0 +1,63 @@
+# Functional test that boots a PReP/40p machine and checks its serial console.
+#
+# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later. See the COPYING file in the top-level directory.
+
+import os
+import logging
+
+from avocado import skipIf
+from avocado_qemu import Test
+
+
+class IbmPrep40pMachine(Test):
+
+    timeout = 60
+
+    # TODO refactor to MachineTest
+    def wait_for_console_pattern(self, success_message, failure_message=None):
+        """
+        Waits for messages to appear on the console, while logging the content
+
+        :param success_message: if this message appears, test succeeds
+        :param failure_message: if this message appears, test fails
+        """
+        console = self.vm.console_socket.makefile()
+        console_logger = logging.getLogger('console')
+        while True:
+            msg = console.readline().strip()
+            if not msg:
+                continue
+            console_logger.debug(msg)
+            if success_message in msg:
+                break
+            if failure_message and failure_message in msg:
+                fail = 'Failure message found in console: %s' % failure_message
+                self.fail(fail)
+
+    @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI')
+    def test_factory_firmware_and_netbsd(self):
+        """
+        :avocado: tags=arch:ppc
+        :avocado: tags=machine:40p
+        :avocado: tags=slowness:high
+        """
+        bios_url = ('ftp://ftp.boulder.ibm.com/rs6000/firmware/'
+                    '7020-40p/P12H0456.IMG')
+        bios_hash = '1775face4e6dc27f3a6ed955ef6eb331bf817f03'
+        bios_path = self.fetch_asset(bios_url, asset_hash=bios_hash)
+        drive_url = ('https://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/'
+                     'NetBSD-4.0/prep/installation/floppy/generic_com0.fs')
+        drive_hash = 'dbcfc09912e71bd5f0d82c7c1ee43082fb596ceb'
+        drive_path = self.fetch_asset(drive_url, asset_hash=drive_hash)
+
+        self.vm.set_machine('40p')
+        self.vm.set_console()
+        self.vm.add_args('-bios', bios_path,
+                         '-fda', drive_path)
+        self.vm.launch()
+        os_banner = 'NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:49:40 PST 2007'
+        self.wait_for_console_pattern(os_banner)
+        self.wait_for_console_pattern('Model: IBM PPS Model 6015')
-- 
2.20.1


Re: [Qemu-devel] [PATCH v2 1/6] tests/acceptance: Add test that runs NetBSD 4.0 installer on PRep/40p
Posted by Artyom Tarasenko 6 years, 1 month ago
On Sun, Sep 15, 2019 at 11:19 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> As of this commit, NetBSD 4.0 is very old. However it is enough to
> test the PRep/40p machine.

Not just it's enough, it's also the NetBSD release which definitely
was tested on physical 40p machines.
(It already has reviewed-by maintainer, so I don't suppose you'll need
it, but just in case,
Acked-by: Artyom Tarasenko <atar4qemu@gmail.com>
)

>
> User case from:
> http://mail-index.netbsd.org/port-prep/2017/04/11/msg000112.html
>
> Reviewed-by: Hervé Poussineau <hpoussin@reactos.org>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> Installers after 4.0 doesn't work anymore, not sure if this is a
> problem from the QEMU model or from NetBSD.
> ---
>  MAINTAINERS                      |  1 +
>  tests/acceptance/ppc_prep_40p.py | 63 ++++++++++++++++++++++++++++++++
>  2 files changed, 64 insertions(+)
>  create mode 100644 tests/acceptance/ppc_prep_40p.py
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 50eaf005f4..ce809c7dee 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1068,6 +1068,7 @@ F: hw/timer/m48t59-isa.c
>  F: include/hw/isa/pc87312.h
>  F: include/hw/timer/m48t59.h
>  F: pc-bios/ppc_rom.bin
> +F: tests/acceptance/machine_ppc_prep_40p.py
>
>  sPAPR
>  M: David Gibson <david@gibson.dropbear.id.au>
> diff --git a/tests/acceptance/ppc_prep_40p.py b/tests/acceptance/ppc_prep_40p.py
> new file mode 100644
> index 0000000000..53f2d2ecf0
> --- /dev/null
> +++ b/tests/acceptance/ppc_prep_40p.py
> @@ -0,0 +1,63 @@
> +# Functional test that boots a PReP/40p machine and checks its serial console.
> +#
> +# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# later. See the COPYING file in the top-level directory.
> +
> +import os
> +import logging
> +
> +from avocado import skipIf
> +from avocado_qemu import Test
> +
> +
> +class IbmPrep40pMachine(Test):
> +
> +    timeout = 60
> +
> +    # TODO refactor to MachineTest
> +    def wait_for_console_pattern(self, success_message, failure_message=None):
> +        """
> +        Waits for messages to appear on the console, while logging the content
> +
> +        :param success_message: if this message appears, test succeeds
> +        :param failure_message: if this message appears, test fails
> +        """
> +        console = self.vm.console_socket.makefile()
> +        console_logger = logging.getLogger('console')
> +        while True:
> +            msg = console.readline().strip()
> +            if not msg:
> +                continue
> +            console_logger.debug(msg)
> +            if success_message in msg:
> +                break
> +            if failure_message and failure_message in msg:
> +                fail = 'Failure message found in console: %s' % failure_message
> +                self.fail(fail)
> +
> +    @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI')
> +    def test_factory_firmware_and_netbsd(self):
> +        """
> +        :avocado: tags=arch:ppc
> +        :avocado: tags=machine:40p
> +        :avocado: tags=slowness:high
> +        """
> +        bios_url = ('ftp://ftp.boulder.ibm.com/rs6000/firmware/'
> +                    '7020-40p/P12H0456.IMG')
> +        bios_hash = '1775face4e6dc27f3a6ed955ef6eb331bf817f03'
> +        bios_path = self.fetch_asset(bios_url, asset_hash=bios_hash)
> +        drive_url = ('https://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/'
> +                     'NetBSD-4.0/prep/installation/floppy/generic_com0.fs')
> +        drive_hash = 'dbcfc09912e71bd5f0d82c7c1ee43082fb596ceb'
> +        drive_path = self.fetch_asset(drive_url, asset_hash=drive_hash)
> +
> +        self.vm.set_machine('40p')
> +        self.vm.set_console()
> +        self.vm.add_args('-bios', bios_path,
> +                         '-fda', drive_path)
> +        self.vm.launch()
> +        os_banner = 'NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:49:40 PST 2007'
> +        self.wait_for_console_pattern(os_banner)
> +        self.wait_for_console_pattern('Model: IBM PPS Model 6015')
> --
> 2.20.1
>


-- 
Regards,
Artyom Tarasenko

SPARC and PPC PReP under qemu blog: http://tyom.blogspot.com/search/label/qemu

Re: [Qemu-devel] [PATCH v2 1/6] tests/acceptance: Add test that runs NetBSD 4.0 installer on PRep/40p
Posted by Cleber Rosa 6 years, 1 month ago
On Sun, Sep 15, 2019 at 11:19:35PM +0200, Philippe Mathieu-Daudé wrote:
> As of this commit, NetBSD 4.0 is very old. However it is enough to
> test the PRep/40p machine.
> 
> User case from:
> http://mail-index.netbsd.org/port-prep/2017/04/11/msg000112.html
> 
> Reviewed-by: Hervé Poussineau <hpoussin@reactos.org>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> Installers after 4.0 doesn't work anymore, not sure if this is a
> problem from the QEMU model or from NetBSD.
> ---
>  MAINTAINERS                      |  1 +
>  tests/acceptance/ppc_prep_40p.py | 63 ++++++++++++++++++++++++++++++++
>  2 files changed, 64 insertions(+)
>  create mode 100644 tests/acceptance/ppc_prep_40p.py
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 50eaf005f4..ce809c7dee 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1068,6 +1068,7 @@ F: hw/timer/m48t59-isa.c
>  F: include/hw/isa/pc87312.h
>  F: include/hw/timer/m48t59.h
>  F: pc-bios/ppc_rom.bin
> +F: tests/acceptance/machine_ppc_prep_40p.py
>  
>  sPAPR
>  M: David Gibson <david@gibson.dropbear.id.au>
> diff --git a/tests/acceptance/ppc_prep_40p.py b/tests/acceptance/ppc_prep_40p.py
> new file mode 100644
> index 0000000000..53f2d2ecf0
> --- /dev/null
> +++ b/tests/acceptance/ppc_prep_40p.py
> @@ -0,0 +1,63 @@
> +# Functional test that boots a PReP/40p machine and checks its serial console.
> +#
> +# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# later. See the COPYING file in the top-level directory.
> +
> +import os
> +import logging
> +
> +from avocado import skipIf
> +from avocado_qemu import Test
> +
> +
> +class IbmPrep40pMachine(Test):
> +
> +    timeout = 60
> +
> +    # TODO refactor to MachineTest

Your TODO is a clear sign of awareness of the duplicated code that
follows.  The mention of a MachineTest points into the direction that
I can see as the best final solution (that is, test classes that target
specific test scenarions).

But, it may be a more effective refactor strategy, to simply turn the
`wait_for_console_pattern` from a method into a utility function, and
then the discussion of the common test classes (say MachineTest,
GuestTest, MigrationTest) can follow later.

> +    def wait_for_console_pattern(self, success_message, failure_message=None):

Following the previous suggestion, `self` would become something like `test`.

> +        """
> +        Waits for messages to appear on the console, while logging the content
> +

Documented as something like:

  :param test: an Avocado test containing a VM that will have its console
               read and probed for a success or failure message
  :type test: :class:`avocado_qemu.Test`

> +        :param success_message: if this message appears, test succeeds
> +        :param failure_message: if this message appears, test fails
> +        """
> +        console = self.vm.console_socket.makefile()
> +        console_logger = logging.getLogger('console')
> +        while True:
> +            msg = console.readline().strip()
> +            if not msg:
> +                continue
> +            console_logger.debug(msg)
> +            if success_message in msg:
> +                break
> +            if failure_message and failure_message in msg:
> +                fail = 'Failure message found in console: %s' % failure_message
> +                self.fail(fail)
> +
> +    @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI')
> +    def test_factory_firmware_and_netbsd(self):
> +        """
> +        :avocado: tags=arch:ppc
> +        :avocado: tags=machine:40p
> +        :avocado: tags=slowness:high

This is certainly a discussion in itself, but I wonder what is your
criteria for definising the slowness level of a test.  FOY, this one
takes me ~17 seconds on my local machine.

> +        """
> +        bios_url = ('ftp://ftp.boulder.ibm.com/rs6000/firmware/'
> +                    '7020-40p/P12H0456.IMG')
> +        bios_hash = '1775face4e6dc27f3a6ed955ef6eb331bf817f03'
> +        bios_path = self.fetch_asset(bios_url, asset_hash=bios_hash)
> +        drive_url = ('https://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/'
> +                     'NetBSD-4.0/prep/installation/floppy/generic_com0.fs')
> +        drive_hash = 'dbcfc09912e71bd5f0d82c7c1ee43082fb596ceb'
> +        drive_path = self.fetch_asset(drive_url, asset_hash=drive_hash)
> +
> +        self.vm.set_machine('40p')

FIY, Avocado 72.0 (due Tomorrow) will have relaxed strictness for tags
values.  That will allow us to represent all current machine type
names in ":avocado: tags=machine:$VALUE" (such as "s390-ccw-virtio").
Then we'll be able to reuse them here, avoiding a bit of boiler plate
code.

> +        self.vm.set_console()
> +        self.vm.add_args('-bios', bios_path,
> +                         '-fda', drive_path)
> +        self.vm.launch()
> +        os_banner = 'NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:49:40 PST 2007'
> +        self.wait_for_console_pattern(os_banner)
> +        self.wait_for_console_pattern('Model: IBM PPS Model 6015')
> -- 
> 2.20.1
> 

Overall it looks good and works for me.  Let me know what you think of
the wait_for_console_pattern() refactor suggestions.

- Cleber.

Re: [Qemu-devel] [PATCH v2 1/6] tests/acceptance: Add test that runs NetBSD 4.0 installer on PRep/40p
Posted by Philippe Mathieu-Daudé 6 years, 1 month ago
On 9/16/19 6:08 PM, Cleber Rosa wrote:
> On Sun, Sep 15, 2019 at 11:19:35PM +0200, Philippe Mathieu-Daudé wrote:
>> As of this commit, NetBSD 4.0 is very old. However it is enough to
>> test the PRep/40p machine.
>>
>> User case from:
>> http://mail-index.netbsd.org/port-prep/2017/04/11/msg000112.html
>>
>> Reviewed-by: Hervé Poussineau <hpoussin@reactos.org>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> Installers after 4.0 doesn't work anymore, not sure if this is a
>> problem from the QEMU model or from NetBSD.
>> ---
>>  MAINTAINERS                      |  1 +
>>  tests/acceptance/ppc_prep_40p.py | 63 ++++++++++++++++++++++++++++++++
>>  2 files changed, 64 insertions(+)
>>  create mode 100644 tests/acceptance/ppc_prep_40p.py
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 50eaf005f4..ce809c7dee 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -1068,6 +1068,7 @@ F: hw/timer/m48t59-isa.c
>>  F: include/hw/isa/pc87312.h
>>  F: include/hw/timer/m48t59.h
>>  F: pc-bios/ppc_rom.bin
>> +F: tests/acceptance/machine_ppc_prep_40p.py
>>  
>>  sPAPR
>>  M: David Gibson <david@gibson.dropbear.id.au>
>> diff --git a/tests/acceptance/ppc_prep_40p.py b/tests/acceptance/ppc_prep_40p.py
>> new file mode 100644
>> index 0000000000..53f2d2ecf0
>> --- /dev/null
>> +++ b/tests/acceptance/ppc_prep_40p.py
>> @@ -0,0 +1,63 @@
>> +# Functional test that boots a PReP/40p machine and checks its serial console.
>> +#
>> +# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
>> +#
>> +# This work is licensed under the terms of the GNU GPL, version 2 or
>> +# later. See the COPYING file in the top-level directory.
>> +
>> +import os
>> +import logging
>> +
>> +from avocado import skipIf
>> +from avocado_qemu import Test
>> +
>> +
>> +class IbmPrep40pMachine(Test):
>> +
>> +    timeout = 60
>> +
>> +    # TODO refactor to MachineTest
> 
> Your TODO is a clear sign of awareness of the duplicated code that
> follows.  The mention of a MachineTest points into the direction that
> I can see as the best final solution (that is, test classes that target
> specific test scenarions).
> 
> But, it may be a more effective refactor strategy, to simply turn the
> `wait_for_console_pattern` from a method into a utility function, and
> then the discussion of the common test classes (say MachineTest,
> GuestTest, MigrationTest) can follow later.

Yes, I'd like we clean this and make it robust, but for now, the more
tests we have, the better we can see how the common MachineTest should
be. Let's do this in another follow-up series.

>> +    def wait_for_console_pattern(self, success_message, failure_message=None):
> 
> Following the previous suggestion, `self` would become something like `test`.
> 
>> +        """
>> +        Waits for messages to appear on the console, while logging the content
>> +
> 
> Documented as something like:
> 
>   :param test: an Avocado test containing a VM that will have its console
>                read and probed for a success or failure message
>   :type test: :class:`avocado_qemu.Test`
> 
>> +        :param success_message: if this message appears, test succeeds
>> +        :param failure_message: if this message appears, test fails
>> +        """
>> +        console = self.vm.console_socket.makefile()
>> +        console_logger = logging.getLogger('console')
>> +        while True:
>> +            msg = console.readline().strip()
>> +            if not msg:
>> +                continue
>> +            console_logger.debug(msg)
>> +            if success_message in msg:
>> +                break
>> +            if failure_message and failure_message in msg:
>> +                fail = 'Failure message found in console: %s' % failure_message
>> +                self.fail(fail)
>> +
>> +    @skipIf(os.getenv('CONTINUOUS_INTEGRATION'), 'Running on Travis-CI')
>> +    def test_factory_firmware_and_netbsd(self):
>> +        """
>> +        :avocado: tags=arch:ppc
>> +        :avocado: tags=machine:40p
>> +        :avocado: tags=slowness:high
> 
> This is certainly a discussion in itself, but I wonder what is your
> criteria for definising the slowness level of a test.  FOY, this one
> takes me ~17 seconds on my local machine.

Ah, I was running this in my --enable-debug --enable-tcg-debug
out-of-tree directory, it takes >2min here.

>> +        """
>> +        bios_url = ('ftp://ftp.boulder.ibm.com/rs6000/firmware/'
>> +                    '7020-40p/P12H0456.IMG')
>> +        bios_hash = '1775face4e6dc27f3a6ed955ef6eb331bf817f03'
>> +        bios_path = self.fetch_asset(bios_url, asset_hash=bios_hash)
>> +        drive_url = ('https://ftp.netbsd.org/pub/NetBSD/NetBSD-archive/'
>> +                     'NetBSD-4.0/prep/installation/floppy/generic_com0.fs')
>> +        drive_hash = 'dbcfc09912e71bd5f0d82c7c1ee43082fb596ceb'
>> +        drive_path = self.fetch_asset(drive_url, asset_hash=drive_hash)
>> +
>> +        self.vm.set_machine('40p')
> 
> FIY, Avocado 72.0 (due Tomorrow) will have relaxed strictness for tags
> values.  That will allow us to represent all current machine type
> names in ":avocado: tags=machine:$VALUE" (such as "s390-ccw-virtio").
> Then we'll be able to reuse them here, avoiding a bit of boiler plate
> code.

Good news!

>> +        self.vm.set_console()
>> +        self.vm.add_args('-bios', bios_path,
>> +                         '-fda', drive_path)
>> +        self.vm.launch()
>> +        os_banner = 'NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:49:40 PST 2007'
>> +        self.wait_for_console_pattern(os_banner)
>> +        self.wait_for_console_pattern('Model: IBM PPS Model 6015')
>> -- 
>> 2.20.1
>>
> 
> Overall it looks good and works for me.  Let me know what you think of
> the wait_for_console_pattern() refactor suggestions.

Thanks, I agree we can do it later :)

Regards,

Phil.

[Qemu-devel] [PATCH] Acceptance tests: refactor wait_for_console_pattern
Posted by Cleber Rosa 6 years, 1 month ago
The same utility method is already present in two different test
files, so let's consolidate it into a single utility function.

Signed-off-by: Cleber Rosa <crosa@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py | 26 +++++++++++++
 tests/acceptance/boot_linux_console.py    | 47 +++++++----------------
 tests/acceptance/linux_ssh_mips_malta.py  | 18 ++-------
 3 files changed, 42 insertions(+), 49 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index bd41e0443c..a0fe16e47f 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -8,6 +8,7 @@
 # This work is licensed under the terms of the GNU GPL, version 2 or
 # later.  See the COPYING file in the top-level directory.
 
+import logging
 import os
 import sys
 import uuid
@@ -53,6 +54,31 @@ def pick_default_qemu_bin(arch=None):
         return qemu_bin_from_src_dir_path
 
 
+def wait_for_console_pattern(test, success_message,
+                             failure_message='Kernel panic - not syncing'):
+    """
+    Waits for messages to appear on the console, while logging the content
+
+    :param test: an Avocado test containing a VM that will have its console
+                 read and probed for a success or failure message
+    :type test: :class:`avocado_qemu.Test`
+    :param success_message: if this message appears, test succeeds
+    :param failure_message: if this message appears, test fails
+    """
+    console = test.vm.console_socket.makefile()
+    console_logger = logging.getLogger('console')
+    while True:
+        msg = console.readline().strip()
+        if not msg:
+            continue
+        console_logger.debug(msg)
+        if success_message in msg:
+            break
+        if failure_message in msg:
+            fail = 'Failure message found in console: %s' % failure_message
+            test.fail(fail)
+
+
 class Test(avocado.Test):
     def setUp(self):
         self._vms = {}
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 8a9a314ab4..9ff2213874 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -9,12 +9,12 @@
 # later.  See the COPYING file in the top-level directory.
 
 import os
-import logging
 import lzma
 import gzip
 import shutil
 
 from avocado_qemu import Test
+from avocado_qemu import wait_for_console_pattern
 from avocado.utils import process
 from avocado.utils import archive
 
@@ -29,31 +29,10 @@ class BootLinuxConsole(Test):
 
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
 
-    def wait_for_console_pattern(self, success_message,
-                                 failure_message='Kernel panic - not syncing'):
-        """
-        Waits for messages to appear on the console, while logging the content
-
-        :param success_message: if this message appears, test succeeds
-        :param failure_message: if this message appears, test fails
-        """
-        console = self.vm.console_socket.makefile()
-        console_logger = logging.getLogger('console')
-        while True:
-            msg = console.readline().strip()
-            if not msg:
-                continue
-            console_logger.debug(msg)
-            if success_message in msg:
-                break
-            if failure_message in msg:
-                fail = 'Failure message found in console: %s' % failure_message
-                self.fail(fail)
-
     def exec_command_and_wait_for_pattern(self, command, success_message):
         command += '\n'
         self.vm.console_socket.sendall(command.encode())
-        self.wait_for_console_pattern(success_message)
+        wait_for_console_pattern(self, success_message)
 
     def extract_from_deb(self, deb, path):
         """
@@ -89,7 +68,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
 
     def test_mips_malta(self):
         """
@@ -112,7 +91,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
 
     def test_mips64el_malta(self):
         """
@@ -145,7 +124,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
 
     def test_mips_malta_cpio(self):
         """
@@ -181,7 +160,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line,
                          '-no-reboot')
         self.vm.launch()
-        self.wait_for_console_pattern('Boot successful.')
+        wait_for_console_pattern(self, 'Boot successful.')
 
         self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
                                                'BogoMIPS')
@@ -208,7 +187,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
 
     def test_mips_malta32el_nanomips_4k(self):
         """
@@ -266,7 +245,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
 
     def test_arm_virt(self):
         """
@@ -287,7 +266,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
 
     def test_arm_emcraft_sf2(self):
         """
@@ -314,7 +293,7 @@ class BootLinuxConsole(Test):
                          '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
                          '-no-reboot')
         self.vm.launch()
-        self.wait_for_console_pattern('init started: BusyBox')
+        wait_for_console_pattern(self, 'init started: BusyBox')
 
     def test_s390x_s390_ccw_virtio(self):
         """
@@ -335,7 +314,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
 
     def test_alpha_clipper(self):
         """
@@ -357,7 +336,7 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
 
     def test_ppc64_pseries(self):
         """
@@ -377,4 +356,4 @@ class BootLinuxConsole(Test):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern)
diff --git a/tests/acceptance/linux_ssh_mips_malta.py b/tests/acceptance/linux_ssh_mips_malta.py
index 134f10cac3..da7a386117 100644
--- a/tests/acceptance/linux_ssh_mips_malta.py
+++ b/tests/acceptance/linux_ssh_mips_malta.py
@@ -14,6 +14,7 @@ import time
 
 from avocado import skipIf
 from avocado_qemu import Test
+from avocado_qemu import wait_for_console_pattern
 from avocado.utils import process
 from avocado.utils import archive
 
@@ -56,19 +57,6 @@ class LinuxSSH(Test):
         },
     }
 
-    def wait_for_console_pattern(self, success_message,
-                                 failure_message='Oops'):
-        console = self.vm.console_socket.makefile()
-        console_logger = logging.getLogger('console')
-        while True:
-            msg = console.readline()
-            console_logger.debug(msg.strip())
-            if success_message in msg:
-                break
-            if failure_message in msg:
-                fail = 'Failure message found in console: %s' % failure_message
-                self.fail(fail)
-
     def get_portfwd(self):
         res = self.vm.command('human-monitor-command',
                               command_line='info usernet')
@@ -135,7 +123,7 @@ class LinuxSSH(Test):
 
         self.log.info('VM launched, waiting for sshd')
         console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
-        self.wait_for_console_pattern(console_pattern)
+        wait_for_console_pattern(self, console_pattern, 'Oops')
         self.log.info('sshd ready')
 
         self.ssh_connect('root', 'root', rsa_hostkey_b64=rsa_hostkey_b64)
@@ -143,7 +131,7 @@ class LinuxSSH(Test):
     def shutdown_via_ssh(self):
         self.ssh_command('poweroff')
         self.ssh_disconnect_vm()
-        self.wait_for_console_pattern('Power down')
+        wait_for_console_pattern(self, 'Power down', 'Oops')
 
     def run_common_commands(self):
         stdout, stderr = self.ssh_command('lspci -d 11ab:4620')
-- 
2.21.0


Re: [Qemu-devel] [PATCH] Acceptance tests: refactor wait_for_console_pattern
Posted by Wainer dos Santos Moschetta 6 years ago
Hi Cleber,

On 9/16/19 1:40 PM, Cleber Rosa wrote:
> The same utility method is already present in two different test
> files, so let's consolidate it into a single utility function.
>
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
>   tests/acceptance/avocado_qemu/__init__.py | 26 +++++++++++++
>   tests/acceptance/boot_linux_console.py    | 47 +++++++----------------
>   tests/acceptance/linux_ssh_mips_malta.py  | 18 ++-------
>   3 files changed, 42 insertions(+), 49 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index bd41e0443c..a0fe16e47f 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -8,6 +8,7 @@
>   # This work is licensed under the terms of the GNU GPL, version 2 or
>   # later.  See the COPYING file in the top-level directory.
>   
> +import logging
>   import os
>   import sys
>   import uuid
> @@ -53,6 +54,31 @@ def pick_default_qemu_bin(arch=None):
>           return qemu_bin_from_src_dir_path
>   
>   
> +def wait_for_console_pattern(test, success_message,
> +                             failure_message='Kernel panic - not syncing'):
> +    """
> +    Waits for messages to appear on the console, while logging the content
> +
> +    :param test: an Avocado test containing a VM that will have its console
> +                 read and probed for a success or failure message
> +    :type test: :class:`avocado_qemu.Test`
> +    :param success_message: if this message appears, test succeeds
> +    :param failure_message: if this message appears, test fails
> +    """
> +    console = test.vm.console_socket.makefile()
> +    console_logger = logging.getLogger('console')
> +    while True:
> +        msg = console.readline().strip()
> +        if not msg:
> +            continue
> +        console_logger.debug(msg)
> +        if success_message in msg:
> +            break
> +        if failure_message in msg:
> +            fail = 'Failure message found in console: %s' % failure_message
> +            test.fail(fail)
> +
> +

Note to self: it would be useful if wait_for_console_pattern could 
return the read lines. Example of use: a test case waits the kernel to 
boot - if succeed - then it can check if SMP topology is expected by 
parsing the console lines.

Regardless, this change looks good to me.

Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>


>   class Test(avocado.Test):
>       def setUp(self):
>           self._vms = {}
> diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
> index 8a9a314ab4..9ff2213874 100644
> --- a/tests/acceptance/boot_linux_console.py
> +++ b/tests/acceptance/boot_linux_console.py
> @@ -9,12 +9,12 @@
>   # later.  See the COPYING file in the top-level directory.
>   
>   import os
> -import logging
>   import lzma
>   import gzip
>   import shutil
>   
>   from avocado_qemu import Test
> +from avocado_qemu import wait_for_console_pattern
>   from avocado.utils import process
>   from avocado.utils import archive
>   
> @@ -29,31 +29,10 @@ class BootLinuxConsole(Test):
>   
>       KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
>   
> -    def wait_for_console_pattern(self, success_message,
> -                                 failure_message='Kernel panic - not syncing'):
> -        """
> -        Waits for messages to appear on the console, while logging the content
> -
> -        :param success_message: if this message appears, test succeeds
> -        :param failure_message: if this message appears, test fails
> -        """
> -        console = self.vm.console_socket.makefile()
> -        console_logger = logging.getLogger('console')
> -        while True:
> -            msg = console.readline().strip()
> -            if not msg:
> -                continue
> -            console_logger.debug(msg)
> -            if success_message in msg:
> -                break
> -            if failure_message in msg:
> -                fail = 'Failure message found in console: %s' % failure_message
> -                self.fail(fail)
> -
>       def exec_command_and_wait_for_pattern(self, command, success_message):
>           command += '\n'
>           self.vm.console_socket.sendall(command.encode())
> -        self.wait_for_console_pattern(success_message)
> +        wait_for_console_pattern(self, success_message)
>   
>       def extract_from_deb(self, deb, path):
>           """
> @@ -89,7 +68,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_mips_malta(self):
>           """
> @@ -112,7 +91,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_mips64el_malta(self):
>           """
> @@ -145,7 +124,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_mips_malta_cpio(self):
>           """
> @@ -181,7 +160,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line,
>                            '-no-reboot')
>           self.vm.launch()
> -        self.wait_for_console_pattern('Boot successful.')
> +        wait_for_console_pattern(self, 'Boot successful.')
>   
>           self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
>                                                  'BogoMIPS')
> @@ -208,7 +187,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_mips_malta32el_nanomips_4k(self):
>           """
> @@ -266,7 +245,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_arm_virt(self):
>           """
> @@ -287,7 +266,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_arm_emcraft_sf2(self):
>           """
> @@ -314,7 +293,7 @@ class BootLinuxConsole(Test):
>                            '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
>                            '-no-reboot')
>           self.vm.launch()
> -        self.wait_for_console_pattern('init started: BusyBox')
> +        wait_for_console_pattern(self, 'init started: BusyBox')
>   
>       def test_s390x_s390_ccw_virtio(self):
>           """
> @@ -335,7 +314,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_alpha_clipper(self):
>           """
> @@ -357,7 +336,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_ppc64_pseries(self):
>           """
> @@ -377,4 +356,4 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
> diff --git a/tests/acceptance/linux_ssh_mips_malta.py b/tests/acceptance/linux_ssh_mips_malta.py
> index 134f10cac3..da7a386117 100644
> --- a/tests/acceptance/linux_ssh_mips_malta.py
> +++ b/tests/acceptance/linux_ssh_mips_malta.py
> @@ -14,6 +14,7 @@ import time
>   
>   from avocado import skipIf
>   from avocado_qemu import Test
> +from avocado_qemu import wait_for_console_pattern
>   from avocado.utils import process
>   from avocado.utils import archive
>   
> @@ -56,19 +57,6 @@ class LinuxSSH(Test):
>           },
>       }
>   
> -    def wait_for_console_pattern(self, success_message,
> -                                 failure_message='Oops'):
> -        console = self.vm.console_socket.makefile()
> -        console_logger = logging.getLogger('console')
> -        while True:
> -            msg = console.readline()
> -            console_logger.debug(msg.strip())
> -            if success_message in msg:
> -                break
> -            if failure_message in msg:
> -                fail = 'Failure message found in console: %s' % failure_message
> -                self.fail(fail)
> -
>       def get_portfwd(self):
>           res = self.vm.command('human-monitor-command',
>                                 command_line='info usernet')
> @@ -135,7 +123,7 @@ class LinuxSSH(Test):
>   
>           self.log.info('VM launched, waiting for sshd')
>           console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern, 'Oops')
>           self.log.info('sshd ready')
>   
>           self.ssh_connect('root', 'root', rsa_hostkey_b64=rsa_hostkey_b64)
> @@ -143,7 +131,7 @@ class LinuxSSH(Test):
>       def shutdown_via_ssh(self):
>           self.ssh_command('poweroff')
>           self.ssh_disconnect_vm()
> -        self.wait_for_console_pattern('Power down')
> +        wait_for_console_pattern(self, 'Power down', 'Oops')
>   
>       def run_common_commands(self):
>           stdout, stderr = self.ssh_command('lspci -d 11ab:4620')


Re: [PATCH] Acceptance tests: refactor wait_for_console_pattern
Posted by Philippe Mathieu-Daudé 6 years ago
On 9/16/19 6:40 PM, Cleber Rosa wrote:
> The same utility method is already present in two different test
> files, so let's consolidate it into a single utility function.
> 
> Signed-off-by: Cleber Rosa <crosa@redhat.com>
> ---
>   tests/acceptance/avocado_qemu/__init__.py | 26 +++++++++++++
>   tests/acceptance/boot_linux_console.py    | 47 +++++++----------------
>   tests/acceptance/linux_ssh_mips_malta.py  | 18 ++-------
>   3 files changed, 42 insertions(+), 49 deletions(-)
> 
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index bd41e0443c..a0fe16e47f 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -8,6 +8,7 @@
>   # This work is licensed under the terms of the GNU GPL, version 2 or
>   # later.  See the COPYING file in the top-level directory.
>   
> +import logging
>   import os
>   import sys
>   import uuid
> @@ -53,6 +54,31 @@ def pick_default_qemu_bin(arch=None):
>           return qemu_bin_from_src_dir_path
>   
>   
> +def wait_for_console_pattern(test, success_message,
> +                             failure_message='Kernel panic - not syncing'):
> +    """
> +    Waits for messages to appear on the console, while logging the content
> +
> +    :param test: an Avocado test containing a VM that will have its console
> +                 read and probed for a success or failure message
> +    :type test: :class:`avocado_qemu.Test`
> +    :param success_message: if this message appears, test succeeds
> +    :param failure_message: if this message appears, test fails
> +    """
> +    console = test.vm.console_socket.makefile()
> +    console_logger = logging.getLogger('console')
> +    while True:
> +        msg = console.readline().strip()
> +        if not msg:
> +            continue
> +        console_logger.debug(msg)
> +        if success_message in msg:
> +            break
> +        if failure_message in msg:
> +            fail = 'Failure message found in console: %s' % failure_message
> +            test.fail(fail)
> +
> +
>   class Test(avocado.Test):
>       def setUp(self):
>           self._vms = {}
> diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
> index 8a9a314ab4..9ff2213874 100644
> --- a/tests/acceptance/boot_linux_console.py
> +++ b/tests/acceptance/boot_linux_console.py
> @@ -9,12 +9,12 @@
>   # later.  See the COPYING file in the top-level directory.
>   
>   import os
> -import logging
>   import lzma
>   import gzip
>   import shutil
>   
>   from avocado_qemu import Test
> +from avocado_qemu import wait_for_console_pattern
>   from avocado.utils import process
>   from avocado.utils import archive
>   
> @@ -29,31 +29,10 @@ class BootLinuxConsole(Test):
>   
>       KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
>   
> -    def wait_for_console_pattern(self, success_message,
> -                                 failure_message='Kernel panic - not syncing'):
> -        """
> -        Waits for messages to appear on the console, while logging the content
> -
> -        :param success_message: if this message appears, test succeeds
> -        :param failure_message: if this message appears, test fails
> -        """
> -        console = self.vm.console_socket.makefile()
> -        console_logger = logging.getLogger('console')
> -        while True:
> -            msg = console.readline().strip()
> -            if not msg:
> -                continue
> -            console_logger.debug(msg)
> -            if success_message in msg:
> -                break
> -            if failure_message in msg:
> -                fail = 'Failure message found in console: %s' % failure_message
> -                self.fail(fail)
> -
>       def exec_command_and_wait_for_pattern(self, command, success_message):
>           command += '\n'
>           self.vm.console_socket.sendall(command.encode())
> -        self.wait_for_console_pattern(success_message)
> +        wait_for_console_pattern(self, success_message)
>   
>       def extract_from_deb(self, deb, path):
>           """
> @@ -89,7 +68,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_mips_malta(self):
>           """
> @@ -112,7 +91,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_mips64el_malta(self):
>           """
> @@ -145,7 +124,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_mips_malta_cpio(self):
>           """
> @@ -181,7 +160,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line,
>                            '-no-reboot')
>           self.vm.launch()
> -        self.wait_for_console_pattern('Boot successful.')
> +        wait_for_console_pattern(self, 'Boot successful.')
>   
>           self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
>                                                  'BogoMIPS')
> @@ -208,7 +187,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_mips_malta32el_nanomips_4k(self):
>           """
> @@ -266,7 +245,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_arm_virt(self):
>           """
> @@ -287,7 +266,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_arm_emcraft_sf2(self):
>           """
> @@ -314,7 +293,7 @@ class BootLinuxConsole(Test):
>                            '-drive', 'file=' + spi_path + ',if=mtd,format=raw',
>                            '-no-reboot')
>           self.vm.launch()
> -        self.wait_for_console_pattern('init started: BusyBox')
> +        wait_for_console_pattern(self, 'init started: BusyBox')
>   
>       def test_s390x_s390_ccw_virtio(self):
>           """
> @@ -335,7 +314,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_alpha_clipper(self):
>           """
> @@ -357,7 +336,7 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
>   
>       def test_ppc64_pseries(self):
>           """
> @@ -377,4 +356,4 @@ class BootLinuxConsole(Test):
>                            '-append', kernel_command_line)
>           self.vm.launch()
>           console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern)
> diff --git a/tests/acceptance/linux_ssh_mips_malta.py b/tests/acceptance/linux_ssh_mips_malta.py
> index 134f10cac3..da7a386117 100644
> --- a/tests/acceptance/linux_ssh_mips_malta.py
> +++ b/tests/acceptance/linux_ssh_mips_malta.py
> @@ -14,6 +14,7 @@ import time
>   
>   from avocado import skipIf
>   from avocado_qemu import Test
> +from avocado_qemu import wait_for_console_pattern
>   from avocado.utils import process
>   from avocado.utils import archive
>   
> @@ -56,19 +57,6 @@ class LinuxSSH(Test):
>           },
>       }
>   
> -    def wait_for_console_pattern(self, success_message,
> -                                 failure_message='Oops'):
> -        console = self.vm.console_socket.makefile()
> -        console_logger = logging.getLogger('console')
> -        while True:
> -            msg = console.readline()
> -            console_logger.debug(msg.strip())
> -            if success_message in msg:
> -                break
> -            if failure_message in msg:
> -                fail = 'Failure message found in console: %s' % failure_message
> -                self.fail(fail)
> -
>       def get_portfwd(self):
>           res = self.vm.command('human-monitor-command',
>                                 command_line='info usernet')
> @@ -135,7 +123,7 @@ class LinuxSSH(Test):
>   
>           self.log.info('VM launched, waiting for sshd')
>           console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
> -        self.wait_for_console_pattern(console_pattern)
> +        wait_for_console_pattern(self, console_pattern, 'Oops')
>           self.log.info('sshd ready')
>   
>           self.ssh_connect('root', 'root', rsa_hostkey_b64=rsa_hostkey_b64)
> @@ -143,7 +131,7 @@ class LinuxSSH(Test):
>       def shutdown_via_ssh(self):
>           self.ssh_command('poweroff')
>           self.ssh_disconnect_vm()
> -        self.wait_for_console_pattern('Power down')
> +        wait_for_console_pattern(self, 'Power down', 'Oops')
>   
>       def run_common_commands(self):
>           stdout, stderr = self.ssh_command('lspci -d 11ab:4620')
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>