Skip to contentSkip to conversation

testing: some minor QoL changes for functional tests

PATCH In review Alex Bennée 3 participants 10 messages Jun 14 – Jun 19

lore
Share & tools
lore
#0 lore raw

cover testing: some minor QoL changes for functional tests

I spend a lot of time trying to recreate functional test failures on the command line where I can add gdbstub or run under rr. Invariably this involves running the test with "env QEMU_TEST_KEEP_SCRATCH=1" and then extracting the command line and tweaking it.

I finally got annoyed enough to look at the command line code and see if I could do this a better way. Ideally I could just do something like:

  ./pyvenv/bin/meson test --suite thorough func-arm-aspeed_anacapa --cmdline

but for now I'll stick with copy and pasting a line from the logs and saving a few seconds removing all the QMP and console sockets.

I've also included the pylint change which is now reviewed and can be picked up. If not I'll grab it next time I do a testing/next sweep.

Alex.

Alex Bennée (4):
python/qemu: split arg between base and harness lists python/qemu: split console from harness args python/qemu: dump a developer friendly version of cmdline to logs tests/functional: tell pylint not to check c-modules

 python/qemu/machine/machine.py | 29 ++++++++++++++++++++++++-----
 tests/functional/pylintrc      |  1 +
 2 files changed, 25 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/4 python/qemu: split arg between base and harness lists

There are argument we add because we want the test harness to control QEMU and arguments we default for handling the display and machine type. Split the obvious ones between base_args and a new list called harness_args.

We will leave the complexity of the serial ports for now.

---
 python/qemu/machine/machine.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
python/qemu/machine/machine.py +10 -4
index ebb58d5b68c..e8973a87394 100644
@@ -292,8 +292,8 @@ def _load_io_log(self) -> None:
                 self._iolog = iolog.read()
 
     @property
-    def _base_args(self) -> List[str]:
-        args = ['-display', 'none', '-vga', 'none']
+    def _harness_args(self) -> List[str]:
+        args: List[str] = []
 
         if self._qmp_set:
             if self._sock_pair:
@@ -307,8 +307,6 @@ def _base_args(self) -> List[str]:
             args.extend(['-chardev', moncdev, '-mon',
                          'chardev=mon,mode=control'])
 
-        if self._machine is not None:
-            args.extend(['-machine', self._machine])
         for _ in range(self._console_index):
             args.extend(['-serial', 'null'])
         if self._console_set:
@@ -323,6 +321,13 @@ def _base_args(self) -> List[str]:
                 args.extend(['-device', device])
         return args
 
+    @property
+    def _base_args(self) -> List[str]:
+        args: List[str] = ['-display', 'none', '-vga', 'none']
+        if self._machine is not None:
+            args.extend(['-machine', self._machine])
+        return args
+
     @property
     def args(self) -> List[str]:
         """Returns the list of arguments given to the QEMU binary."""
@@ -366,6 +371,7 @@ def _pre_launch(self) -> None:
         self._qemu_full_args = tuple(chain(
             self._wrapper,
             [self._binary],
+            self._harness_args,
             self._base_args,
             self._args
         ))
Signature · 1 line
2.47.3
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] python/qemu: split arg between base and harness lists

Quoted 11 lines · Alex Bennée

There are argument we add because we want the test harness to control QEMU and arguments we default for handling the display and machine type. Split the obvious ones between base_args and a new list called harness_args.

We will leave the complexity of the serial ports for now.

---
  python/qemu/machine/machine.py | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)
#3 lore raw

PATCH 2/4 python/qemu: split console from harness args

In reply to Alex Bennée

Before we mess with the console output lets create a new helper just for that.

---
 python/qemu/machine/machine.py | 5 +++++
 1 file changed, 5 insertions(+)
python/qemu/machine/machine.py +5 -0
index e8973a87394..18ee5ec0147 100644
@@ -306,7 +306,11 @@ def _harness_args(self) -> List[str]:
                 moncdev = f"socket,id=mon,path={self._monitor_address}"
             args.extend(['-chardev', moncdev, '-mon',
                          'chardev=mon,mode=control'])
+        return args
 
+    @property
+    def _console_args(self) -> List[str]:
+        args: List[str] = []
         for _ in range(self._console_index):
             args.extend(['-serial', 'null'])
         if self._console_set:
@@ -372,6 +376,7 @@ def _pre_launch(self) -> None:
             self._wrapper,
             [self._binary],
             self._harness_args,
+            self._console_args,
             self._base_args,
             self._args
         ))
Signature · 1 line
2.47.3
#5 lore raw

PATCH 3/4 python/qemu: dump a developer friendly version of cmdline to logs

In reply to Alex Bennée

Now we have the arguments nicely split up we can make _console_args a function call and present a slightly different version to the logs to save developers manually hacking the command line up.

---
 python/qemu/machine/machine.py | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
python/qemu/machine/machine.py +12 -4
index 18ee5ec0147..26a7bf5948f 100644
@@ -308,12 +308,15 @@ def _harness_args(self) -> List[str]:
                          'chardev=mon,mode=control'])
         return args
 
-    @property
-    def _console_args(self) -> List[str]:
+    def _console_args(self, interactive=False) -> List[str]:
         args: List[str] = []
+        # redirect pre_console_index serials to null
         for _ in range(self._console_index):
             args.extend(['-serial', 'null'])
-        if self._console_set:
+
+        if interactive:
+            args.extend(['-serial', 'mon:stdio'])
+        elif self._console_set:
             assert self._cons_sock_pair is not None
             fd = self._cons_sock_pair[0].fileno()
             chardev = f"socket,id=console,fd={fd}"
@@ -376,7 +379,7 @@ def _pre_launch(self) -> None:
             self._wrapper,
             [self._binary],
             self._harness_args,
-            self._console_args,
+            self._console_args(),
             self._base_args,
             self._args
         ))
@@ -485,6 +488,11 @@ def _launch(self) -> None:
         """
         self._pre_launch()
         LOG.debug('VM launch command: %r', ' '.join(self._qemu_full_args))
+        # Log a simplified, developer-runnable command:
+        # Exclude harness-managed infrastructure args (harness_args)
+        # and wrapper.
+        debug_cmd = [self._binary] + self._console_args(interactive=True) + self._base_args + self._args
+        LOG.debug('Developer-runnable command: %r', ' '.join(debug_cmd))
 
         # Cleaning up of this subprocess is guaranteed by _do_shutdown.
         # pylint: disable=consider-using-with
Signature · 1 line
2.47.3
Reviewed-by on v1 3/4
#6 lore raw

Re: [PATCH 3/4] python/qemu: dump a developer friendly version of cmdline to logs

Quoted 8 lines · Alex Bennée

Now we have the arguments nicely split up we can make _console_args a function call and present a slightly different version to the logs to save developers manually hacking the command line up.

---
  python/qemu/machine/machine.py | 16 ++++++++++++----
  1 file changed, 12 insertions(+), 4 deletions(-)
#7 lore raw

PATCH 4/4 tests/functional: tell pylint not to check c-modules

In reply to Alex Bennée

To fix:

qemu-test.test_pylint "/home/alex/lsrc/qemu.git/tests/functional/arm/test_integratorcp.py:83: I1101: Module 'cv2' has no 'imread' member, but source is unavailable. Consider adding this module to extension-pkg-allow-list if you want to perform analysis based on run-time introspection of living objects. (c-extension-no-member)"

Manually running python3 showed I could indeed import cv2 and call those functions. Rather than allowing pylint to introspect lets just tell it to skip c modules.

Message-ID: <[email protected]>

---
 tests/functional/pylintrc | 1 +
 1 file changed, 1 insertion(+)
tests/functional/pylintrc +1 -0
index 049c3e76f12..949bea611fe 100644
@@ -58,6 +58,7 @@ confidence=HIGH,
 # no Warning level messages displayed, use "--disable=all --enable=classes
 # --disable=W".
 disable=bad-inline-option,
+        c-extension-no-member,
         consider-using-f-string,
         file-ignored,
         fixme,
Signature · 1 line
2.47.3
Reviewed-by on the v1 series
#8 lore raw
In reply to Alex Bennée
Quoted 9 lines · Alex Bennée

I spend a lot of time trying to recreate functional test failures on the command line where I can add gdbstub or run under rr. Invariably this involves running the test with "env QEMU_TEST_KEEP_SCRATCH=1" and then extracting the command line and tweaking it.

I finally got annoyed enough to look at the command line code and see if I could do this a better way. Ideally I could just do something like:

Quoted 7 lines
   ./pyvenv/bin/meson test --suite thorough func-arm-aspeed_anacapa --cmdline

but for now I'll stick with copy and pasting a line from the logs and saving a few seconds removing all the QMP and console sockets.

I've also included the pylint change which is now reviewed and can be picked up. If not I'll grab it next time I do a testing/next sweep.

Series

Feel free to pick it up through your testing tree, I don't have much other things currently pending that would justify a pull request from my side right now.

Thanks,
Thomas

#9 lore raw
In reply to Alex Bennée
Quoted 9 lines · Alex Bennée

I spend a lot of time trying to recreate functional test failures on the command line where I can add gdbstub or run under rr. Invariably this involves running the test with "env QEMU_TEST_KEEP_SCRATCH=1" and then extracting the command line and tweaking it.

I finally got annoyed enough to look at the command line code and see if I could do this a better way. Ideally I could just do something like:

Quoted 8 lines
  ./pyvenv/bin/meson test --suite thorough func-arm-aspeed_anacapa --cmdline

but for now I'll stick with copy and pasting a line from the logs and saving a few seconds removing all the QMP and console sockets.

I've also included the pylint change which is now reviewed and can be picked up. If not I'll grab it next time I do a testing/next sweep.

Queued to testing/next, thanks.

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