diff mbox series

tests/functional: Convert Aarch64 Virt machine avocado tests

Message ID 20240822120750.89065-1-philmd@linaro.org
State New
Headers show
Series tests/functional: Convert Aarch64 Virt machine avocado tests | expand

Commit Message

Philippe Mathieu-Daudé Aug. 22, 2024, 12:07 p.m. UTC
Straight forward conversion. Update the SHA1 hash to
SHA256 since SHA1 should not be used anymore nowadays.
Use has_cmd() and run_cmd() methods from qemu_test.

  $ make check-functional-aarch64 V=1
  ...
  ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv2                 OK
  ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv3                 OK
  ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_alpine_virt_tcg_gic_max            OK
  1/4 qemu:func-thorough+func-aarch64-thorough+thorough / func-aarch64-aarch64_virt  OK   30.44s  3 subtests passed

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
Based-on: <20240822114146.86838-1-philmd@linaro.org>
---
 MAINTAINERS                                   |  2 +-
 tests/functional/meson.build                  |  2 +
 .../test_aarch64_virt.py}                     | 63 ++++++++-----------
 3 files changed, 29 insertions(+), 38 deletions(-)
 rename tests/{avocado/machine_aarch64_virt.py => functional/test_aarch64_virt.py} (74%)
 mode change 100644 => 100755

Comments

Thomas Huth Aug. 22, 2024, 12:41 p.m. UTC | #1
On 22/08/2024 14.07, Philippe Mathieu-Daudé wrote:
> Straight forward conversion. Update the SHA1 hash to
> SHA256 since SHA1 should not be used anymore nowadays.
> Use has_cmd() and run_cmd() methods from qemu_test.
> 
>    $ make check-functional-aarch64 V=1
>    ...
>    ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv2                 OK
>    ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv3                 OK
>    ▶ 1/4 test_aarch64_virt.Aarch64VirtMachine.test_alpine_virt_tcg_gic_max            OK
>    1/4 qemu:func-thorough+func-aarch64-thorough+thorough / func-aarch64-aarch64_virt  OK   30.44s  3 subtests passed
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
> Based-on: <20240822114146.86838-1-philmd@linaro.org>
> ---
...
> @@ -100,12 +98,11 @@ def common_aarch64_virt(self, machine):
>           image_path = os.path.join(self.workdir, 'scratch.qcow2')
>           qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
>           if not os.path.exists(qemu_img):
> -            qemu_img = find_command('qemu-img', False)
> +            qemu_img = has_cmd('qemu-img')

As far as I can see, has_cmd() returns either True or False ...

>           if qemu_img is False:
>               self.cancel('Could not find "qemu-img", which is required to '
>                           'create the temporary qcow2 image')
> -        cmd = '%s create -f qcow2 %s 8M' % (qemu_img, image_path)
> -        process.run(cmd)
> +        run_cmd([qemu_img, 'create', '-f', 'qcow2', image_path, '8M'])

... so this seems wrong to me?

tests/avocado/avocado_qemu/__init__.py used to have a get_qemu_img() 
function, maybe you could port that one over?

  Thomas
Philippe Mathieu-Daudé Aug. 23, 2024, 8:24 a.m. UTC | #2
On 22/8/24 14:41, Thomas Huth wrote:
> On 22/08/2024 14.07, Philippe Mathieu-Daudé wrote:
>> Straight forward conversion. Update the SHA1 hash to
>> SHA256 since SHA1 should not be used anymore nowadays.
>> Use has_cmd() and run_cmd() methods from qemu_test.
>>
>>    $ make check-functional-aarch64 V=1
>>    ...
>>    ▶ 1/4 
>> test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv2                 OK
>>    ▶ 1/4 
>> test_aarch64_virt.Aarch64VirtMachine.test_aarch64_virt_gicv3                 OK
>>    ▶ 1/4 
>> test_aarch64_virt.Aarch64VirtMachine.test_alpine_virt_tcg_gic_max            OK
>>    1/4 qemu:func-thorough+func-aarch64-thorough+thorough / 
>> func-aarch64-aarch64_virt  OK   30.44s  3 subtests passed
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>> Based-on: <20240822114146.86838-1-philmd@linaro.org>
>> ---
> ...
>> @@ -100,12 +98,11 @@ def common_aarch64_virt(self, machine):
>>           image_path = os.path.join(self.workdir, 'scratch.qcow2')
>>           qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
>>           if not os.path.exists(qemu_img):
>> -            qemu_img = find_command('qemu-img', False)
>> +            qemu_img = has_cmd('qemu-img')
> 
> As far as I can see, has_cmd() returns either True or False ...

Oops.

> 
>>           if qemu_img is False:
>>               self.cancel('Could not find "qemu-img", which is 
>> required to '
>>                           'create the temporary qcow2 image')
>> -        cmd = '%s create -f qcow2 %s 8M' % (qemu_img, image_path)
>> -        process.run(cmd)
>> +        run_cmd([qemu_img, 'create', '-f', 'qcow2', image_path, '8M'])
> 
> ... so this seems wrong to me?
> 
> tests/avocado/avocado_qemu/__init__.py used to have a get_qemu_img() 
> function, maybe you could port that one over?

Good idea.
diff mbox series

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index c720c02800..502065a1f2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1023,7 +1023,7 @@  S: Maintained
 F: hw/arm/virt*
 F: include/hw/arm/virt.h
 F: docs/system/arm/virt.rst
-F: tests/avocado/machine_aarch64_virt.py
+F: tests/functional/test_aarch64_virt.py
 
 Xilinx Zynq
 M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index aebeec1e0e..d31a1e7ac0 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -12,6 +12,7 @@  endif
 # Timeouts for individual tests that can be slow e.g. with debugging enabled
 test_timeouts = {
   'aarch64_sbsaref' : 18000,
+  'aarch64_virt' : 360,
   'acpi_bits' : 240,
   'netdev_ethtool' : 180,
   'ppc_40p' : 240,
@@ -29,6 +30,7 @@  tests_generic = [
 
 tests_aarch64_thorough = [
   'aarch64_sbsaref',
+  'aarch64_virt',
 ]
 
 tests_arm_thorough = [
diff --git a/tests/avocado/machine_aarch64_virt.py b/tests/functional/test_aarch64_virt.py
old mode 100644
new mode 100755
similarity index 74%
rename from tests/avocado/machine_aarch64_virt.py
rename to tests/functional/test_aarch64_virt.py
index 6831d2c0ed..d9a8e118c1
--- a/tests/avocado/machine_aarch64_virt.py
+++ b/tests/functional/test_aarch64_virt.py
@@ -1,3 +1,5 @@ 
+#!/usr/bin/env python3
+#
 # Functional test that boots a various Linux systems and checks the
 # console output.
 #
@@ -12,12 +14,10 @@ 
 import os
 import logging
 
-from avocado_qemu import QemuSystemTest
-from avocado_qemu import wait_for_console_pattern
-from avocado_qemu import exec_command
-from avocado_qemu import BUILD_DIR
-from avocado.utils import process
-from avocado.utils.path import find_command
+from qemu_test import BUILD_DIR
+from qemu_test import QemuSystemTest, Asset
+from qemu_test import exec_command, wait_for_console_pattern
+from qemu_test import has_cmd, run_cmd
 
 class Aarch64VirtMachine(QemuSystemTest):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -28,23 +28,18 @@  def wait_for_console_pattern(self, success_message, vm=None):
                                  failure_message='Kernel panic - not syncing',
                                  vm=vm)
 
+    ASSET_ALPINE_ISO = Asset(
+        ('https://dl-cdn.alpinelinux.org/'
+         'alpine/v3.17/releases/aarch64/alpine-standard-3.17.2-aarch64.iso'),
+        '5a36304ecf039292082d92b48152a9ec21009d3a62f459de623e19c4bd9dc027')
+
     # This tests the whole boot chain from EFI to Userspace
     # We only boot a whole OS for the current top level CPU and GIC
     # Other test profiles should use more minimal boots
     def test_alpine_virt_tcg_gic_max(self):
-        """
-        :avocado: tags=arch:aarch64
-        :avocado: tags=machine:virt
-        :avocado: tags=accel:tcg
-        """
-        iso_url = (
-            "https://dl-cdn.alpinelinux.org/"
-            "alpine/v3.17/releases/aarch64/alpine-standard-3.17.2-aarch64.iso"
-        )
-
-        iso_hash = "5a36304ecf039292082d92b48152a9ec21009d3a62f459de623e19c4bd9dc027"
-        iso_path = self.fetch_asset(iso_url, algorithm="sha256", asset_hash=iso_hash)
+        iso_path = self.ASSET_ALPINE_ISO.fetch()
 
+        self.set_machine('virt')
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
                                'console=ttyAMA0')
@@ -68,6 +63,11 @@  def test_alpine_virt_tcg_gic_max(self):
         self.wait_for_console_pattern('Welcome to Alpine Linux 3.17')
 
 
+    ASSET_KERNEL = Asset(
+        ('https://fileserver.linaro.org/s/'
+         'z6B2ARM7DQT3HWN/download'),
+        '12a54d4805cda6ab647cb7c7bbdb16fafb3df400e0d6f16445c1a0436100ef8d')
+
     def common_aarch64_virt(self, machine):
         """
         Common code to launch basic virt machine with kernel+initrd
@@ -75,11 +75,9 @@  def common_aarch64_virt(self, machine):
         """
         logger = logging.getLogger('aarch64_virt')
 
-        kernel_url = ('https://fileserver.linaro.org/s/'
-                      'z6B2ARM7DQT3HWN/download')
-        kernel_hash = 'ed11daab50c151dde0e1e9c9cb8b2d9bd3215347'
-        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
+        kernel_path = self.ASSET_KERNEL.fetch()
 
+        self.set_machine('virt')
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
                                'console=ttyAMA0')
@@ -100,12 +98,11 @@  def common_aarch64_virt(self, machine):
         image_path = os.path.join(self.workdir, 'scratch.qcow2')
         qemu_img = os.path.join(BUILD_DIR, 'qemu-img')
         if not os.path.exists(qemu_img):
-            qemu_img = find_command('qemu-img', False)
+            qemu_img = has_cmd('qemu-img')
         if qemu_img is False:
             self.cancel('Could not find "qemu-img", which is required to '
                         'create the temporary qcow2 image')
-        cmd = '%s create -f qcow2 %s 8M' % (qemu_img, image_path)
-        process.run(cmd)
+        run_cmd([qemu_img, 'create', '-f', 'qcow2', image_path, '8M'])
 
         # Add the device
         self.vm.add_args('-blockdev',
@@ -128,19 +125,11 @@  def common_aarch64_virt(self, machine):
         time.sleep(0.1)
 
     def test_aarch64_virt_gicv3(self):
-        """
-        :avocado: tags=arch:aarch64
-        :avocado: tags=machine:virt
-        :avocado: tags=accel:tcg
-        :avocado: tags=cpu:max
-        """
         self.common_aarch64_virt("virt,gic_version=3")
 
     def test_aarch64_virt_gicv2(self):
-        """
-        :avocado: tags=arch:aarch64
-        :avocado: tags=machine:virt
-        :avocado: tags=accel:tcg
-        :avocado: tags=cpu:max
-        """
         self.common_aarch64_virt("virt,gic-version=2")
+
+
+if __name__ == '__main__':
+    QemuSystemTest.main()