From patchwork Thu Jul 11 11:55:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 13730619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 035D1C3DA4A for ; Thu, 11 Jul 2024 11:56:27 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRsPB-0002H9-4l; Thu, 11 Jul 2024 07:56:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsP9-0002By-Mz for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsP6-00046k-AB for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720698963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=erdYB82SWsESpyIDAkDTJBDapAsUIM7zIcvc71btW3U=; b=R4x9K/bB6grztvZJad2kBHvYkphtr1HwUmElvkHpiy6+yGfCaMOaFtg/MfZSKIEpFcwSy+ D1rzjsdVcPmQxgnCj4wsOGTFF2qgYHmM0MKHVEIr6qDRJjRcXHJD4MOQ3aw4kfUunyhS3N Lanp/1bRS+gi/qebTMu2BpEwkXW1i+s= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-684-Z4fZMx5wMqGIwaEd7ThW8A-1; Thu, 11 Jul 2024 07:56:00 -0400 X-MC-Unique: Z4fZMx5wMqGIwaEd7ThW8A-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 924FB1935843; Thu, 11 Jul 2024 11:55:58 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.193.118]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2C1251954219; Thu, 11 Jul 2024 11:55:53 +0000 (UTC) From: Thomas Huth To: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Ani Sinha , Richard Henderson , Paolo Bonzini , "Daniel P . Berrange" , John Snow Subject: [RFC PATCH 1/8] tests/pytest: Add base classes for the upcoming pytest-based tests Date: Thu, 11 Jul 2024 13:55:39 +0200 Message-ID: <20240711115546.40859-2-thuth@redhat.com> In-Reply-To: <20240711115546.40859-1-thuth@redhat.com> References: <20240711115546.40859-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The file is a copy of the tests/avocado/avocado_qemu/__init__.py file with some adjustments to get rid of the Avocado dependencies (i.e. we also have to drop the LinuxSSHMixIn and LinuxTest for now). The emulator binary, source and build directory are now passed via environment variables that will be set via meson.build later. Signed-off-by: Thomas Huth --- tests/pytest/qemu_pytest/__init__.py | 344 +++++++++++++++++++++++++++ 1 file changed, 344 insertions(+) create mode 100644 tests/pytest/qemu_pytest/__init__.py diff --git a/tests/pytest/qemu_pytest/__init__.py b/tests/pytest/qemu_pytest/__init__.py new file mode 100644 index 0000000000..e3ed32e3de --- /dev/null +++ b/tests/pytest/qemu_pytest/__init__.py @@ -0,0 +1,344 @@ +# Test class and utilities for functional tests +# +# Copyright 2018, 2024 Red Hat, Inc. +# +# Original Author (Avocado-based tests): +# Cleber Rosa +# +# Adaption for pytest based version: +# Thomas Huth +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. + +import logging +import os +import shutil +import subprocess +import sys +import tempfile +import time +import uuid +import unittest + +from qemu.machine import QEMUMachine +from qemu.utils import (get_info_usernet_hostfwd_port, kvm_available, + tcg_available) + +BUILD_DIR = os.getenv('PYTEST_BUILD_ROOT') +SOURCE_DIR = os.getenv('PYTEST_SOURCE_ROOT') + +def has_cmd(name, args=None): + """ + This function is for use in a @skipUnless decorator, e.g.: + + @skipUnless(*has_cmd('sudo -n', ('sudo', '-n', 'true'))) + def test_something_that_needs_sudo(self): + ... + """ + + if args is None: + args = ('which', name) + + try: + _, stderr, exitcode = run_cmd(args) + except Exception as e: + exitcode = -1 + stderr = str(e) + + if exitcode != 0: + cmd_line = ' '.join(args) + err = f'{name} required, but "{cmd_line}" failed: {stderr.strip()}' + return (False, err) + else: + return (True, '') + +def has_cmds(*cmds): + """ + This function is for use in a @skipUnless decorator and + allows checking for the availability of multiple commands, e.g.: + + @skipUnless(*has_cmds(('cmd1', ('cmd1', '--some-parameter')), + 'cmd2', 'cmd3')) + def test_something_that_needs_cmd1_and_cmd2(self): + ... + """ + + for cmd in cmds: + if isinstance(cmd, str): + cmd = (cmd,) + + ok, errstr = has_cmd(*cmd) + if not ok: + return (False, errstr) + + return (True, '') + +def run_cmd(args): + subp = subprocess.Popen(args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True) + stdout, stderr = subp.communicate() + ret = subp.returncode + + return (stdout, stderr, ret) + +def is_readable_executable_file(path): + return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK) + +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_file + 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 + try: + msg = console.readline().decode().strip() + except UnicodeDecodeError: + msg = None + 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) + +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: a test containing a VM that will have its console + read and probed for a success or failure message + :type test: :class:`qemu_pytest.QemuSystemTest` + :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): + """ + Waits for messages to appear on the console, while logging the content + + :param test: a test containing a VM that will have its console + read and probed for a success or failure message + :type test: :class:`qemu_pytest.QemuSystemTest` + :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) + +def exec_command(test, command): + """ + Send a command to a console (appending CRLF characters), while logging + the content. + + :param test: a test containing a VM. + :type test: :class:`qemu_pytest.QemuSystemTest` + :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): + """ + 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: a test containing a VM that will have its console + read and probed for a success or failure message + :type test: :class:`qemu_pytest.QemuSystemTest` + :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 QemuBaseTest(unittest.TestCase): + + # default timeout for all tests, can be overridden + timeout = 120 + + qemu_bin = os.getenv('PYTEST_QEMU_BINARY') + + workdir = os.path.join(BUILD_DIR, 'tests/pytest') + logdir = os.path.join(BUILD_DIR, 'tests/pytest') + + cpu = None + machine = None + + log = logging.getLogger('qemu-pytest') + + def setUp(self, bin_prefix): + self.assertIsNotNone(BUILD_DIR, 'PYTEST_BUILD_ROOT must be set') + self.assertIsNotNone(SOURCE_DIR,'PYTEST_SOURCE_ROOT must be set') + self.assertIsNotNone(self.qemu_bin, 'PYTEST_QEMU_BINARY must be set') + + def fetch_asset(self, name, + asset_hash, algorithm=None, + locations=None, expire=None, + find_only=False, cancel_on_missing=True): + return super().fetch_asset(name, + asset_hash=asset_hash, + algorithm=algorithm, + locations=locations, + expire=expire, + find_only=find_only, + cancel_on_missing=cancel_on_missing) + + +class QemuSystemTest(QemuBaseTest): + """Facilitates system emulation tests.""" + + def setUp(self): + self._vms = {} + + super().setUp('qemu-system-') + + def require_accelerator(self, accelerator): + """ + Requires an accelerator to be available for the test to continue + + It takes into account the currently set qemu binary. + + If the check fails, the test is canceled. If the check itself + for the given accelerator is not available, the test is also + canceled. + + :param accelerator: name of the accelerator, such as "kvm" or "tcg" + :type accelerator: str + """ + checker = {'tcg': tcg_available, + 'kvm': kvm_available}.get(accelerator) + if checker is None: + self.cancel("Don't know how to check for the presence " + "of accelerator %s" % accelerator) + if not checker(qemu_bin=self.qemu_bin): + self.cancel("%s accelerator does not seem to be " + "available" % accelerator) + + def require_netdev(self, netdevname): + netdevhelp = run_cmd([self.qemu_bin, + '-M', 'none', '-netdev', 'help'])[0]; + if netdevhelp.find('\n' + netdevname + '\n') < 0: + self.cancel('no support for user networking') + + def require_multiprocess(self): + """ + Test for the presence of the x-pci-proxy-dev which is required + to support multiprocess. + """ + devhelp = run_cmd([self.qemu_bin, + '-M', 'none', '-device', 'help'])[0]; + if devhelp.find('x-pci-proxy-dev') < 0: + self.cancel('no support for multiprocess device emulation') + + def _new_vm(self, name, *args): + self._sd = tempfile.TemporaryDirectory(prefix="qemu_") + vm = QEMUMachine(self.qemu_bin, base_temp_dir=self.workdir, + log_dir=self.logdir) + self.log.debug('QEMUMachine "%s" created', name) + self.log.debug('QEMUMachine "%s" temp_dir: %s', name, vm.temp_dir) + self.log.debug('QEMUMachine "%s" log_dir: %s', name, vm.log_dir) + if args: + vm.add_args(*args) + return vm + + def get_qemu_img(self): + self.log.debug('Looking for and selecting a qemu-img binary') + + # If qemu-img has been built, use it, otherwise the system wide one + # will be used. + qemu_img = os.path.join(BUILD_DIR, 'qemu-img') + if not os.path.exists(qemu_img): + qemu_img = find_command('qemu-img', False) + if qemu_img is False: + self.cancel('Could not find "qemu-img"') + + return qemu_img + + @property + def vm(self): + return self.get_vm(name='default') + + def get_vm(self, *args, name=None): + if not name: + name = str(uuid.uuid4()) + if self._vms.get(name) is None: + self._vms[name] = self._new_vm(name, *args) + if self.cpu is not None: + self._vms[name].add_args('-cpu', self.cpu) + if self.machine is not None: + self._vms[name].set_machine(self.machine) + return self._vms[name] + + def set_vm_arg(self, arg, value): + """ + Set an argument to list of extra arguments to be given to the QEMU + binary. If the argument already exists then its value is replaced. + + :param arg: the QEMU argument, such as "-cpu" in "-cpu host" + :type arg: str + :param value: the argument value, such as "host" in "-cpu host" + :type value: str + """ + if not arg or not value: + return + if arg not in self.vm.args: + self.vm.args.extend([arg, value]) + else: + idx = self.vm.args.index(arg) + 1 + if idx < len(self.vm.args): + self.vm.args[idx] = value + else: + self.vm.args.append(value) + + def tearDown(self): + for vm in self._vms.values(): + vm.shutdown() + self._sd = None + super().tearDown() + + +class QemuUserTest(QemuBaseTest): + """Facilitates user-mode emulation tests.""" + + def setUp(self): + self._ldpath = [] + super().setUp('qemu-') + + def add_ldpath(self, ldpath): + self._ldpath.append(os.path.abspath(ldpath)) + + def run(self, bin_path, args=[]): + qemu_args = " ".join(["-L %s" % ldpath for ldpath in self._ldpath]) + bin_args = " ".join(args) + return process.run("%s %s %s %s" % (self.qemu_bin, qemu_args, + bin_path, bin_args)) From patchwork Thu Jul 11 11:55:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 13730622 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7C6E6C3DA41 for ; Thu, 11 Jul 2024 11:57:01 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRsPe-00042I-1v; Thu, 11 Jul 2024 07:56:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPN-00036U-5w for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPA-000477-WB for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720698968; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kFDx3AzhkOo696BWjrSPKvBIZNzTiUauoq2tCa2FXRQ=; b=LpGvFQ1hnuWsJxizmWhbYZFZ8eBud0pnnNeY1tWWaZdBS8AxXcLx5KQIlzIWjQHzVKiljB N218YeQFO6LD6DFRlnJt2JanbQaGNHJwBLdhGr6eJKeYNyau2tmd4/YMk8I1Di+2EF8w4h EtoixkGnLdTCyv0HY5oPC7c1qRgLcfU= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-113-lSR4S4ZyOLmSRa-sjdVGsw-1; Thu, 11 Jul 2024 07:56:05 -0400 X-MC-Unique: lSR4S4ZyOLmSRa-sjdVGsw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 38D6518B65CA; Thu, 11 Jul 2024 11:56:04 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.193.118]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0A6DD1955E85; Thu, 11 Jul 2024 11:55:58 +0000 (UTC) From: Thomas Huth To: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Ani Sinha , Richard Henderson , Paolo Bonzini , "Daniel P . Berrange" , John Snow Subject: [RFC PATCH 2/8] tests/pytest: Convert some simple avocado tests into pytests Date: Thu, 11 Jul 2024 13:55:40 +0200 Message-ID: <20240711115546.40859-3-thuth@redhat.com> In-Reply-To: <20240711115546.40859-1-thuth@redhat.com> References: <20240711115546.40859-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org These test are rather simple and don't need any modifications apart from adjusting the "from avocado_qemu" line. These tests can now be run directly via "pytest" by setting the PYTHONPATH environment variable to the python folder of QEMU and by providing the QEMU binary via the PYTEST_QEMU_BINARY environment variable, and the source and build directories via the PYTEST_SOURCE_ROOTand PYTEST_BUILD_ROOT environment variables. Signed-off-by: Thomas Huth Reviewed-by: Daniel P. Berrangé --- tests/{avocado/cpu_queries.py => pytest/test_cpu_queries.py} | 2 +- .../empty_cpu_model.py => pytest/test_empty_cpu_model.py} | 2 +- .../mem-addr-space-check.py => pytest/test_mem_addr_space.py} | 3 +-- .../virtio_version.py => pytest/test_virtio_version.py} | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) rename tests/{avocado/cpu_queries.py => pytest/test_cpu_queries.py} (96%) rename tests/{avocado/empty_cpu_model.py => pytest/test_empty_cpu_model.py} (94%) rename tests/{avocado/mem-addr-space-check.py => pytest/test_mem_addr_space.py} (99%) rename tests/{avocado/virtio_version.py => pytest/test_virtio_version.py} (99%) diff --git a/tests/avocado/cpu_queries.py b/tests/pytest/test_cpu_queries.py similarity index 96% rename from tests/avocado/cpu_queries.py rename to tests/pytest/test_cpu_queries.py index d3faa14720..b300447121 100644 --- a/tests/avocado/cpu_queries.py +++ b/tests/pytest/test_cpu_queries.py @@ -8,7 +8,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. -from avocado_qemu import QemuSystemTest +from qemu_pytest import QemuSystemTest class QueryCPUModelExpansion(QemuSystemTest): """ diff --git a/tests/avocado/empty_cpu_model.py b/tests/pytest/test_empty_cpu_model.py similarity index 94% rename from tests/avocado/empty_cpu_model.py rename to tests/pytest/test_empty_cpu_model.py index d906ef3d3c..113740bc82 100644 --- a/tests/avocado/empty_cpu_model.py +++ b/tests/pytest/test_empty_cpu_model.py @@ -7,7 +7,7 @@ # # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. -from avocado_qemu import QemuSystemTest +from qemu_pytest import QemuSystemTest class EmptyCPUModel(QemuSystemTest): def test(self): diff --git a/tests/avocado/mem-addr-space-check.py b/tests/pytest/test_mem_addr_space.py similarity index 99% rename from tests/avocado/mem-addr-space-check.py rename to tests/pytest/test_mem_addr_space.py index 85541ea051..6ae7ba5e6b 100644 --- a/tests/avocado/mem-addr-space-check.py +++ b/tests/pytest/test_mem_addr_space.py @@ -8,8 +8,7 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -from avocado_qemu import QemuSystemTest -import signal +from qemu_pytest import QemuSystemTest import time class MemAddrCheck(QemuSystemTest): diff --git a/tests/avocado/virtio_version.py b/tests/pytest/test_virtio_version.py similarity index 99% rename from tests/avocado/virtio_version.py rename to tests/pytest/test_virtio_version.py index afe5e828b5..ca3aa806df 100644 --- a/tests/avocado/virtio_version.py +++ b/tests/pytest/test_virtio_version.py @@ -12,7 +12,7 @@ import os from qemu.machine import QEMUMachine -from avocado_qemu import QemuSystemTest +from qemu_pytest import QemuSystemTest # Virtio Device IDs: VIRTIO_NET = 1 From patchwork Thu Jul 11 11:55:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 13730621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 050E4C41513 for ; Thu, 11 Jul 2024 11:56:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRsPX-0003Hf-VM; Thu, 11 Jul 2024 07:56:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPI-0002kb-Ho for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPG-000499-1F for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720698972; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5fu+46QJHWywwyFBmzBK0M1K/+VQFbUkdqggpGNG6nA=; b=eeu79MPMnYBVh77vjljDrdIe2dzcdRvZ4zMdAhMp4r8y92Gi7huBFNMULH4Ik17EhDjhga oCBFeVOniOMn+971TQ0k6/1nh7edenoJrDTdhFSi+oZfXZkhCAoIeRm1qTuVxOlGzhswgs nUEiNou3C6pid7voWhXQmm/J2HUzFhk= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-586-5Aret1sqNmuU2q5FhBmxEA-1; Thu, 11 Jul 2024 07:56:09 -0400 X-MC-Unique: 5Aret1sqNmuU2q5FhBmxEA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 17A481954B3E; Thu, 11 Jul 2024 11:56:08 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.193.118]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A5F761955BD4; Thu, 11 Jul 2024 11:56:04 +0000 (UTC) From: Thomas Huth To: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Ani Sinha , Richard Henderson , Paolo Bonzini , "Daniel P . Berrange" , John Snow Subject: [RFC PATCH 3/8] tests/pytest: Convert info_usernet and version test with small adjustments Date: Thu, 11 Jul 2024 13:55:41 +0200 Message-ID: <20240711115546.40859-4-thuth@redhat.com> In-Reply-To: <20240711115546.40859-1-thuth@redhat.com> References: <20240711115546.40859-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org These two simple tests can be converted to a pytest quite easily, we just have to set the machine to 'none' now manually since we don't support the avocado tags here yet. Signed-off-by: Thomas Huth Reviewed-by: Daniel P. Berrangé --- .../info_usernet.py => pytest/test_info_usernet.py} | 6 ++---- tests/{avocado/version.py => pytest/test_version.py} | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) rename tests/{avocado/info_usernet.py => pytest/test_info_usernet.py} (91%) rename tests/{avocado/version.py => pytest/test_version.py} (82%) diff --git a/tests/avocado/info_usernet.py b/tests/pytest/test_info_usernet.py similarity index 91% rename from tests/avocado/info_usernet.py rename to tests/pytest/test_info_usernet.py index e1aa7a6e0a..0cc3697c0b 100644 --- a/tests/avocado/info_usernet.py +++ b/tests/pytest/test_info_usernet.py @@ -8,18 +8,16 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. -from avocado_qemu import QemuSystemTest +from qemu_pytest import QemuSystemTest from qemu.utils import get_info_usernet_hostfwd_port class InfoUsernet(QemuSystemTest): - """ - :avocado: tags=machine:none - """ def test_hostfwd(self): self.require_netdev('user') + self.machine = 'none' self.vm.add_args('-netdev', 'user,id=vnet,hostfwd=:127.0.0.1:0-:22') self.vm.launch() res = self.vm.cmd('human-monitor-command', diff --git a/tests/avocado/version.py b/tests/pytest/test_version.py similarity index 82% rename from tests/avocado/version.py rename to tests/pytest/test_version.py index c6139568a1..2d16b4075d 100644 --- a/tests/avocado/version.py +++ b/tests/pytest/test_version.py @@ -9,15 +9,13 @@ # later. See the COPYING file in the top-level directory. -from avocado_qemu import QemuSystemTest +from qemu_pytest import QemuSystemTest class Version(QemuSystemTest): - """ - :avocado: tags=quick - :avocado: tags=machine:none - """ + def test_qmp_human_info_version(self): + self.machine = 'none' self.vm.add_args('-nodefaults') self.vm.launch() res = self.vm.cmd('human-monitor-command', From patchwork Thu Jul 11 11:55:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 13730626 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3FC0AC41513 for ; Thu, 11 Jul 2024 11:57:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRsPo-00050E-NK; Thu, 11 Jul 2024 07:56:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPL-0002xz-Li for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPJ-00049T-Dx for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720698976; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BzwkZqC9qi7v/FxNIMeqQtAlpjf1dJrzDsFE1tBNDhQ=; b=K9h6r2i1CKpcclCM6oKCDoj9b0KRMFTHVj0lAtXc6cD98XsHobnbu/A2+PBQ30g3QJLM4Q D8f77gdvcam8Ufl+RnawvIJkKqLpYvL/aMHJ/rOA9aKz+ET2FJcYMaT6MlHGJTqJ0rTHbZ 0Eam+btOI0iAKhgjA17WHdqJhkvHfH4= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-21-w-RpeTIWNEWJ0u0oPU7Slw-1; Thu, 11 Jul 2024 07:56:13 -0400 X-MC-Unique: w-RpeTIWNEWJ0u0oPU7Slw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4CE7519773FE; Thu, 11 Jul 2024 11:56:12 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.193.118]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id BA4A61955E85; Thu, 11 Jul 2024 11:56:08 +0000 (UTC) From: Thomas Huth To: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Ani Sinha , Richard Henderson , Paolo Bonzini , "Daniel P . Berrange" , John Snow Subject: [RFC PATCH 4/8] tests/pytest: add pytest to the meson build system Date: Thu, 11 Jul 2024 13:55:42 +0200 Message-ID: <20240711115546.40859-5-thuth@redhat.com> In-Reply-To: <20240711115546.40859-1-thuth@redhat.com> References: <20240711115546.40859-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org From: Ani Sinha Integrate the pytest framework with the meson build system. This will make meson run all the pytests under the pytest directory. Signed-off-by: Ani Sinha [thuth: Removed the acpi-bits and adjusted for converted avocado tests instead] Signed-off-by: Thomas Huth --- tests/Makefile.include | 4 ++- tests/meson.build | 1 + tests/pytest/meson.build | 53 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/pytest/meson.build diff --git a/tests/Makefile.include b/tests/Makefile.include index d39d5dd6a4..68151717d7 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -3,12 +3,14 @@ .PHONY: check-help check-help: @echo "Regression testing targets:" - @echo " $(MAKE) check Run block, qapi-schema, unit, softfloat, qtest and decodetree tests" + @echo " $(MAKE) check Run block, qapi-schema, unit, softfloat, qtest, pytest and decodetree tests" @echo " $(MAKE) bench Run speed tests" @echo @echo "Individual test suites:" @echo " $(MAKE) check-qtest-TARGET Run qtest tests for given target" @echo " $(MAKE) check-qtest Run qtest tests" + @echo " $(MAKE) check-pytest Run pytest tests" + @echo " $(MAKE) check-pytest-TARGET Run pytest for a given target" @echo " $(MAKE) check-unit Run qobject tests" @echo " $(MAKE) check-qapi-schema Run QAPI schema tests" @echo " $(MAKE) check-block Run block tests" diff --git a/tests/meson.build b/tests/meson.build index acb6807094..17510a468e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -85,3 +85,4 @@ subdir('unit') subdir('qapi-schema') subdir('qtest') subdir('migration') +subdir('pytest') diff --git a/tests/pytest/meson.build b/tests/pytest/meson.build new file mode 100644 index 0000000000..1486628d45 --- /dev/null +++ b/tests/pytest/meson.build @@ -0,0 +1,53 @@ +slow_pytests = { + 'mem_addr_space' : 90, +} + +pytests_generic = [ + 'empty_cpu_model', + 'info_usernet', + 'version', +] + +pytests_x86_64 = [ + 'cpu_queries', + 'mem_addr_space', + 'virtio_version', +] + +pytest = find_program('pytest', required: false) +if not pytest.found() + message('pytest not available ==> Disabled the qemu-pytests.') + subdir_done() +endif + +foreach dir : target_dirs + if not dir.endswith('-softmmu') + continue + endif + + target_base = dir.split('-')[0] + pytest_emulator = emulators['qemu-system-' + target_base] + target_pytests = get_variable('pytests_' + target_base, []) + pytests_generic + + test_deps = roms + pytest_env = environment() + if have_tools + pytest_env.set('PYTEST_QEMU_IMG', './qemu-img') + test_deps += [qemu_img] + endif + pytest_env.set('PYTEST_QEMU_BINARY', meson.global_build_root() / 'qemu-system-' + target_base) + pytest_env.set('PYTEST_SOURCE_ROOT', meson.project_source_root()) + pytest_env.set('PYTEST_BUILD_ROOT', meson.project_build_root()) + pytest_env.set('PYTHONPATH', meson.project_source_root() / 'python') + + foreach test : target_pytests + test('pytest-@0@/@1@'.format(target_base, test), + pytest, + depends: [test_deps, pytest_emulator, emulator_modules], + env: pytest_env, + args: [meson.current_source_dir() / 'test_' + test + '.py'], + timeout: slow_pytests.get(test, 60), + priority: slow_pytests.get(test, 60), + suite: ['pytest', 'pytest-' + target_base]) + endforeach +endforeach From patchwork Thu Jul 11 11:55:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 13730625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 09453C3DA41 for ; Thu, 11 Jul 2024 11:57:43 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRsPj-0004bG-1P; Thu, 11 Jul 2024 07:56:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPQ-0003Ir-6j for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPO-0004A1-CA for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720698981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UTuTKKfgydqIlWwz40hk1KYERihdyi4iwi8ncTl+GqU=; b=EVbmz/EN2IgMvg9p9Xde9wSgZ2ZCSwp+lOOaDYsJxO8nGAl3Mg2bnyjR2sfBQA/4/vHnYw tmPrtzDuktIU2wNgSHcsxs7zot5FtCoXtufAKJSHvnsOXp4iPfDDp8K3+Q1o0ErIBqQwEl Hkyh/yll4OtjaMOc1AO6itBW0WkkA8o= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-8fKPfOauNiqQ3xuDW3yjlg-1; Thu, 11 Jul 2024 07:56:18 -0400 X-MC-Unique: 8fKPfOauNiqQ3xuDW3yjlg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EBA6419792FB; Thu, 11 Jul 2024 11:56:16 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.193.118]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2ECA1955BD4; Thu, 11 Jul 2024 11:56:12 +0000 (UTC) From: Thomas Huth To: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Ani Sinha , Richard Henderson , Paolo Bonzini , "Daniel P . Berrange" , John Snow Subject: [RFC PATCH 5/8] tests_pytest: Implement fetch_asset() method for downloading assets Date: Thu, 11 Jul 2024 13:55:43 +0200 Message-ID: <20240711115546.40859-6-thuth@redhat.com> In-Reply-To: <20240711115546.40859-1-thuth@redhat.com> References: <20240711115546.40859-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org In the pytests, we cannot use the fetch_asset() function from Avocado anymore, so we have to provide our own implementation now instead. Thus add such a function based on the _download_with_cache() function from tests/vm/basevm.py for this purpose. Signed-off-by: Thomas Huth --- tests/pytest/qemu_pytest/__init__.py | 40 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/tests/pytest/qemu_pytest/__init__.py b/tests/pytest/qemu_pytest/__init__.py index e3ed32e3de..73d80b3828 100644 --- a/tests/pytest/qemu_pytest/__init__.py +++ b/tests/pytest/qemu_pytest/__init__.py @@ -11,6 +11,7 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. +import hashlib import logging import os import shutil @@ -201,17 +202,34 @@ def setUp(self, bin_prefix): self.assertIsNotNone(SOURCE_DIR,'PYTEST_SOURCE_ROOT must be set') self.assertIsNotNone(self.qemu_bin, 'PYTEST_QEMU_BINARY must be set') - def fetch_asset(self, name, - asset_hash, algorithm=None, - locations=None, expire=None, - find_only=False, cancel_on_missing=True): - return super().fetch_asset(name, - asset_hash=asset_hash, - algorithm=algorithm, - locations=locations, - expire=expire, - find_only=find_only, - cancel_on_missing=cancel_on_missing) + def check_hash(self, file_name, expected_hash): + if not expected_hash: + return True + if len(expected_hash) == 32: + sum_prog = 'md5sum' + elif len(expected_hash) == 40: + sum_prog = 'sha1sum' + elif len(expected_hash) == 64: + sum_prog = 'sha256sum' + elif len(expected_hash) == 128: + sum_prog = 'sha512sum' + else: + raise Exception("unknown hash type") + checksum = subprocess.check_output([sum_prog, file_name]).split()[0] + return expected_hash == checksum.decode("utf-8") + + def fetch_asset(self, url, asset_hash): + cache_dir = os.path.expanduser("~/.cache/qemu/download") + if not os.path.exists(cache_dir): + os.makedirs(cache_dir) + fname = os.path.join(cache_dir, + hashlib.sha1(url.encode("utf-8")).hexdigest()) + if os.path.exists(fname) and self.check_hash(fname, asset_hash): + return fname + logging.debug("Downloading %s to %s...", url, fname) + subprocess.check_call(["wget", "-c", url, "-O", fname + ".download"]) + os.rename(fname + ".download", fname) + return fname class QemuSystemTest(QemuBaseTest): From patchwork Thu Jul 11 11:55:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 13730624 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A510C3DA4A for ; Thu, 11 Jul 2024 11:57:39 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRsQ7-0006P3-OP; Thu, 11 Jul 2024 07:57:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPZ-00040n-Ro for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPU-0004Ad-BP for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720698986; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h18LYbjBJTgvDMDvH+3FMrTXwPHvgF54cOWbiPgrN0I=; b=ckfJVyoDa2WtiDi5YaeyQoCWy5QDeUbZkDHodejKbKC9P00r3fgQlfp9h4cSK0mFTtk7fM g6yYa+y0wmG509Hx94OwVie6ZY1A2laBhR8fWu5U6bI8hk6pRpIJH7UV6gGSBS4ouWH2F5 LiveEfLDym0RqdiI49uhkYQEmMEeFKU= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-688-M5v_Oe42NuKpmiTR4JIW3Q-1; Thu, 11 Jul 2024 07:56:23 -0400 X-MC-Unique: M5v_Oe42NuKpmiTR4JIW3Q-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1C9BA1954B3F; Thu, 11 Jul 2024 11:56:22 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.193.118]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 375F21954219; Thu, 11 Jul 2024 11:56:16 +0000 (UTC) From: Thomas Huth To: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Ani Sinha , Richard Henderson , Paolo Bonzini , "Daniel P . Berrange" , John Snow Subject: [RFC PATCH 6/8] tests/pytest: Convert some tests that download files via fetch_asset() Date: Thu, 11 Jul 2024 13:55:44 +0200 Message-ID: <20240711115546.40859-7-thuth@redhat.com> In-Reply-To: <20240711115546.40859-1-thuth@redhat.com> References: <20240711115546.40859-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Now that we've got a working fetch_asset() function, we can convert some Avocado tests that use this function for downloading their required files. Signed-off-by: Thomas Huth Reviewed-by: Daniel P. Berrangé --- tests/pytest/meson.build | 16 +++++++++++++++ .../test_machine_arm_n8x0.py} | 20 +++++++------------ .../test_machine_avr6.py} | 7 ++----- .../test_machine_loongarch.py} | 11 ++++------ .../test_machine_mips_loongson3v.py} | 19 ++++++------------ 5 files changed, 35 insertions(+), 38 deletions(-) rename tests/{avocado/machine_arm_n8x0.py => pytest/test_machine_arm_n8x0.py} (71%) rename tests/{avocado/machine_avr6.py => pytest/test_machine_avr6.py} (91%) rename tests/{avocado/machine_loongarch.py => pytest/test_machine_loongarch.py} (89%) rename tests/{avocado/machine_mips_loongson3v.py => pytest/test_machine_mips_loongson3v.py} (59%) diff --git a/tests/pytest/meson.build b/tests/pytest/meson.build index 1486628d45..d3607db362 100644 --- a/tests/pytest/meson.build +++ b/tests/pytest/meson.build @@ -8,6 +8,22 @@ pytests_generic = [ 'version', ] +pytests_arm = [ + 'machine_arm_n8x0', +] + +pytests_avr = [ + 'machine_avr6', +] + +pytests_loongarch64 = [ + 'machine_loongarch', +] + +pytests_mips64el = [ + 'machine_mips_loongson3v', +] + pytests_x86_64 = [ 'cpu_queries', 'mem_addr_space', diff --git a/tests/avocado/machine_arm_n8x0.py b/tests/pytest/test_machine_arm_n8x0.py similarity index 71% rename from tests/avocado/machine_arm_n8x0.py rename to tests/pytest/test_machine_arm_n8x0.py index 12e9a6803b..082284b975 100644 --- a/tests/avocado/machine_arm_n8x0.py +++ b/tests/pytest/test_machine_arm_n8x0.py @@ -10,9 +10,9 @@ import os -from avocado import skipUnless -from avocado_qemu import QemuSystemTest -from avocado_qemu import wait_for_console_pattern +from unittest import skipUnless +from qemu_pytest import QemuSystemTest +from qemu_pytest import wait_for_console_pattern class N8x0Machine(QemuSystemTest): """Boots the Linux kernel and checks that the console is operational""" @@ -32,18 +32,12 @@ def __do_test_n8x0(self): self.vm.launch() wait_for_console_pattern(self, 'TSC2005 driver initializing') - @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code') + @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code') def test_n800(self): - """ - :avocado: tags=arch:arm - :avocado: tags=machine:n800 - """ + self.machine = 'n800' self.__do_test_n8x0() - @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code') + @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code') def test_n810(self): - """ - :avocado: tags=arch:arm - :avocado: tags=machine:n810 - """ + self.machine = 'n810' self.__do_test_n8x0() diff --git a/tests/avocado/machine_avr6.py b/tests/pytest/test_machine_avr6.py similarity index 91% rename from tests/avocado/machine_avr6.py rename to tests/pytest/test_machine_avr6.py index 5485db79c6..479038a221 100644 --- a/tests/avocado/machine_avr6.py +++ b/tests/pytest/test_machine_avr6.py @@ -19,16 +19,12 @@ import time -from avocado_qemu import QemuSystemTest +from qemu_pytest import QemuSystemTest class AVR6Machine(QemuSystemTest): timeout = 5 def test_freertos(self): - """ - :avocado: tags=arch:avr - :avocado: tags=machine:arduino-mega-2560-v3 - """ """ https://github.com/seharris/qemu-avr-tests/raw/master/free-rtos/Demo/AVR_ATMega2560_GCC/demo.elf constantly prints out 'ABCDEFGHIJKLMNOPQRSTUVWXABCDEFGHIJKLMNOPQRSTUVWX' @@ -39,6 +35,7 @@ def test_freertos(self): rom_hash = '7eb521f511ca8f2622e0a3c5e8dd686efbb911d4' rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash) + self.machine = 'arduino-mega-2560-v3' self.vm.add_args('-bios', rom_path) self.vm.add_args('-nographic') self.vm.launch() diff --git a/tests/avocado/machine_loongarch.py b/tests/pytest/test_machine_loongarch.py similarity index 89% rename from tests/avocado/machine_loongarch.py rename to tests/pytest/test_machine_loongarch.py index 8de308f2d6..3eb68745ac 100644 --- a/tests/avocado/machine_loongarch.py +++ b/tests/pytest/test_machine_loongarch.py @@ -5,9 +5,9 @@ # Copyright (c) 2023 Loongson Technology Corporation Limited # -from avocado_qemu import QemuSystemTest -from avocado_qemu import exec_command_and_wait_for_pattern -from avocado_qemu import wait_for_console_pattern +from qemu_pytest import QemuSystemTest +from qemu_pytest import exec_command_and_wait_for_pattern +from qemu_pytest import wait_for_console_pattern class LoongArchMachine(QemuSystemTest): KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' @@ -21,10 +21,7 @@ def wait_for_console_pattern(self, success_message, vm=None): def test_loongarch64_devices(self): - """ - :avocado: tags=arch:loongarch64 - :avocado: tags=machine:virt - """ + self.machine = 'virt' kernel_url = ('https://github.com/yangxiaojuan-loongson/qemu-binary/' 'releases/download/2024-05-30/vmlinuz.efi') diff --git a/tests/avocado/machine_mips_loongson3v.py b/tests/pytest/test_machine_mips_loongson3v.py similarity index 59% rename from tests/avocado/machine_mips_loongson3v.py rename to tests/pytest/test_machine_mips_loongson3v.py index 5194cf18c9..189b22c04e 100644 --- a/tests/avocado/machine_mips_loongson3v.py +++ b/tests/pytest/test_machine_mips_loongson3v.py @@ -10,28 +10,21 @@ import os import time -from avocado import skipUnless -from avocado_qemu import QemuSystemTest -from avocado_qemu import wait_for_console_pattern +from unittest import skipUnless +from qemu_pytest import QemuSystemTest +from qemu_pytest import wait_for_console_pattern class MipsLoongson3v(QemuSystemTest): timeout = 60 - @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code') + @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code') def test_pmon_serial_console(self): - """ - :avocado: tags=arch:mips64el - :avocado: tags=endian:little - :avocado: tags=machine:loongson3-virt - :avocado: tags=cpu:Loongson-3A1000 - :avocado: tags=device:liointc - :avocado: tags=device:goldfish_rtc - """ + self.machine = 'loongson3-virt' pmon_hash = '7c8b45dd81ccfc55ff28f5aa267a41c3' pmon_path = self.fetch_asset('https://github.com/loongson-community/pmon/' 'releases/download/20210112/pmon-3avirt.bin', - asset_hash=pmon_hash, algorithm='md5') + asset_hash=pmon_hash) self.vm.set_console() self.vm.add_args('-bios', pmon_path) From patchwork Thu Jul 11 11:55:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 13730627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 250DEC3DA4A for ; Thu, 11 Jul 2024 11:57:53 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRsQA-0006gO-D2; Thu, 11 Jul 2024 07:57:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPb-00048J-NX for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPZ-0004Do-Js for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720698991; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L9XVptoyfJC1s3k6W3dh/KudkasKHfThFVX6ebRGQmU=; b=K78Y8fiyYjc7EerJpk2vGgoTCEeEjgroC0EnkqJoClXgTadKyl7639c3r2fayAh0SNqnKh vAh3peML+EagCXfMXI0+m02ryUs4qSPSbs2/GiNNrFhMmc6NvDJpbGnHmG/2h+DjYOh/pB 7cem5Xhxu8faE2ScWGJhup4UsfVimkI= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-392-6zsrmp6PObmI4rS45OLNbw-1; Thu, 11 Jul 2024 07:56:27 -0400 X-MC-Unique: 6zsrmp6PObmI4rS45OLNbw-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 707F619331B2; Thu, 11 Jul 2024 11:56:26 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.193.118]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D79471954225; Thu, 11 Jul 2024 11:56:22 +0000 (UTC) From: Thomas Huth To: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Ani Sinha , Richard Henderson , Paolo Bonzini , "Daniel P . Berrange" , John Snow Subject: [RFC PATCH 7/8] tests/pytest: Add a function for extracting files from an archive Date: Thu, 11 Jul 2024 13:55:45 +0200 Message-ID: <20240711115546.40859-8-thuth@redhat.com> In-Reply-To: <20240711115546.40859-1-thuth@redhat.com> References: <20240711115546.40859-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Some Avocado-based tests use the "archive" module from avocado.utils to extract files from an archive. To be able to use these tests without Avocado, we have to provide our own function for extracting files. Fortunately, there is already the tarfile module that will provide us with this functionality, so let's just add a nice wrapper function around that. Signed-off-by: Thomas Huth --- tests/pytest/qemu_pytest/utils.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/pytest/qemu_pytest/utils.py diff --git a/tests/pytest/qemu_pytest/utils.py b/tests/pytest/qemu_pytest/utils.py new file mode 100644 index 0000000000..4eb5e5d5e5 --- /dev/null +++ b/tests/pytest/qemu_pytest/utils.py @@ -0,0 +1,21 @@ +# Utilities for python-based QEMU tests +# +# Copyright 2024 Red Hat, Inc. +# +# Authors: +# Thomas Huth +# +# 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 tarfile + +def archive_extract(archive, dest_dir, member=None): + with tarfile.open(archive) as tf: + if hasattr(tarfile, 'data_filter'): + tf.extraction_filter = getattr(tarfile, 'data_filter', + (lambda member, path: member)) + if member: + tf.extract(member=member, path=dest_dir) + else: + tf.extractall(path=dest_dir) From patchwork Thu Jul 11 11:55:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 13730623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D3D9C3DA4A for ; Thu, 11 Jul 2024 11:57:10 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRsPz-00059L-VZ; Thu, 11 Jul 2024 07:57:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPd-0004GY-ME for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRsPa-0004ER-Un for qemu-devel@nongnu.org; Thu, 11 Jul 2024 07:56:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720698994; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=L5PcsCgL2IcK8j5iQ5rWgADeldCnm0hNp0IysS8YInY=; b=cPIGj1Gn959lUGaSMsAig1mQsB+/2ZRVGCBs5+AJYXpYfY5L2GmOdrpuVjSJG+Cznne3n9 KsMxsOPOHN3xSlffNSHCl8LED3wxw0Z+vD5m0KesXSektp8+6Sa8fuWDswTdJ9VnohGncI G5QCwde7RcCt482ilj2d3JjZrANewpE= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-647-X1AUam9sNcW5Bpm4uk_6dg-1; Thu, 11 Jul 2024 07:56:32 -0400 X-MC-Unique: X1AUam9sNcW5Bpm4uk_6dg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 308251944DFE; Thu, 11 Jul 2024 11:56:31 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.193.118]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E636D1955E85; Thu, 11 Jul 2024 11:56:26 +0000 (UTC) From: Thomas Huth To: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Cc: Ani Sinha , Richard Henderson , Paolo Bonzini , "Daniel P . Berrange" , John Snow Subject: [RFC PATCH 8/8] tests/pytest: Convert avocado test that needed avocado.utils.archive Date: Thu, 11 Jul 2024 13:55:46 +0200 Message-ID: <20240711115546.40859-9-thuth@redhat.com> In-Reply-To: <20240711115546.40859-1-thuth@redhat.com> References: <20240711115546.40859-1-thuth@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Instead of using the "archive" module from avocado.utils, switch these tests to use the new wrapper function that is based on the "tarfile" module instead. Signed-off-by: Thomas Huth --- tests/pytest/meson.build | 5 +++++ .../test_arm_canona1100.py} | 16 +++++++--------- .../test_ppc_bamboo.py} | 18 ++++++------------ 3 files changed, 18 insertions(+), 21 deletions(-) rename tests/{avocado/machine_arm_canona1100.py => pytest/test_arm_canona1100.py} (74%) rename tests/{avocado/ppc_bamboo.py => pytest/test_ppc_bamboo.py} (75%) diff --git a/tests/pytest/meson.build b/tests/pytest/meson.build index d3607db362..baaacf00cc 100644 --- a/tests/pytest/meson.build +++ b/tests/pytest/meson.build @@ -9,6 +9,7 @@ pytests_generic = [ ] pytests_arm = [ + 'arm_canona1100', 'machine_arm_n8x0', ] @@ -24,6 +25,10 @@ pytests_mips64el = [ 'machine_mips_loongson3v', ] +pytests_ppc = [ + 'ppc_bamboo', +] + pytests_x86_64 = [ 'cpu_queries', 'mem_addr_space', diff --git a/tests/avocado/machine_arm_canona1100.py b/tests/pytest/test_arm_canona1100.py similarity index 74% rename from tests/avocado/machine_arm_canona1100.py rename to tests/pytest/test_arm_canona1100.py index a42d8b0f2b..296df41a06 100644 --- a/tests/avocado/machine_arm_canona1100.py +++ b/tests/pytest/test_arm_canona1100.py @@ -8,9 +8,9 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. -from avocado_qemu import QemuSystemTest -from avocado_qemu import wait_for_console_pattern -from avocado.utils import archive +from qemu_pytest import QemuSystemTest +from qemu_pytest import wait_for_console_pattern +from qemu_pytest.utils import archive_extract class CanonA1100Machine(QemuSystemTest): """Boots the barebox firmware and checks that the console is operational""" @@ -18,16 +18,14 @@ class CanonA1100Machine(QemuSystemTest): timeout = 90 def test_arm_canona1100(self): - """ - :avocado: tags=arch:arm - :avocado: tags=machine:canon-a1100 - :avocado: tags=device:pflash_cfi02 - """ + self.machine = 'canon-a1100' + tar_url = ('https://qemu-advcal.gitlab.io' '/qac-best-of-multiarch/download/day18.tar.xz') tar_hash = '068b5fc4242b29381acee94713509f8a876e9db6' file_path = self.fetch_asset(tar_url, asset_hash=tar_hash) - archive.extract(file_path, self.workdir) + archive_extract(file_path, dest_dir=self.workdir, + member="day18/barebox.canon-a1100.bin") self.vm.set_console() self.vm.add_args('-bios', self.workdir + '/day18/barebox.canon-a1100.bin') diff --git a/tests/avocado/ppc_bamboo.py b/tests/pytest/test_ppc_bamboo.py similarity index 75% rename from tests/avocado/ppc_bamboo.py rename to tests/pytest/test_ppc_bamboo.py index a81be3d608..4964dedbfe 100644 --- a/tests/avocado/ppc_bamboo.py +++ b/tests/pytest/test_ppc_bamboo.py @@ -5,30 +5,24 @@ # This work is licensed under the terms of the GNU GPL, version 2 or # later. See the COPYING file in the top-level directory. -from avocado.utils import archive -from avocado_qemu import QemuSystemTest -from avocado_qemu import wait_for_console_pattern -from avocado_qemu import exec_command_and_wait_for_pattern +from qemu_pytest.utils import archive_extract +from qemu_pytest import QemuSystemTest +from qemu_pytest import wait_for_console_pattern +from qemu_pytest import exec_command_and_wait_for_pattern class BambooMachine(QemuSystemTest): timeout = 90 def test_ppc_bamboo(self): - """ - :avocado: tags=arch:ppc - :avocado: tags=machine:bamboo - :avocado: tags=cpu:440epb - :avocado: tags=device:rtl8139 - :avocado: tags=accel:tcg - """ + self.machine = 'bamboo' self.require_accelerator("tcg") self.require_netdev('user') tar_url = ('http://landley.net/aboriginal/downloads/binaries/' 'system-image-powerpc-440fp.tar.gz') tar_hash = '53e5f16414b195b82d2c70272f81c2eedb39bad9' file_path = self.fetch_asset(tar_url, asset_hash=tar_hash) - archive.extract(file_path, self.workdir) + archive_extract(file_path, self.workdir) self.vm.set_console() self.vm.add_args('-kernel', self.workdir + '/system-image-powerpc-440fp/linux',