Skip to contentSkip to conversation

Functional test improvements and fixes

GIT PULL Applied Thomas Huth 2 participants 12 messages Jan 2, 2025 – Jan 3, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

Hi Stefan!

The following changes since commit 8b70d7f2071e2db51b1910502bfb7f84ebf926be:

Merge tag 'hw-misc-20241231' of https://github.com/philmd/qemu into staging (2025-01-01 15:17:08 -0500)

are available in the Git repository at:

https://gitlab.com/thuth/qemu.git tags/pull-request-2025-01-02

for you to fetch changes up to c5efe54622953c4350566ab42323de61a1c06b8f:

tests/functional/test_arm_quanta_gsj: Fix broken test (2025-01-02 09:16:42 +0100)

----------------------------------------------------------------
* Update year in copyright statements
* Convert the VNC test to the functional framework
* Improve and update the ppc64_hv functional test
* Fix broken rx_gdbsim and arm_quanta_gsj functional tests

----------------------------------------------------------------
Ani Sinha (1):
docs: update copyright date to the year 2025

Nicholas Piggin (3):
tests/functional/test_ppc64_hv: Simplify console handling tests/functional/test_ppc64_hv: Update repo management tests/functional/test_ppc64_hv: Update to Alpine 3.21.0

Philippe Mathieu-Daudé (1):
tests/functional/test_rx_gdbsim: Use stable URL for test_linux_sash

Thomas Huth (5):
tests/functional: Convert the vnc test tests/functional/test_vnc: Do not use a hard-coded VNC port tests/functional/test_vnc: Remove the test_no_vnc test tests/functional: Extract the find_free_ports() function into a helper file tests/functional/test_arm_quanta_gsj: Fix broken test

 docs/conf.py                                     |  2 +-
 include/qemu/help-texts.h                        |  2 +-
 tests/functional/meson.build                     |  1 +
 tests/functional/qemu_test/ports.py              | 56 ++++++++++++++++++++++++
 tests/functional/test_arm_quanta_gsj.py          |  2 +-
 tests/functional/test_ppc64_hv.py                | 52 ++++++++++------------
 tests/functional/test_rx_gdbsim.py               | 13 +++---
 tests/{avocado/vnc.py => functional/test_vnc.py} | 55 +++++++----------------
 8 files changed, 108 insertions(+), 75 deletions(-)
 create mode 100644 tests/functional/qemu_test/ports.py
 rename tests/{avocado/vnc.py => functional/test_vnc.py} (74%)
 mode change 100644 => 100755
#1 lore raw

[PULL 01/10] docs: update copyright date to the year 2025

From: Ani Sinha <[email protected]>

We are already in January 2025! Update copyright notices.

Message-ID: <[email protected]>

---
 docs/conf.py              | 2 +-
 include/qemu/help-texts.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
docs/conf.py +1 -1
index 164a8ee8b2..31bb9a3789 100644
@@ -87,7 +87,7 @@
 
 # General information about the project.
 project = u'QEMU'
-copyright = u'2024, The QEMU Project Developers'
+copyright = u'2025, The QEMU Project Developers'
 author = u'The QEMU Project Developers'
 
 # The version info for the project you're documenting, acts as replacement for
include/qemu/help-texts.h +1 -1
index 353ab2ad8b..bc8fab9169 100644
@@ -2,7 +2,7 @@
 #define QEMU_HELP_TEXTS_H
 
 /* Copyright string for -version arguments, About dialogs, etc */
-#define QEMU_COPYRIGHT "Copyright (c) 2003-2024 " \
+#define QEMU_COPYRIGHT "Copyright (c) 2003-2025 " \
     "Fabrice Bellard and the QEMU Project developers"
 
 /* Bug reporting information for --help arguments, About dialogs, etc */
Signature · 1 line
2.47.1
#2 lore raw

[PULL 08/10] tests/functional/test_ppc64_hv: Update to Alpine 3.21.0

In reply to Thomas Huth

From: Nicholas Piggin <[email protected]>

Message-ID: <[email protected]>

---
 tests/functional/test_ppc64_hv.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/functional/test_ppc64_hv.py +4 -4
index e0dffb1f15..62f996adf6 100755
@@ -35,9 +35,9 @@ class HypervisorTest(QemuSystemTest):
     good_message = 'VFS: Cannot open root device'
 
     ASSET_ISO = Asset(
-        ('https://dl-cdn.alpinelinux.org/alpine/v3.18/'
-         'releases/ppc64le/alpine-standard-3.18.4-ppc64le.iso'),
-        'c26b8d3e17c2f3f0fed02b4b1296589c2390e6d5548610099af75300edd7b3ff')
+        ('https://dl-cdn.alpinelinux.org/alpine/v3.21/'
+         'releases/ppc64le/alpine-standard-3.21.0-ppc64le.iso'),
+        '7651ab4e3027604535c0b36e86c901b4695bf8fe97b908f5b48590f6baae8f30')
 
     def extract_from_iso(self, iso, path):
         """
@@ -114,7 +114,7 @@ def do_test_kvm(self, hpt=False):
                            '-initrd /media/nvme0n1/boot/initramfs-lts '
                            '-kernel /media/nvme0n1/boot/vmlinuz-lts '
                            '-append \'usbcore.nousb ' + append + '\'')
-        # Alpine 3.18 kernel seems to crash in XHCI USB driver.
+        # Alpine 3.21 kernel seems to crash in XHCI USB driver.
         ps1='localhost:~#'
         wait_for_console_pattern(self, 'localhost login:')
         exec_command_and_wait_for_pattern(self, 'root', ps1)
Signature · 1 line
2.47.1
#3 lore raw

[PULL 10/10] tests/functional/test_arm_quanta_gsj: Fix broken test

In reply to Thomas Huth

ASSET_IMAGE needs to be prefixed with "self." ... this bug apparently went in unnoticed because the test is not run by default.

Message-ID: <[email protected]>

---
 tests/functional/test_arm_quanta_gsj.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tests/functional/test_arm_quanta_gsj.py +1 -1
index 7aa5209bea..7b82e2185c 100755
@@ -35,7 +35,7 @@ class EmcraftSf2Machine(LinuxKernelTest):
     @skipUnless(os.getenv('QEMU_TEST_TIMEOUT_EXPECTED'), 'Test might timeout')
     def test_arm_quanta_gsj(self):
         self.set_machine('quanta-gsj')
-        image_path = self.uncompress(ASSET_IMAGE, 'obmc.mtd', format='gz')
+        image_path = self.uncompress(self.ASSET_IMAGE, format='gz')
 
         self.vm.set_console()
         drive_args = 'file=' + image_path + ',if=mtd,bus=0,unit=0'
Signature · 1 line
2.47.1
#4 lore raw

[PULL 06/10] tests/functional/test_ppc64_hv: Simplify console handling

In reply to Thomas Huth

From: Nicholas Piggin <[email protected]>

Since functional tests have character-based console output parsing, there is no need for strange hacks to work around old line-based.

Message-ID: <[email protected]>

---
 tests/functional/test_ppc64_hv.py | 43 ++++++++++++++-----------------
 1 file changed, 19 insertions(+), 24 deletions(-)
tests/functional/test_ppc64_hv.py +19 -24
index 037dfdf87e..2182a68c91 100755
@@ -12,6 +12,7 @@
 from qemu_test import QemuSystemTest, Asset
 from qemu_test import wait_for_console_pattern, exec_command
 from qemu_test import skipIfMissingCommands, skipBigDataTest
+from qemu_test import exec_command_and_wait_for_pattern
 import os
 import time
 import subprocess
@@ -73,31 +74,28 @@ def do_start_alpine(self):
                                     "id=drive0,read-only=true")
 
         self.vm.launch()
-        wait_for_console_pattern(self, 'Welcome to Alpine Linux 3.18')
-        exec_command(self, 'root')
+        ps1='localhost:~#'
         wait_for_console_pattern(self, 'localhost login:')
-        wait_for_console_pattern(self, 'You may change this message by editing /etc/motd.')
+        exec_command_and_wait_for_pattern(self, 'root', ps1)
         # If the time is wrong, SSL certificates can fail.
-        exec_command(self, 'date -s "' + datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S' + '"'))
-        exec_command(self, 'setup-alpine -qe')
-        wait_for_console_pattern(self, 'Updating repository indexes... done.')
+        exec_command_and_wait_for_pattern(self, 'date -s "' + datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S' + '"'), ps1)
+        ps1='alpine:~#'
+        exec_command_and_wait_for_pattern(self, 'setup-alpine -qe', ps1)
 
     def do_stop_alpine(self):
-        exec_command(self, 'poweroff')
+        exec_command(self, 'echo "TEST ME"')
         wait_for_console_pattern(self, 'alpine:~#')
+        exec_command(self, 'poweroff')
+        wait_for_console_pattern(self, 'reboot: Power down')
         self.vm.wait()
 
     def do_setup_kvm(self):
-        exec_command(self, 'echo http://dl-cdn.alpinelinux.org/alpine/v3.18/main > /etc/apk/repositories')
-        wait_for_console_pattern(self, 'alpine:~#')
-        exec_command(self, 'echo http://dl-cdn.alpinelinux.org/alpine/v3.18/community >> /etc/apk/repositories')
-        wait_for_console_pattern(self, 'alpine:~#')
-        exec_command(self, 'apk update')
-        wait_for_console_pattern(self, 'alpine:~#')
-        exec_command(self, 'apk add qemu-system-ppc64')
-        wait_for_console_pattern(self, 'alpine:~#')
-        exec_command(self, 'modprobe kvm-hv')
-        wait_for_console_pattern(self, 'alpine:~#')
+        ps1='alpine:~#'
+        exec_command_and_wait_for_pattern(self, 'echo http://dl-cdn.alpinelinux.org/alpine/v3.18/main > /etc/apk/repositories', ps1)
+        exec_command_and_wait_for_pattern(self, 'echo http://dl-cdn.alpinelinux.org/alpine/v3.18/community >> /etc/apk/repositories', ps1)
+        exec_command_and_wait_for_pattern(self, 'apk update', ps1)
+        exec_command_and_wait_for_pattern(self, 'apk add qemu-system-ppc64', ps1)
+        exec_command_and_wait_for_pattern(self, 'modprobe kvm-hv', ps1)
 
     # This uses the host's block device as the source file for guest block
     # device for install media. This is a bit hacky but allows reuse of the
@@ -116,15 +114,12 @@ def do_test_kvm(self, hpt=False):
                            '-kernel /media/nvme0n1/boot/vmlinuz-lts '
                            '-append \'usbcore.nousb ' + append + '\'')
         # Alpine 3.18 kernel seems to crash in XHCI USB driver.
-        wait_for_console_pattern(self, 'Welcome to Alpine Linux 3.18')
-        exec_command(self, 'root')
+        ps1='localhost:~#'
         wait_for_console_pattern(self, 'localhost login:')
-        wait_for_console_pattern(self, 'You may change this message by editing /etc/motd.')
-        exec_command(self, 'poweroff >& /dev/null')
-        wait_for_console_pattern(self, 'localhost:~#')
+        exec_command_and_wait_for_pattern(self, 'root', ps1)
+        exec_command(self, 'poweroff')
         wait_for_console_pattern(self, 'reboot: Power down')
-        time.sleep(1)
-        exec_command(self, '')
+        # Now wait for the host's prompt to come back
         wait_for_console_pattern(self, 'alpine:~#')
 
     def test_hv_pseries(self):
Signature · 1 line
2.47.1
#5 lore raw

[PULL 04/10] tests/functional/test_vnc: Remove the test_no_vnc test

In reply to Thomas Huth

This test matches exactly the first three lines of the following test_no_vnc_change_password test, so there is exactly zero additional test coverage in here.

Message-ID: <[email protected]>

---
 tests/functional/test_vnc.py | 5 -----
 1 file changed, 5 deletions(-)
tests/functional/test_vnc.py +0 -5
index e6328567c7..e600d75234 100755
@@ -54,11 +54,6 @@ def find_free_ports(count: int) -> List[int]:
 
 class Vnc(QemuSystemTest):
 
-    def test_no_vnc(self):
-        self.vm.add_args('-nodefaults', '-S')
-        self.vm.launch()
-        self.assertFalse(self.vm.qmp('query-vnc')['return']['enabled'])
-
     def test_no_vnc_change_password(self):
         self.vm.add_args('-nodefaults', '-S')
         self.vm.launch()
Signature · 1 line
2.47.1
#6 lore raw

[PULL 09/10] tests/functional/test_rx_gdbsim: Use stable URL for test_linux_sash

In reply to Thomas Huth

From: Philippe Mathieu-Daudé <[email protected]>

Yoshinori said [*] URL references on OSDN were stable, but they appear not to be. Mirror the artifacts on GitHub to avoid failures while testing on CI.

[*] https://www.mail-archive.com/[email protected]/msg686487.html

Message-ID: <[email protected]>
[huth: Adapt the patch to the new version in the functional framework]
Message-ID: <[email protected]>

---
 tests/functional/test_rx_gdbsim.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
tests/functional/test_rx_gdbsim.py +8 -5
index 20623aa51c..49245793e1 100755
@@ -21,13 +21,16 @@ class RxGdbSimMachine(QemuSystemTest):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
 
     ASSET_UBOOT = Asset(
-        'https://acc.dl.osdn.jp/users/23/23888/u-boot.bin.gz',
-        '7146567d669e91dbac166384b29aeba1715beb844c8551e904b86831bfd9d046')
+        ('https://github.com/philmd/qemu-testing-blob/raw/rx-gdbsim/rx/gdbsim/'
+         'u-boot.bin'),
+        'dd7dd4220cccf7aeb32227b26233bf39600db05c3f8e26005bcc2bf6c927207d')
     ASSET_DTB = Asset(
-        'https://acc.dl.osdn.jp/users/23/23887/rx-virt.dtb',
+        ('https://github.com/philmd/qemu-testing-blob/raw/rx-gdbsim/rx/gdbsim/'
+         'rx-gdbsim.dtb'),
         'aa278d9c1907a4501741d7ee57e7f65c02dd1b3e0323b33c6d4247f1b32cf29a')
     ASSET_KERNEL = Asset(
-        'http://acc.dl.osdn.jp/users/23/23845/zImage',
+        ('https://github.com/philmd/qemu-testing-blob/raw/rx-gdbsim/rx/gdbsim/'
+         'zImage'),
         'baa43205e74a7220ed8482188c5e9ce497226712abb7f4e7e4f825ce19ff9656')
 
     def test_uboot(self):
@@ -36,7 +39,7 @@ def test_uboot(self):
         """
         self.set_machine('gdbsim-r5f562n8')
 
-        uboot_path = self.uncompress(self.ASSET_UBOOT)
+        uboot_path = self.ASSET_UBOOT.fetch()
 
         self.vm.set_console()
         self.vm.add_args('-bios', uboot_path,
Signature · 1 line
2.47.1
#7 lore raw

[PULL 07/10] tests/functional/test_ppc64_hv: Update repo management

In reply to Thomas Huth

From: Nicholas Piggin <[email protected]>

setup-apkrepos can be used to set repos rather than open-coding URLs.

Message-ID: <[email protected]>

---
 tests/functional/test_ppc64_hv.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
tests/functional/test_ppc64_hv.py +4 -3
index 2182a68c91..e0dffb1f15 100755
@@ -81,6 +81,10 @@ def do_start_alpine(self):
         exec_command_and_wait_for_pattern(self, 'date -s "' + datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S' + '"'), ps1)
         ps1='alpine:~#'
         exec_command_and_wait_for_pattern(self, 'setup-alpine -qe', ps1)
+        exec_command_and_wait_for_pattern(self, 'setup-apkrepos -c1', ps1)
+        exec_command_and_wait_for_pattern(self, 'apk update', ps1)
+        # Could upgrade here but it usually should not be necessary
+        # exec_command_and_wait_for_pattern(self, 'apk upgrade --available', ps1)
 
     def do_stop_alpine(self):
         exec_command(self, 'echo "TEST ME"')
@@ -91,9 +95,6 @@ def do_stop_alpine(self):
 
     def do_setup_kvm(self):
         ps1='alpine:~#'
-        exec_command_and_wait_for_pattern(self, 'echo http://dl-cdn.alpinelinux.org/alpine/v3.18/main > /etc/apk/repositories', ps1)
-        exec_command_and_wait_for_pattern(self, 'echo http://dl-cdn.alpinelinux.org/alpine/v3.18/community >> /etc/apk/repositories', ps1)
-        exec_command_and_wait_for_pattern(self, 'apk update', ps1)
         exec_command_and_wait_for_pattern(self, 'apk add qemu-system-ppc64', ps1)
         exec_command_and_wait_for_pattern(self, 'modprobe kvm-hv', ps1)
 
Signature · 1 line
2.47.1
#8 lore raw

[PULL 03/10] tests/functional/test_vnc: Do not use a hard-coded VNC port

In reply to Thomas Huth

Two tests here are using the hard-coded VNC port :0 ... if there is already a QEMU or other program running that is using this port, the tests will be failing. Fortunately, QEMU can also auto-detect a free port with the "to=..." parameter, so let's use that for the tests to avoid the problem.

Message-ID: <[email protected]>

---
 tests/functional/test_vnc.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tests/functional/test_vnc.py +2 -2
index b769d3b268..e6328567c7 100755
@@ -72,7 +72,7 @@ def test_no_vnc_change_password(self):
                          'Could not set password')
 
     def test_change_password_requires_a_password(self):
-        self.vm.add_args('-nodefaults', '-S', '-vnc', ':0')
+        self.vm.add_args('-nodefaults', '-S', '-vnc', ':1,to=999')
         self.vm.launch()
         self.assertTrue(self.vm.qmp('query-vnc')['return']['enabled'])
         set_password_response = self.vm.qmp('change-vnc-password',
@@ -84,7 +84,7 @@ def test_change_password_requires_a_password(self):
                          'Could not set password')
 
     def test_change_password(self):
-        self.vm.add_args('-nodefaults', '-S', '-vnc', ':0,password=on')
+        self.vm.add_args('-nodefaults', '-S', '-vnc', ':1,to=999,password=on')
         self.vm.launch()
         self.assertTrue(self.vm.qmp('query-vnc')['return']['enabled'])
         self.vm.cmd('change-vnc-password',
Signature · 1 line
2.47.1
#9 lore raw

[PULL 02/10] tests/functional: Convert the vnc test

In reply to Thomas Huth

Nothing thrilling in here, it's just a straight forward conversion.

Message-ID: <[email protected]>

---
 tests/functional/meson.build                     |  1 +
 tests/{avocado/vnc.py => functional/test_vnc.py} | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)
 rename tests/{avocado/vnc.py => functional/test_vnc.py} (97%)
 mode change 100644 => 100755
tests/functional/meson.build +1 -0
index 24f7f8f2f1..a5087fcb34 100644
@@ -224,6 +224,7 @@ tests_x86_64_system_quick = [
   'pc_cpu_hotplug_props',
   'virtio_version',
   'x86_cpu_model_versions',
+  'vnc',
 ]
 
 tests_x86_64_system_thorough = [
tests/functional/test_vnc.py renamed from tests/avocado/vnc.py +7 -5
old mode 100644
new mode 100755
similarity index 97%
rename from tests/avocado/vnc.py
rename to tests/functional/test_vnc.py
index 862c8996a8..b769d3b268
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+#
 # Simple functional tests for VNC functionality
 #
 # Copyright (c) 2018 Red Hat, Inc.
@@ -11,7 +13,7 @@
 import socket
 from typing import List
 
-from avocado_qemu import QemuSystemTest
+from qemu_test import QemuSystemTest
 
 
 VNC_ADDR = '127.0.0.1'
@@ -51,10 +53,7 @@ def find_free_ports(count: int) -> List[int]:
 
 
 class Vnc(QemuSystemTest):
-    """
-    :avocado: tags=vnc,quick
-    :avocado: tags=machine:none
-    """
+
     def test_no_vnc(self):
         self.vm.add_args('-nodefaults', '-S')
         self.vm.launch()
@@ -113,3 +112,6 @@ def test_change_listen(self):
         self.assertFalse(check_connect(a))
         self.assertTrue(check_connect(b))
         self.assertTrue(check_connect(c))
+
+if __name__ == '__main__':
+    QemuSystemTest.main()
Signature · 1 line
2.47.1
#10 lore raw

[PULL 05/10] tests/functional: Extract the find_free_ports() function into a helper file

In reply to Thomas Huth

We'll need this functionality in other functional tests, too, so let's extract it into the qemu_test module.
Also add an __enter__ and __exit__ function that can be used for using this functionality in a locked context, so that tests that are running in parallel don't try to compete for the same ports later.
Also make sure to only use ports in the "Dynamic Ports" range (see https://www.rfc-editor.org/rfc/rfc6335) and "randomize" the start of the probed range with the PID of the test process to further avoid possible clashes with other competing processes.

Message-ID: <[email protected]>

---
 tests/functional/qemu_test/ports.py | 56 +++++++++++++++++++++++++++++
 tests/functional/test_vnc.py        | 36 +++++--------------
 2 files changed, 64 insertions(+), 28 deletions(-)
 create mode 100644 tests/functional/qemu_test/ports.py
tests/functional/qemu_test/ports.py new file +56 -0
new file mode 100644
index 0000000000..cc39939d48
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+#
+# Simple functional tests for VNC functionality
+#
+# Copyright 2018, 2024 Red Hat, Inc.
+#
+# 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 fcntl
+import os
+import socket
+import sys
+import tempfile
+
+from .config import BUILD_DIR
+from typing import List
+
+class Ports():
+
+    PORTS_ADDR = '127.0.0.1'
+    PORTS_RANGE_SIZE = 1024
+    PORTS_START = 49152 + ((os.getpid() * PORTS_RANGE_SIZE) % 16384)
+    PORTS_END = PORTS_START + PORTS_RANGE_SIZE
+
+    def __enter__(self):
+        lock_file = os.path.join(BUILD_DIR, "tests", "functional", "port_lock")
+        self.lock_fh = os.open(lock_file, os.O_CREAT)
+        fcntl.flock(self.lock_fh, fcntl.LOCK_EX)
+        return self
+
+    def __exit__(self, exc_type, exc_value, traceback):
+        fcntl.flock(self.lock_fh, fcntl.LOCK_UN)
+        os.close(self.lock_fh)
+
+    def check_bind(self, port: int) -> bool:
+        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
+            try:
+                sock.bind((self.PORTS_ADDR, port))
+            except OSError:
+                return False
+
+        return True
+
+    def find_free_ports(self, count: int) -> List[int]:
+        result = []
+        for port in range(self.PORTS_START, self.PORTS_END):
+            if self.check_bind(port):
+                result.append(port)
+                if len(result) >= count:
+                    break
+        assert len(result) == count
+        return result
+
+    def find_free_port(self) -> int:
+        return self.find_free_ports(1)[0]
tests/functional/test_vnc.py +8 -28
index e600d75234..1916be0103 100755
@@ -14,22 +14,9 @@
 from typing import List
 
 from qemu_test import QemuSystemTest
-
+from qemu_test.ports import Ports
 
 VNC_ADDR = '127.0.0.1'
-VNC_PORT_START = 32768
-VNC_PORT_END = VNC_PORT_START + 1024
-
-
-def check_bind(port: int) -> bool:
-    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
-        try:
-            sock.bind((VNC_ADDR, port))
-        except OSError:
-            return False
-
-    return True
-
 
 def check_connect(port: int) -> bool:
     with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
@@ -40,18 +27,6 @@ def check_connect(port: int) -> bool:
 
     return True
 
-
-def find_free_ports(count: int) -> List[int]:
-    result = []
-    for port in range(VNC_PORT_START, VNC_PORT_END):
-        if check_bind(port):
-            result.append(port)
-            if len(result) >= count:
-                break
-    assert len(result) == count
-    return result
-
-
 class Vnc(QemuSystemTest):
 
     def test_no_vnc_change_password(self):
@@ -85,8 +60,7 @@ def test_change_password(self):
         self.vm.cmd('change-vnc-password',
                     password='new_password')
 
-    def test_change_listen(self):
-        a, b, c = find_free_ports(3)
+    def do_test_change_listen(self, a, b, c):
         self.assertFalse(check_connect(a))
         self.assertFalse(check_connect(b))
         self.assertFalse(check_connect(c))
@@ -108,5 +82,11 @@ def test_change_listen(self):
         self.assertTrue(check_connect(b))
         self.assertTrue(check_connect(c))
 
+    def test_change_listen(self):
+        with Ports() as ports:
+            a, b, c = ports.find_free_ports(3)
+            self.do_test_change_listen(a, b, c)
+
+
 if __name__ == '__main__':
     QemuSystemTest.main()
Signature · 1 line
2.47.1