Skip to contentSkip to conversation

tests/functional: remove last use of avocado.utils

PATCH In review Daniel P. Berrangé 2 participants 19 messages Sep 12, 2025 – Sep 15, 2025

lore
Share & tools
lore
#7 lore raw

PATCH 4/6 tests/functional: drop datadrainer class in reverse debugging

In reply to Daniel P. Berrangé

The reverse debugging test uses the avocado datadrainer class to create a background thread that reads from the console socket and dumps it via python logger.

Most tests log console output as a side effect of doing calls to match strings, but this test never tries to match anything.

This isn't critical, so just drop the functionality.

---
 tests/functional/reverse_debugging.py | 6 ------
 1 file changed, 6 deletions(-)
tests/functional/reverse_debugging.py +0 -6
index 1b880cda8f..9c89f5c897 100644
@@ -35,8 +35,6 @@ class ReverseDebugging(LinuxKernelTest):
     endian_is_le = True
 
     def run_vm(self, record, shift, args, replay_path, image_path, port):
-        from avocado.utils import datadrainer
-
         logger = logging.getLogger('replay')
         vm = self.get_vm(name='record' if record else 'replay')
         vm.set_console()
@@ -54,10 +52,6 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
         if args:
             vm.add_args(*args)
         vm.launch()
-        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
-                                    logger=self.log.getChild('console'),
-                                    stop_check=(lambda : not vm.is_running()))
-        console_drainer.start()
         return vm
 
     @staticmethod
Signature · 1 line
2.50.1
#12 lore raw

PATCH 5/6 tests/functional: close GDB socket in reverse debugging test

In reply to Daniel P. Berrangé

The GDB socket FD is leaked currently resulting in a warning from python about the unclosed resource.

---
 tests/functional/qemu_test/gdb.py     | 4 ++++
 tests/functional/reverse_debugging.py | 2 ++
 2 files changed, 6 insertions(+)
tests/functional/qemu_test/gdb.py +4 -0
index 913e3b65ab..1b463e8a82 100644
@@ -231,3 +231,7 @@ def connect(self):
 
         if self._extended_mode:
             self.set_extended_mode()
+
+    def close(self):
+        self._socket.close()
+        self._socket = None
tests/functional/reverse_debugging.py +2 -0
index 9c89f5c897..fbb5adbcce 100644
@@ -186,5 +186,7 @@ def reverse_debugging(self, shift=7, args=None):
         self.check_pc(g, steps[-1])
         logger.info('successfully reached %x' % steps[-1])
 
+        g.close()
+
         logger.info('exiting gdb and qemu')
         vm.shutdown()
Signature · 1 line
2.50.1
#14 lore raw

PATCH 6/6 tests/functional: use self.log for all logging

In reply to Daniel P. Berrangé

Some tests are creating their on logger category which means any output they log is not captured in base.log.

---
 tests/functional/aarch64/test_virt.py     |  4 +--
 tests/functional/arm/test_integratorcp.py |  3 +-
 tests/functional/mips64el/test_malta.py   |  3 +-
 tests/functional/replay_kernel.py         | 16 ++++-----
 tests/functional/reverse_debugging.py     | 41 +++++++++++------------
 tests/functional/x86_64/test_acpi_bits.py | 31 +++++++++--------
 6 files changed, 44 insertions(+), 54 deletions(-)
tests/functional/aarch64/test_virt.py +1 -3
index 4d0ad90ff8..63071f9b51 100755
@@ -72,8 +72,6 @@ def common_aarch64_virt(self, machine):
         self.set_machine('virt')
         self.require_accelerator("tcg")
 
-        logger = logging.getLogger('aarch64_virt')
-
         kernel_path = self.ASSET_KERNEL.fetch()
 
         self.vm.set_console()
@@ -91,7 +89,7 @@ def common_aarch64_virt(self, machine):
                          'rng-random,id=rng0,filename=/dev/urandom')
 
         # Also add a scratch block device
-        logger.info('creating scratch qcow2 image')
+        self.log.info('creating scratch qcow2 image')
         image_path = self.scratch_file('scratch.qcow2')
         qemu_img = get_qemu_img(self)
         check_call([qemu_img, 'create', '-f', 'qcow2', image_path, '8M'],
tests/functional/arm/test_integratorcp.py +1 -2
index 4f00924aa0..23ae919359 100755
@@ -77,7 +77,6 @@ def test_framebuffer_tux_logo(self):
                           command_line='screendump %s' % screendump_path)
         if 'unknown command' in res:
             self.skipTest('screendump not available')
-        logger = logging.getLogger('framebuffer')
 
         cpu_count = 1
         match_threshold = 0.92
@@ -88,7 +87,7 @@ def test_framebuffer_tux_logo(self):
         loc = np.where(result >= match_threshold)
         tux_count = 0
         for tux_count, pt in enumerate(zip(*loc[::-1]), start=1):
-            logger.debug('found Tux at position [x, y] = %s', pt)
+            self.log.debug('found Tux at position [x, y] = %s', pt)
         self.assertGreaterEqual(tux_count, cpu_count)
 
 if __name__ == '__main__':
tests/functional/mips64el/test_malta.py +1 -2
index 8fdc49b300..170147bfcc 100755
@@ -159,7 +159,6 @@ def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
                           command_line='screendump %s' % screendump_path)
         if 'unknown command' in res:
             self.skipTest('screendump not available')
-        logger = logging.getLogger('framebuffer')
 
         match_threshold = 0.95
         screendump_bgr = cv2.imread(screendump_path, cv2.IMREAD_COLOR)
@@ -171,7 +170,7 @@ def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
         h, w = tuxlogo_bgr.shape[:2]
         debug_png = os.getenv('QEMU_TEST_CV2_SCREENDUMP_PNG_PATH')
         for tuxlogo_count, pt in enumerate(zip(*loc[::-1]), start=1):
-            logger.debug('found Tux at position (x, y) = %s', pt)
+            self.log.debug('found Tux at position (x, y) = %s', pt)
             cv2.rectangle(screendump_bgr, pt,
                           (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
         if debug_png:
tests/functional/replay_kernel.py +7 -9
index 80795eb052..acb1d29a1b 100644
@@ -32,15 +32,14 @@ def run_vm(self, kernel_path, kernel_command_line, console_pattern,
         # icount requires TCG to be available
         self.require_accelerator('tcg')
 
-        logger = logging.getLogger('replay')
         start_time = time.time()
         vm = self.get_vm(name='recording' if record else 'replay')
         vm.set_console()
         if record:
-            logger.info('recording the execution...')
+            self.log.info('recording the execution...')
             mode = 'record'
         else:
-            logger.info('replaying the execution...')
+            self.log.info('replaying the execution...')
             mode = 'replay'
         vm.add_args('-icount', 'shift=%s,rr=%s,rrfile=%s' %
                     (shift, mode, replay_path),
@@ -54,15 +53,15 @@ def run_vm(self, kernel_path, kernel_command_line, console_pattern,
         self.wait_for_console_pattern(console_pattern, vm)
         if record:
             vm.shutdown()
-            logger.info('finished the recording with log size %s bytes'
+            self.log.info('finished the recording with log size %s bytes'
                         % os.path.getsize(replay_path))
             self.run_replay_dump(replay_path)
-            logger.info('successfully tested replay-dump.py')
+            self.log.info('successfully tested replay-dump.py')
         else:
             vm.wait()
-            logger.info('successfully finished the replay')
+            self.log.info('successfully finished the replay')
         elapsed = time.time() - start_time
-        logger.info('elapsed time %.2f sec' % elapsed)
+        self.log.info('elapsed time %.2f sec' % elapsed)
         return elapsed
 
     def run_replay_dump(self, replay_path):
@@ -80,5 +79,4 @@ def run_rr(self, kernel_path, kernel_command_line, console_pattern,
                          True, shift, args, replay_path)
         t2 = self.run_vm(kernel_path, kernel_command_line, console_pattern,
                          False, shift, args, replay_path)
-        logger = logging.getLogger('replay')
-        logger.info('replay overhead {:.2%}'.format(t2 / t1 - 1))
+        self.log.info('replay overhead {:.2%}'.format(t2 / t1 - 1))
tests/functional/reverse_debugging.py +19 -22

122 lines not on this page · raw message

tests/functional/x86_64/test_acpi_bits.py +15 -16
index 8e0563a97b..9a2816533d 100755
@@ -121,10 +121,10 @@ def __init__(self, *args, **kwargs):
         self._debugcon_log = 'debugcon-log.txt'
 
     def _print_log(self, log):
-        self.logger.info('\nlogs from biosbits follows:')
-        self.logger.info('==========================================\n')
-        self.logger.info(log)
-        self.logger.info('==========================================\n')
+        self.log.info('\nlogs from biosbits follows:')
+        self.log.info('==========================================\n')
+        self.log.info(log)
+        self.log.info('==========================================\n')
 
     def copy_bits_config(self):
         """ copies the bios bits config file into bits.
@@ -138,8 +138,8 @@ def copy_bits_config(self):
         self.assertTrue(os.path.exists(bits_config_file))
         self.assertTrue(os.path.exists(target_config_dir))
         shutil.copy2(bits_config_file, target_config_dir)
-        self.logger.info('copied config file %s to %s',
-                         bits_config_file, target_config_dir)
+        self.log.info('copied config file %s to %s',
+                      bits_config_file, target_config_dir)
 
     def copy_test_scripts(self):
         """copies the python test scripts into bits. """
@@ -163,8 +163,8 @@ def copy_test_scripts(self):
                 newfilename = os.path.splitext(filename)[0] + '.py'
                 shutil.copy2(os.path.join(bits_test_dir, filename),
                              os.path.join(target_test_dir, newfilename))
-                self.logger.info('copied test file %s to %s',
-                                 filename, target_test_dir)
+                self.log.info('copied test file %s to %s',
+                              filename, target_test_dir)
 
                 # now remove the pyc test file if it exists, otherwise the
                 # changes in the python test script won't be executed.
@@ -172,9 +172,9 @@ def copy_test_scripts(self):
                 if os.access(os.path.join(target_test_dir, testfile_pyc),
                              os.F_OK):
                     os.remove(os.path.join(target_test_dir, testfile_pyc))
-                    self.logger.info('removed compiled file %s',
-                                     os.path.join(target_test_dir,
-                                     testfile_pyc))
+                    self.log.info('removed compiled file %s',
+                                  os.path.join(target_test_dir,
+                                               testfile_pyc))
 
     def fix_mkrescue(self, mkrescue):
         """ grub-mkrescue is a bash script with two variables, 'prefix' and
@@ -216,7 +216,7 @@ def generate_bits_iso(self):
 
         self.fix_mkrescue(mkrescue_script)
 
-        self.logger.info('using grub-mkrescue for generating biosbits iso ...')
+        self.log.info('using grub-mkrescue for generating biosbits iso ...')
 
         try:
             if os.getenv('V') or os.getenv('BITS_DEBUG'):
@@ -225,7 +225,7 @@ def generate_bits_iso(self):
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT,
                                       check=True)
-                self.logger.info("grub-mkrescue output %s" % proc.stdout)
+                self.log.info("grub-mkrescue output %s" % proc.stdout)
             else:
                 subprocess.check_call([mkrescue_script, '-o',
                                       iso_file, bits_dir],
@@ -238,11 +238,10 @@ def generate_bits_iso(self):
 
         self.assertTrue(os.access(iso_file, os.R_OK))
 
-        self.logger.info('iso file %s successfully generated.', iso_file)
+        self.log.info('iso file %s successfully generated.', iso_file)
 
     def setUp(self): # pylint: disable=arguments-differ
         super().setUp()
-        self.logger = self.log
 
         prebuiltDir = self.scratch_file('prebuilt')
         if not os.path.isdir(prebuiltDir):
@@ -333,7 +332,7 @@ def test_acpi_smbios_bits(self):
         # in batch mode and then automatically initiate a vm shutdown.
         self._vm.event_wait('SHUTDOWN', timeout=BITS_TIMEOUT)
         self._vm.wait(timeout=None)
-        self.logger.debug("Checking console output ...")
+        self.log.debug("Checking console output ...")
         self.parse_log()
 
 if __name__ == '__main__':
Signature · 1 line
2.50.1
#3 lore raw

PATCH 2/6 tests/functional: convert reverse debug test to local gdb module

In reply to Daniel P. Berrangé

This replaces the use of Avocado for the GDBRemote class with our in-tree copy.

---
 tests/functional/reverse_debugging.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/functional/reverse_debugging.py +2 -2
index f9a1d395f1..405eb6b3b7 100644
@@ -14,6 +14,7 @@
 
 from qemu_test import LinuxKernelTest, get_qemu_img
 from qemu_test.ports import Ports
+from qemu_test.gdb import GDBRemote
 
 
 class ReverseDebugging(LinuxKernelTest):
@@ -99,7 +100,6 @@ def vm_get_icount(vm):
         return vm.qmp('query-replay')['return']['icount']
 
     def reverse_debugging(self, shift=7, args=None):
-        from avocado.utils import gdb
         from avocado.utils import process
 
         logger = logging.getLogger('replay')
@@ -130,7 +130,7 @@ def reverse_debugging(self, shift=7, args=None):
             port = ports.find_free_port()
             vm = self.run_vm(False, shift, args, replay_path, image_path, port)
         logger.info('connecting to gdbstub')
-        g = gdb.GDBRemote('127.0.0.1', port, False, False)
+        g = GDBRemote('127.0.0.1', port, False, False)
         g.connect()
         r = g.cmd(b'qSupported')
         if b'qXfer:features:read+' in r:
Signature · 1 line
2.50.1
#5 lore raw

PATCH 3/6 tests/functional: replace avocado process with subprocess

In reply to Daniel P. Berrangé

The standard python subprocess.check_call method is better than avocado.utils.process as it doesn't require stuffing all args into a single string.

---
 tests/functional/reverse_debugging.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/functional/reverse_debugging.py +4 -4
index 405eb6b3b7..1b880cda8f 100644
@@ -11,6 +11,7 @@
 # later.  See the COPYING file in the top-level directory.
 import os
 import logging
+from subprocess import check_output
 
 from qemu_test import LinuxKernelTest, get_qemu_img
 from qemu_test.ports import Ports
@@ -100,8 +101,6 @@ def vm_get_icount(vm):
         return vm.qmp('query-replay')['return']['icount']
 
     def reverse_debugging(self, shift=7, args=None):
-        from avocado.utils import process
-
         logger = logging.getLogger('replay')
 
         # create qcow2 for snapshots
@@ -111,8 +110,9 @@ def reverse_debugging(self, shift=7, args=None):
         if qemu_img is None:
             self.skipTest('Could not find "qemu-img", which is required to '
                           'create the temporary qcow2 image')
-        cmd = '%s create -f qcow2 %s 128M' % (qemu_img, image_path)
-        process.run(cmd)
+        out = check_output([qemu_img, 'create', '-f', 'qcow2', image_path, '128M'],
+                           encoding='utf8')
+        logger.info("qemu-img: %s" % out)
 
         replay_path = os.path.join(self.workdir, 'replay.bin')
 
Signature · 1 line
2.50.1
#1 lore raw

PATCH 1/6 tests/functional: import GDB remote code from avocado

In reply to Daniel P. Berrangé

The gdbmi_parser.py and spark.py modules originated in projects that pre-date avocado and are imported unchanged aside from the 'import' statement in gdbmi_parser.py

The gdb.py module is original avocado code that is imported with all classes except GDBRemote removed.

---
 tests/functional/qemu_test/gdb.py          | 233 ++++++
 tests/functional/qemu_test/gdbmi_parser.py | 419 ++++++++++
 tests/functional/qemu_test/spark.py        | 850 +++++++++++++++++++++
 3 files changed, 1502 insertions(+)
 create mode 100644 tests/functional/qemu_test/gdb.py
 create mode 100644 tests/functional/qemu_test/gdbmi_parser.py
 create mode 100644 tests/functional/qemu_test/spark.py
tests/functional/qemu_test/gdb.py new file +233 -0
new file mode 100644
index 0000000000..913e3b65ab
@@ -0,0 +1,233 @@
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# A cut-down copy of gdb.py from the avocado project:
+#
+# Copyright: Red Hat Inc. 2014
+# Authors: Cleber Rosa <[email protected]>
+
+__all__ = ["GDB", "GDBServer", "GDBRemote"]
+
+
+import socket
+
+from . import gdbmi_parser
+
+#: How the remote protocol signals a transmission success (in ACK mode)
+REMOTE_TRANSMISSION_SUCCESS = "+"
+
+#: How the remote protocol signals a transmission failure (in ACK mode)
+REMOTE_TRANSMISSION_FAILURE = "-"
+
+#: How the remote protocol flags the start of a packet
+REMOTE_PREFIX = b"$"
+
+#: How the remote protocol flags the end of the packet payload, and that the
+#: two digits checksum follow
+REMOTE_DELIMITER = b"#"
+
+#: Rather conservative default maximum packet size for clients using the
+#: remote protocol. Individual connections can ask (and do so by default)
+#: the server about the maximum packet size they can handle.
+REMOTE_MAX_PACKET_SIZE = 1024
+
+
+class UnexpectedResponseError(Exception):
+    """A response different from the one expected was received from GDB"""
+
+
+class ServerInitTimeoutError(Exception):
+    """Server took longer than expected to initialize itself properly"""
+
+
+class InvalidPacketError(Exception):
+    """Packet received has invalid format"""
+
+
+class NotConnectedError(Exception):
+    """GDBRemote is not connected to a remote GDB server"""
+
+
+class RetransmissionRequestedError(Exception):
+    """Message integrity was not validated and retransmission is being requested"""
+
+
+
+class GDBRemote:
+    """A GDBRemote acts like a client that speaks the GDB remote protocol,
+    documented at:
+
+    https://sourceware.org/gdb/current/onlinedocs/gdb/Remote-Protocol.html
+
+    Caveat: we currently do not support communicating with devices, only
+    with TCP sockets. This limitation is basically due to the lack of
+    use cases that justify an implementation, but not due to any technical
+    shortcoming.
+    """
+
+    def __init__(self, host, port, no_ack_mode=True, extended_mode=True):
+        """Initializes a new GDBRemote object.
+
+        :param host: the IP address or host name
+        :type host: str
+        :param port: the port number where the the remote GDB is listening on
+        :type port: int
+        :param no_ack_mode: if the packet transmission confirmation mode should
+                            be disabled
+        :type no_ack_mode: bool
+        :param extended_mode: if the remote extended mode should be enabled
+        :type param extended_mode: bool
+        """
+        self.host = host
+        self.port = port
+
+        # Temporary holder for the class init attributes
+        self._no_ack_mode = no_ack_mode
+        self.no_ack_mode = False
+        self._extended_mode = extended_mode
+        self.extended_mode = False
+
+        self._socket = None
+
+    @staticmethod
+    def checksum(input_message):
+        """Calculates a remote message checksum.
+
+        More details are available at:
+        https://sourceware.org/gdb/current/onlinedocs/gdb/Overview.html
+
+        :param input_message: the message input payload, without the
+                              start and end markers
+        :type input_message: bytes
+        :returns: two byte checksum
+        :rtype: bytes
+        """
+        total = 0
+        for i in input_message:
+            total += i
+        result = total % 256
+
+        return b"%02x" % result
+
+    @staticmethod
+    def encode(data):
+        """Encodes a command.
+
+        That is, add prefix, suffix and checksum.
+
+        More details are available at:
+        https://sourceware.org/gdb/current/onlinedocs/gdb/Overview.html
+
+        :param data: the command data payload
+        :type data: bytes
+        :returns: the encoded command, ready to be sent to a remote GDB
+        :rtype: bytes
+        """
+        return b"$%b#%b" % (data, GDBRemote.checksum(data))
+
+    @staticmethod
+    def decode(data):
+        """Decodes a packet and returns its payload.
+
+        More details are available at:
+        https://sourceware.org/gdb/current/onlinedocs/gdb/Overview.html
+
+        :param data: the command data payload
+        :type data: bytes
+        :returns: the encoded command, ready to be sent to a remote GDB
+        :rtype: bytes
+        :raises InvalidPacketError: if the packet is not well constructed,
+                                    like in checksum mismatches
+        """
+        if data[0:1] != REMOTE_PREFIX:
+            raise InvalidPacketError
+
+        if data[-3:-2] != REMOTE_DELIMITER:
+            raise InvalidPacketError
+
+        payload = data[1:-3]
+        checksum = data[-2:]
+
+        if payload == b"":
+            expected_checksum = b"00"
+        else:
+            expected_checksum = GDBRemote.checksum(payload)
+
+        if checksum != expected_checksum:
+            raise InvalidPacketError
+
+        return payload
+
+    def cmd(self, command_data, expected_response=None):
+        """Sends a command data to a remote gdb server
+
+        Limitations: the current version does not deal with retransmissions.
+
+        :param command_data: the remote command to send the the remote stub
+        :type command_data: str
+        :param expected_response: the (optional) response that is expected
+                                  as a response for the command sent
+        :type expected_response: str
+        :raises: RetransmissionRequestedError, UnexpectedResponseError
+        :returns: raw data read from from the remote server
+        :rtype: str
+        :raises NotConnectedError: if the socket is not initialized
+        :raises RetransmissionRequestedError: if there was a failure while
+                                              reading the result of the command
+        :raises UnexpectedResponseError: if response is unexpected
+        """
+        if self._socket is None:
+            raise NotConnectedError
+
+        data = self.encode(command_data)
+        self._socket.send(data)
+
+        if not self.no_ack_mode:
+            transmission_result = self._socket.recv(1)
+            if transmission_result == REMOTE_TRANSMISSION_FAILURE:
+                raise RetransmissionRequestedError
+
+        result = self._socket.recv(REMOTE_MAX_PACKET_SIZE)
+        response_payload = self.decode(result)
+
+        if expected_response is not None:
+            if expected_response != response_payload:
+                raise UnexpectedResponseError
+
+        return response_payload
+
+    def set_extended_mode(self):
+        """Enable extended mode. In extended mode, the remote server is made
+        persistent. The 'R' packet is used to restart the program being
+        debugged. Original documentation at:
+
+        https://sourceware.org/gdb/current/onlinedocs/gdb/Packets.html#extended-mode
+        """
+        self.cmd(b"!", b"OK")
+        self.extended_mode = True
+
+    def start_no_ack_mode(self):
+        """Request that the remote stub disable the normal +/- protocol
+        acknowledgments. Original documentation at:
+
+        https://sourceware.org/gdb/current/onlinedocs/gdb/General-Query-Packets.html#QStartNoAckMode
+        """
+        self.cmd(b"QStartNoAckMode", b"OK")
+        self.no_ack_mode = True
+
+    def connect(self):
+        """Connects to the remote target and initializes the chosen modes"""
+        self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        self._socket.connect((self.host, self.port))
+
+        if self._no_ack_mode:
+            self.start_no_ack_mode()
+
+        if self._extended_mode:
+            self.set_extended_mode()
tests/functional/qemu_test/gdbmi_parser.py new file +419 -0

419 lines not on this page · raw message

tests/functional/qemu_test/spark.py new file +850 -0

850 lines not on this page · raw message

Signature · 1 line
2.50.1
#0 lore raw

cover tests/functional: remove last use of avocado.utils

This simply imports the GDB code from avocado.utils to the QEMU functional test suite, and drops the other redundant avocado usage.

Daniel P. Berrangé (6):
tests/functional: import GDB remote code from avocado tests/functional: convert reverse debug test to local gdb module tests/functional: replace avocado process with subprocess tests/functional: drop datadrainer class in reverse debugging tests/functional: close GDB socket in reverse debugging test tests/functional: use self.log for all logging

 tests/functional/aarch64/test_virt.py      |   4 +-
 tests/functional/arm/test_integratorcp.py  |   3 +-
 tests/functional/mips64el/test_malta.py    |   3 +-
 tests/functional/qemu_test/gdb.py          | 237 ++++++
 tests/functional/qemu_test/gdbmi_parser.py | 419 ++++++++++
 tests/functional/qemu_test/spark.py        | 850 +++++++++++++++++++++
 tests/functional/replay_kernel.py          |  16 +-
 tests/functional/reverse_debugging.py      |  59 +-
 tests/functional/x86_64/test_acpi_bits.py  |  31 +-
 9 files changed, 1557 insertions(+), 65 deletions(-)
 create mode 100644 tests/functional/qemu_test/gdb.py
 create mode 100644 tests/functional/qemu_test/gdbmi_parser.py
 create mode 100644 tests/functional/qemu_test/spark.py
Signature · 1 line
2.50.1
Reviewed-by on v1 3/6
#6 lore raw

Re: [PATCH 3/6] tests/functional: replace avocado process with subprocess

In reply to Daniel P. Berrangé
Quoted 5 lines · Daniel P. Berrangé

The standard python subprocess.check_call method is better than avocado.utils.process as it doesn't require stuffing all args into a single string.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] tests/functional: import GDB remote code from avocado

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé

The gdbmi_parser.py and spark.py modules originated in projects that pre-date avocado and are imported unchanged aside from the 'import' statement in gdbmi_parser.py

The gdb.py module is original avocado code that is imported with all classes except GDBRemote removed.

Quoted 8 lines
---
 tests/functional/qemu_test/gdb.py          | 233 ++++++
 tests/functional/qemu_test/gdbmi_parser.py | 419 ++++++++++
 tests/functional/qemu_test/spark.py        | 850 +++++++++++++++++++++
 3 files changed, 1502 insertions(+)
 create mode 100644 tests/functional/qemu_test/gdb.py
 create mode 100644 tests/functional/qemu_test/gdbmi_parser.py
 create mode 100644 tests/functional/qemu_test/spark.py

I wonder if we should put these in a subdir named "imported" or something similar to make it clear these didn't start here.

Quoted 7 lines
tests/functional/qemu_test/gdb.py new file +0 -0
new file mode 100644
index 0000000000..913e3b65ab

tests/functional/qemu_test/gdb.py line 10

Quoted 10 lines
tests/functional/qemu_test/gdb.py new file +10 -0
@@ -0,0 +1,233 @@
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# A cut-down copy of gdb.py from the avocado project:

Or indeed a link to upstream from here and the other python comment blocks.

Otherwise:

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#8 lore raw

Re: [PATCH 4/6] tests/functional: drop datadrainer class in reverse debugging

In reply to Daniel P. Berrangé
Quoted 8 lines · Daniel P. Berrangé

The reverse debugging test uses the avocado datadrainer class to create a background thread that reads from the console socket and dumps it via python logger.

Most tests log console output as a side effect of doing calls to match strings, but this test never tries to match anything.

This isn't critical, so just drop the functionality.

We do end up with zero length logs for all console output although I don't know if we got that far before:

➜ find tests/functional/ -iwholename "*reverse_debug*log" -exec ls -l {} \;
-rw-rw-r-- 1 alex alex 3196 Aug 26 10:18 tests/functional/aarch64/test_aarch64_reverse_debug.ReverseDebugging_AArch64.test_aarch64_virt/base.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:18 tests/functional/aarch64/test_aarch64_reverse_debug.ReverseDebugging_AArch64.test_aarch64_virt/record.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:18 tests/functional/aarch64/test_aarch64_reverse_debug.ReverseDebugging_AArch64.test_aarch64_virt/console.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:18 tests/functional/aarch64/test_aarch64_reverse_debug.ReverseDebugging_AArch64.test_aarch64_virt/replay.log -rw-rw-r-- 1 alex alex 5968 Sep 15 11:09 tests/functional/aarch64/test_reverse_debug.ReverseDebugging_AArch64.test_aarch64_virt/base.log -rw-rw-r-- 1 alex alex 0 Sep 15 11:09 tests/functional/aarch64/test_reverse_debug.ReverseDebugging_AArch64.test_aarch64_virt/record.log -rw-rw-r-- 1 alex alex 0 Sep 15 11:09 tests/functional/aarch64/test_reverse_debug.ReverseDebugging_AArch64.test_aarch64_virt/console.log -rw-rw-r-- 1 alex alex 0 Sep 15 11:09 tests/functional/aarch64/test_reverse_debug.ReverseDebugging_AArch64.test_aarch64_virt/replay.log -rw-rw-r-- 1 alex alex 2656 Aug 26 10:04 tests/functional/ppc64/test_ppc64_reverse_debug.ReverseDebugging_ppc64.test_ppc64_pseries/base.log -rw-rw-r-- 1 alex alex 258 Aug 26 10:04 tests/functional/ppc64/test_ppc64_reverse_debug.ReverseDebugging_ppc64.test_ppc64_pseries/record.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:04 tests/functional/ppc64/test_ppc64_reverse_debug.ReverseDebugging_ppc64.test_ppc64_pseries/console.log -rw-rw-r-- 1 alex alex 516 Aug 26 10:04 tests/functional/ppc64/test_ppc64_reverse_debug.ReverseDebugging_ppc64.test_ppc64_pseries/replay.log -rw-rw-r-- 1 alex alex 2620 Sep 4 18:03 tests/functional/ppc64/test_reverse_debug.ReverseDebugging_ppc64.test_ppc64_pseries/base.log -rw-rw-r-- 1 alex alex 258 Sep 4 18:03 tests/functional/ppc64/test_reverse_debug.ReverseDebugging_ppc64.test_ppc64_pseries/record.log -rw-rw-r-- 1 alex alex 0 Sep 4 18:03 tests/functional/ppc64/test_reverse_debug.ReverseDebugging_ppc64.test_ppc64_pseries/console.log -rw-rw-r-- 1 alex alex 516 Sep 4 18:03 tests/functional/ppc64/test_reverse_debug.ReverseDebugging_ppc64.test_ppc64_pseries/replay.log -rw-rw-r-- 1 alex alex 2656 Aug 26 10:04 tests/functional/ppc64/test_ppc64_reverse_debug.ReverseDebugging_ppc64.test_ppc64_powernv/base.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:04 tests/functional/ppc64/test_ppc64_reverse_debug.ReverseDebugging_ppc64.test_ppc64_powernv/record.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:04 tests/functional/ppc64/test_ppc64_reverse_debug.ReverseDebugging_ppc64.test_ppc64_powernv/console.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:04 tests/functional/ppc64/test_ppc64_reverse_debug.ReverseDebugging_ppc64.test_ppc64_powernv/replay.log -rw-rw-r-- 1 alex alex 4810 Sep 15 11:09 tests/functional/ppc64/test_reverse_debug.ReverseDebugging_ppc64.test_ppc64_powernv/base.log -rw-rw-r-- 1 alex alex 0 Sep 15 11:09 tests/functional/ppc64/test_reverse_debug.ReverseDebugging_ppc64.test_ppc64_powernv/record.log -rw-rw-r-- 1 alex alex 0 Sep 15 11:09 tests/functional/ppc64/test_reverse_debug.ReverseDebugging_ppc64.test_ppc64_powernv/console.log -rw-rw-r-- 1 alex alex 118 Sep 15 11:11 tests/functional/ppc64/test_reverse_debug.ReverseDebugging_ppc64.test_ppc64_powernv/replay.log -rw-rw-r-- 1 alex alex 2642 Aug 26 10:05 tests/functional/x86_64/test_x86_64_reverse_debug.ReverseDebugging_X86_64.test_x86_64_pc/base.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:05 tests/functional/x86_64/test_x86_64_reverse_debug.ReverseDebugging_X86_64.test_x86_64_pc/record.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:05 tests/functional/x86_64/test_x86_64_reverse_debug.ReverseDebugging_X86_64.test_x86_64_pc/console.log -rw-rw-r-- 1 alex alex 0 Aug 26 10:05 tests/functional/x86_64/test_x86_64_reverse_debug.ReverseDebugging_X86_64.test_x86_64_pc/replay.log -rw-rw-r-- 1 alex alex 5317 Sep 15 11:09 tests/functional/x86_64/test_reverse_debug.ReverseDebugging_X86_64.test_x86_64_pc/base.log -rw-rw-r-- 1 alex alex 0 Sep 15 11:09 tests/functional/x86_64/test_reverse_debug.ReverseDebugging_X86_64.test_x86_64_pc/record.log -rw-rw-r-- 1 alex alex 0 Sep 15 11:09 tests/functional/x86_64/test_reverse_debug.ReverseDebugging_X86_64.test_x86_64_pc/console.log -rw-rw-r-- 1 alex alex 0 Sep 15 11:09 tests/functional/x86_64/test_reverse_debug.ReverseDebugging_X86_64.test_x86_64_pc/replay.log

Quoted 30 lines
---
 tests/functional/reverse_debugging.py | 6 ------
 1 file changed, 6 deletions(-)
tests/functional/reverse_debugging.py +0 -6
index 1b880cda8f..9c89f5c897 100644
@@ -35,8 +35,6 @@ class ReverseDebugging(LinuxKernelTest):
     endian_is_le = True
 
     def run_vm(self, record, shift, args, replay_path, image_path, port):
-        from avocado.utils import datadrainer
-
         logger = logging.getLogger('replay')
         vm = self.get_vm(name='record' if record else 'replay')
         vm.set_console()
@@ -54,10 +52,6 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
         if args:
             vm.add_args(*args)
         vm.launch()
-        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
-                                    logger=self.log.getChild('console'),
-                                    stop_check=(lambda : not vm.is_running()))
-        console_drainer.start()
         return vm
 
     @staticmethod
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Reviewed-by on v1 6/6
#15 lore raw

Re: [PATCH 6/6] tests/functional: use self.log for all logging

In reply to Daniel P. Berrangé
Quoted 2 lines · Daniel P. Berrangé

Some tests are creating their on logger category which means any output they log is not captured in base.log.

This seems unrelated to reverse debugging and perhaps should be split to each test. But otherwise LGTM:

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#17 lore raw
In reply to Daniel P. Berrangé
Quoted 3 lines · Daniel P. Berrangé

This simply imports the GDB code from avocado.utils to the QEMU functional test suite, and drops the other redundant avocado usage.

Missing patches include dropping the:

@skipIfMissingImports('avocado.utils')

from the reverse tests.

With this done can we remove the remaining references to avocado?

python/Makefile
110: @avocado --config avocado.cfg run tests/
118: @coverage run -m avocado --config avocado.cfg run tests/*.py
python/README.rst
73:- ``avocado.cfg`` Configuration for the Avocado test-runner. python/qemu/machine/README.rst
5:QEMU. It is used by the iotests, vm tests, avocado tests, and several python/qemu/utils/README.rst
5:debugging QEMU. It is used primarily by the vm and avocado tests. python/setup.cfg
37: avocado-framework >= 90.0
python/tests/minreqs.txt
35:avocado-framework==90.0
python/tests/protocol.py
7:import avocado
160:class Smoke(avocado.Test):
208:class TestBase(avocado.Test):

Quoted 22 lines

Daniel P. Berrangé (6):
tests/functional: import GDB remote code from avocado tests/functional: convert reverse debug test to local gdb module tests/functional: replace avocado process with subprocess tests/functional: drop datadrainer class in reverse debugging tests/functional: close GDB socket in reverse debugging test tests/functional: use self.log for all logging

 tests/functional/aarch64/test_virt.py      |   4 +-
 tests/functional/arm/test_integratorcp.py  |   3 +-
 tests/functional/mips64el/test_malta.py    |   3 +-
 tests/functional/qemu_test/gdb.py          | 237 ++++++
 tests/functional/qemu_test/gdbmi_parser.py | 419 ++++++++++
 tests/functional/qemu_test/spark.py        | 850 +++++++++++++++++++++
 tests/functional/replay_kernel.py          |  16 +-
 tests/functional/reverse_debugging.py      |  59 +-
 tests/functional/x86_64/test_acpi_bits.py  |  31 +-
 9 files changed, 1557 insertions(+), 65 deletions(-)
 create mode 100644 tests/functional/qemu_test/gdb.py
 create mode 100644 tests/functional/qemu_test/gdbmi_parser.py
 create mode 100644 tests/functional/qemu_test/spark.py
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#9 lore raw

Re: [PATCH 4/6] tests/functional: drop datadrainer class in reverse debugging

In reply to Alex Bennée
Quoted 6 lines · Alex Bennée
Quoted 4 lines · Daniel P. Berrangé

The reverse debugging test uses the avocado datadrainer class to create a background thread that reads from the console socket and dumps it via python logger.

Quoted 7 lines
Quoted 4 lines

Most tests log console output as a side effect of doing calls to match strings, but this test never tries to match anything.

This isn't critical, so just drop the functionality.

We do end up with zero length logs for all console output although I don't know if we got that far before:

AFAICT, the logs were also zero-length with the current code. When I ran it with the datadrainer code, there didn't seem to be any output to be drained. I'm unclear if that's expected or a sign I did something wrong, or something has broken since the test was first written ?

Quoted 28 lines
Quoted 28 lines
---
 tests/functional/reverse_debugging.py | 6 ------
 1 file changed, 6 deletions(-)
tests/functional/reverse_debugging.py +0 -6
index 1b880cda8f..9c89f5c897 100644
@@ -35,8 +35,6 @@ class ReverseDebugging(LinuxKernelTest):
     endian_is_le = True
 
     def run_vm(self, record, shift, args, replay_path, image_path, port):
-        from avocado.utils import datadrainer
-
         logger = logging.getLogger('replay')
         vm = self.get_vm(name='record' if record else 'replay')
         vm.set_console()
@@ -54,10 +52,6 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
         if args:
             vm.add_args(*args)
         vm.launch()
-        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
-                                    logger=self.log.getChild('console'),
-                                    stop_check=(lambda : not vm.is_running()))
-        console_drainer.start()
         return vm
 
Quoted 6 lines
Quoted 1 line
tests/functional/reverse_debugging.py +0 -0
     @staticmethod
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#16 lore raw

Re: [PATCH 6/6] tests/functional: use self.log for all logging

In reply to Alex Bennée
Quoted 7 lines · Alex Bennée
Quoted 2 lines · Daniel P. Berrangé

Some tests are creating their on logger category which means any output they log is not captured in base.log.

This seems unrelated to reverse debugging and perhaps should be split to each test. But otherwise LGTM:

The reverse_debugging.py changes were because I wanted to see the log messages from that test when debugging this series. I then noticed several other tests had the same problem of logging to a category that is not saved.

Quoted 7 lines
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#18 lore raw
In reply to Alex Bennée
Quoted 23 lines · Alex Bennée
Quoted 3 lines · Daniel P. Berrangé

This simply imports the GDB code from avocado.utils to the QEMU functional test suite, and drops the other redundant avocado usage.

Missing patches include dropping the:

@skipIfMissingImports('avocado.utils')

from the reverse tests.

With this done can we remove the remaining references to avocado?

python/Makefile
110: @avocado --config avocado.cfg run tests/
118: @coverage run -m avocado --config avocado.cfg run tests/*.py
python/README.rst
73:- ``avocado.cfg`` Configuration for the Avocado test-runner. python/qemu/machine/README.rst
5:QEMU. It is used by the iotests, vm tests, avocado tests, and several python/qemu/utils/README.rst
5:debugging QEMU. It is used primarily by the vm and avocado tests.

Quoted 8 lines

python/setup.cfg
37: avocado-framework >= 90.0
python/tests/minreqs.txt
35:avocado-framework==90.0
python/tests/protocol.py
7:import avocado
160:class Smoke(avocado.Test):
208:class TestBase(avocado.Test):

IIUC, John Snow plans to drop the 'python' directory during this release cycle, so I think we can ignore that for now. I've also suggested that python-qemu-qmp would be better off switching to use pytest instead of avocado, as the latter is what python devs are commonly familiar with and is sufficient for our needs.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#10 lore raw

Re: [PATCH 4/6] tests/functional: drop datadrainer class in reverse debugging

In reply to Daniel P. Berrangé
Quoted 12 lines · Daniel P. Berrangé
Quoted 11 lines · Alex Bennée
Quoted 8 lines · Daniel P. Berrangé

The reverse debugging test uses the avocado datadrainer class to create a background thread that reads from the console socket and dumps it via python logger.

Most tests log console output as a side effect of doing calls to match strings, but this test never tries to match anything.

This isn't critical, so just drop the functionality.

Quoted 8 lines
Quoted 2 lines

We do end up with zero length logs for all console output although I don't know if we got that far before:

AFAICT, the logs were also zero-length with the current code. When I ran it with the datadrainer code, there didn't seem to be any output to be drained. I'm unclear if that's expected or a sign I did something wrong, or something has broken since the test was first written ?

Hmm looking at test it looks like it only runs the first few instructions so unlikely to have any output.

This makes me more inclined just to port to the check-tcg tests where we have control of the binary and we can more easily verify things are working as they should.

Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
---
 tests/functional/reverse_debugging.py | 6 ------
 1 file changed, 6 deletions(-)
tests/functional/reverse_debugging.py +0 -6
index 1b880cda8f..9c89f5c897 100644
@@ -35,8 +35,6 @@ class ReverseDebugging(LinuxKernelTest):
     endian_is_le = True
 
     def run_vm(self, record, shift, args, replay_path, image_path, port):
-        from avocado.utils import datadrainer
-
         logger = logging.getLogger('replay')
         vm = self.get_vm(name='record' if record else 'replay')
         vm.set_console()
@@ -54,10 +52,6 @@ def run_vm(self, record, shift, args, replay_path, image_path, port):
         if args:
             vm.add_args(*args)
         vm.launch()
-        console_drainer = datadrainer.LineLogger(vm.console_socket.fileno(),
-                                    logger=self.log.getChild('console'),
-                                    stop_check=(lambda : not vm.is_running()))
-        console_drainer.start()
         return vm
 
Quoted 6 lines
Quoted 1 line
tests/functional/reverse_debugging.py +0 -0
     @staticmethod
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro

With regards,
Daniel

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Reviewed-by on v1 4/6
#11 lore raw

Re: [PATCH 4/6] tests/functional: drop datadrainer class in reverse debugging

In reply to Daniel P. Berrangé
Quoted 10 lines · Daniel P. Berrangé

The reverse debugging test uses the avocado datadrainer class to create a background thread that reads from the console socket and dumps it via python logger.

Most tests log console output as a side effect of doing calls to match strings, but this test never tries to match anything.

This isn't critical, so just drop the functionality.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro