qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn
@ 2021-05-03 22:43 Wainer dos Santos Moschetta
  2021-05-03 22:43 ` [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class Wainer dos Santos Moschetta
                   ` (7 more replies)
  0 siblings, 8 replies; 19+ messages in thread
From: Wainer dos Santos Moschetta @ 2021-05-03 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: willianr, philmd, crosa

The avocado_qemu package provides the following methods to interact with the
guest via console, which are mainly used on the acceptance boot tests:

 exec_command(), exec_command_and_wait_for_pattern(), wait_for_console_pattern(),
 interrupt_interactive_console_until_pattern()

Those methods are loosely defined in avocado_qemu/__init__.py. Because that file is expected to
grow, I thought that for the sake of keeping it organized it would be better to logically group
them. So in this series I create the ConsoleMixIn class to be the new home for the console
methods. An alternative approach could be to create a separated package, however because
they are just a few methods at the moment, I prefered not to break avocado_qemu into smaller pieces.

As the "MixIn" in the name implies, the class is meant to be used as a mixin on the test class. Here
I am following an idea introduced by Cleber in [1].

This series was tested on CI (https://gitlab.com/wainersm/qemu/-/pipelines/296412039)

[1] http://next.patchew.org/QEMU/20210412044644.55083-1-crosa@redhat.com/

Wainer dos Santos Moschetta (7):
  tests/acceptance: Introduce the ConsoleMixIn class
  tests/acceptance: Move exec_command to ConsoleMixIn
  tests/acceptance: Move exec_command_and_wait_for_pattern to
    ConsoleMixIn
  tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest
  tests/acceptance: replay_kernel: Remove unused
    wait_for_console_pattern
  tests/acceptance: Move wait_for_console_pattern to ConsoleMixIn
  tests/acceptance: Move _console_interaction to ConsoleMixIn

 tests/acceptance/avocado_qemu/__init__.py    | 161 +++++++++----------
 tests/acceptance/boot_linux_console.py       | 133 ++++++++-------
 tests/acceptance/boot_xen.py                 |   5 +-
 tests/acceptance/linux_ssh_mips_malta.py     |   8 +-
 tests/acceptance/machine_arm_canona1100.py   |   6 +-
 tests/acceptance/machine_arm_integratorcp.py |   8 +-
 tests/acceptance/machine_arm_n8x0.py         |   6 +-
 tests/acceptance/machine_microblaze.py       |   8 +-
 tests/acceptance/machine_mips_loongson3v.py  |   6 +-
 tests/acceptance/machine_mips_malta.py       |   6 +-
 tests/acceptance/machine_ppc.py              |  10 +-
 tests/acceptance/machine_rx_gdbsim.py        |  15 +-
 tests/acceptance/machine_s390_ccw_virtio.py  |  79 +++++----
 tests/acceptance/machine_sparc64_sun4u.py    |  13 +-
 tests/acceptance/machine_sparc_leon3.py      |   8 +-
 tests/acceptance/multiprocess.py             |  14 +-
 tests/acceptance/ppc_prep_40p.py             |  16 +-
 tests/acceptance/replay_kernel.py            |   1 -
 tests/acceptance/virtio-gpu.py               |  16 +-
 tests/acceptance/virtiofs_submounts.py       |   1 -
 20 files changed, 249 insertions(+), 271 deletions(-)

-- 
2.29.2



^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class
  2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
@ 2021-05-03 22:43 ` Wainer dos Santos Moschetta
  2021-05-24 18:14   ` Willian Rampazzo
  2021-05-03 22:43 ` [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn Wainer dos Santos Moschetta
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Wainer dos Santos Moschetta @ 2021-05-03 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: willianr, philmd, crosa

This created the ConsoleMixIn class to wrap the methods related with console
interaction with the guest that currently are loose in the avocado_qemu
package. It should be used as a mixin on the test classes.

At this point only the interrupt_interactive_console_until_pattern() was moved
to ConsoleMixIn. This method is only used in boot_linux_console.py tests, so
there was needed to adapt them.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py | 52 +++++++++++------------
 tests/acceptance/boot_linux_console.py    | 10 ++---
 2 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 83b1741ec8..6f4e0edfa3 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -101,32 +101,6 @@ def _console_interaction(test, success_message, failure_message,
                     (failure_message, success_message)
             test.fail(fail)
 
-def interrupt_interactive_console_until_pattern(test, success_message,
-                                                failure_message=None,
-                                                interrupt_string='\r'):
-    """
-    Keep sending a string to interrupt a console prompt, while logging the
-    console output. Typical use case is to break a boot loader prompt, such:
-
-        Press a key within 5 seconds to interrupt boot process.
-        5
-        4
-        3
-        2
-        1
-        Booting default image...
-
-    :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
-    :param interrupt_string: a string to send to the console before trying
-                             to read a new line
-    """
-    _console_interaction(test, success_message, failure_message,
-                         interrupt_string, True)
-
 def wait_for_console_pattern(test, success_message, failure_message=None,
                              vm=None):
     """
@@ -168,6 +142,32 @@ def exec_command_and_wait_for_pattern(test, command,
     """
     _console_interaction(test, success_message, failure_message, command + '\r')
 
+class ConsoleMixIn():
+    """Contains utilities for interacting with a guest via Console."""
+
+    def interrupt_interactive_console_until_pattern(self, success_message,
+                                                    failure_message=None,
+                                                    interrupt_string='\r'):
+        """
+        Keep sending a string to interrupt a console prompt, while logging the
+        console output. Typical use case is to break a boot loader prompt, such:
+
+            Press a key within 5 seconds to interrupt boot process.
+            5
+            4
+            3
+            2
+            1
+            Booting default image...
+
+        :param success_message: if this message appears, test succeeds
+        :param failure_message: if this message appears, test fails
+        :param interrupt_string: a string to send to the console before trying
+                                to read a new line
+        """
+        _console_interaction(self, success_message, failure_message,
+                         interrupt_string, True)
+
 class Test(avocado.Test):
     def _get_unique_tag_val(self, tag_name):
         """
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 1ca32ecf25..10317b232b 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -17,7 +17,7 @@
 from avocado import skipUnless
 from avocado_qemu import Test
 from avocado_qemu import exec_command_and_wait_for_pattern
-from avocado_qemu import interrupt_interactive_console_until_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado_qemu import wait_for_console_pattern
 from avocado.utils import process
 from avocado.utils import archive
@@ -45,7 +45,7 @@ def image_pow2ceil_expand(path):
             with open(path, 'ab+') as fd:
                 fd.truncate(size_aligned)
 
-class LinuxKernelTest(Test):
+class LinuxKernelTest(Test, ConsoleMixIn):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
 
     def wait_for_console_pattern(self, success_message, vm=None):
@@ -626,8 +626,8 @@ def test_arm_quanta_gsj(self):
         self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
         self.wait_for_console_pattern('>Skip DDR init.')
         self.wait_for_console_pattern('U-Boot ')
-        interrupt_interactive_console_until_pattern(
-                self, 'Hit any key to stop autoboot:', 'U-Boot>')
+        self.interrupt_interactive_console_until_pattern(
+                'Hit any key to stop autoboot:', 'U-Boot>')
         exec_command_and_wait_for_pattern(
                 self, "setenv bootargs ${bootargs} " + kernel_command_line,
                 'U-Boot>')
@@ -879,7 +879,7 @@ def test_arm_orangepi_uboot_netbsd9(self):
                          '-no-reboot')
         self.vm.launch()
         wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
-        interrupt_interactive_console_until_pattern(self,
+        self.interrupt_interactive_console_until_pattern(
                                        'Hit any key to stop autoboot:',
                                        'switch to partitions #0, OK')
 
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn
  2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
  2021-05-03 22:43 ` [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class Wainer dos Santos Moschetta
@ 2021-05-03 22:43 ` Wainer dos Santos Moschetta
  2021-05-24 18:16   ` Willian Rampazzo
  2021-05-03 22:43 ` [PATCH 3/7] tests/acceptance: Move exec_command_and_wait_for_pattern " Wainer dos Santos Moschetta
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Wainer dos Santos Moschetta @ 2021-05-03 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: willianr, philmd, crosa

This moved exec_command() to ConsoleMixIn class.

Only the multiprocess.py file were touched by that change, so its tests
were adapted.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py | 22 ++++++++++------------
 tests/acceptance/multiprocess.py          |  6 +++---
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 6f4e0edfa3..4d3b869765 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -114,18 +114,6 @@ def wait_for_console_pattern(test, success_message, failure_message=None,
     """
     _console_interaction(test, success_message, failure_message, None, vm=vm)
 
-def exec_command(test, command):
-    """
-    Send a command to a console (appending CRLF characters), while logging
-    the content.
-
-    :param test: an Avocado test containing a VM.
-    :type test: :class:`avocado_qemu.Test`
-    :param command: the command to send
-    :type command: str
-    """
-    _console_interaction(test, None, None, command + '\r')
-
 def exec_command_and_wait_for_pattern(test, command,
                                       success_message, failure_message=None):
     """
@@ -145,6 +133,16 @@ def exec_command_and_wait_for_pattern(test, command,
 class ConsoleMixIn():
     """Contains utilities for interacting with a guest via Console."""
 
+    def exec_command(self, command):
+        """
+        Send a command to a console (appending CRLF characters), while logging
+        the content.
+
+        :param command: the command to send
+        :type command: str
+        """
+        _console_interaction(self, None, None, command + '\r')
+
     def interrupt_interactive_console_until_pattern(self, success_message,
                                                     failure_message=None,
                                                     interrupt_string='\r'):
diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
index 96627f022a..41d3e51164 100644
--- a/tests/acceptance/multiprocess.py
+++ b/tests/acceptance/multiprocess.py
@@ -9,10 +9,10 @@
 
 from avocado_qemu import Test
 from avocado_qemu import wait_for_console_pattern
-from avocado_qemu import exec_command
+from avocado_qemu import ConsoleMixIn
 from avocado_qemu import exec_command_and_wait_for_pattern
 
-class Multiprocess(Test):
+class Multiprocess(Test, ConsoleMixIn):
     """
     :avocado: tags=multiprocess
     """
@@ -59,7 +59,7 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line,
         self.vm.launch()
         wait_for_console_pattern(self, 'as init process',
                                  'Kernel panic - not syncing')
-        exec_command(self, 'mount -t sysfs sysfs /sys')
+        self.exec_command('mount -t sysfs sysfs /sys')
         exec_command_and_wait_for_pattern(self,
                                           'cat /sys/bus/pci/devices/*/uevent',
                                           'PCI_ID=1000:0012')
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/7] tests/acceptance: Move exec_command_and_wait_for_pattern to ConsoleMixIn
  2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
  2021-05-03 22:43 ` [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class Wainer dos Santos Moschetta
  2021-05-03 22:43 ` [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn Wainer dos Santos Moschetta
@ 2021-05-03 22:43 ` Wainer dos Santos Moschetta
  2021-05-24 18:21   ` Willian Rampazzo
  2021-05-03 22:43 ` [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest Wainer dos Santos Moschetta
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Wainer dos Santos Moschetta @ 2021-05-03 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: willianr, philmd, crosa

It was the time of exec_command_and_wait_for_pattern() to find a new
home at ConsoleMixIn. This time various tests needed to be adapted.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py   |  29 +++---
 tests/acceptance/boot_linux_console.py      | 107 ++++++++++----------
 tests/acceptance/machine_rx_gdbsim.py       |   8 +-
 tests/acceptance/machine_s390_ccw_virtio.py |  72 ++++++-------
 tests/acceptance/multiprocess.py            |   3 +-
 tests/acceptance/virtio-gpu.py              |  12 +--
 6 files changed, 111 insertions(+), 120 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 4d3b869765..4a0129c0eb 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -114,22 +114,6 @@ def wait_for_console_pattern(test, success_message, failure_message=None,
     """
     _console_interaction(test, success_message, failure_message, None, vm=vm)
 
-def exec_command_and_wait_for_pattern(test, command,
-                                      success_message, failure_message=None):
-    """
-    Send a command to a console (appending CRLF characters), then wait
-    for success_message to appear on the console, while logging the.
-    content. Mark the test as failed if failure_message is found instead.
-
-    :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 command: the command to send
-    :param success_message: if this message appears, test succeeds
-    :param failure_message: if this message appears, test fails
-    """
-    _console_interaction(test, success_message, failure_message, command + '\r')
-
 class ConsoleMixIn():
     """Contains utilities for interacting with a guest via Console."""
 
@@ -143,6 +127,19 @@ def exec_command(self, command):
         """
         _console_interaction(self, None, None, command + '\r')
 
+    def exec_command_and_wait_for_pattern(self, command,
+                                          success_message, failure_message=None):
+        """
+        Send a command to a console (appending CRLF characters), then wait
+        for success_message to appear on the console, while logging the.
+        content. Mark the test as failed if failure_message is found instead.
+
+        :param command: the command to send
+        :param success_message: if this message appears, test succeeds
+        :param failure_message: if this message appears, test fails
+        """
+        _console_interaction(self, success_message, failure_message, command + '\r')
+
     def interrupt_interactive_console_until_pattern(self, success_message,
                                                     failure_message=None,
                                                     interrupt_string='\r'):
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 10317b232b..50e0a3fe79 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -16,7 +16,6 @@
 from avocado import skip
 from avocado import skipUnless
 from avocado_qemu import Test
-from avocado_qemu import exec_command_and_wait_for_pattern
 from avocado_qemu import ConsoleMixIn
 from avocado_qemu import wait_for_console_pattern
 from avocado.utils import process
@@ -223,12 +222,12 @@ def test_mips_malta_cpio(self):
         self.vm.launch()
         self.wait_for_console_pattern('Boot successful.')
 
-        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
-                                                'BogoMIPS')
-        exec_command_and_wait_for_pattern(self, 'uname -a',
-                                                'Debian')
-        exec_command_and_wait_for_pattern(self, 'reboot',
-                                                'reboot: Restarting system')
+        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
+                                               'BogoMIPS')
+        self.exec_command_and_wait_for_pattern('uname -a',
+                                               'Debian')
+        self.exec_command_and_wait_for_pattern('reboot',
+                                               'reboot: Restarting system')
         # Wait for VM to shut down gracefully
         self.vm.wait()
 
@@ -265,12 +264,12 @@ def test_mips64el_malta_5KEc_cpio(self):
         self.vm.launch()
         wait_for_console_pattern(self, 'Boot successful.')
 
-        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
-                                                'MIPS 5KE')
-        exec_command_and_wait_for_pattern(self, 'uname -a',
-                                                '3.19.3.mtoman.20150408')
-        exec_command_and_wait_for_pattern(self, 'reboot',
-                                                'reboot: Restarting system')
+        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
+                                               'MIPS 5KE')
+        self.exec_command_and_wait_for_pattern('uname -a',
+                                               '3.19.3.mtoman.20150408')
+        self.exec_command_and_wait_for_pattern('reboot',
+                                               'reboot: Restarting system')
         # Wait for VM to shut down gracefully
         self.vm.wait()
 
@@ -422,9 +421,9 @@ def test_arm_emcraft_sf2(self):
         self.vm.launch()
         self.wait_for_console_pattern('Enter \'help\' for a list')
 
-        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15',
-                                                 'eth0: link becomes ready')
-        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
+        self.exec_command_and_wait_for_pattern('ifconfig eth0 10.0.2.15',
+                                               'eth0: link becomes ready')
+        self.exec_command_and_wait_for_pattern('ping -c 3 10.0.2.2',
             '3 packets transmitted, 3 packets received, 0% packet loss')
 
     def do_test_arm_raspi2(self, uart_id):
@@ -541,10 +540,10 @@ def test_arm_cubieboard_initrd(self):
         self.vm.launch()
         self.wait_for_console_pattern('Boot successful.')
 
-        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
-                                                'Allwinner sun4i/sun5i')
-        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
-                                                'system-control@1c00000')
+        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
+                                               'Allwinner sun4i/sun5i')
+        self.exec_command_and_wait_for_pattern('cat /proc/iomem',
+                                               'system-control@1c00000')
         # cubieboard's reboot is not functioning; omit reboot test.
 
     def test_arm_cubieboard_sata(self):
@@ -584,10 +583,10 @@ def test_arm_cubieboard_sata(self):
         self.vm.launch()
         self.wait_for_console_pattern('Boot successful.')
 
-        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
-                                                'Allwinner sun4i/sun5i')
-        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
-                                                'sda')
+        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
+                                               'Allwinner sun4i/sun5i')
+        self.exec_command_and_wait_for_pattern('cat /proc/partitions',
+                                               'sda')
         # cubieboard's reboot is not functioning; omit reboot test.
 
     @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
@@ -628,11 +627,11 @@ def test_arm_quanta_gsj(self):
         self.wait_for_console_pattern('U-Boot ')
         self.interrupt_interactive_console_until_pattern(
                 'Hit any key to stop autoboot:', 'U-Boot>')
-        exec_command_and_wait_for_pattern(
-                self, "setenv bootargs ${bootargs} " + kernel_command_line,
+        self.exec_command_and_wait_for_pattern(
+                "setenv bootargs ${bootargs} " + kernel_command_line,
                 'U-Boot>')
-        exec_command_and_wait_for_pattern(
-                self, 'run romboot', 'Booting Kernel from flash')
+        self.exec_command_and_wait_for_pattern(
+                'run romboot', 'Booting Kernel from flash')
         self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
         self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
         self.wait_for_console_pattern('OpenBMC Project Reference Distro')
@@ -732,12 +731,12 @@ def test_arm_orangepi_initrd(self):
         self.vm.launch()
         self.wait_for_console_pattern('Boot successful.')
 
-        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
-                                                'Allwinner sun8i Family')
-        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
-                                                'system-control@1c00000')
-        exec_command_and_wait_for_pattern(self, 'reboot',
-                                                'reboot: Restarting system')
+        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
+                                               'Allwinner sun8i Family')
+        self.exec_command_and_wait_for_pattern('cat /proc/iomem',
+                                               'system-control@1c00000')
+        self.exec_command_and_wait_for_pattern('reboot',
+                                               'reboot: Restarting system')
         # Wait for VM to shut down gracefully
         self.vm.wait()
 
@@ -777,18 +776,18 @@ def test_arm_orangepi_sd(self):
         shell_ready = "/bin/sh: can't access tty; job control turned off"
         self.wait_for_console_pattern(shell_ready)
 
-        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
-                                                'Allwinner sun8i Family')
-        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
-                                                'mmcblk0')
-        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up',
-                                                 'eth0: Link is Up')
-        exec_command_and_wait_for_pattern(self, 'udhcpc eth0',
+        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
+                                               'Allwinner sun8i Family')
+        self.exec_command_and_wait_for_pattern('cat /proc/partitions',
+                                               'mmcblk0')
+        self.exec_command_and_wait_for_pattern('ifconfig eth0 up',
+                                               'eth0: Link is Up')
+        self.exec_command_and_wait_for_pattern('udhcpc eth0',
             'udhcpc: lease of 10.0.2.15 obtained')
-        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
+        self.exec_command_and_wait_for_pattern('ping -c 3 10.0.2.2',
             '3 packets transmitted, 3 packets received, 0% packet loss')
-        exec_command_and_wait_for_pattern(self, 'reboot',
-                                                'reboot: Restarting system')
+        self.exec_command_and_wait_for_pattern('reboot',
+                                               'reboot: Restarting system')
         # Wait for VM to shut down gracefully
         self.vm.wait()
 
@@ -829,10 +828,10 @@ def test_arm_orangepi_bionic_20_08(self):
 
         self.wait_for_console_pattern('U-Boot SPL')
         self.wait_for_console_pattern('Autoboot in ')
-        exec_command_and_wait_for_pattern(self, ' ', '=>')
-        exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
-                                                kernel_command_line + "'", '=>')
-        exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...');
+        self.exec_command_and_wait_for_pattern(' ', '=>')
+        self.exec_command_and_wait_for_pattern("setenv extraargs '" +
+                                               kernel_command_line + "'", '=>')
+        self.exec_command_and_wait_for_pattern('boot', 'Starting kernel ...');
 
         self.wait_for_console_pattern('systemd[1]: Set hostname ' +
                                       'to <orangepipc>')
@@ -883,20 +882,20 @@ def test_arm_orangepi_uboot_netbsd9(self):
                                        'Hit any key to stop autoboot:',
                                        'switch to partitions #0, OK')
 
-        exec_command_and_wait_for_pattern(self, '', '=>')
+        self.exec_command_and_wait_for_pattern('', '=>')
         cmd = 'setenv bootargs root=ld0a'
-        exec_command_and_wait_for_pattern(self, cmd, '=>')
+        self.exec_command_and_wait_for_pattern(cmd, '=>')
         cmd = 'setenv kernel netbsd-GENERIC.ub'
-        exec_command_and_wait_for_pattern(self, cmd, '=>')
+        self.exec_command_and_wait_for_pattern(cmd, '=>')
         cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb'
-        exec_command_and_wait_for_pattern(self, cmd, '=>')
+        self.exec_command_and_wait_for_pattern(cmd, '=>')
         cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; "
                "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; "
                "fdt addr ${fdt_addr_r}; "
                "bootm ${kernel_addr_r} - ${fdt_addr_r}'")
-        exec_command_and_wait_for_pattern(self, cmd, '=>')
+        self.exec_command_and_wait_for_pattern(cmd, '=>')
 
-        exec_command_and_wait_for_pattern(self, 'boot',
+        self.exec_command_and_wait_for_pattern('boot',
                                           'Booting kernel from Legacy Image')
         wait_for_console_pattern(self, 'Starting kernel ...')
         wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
diff --git a/tests/acceptance/machine_rx_gdbsim.py b/tests/acceptance/machine_rx_gdbsim.py
index 32b737b6d8..a893273bad 100644
--- a/tests/acceptance/machine_rx_gdbsim.py
+++ b/tests/acceptance/machine_rx_gdbsim.py
@@ -12,12 +12,12 @@
 
 from avocado import skipIf
 from avocado_qemu import Test
-from avocado_qemu import exec_command_and_wait_for_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado_qemu import wait_for_console_pattern
 from avocado.utils import archive
 
 
-class RxGdbSimMachine(Test):
+class RxGdbSimMachine(Test, ConsoleMixIn):
 
     timeout = 30
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -44,7 +44,7 @@ def test_uboot(self):
         wait_for_console_pattern(self, uboot_version)
         gcc_version = 'rx-unknown-linux-gcc (GCC) 9.0.0 20181105 (experimental)'
         # FIXME limit baudrate on chardev, else we type too fast
-        #exec_command_and_wait_for_pattern(self, 'version', gcc_version)
+        #self.exec_command_and_wait_for_pattern('version', gcc_version)
 
     @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
     def test_linux_sash(self):
@@ -70,4 +70,4 @@ def test_linux_sash(self):
         self.vm.launch()
         wait_for_console_pattern(self, 'Sash command shell (version 1.1.1)',
                                  failure_message='Kernel panic - not syncing')
-        exec_command_and_wait_for_pattern(self, 'printenv', 'TERM=linux')
+        self.exec_command_and_wait_for_pattern('printenv', 'TERM=linux')
diff --git a/tests/acceptance/machine_s390_ccw_virtio.py b/tests/acceptance/machine_s390_ccw_virtio.py
index 4028c99afc..537393c42f 100644
--- a/tests/acceptance/machine_s390_ccw_virtio.py
+++ b/tests/acceptance/machine_s390_ccw_virtio.py
@@ -14,11 +14,11 @@
 
 from avocado import skipIf
 from avocado_qemu import Test
-from avocado_qemu import exec_command_and_wait_for_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado_qemu import wait_for_console_pattern
 from avocado.utils import archive
 
-class S390CCWVirtioMachine(Test):
+class S390CCWVirtioMachine(Test, ConsoleMixIn):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
 
     timeout = 120
@@ -29,13 +29,13 @@ def wait_for_console_pattern(self, success_message, vm=None):
                                  vm=vm)
 
     def wait_for_crw_reports(self):
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'while ! (dmesg -c | grep CRW) ; do sleep 1 ; done',
                         'CRW reports')
 
     dmesg_clear_count = 1
     def clear_guest_dmesg(self):
-        exec_command_and_wait_for_pattern(self, 'dmesg -c > /dev/null; '
+        self.exec_command_and_wait_for_pattern('dmesg -c > /dev/null; '
                     'echo dm_clear\ ' + str(self.dmesg_clear_count),
                     'dm_clear ' + str(self.dmesg_clear_count))
         self.dmesg_clear_count += 1
@@ -81,13 +81,13 @@ def test_s390x_devices(self):
         shell_ready = "sh: can't access tty; job control turned off"
         self.wait_for_console_pattern(shell_ready)
         # first debug shell is too early, we need to wait for device detection
-        exec_command_and_wait_for_pattern(self, 'exit', shell_ready)
+        self.exec_command_and_wait_for_pattern('exit', shell_ready)
 
         ccw_bus_ids="0.1.1111  0.2.0000  0.3.1234"
         pci_bus_ids="0005:00:00.0  000a:00:00.0"
-        exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/',
+        self.exec_command_and_wait_for_pattern('ls /sys/bus/ccw/devices/',
                                           ccw_bus_ids)
-        exec_command_and_wait_for_pattern(self, 'ls /sys/bus/pci/devices/',
+        self.exec_command_and_wait_for_pattern('ls /sys/bus/pci/devices/',
                                           pci_bus_ids)
         # check that the device at 0.2.0000 is in legacy mode, while the
         # device at 0.3.1234 has the virtio-1 feature bit set
@@ -95,14 +95,14 @@ def test_s390x_devices(self):
                             "10000000000000000000000000000000"
         virtio_rng_features_legacy="00000000000000000000000000001100" + \
                                    "00000000000000000000000000000000"
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'cat /sys/bus/ccw/devices/0.2.0000/virtio?/features',
                         virtio_rng_features_legacy)
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'cat /sys/bus/ccw/devices/0.3.1234/virtio?/features',
                         virtio_rng_features)
         # check that /dev/hwrng works - and that it's gone after ejecting
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'dd if=/dev/hwrng of=/dev/null bs=1k count=10',
                         '10+0 records out')
         self.clear_guest_dmesg()
@@ -111,22 +111,22 @@ def test_s390x_devices(self):
         self.clear_guest_dmesg()
         self.vm.command('device_del', id='rn2')
         self.wait_for_crw_reports()
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'dd if=/dev/hwrng of=/dev/null bs=1k count=10',
                         'dd: /dev/hwrng: No such device')
         # verify that we indeed have virtio-net devices (without having the
         # virtio-net driver handy)
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                                     'cat /sys/bus/ccw/devices/0.1.1111/cutype',
                                     '3832/01')
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                     'cat /sys/bus/pci/devices/0005\:00\:00.0/subsystem_vendor',
                     '0x1af4')
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                     'cat /sys/bus/pci/devices/0005\:00\:00.0/subsystem_device',
                     '0x0001')
         # check fid propagation
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id',
                         '0x0000000c')
         # add another device
@@ -134,7 +134,7 @@ def test_s390x_devices(self):
         self.vm.command('device_add', driver='virtio-net-ccw',
                         devno='fe.0.4711', id='net_4711')
         self.wait_for_crw_reports()
-        exec_command_and_wait_for_pattern(self, 'for i in 1 2 3 4 5 6 7 ; do '
+        self.exec_command_and_wait_for_pattern('for i in 1 2 3 4 5 6 7 ; do '
                     'if [ -e /sys/bus/ccw/devices/*4711 ]; then break; fi ;'
                     'sleep 1 ; done ; ls /sys/bus/ccw/devices/',
                     '0.0.4711')
@@ -144,17 +144,17 @@ def test_s390x_devices(self):
         self.vm.event_wait(name='DEVICE_DELETED',
                            match={'data': {'device': 'net_4711'}})
         self.wait_for_crw_reports()
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                                           'ls /sys/bus/ccw/devices/0.0.4711',
                                           'No such file or directory')
         # test the virtio-balloon device
-        exec_command_and_wait_for_pattern(self, 'head -n 1 /proc/meminfo',
+        self.exec_command_and_wait_for_pattern('head -n 1 /proc/meminfo',
                                           'MemTotal:         115640 kB')
         self.vm.command('human-monitor-command', command_line='balloon 96')
-        exec_command_and_wait_for_pattern(self, 'head -n 1 /proc/meminfo',
+        self.exec_command_and_wait_for_pattern('head -n 1 /proc/meminfo',
                                           'MemTotal:          82872 kB')
         self.vm.command('human-monitor-command', command_line='balloon 128')
-        exec_command_and_wait_for_pattern(self, 'head -n 1 /proc/meminfo',
+        self.exec_command_and_wait_for_pattern('head -n 1 /proc/meminfo',
                                           'MemTotal:         115640 kB')
 
 
@@ -203,23 +203,23 @@ def test_s390x_fedora(self):
 
         # Some tests to see whether the CLI options have been considered:
         self.log.info("Test whether QEMU CLI options have been considered")
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'while ! (dmesg | grep enP7p0s0) ; do sleep 1 ; done',
                         'virtio_net virtio0 enP7p0s0: renamed')
-        exec_command_and_wait_for_pattern(self, 'lspci',
+        self.exec_command_and_wait_for_pattern('lspci',
                              '0007:00:00.0 Class 0200: Device 1af4:1000')
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                              'cat /sys/class/net/enP7p0s0/address',
                              '02:ca:fe:fa:ce:12')
-        exec_command_and_wait_for_pattern(self, 'lscss', '0.1.9876')
-        exec_command_and_wait_for_pattern(self, 'lscss', '0.2.5432')
-        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
+        self.exec_command_and_wait_for_pattern('lscss', '0.1.9876')
+        self.exec_command_and_wait_for_pattern('lscss', '0.2.5432')
+        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
                              'processors    : 4')
-        exec_command_and_wait_for_pattern(self, 'grep MemTotal /proc/meminfo',
+        self.exec_command_and_wait_for_pattern('grep MemTotal /proc/meminfo',
                              'MemTotal:         499848 kB')
-        exec_command_and_wait_for_pattern(self, 'grep Name /proc/sysinfo',
+        self.exec_command_and_wait_for_pattern('grep Name /proc/sysinfo',
                              'Extended Name:   Some Guest Name')
-        exec_command_and_wait_for_pattern(self, 'grep UUID /proc/sysinfo',
+        self.exec_command_and_wait_for_pattern('grep UUID /proc/sysinfo',
                              '30de4fd9-b4d5-409e-86a5-09b387f70bfa')
 
         # Disable blinking cursor, then write some stuff into the framebuffer.
@@ -229,16 +229,16 @@ def test_s390x_fedora(self):
         # can simply read the written "magic bytes" back from the PPM file to
         # check whether the framebuffer is working as expected.
         self.log.info("Test screendump of virtio-gpu device")
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'while ! (dmesg | grep gpudrmfb) ; do sleep 1 ; done',
                         'virtio_gpudrmfb frame buffer device')
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
             'echo -e "\e[?25l" > /dev/tty0', ':/#')
-        exec_command_and_wait_for_pattern(self, 'for ((i=0;i<250;i++)); do '
+        self.exec_command_and_wait_for_pattern('for ((i=0;i<250;i++)); do '
             'echo " The  qu ick  fo x j ump s o ver  a  laz y d og" >> fox.txt;'
             'done',
             ':/#')
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
             'dd if=fox.txt of=/dev/fb0 bs=1000 oflag=sync,nocache ; rm fox.txt',
             '12+0 records out')
         with tempfile.NamedTemporaryFile(suffix='.ppm',
@@ -261,12 +261,12 @@ def test_s390x_fedora(self):
                         id='cbe0')
         self.vm.command('device_add', driver='virtio-crypto-ccw', id='crypdev0',
                         cryptodev='cbe0', devno='fe.0.2342')
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'while ! (dmesg -c | grep Accelerator.device) ; do'
                         ' sleep 1 ; done', 'Accelerator device is ready')
-        exec_command_and_wait_for_pattern(self, 'lscss', '0.0.2342')
+        self.exec_command_and_wait_for_pattern('lscss', '0.0.2342')
         self.vm.command('device_del', id='crypdev0')
         self.vm.command('object-del', id='cbe0')
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                         'while ! (dmesg -c | grep Start.virtcrypto_remove) ; do'
                         ' sleep 1 ; done', 'Start virtcrypto_remove.')
diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
index 41d3e51164..b4a6d20770 100644
--- a/tests/acceptance/multiprocess.py
+++ b/tests/acceptance/multiprocess.py
@@ -10,7 +10,6 @@
 from avocado_qemu import Test
 from avocado_qemu import wait_for_console_pattern
 from avocado_qemu import ConsoleMixIn
-from avocado_qemu import exec_command_and_wait_for_pattern
 
 class Multiprocess(Test, ConsoleMixIn):
     """
@@ -60,7 +59,7 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line,
         wait_for_console_pattern(self, 'as init process',
                                  'Kernel panic - not syncing')
         self.exec_command('mount -t sysfs sysfs /sys')
-        exec_command_and_wait_for_pattern(self,
+        self.exec_command_and_wait_for_pattern(
                                           'cat /sys/bus/pci/devices/*/uevent',
                                           'PCI_ID=1000:0012')
 
diff --git a/tests/acceptance/virtio-gpu.py b/tests/acceptance/virtio-gpu.py
index ab18cddbb7..4d65431ef1 100644
--- a/tests/acceptance/virtio-gpu.py
+++ b/tests/acceptance/virtio-gpu.py
@@ -7,7 +7,7 @@
 from avocado_qemu import Test
 from avocado_qemu import BUILD_DIR
 from avocado_qemu import wait_for_console_pattern
-from avocado_qemu import exec_command_and_wait_for_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado_qemu import is_readable_executable_file
 
 from qemu.accel import kvm_available
@@ -31,7 +31,7 @@ def pick_default_vug_bin():
         return bld_dir_path
 
 
-class VirtioGPUx86(Test):
+class VirtioGPUx86(Test, ConsoleMixIn):
     """
     :avocado: tags=virtio-gpu
     """
@@ -92,9 +92,7 @@ def test_virtio_vga_virgl(self):
             self.cancel("VirGL not enabled?")
 
         self.wait_for_console_pattern("as init process")
-        exec_command_and_wait_for_pattern(
-            self, "/usr/sbin/modprobe virtio_gpu", ""
-        )
+        self.exec_command_and_wait_for_pattern("/usr/sbin/modprobe virtio_gpu", "")
         self.wait_for_console_pattern("features: +virgl +edid")
 
     def test_vhost_user_vga_virgl(self):
@@ -157,9 +155,7 @@ def test_vhost_user_vga_virgl(self):
         )
         self.vm.launch()
         self.wait_for_console_pattern("as init process")
-        exec_command_and_wait_for_pattern(
-            self, "/usr/sbin/modprobe virtio_gpu", ""
-        )
+        self.exec_command_and_wait_for_pattern("/usr/sbin/modprobe virtio_gpu", "")
         self.wait_for_console_pattern("features: +virgl -edid")
         self.vm.shutdown()
         qemu_sock.close()
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest
  2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
                   ` (2 preceding siblings ...)
  2021-05-03 22:43 ` [PATCH 3/7] tests/acceptance: Move exec_command_and_wait_for_pattern " Wainer dos Santos Moschetta
@ 2021-05-03 22:43 ` Wainer dos Santos Moschetta
  2021-05-04 16:01   ` Philippe Mathieu-Daudé
  2021-05-24 18:24   ` Willian Rampazzo
  2021-05-03 22:43 ` [PATCH 5/7] tests/acceptance: replay_kernel: Remove unused wait_for_console_pattern Wainer dos Santos Moschetta
                   ` (3 subsequent siblings)
  7 siblings, 2 replies; 19+ messages in thread
From: Wainer dos Santos Moschetta @ 2021-05-03 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: willianr, philmd, crosa

The Sun4uMachine class inherit from LinuxKernelTest to effectively only use
the KERNEL_COMMON_COMMAND_LINE attribute. This change remove that unneeded
dependency, making Sun4uMachine self-content.

I took the occasion to delint the code: the unused os import was
removed, imports were reordered, and the module has a docstring now.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tests/acceptance/machine_sparc64_sun4u.py | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/tests/acceptance/machine_sparc64_sun4u.py b/tests/acceptance/machine_sparc64_sun4u.py
index 458165500e..c7ad474bdc 100644
--- a/tests/acceptance/machine_sparc64_sun4u.py
+++ b/tests/acceptance/machine_sparc64_sun4u.py
@@ -1,4 +1,4 @@
-# Functional test that boots a Linux kernel and checks the console
+"""Functional test that boots a Linux kernel and checks the console"""
 #
 # Copyright (c) 2020 Red Hat, Inc.
 #
@@ -8,16 +8,15 @@
 # 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
-
-from avocado_qemu import wait_for_console_pattern
 from avocado.utils import archive
-from boot_linux_console import LinuxKernelTest
+from avocado_qemu import Test
+from avocado_qemu import wait_for_console_pattern
 
-class Sun4uMachine(LinuxKernelTest):
+class Sun4uMachine(Test):
     """Boots the Linux kernel and checks that the console is operational"""
 
     timeout = 90
+    KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
 
     def test_sparc64_sun4u(self):
         """
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 5/7] tests/acceptance: replay_kernel: Remove unused wait_for_console_pattern
  2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
                   ` (3 preceding siblings ...)
  2021-05-03 22:43 ` [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest Wainer dos Santos Moschetta
@ 2021-05-03 22:43 ` Wainer dos Santos Moschetta
  2021-05-24 18:32   ` Willian Rampazzo
  2021-05-03 22:43 ` [PATCH 6/7] tests/acceptance: Move wait_for_console_pattern to ConsoleMixIn Wainer dos Santos Moschetta
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Wainer dos Santos Moschetta @ 2021-05-03 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: willianr, philmd, crosa

The ReplayKernelBase class uses the wait_for_console_pattern from its
parent LinuxKernelTest class, thus it doesn't need to import that method
from avocado_qemu.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tests/acceptance/replay_kernel.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tests/acceptance/replay_kernel.py b/tests/acceptance/replay_kernel.py
index 71facdaa75..6d4e202723 100644
--- a/tests/acceptance/replay_kernel.py
+++ b/tests/acceptance/replay_kernel.py
@@ -17,7 +17,6 @@
 from avocado import skip
 from avocado import skipIf
 from avocado import skipUnless
-from avocado_qemu import wait_for_console_pattern
 from avocado.utils import archive
 from avocado.utils import process
 from boot_linux_console import LinuxKernelTest
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 6/7] tests/acceptance: Move wait_for_console_pattern to ConsoleMixIn
  2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
                   ` (4 preceding siblings ...)
  2021-05-03 22:43 ` [PATCH 5/7] tests/acceptance: replay_kernel: Remove unused wait_for_console_pattern Wainer dos Santos Moschetta
@ 2021-05-03 22:43 ` Wainer dos Santos Moschetta
  2021-05-24 20:52   ` Willian Rampazzo
  2021-05-03 22:43 ` [PATCH 7/7] tests/acceptance: Move _console_interaction " Wainer dos Santos Moschetta
  2021-05-24 20:58 ` [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Willian Rampazzo
  7 siblings, 1 reply; 19+ messages in thread
From: Wainer dos Santos Moschetta @ 2021-05-03 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: willianr, philmd, crosa

This moved wait_for_console_pattern() to ConsoleMixIn.

By far this change required the most adaptations on tests.

Notice that:

 1) Some tests from boot_linux_console.py were using the wait_for_console_pattern()
    from the avocado_qemu package rather than the overloaded method on the
    LinuxKernelTest class, and that explains the explict calls to
    ConsoleMixIn.wait_for_console_pattern().

    Likewise in boot_xen.py file.

 2) In virtiofs_submounts.py, wait_for_console_pattern() was imported but not used.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py    | 23 +++++++++-----------
 tests/acceptance/boot_linux_console.py       | 14 ++++++------
 tests/acceptance/boot_xen.py                 |  5 +++--
 tests/acceptance/linux_ssh_mips_malta.py     |  8 +++----
 tests/acceptance/machine_arm_canona1100.py   |  6 ++---
 tests/acceptance/machine_arm_integratorcp.py |  8 +++----
 tests/acceptance/machine_arm_n8x0.py         |  6 ++---
 tests/acceptance/machine_microblaze.py       |  8 +++----
 tests/acceptance/machine_mips_loongson3v.py  |  6 ++---
 tests/acceptance/machine_mips_malta.py       |  6 ++---
 tests/acceptance/machine_ppc.py              | 10 ++++-----
 tests/acceptance/machine_rx_gdbsim.py        |  7 +++---
 tests/acceptance/machine_s390_ccw_virtio.py  |  7 +++---
 tests/acceptance/machine_sparc64_sun4u.py    |  6 ++---
 tests/acceptance/machine_sparc_leon3.py      |  8 +++----
 tests/acceptance/multiprocess.py             |  5 ++---
 tests/acceptance/ppc_prep_40p.py             | 16 +++++++-------
 tests/acceptance/virtio-gpu.py               |  4 +---
 tests/acceptance/virtiofs_submounts.py       |  1 -
 19 files changed, 73 insertions(+), 81 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index 4a0129c0eb..b21f9ea3ff 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -101,19 +101,6 @@ def _console_interaction(test, success_message, failure_message,
                     (failure_message, success_message)
             test.fail(fail)
 
-def wait_for_console_pattern(test, success_message, failure_message=None,
-                             vm=None):
-    """
-    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_interaction(test, success_message, failure_message, None, vm=vm)
-
 class ConsoleMixIn():
     """Contains utilities for interacting with a guest via Console."""
 
@@ -163,6 +150,16 @@ def interrupt_interactive_console_until_pattern(self, success_message,
         _console_interaction(self, success_message, failure_message,
                          interrupt_string, True)
 
+    def wait_for_console_pattern(self, success_message, failure_message=None,
+                             vm=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_interaction(self, success_message, failure_message, None, vm=vm)
+
 class Test(avocado.Test):
     def _get_unique_tag_val(self, tag_name):
         """
diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
index 50e0a3fe79..e8d7a127fe 100644
--- a/tests/acceptance/boot_linux_console.py
+++ b/tests/acceptance/boot_linux_console.py
@@ -17,7 +17,6 @@
 from avocado import skipUnless
 from avocado_qemu import Test
 from avocado_qemu import ConsoleMixIn
-from avocado_qemu import wait_for_console_pattern
 from avocado.utils import process
 from avocado.utils import archive
 from avocado.utils.path import find_command, CmdNotFoundError
@@ -48,7 +47,7 @@ class LinuxKernelTest(Test, ConsoleMixIn):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
 
     def wait_for_console_pattern(self, success_message, vm=None):
-        wait_for_console_pattern(self, success_message,
+        super().wait_for_console_pattern(success_message,
                                  failure_message='Kernel panic - not syncing',
                                  vm=vm)
 
@@ -262,7 +261,7 @@ def test_mips64el_malta_5KEc_cpio(self):
                          '-append', kernel_command_line,
                          '-no-reboot')
         self.vm.launch()
-        wait_for_console_pattern(self, 'Boot successful.')
+        ConsoleMixIn.wait_for_console_pattern(self, 'Boot successful.')
 
         self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
                                                'MIPS 5KE')
@@ -877,7 +876,7 @@ def test_arm_orangepi_uboot_netbsd9(self):
                          '-global', 'allwinner-rtc.base-year=2000',
                          '-no-reboot')
         self.vm.launch()
-        wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
+        ConsoleMixIn.wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
         self.interrupt_interactive_console_until_pattern(
                                        'Hit any key to stop autoboot:',
                                        'switch to partitions #0, OK')
@@ -897,10 +896,11 @@ def test_arm_orangepi_uboot_netbsd9(self):
 
         self.exec_command_and_wait_for_pattern('boot',
                                           'Booting kernel from Legacy Image')
-        wait_for_console_pattern(self, 'Starting kernel ...')
-        wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
+        ConsoleMixIn.wait_for_console_pattern(self, 'Starting kernel ...')
+        ConsoleMixIn.wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
         # Wait for user-space
-        wait_for_console_pattern(self, 'Starting root file system check')
+        ConsoleMixIn.wait_for_console_pattern(self,
+                                            'Starting root file system check')
 
     def test_aarch64_raspi3_atf(self):
         """
diff --git a/tests/acceptance/boot_xen.py b/tests/acceptance/boot_xen.py
index 75c2d44492..9b5506398e 100644
--- a/tests/acceptance/boot_xen.py
+++ b/tests/acceptance/boot_xen.py
@@ -14,7 +14,6 @@
 import os
 
 from avocado import skipIf
-from avocado_qemu import wait_for_console_pattern
 from boot_linux_console import LinuxKernelTest
 
 
@@ -59,7 +58,9 @@ def launch_xen(self, xen_path):
         self.vm.launch()
 
         console_pattern = 'VFS: Cannot open root device'
-        wait_for_console_pattern(self, console_pattern, "Panic on CPU 0:")
+        # pylint: disable=E1003
+        super(LinuxKernelTest, self).wait_for_console_pattern(console_pattern,
+            "Panic on CPU 0:")
 
 
 class BootXen(BootXenBase):
diff --git a/tests/acceptance/linux_ssh_mips_malta.py b/tests/acceptance/linux_ssh_mips_malta.py
index 6dbd02d49d..8d8531b6c5 100644
--- a/tests/acceptance/linux_ssh_mips_malta.py
+++ b/tests/acceptance/linux_ssh_mips_malta.py
@@ -13,13 +13,13 @@
 
 from avocado import skipUnless
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado.utils import process
 from avocado.utils import archive
 from avocado.utils import ssh
 
 
-class LinuxSSH(Test):
+class LinuxSSH(Test, ConsoleMixIn):
 
     timeout = 150 # Not for 'configure --enable-debug --enable-debug-tcg'
 
@@ -126,7 +126,7 @@ def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path):
 
         self.log.info('VM launched, waiting for sshd')
         console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
-        wait_for_console_pattern(self, console_pattern, 'Oops')
+        self.wait_for_console_pattern(console_pattern, 'Oops')
         self.log.info('sshd ready')
 
         self.ssh_connect('root', 'root')
@@ -134,7 +134,7 @@ def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path):
     def shutdown_via_ssh(self):
         self.ssh_command('poweroff')
         self.ssh_disconnect_vm()
-        wait_for_console_pattern(self, 'Power down', 'Oops')
+        self.wait_for_console_pattern('Power down', 'Oops')
 
     def ssh_command_output_contains(self, cmd, exp):
         stdout, _ = self.ssh_command(cmd)
diff --git a/tests/acceptance/machine_arm_canona1100.py b/tests/acceptance/machine_arm_canona1100.py
index 0e5c43dbcf..945aa83270 100644
--- a/tests/acceptance/machine_arm_canona1100.py
+++ b/tests/acceptance/machine_arm_canona1100.py
@@ -9,10 +9,10 @@
 # later.  See the COPYING file in the top-level directory.
 
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado.utils import archive
 
-class CanonA1100Machine(Test):
+class CanonA1100Machine(Test, ConsoleMixIn):
     """Boots the barebox firmware and checks that the console is operational"""
 
     timeout = 90
@@ -32,4 +32,4 @@ def test_arm_canona1100(self):
         self.vm.add_args('-bios',
                          self.workdir + '/day18/barebox.canon-a1100.bin')
         self.vm.launch()
-        wait_for_console_pattern(self, 'running /env/bin/init')
+        self.wait_for_console_pattern('running /env/bin/init')
diff --git a/tests/acceptance/machine_arm_integratorcp.py b/tests/acceptance/machine_arm_integratorcp.py
index 49c8ebff78..490bafa571 100644
--- a/tests/acceptance/machine_arm_integratorcp.py
+++ b/tests/acceptance/machine_arm_integratorcp.py
@@ -13,7 +13,7 @@
 
 from avocado import skipUnless
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 
 
 NUMPY_AVAILABLE = True
@@ -29,7 +29,7 @@
     CV2_AVAILABLE = False
 
 
-class IntegratorMachine(Test):
+class IntegratorMachine(Test, ConsoleMixIn):
 
     timeout = 90
 
@@ -59,7 +59,7 @@ def test_integratorcp_console(self):
         :avocado: tags=device:pl011
         """
         self.boot_integratorcp()
-        wait_for_console_pattern(self, 'Log in as root')
+        self.wait_for_console_pattern('Log in as root')
 
     @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
     @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
@@ -80,7 +80,7 @@ def test_framebuffer_tux_logo(self):
 
         self.boot_integratorcp()
         framebuffer_ready = 'Console: switching to colour frame buffer device'
-        wait_for_console_pattern(self, framebuffer_ready)
+        self.wait_for_console_pattern(framebuffer_ready)
         self.vm.command('human-monitor-command', command_line='stop')
         self.vm.command('human-monitor-command',
                         command_line='screendump %s' % screendump_path)
diff --git a/tests/acceptance/machine_arm_n8x0.py b/tests/acceptance/machine_arm_n8x0.py
index e5741f2d8d..403415243e 100644
--- a/tests/acceptance/machine_arm_n8x0.py
+++ b/tests/acceptance/machine_arm_n8x0.py
@@ -12,9 +12,9 @@
 
 from avocado import skipUnless
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 
-class N8x0Machine(Test):
+class N8x0Machine(Test, ConsoleMixIn):
     """Boots the Linux kernel and checks that the console is operational"""
 
     timeout = 90
@@ -30,7 +30,7 @@ def __do_test_n8x0(self):
         self.vm.add_args('-kernel', kernel_path,
                          '-append', 'printk.time=0 console=ttyS1')
         self.vm.launch()
-        wait_for_console_pattern(self, 'TSC2005 driver initializing')
+        self.wait_for_console_pattern('TSC2005 driver initializing')
 
     @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
     def test_n800(self):
diff --git a/tests/acceptance/machine_microblaze.py b/tests/acceptance/machine_microblaze.py
index 7f6d18495d..d6ecd69e95 100644
--- a/tests/acceptance/machine_microblaze.py
+++ b/tests/acceptance/machine_microblaze.py
@@ -6,10 +6,10 @@
 # later. See the COPYING file in the top-level directory.
 
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado.utils import archive
 
-class MicroblazeMachine(Test):
+class MicroblazeMachine(Test, ConsoleMixIn):
 
     timeout = 90
 
@@ -27,8 +27,8 @@ def test_microblaze_s3adsp1800(self):
         self.vm.set_console()
         self.vm.add_args('-kernel', self.workdir + '/day17/ballerina.bin')
         self.vm.launch()
-        wait_for_console_pattern(self, 'This architecture does not have '
-                                       'kernel memory protection')
+        self.wait_for_console_pattern('This architecture does not have '
+                                      'kernel memory protection')
         # Note:
         # The kernel sometimes gets stuck after the "This architecture ..."
         # message, that's why we don't test for a later string here. This
diff --git a/tests/acceptance/machine_mips_loongson3v.py b/tests/acceptance/machine_mips_loongson3v.py
index 85b131a40f..58242d5c9b 100644
--- a/tests/acceptance/machine_mips_loongson3v.py
+++ b/tests/acceptance/machine_mips_loongson3v.py
@@ -12,9 +12,9 @@
 
 from avocado import skipUnless
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 
-class MipsLoongson3v(Test):
+class MipsLoongson3v(Test, ConsoleMixIn):
     timeout = 60
 
     @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
@@ -36,4 +36,4 @@ def test_pmon_serial_console(self):
         self.vm.set_console()
         self.vm.add_args('-bios', pmon_path)
         self.vm.launch()
-        wait_for_console_pattern(self, 'CPU GODSON3 BogoMIPS:')
+        self.wait_for_console_pattern('CPU GODSON3 BogoMIPS:')
diff --git a/tests/acceptance/machine_mips_malta.py b/tests/acceptance/machine_mips_malta.py
index 7c9a4ee4d2..e05fa862cc 100644
--- a/tests/acceptance/machine_mips_malta.py
+++ b/tests/acceptance/machine_mips_malta.py
@@ -13,7 +13,7 @@
 
 from avocado import skipUnless
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado.utils import archive
 from avocado import skipIf
 
@@ -33,7 +33,7 @@
 
 @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
 @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
-class MaltaMachineFramebuffer(Test):
+class MaltaMachineFramebuffer(Test, ConsoleMixIn):
 
     timeout = 30
 
@@ -68,7 +68,7 @@ def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
                          '-append', kernel_command_line)
         self.vm.launch()
         framebuffer_ready = 'Console: switching to colour frame buffer device'
-        wait_for_console_pattern(self, framebuffer_ready,
+        self.wait_for_console_pattern(framebuffer_ready,
                                  failure_message='Kernel panic - not syncing')
         self.vm.command('human-monitor-command', command_line='stop')
         self.vm.command('human-monitor-command',
diff --git a/tests/acceptance/machine_ppc.py b/tests/acceptance/machine_ppc.py
index a836e2496f..61f378a3a2 100644
--- a/tests/acceptance/machine_ppc.py
+++ b/tests/acceptance/machine_ppc.py
@@ -7,9 +7,9 @@
 
 from avocado.utils import archive
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 
-class PpcMachine(Test):
+class PpcMachine(Test, ConsoleMixIn):
 
     timeout = 90
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -32,7 +32,7 @@ def test_ppc64_pseries(self):
                          '-append', kernel_command_line)
         self.vm.launch()
         console_pattern = 'Kernel command line: %s' % kernel_command_line
-        wait_for_console_pattern(self, console_pattern, self.panic_message)
+        self.wait_for_console_pattern(console_pattern, self.panic_message)
 
     def test_ppc_mpc8544ds(self):
         """
@@ -47,7 +47,7 @@ def test_ppc_mpc8544ds(self):
         self.vm.set_console()
         self.vm.add_args('-kernel', self.workdir + '/creek/creek.bin')
         self.vm.launch()
-        wait_for_console_pattern(self, 'QEMU advent calendar 2020',
+        self.wait_for_console_pattern('QEMU advent calendar 2020',
                                  self.panic_message)
 
     def test_ppc_virtex_ml507(self):
@@ -65,5 +65,5 @@ def test_ppc_virtex_ml507(self):
                          '-dtb', self.workdir + '/hippo/virtex440-ml507.dtb',
                          '-m', '512')
         self.vm.launch()
-        wait_for_console_pattern(self, 'QEMU advent calendar 2020',
+        self.wait_for_console_pattern('QEMU advent calendar 2020',
                                  self.panic_message)
diff --git a/tests/acceptance/machine_rx_gdbsim.py b/tests/acceptance/machine_rx_gdbsim.py
index a893273bad..7a77cfe116 100644
--- a/tests/acceptance/machine_rx_gdbsim.py
+++ b/tests/acceptance/machine_rx_gdbsim.py
@@ -13,7 +13,6 @@
 from avocado import skipIf
 from avocado_qemu import Test
 from avocado_qemu import ConsoleMixIn
-from avocado_qemu import wait_for_console_pattern
 from avocado.utils import archive
 
 
@@ -41,7 +40,7 @@ def test_uboot(self):
                          '-no-reboot')
         self.vm.launch()
         uboot_version = 'U-Boot 2016.05-rc3-23705-ga1ef3c71cb-dirty'
-        wait_for_console_pattern(self, uboot_version)
+        self.wait_for_console_pattern(uboot_version)
         gcc_version = 'rx-unknown-linux-gcc (GCC) 9.0.0 20181105 (experimental)'
         # FIXME limit baudrate on chardev, else we type too fast
         #self.exec_command_and_wait_for_pattern('version', gcc_version)
@@ -68,6 +67,6 @@ def test_linux_sash(self):
                          '-dtb', dtb_path,
                          '-no-reboot')
         self.vm.launch()
-        wait_for_console_pattern(self, 'Sash command shell (version 1.1.1)',
-                                 failure_message='Kernel panic - not syncing')
+        self.wait_for_console_pattern('Sash command shell (version 1.1.1)',
+                                      failure_message='Kernel panic - not syncing')
         self.exec_command_and_wait_for_pattern('printenv', 'TERM=linux')
diff --git a/tests/acceptance/machine_s390_ccw_virtio.py b/tests/acceptance/machine_s390_ccw_virtio.py
index 537393c42f..bc1606ae43 100644
--- a/tests/acceptance/machine_s390_ccw_virtio.py
+++ b/tests/acceptance/machine_s390_ccw_virtio.py
@@ -15,7 +15,6 @@
 from avocado import skipIf
 from avocado_qemu import Test
 from avocado_qemu import ConsoleMixIn
-from avocado_qemu import wait_for_console_pattern
 from avocado.utils import archive
 
 class S390CCWVirtioMachine(Test, ConsoleMixIn):
@@ -24,9 +23,9 @@ class S390CCWVirtioMachine(Test, ConsoleMixIn):
     timeout = 120
 
     def wait_for_console_pattern(self, success_message, vm=None):
-        wait_for_console_pattern(self, success_message,
-                                 failure_message='Kernel panic - not syncing',
-                                 vm=vm)
+        super().wait_for_console_pattern(success_message,
+                                       failure_message='Kernel panic - not syncing',
+                                       vm=vm)
 
     def wait_for_crw_reports(self):
         self.exec_command_and_wait_for_pattern(
diff --git a/tests/acceptance/machine_sparc64_sun4u.py b/tests/acceptance/machine_sparc64_sun4u.py
index c7ad474bdc..810f11b049 100644
--- a/tests/acceptance/machine_sparc64_sun4u.py
+++ b/tests/acceptance/machine_sparc64_sun4u.py
@@ -9,10 +9,10 @@
 # later. See the COPYING file in the top-level directory.
 
 from avocado.utils import archive
+from avocado_qemu import ConsoleMixIn
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
 
-class Sun4uMachine(Test):
+class Sun4uMachine(Test, ConsoleMixIn):
     """Boots the Linux kernel and checks that the console is operational"""
 
     timeout = 90
@@ -32,4 +32,4 @@ def test_sparc64_sun4u(self):
         self.vm.add_args('-kernel', self.workdir + '/day23/vmlinux',
                          '-append', self.KERNEL_COMMON_COMMAND_LINE)
         self.vm.launch()
-        wait_for_console_pattern(self, 'Starting logging: OK')
+        self.wait_for_console_pattern('Starting logging: OK')
diff --git a/tests/acceptance/machine_sparc_leon3.py b/tests/acceptance/machine_sparc_leon3.py
index 2405cd7a0d..1bf7812987 100644
--- a/tests/acceptance/machine_sparc_leon3.py
+++ b/tests/acceptance/machine_sparc_leon3.py
@@ -6,11 +6,11 @@
 # later. See the COPYING file in the top-level directory.
 
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 from avocado import skip
 
 
-class Leon3Machine(Test):
+class Leon3Machine(Test, ConsoleMixIn):
 
     timeout = 60
 
@@ -33,5 +33,5 @@ def test_leon3_helenos_uimage(self):
 
         self.vm.launch()
 
-        wait_for_console_pattern(self, 'Copyright (c) 2001-2014 HelenOS project')
-        wait_for_console_pattern(self, 'Booting the kernel ...')
+        self.wait_for_console_pattern('Copyright (c) 2001-2014 HelenOS project')
+        self.wait_for_console_pattern('Booting the kernel ...')
diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
index b4a6d20770..9f487fb7bc 100644
--- a/tests/acceptance/multiprocess.py
+++ b/tests/acceptance/multiprocess.py
@@ -8,7 +8,6 @@
 import socket
 
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
 from avocado_qemu import ConsoleMixIn
 
 class Multiprocess(Test, ConsoleMixIn):
@@ -56,8 +55,8 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line,
                          'x-pci-proxy-dev,'
                          'id=lsi1,fd='+str(proxy_sock.fileno()))
         self.vm.launch()
-        wait_for_console_pattern(self, 'as init process',
-                                 'Kernel panic - not syncing')
+        self.wait_for_console_pattern('as init process',
+                                      'Kernel panic - not syncing')
         self.exec_command('mount -t sysfs sysfs /sys')
         self.exec_command_and_wait_for_pattern(
                                           'cat /sys/bus/pci/devices/*/uevent',
diff --git a/tests/acceptance/ppc_prep_40p.py b/tests/acceptance/ppc_prep_40p.py
index 96ba13b894..35475892be 100644
--- a/tests/acceptance/ppc_prep_40p.py
+++ b/tests/acceptance/ppc_prep_40p.py
@@ -10,10 +10,10 @@
 from avocado import skipIf
 from avocado import skipUnless
 from avocado_qemu import Test
-from avocado_qemu import wait_for_console_pattern
+from avocado_qemu import ConsoleMixIn
 
 
-class IbmPrep40pMachine(Test):
+class IbmPrep40pMachine(Test, ConsoleMixIn):
 
     timeout = 60
 
@@ -44,8 +44,8 @@ def test_factory_firmware_and_netbsd(self):
                          '-fda', drive_path)
         self.vm.launch()
         os_banner = 'NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:49:40 PST 2007'
-        wait_for_console_pattern(self, os_banner)
-        wait_for_console_pattern(self, 'Model: IBM PPS Model 6015')
+        self.wait_for_console_pattern(os_banner)
+        self.wait_for_console_pattern('Model: IBM PPS Model 6015')
 
     def test_openbios_192m(self):
         """
@@ -56,9 +56,9 @@ def test_openbios_192m(self):
         self.vm.add_args('-m', '192') # test fw_cfg
 
         self.vm.launch()
-        wait_for_console_pattern(self, '>> OpenBIOS')
-        wait_for_console_pattern(self, '>> Memory: 192M')
-        wait_for_console_pattern(self, '>> CPU type PowerPC,604')
+        self.wait_for_console_pattern('>> OpenBIOS')
+        self.wait_for_console_pattern('>> Memory: 192M')
+        self.wait_for_console_pattern('>> CPU type PowerPC,604')
 
     def test_openbios_and_netbsd(self):
         """
@@ -75,4 +75,4 @@ def test_openbios_and_netbsd(self):
                          '-boot', 'd')
 
         self.vm.launch()
-        wait_for_console_pattern(self, 'NetBSD/prep BOOT, Revision 1.9')
+        self.wait_for_console_pattern('NetBSD/prep BOOT, Revision 1.9')
diff --git a/tests/acceptance/virtio-gpu.py b/tests/acceptance/virtio-gpu.py
index 4d65431ef1..a7e6bbb8a2 100644
--- a/tests/acceptance/virtio-gpu.py
+++ b/tests/acceptance/virtio-gpu.py
@@ -6,7 +6,6 @@
 
 from avocado_qemu import Test
 from avocado_qemu import BUILD_DIR
-from avocado_qemu import wait_for_console_pattern
 from avocado_qemu import ConsoleMixIn
 from avocado_qemu import is_readable_executable_file
 
@@ -49,8 +48,7 @@ class VirtioGPUx86(Test, ConsoleMixIn):
     )
 
     def wait_for_console_pattern(self, success_message, vm=None):
-        wait_for_console_pattern(
-            self,
+        super().wait_for_console_pattern(
             success_message,
             failure_message="Kernel panic - not syncing",
             vm=vm,
diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
index 46fa65392a..ad1999a372 100644
--- a/tests/acceptance/virtiofs_submounts.py
+++ b/tests/acceptance/virtiofs_submounts.py
@@ -6,7 +6,6 @@
 
 from avocado import skipUnless
 from avocado_qemu import LinuxTest, BUILD_DIR
-from avocado_qemu import wait_for_console_pattern
 from avocado.utils import ssh
 
 
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 7/7] tests/acceptance: Move _console_interaction to ConsoleMixIn
  2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
                   ` (5 preceding siblings ...)
  2021-05-03 22:43 ` [PATCH 6/7] tests/acceptance: Move wait_for_console_pattern to ConsoleMixIn Wainer dos Santos Moschetta
@ 2021-05-03 22:43 ` Wainer dos Santos Moschetta
  2021-05-24 18:37   ` Willian Rampazzo
  2021-05-24 20:58 ` [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Willian Rampazzo
  7 siblings, 1 reply; 19+ messages in thread
From: Wainer dos Santos Moschetta @ 2021-05-03 22:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: willianr, philmd, crosa

This moved the last remaining _console_interaction() to ConsoleMixIn.

None tests call it directly, so only the other methods in ConsoleMixIn
needed to be adapted.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 tests/acceptance/avocado_qemu/__init__.py | 57 +++++++++++------------
 1 file changed, 28 insertions(+), 29 deletions(-)

diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
index b21f9ea3ff..a6de3fe11a 100644
--- a/tests/acceptance/avocado_qemu/__init__.py
+++ b/tests/acceptance/avocado_qemu/__init__.py
@@ -76,34 +76,33 @@ def pick_default_qemu_bin(arch=None):
     if is_readable_executable_file(qemu_bin_from_bld_dir_path):
         return qemu_bin_from_bld_dir_path
 
-
-def _console_interaction(test, success_message, failure_message,
-                         send_string, keep_sending=False, vm=None):
-    assert not keep_sending or send_string
-    if vm is None:
-        vm = test.vm
-    console = vm.console_socket.makefile()
-    console_logger = logging.getLogger('console')
-    while True:
-        if send_string:
-            vm.console_socket.sendall(send_string.encode())
-            if not keep_sending:
-                send_string = None # send only once
-        msg = console.readline().strip()
-        if not msg:
-            continue
-        console_logger.debug(msg)
-        if success_message is None or success_message in msg:
-            break
-        if failure_message and failure_message in msg:
-            console.close()
-            fail = 'Failure message found in console: "%s". Expected: "%s"' % \
-                    (failure_message, success_message)
-            test.fail(fail)
-
 class ConsoleMixIn():
     """Contains utilities for interacting with a guest via Console."""
 
+    def _console_interaction(self, success_message, failure_message,
+                             send_string, keep_sending=False, vm=None):
+        assert not keep_sending or send_string
+        if vm is None:
+            vm = self.vm
+        console = vm.console_socket.makefile()
+        console_logger = logging.getLogger('console')
+        while True:
+            if send_string:
+                vm.console_socket.sendall(send_string.encode())
+                if not keep_sending:
+                    send_string = None # send only once
+            msg = console.readline().strip()
+            if not msg:
+                continue
+            console_logger.debug(msg)
+            if success_message is None or success_message in msg:
+                break
+            if failure_message and failure_message in msg:
+                console.close()
+                fail = 'Failure message found in console: "%s". Expected: "%s"' % \
+                        (failure_message, success_message)
+                self.fail(fail)
+
     def exec_command(self, command):
         """
         Send a command to a console (appending CRLF characters), while logging
@@ -112,7 +111,7 @@ def exec_command(self, command):
         :param command: the command to send
         :type command: str
         """
-        _console_interaction(self, None, None, command + '\r')
+        self._console_interaction(None, None, command + '\r')
 
     def exec_command_and_wait_for_pattern(self, command,
                                           success_message, failure_message=None):
@@ -125,7 +124,7 @@ def exec_command_and_wait_for_pattern(self, command,
         :param success_message: if this message appears, test succeeds
         :param failure_message: if this message appears, test fails
         """
-        _console_interaction(self, success_message, failure_message, command + '\r')
+        self._console_interaction(success_message, failure_message, command + '\r')
 
     def interrupt_interactive_console_until_pattern(self, success_message,
                                                     failure_message=None,
@@ -147,7 +146,7 @@ def interrupt_interactive_console_until_pattern(self, success_message,
         :param interrupt_string: a string to send to the console before trying
                                 to read a new line
         """
-        _console_interaction(self, success_message, failure_message,
+        self._console_interaction(success_message, failure_message,
                          interrupt_string, True)
 
     def wait_for_console_pattern(self, success_message, failure_message=None,
@@ -158,7 +157,7 @@ def wait_for_console_pattern(self, success_message, failure_message=None,
         :param success_message: if this message appears, test succeeds
         :param failure_message: if this message appears, test fails
         """
-        _console_interaction(self, success_message, failure_message, None, vm=vm)
+        self._console_interaction(success_message, failure_message, None, vm=vm)
 
 class Test(avocado.Test):
     def _get_unique_tag_val(self, tag_name):
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest
  2021-05-03 22:43 ` [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest Wainer dos Santos Moschetta
@ 2021-05-04 16:01   ` Philippe Mathieu-Daudé
  2021-05-24 18:30     ` Willian Rampazzo
  2021-05-24 18:24   ` Willian Rampazzo
  1 sibling, 1 reply; 19+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-05-04 16:01 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta, qemu-devel; +Cc: willianr, Thomas Huth, crosa

Hi Wainer,

On 5/4/21 12:43 AM, Wainer dos Santos Moschetta wrote:
> The Sun4uMachine class inherit from LinuxKernelTest to effectively only use
> the KERNEL_COMMON_COMMAND_LINE attribute. This change remove that unneeded
> dependency, making Sun4uMachine self-content.

It is odd because the test boots a Linux kernel...

Once you added ConsoleMixIn, LinuxKernelTest is left with
2 methods related to archive extraction. Not particularly
specific to Linux kernel. Beside, shouldn't these methods
be provided by Avocado directly, by avocado.utils.archive
and avocado.utils.software_manager.backends?

> I took the occasion to delint the code: the unused os import was
> removed, imports were reordered, and the module has a docstring now.
> 
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/machine_sparc64_sun4u.py | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class
  2021-05-03 22:43 ` [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class Wainer dos Santos Moschetta
@ 2021-05-24 18:14   ` Willian Rampazzo
  0 siblings, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 18:14 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta
  Cc: Philippe Mathieu Daude, qemu-devel, Cleber Rosa Junior

Hi Wainer,

On Mon, May 3, 2021 at 7:43 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> This created the ConsoleMixIn class to wrap the methods related with console
> interaction with the guest that currently are loose in the avocado_qemu
> package. It should be used as a mixin on the test classes.
>
> At this point only the interrupt_interactive_console_until_pattern() was moved
> to ConsoleMixIn. This method is only used in boot_linux_console.py tests, so
> there was needed to adapt them.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 52 +++++++++++------------
>  tests/acceptance/boot_linux_console.py    | 10 ++---
>  2 files changed, 31 insertions(+), 31 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 83b1741ec8..6f4e0edfa3 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -101,32 +101,6 @@ def _console_interaction(test, success_message, failure_message,
>                      (failure_message, success_message)
>              test.fail(fail)
>
> -def interrupt_interactive_console_until_pattern(test, success_message,
> -                                                failure_message=None,
> -                                                interrupt_string='\r'):
> -    """
> -    Keep sending a string to interrupt a console prompt, while logging the
> -    console output. Typical use case is to break a boot loader prompt, such:
> -
> -        Press a key within 5 seconds to interrupt boot process.
> -        5
> -        4
> -        3
> -        2
> -        1
> -        Booting default image...
> -
> -    :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
> -    :param interrupt_string: a string to send to the console before trying
> -                             to read a new line
> -    """
> -    _console_interaction(test, success_message, failure_message,
> -                         interrupt_string, True)
> -
>  def wait_for_console_pattern(test, success_message, failure_message=None,
>                               vm=None):
>      """
> @@ -168,6 +142,32 @@ def exec_command_and_wait_for_pattern(test, command,
>      """
>      _console_interaction(test, success_message, failure_message, command + '\r')
>
> +class ConsoleMixIn():
> +    """Contains utilities for interacting with a guest via Console."""
> +
> +    def interrupt_interactive_console_until_pattern(self, success_message,
> +                                                    failure_message=None,
> +                                                    interrupt_string='\r'):
> +        """
> +        Keep sending a string to interrupt a console prompt, while logging the
> +        console output. Typical use case is to break a boot loader prompt, such:
> +
> +            Press a key within 5 seconds to interrupt boot process.
> +            5
> +            4
> +            3
> +            2
> +            1
> +            Booting default image...
> +
> +        :param success_message: if this message appears, test succeeds
> +        :param failure_message: if this message appears, test fails
> +        :param interrupt_string: a string to send to the console before trying
> +                                to read a new line
> +        """
> +        _console_interaction(self, success_message, failure_message,
> +                         interrupt_string, True)
> +
>  class Test(avocado.Test):
>      def _get_unique_tag_val(self, tag_name):
>          """
> diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
> index 1ca32ecf25..10317b232b 100644
> --- a/tests/acceptance/boot_linux_console.py
> +++ b/tests/acceptance/boot_linux_console.py
> @@ -17,7 +17,7 @@
>  from avocado import skipUnless
>  from avocado_qemu import Test
>  from avocado_qemu import exec_command_and_wait_for_pattern
> -from avocado_qemu import interrupt_interactive_console_until_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import wait_for_console_pattern
>  from avocado.utils import process
>  from avocado.utils import archive
> @@ -45,7 +45,7 @@ def image_pow2ceil_expand(path):
>              with open(path, 'ab+') as fd:
>                  fd.truncate(size_aligned)
>
> -class LinuxKernelTest(Test):
> +class LinuxKernelTest(Test, ConsoleMixIn):

The Python class hierarchy is defined from right to left. This would
not cause a problem now but can result in unexpected behavior in the
future. In this case, my suggestion is to switch the order here and
make the Test class the last.

>      KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
>
>      def wait_for_console_pattern(self, success_message, vm=None):
> @@ -626,8 +626,8 @@ def test_arm_quanta_gsj(self):
>          self.wait_for_console_pattern('>Device: Poleg BMC NPCM730')
>          self.wait_for_console_pattern('>Skip DDR init.')
>          self.wait_for_console_pattern('U-Boot ')
> -        interrupt_interactive_console_until_pattern(
> -                self, 'Hit any key to stop autoboot:', 'U-Boot>')
> +        self.interrupt_interactive_console_until_pattern(
> +                'Hit any key to stop autoboot:', 'U-Boot>')
>          exec_command_and_wait_for_pattern(
>                  self, "setenv bootargs ${bootargs} " + kernel_command_line,
>                  'U-Boot>')
> @@ -879,7 +879,7 @@ def test_arm_orangepi_uboot_netbsd9(self):
>                           '-no-reboot')
>          self.vm.launch()
>          wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
> -        interrupt_interactive_console_until_pattern(self,
> +        self.interrupt_interactive_console_until_pattern(
>                                         'Hit any key to stop autoboot:',
>                                         'switch to partitions #0, OK')
>
> --
> 2.29.2
>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn
  2021-05-03 22:43 ` [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn Wainer dos Santos Moschetta
@ 2021-05-24 18:16   ` Willian Rampazzo
  0 siblings, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 18:16 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta
  Cc: Philippe Mathieu Daude, qemu-devel, Cleber Rosa Junior

On Mon, May 3, 2021 at 7:43 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> This moved exec_command() to ConsoleMixIn class.
>
> Only the multiprocess.py file were touched by that change, so its tests
> were adapted.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 22 ++++++++++------------
>  tests/acceptance/multiprocess.py          |  6 +++---
>  2 files changed, 13 insertions(+), 15 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 6f4e0edfa3..4d3b869765 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -114,18 +114,6 @@ def wait_for_console_pattern(test, success_message, failure_message=None,
>      """
>      _console_interaction(test, success_message, failure_message, None, vm=vm)
>
> -def exec_command(test, command):
> -    """
> -    Send a command to a console (appending CRLF characters), while logging
> -    the content.
> -
> -    :param test: an Avocado test containing a VM.
> -    :type test: :class:`avocado_qemu.Test`
> -    :param command: the command to send
> -    :type command: str
> -    """
> -    _console_interaction(test, None, None, command + '\r')
> -
>  def exec_command_and_wait_for_pattern(test, command,
>                                        success_message, failure_message=None):
>      """
> @@ -145,6 +133,16 @@ def exec_command_and_wait_for_pattern(test, command,
>  class ConsoleMixIn():
>      """Contains utilities for interacting with a guest via Console."""
>
> +    def exec_command(self, command):
> +        """
> +        Send a command to a console (appending CRLF characters), while logging
> +        the content.
> +
> +        :param command: the command to send
> +        :type command: str
> +        """
> +        _console_interaction(self, None, None, command + '\r')
> +
>      def interrupt_interactive_console_until_pattern(self, success_message,
>                                                      failure_message=None,
>                                                      interrupt_string='\r'):
> diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
> index 96627f022a..41d3e51164 100644
> --- a/tests/acceptance/multiprocess.py
> +++ b/tests/acceptance/multiprocess.py
> @@ -9,10 +9,10 @@
>
>  from avocado_qemu import Test
>  from avocado_qemu import wait_for_console_pattern
> -from avocado_qemu import exec_command
> +from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import exec_command_and_wait_for_pattern
>
> -class Multiprocess(Test):
> +class Multiprocess(Test, ConsoleMixIn):

Same comment here from the previous patch regarding the order of classes.

>      """
>      :avocado: tags=multiprocess
>      """
> @@ -59,7 +59,7 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line,
>          self.vm.launch()
>          wait_for_console_pattern(self, 'as init process',
>                                   'Kernel panic - not syncing')
> -        exec_command(self, 'mount -t sysfs sysfs /sys')
> +        self.exec_command('mount -t sysfs sysfs /sys')
>          exec_command_and_wait_for_pattern(self,
>                                            'cat /sys/bus/pci/devices/*/uevent',
>                                            'PCI_ID=1000:0012')
> --
> 2.29.2
>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/7] tests/acceptance: Move exec_command_and_wait_for_pattern to ConsoleMixIn
  2021-05-03 22:43 ` [PATCH 3/7] tests/acceptance: Move exec_command_and_wait_for_pattern " Wainer dos Santos Moschetta
@ 2021-05-24 18:21   ` Willian Rampazzo
  0 siblings, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 18:21 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta
  Cc: Philippe Mathieu Daude, qemu-devel, Cleber Rosa Junior

On Mon, May 3, 2021 at 7:43 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> It was the time of exec_command_and_wait_for_pattern() to find a new
> home at ConsoleMixIn. This time various tests needed to be adapted.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py   |  29 +++---
>  tests/acceptance/boot_linux_console.py      | 107 ++++++++++----------
>  tests/acceptance/machine_rx_gdbsim.py       |   8 +-
>  tests/acceptance/machine_s390_ccw_virtio.py |  72 ++++++-------
>  tests/acceptance/multiprocess.py            |   3 +-
>  tests/acceptance/virtio-gpu.py              |  12 +--
>  6 files changed, 111 insertions(+), 120 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 4d3b869765..4a0129c0eb 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -114,22 +114,6 @@ def wait_for_console_pattern(test, success_message, failure_message=None,
>      """
>      _console_interaction(test, success_message, failure_message, None, vm=vm)
>
> -def exec_command_and_wait_for_pattern(test, command,
> -                                      success_message, failure_message=None):
> -    """
> -    Send a command to a console (appending CRLF characters), then wait
> -    for success_message to appear on the console, while logging the.
> -    content. Mark the test as failed if failure_message is found instead.
> -
> -    :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 command: the command to send
> -    :param success_message: if this message appears, test succeeds
> -    :param failure_message: if this message appears, test fails
> -    """
> -    _console_interaction(test, success_message, failure_message, command + '\r')
> -
>  class ConsoleMixIn():
>      """Contains utilities for interacting with a guest via Console."""
>
> @@ -143,6 +127,19 @@ def exec_command(self, command):
>          """
>          _console_interaction(self, None, None, command + '\r')
>
> +    def exec_command_and_wait_for_pattern(self, command,
> +                                          success_message, failure_message=None):
> +        """
> +        Send a command to a console (appending CRLF characters), then wait
> +        for success_message to appear on the console, while logging the.
> +        content. Mark the test as failed if failure_message is found instead.
> +
> +        :param command: the command to send
> +        :param success_message: if this message appears, test succeeds
> +        :param failure_message: if this message appears, test fails
> +        """
> +        _console_interaction(self, success_message, failure_message, command + '\r')
> +
>      def interrupt_interactive_console_until_pattern(self, success_message,
>                                                      failure_message=None,
>                                                      interrupt_string='\r'):
> diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
> index 10317b232b..50e0a3fe79 100644
> --- a/tests/acceptance/boot_linux_console.py
> +++ b/tests/acceptance/boot_linux_console.py
> @@ -16,7 +16,6 @@
>  from avocado import skip
>  from avocado import skipUnless
>  from avocado_qemu import Test
> -from avocado_qemu import exec_command_and_wait_for_pattern
>  from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import wait_for_console_pattern
>  from avocado.utils import process
> @@ -223,12 +222,12 @@ def test_mips_malta_cpio(self):
>          self.vm.launch()
>          self.wait_for_console_pattern('Boot successful.')
>
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
> -                                                'BogoMIPS')
> -        exec_command_and_wait_for_pattern(self, 'uname -a',
> -                                                'Debian')
> -        exec_command_and_wait_for_pattern(self, 'reboot',
> -                                                'reboot: Restarting system')
> +        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
> +                                               'BogoMIPS')
> +        self.exec_command_and_wait_for_pattern('uname -a',
> +                                               'Debian')
> +        self.exec_command_and_wait_for_pattern('reboot',
> +                                               'reboot: Restarting system')
>          # Wait for VM to shut down gracefully
>          self.vm.wait()
>
> @@ -265,12 +264,12 @@ def test_mips64el_malta_5KEc_cpio(self):
>          self.vm.launch()
>          wait_for_console_pattern(self, 'Boot successful.')
>
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
> -                                                'MIPS 5KE')
> -        exec_command_and_wait_for_pattern(self, 'uname -a',
> -                                                '3.19.3.mtoman.20150408')
> -        exec_command_and_wait_for_pattern(self, 'reboot',
> -                                                'reboot: Restarting system')
> +        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
> +                                               'MIPS 5KE')
> +        self.exec_command_and_wait_for_pattern('uname -a',
> +                                               '3.19.3.mtoman.20150408')
> +        self.exec_command_and_wait_for_pattern('reboot',
> +                                               'reboot: Restarting system')
>          # Wait for VM to shut down gracefully
>          self.vm.wait()
>
> @@ -422,9 +421,9 @@ def test_arm_emcraft_sf2(self):
>          self.vm.launch()
>          self.wait_for_console_pattern('Enter \'help\' for a list')
>
> -        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15',
> -                                                 'eth0: link becomes ready')
> -        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
> +        self.exec_command_and_wait_for_pattern('ifconfig eth0 10.0.2.15',
> +                                               'eth0: link becomes ready')
> +        self.exec_command_and_wait_for_pattern('ping -c 3 10.0.2.2',
>              '3 packets transmitted, 3 packets received, 0% packet loss')
>
>      def do_test_arm_raspi2(self, uart_id):
> @@ -541,10 +540,10 @@ def test_arm_cubieboard_initrd(self):
>          self.vm.launch()
>          self.wait_for_console_pattern('Boot successful.')
>
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
> -                                                'Allwinner sun4i/sun5i')
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
> -                                                'system-control@1c00000')
> +        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
> +                                               'Allwinner sun4i/sun5i')
> +        self.exec_command_and_wait_for_pattern('cat /proc/iomem',
> +                                               'system-control@1c00000')
>          # cubieboard's reboot is not functioning; omit reboot test.
>
>      def test_arm_cubieboard_sata(self):
> @@ -584,10 +583,10 @@ def test_arm_cubieboard_sata(self):
>          self.vm.launch()
>          self.wait_for_console_pattern('Boot successful.')
>
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
> -                                                'Allwinner sun4i/sun5i')
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
> -                                                'sda')
> +        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
> +                                               'Allwinner sun4i/sun5i')
> +        self.exec_command_and_wait_for_pattern('cat /proc/partitions',
> +                                               'sda')
>          # cubieboard's reboot is not functioning; omit reboot test.
>
>      @skipUnless(os.getenv('AVOCADO_TIMEOUT_EXPECTED'), 'Test might timeout')
> @@ -628,11 +627,11 @@ def test_arm_quanta_gsj(self):
>          self.wait_for_console_pattern('U-Boot ')
>          self.interrupt_interactive_console_until_pattern(
>                  'Hit any key to stop autoboot:', 'U-Boot>')
> -        exec_command_and_wait_for_pattern(
> -                self, "setenv bootargs ${bootargs} " + kernel_command_line,
> +        self.exec_command_and_wait_for_pattern(
> +                "setenv bootargs ${bootargs} " + kernel_command_line,
>                  'U-Boot>')
> -        exec_command_and_wait_for_pattern(
> -                self, 'run romboot', 'Booting Kernel from flash')
> +        self.exec_command_and_wait_for_pattern(
> +                'run romboot', 'Booting Kernel from flash')
>          self.wait_for_console_pattern('Booting Linux on physical CPU 0x0')
>          self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0')
>          self.wait_for_console_pattern('OpenBMC Project Reference Distro')
> @@ -732,12 +731,12 @@ def test_arm_orangepi_initrd(self):
>          self.vm.launch()
>          self.wait_for_console_pattern('Boot successful.')
>
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
> -                                                'Allwinner sun8i Family')
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/iomem',
> -                                                'system-control@1c00000')
> -        exec_command_and_wait_for_pattern(self, 'reboot',
> -                                                'reboot: Restarting system')
> +        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
> +                                               'Allwinner sun8i Family')
> +        self.exec_command_and_wait_for_pattern('cat /proc/iomem',
> +                                               'system-control@1c00000')
> +        self.exec_command_and_wait_for_pattern('reboot',
> +                                               'reboot: Restarting system')
>          # Wait for VM to shut down gracefully
>          self.vm.wait()
>
> @@ -777,18 +776,18 @@ def test_arm_orangepi_sd(self):
>          shell_ready = "/bin/sh: can't access tty; job control turned off"
>          self.wait_for_console_pattern(shell_ready)
>
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
> -                                                'Allwinner sun8i Family')
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/partitions',
> -                                                'mmcblk0')
> -        exec_command_and_wait_for_pattern(self, 'ifconfig eth0 up',
> -                                                 'eth0: Link is Up')
> -        exec_command_and_wait_for_pattern(self, 'udhcpc eth0',
> +        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
> +                                               'Allwinner sun8i Family')
> +        self.exec_command_and_wait_for_pattern('cat /proc/partitions',
> +                                               'mmcblk0')
> +        self.exec_command_and_wait_for_pattern('ifconfig eth0 up',
> +                                               'eth0: Link is Up')
> +        self.exec_command_and_wait_for_pattern('udhcpc eth0',
>              'udhcpc: lease of 10.0.2.15 obtained')
> -        exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2',
> +        self.exec_command_and_wait_for_pattern('ping -c 3 10.0.2.2',
>              '3 packets transmitted, 3 packets received, 0% packet loss')
> -        exec_command_and_wait_for_pattern(self, 'reboot',
> -                                                'reboot: Restarting system')
> +        self.exec_command_and_wait_for_pattern('reboot',
> +                                               'reboot: Restarting system')
>          # Wait for VM to shut down gracefully
>          self.vm.wait()
>
> @@ -829,10 +828,10 @@ def test_arm_orangepi_bionic_20_08(self):
>
>          self.wait_for_console_pattern('U-Boot SPL')
>          self.wait_for_console_pattern('Autoboot in ')
> -        exec_command_and_wait_for_pattern(self, ' ', '=>')
> -        exec_command_and_wait_for_pattern(self, "setenv extraargs '" +
> -                                                kernel_command_line + "'", '=>')
> -        exec_command_and_wait_for_pattern(self, 'boot', 'Starting kernel ...');
> +        self.exec_command_and_wait_for_pattern(' ', '=>')
> +        self.exec_command_and_wait_for_pattern("setenv extraargs '" +
> +                                               kernel_command_line + "'", '=>')
> +        self.exec_command_and_wait_for_pattern('boot', 'Starting kernel ...');
>
>          self.wait_for_console_pattern('systemd[1]: Set hostname ' +
>                                        'to <orangepipc>')
> @@ -883,20 +882,20 @@ def test_arm_orangepi_uboot_netbsd9(self):
>                                         'Hit any key to stop autoboot:',
>                                         'switch to partitions #0, OK')
>
> -        exec_command_and_wait_for_pattern(self, '', '=>')
> +        self.exec_command_and_wait_for_pattern('', '=>')
>          cmd = 'setenv bootargs root=ld0a'
> -        exec_command_and_wait_for_pattern(self, cmd, '=>')
> +        self.exec_command_and_wait_for_pattern(cmd, '=>')
>          cmd = 'setenv kernel netbsd-GENERIC.ub'
> -        exec_command_and_wait_for_pattern(self, cmd, '=>')
> +        self.exec_command_and_wait_for_pattern(cmd, '=>')
>          cmd = 'setenv fdtfile dtb/sun8i-h3-orangepi-pc.dtb'
> -        exec_command_and_wait_for_pattern(self, cmd, '=>')
> +        self.exec_command_and_wait_for_pattern(cmd, '=>')
>          cmd = ("setenv bootcmd 'fatload mmc 0:1 ${kernel_addr_r} ${kernel}; "
>                 "fatload mmc 0:1 ${fdt_addr_r} ${fdtfile}; "
>                 "fdt addr ${fdt_addr_r}; "
>                 "bootm ${kernel_addr_r} - ${fdt_addr_r}'")
> -        exec_command_and_wait_for_pattern(self, cmd, '=>')
> +        self.exec_command_and_wait_for_pattern(cmd, '=>')
>
> -        exec_command_and_wait_for_pattern(self, 'boot',
> +        self.exec_command_and_wait_for_pattern('boot',
>                                            'Booting kernel from Legacy Image')
>          wait_for_console_pattern(self, 'Starting kernel ...')
>          wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
> diff --git a/tests/acceptance/machine_rx_gdbsim.py b/tests/acceptance/machine_rx_gdbsim.py
> index 32b737b6d8..a893273bad 100644
> --- a/tests/acceptance/machine_rx_gdbsim.py
> +++ b/tests/acceptance/machine_rx_gdbsim.py
> @@ -12,12 +12,12 @@
>
>  from avocado import skipIf
>  from avocado_qemu import Test
> -from avocado_qemu import exec_command_and_wait_for_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import wait_for_console_pattern
>  from avocado.utils import archive
>
>
> -class RxGdbSimMachine(Test):
> +class RxGdbSimMachine(Test, ConsoleMixIn):

Same comment here regarding the class order from the previous two patches.

>
>      timeout = 30
>      KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
> @@ -44,7 +44,7 @@ def test_uboot(self):
>          wait_for_console_pattern(self, uboot_version)
>          gcc_version = 'rx-unknown-linux-gcc (GCC) 9.0.0 20181105 (experimental)'
>          # FIXME limit baudrate on chardev, else we type too fast
> -        #exec_command_and_wait_for_pattern(self, 'version', gcc_version)
> +        #self.exec_command_and_wait_for_pattern('version', gcc_version)
>
>      @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
>      def test_linux_sash(self):
> @@ -70,4 +70,4 @@ def test_linux_sash(self):
>          self.vm.launch()
>          wait_for_console_pattern(self, 'Sash command shell (version 1.1.1)',
>                                   failure_message='Kernel panic - not syncing')
> -        exec_command_and_wait_for_pattern(self, 'printenv', 'TERM=linux')
> +        self.exec_command_and_wait_for_pattern('printenv', 'TERM=linux')
> diff --git a/tests/acceptance/machine_s390_ccw_virtio.py b/tests/acceptance/machine_s390_ccw_virtio.py
> index 4028c99afc..537393c42f 100644
> --- a/tests/acceptance/machine_s390_ccw_virtio.py
> +++ b/tests/acceptance/machine_s390_ccw_virtio.py
> @@ -14,11 +14,11 @@
>
>  from avocado import skipIf
>  from avocado_qemu import Test
> -from avocado_qemu import exec_command_and_wait_for_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import wait_for_console_pattern
>  from avocado.utils import archive
>
> -class S390CCWVirtioMachine(Test):
> +class S390CCWVirtioMachine(Test, ConsoleMixIn):

Same here!

>      KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
>
>      timeout = 120
> @@ -29,13 +29,13 @@ def wait_for_console_pattern(self, success_message, vm=None):
>                                   vm=vm)
>
>      def wait_for_crw_reports(self):
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'while ! (dmesg -c | grep CRW) ; do sleep 1 ; done',
>                          'CRW reports')
>
>      dmesg_clear_count = 1
>      def clear_guest_dmesg(self):
> -        exec_command_and_wait_for_pattern(self, 'dmesg -c > /dev/null; '
> +        self.exec_command_and_wait_for_pattern('dmesg -c > /dev/null; '
>                      'echo dm_clear\ ' + str(self.dmesg_clear_count),
>                      'dm_clear ' + str(self.dmesg_clear_count))
>          self.dmesg_clear_count += 1
> @@ -81,13 +81,13 @@ def test_s390x_devices(self):
>          shell_ready = "sh: can't access tty; job control turned off"
>          self.wait_for_console_pattern(shell_ready)
>          # first debug shell is too early, we need to wait for device detection
> -        exec_command_and_wait_for_pattern(self, 'exit', shell_ready)
> +        self.exec_command_and_wait_for_pattern('exit', shell_ready)
>
>          ccw_bus_ids="0.1.1111  0.2.0000  0.3.1234"
>          pci_bus_ids="0005:00:00.0  000a:00:00.0"
> -        exec_command_and_wait_for_pattern(self, 'ls /sys/bus/ccw/devices/',
> +        self.exec_command_and_wait_for_pattern('ls /sys/bus/ccw/devices/',
>                                            ccw_bus_ids)
> -        exec_command_and_wait_for_pattern(self, 'ls /sys/bus/pci/devices/',
> +        self.exec_command_and_wait_for_pattern('ls /sys/bus/pci/devices/',
>                                            pci_bus_ids)
>          # check that the device at 0.2.0000 is in legacy mode, while the
>          # device at 0.3.1234 has the virtio-1 feature bit set
> @@ -95,14 +95,14 @@ def test_s390x_devices(self):
>                              "10000000000000000000000000000000"
>          virtio_rng_features_legacy="00000000000000000000000000001100" + \
>                                     "00000000000000000000000000000000"
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'cat /sys/bus/ccw/devices/0.2.0000/virtio?/features',
>                          virtio_rng_features_legacy)
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'cat /sys/bus/ccw/devices/0.3.1234/virtio?/features',
>                          virtio_rng_features)
>          # check that /dev/hwrng works - and that it's gone after ejecting
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'dd if=/dev/hwrng of=/dev/null bs=1k count=10',
>                          '10+0 records out')
>          self.clear_guest_dmesg()
> @@ -111,22 +111,22 @@ def test_s390x_devices(self):
>          self.clear_guest_dmesg()
>          self.vm.command('device_del', id='rn2')
>          self.wait_for_crw_reports()
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'dd if=/dev/hwrng of=/dev/null bs=1k count=10',
>                          'dd: /dev/hwrng: No such device')
>          # verify that we indeed have virtio-net devices (without having the
>          # virtio-net driver handy)
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                                      'cat /sys/bus/ccw/devices/0.1.1111/cutype',
>                                      '3832/01')
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                      'cat /sys/bus/pci/devices/0005\:00\:00.0/subsystem_vendor',
>                      '0x1af4')
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                      'cat /sys/bus/pci/devices/0005\:00\:00.0/subsystem_device',
>                      '0x0001')
>          # check fid propagation
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'cat /sys/bus/pci/devices/000a\:00\:00.0/function_id',
>                          '0x0000000c')
>          # add another device
> @@ -134,7 +134,7 @@ def test_s390x_devices(self):
>          self.vm.command('device_add', driver='virtio-net-ccw',
>                          devno='fe.0.4711', id='net_4711')
>          self.wait_for_crw_reports()
> -        exec_command_and_wait_for_pattern(self, 'for i in 1 2 3 4 5 6 7 ; do '
> +        self.exec_command_and_wait_for_pattern('for i in 1 2 3 4 5 6 7 ; do '
>                      'if [ -e /sys/bus/ccw/devices/*4711 ]; then break; fi ;'
>                      'sleep 1 ; done ; ls /sys/bus/ccw/devices/',
>                      '0.0.4711')
> @@ -144,17 +144,17 @@ def test_s390x_devices(self):
>          self.vm.event_wait(name='DEVICE_DELETED',
>                             match={'data': {'device': 'net_4711'}})
>          self.wait_for_crw_reports()
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                                            'ls /sys/bus/ccw/devices/0.0.4711',
>                                            'No such file or directory')
>          # test the virtio-balloon device
> -        exec_command_and_wait_for_pattern(self, 'head -n 1 /proc/meminfo',
> +        self.exec_command_and_wait_for_pattern('head -n 1 /proc/meminfo',
>                                            'MemTotal:         115640 kB')
>          self.vm.command('human-monitor-command', command_line='balloon 96')
> -        exec_command_and_wait_for_pattern(self, 'head -n 1 /proc/meminfo',
> +        self.exec_command_and_wait_for_pattern('head -n 1 /proc/meminfo',
>                                            'MemTotal:          82872 kB')
>          self.vm.command('human-monitor-command', command_line='balloon 128')
> -        exec_command_and_wait_for_pattern(self, 'head -n 1 /proc/meminfo',
> +        self.exec_command_and_wait_for_pattern('head -n 1 /proc/meminfo',
>                                            'MemTotal:         115640 kB')
>
>
> @@ -203,23 +203,23 @@ def test_s390x_fedora(self):
>
>          # Some tests to see whether the CLI options have been considered:
>          self.log.info("Test whether QEMU CLI options have been considered")
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'while ! (dmesg | grep enP7p0s0) ; do sleep 1 ; done',
>                          'virtio_net virtio0 enP7p0s0: renamed')
> -        exec_command_and_wait_for_pattern(self, 'lspci',
> +        self.exec_command_and_wait_for_pattern('lspci',
>                               '0007:00:00.0 Class 0200: Device 1af4:1000')
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                               'cat /sys/class/net/enP7p0s0/address',
>                               '02:ca:fe:fa:ce:12')
> -        exec_command_and_wait_for_pattern(self, 'lscss', '0.1.9876')
> -        exec_command_and_wait_for_pattern(self, 'lscss', '0.2.5432')
> -        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
> +        self.exec_command_and_wait_for_pattern('lscss', '0.1.9876')
> +        self.exec_command_and_wait_for_pattern('lscss', '0.2.5432')
> +        self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
>                               'processors    : 4')
> -        exec_command_and_wait_for_pattern(self, 'grep MemTotal /proc/meminfo',
> +        self.exec_command_and_wait_for_pattern('grep MemTotal /proc/meminfo',
>                               'MemTotal:         499848 kB')
> -        exec_command_and_wait_for_pattern(self, 'grep Name /proc/sysinfo',
> +        self.exec_command_and_wait_for_pattern('grep Name /proc/sysinfo',
>                               'Extended Name:   Some Guest Name')
> -        exec_command_and_wait_for_pattern(self, 'grep UUID /proc/sysinfo',
> +        self.exec_command_and_wait_for_pattern('grep UUID /proc/sysinfo',
>                               '30de4fd9-b4d5-409e-86a5-09b387f70bfa')
>
>          # Disable blinking cursor, then write some stuff into the framebuffer.
> @@ -229,16 +229,16 @@ def test_s390x_fedora(self):
>          # can simply read the written "magic bytes" back from the PPM file to
>          # check whether the framebuffer is working as expected.
>          self.log.info("Test screendump of virtio-gpu device")
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'while ! (dmesg | grep gpudrmfb) ; do sleep 1 ; done',
>                          'virtio_gpudrmfb frame buffer device')
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>              'echo -e "\e[?25l" > /dev/tty0', ':/#')
> -        exec_command_and_wait_for_pattern(self, 'for ((i=0;i<250;i++)); do '
> +        self.exec_command_and_wait_for_pattern('for ((i=0;i<250;i++)); do '
>              'echo " The  qu ick  fo x j ump s o ver  a  laz y d og" >> fox.txt;'
>              'done',
>              ':/#')
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>              'dd if=fox.txt of=/dev/fb0 bs=1000 oflag=sync,nocache ; rm fox.txt',
>              '12+0 records out')
>          with tempfile.NamedTemporaryFile(suffix='.ppm',
> @@ -261,12 +261,12 @@ def test_s390x_fedora(self):
>                          id='cbe0')
>          self.vm.command('device_add', driver='virtio-crypto-ccw', id='crypdev0',
>                          cryptodev='cbe0', devno='fe.0.2342')
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'while ! (dmesg -c | grep Accelerator.device) ; do'
>                          ' sleep 1 ; done', 'Accelerator device is ready')
> -        exec_command_and_wait_for_pattern(self, 'lscss', '0.0.2342')
> +        self.exec_command_and_wait_for_pattern('lscss', '0.0.2342')
>          self.vm.command('device_del', id='crypdev0')
>          self.vm.command('object-del', id='cbe0')
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                          'while ! (dmesg -c | grep Start.virtcrypto_remove) ; do'
>                          ' sleep 1 ; done', 'Start virtcrypto_remove.')
> diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
> index 41d3e51164..b4a6d20770 100644
> --- a/tests/acceptance/multiprocess.py
> +++ b/tests/acceptance/multiprocess.py
> @@ -10,7 +10,6 @@
>  from avocado_qemu import Test
>  from avocado_qemu import wait_for_console_pattern
>  from avocado_qemu import ConsoleMixIn
> -from avocado_qemu import exec_command_and_wait_for_pattern
>
>  class Multiprocess(Test, ConsoleMixIn):
>      """
> @@ -60,7 +59,7 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line,
>          wait_for_console_pattern(self, 'as init process',
>                                   'Kernel panic - not syncing')
>          self.exec_command('mount -t sysfs sysfs /sys')
> -        exec_command_and_wait_for_pattern(self,
> +        self.exec_command_and_wait_for_pattern(
>                                            'cat /sys/bus/pci/devices/*/uevent',
>                                            'PCI_ID=1000:0012')
>
> diff --git a/tests/acceptance/virtio-gpu.py b/tests/acceptance/virtio-gpu.py
> index ab18cddbb7..4d65431ef1 100644
> --- a/tests/acceptance/virtio-gpu.py
> +++ b/tests/acceptance/virtio-gpu.py
> @@ -7,7 +7,7 @@
>  from avocado_qemu import Test
>  from avocado_qemu import BUILD_DIR
>  from avocado_qemu import wait_for_console_pattern
> -from avocado_qemu import exec_command_and_wait_for_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import is_readable_executable_file
>
>  from qemu.accel import kvm_available
> @@ -31,7 +31,7 @@ def pick_default_vug_bin():
>          return bld_dir_path
>
>
> -class VirtioGPUx86(Test):
> +class VirtioGPUx86(Test, ConsoleMixIn):

And here!

>      """
>      :avocado: tags=virtio-gpu
>      """
> @@ -92,9 +92,7 @@ def test_virtio_vga_virgl(self):
>              self.cancel("VirGL not enabled?")
>
>          self.wait_for_console_pattern("as init process")
> -        exec_command_and_wait_for_pattern(
> -            self, "/usr/sbin/modprobe virtio_gpu", ""
> -        )
> +        self.exec_command_and_wait_for_pattern("/usr/sbin/modprobe virtio_gpu", "")
>          self.wait_for_console_pattern("features: +virgl +edid")
>
>      def test_vhost_user_vga_virgl(self):
> @@ -157,9 +155,7 @@ def test_vhost_user_vga_virgl(self):
>          )
>          self.vm.launch()
>          self.wait_for_console_pattern("as init process")
> -        exec_command_and_wait_for_pattern(
> -            self, "/usr/sbin/modprobe virtio_gpu", ""
> -        )
> +        self.exec_command_and_wait_for_pattern("/usr/sbin/modprobe virtio_gpu", "")
>          self.wait_for_console_pattern("features: +virgl -edid")
>          self.vm.shutdown()
>          qemu_sock.close()
> --
> 2.29.2
>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest
  2021-05-03 22:43 ` [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest Wainer dos Santos Moschetta
  2021-05-04 16:01   ` Philippe Mathieu-Daudé
@ 2021-05-24 18:24   ` Willian Rampazzo
  1 sibling, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 18:24 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta
  Cc: Philippe Mathieu Daude, qemu-devel, Cleber Rosa Junior

On Mon, May 3, 2021 at 7:44 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> The Sun4uMachine class inherit from LinuxKernelTest to effectively only use
> the KERNEL_COMMON_COMMAND_LINE attribute. This change remove that unneeded
> dependency, making Sun4uMachine self-content.
>
> I took the occasion to delint the code: the unused os import was
> removed, imports were reordered, and the module has a docstring now.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/machine_sparc64_sun4u.py | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
>

Reviewed-by: Willian Rampazzo <willianr@redhat.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest
  2021-05-04 16:01   ` Philippe Mathieu-Daudé
@ 2021-05-24 18:30     ` Willian Rampazzo
  2021-05-24 18:54       ` Willian Rampazzo
  0 siblings, 1 reply; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 18:30 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Thomas Huth, qemu-devel, Wainer dos Santos Moschetta, Cleber Rosa Junior

On Tue, May 4, 2021 at 1:01 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> Hi Wainer,
>
> On 5/4/21 12:43 AM, Wainer dos Santos Moschetta wrote:
> > The Sun4uMachine class inherit from LinuxKernelTest to effectively only use
> > the KERNEL_COMMON_COMMAND_LINE attribute. This change remove that unneeded
> > dependency, making Sun4uMachine self-content.
>
> It is odd because the test boots a Linux kernel...
>
> Once you added ConsoleMixIn, LinuxKernelTest is left with
> 2 methods related to archive extraction. Not particularly
> specific to Linux kernel. Beside, shouldn't these methods
> be provided by Avocado directly, by avocado.utils.archive
> and avocado.utils.software_manager.backends?

Indeed, it makes a lot of sense to have those two methods inside the
Avocado utilities. I opened an issue on the Avocado side to track
that: https://github.com/avocado-framework/avocado/issues/4610.

>
> > I took the occasion to delint the code: the unused os import was
> > removed, imports were reordered, and the module has a docstring now.
> >
> > Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> > ---
> >  tests/acceptance/machine_sparc64_sun4u.py | 11 +++++------
> >  1 file changed, 5 insertions(+), 6 deletions(-)
>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 5/7] tests/acceptance: replay_kernel: Remove unused wait_for_console_pattern
  2021-05-03 22:43 ` [PATCH 5/7] tests/acceptance: replay_kernel: Remove unused wait_for_console_pattern Wainer dos Santos Moschetta
@ 2021-05-24 18:32   ` Willian Rampazzo
  0 siblings, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 18:32 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta
  Cc: Philippe Mathieu Daude, qemu-devel, Cleber Rosa Junior

On Mon, May 3, 2021 at 7:44 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> The ReplayKernelBase class uses the wait_for_console_pattern from its
> parent LinuxKernelTest class, thus it doesn't need to import that method
> from avocado_qemu.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/replay_kernel.py | 1 -
>  1 file changed, 1 deletion(-)
>

Reviewed-by: Willian Rampazzo <willianr@redhat.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 7/7] tests/acceptance: Move _console_interaction to ConsoleMixIn
  2021-05-03 22:43 ` [PATCH 7/7] tests/acceptance: Move _console_interaction " Wainer dos Santos Moschetta
@ 2021-05-24 18:37   ` Willian Rampazzo
  0 siblings, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 18:37 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta
  Cc: Philippe Mathieu Daude, qemu-devel, Cleber Rosa Junior

On Mon, May 3, 2021 at 7:44 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> This moved the last remaining _console_interaction() to ConsoleMixIn.
>
> None tests call it directly, so only the other methods in ConsoleMixIn
> needed to be adapted.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py | 57 +++++++++++------------
>  1 file changed, 28 insertions(+), 29 deletions(-)
>

Reviewed-by: Willian Rampazzo <willianr@redhat.com>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest
  2021-05-24 18:30     ` Willian Rampazzo
@ 2021-05-24 18:54       ` Willian Rampazzo
  0 siblings, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 18:54 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Thomas Huth, qemu-devel, Wainer dos Santos Moschetta, Cleber Rosa Junior

On Mon, May 24, 2021 at 3:30 PM Willian Rampazzo <wrampazz@redhat.com> wrote:
>
> On Tue, May 4, 2021 at 1:01 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
> >
> > Hi Wainer,
> >
> > On 5/4/21 12:43 AM, Wainer dos Santos Moschetta wrote:
> > > The Sun4uMachine class inherit from LinuxKernelTest to effectively only use
> > > the KERNEL_COMMON_COMMAND_LINE attribute. This change remove that unneeded
> > > dependency, making Sun4uMachine self-content.
> >
> > It is odd because the test boots a Linux kernel...
> >
> > Once you added ConsoleMixIn, LinuxKernelTest is left with
> > 2 methods related to archive extraction. Not particularly
> > specific to Linux kernel. Beside, shouldn't these methods
> > be provided by Avocado directly, by avocado.utils.archive
> > and avocado.utils.software_manager.backends?
>
> Indeed, it makes a lot of sense to have those two methods inside the
> Avocado utilities. I opened an issue on the Avocado side to track
> that: https://github.com/avocado-framework/avocado/issues/4610.

Beraldo reminded me there is already an issue to handle this:
https://github.com/avocado-framework/avocado/issues/3549.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 6/7] tests/acceptance: Move wait_for_console_pattern to ConsoleMixIn
  2021-05-03 22:43 ` [PATCH 6/7] tests/acceptance: Move wait_for_console_pattern to ConsoleMixIn Wainer dos Santos Moschetta
@ 2021-05-24 20:52   ` Willian Rampazzo
  0 siblings, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 20:52 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta
  Cc: Philippe Mathieu Daude, qemu-devel, Cleber Rosa Junior

On Mon, May 3, 2021 at 7:44 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> This moved wait_for_console_pattern() to ConsoleMixIn.
>
> By far this change required the most adaptations on tests.
>
> Notice that:
>
>  1) Some tests from boot_linux_console.py were using the wait_for_console_pattern()
>     from the avocado_qemu package rather than the overloaded method on the
>     LinuxKernelTest class, and that explains the explict calls to
>     ConsoleMixIn.wait_for_console_pattern().

I know it is not your fault, but I find confusing this mix of calls to
`wait_for_console_pattern` just because one call is using a default
`failure_message`.
What if we change the method from the LinuxKernelTest to something like:

    def wait_for_console_pattern(self, success_message, failure_message=None,
                                 vm=None):
        if failure_message is None:
            failure_message = 'Kernel panic - not syncing'
        wait_for_console_pattern(self, success_message,
                                 failure_message,
                                 vm=vm)

This way we could use the same call instead of mixing them.

>
>     Likewise in boot_xen.py file.
>
>  2) In virtiofs_submounts.py, wait_for_console_pattern() was imported but not used.
>
> Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
> ---
>  tests/acceptance/avocado_qemu/__init__.py    | 23 +++++++++-----------
>  tests/acceptance/boot_linux_console.py       | 14 ++++++------
>  tests/acceptance/boot_xen.py                 |  5 +++--
>  tests/acceptance/linux_ssh_mips_malta.py     |  8 +++----
>  tests/acceptance/machine_arm_canona1100.py   |  6 ++---
>  tests/acceptance/machine_arm_integratorcp.py |  8 +++----
>  tests/acceptance/machine_arm_n8x0.py         |  6 ++---
>  tests/acceptance/machine_microblaze.py       |  8 +++----
>  tests/acceptance/machine_mips_loongson3v.py  |  6 ++---
>  tests/acceptance/machine_mips_malta.py       |  6 ++---
>  tests/acceptance/machine_ppc.py              | 10 ++++-----
>  tests/acceptance/machine_rx_gdbsim.py        |  7 +++---
>  tests/acceptance/machine_s390_ccw_virtio.py  |  7 +++---
>  tests/acceptance/machine_sparc64_sun4u.py    |  6 ++---
>  tests/acceptance/machine_sparc_leon3.py      |  8 +++----
>  tests/acceptance/multiprocess.py             |  5 ++---
>  tests/acceptance/ppc_prep_40p.py             | 16 +++++++-------
>  tests/acceptance/virtio-gpu.py               |  4 +---
>  tests/acceptance/virtiofs_submounts.py       |  1 -
>  19 files changed, 73 insertions(+), 81 deletions(-)
>
> diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/avocado_qemu/__init__.py
> index 4a0129c0eb..b21f9ea3ff 100644
> --- a/tests/acceptance/avocado_qemu/__init__.py
> +++ b/tests/acceptance/avocado_qemu/__init__.py
> @@ -101,19 +101,6 @@ def _console_interaction(test, success_message, failure_message,
>                      (failure_message, success_message)
>              test.fail(fail)
>
> -def wait_for_console_pattern(test, success_message, failure_message=None,
> -                             vm=None):
> -    """
> -    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_interaction(test, success_message, failure_message, None, vm=vm)
> -
>  class ConsoleMixIn():
>      """Contains utilities for interacting with a guest via Console."""
>
> @@ -163,6 +150,16 @@ def interrupt_interactive_console_until_pattern(self, success_message,
>          _console_interaction(self, success_message, failure_message,
>                           interrupt_string, True)
>
> +    def wait_for_console_pattern(self, success_message, failure_message=None,
> +                             vm=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_interaction(self, success_message, failure_message, None, vm=vm)
> +
>  class Test(avocado.Test):
>      def _get_unique_tag_val(self, tag_name):
>          """
> diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py
> index 50e0a3fe79..e8d7a127fe 100644
> --- a/tests/acceptance/boot_linux_console.py
> +++ b/tests/acceptance/boot_linux_console.py
> @@ -17,7 +17,6 @@
>  from avocado import skipUnless
>  from avocado_qemu import Test
>  from avocado_qemu import ConsoleMixIn
> -from avocado_qemu import wait_for_console_pattern
>  from avocado.utils import process
>  from avocado.utils import archive
>  from avocado.utils.path import find_command, CmdNotFoundError
> @@ -48,7 +47,7 @@ class LinuxKernelTest(Test, ConsoleMixIn):
>      KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
>
>      def wait_for_console_pattern(self, success_message, vm=None):
> -        wait_for_console_pattern(self, success_message,
> +        super().wait_for_console_pattern(success_message,
>                                   failure_message='Kernel panic - not syncing',
>                                   vm=vm)
>
> @@ -262,7 +261,7 @@ def test_mips64el_malta_5KEc_cpio(self):
>                           '-append', kernel_command_line,
>                           '-no-reboot')
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'Boot successful.')
> +        ConsoleMixIn.wait_for_console_pattern(self, 'Boot successful.')
>
>          self.exec_command_and_wait_for_pattern('cat /proc/cpuinfo',
>                                                 'MIPS 5KE')
> @@ -877,7 +876,7 @@ def test_arm_orangepi_uboot_netbsd9(self):
>                           '-global', 'allwinner-rtc.base-year=2000',
>                           '-no-reboot')
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
> +        ConsoleMixIn.wait_for_console_pattern(self, 'U-Boot 2020.01+dfsg-1')
>          self.interrupt_interactive_console_until_pattern(
>                                         'Hit any key to stop autoboot:',
>                                         'switch to partitions #0, OK')
> @@ -897,10 +896,11 @@ def test_arm_orangepi_uboot_netbsd9(self):
>
>          self.exec_command_and_wait_for_pattern('boot',
>                                            'Booting kernel from Legacy Image')
> -        wait_for_console_pattern(self, 'Starting kernel ...')
> -        wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
> +        ConsoleMixIn.wait_for_console_pattern(self, 'Starting kernel ...')
> +        ConsoleMixIn.wait_for_console_pattern(self, 'NetBSD 9.0 (GENERIC)')
>          # Wait for user-space
> -        wait_for_console_pattern(self, 'Starting root file system check')
> +        ConsoleMixIn.wait_for_console_pattern(self,
> +                                            'Starting root file system check')
>
>      def test_aarch64_raspi3_atf(self):
>          """
> diff --git a/tests/acceptance/boot_xen.py b/tests/acceptance/boot_xen.py
> index 75c2d44492..9b5506398e 100644
> --- a/tests/acceptance/boot_xen.py
> +++ b/tests/acceptance/boot_xen.py
> @@ -14,7 +14,6 @@
>  import os
>
>  from avocado import skipIf
> -from avocado_qemu import wait_for_console_pattern
>  from boot_linux_console import LinuxKernelTest
>
>
> @@ -59,7 +58,9 @@ def launch_xen(self, xen_path):
>          self.vm.launch()
>
>          console_pattern = 'VFS: Cannot open root device'
> -        wait_for_console_pattern(self, console_pattern, "Panic on CPU 0:")
> +        # pylint: disable=E1003
> +        super(LinuxKernelTest, self).wait_for_console_pattern(console_pattern,
> +            "Panic on CPU 0:")
>
>
>  class BootXen(BootXenBase):
> diff --git a/tests/acceptance/linux_ssh_mips_malta.py b/tests/acceptance/linux_ssh_mips_malta.py
> index 6dbd02d49d..8d8531b6c5 100644
> --- a/tests/acceptance/linux_ssh_mips_malta.py
> +++ b/tests/acceptance/linux_ssh_mips_malta.py
> @@ -13,13 +13,13 @@
>
>  from avocado import skipUnless
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado.utils import process
>  from avocado.utils import archive
>  from avocado.utils import ssh
>
>
> -class LinuxSSH(Test):
> +class LinuxSSH(Test, ConsoleMixIn):

Same comment about the order of the classes here that I made on
previous patches.

>
>      timeout = 150 # Not for 'configure --enable-debug --enable-debug-tcg'
>
> @@ -126,7 +126,7 @@ def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path):
>
>          self.log.info('VM launched, waiting for sshd')
>          console_pattern = 'Starting OpenBSD Secure Shell server: sshd'
> -        wait_for_console_pattern(self, console_pattern, 'Oops')
> +        self.wait_for_console_pattern(console_pattern, 'Oops')
>          self.log.info('sshd ready')
>
>          self.ssh_connect('root', 'root')
> @@ -134,7 +134,7 @@ def boot_debian_wheezy_image_and_ssh_login(self, endianess, kernel_path):
>      def shutdown_via_ssh(self):
>          self.ssh_command('poweroff')
>          self.ssh_disconnect_vm()
> -        wait_for_console_pattern(self, 'Power down', 'Oops')
> +        self.wait_for_console_pattern('Power down', 'Oops')
>
>      def ssh_command_output_contains(self, cmd, exp):
>          stdout, _ = self.ssh_command(cmd)
> diff --git a/tests/acceptance/machine_arm_canona1100.py b/tests/acceptance/machine_arm_canona1100.py
> index 0e5c43dbcf..945aa83270 100644
> --- a/tests/acceptance/machine_arm_canona1100.py
> +++ b/tests/acceptance/machine_arm_canona1100.py
> @@ -9,10 +9,10 @@
>  # later.  See the COPYING file in the top-level directory.
>
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado.utils import archive
>
> -class CanonA1100Machine(Test):
> +class CanonA1100Machine(Test, ConsoleMixIn):

And here!

>      """Boots the barebox firmware and checks that the console is operational"""
>
>      timeout = 90
> @@ -32,4 +32,4 @@ def test_arm_canona1100(self):
>          self.vm.add_args('-bios',
>                           self.workdir + '/day18/barebox.canon-a1100.bin')
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'running /env/bin/init')
> +        self.wait_for_console_pattern('running /env/bin/init')
> diff --git a/tests/acceptance/machine_arm_integratorcp.py b/tests/acceptance/machine_arm_integratorcp.py
> index 49c8ebff78..490bafa571 100644
> --- a/tests/acceptance/machine_arm_integratorcp.py
> +++ b/tests/acceptance/machine_arm_integratorcp.py
> @@ -13,7 +13,7 @@
>
>  from avocado import skipUnless
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>
>
>  NUMPY_AVAILABLE = True
> @@ -29,7 +29,7 @@
>      CV2_AVAILABLE = False
>
>
> -class IntegratorMachine(Test):
> +class IntegratorMachine(Test, ConsoleMixIn):

And here!

>
>      timeout = 90
>
> @@ -59,7 +59,7 @@ def test_integratorcp_console(self):
>          :avocado: tags=device:pl011
>          """
>          self.boot_integratorcp()
> -        wait_for_console_pattern(self, 'Log in as root')
> +        self.wait_for_console_pattern('Log in as root')
>
>      @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
>      @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
> @@ -80,7 +80,7 @@ def test_framebuffer_tux_logo(self):
>
>          self.boot_integratorcp()
>          framebuffer_ready = 'Console: switching to colour frame buffer device'
> -        wait_for_console_pattern(self, framebuffer_ready)
> +        self.wait_for_console_pattern(framebuffer_ready)
>          self.vm.command('human-monitor-command', command_line='stop')
>          self.vm.command('human-monitor-command',
>                          command_line='screendump %s' % screendump_path)
> diff --git a/tests/acceptance/machine_arm_n8x0.py b/tests/acceptance/machine_arm_n8x0.py
> index e5741f2d8d..403415243e 100644
> --- a/tests/acceptance/machine_arm_n8x0.py
> +++ b/tests/acceptance/machine_arm_n8x0.py
> @@ -12,9 +12,9 @@
>
>  from avocado import skipUnless
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>
> -class N8x0Machine(Test):
> +class N8x0Machine(Test, ConsoleMixIn):

And here!

>      """Boots the Linux kernel and checks that the console is operational"""
>
>      timeout = 90
> @@ -30,7 +30,7 @@ def __do_test_n8x0(self):
>          self.vm.add_args('-kernel', kernel_path,
>                           '-append', 'printk.time=0 console=ttyS1')
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'TSC2005 driver initializing')
> +        self.wait_for_console_pattern('TSC2005 driver initializing')
>
>      @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
>      def test_n800(self):
> diff --git a/tests/acceptance/machine_microblaze.py b/tests/acceptance/machine_microblaze.py
> index 7f6d18495d..d6ecd69e95 100644
> --- a/tests/acceptance/machine_microblaze.py
> +++ b/tests/acceptance/machine_microblaze.py
> @@ -6,10 +6,10 @@
>  # later. See the COPYING file in the top-level directory.
>
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado.utils import archive
>
> -class MicroblazeMachine(Test):
> +class MicroblazeMachine(Test, ConsoleMixIn):

One more :)

>
>      timeout = 90
>
> @@ -27,8 +27,8 @@ def test_microblaze_s3adsp1800(self):
>          self.vm.set_console()
>          self.vm.add_args('-kernel', self.workdir + '/day17/ballerina.bin')
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'This architecture does not have '
> -                                       'kernel memory protection')
> +        self.wait_for_console_pattern('This architecture does not have '
> +                                      'kernel memory protection')
>          # Note:
>          # The kernel sometimes gets stuck after the "This architecture ..."
>          # message, that's why we don't test for a later string here. This
> diff --git a/tests/acceptance/machine_mips_loongson3v.py b/tests/acceptance/machine_mips_loongson3v.py
> index 85b131a40f..58242d5c9b 100644
> --- a/tests/acceptance/machine_mips_loongson3v.py
> +++ b/tests/acceptance/machine_mips_loongson3v.py
> @@ -12,9 +12,9 @@
>
>  from avocado import skipUnless
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>
> -class MipsLoongson3v(Test):
> +class MipsLoongson3v(Test, ConsoleMixIn):

Same here!

>      timeout = 60
>
>      @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
> @@ -36,4 +36,4 @@ def test_pmon_serial_console(self):
>          self.vm.set_console()
>          self.vm.add_args('-bios', pmon_path)
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'CPU GODSON3 BogoMIPS:')
> +        self.wait_for_console_pattern('CPU GODSON3 BogoMIPS:')
> diff --git a/tests/acceptance/machine_mips_malta.py b/tests/acceptance/machine_mips_malta.py
> index 7c9a4ee4d2..e05fa862cc 100644
> --- a/tests/acceptance/machine_mips_malta.py
> +++ b/tests/acceptance/machine_mips_malta.py
> @@ -13,7 +13,7 @@
>
>  from avocado import skipUnless
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado.utils import archive
>  from avocado import skipIf
>
> @@ -33,7 +33,7 @@
>
>  @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
>  @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
> -class MaltaMachineFramebuffer(Test):
> +class MaltaMachineFramebuffer(Test, ConsoleMixIn):

Is this the last? :D

>
>      timeout = 30
>
> @@ -68,7 +68,7 @@ def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
>                           '-append', kernel_command_line)
>          self.vm.launch()
>          framebuffer_ready = 'Console: switching to colour frame buffer device'
> -        wait_for_console_pattern(self, framebuffer_ready,
> +        self.wait_for_console_pattern(framebuffer_ready,
>                                   failure_message='Kernel panic - not syncing')
>          self.vm.command('human-monitor-command', command_line='stop')
>          self.vm.command('human-monitor-command',
> diff --git a/tests/acceptance/machine_ppc.py b/tests/acceptance/machine_ppc.py
> index a836e2496f..61f378a3a2 100644
> --- a/tests/acceptance/machine_ppc.py
> +++ b/tests/acceptance/machine_ppc.py
> @@ -7,9 +7,9 @@
>
>  from avocado.utils import archive
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>
> -class PpcMachine(Test):
> +class PpcMachine(Test, ConsoleMixIn):

No, that was not the last. One more here!

>
>      timeout = 90
>      KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
> @@ -32,7 +32,7 @@ def test_ppc64_pseries(self):
>                           '-append', kernel_command_line)
>          self.vm.launch()
>          console_pattern = 'Kernel command line: %s' % kernel_command_line
> -        wait_for_console_pattern(self, console_pattern, self.panic_message)
> +        self.wait_for_console_pattern(console_pattern, self.panic_message)
>
>      def test_ppc_mpc8544ds(self):
>          """
> @@ -47,7 +47,7 @@ def test_ppc_mpc8544ds(self):
>          self.vm.set_console()
>          self.vm.add_args('-kernel', self.workdir + '/creek/creek.bin')
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'QEMU advent calendar 2020',
> +        self.wait_for_console_pattern('QEMU advent calendar 2020',
>                                   self.panic_message)
>
>      def test_ppc_virtex_ml507(self):
> @@ -65,5 +65,5 @@ def test_ppc_virtex_ml507(self):
>                           '-dtb', self.workdir + '/hippo/virtex440-ml507.dtb',
>                           '-m', '512')
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'QEMU advent calendar 2020',
> +        self.wait_for_console_pattern('QEMU advent calendar 2020',
>                                   self.panic_message)
> diff --git a/tests/acceptance/machine_rx_gdbsim.py b/tests/acceptance/machine_rx_gdbsim.py
> index a893273bad..7a77cfe116 100644
> --- a/tests/acceptance/machine_rx_gdbsim.py
> +++ b/tests/acceptance/machine_rx_gdbsim.py
> @@ -13,7 +13,6 @@
>  from avocado import skipIf
>  from avocado_qemu import Test
>  from avocado_qemu import ConsoleMixIn
> -from avocado_qemu import wait_for_console_pattern
>  from avocado.utils import archive
>
>
> @@ -41,7 +40,7 @@ def test_uboot(self):
>                           '-no-reboot')
>          self.vm.launch()
>          uboot_version = 'U-Boot 2016.05-rc3-23705-ga1ef3c71cb-dirty'
> -        wait_for_console_pattern(self, uboot_version)
> +        self.wait_for_console_pattern(uboot_version)
>          gcc_version = 'rx-unknown-linux-gcc (GCC) 9.0.0 20181105 (experimental)'
>          # FIXME limit baudrate on chardev, else we type too fast
>          #self.exec_command_and_wait_for_pattern('version', gcc_version)
> @@ -68,6 +67,6 @@ def test_linux_sash(self):
>                           '-dtb', dtb_path,
>                           '-no-reboot')
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'Sash command shell (version 1.1.1)',
> -                                 failure_message='Kernel panic - not syncing')
> +        self.wait_for_console_pattern('Sash command shell (version 1.1.1)',
> +                                      failure_message='Kernel panic - not syncing')
>          self.exec_command_and_wait_for_pattern('printenv', 'TERM=linux')
> diff --git a/tests/acceptance/machine_s390_ccw_virtio.py b/tests/acceptance/machine_s390_ccw_virtio.py
> index 537393c42f..bc1606ae43 100644
> --- a/tests/acceptance/machine_s390_ccw_virtio.py
> +++ b/tests/acceptance/machine_s390_ccw_virtio.py
> @@ -15,7 +15,6 @@
>  from avocado import skipIf
>  from avocado_qemu import Test
>  from avocado_qemu import ConsoleMixIn
> -from avocado_qemu import wait_for_console_pattern
>  from avocado.utils import archive
>
>  class S390CCWVirtioMachine(Test, ConsoleMixIn):
> @@ -24,9 +23,9 @@ class S390CCWVirtioMachine(Test, ConsoleMixIn):
>      timeout = 120
>
>      def wait_for_console_pattern(self, success_message, vm=None):
> -        wait_for_console_pattern(self, success_message,
> -                                 failure_message='Kernel panic - not syncing',
> -                                 vm=vm)
> +        super().wait_for_console_pattern(success_message,
> +                                       failure_message='Kernel panic - not syncing',
> +                                       vm=vm)
>
>      def wait_for_crw_reports(self):
>          self.exec_command_and_wait_for_pattern(
> diff --git a/tests/acceptance/machine_sparc64_sun4u.py b/tests/acceptance/machine_sparc64_sun4u.py
> index c7ad474bdc..810f11b049 100644
> --- a/tests/acceptance/machine_sparc64_sun4u.py
> +++ b/tests/acceptance/machine_sparc64_sun4u.py
> @@ -9,10 +9,10 @@
>  # later. See the COPYING file in the top-level directory.
>
>  from avocado.utils import archive
> +from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
>
> -class Sun4uMachine(Test):
> +class Sun4uMachine(Test, ConsoleMixIn):

One more here!

>      """Boots the Linux kernel and checks that the console is operational"""
>
>      timeout = 90
> @@ -32,4 +32,4 @@ def test_sparc64_sun4u(self):
>          self.vm.add_args('-kernel', self.workdir + '/day23/vmlinux',
>                           '-append', self.KERNEL_COMMON_COMMAND_LINE)
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'Starting logging: OK')
> +        self.wait_for_console_pattern('Starting logging: OK')
> diff --git a/tests/acceptance/machine_sparc_leon3.py b/tests/acceptance/machine_sparc_leon3.py
> index 2405cd7a0d..1bf7812987 100644
> --- a/tests/acceptance/machine_sparc_leon3.py
> +++ b/tests/acceptance/machine_sparc_leon3.py
> @@ -6,11 +6,11 @@
>  # later. See the COPYING file in the top-level directory.
>
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>  from avocado import skip
>
>
> -class Leon3Machine(Test):
> +class Leon3Machine(Test, ConsoleMixIn):

Another here!

>
>      timeout = 60
>
> @@ -33,5 +33,5 @@ def test_leon3_helenos_uimage(self):
>
>          self.vm.launch()
>
> -        wait_for_console_pattern(self, 'Copyright (c) 2001-2014 HelenOS project')
> -        wait_for_console_pattern(self, 'Booting the kernel ...')
> +        self.wait_for_console_pattern('Copyright (c) 2001-2014 HelenOS project')
> +        self.wait_for_console_pattern('Booting the kernel ...')
> diff --git a/tests/acceptance/multiprocess.py b/tests/acceptance/multiprocess.py
> index b4a6d20770..9f487fb7bc 100644
> --- a/tests/acceptance/multiprocess.py
> +++ b/tests/acceptance/multiprocess.py
> @@ -8,7 +8,6 @@
>  import socket
>
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
>  from avocado_qemu import ConsoleMixIn
>
>  class Multiprocess(Test, ConsoleMixIn):
> @@ -56,8 +55,8 @@ def do_test(self, kernel_url, initrd_url, kernel_command_line,
>                           'x-pci-proxy-dev,'
>                           'id=lsi1,fd='+str(proxy_sock.fileno()))
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'as init process',
> -                                 'Kernel panic - not syncing')
> +        self.wait_for_console_pattern('as init process',
> +                                      'Kernel panic - not syncing')
>          self.exec_command('mount -t sysfs sysfs /sys')
>          self.exec_command_and_wait_for_pattern(
>                                            'cat /sys/bus/pci/devices/*/uevent',
> diff --git a/tests/acceptance/ppc_prep_40p.py b/tests/acceptance/ppc_prep_40p.py
> index 96ba13b894..35475892be 100644
> --- a/tests/acceptance/ppc_prep_40p.py
> +++ b/tests/acceptance/ppc_prep_40p.py
> @@ -10,10 +10,10 @@
>  from avocado import skipIf
>  from avocado import skipUnless
>  from avocado_qemu import Test
> -from avocado_qemu import wait_for_console_pattern
> +from avocado_qemu import ConsoleMixIn
>
>
> -class IbmPrep40pMachine(Test):
> +class IbmPrep40pMachine(Test, ConsoleMixIn):

And here!

>
>      timeout = 60
>
> @@ -44,8 +44,8 @@ def test_factory_firmware_and_netbsd(self):
>                           '-fda', drive_path)
>          self.vm.launch()
>          os_banner = 'NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:49:40 PST 2007'
> -        wait_for_console_pattern(self, os_banner)
> -        wait_for_console_pattern(self, 'Model: IBM PPS Model 6015')
> +        self.wait_for_console_pattern(os_banner)
> +        self.wait_for_console_pattern('Model: IBM PPS Model 6015')
>
>      def test_openbios_192m(self):
>          """
> @@ -56,9 +56,9 @@ def test_openbios_192m(self):
>          self.vm.add_args('-m', '192') # test fw_cfg
>
>          self.vm.launch()
> -        wait_for_console_pattern(self, '>> OpenBIOS')
> -        wait_for_console_pattern(self, '>> Memory: 192M')
> -        wait_for_console_pattern(self, '>> CPU type PowerPC,604')
> +        self.wait_for_console_pattern('>> OpenBIOS')
> +        self.wait_for_console_pattern('>> Memory: 192M')
> +        self.wait_for_console_pattern('>> CPU type PowerPC,604')
>
>      def test_openbios_and_netbsd(self):
>          """
> @@ -75,4 +75,4 @@ def test_openbios_and_netbsd(self):
>                           '-boot', 'd')
>
>          self.vm.launch()
> -        wait_for_console_pattern(self, 'NetBSD/prep BOOT, Revision 1.9')
> +        self.wait_for_console_pattern('NetBSD/prep BOOT, Revision 1.9')
> diff --git a/tests/acceptance/virtio-gpu.py b/tests/acceptance/virtio-gpu.py
> index 4d65431ef1..a7e6bbb8a2 100644
> --- a/tests/acceptance/virtio-gpu.py
> +++ b/tests/acceptance/virtio-gpu.py
> @@ -6,7 +6,6 @@
>
>  from avocado_qemu import Test
>  from avocado_qemu import BUILD_DIR
> -from avocado_qemu import wait_for_console_pattern
>  from avocado_qemu import ConsoleMixIn
>  from avocado_qemu import is_readable_executable_file
>
> @@ -49,8 +48,7 @@ class VirtioGPUx86(Test, ConsoleMixIn):
>      )
>
>      def wait_for_console_pattern(self, success_message, vm=None):
> -        wait_for_console_pattern(
> -            self,
> +        super().wait_for_console_pattern(
>              success_message,
>              failure_message="Kernel panic - not syncing",
>              vm=vm,
> diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virtiofs_submounts.py
> index 46fa65392a..ad1999a372 100644
> --- a/tests/acceptance/virtiofs_submounts.py
> +++ b/tests/acceptance/virtiofs_submounts.py
> @@ -6,7 +6,6 @@
>
>  from avocado import skipUnless
>  from avocado_qemu import LinuxTest, BUILD_DIR
> -from avocado_qemu import wait_for_console_pattern
>  from avocado.utils import ssh
>
>
> --
> 2.29.2
>



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn
  2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
                   ` (6 preceding siblings ...)
  2021-05-03 22:43 ` [PATCH 7/7] tests/acceptance: Move _console_interaction " Wainer dos Santos Moschetta
@ 2021-05-24 20:58 ` Willian Rampazzo
  7 siblings, 0 replies; 19+ messages in thread
From: Willian Rampazzo @ 2021-05-24 20:58 UTC (permalink / raw)
  To: Wainer dos Santos Moschetta
  Cc: Philippe Mathieu Daude, qemu-devel, Cleber Rosa Junior

Hi Wainer,

On Mon, May 3, 2021 at 7:43 PM Wainer dos Santos Moschetta
<wainersm@redhat.com> wrote:
>
> The avocado_qemu package provides the following methods to interact with the
> guest via console, which are mainly used on the acceptance boot tests:
>
>  exec_command(), exec_command_and_wait_for_pattern(), wait_for_console_pattern(),
>  interrupt_interactive_console_until_pattern()
>
> Those methods are loosely defined in avocado_qemu/__init__.py. Because that file is expected to
> grow, I thought that for the sake of keeping it organized it would be better to logically group
> them. So in this series I create the ConsoleMixIn class to be the new home for the console
> methods. An alternative approach could be to create a separated package, however because
> they are just a few methods at the moment, I prefered not to break avocado_qemu into smaller pieces.
>
> As the "MixIn" in the name implies, the class is meant to be used as a mixin on the test class. Here
> I am following an idea introduced by Cleber in [1].
>
> This series was tested on CI (https://gitlab.com/wainersm/qemu/-/pipelines/296412039)
>
> [1] http://next.patchew.org/QEMU/20210412044644.55083-1-crosa@redhat.com/
>

So, personally, I found this an interesting change, it keeps the code
more organized IMO.

I have mixed feelings about using mixin for something that should be
straightforward, like develop tests on a project where python is not
the primary programming language. I would imagine that the mixin
pattern is nice inside core code and functions or methods are more
suitable for test writers.

Anyway, I'm not against it and will not block the series if others are
okay with the changes.



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2021-05-24 21:00 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-03 22:43 [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Wainer dos Santos Moschetta
2021-05-03 22:43 ` [PATCH 1/7] tests/acceptance: Introduce the ConsoleMixIn class Wainer dos Santos Moschetta
2021-05-24 18:14   ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 2/7] tests/acceptance: Move exec_command to ConsoleMixIn Wainer dos Santos Moschetta
2021-05-24 18:16   ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 3/7] tests/acceptance: Move exec_command_and_wait_for_pattern " Wainer dos Santos Moschetta
2021-05-24 18:21   ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 4/7] tests/acceptance: Sun4uMachine: Remove dependency to LinuxKernelTest Wainer dos Santos Moschetta
2021-05-04 16:01   ` Philippe Mathieu-Daudé
2021-05-24 18:30     ` Willian Rampazzo
2021-05-24 18:54       ` Willian Rampazzo
2021-05-24 18:24   ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 5/7] tests/acceptance: replay_kernel: Remove unused wait_for_console_pattern Wainer dos Santos Moschetta
2021-05-24 18:32   ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 6/7] tests/acceptance: Move wait_for_console_pattern to ConsoleMixIn Wainer dos Santos Moschetta
2021-05-24 20:52   ` Willian Rampazzo
2021-05-03 22:43 ` [PATCH 7/7] tests/acceptance: Move _console_interaction " Wainer dos Santos Moschetta
2021-05-24 18:37   ` Willian Rampazzo
2021-05-24 20:58 ` [PATCH 0/7] tests/acceptance: Introducing the ConsoleMixIn Willian Rampazzo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).