Skip to contentSkip to conversation

tests/functional: various improvements wrt assets/scratch files

PATCH Superseded Daniel P. Berrangé 4 participants 63 messages Nov 29, 2024 – Dec 6, 2024

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#6 lore raw

PATCH 3/22 tests/functional: remove duplicated 'qemu_test' import statements

In reply to Daniel P. Berrangé

Group all imports that originate in the 'qemu_test' package into one statement.

---
 tests/functional/qemu_test/tuxruntest.py         |  9 +++++----
 tests/functional/test_aarch64_raspi4.py          |  4 ++--
 tests/functional/test_aarch64_sbsaref.py         |  5 ++---
 tests/functional/test_aarch64_sbsaref_alpine.py  |  5 ++---
 tests/functional/test_aarch64_sbsaref_freebsd.py |  5 ++---
 tests/functional/test_aarch64_virt.py            |  6 ++----
 tests/functional/test_arm_aspeed.py              |  7 +++----
 tests/functional/test_arm_bflt.py                |  3 +--
 tests/functional/test_arm_bpim2u.py              |  8 ++++----
 tests/functional/test_arm_canona1100.py          |  3 +--
 tests/functional/test_arm_integratorcp.py        |  3 +--
 tests/functional/test_arm_orangepi.py            | 10 +++++-----
 tests/functional/test_arm_raspi2.py              |  4 ++--
 tests/functional/test_loongarch64_virt.py        |  6 +++---
 tests/functional/test_microblaze_s3adsp1800.py   |  5 ++---
 tests/functional/test_microblazeel_s3adsp1800.py |  5 ++---
 tests/functional/test_mips64el_fuloong2e.py      |  7 ++++---
 tests/functional/test_mips64el_loongson3v.py     |  3 +--
 tests/functional/test_mips64el_malta.py          |  4 ++--
 tests/functional/test_mipsel_malta.py            |  6 +++---
 tests/functional/test_multiprocess.py            |  4 ++--
 tests/functional/test_netdev_ethtool.py          |  3 +--
 tests/functional/test_ppc64_hv.py                |  4 ++--
 tests/functional/test_ppc64_powernv.py           |  3 +--
 tests/functional/test_ppc64_pseries.py           |  3 +--
 tests/functional/test_ppc_405.py                 |  6 +++---
 tests/functional/test_ppc_40p.py                 |  3 +--
 tests/functional/test_ppc_74xx.py                |  3 +--
 tests/functional/test_ppc_amiga.py               |  3 +--
 tests/functional/test_ppc_bamboo.py              |  6 +++---
 tests/functional/test_ppc_mpc8544ds.py           |  3 +--
 tests/functional/test_ppc_virtex_ml507.py        |  3 +--
 tests/functional/test_riscv_opensbi.py           |  4 ++--
 tests/functional/test_rx_gdbsim.py               |  6 +++---
 tests/functional/test_s390x_ccw_virtio.py        |  6 +++---
 tests/functional/test_s390x_topology.py          |  7 +++----
 tests/functional/test_sh4eb_r2d.py               |  4 ++--
 tests/functional/test_sparc64_sun4u.py           |  3 +--
 tests/functional/test_virtio_gpu.py              | 10 ++++------
 39 files changed, 85 insertions(+), 107 deletions(-)
tests/functional/qemu_test/tuxruntest.py +5 -4
index ab3b27da43..7c0456923e 100644
@@ -13,10 +13,11 @@
 import stat
 import time
 
-from qemu_test import QemuSystemTest
-from qemu_test import exec_command, exec_command_and_wait_for_pattern
-from qemu_test import wait_for_console_pattern
-from qemu_test import has_cmd, run_cmd, get_qemu_img
+from qemu_test import (QemuSystemTest, exec_command,
+                       exec_command_and_wait_for_pattern,
+                       wait_for_console_pattern,
+                       has_cmd, run_cmd, get_qemu_img)
+
 
 class TuxRunBaselineTest(QemuSystemTest):
 
tests/functional/test_aarch64_raspi4.py +2 -2
index e5c9f77479..95e9c8e643 100755
@@ -7,8 +7,8 @@
 
 import os
 
-from qemu_test import LinuxKernelTest, Asset
-from qemu_test import exec_command_and_wait_for_pattern
+from qemu_test import (LinuxKernelTest, Asset,
+                       exec_command_and_wait_for_pattern)
 from qemu_test.utils import gzip_uncompress
 
 
tests/functional/test_aarch64_sbsaref.py +2 -3
index 6db08da522..8064b691c7 100755
@@ -10,9 +10,8 @@
 
 import os
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
-from qemu_test import interrupt_interactive_console_until_pattern
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       interrupt_interactive_console_until_pattern)
 from qemu_test.utils import lzma_uncompress
 
 def fetch_firmware(test):
tests/functional/test_aarch64_sbsaref_alpine.py +2 -3
index ebc29b2fb5..6496418659 100755
@@ -10,9 +10,8 @@
 
 import os
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
-from qemu_test import interrupt_interactive_console_until_pattern
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       interrupt_interactive_console_until_pattern)
 from unittest import skipUnless
 from test_aarch64_sbsaref import fetch_firmware
 
tests/functional/test_aarch64_sbsaref_freebsd.py +2 -3
index 80298dd190..002da59ea2 100755
@@ -10,9 +10,8 @@
 
 import os
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
-from qemu_test import interrupt_interactive_console_until_pattern
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       interrupt_interactive_console_until_pattern)
 from unittest import skipUnless
 from test_aarch64_sbsaref import fetch_firmware
 
tests/functional/test_aarch64_virt.py +2 -4
index c967da41b4..07b78f6a84 100755
@@ -14,10 +14,8 @@
 import os
 import logging
 
-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 get_qemu_img, run_cmd
+from qemu_test import (BUILD_DIR, QemuSystemTest, Asset, exec_command,
+                       wait_for_console_pattern, get_qemu_img, run_cmd)
 
 
 class Aarch64VirtMachine(QemuSystemTest):
tests/functional/test_arm_aspeed.py +3 -4
index d88170ac24..068740a813 100755
@@ -11,10 +11,9 @@
 import subprocess
 import tempfile
 
-from qemu_test import LinuxKernelTest, Asset
-from qemu_test import exec_command_and_wait_for_pattern
-from qemu_test import interrupt_interactive_console_until_pattern
-from qemu_test import has_cmd
+from qemu_test import (LinuxKernelTest, Asset,
+                       exec_command_and_wait_for_pattern,
+                       interrupt_interactive_console_until_pattern, has_cmd)
 from qemu_test.utils import archive_extract
 from zipfile import ZipFile
 from unittest import skipUnless
tests/functional/test_arm_bflt.py +1 -2
index 281925d11a..cd417ebcfc 100755
@@ -9,8 +9,7 @@
 import os
 import bz2
 
-from qemu_test import QemuUserTest, Asset
-from qemu_test import has_cmd
+from qemu_test import QemuUserTest, Asset, has_cmd
 from qemu_test.utils import cpio_extract
 from unittest import skipUnless
 
tests/functional/test_arm_bpim2u.py +4 -4
index 35ea58d46c..7b1b0a270f 100755
@@ -7,10 +7,10 @@
 
 import os
 
-from qemu_test import LinuxKernelTest, exec_command_and_wait_for_pattern
-from qemu_test import Asset, interrupt_interactive_console_until_pattern
-from qemu_test.utils import archive_extract, gzip_uncompress, lzma_uncompress
-from qemu_test.utils import image_pow2ceil_expand
+from qemu_test import (LinuxKernelTest, exec_command_and_wait_for_pattern,
+                       Asset, interrupt_interactive_console_until_pattern)
+from qemu_test.utils import (archive_extract, gzip_uncompress, lzma_uncompress,
+                             image_pow2ceil_expand)
 from unittest import skipUnless
 
 class BananaPiMachine(LinuxKernelTest):
tests/functional/test_arm_canona1100.py +1 -2
index 65f1228296..41e78b7d1b 100755
@@ -10,8 +10,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 qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 from qemu_test.utils import archive_extract
 
 class CanonA1100Machine(QemuSystemTest):
tests/functional/test_arm_integratorcp.py +1 -2
index 0fe083f661..c2c6ff6ac5 100755
@@ -15,8 +15,7 @@
 import os
 import logging
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 from unittest import skipUnless
 
 
tests/functional/test_arm_orangepi.py +5 -5
index 6d57223a03..676327e8ef 100755
@@ -8,11 +8,11 @@
 import os
 import shutil
 
-from qemu_test import LinuxKernelTest, exec_command_and_wait_for_pattern
-from qemu_test import Asset, interrupt_interactive_console_until_pattern
-from qemu_test import wait_for_console_pattern
-from qemu_test.utils import archive_extract, gzip_uncompress, lzma_uncompress
-from qemu_test.utils import image_pow2ceil_expand
+from qemu_test import (LinuxKernelTest, exec_command_and_wait_for_pattern,
+                       Asset, interrupt_interactive_console_until_pattern,
+                       wait_for_console_pattern)
+from qemu_test.utils import (archive_extract, gzip_uncompress, lzma_uncompress,
+                             image_pow2ceil_expand)
 from unittest import skipUnless
 
 class BananaPiMachine(LinuxKernelTest):
tests/functional/test_arm_raspi2.py +2 -2
index 3bf079dc4d..4d31454f8f 100755
@@ -9,8 +9,8 @@
 
 import os
 
-from qemu_test import LinuxKernelTest, Asset
-from qemu_test import exec_command_and_wait_for_pattern
+from qemu_test import (LinuxKernelTest, Asset,
+                       exec_command_and_wait_for_pattern)
 from qemu_test.utils import gzip_uncompress
 
 
tests/functional/test_loongarch64_virt.py +3 -3
index b7d9abf933..38cdd85f97 100755
@@ -7,9 +7,9 @@
 # Copyright (c) 2023 Loongson Technology Corporation Limited
 #
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import exec_command_and_wait_for_pattern
-from qemu_test import wait_for_console_pattern
+from qemu_test import (QemuSystemTest, Asset,
+                       exec_command_and_wait_for_pattern,
+                       wait_for_console_pattern)
 
 class LoongArchMachine(QemuSystemTest):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
tests/functional/test_microblaze_s3adsp1800.py +2 -3
index d2be3105a2..387feb5dcc 100755
@@ -7,9 +7,8 @@
 # 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 qemu_test import exec_command, exec_command_and_wait_for_pattern
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import (exec_command, exec_command_and_wait_for_pattern,
+                       QemuSystemTest, Asset, wait_for_console_pattern)
 from qemu_test.utils import archive_extract
 
 class MicroblazeMachine(QemuSystemTest):
tests/functional/test_microblazeel_s3adsp1800.py +2 -3
index faa3927f2e..875e2ab14c 100755
@@ -8,9 +8,8 @@
 # later. See the COPYING file in the top-level directory.
 
 import time
-from qemu_test import exec_command, exec_command_and_wait_for_pattern
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import (exec_command, exec_command_and_wait_for_pattern,
+                       QemuSystemTest, Asset, wait_for_console_pattern)
 from qemu_test.utils import archive_extract
 
 class MicroblazeelMachine(QemuSystemTest):
tests/functional/test_mips64el_fuloong2e.py +4 -3
index a32d5f9d08..8d0ae8d1d5 100755
@@ -12,10 +12,11 @@
 import os
 import subprocess
 
-from qemu_test import LinuxKernelTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import (LinuxKernelTest, Asset, wait_for_console_pattern,
+                       skipUntrustedTest)
 from unittest import skipUnless
 
+
 class MipsFuloong2e(LinuxKernelTest):
 
     timeout = 60
@@ -39,7 +40,7 @@ def test_linux_kernel_3_16(self):
         console_pattern = 'Kernel command line: %s' % kernel_command_line
         self.wait_for_console_pattern(console_pattern)
 
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    @skipUntrustedTest()
     @skipUnless(os.getenv('RESCUE_YL_PATH'), 'RESCUE_YL_PATH not available')
     def test_linux_kernel_2_6_27_isa_serial(self):
         # Recovery system for the Yeeloong laptop
tests/functional/test_mips64el_loongson3v.py +1 -2
index e57ec5499e..06032a3a6b 100755
@@ -12,8 +12,7 @@
 import os
 
 from unittest import skipUnless
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 
 class MipsLoongson3v(QemuSystemTest):
     timeout = 60
tests/functional/test_mips64el_malta.py +2 -2
index 6d1195d362..b5959d33ea 100755
@@ -12,8 +12,8 @@
 import os
 import logging
 
-from qemu_test import LinuxKernelTest, Asset
-from qemu_test import exec_command_and_wait_for_pattern
+from qemu_test import (LinuxKernelTest, Asset,
+                       exec_command_and_wait_for_pattern)
 from qemu_test.utils import gzip_uncompress
 from unittest import skipUnless
 
tests/functional/test_mipsel_malta.py +3 -3
index b8dfddd856..af6d280f99 100755
@@ -11,9 +11,9 @@
 
 import os
 
-from qemu_test import QemuSystemTest, LinuxKernelTest, Asset
-from qemu_test import interrupt_interactive_console_until_pattern
-from qemu_test import wait_for_console_pattern
+from qemu_test import (QemuSystemTest, LinuxKernelTest, Asset,
+                       interrupt_interactive_console_until_pattern,
+                       wait_for_console_pattern)
 from qemu_test.utils import lzma_uncompress
 from zipfile import ZipFile
 
tests/functional/test_multiprocess.py +2 -2
index 751cf10e63..33fcb26381 100755
@@ -9,8 +9,8 @@
 import os
 import socket
 
-from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
-from qemu_test import exec_command, exec_command_and_wait_for_pattern
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       exec_command, exec_command_and_wait_for_pattern)
 
 class Multiprocess(QemuSystemTest):
 
tests/functional/test_netdev_ethtool.py +1 -2
index ee1a397bd2..ca4d374de7 100755
@@ -8,8 +8,7 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from unittest import skip
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 
 class NetDevEthtool(QemuSystemTest):
 
tests/functional/test_ppc64_hv.py +2 -2
index 312248bbfe..c31432d18d 100755
@@ -10,8 +10,8 @@
 # later.  See the COPYING file in the top-level directory.
 
 from unittest import skipIf, skipUnless
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern, exec_command
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       exec_command)
 import os
 import time
 import subprocess
tests/functional/test_ppc64_powernv.py +1 -2
index 685e2178ed..4d570a9867 100755
@@ -7,8 +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 qemu_test import LinuxKernelTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import LinuxKernelTest, Asset, wait_for_console_pattern
 
 class powernvMachine(LinuxKernelTest):
 
tests/functional/test_ppc64_pseries.py +1 -2
index fdc404ed03..faca7f46f2 100755
@@ -7,8 +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 qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 
 class pseriesMachine(QemuSystemTest):
 
tests/functional/test_ppc_405.py +3 -3
index 9851c03ee9..04df038af7 100755
@@ -7,9 +7,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 qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
-from qemu_test import exec_command_and_wait_for_pattern
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       exec_command_and_wait_for_pattern)
+
 
 class Ppc405Machine(QemuSystemTest):
 
tests/functional/test_ppc_40p.py +1 -2
index 67bcdae53a..496282b164 100755
@@ -10,8 +10,7 @@
 import os
 
 from unittest import skipUnless
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 
 
 class IbmPrep40pMachine(QemuSystemTest):
tests/functional/test_ppc_74xx.py +1 -2
index 5386016f26..1c3e6b2c94 100755
@@ -7,8 +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 qemu_test import QemuSystemTest
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, wait_for_console_pattern
 
 class ppc74xxCpu(QemuSystemTest):
 
tests/functional/test_ppc_amiga.py +1 -2
index b793b5c432..e92489fdb2 100755
@@ -9,8 +9,7 @@
 
 import subprocess
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern, run_cmd
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern, run_cmd
 from zipfile import ZipFile
 
 class AmigaOneMachine(QemuSystemTest):
tests/functional/test_ppc_bamboo.py +3 -3
index e72cbdee12..71b30781f1 100755
@@ -8,9 +8,9 @@
 # later.  See the COPYING file in the top-level directory.
 
 from qemu_test.utils import archive_extract
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
-from qemu_test import exec_command_and_wait_for_pattern
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       exec_command_and_wait_for_pattern)
+
 
 class BambooMachine(QemuSystemTest):
 
tests/functional/test_ppc_mpc8544ds.py +1 -2
index 2b3f0894ae..746efda1ae 100755
@@ -8,8 +8,7 @@
 # later.  See the COPYING file in the top-level directory.
 
 from qemu_test.utils import archive_extract
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 
 class Mpc8544dsMachine(QemuSystemTest):
 
tests/functional/test_ppc_virtex_ml507.py +1 -2
index ffa9a0633e..3c49d41341 100755
@@ -8,8 +8,7 @@
 # later.  See the COPYING file in the top-level directory.
 
 from qemu_test.utils import archive_extract
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 
 class VirtexMl507Machine(QemuSystemTest):
 
tests/functional/test_riscv_opensbi.py +2 -2
index d077e40f42..bccc2b2fe1 100755
@@ -7,8 +7,8 @@
 # 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 qemu_test import QemuSystemTest
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, wait_for_console_pattern
+
 
 class RiscvOpenSBI(QemuSystemTest):
 
tests/functional/test_rx_gdbsim.py +3 -3
index 5687f756bb..6306863519 100755
@@ -13,9 +13,9 @@
 import os
 
 from unittest import skipUnless
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import exec_command_and_wait_for_pattern
-from qemu_test import wait_for_console_pattern
+from qemu_test import (QemuSystemTest, Asset,
+                       exec_command_and_wait_for_pattern,
+                       wait_for_console_pattern)
 from qemu_test.utils import gzip_uncompress
 
 
tests/functional/test_s390x_ccw_virtio.py +3 -3
index f7acd90a89..c9d4730856 100755
@@ -14,9 +14,9 @@
 import os
 import tempfile
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import exec_command_and_wait_for_pattern
-from qemu_test import wait_for_console_pattern
+from qemu_test import (QemuSystemTest, Asset,
+                       exec_command_and_wait_for_pattern,
+                       wait_for_console_pattern)
 from qemu_test.utils import lzma_uncompress
 
 class S390CCWVirtioMachine(QemuSystemTest):
tests/functional/test_s390x_topology.py +3 -4
index c54c7a8177..6bf64f09fe 100755
@@ -12,10 +12,9 @@
 
 import os
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import exec_command
-from qemu_test import exec_command_and_wait_for_pattern
-from qemu_test import wait_for_console_pattern
+from qemu_test import (QemuSystemTest, Asset, exec_command,
+                       exec_command_and_wait_for_pattern,
+                       wait_for_console_pattern)
 from qemu_test.utils import lzma_uncompress
 
 
tests/functional/test_sh4eb_r2d.py +2 -2
index cd46007942..66daf8add4 100755
@@ -7,8 +7,8 @@
 import os
 import shutil
 
-from qemu_test import LinuxKernelTest, Asset
-from qemu_test import exec_command_and_wait_for_pattern
+from qemu_test import (LinuxKernelTest, Asset,
+                       exec_command_and_wait_for_pattern)
 from qemu_test.utils import archive_extract
 
 class R2dEBTest(LinuxKernelTest):
tests/functional/test_sparc64_sun4u.py +1 -2
index 32e245f4ad..798d6c3fb5 100755
@@ -12,8 +12,7 @@
 
 import os
 
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
+from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 from qemu_test.utils import archive_extract
 
 class Sun4uMachine(QemuSystemTest):
tests/functional/test_virtio_gpu.py +4 -6
index d5027487ac..bc3b00e497 100755
@@ -6,12 +6,10 @@
 # later.  See the COPYING file in the top-level directory.
 
 
-from qemu_test import BUILD_DIR
-from qemu_test import QemuSystemTest, Asset
-from qemu_test import wait_for_console_pattern
-from qemu_test import exec_command_and_wait_for_pattern
-from qemu_test import is_readable_executable_file
-
+from qemu_test import (BUILD_DIR, QemuSystemTest, Asset,
+                       wait_for_console_pattern,
+                       exec_command_and_wait_for_pattern,
+                       is_readable_executable_file)
 from qemu.utils import kvm_available
 
 import os
Signature · 1 line
2.46.0
#20 lore raw

PATCH 7/22 tests/functional: switch to new test skip decorators

In reply to Daniel P. Berrangé

This ensures consistency of behaviour across all the tests, and requires that we provide gitlab bug links when marking a test to be skipped due to unreliability.

---
 tests/functional/test_acpi_bits.py           | 24 +++-------------
 tests/functional/test_arm_aspeed.py          |  6 ++--
 tests/functional/test_arm_bflt.py            |  7 +++--
 tests/functional/test_arm_bpim2u.py          |  7 +++--
 tests/functional/test_arm_integratorcp.py    | 27 ++++++------------
 tests/functional/test_arm_orangepi.py        |  8 +++---
 tests/functional/test_linux_initrd.py        |  7 ++---
 tests/functional/test_m68k_nextcube.py       | 14 +++------
 tests/functional/test_mips64el_loongson3v.py |  8 +++---
 tests/functional/test_mips64el_malta.py      | 30 +++++++-------------
 tests/functional/test_ppc64_hv.py            | 17 ++---------
 tests/functional/test_ppc_40p.py             |  8 ++----
 tests/functional/test_rx_gdbsim.py           |  6 ++--
 tests/functional/test_sh4_r2d.py             |  8 ++----
 14 files changed, 62 insertions(+), 115 deletions(-)
tests/functional/test_acpi_bits.py +4 -20
index 4162faf414..4de5fae37e 100755
@@ -48,28 +48,13 @@
     Sequence,
 )
 from qemu.machine import QEMUMachine
-from unittest import skipIf
-from qemu_test import QemuBaseTest, Asset, which
+from qemu_test import (QemuBaseTest, Asset, skipIfMissingCommands,
+                       skipIfNotMachine)
 
-deps = ["xorriso", "mformat"] # dependent tools needed in the test setup/box.
-supported_platforms = ['x86_64'] # supported test platforms.
 
 # default timeout of 120 secs is sometimes not enough for bits test.
 BITS_TIMEOUT = 200
 
-def missing_deps():
-    """ returns True if any of the test dependent tools are absent.
-    """
-    for dep in deps:
-        if which(dep) is None:
-            return True
-    return False
-
-def supported_platform():
-    """ checks if the test is running on a supported platform.
-    """
-    return platform.machine() in supported_platforms
-
 class QEMUBitsMachine(QEMUMachine): # pylint: disable=too-few-public-methods
     """
     A QEMU VM, with isa-debugcon enabled and bits iso passed
@@ -112,9 +97,8 @@ def base_args(self):
         """return the base argument to QEMU binary"""
         return self._base_args
 
-@skipIf(not supported_platform() or missing_deps(),
-        'unsupported platform or dependencies (%s) not installed' \
-        % ','.join(deps))
+@skipIfMissingCommands("xorriso", "mformat")
+@skipIfNotMachine("x86_64")
 class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
     """
     ACPI and SMBIOS tests using biosbits.
tests/functional/test_arm_aspeed.py +4 -2
index 068740a813..db872ff05e 100755
@@ -13,7 +13,9 @@
 
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern,
-                       interrupt_interactive_console_until_pattern, has_cmd)
+                       interrupt_interactive_console_until_pattern,
+                       skipIfMissingCommands,
+)
 from qemu_test.utils import archive_extract
 from zipfile import ZipFile
 from unittest import skipUnless
@@ -218,7 +220,7 @@ def test_arm_ast2600_evb_buildroot(self):
          'images/ast2600-evb/buildroot-2023.02-tpm/flash.img'),
         'a46009ae8a5403a0826d607215e731a8c68d27c14c41e55331706b8f9c7bd997')
 
-    @skipUnless(*has_cmd('swtpm'))
+    @skipIfMissingCommands('swtpm')
     def test_arm_ast2600_evb_buildroot_tpm(self):
         self.set_machine('ast2600-evb')
 
tests/functional/test_arm_bflt.py +4 -3
index cd417ebcfc..74d04fd381 100755
@@ -10,8 +10,9 @@
 import bz2
 
 from qemu_test import QemuUserTest, Asset, has_cmd
+from qemu_test import (QemuUserTest, Asset, skipIfMissingCommands,
+                       skipUntrustedTest)
 from qemu_test.utils import cpio_extract
-from unittest import skipUnless
 
 
 class LoadBFLT(QemuUserTest):
@@ -20,8 +21,8 @@ class LoadBFLT(QemuUserTest):
         ('https://elinux.org/images/5/51/Stm32_mini_rootfs.cpio.bz2'),
          'eefb788e4980c9e8d6c9d60ce7d15d4da6bf4fbc6a80f487673824600d5ba9cc')
 
-    @skipUnless(*has_cmd('cpio'))
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    @skipIfMissingCommands('cpio')
+    @skipUntrustedTest()
     def test_stm32(self):
         # See https://elinux.org/STM32#User_Space
         rootfs_path_bz2 = self.ASSET_ROOTFS.fetch()
tests/functional/test_arm_bpim2u.py +4 -3
index 7b1b0a270f..d2108fd4ea 100755
@@ -8,10 +8,11 @@
 import os
 
 from qemu_test import (LinuxKernelTest, exec_command_and_wait_for_pattern,
-                       Asset, interrupt_interactive_console_until_pattern)
+                       Asset, interrupt_interactive_console_until_pattern,
+                       skipBigDataTest)
 from qemu_test.utils import (archive_extract, gzip_uncompress, lzma_uncompress,
                              image_pow2ceil_expand)
-from unittest import skipUnless
+
 
 class BananaPiMachine(LinuxKernelTest):
 
@@ -143,7 +144,7 @@ def test_arm_bpim2u_gmac(self):
         os.remove(dtb_path)
         os.remove(rootfs_path)
 
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_LARGE_STORAGE'), 'storage limited')
+    @skipBigDataTest()
     def test_arm_bpim2u_openwrt_22_03_3(self):
         self.set_machine('bpim2u')
         # This test download a 8.9 MiB compressed image and expand it
tests/functional/test_arm_integratorcp.py +8 -19
index c2c6ff6ac5..a13e82bd31 100755
@@ -15,21 +15,8 @@
 import os
 import logging
 
-from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
-from unittest import skipUnless
-
-
-NUMPY_AVAILABLE = True
-try:
-    import numpy as np
-except ImportError:
-    NUMPY_AVAILABLE = False
-
-CV2_AVAILABLE = True
-try:
-    import cv2
-except ImportError:
-    CV2_AVAILABLE = False
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       skipIfMissingImports, skipUntrustedTest)
 
 
 class IntegratorMachine(QemuSystemTest):
@@ -62,7 +49,7 @@ def boot_integratorcp(self):
                          '-append', 'printk.time=0 console=ttyAMA0')
         self.vm.launch()
 
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    @skipUntrustedTest()
     def test_integratorcp_console(self):
         """
         Boots the Linux kernel and checks that the console is operational
@@ -70,13 +57,15 @@ def test_integratorcp_console(self):
         self.boot_integratorcp()
         wait_for_console_pattern(self, 'Log in as root')
 
-    @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
-    @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    @skipIfMissingImports("numpy", "cv2")
+    @skipUntrustedTest()
     def test_framebuffer_tux_logo(self):
         """
         Boot Linux and verify the Tux logo is displayed on the framebuffer.
         """
+        import numpy as np
+        import cv2
+
         screendump_path = os.path.join(self.workdir, "screendump.pbm")
         tuxlogo_path = self.ASSET_TUXLOGO.fetch()
 
tests/functional/test_arm_orangepi.py +4 -4
index 676327e8ef..7974010320 100755
@@ -10,10 +10,10 @@
 
 from qemu_test import (LinuxKernelTest, exec_command_and_wait_for_pattern,
                        Asset, interrupt_interactive_console_until_pattern,
-                       wait_for_console_pattern)
+                       wait_for_console_pattern, skipBigDataTest)
 from qemu_test.utils import (archive_extract, gzip_uncompress, lzma_uncompress,
                              image_pow2ceil_expand)
-from unittest import skipUnless
+
 
 class BananaPiMachine(LinuxKernelTest):
 
@@ -149,7 +149,7 @@ def test_arm_orangepi_sd(self):
         os.remove(dtb_path)
         os.remove(rootfs_path)
 
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_LARGE_STORAGE'), 'storage limited')
+    @skipBigDataTest()
     def test_arm_orangepi_armbian(self):
         self.set_machine('orangepi-pc')
         # This test download a 275 MiB compressed image and expand it
@@ -185,7 +185,7 @@ def test_arm_orangepi_armbian(self):
                                       'to <orangepipc>')
         self.wait_for_console_pattern('Starting Load Kernel Modules...')
 
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_LARGE_STORAGE'), 'storage limited')
+    @skipBigDataTest()
     def test_arm_orangepi_uboot_netbsd9(self):
         self.set_machine('orangepi-pc')
         # This test download a 304MB compressed image and expand it to 2GB
tests/functional/test_linux_initrd.py +3 -4
index c71a59d4c9..2207f83fbf 100755
@@ -10,12 +10,10 @@
 # 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 os
 import logging
 import tempfile
 
-from qemu_test import QemuSystemTest, Asset
-from unittest import skipUnless
+from qemu_test import QemuSystemTest, Asset, skipFlakyTest
 
 
 class LinuxInitrd(QemuSystemTest):
@@ -60,7 +58,8 @@ def test_with_2gib_file_should_exit_error_msg_with_linux_v3_6(self):
                 max_size + 1)
             self.assertRegex(self.vm.get_log(), expected_msg)
 
-    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
+    # XXX file tracking bug
+    @skipFlakyTest(bug_url=None)
     def test_with_2gib_file_should_work_with_linux_v4_16(self):
         """
         QEMU has supported up to 4 GiB initrd for recent kernel
tests/functional/test_m68k_nextcube.py +4 -10
index 0124622c40..82d3d335d0 100755
@@ -10,16 +10,9 @@
 import os
 import time
 
-from qemu_test import QemuSystemTest, Asset
-from unittest import skipUnless
-
+from qemu_test import QemuSystemTest, Asset, skipIfMissingImports
 from qemu_test.tesseract import tesseract_available, tesseract_ocr
-
-PIL_AVAILABLE = True
-try:
-    from PIL import Image
-except ImportError:
-    PIL_AVAILABLE = False
+from unittest import skipUnless
 
 
 class NextCubeMachine(QemuSystemTest):
@@ -43,12 +36,13 @@ def check_bootrom_framebuffer(self, screenshot_path):
         self.vm.cmd('human-monitor-command',
                     command_line='screendump %s' % screenshot_path)
 
-    @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
+    @skipIfMissingImports("PIL")
     def test_bootrom_framebuffer_size(self):
         self.set_machine('next-cube')
         screenshot_path = os.path.join(self.workdir, "dump.ppm")
         self.check_bootrom_framebuffer(screenshot_path)
 
+        from PIL import Image
         width, height = Image.open(screenshot_path).size
         self.assertEqual(width, 1120)
         self.assertEqual(height, 832)
tests/functional/test_mips64el_loongson3v.py +4 -4
index 06032a3a6b..2d1a94e517 100755
@@ -9,10 +9,10 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
 from unittest import skipUnless
-from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       skipUntrustedTest)
+
 
 class MipsLoongson3v(QemuSystemTest):
     timeout = 60
@@ -22,7 +22,7 @@ class MipsLoongson3v(QemuSystemTest):
          'releases/download/20210112/pmon-3avirt.bin'),
         'fcdf6bb2cb7885a4a62f31fcb0d5e368bac7b6cea28f40c6dfa678af22fea20a')
 
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    @skipUntrustedTest()
     def test_pmon_serial_console(self):
         self.set_machine('loongson3-virt')
 
tests/functional/test_mips64el_malta.py +11 -19
index b5959d33ea..ccb9616f68 100755
@@ -13,21 +13,9 @@
 import logging
 
 from qemu_test import (LinuxKernelTest, Asset,
-                       exec_command_and_wait_for_pattern)
+                       exec_command_and_wait_for_pattern,
+                       skipIfMissingImports, skipFlakyTest, skipUntrustedTest)
 from qemu_test.utils import gzip_uncompress
-from unittest import skipUnless
-
-NUMPY_AVAILABLE = True
-try:
-    import numpy as np
-except ImportError:
-    NUMPY_AVAILABLE = False
-
-CV2_AVAILABLE = True
-try:
-    import cv2
-except ImportError:
-    CV2_AVAILABLE = False
 
 
 class MaltaMachineConsole(LinuxKernelTest):
@@ -76,7 +64,7 @@ def test_mips64el_malta(self):
          'rootfs.mipsel64r1.cpio.gz'),
         '75ba10cd35fb44e32948eeb26974f061b703c81c4ba2fab1ebcacf1d1bec3b61')
 
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    @skipUntrustedTest()
     def test_mips64el_malta_5KEc_cpio(self):
         kernel_path = self.ASSET_KERNEL_3_19_3.fetch()
         initrd_path_gz = self.ASSET_CPIO_R1.fetch()
@@ -106,8 +94,7 @@ def test_mips64el_malta_5KEc_cpio(self):
         self.vm.wait()
 
 
-@skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
-@skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
+@skipIfMissingImports('numpy', 'cv2')
 class MaltaMachineFramebuffer(LinuxKernelTest):
 
     timeout = 30
@@ -126,6 +113,10 @@ def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
         """
         Boot Linux kernel and check Tux logo is displayed on the framebuffer.
         """
+
+        import numpy as np
+        import cv2
+
         screendump_path = os.path.join(self.workdir, 'screendump.pbm')
 
         kernel_path_gz = self.ASSET_KERNEL_4_7_0.fetch()
@@ -171,11 +162,12 @@ def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
     def test_mips_malta_i6400_framebuffer_logo_1core(self):
         self.do_test_i6400_framebuffer_logo(1)
 
-    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
+    # XXX file tracking bug
+    @skipFlakyTest(bug_url=None)
     def test_mips_malta_i6400_framebuffer_logo_7cores(self):
         self.do_test_i6400_framebuffer_logo(7)
 
-    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
+    @skipFlakyTest(bug_url=None)
     def test_mips_malta_i6400_framebuffer_logo_8cores(self):
         self.do_test_i6400_framebuffer_logo(8)
 
tests/functional/test_ppc64_hv.py +3 -14
index cc77cd22b1..9ad69b4a15 100755
@@ -9,24 +9,13 @@
 # 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 unittest import skipIf, skipUnless
 from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
-                       exec_command, which)
+                       exec_command, skipIfMissingCommands, skipBigDataTest)
 import os
 import time
 import subprocess
 from datetime import datetime
 
-deps = ["xorriso"] # dependent tools needed in the test setup/box.
-
-def missing_deps():
-    """ returns True if any of the test dependent tools are absent.
-    """
-    for dep in deps:
-        if which(dep) is None:
-            return True
-    return False
-
 # Alpine is a light weight distro that supports QEMU. These tests boot
 # that on the machine then run a QEMU guest inside it in KVM mode,
 # that runs the same Alpine distro image.
@@ -34,8 +23,8 @@ def missing_deps():
 # large download, but it may be more polite to create qcow2 image with
 # QEMU already installed and use that.
 # XXX: The order of these tests seems to matter, see git blame.
-@skipIf(missing_deps(), 'dependencies (%s) not installed' % ','.join(deps))
-@skipUnless(os.getenv('QEMU_TEST_ALLOW_LARGE_STORAGE'), 'storage limited')
+@skipIfMissingCommands("xorriso")
+@skipBigDataTest()
 class HypervisorTest(QemuSystemTest):
 
     timeout = 1000
tests/functional/test_ppc_40p.py +3 -5
index 496282b164..885b8e4ba2 100755
@@ -7,10 +7,8 @@
 # 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 os
-
-from unittest import skipUnless
-from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
+                       skipUntrustedTest)
 
 
 class IbmPrep40pMachine(QemuSystemTest):
@@ -36,7 +34,7 @@ class IbmPrep40pMachine(QemuSystemTest):
     # All rights reserved.
     # U.S. Government Users Restricted Rights - Use, duplication or disclosure
     # restricted by GSA ADP Schedule Contract with IBM Corp.
-    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
+    @skipUntrustedTest()
     def test_factory_firmware_and_netbsd(self):
         self.set_machine('40p')
         self.require_accelerator("tcg")
tests/functional/test_rx_gdbsim.py +3 -3
index 6306863519..7461be0b46 100755
@@ -12,10 +12,9 @@
 
 import os
 
-from unittest import skipUnless
 from qemu_test import (QemuSystemTest, Asset,
                        exec_command_and_wait_for_pattern,
-                       wait_for_console_pattern)
+                       wait_for_console_pattern, skipFlakyTest)
 from qemu_test.utils import gzip_uncompress
 
 
@@ -54,7 +53,8 @@ def test_uboot(self):
         # FIXME limit baudrate on chardev, else we type too fast
         #exec_command_and_wait_for_pattern(self, 'version', gcc_version)
 
-    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
+    # XXX file tracking bug
+    @skipFlakyTest(bug_url=None)
     def test_linux_sash(self):
         """
         Boots a Linux kernel and checks that the console is operational.
tests/functional/test_sh4_r2d.py +3 -5
index c3cfff79ad..e2fcde2d6b 100755
@@ -4,11 +4,8 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
-from qemu_test import LinuxKernelTest, Asset
+from qemu_test import LinuxKernelTest, Asset, skipFlakyTest
 from qemu_test.utils import archive_extract
-from unittest import skipUnless
 
 class R2dTest(LinuxKernelTest):
 
@@ -18,7 +15,8 @@ class R2dTest(LinuxKernelTest):
 
     # This test has a 6-10% failure rate on various hosts that look
     # like issues with a buggy kernel.
-    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable')
+    # XXX file tracking bug
+    @skipFlakyTest(bug_url=None)
     def test_r2d(self):
         self.set_machine('r2d')
         file_path = self.ASSET_DAY09.fetch()
Signature · 1 line
2.46.0
#31 lore raw

PATCH 11/22 tests/functional: switch over to using self.data_file(...)

In reply to Daniel P. Berrangé

This removes direct path manipulation to figure out the source dir

---
 tests/functional/test_acpi_bits.py | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
tests/functional/test_acpi_bits.py +7 -15
index 4de5fae37e..948b134b16 100755
@@ -41,7 +41,6 @@
 import tempfile
 import zipfile
 
-from pathlib import Path
 from typing import (
     List,
     Optional,
@@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
         self._vm = None
-        self._baseDir = None
 
         self._debugcon_addr = '0x403'
         self._debugcon_log = 'debugcon-log.txt'
@@ -137,26 +135,22 @@ def _print_log(self, log):
     def copy_bits_config(self):
         """ copies the bios bits config file into bits.
         """
-        config_file = 'bits-cfg.txt'
-        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                       'bits-config')
+        bits_config_file = self.data_file('acpi-bits',
+                                          'bits-config',
+                                          'bits-cfg.txt')
         target_config_dir = os.path.join(self.workdir,
                                          'bits-%d' %self.BITS_INTERNAL_VER,
                                          'boot')
-        self.assertTrue(os.path.exists(bits_config_dir))
+        self.assertTrue(os.path.exists(bits_config_file))
         self.assertTrue(os.path.exists(target_config_dir))
-        self.assertTrue(os.access(os.path.join(bits_config_dir,
-                                               config_file), os.R_OK))
-        shutil.copy2(os.path.join(bits_config_dir, config_file),
-                     target_config_dir)
+        shutil.copy2(bits_config_file, target_config_dir)
         self.logger.info('copied config file %s to %s',
-                         config_file, target_config_dir)
+                         bits_config_file, target_config_dir)
 
     def copy_test_scripts(self):
         """copies the python test scripts into bits. """
 
-        bits_test_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                     'bits-tests')
+        bits_test_dir = self.data_file('acpi-bits', 'bits-tests')
         target_test_dir = os.path.join(self.workdir,
                                        'bits-%d' %self.BITS_INTERNAL_VER,
                                        'boot', 'python')
@@ -259,8 +253,6 @@ def setUp(self): # pylint: disable=arguments-differ
         super().setUp('qemu-system-')
         self.logger = self.log
 
-        self._baseDir = Path(__file__).parent
-
         prebuiltDir = os.path.join(self.workdir, 'prebuilt')
         if not os.path.isdir(prebuiltDir):
             os.mkdir(prebuiltDir, mode=0o775)
Signature · 1 line
2.46.0
#28 lore raw

PATCH 10/22 tests/functional: switch over to using self.build_file(...)

In reply to Daniel P. Berrangé

This removes direct access of the 'BUILD_DIR' variable.

---
 tests/functional/qemu_test/testcase.py | 4 ++--
 tests/functional/test_aarch64_virt.py  | 6 +++---
 tests/functional/test_virtio_gpu.py    | 9 ++++-----
 3 files changed, 9 insertions(+), 10 deletions(-)
tests/functional/qemu_test/testcase.py +2 -2
index 5b1e6ba04f..2f32742387 100644
@@ -127,8 +127,8 @@ def setUp(self, bin_prefix):
         self.arch = self.qemu_bin.split('-')[-1]
         self.socketdir = None
 
-        self.outputdir = os.path.join(BUILD_DIR, 'tests', 'functional',
-                                      self.arch, self.id())
+        self.outputdir = self.build_file('tests', 'functional',
+                                         self.arch, self.id())
         self.workdir = os.path.join(self.outputdir, 'scratch')
         os.makedirs(self.workdir, exist_ok=True)
 
tests/functional/test_aarch64_virt.py +3 -3
index 07b78f6a84..29eeb8e32d 100755
@@ -14,7 +14,7 @@
 import os
 import logging
 
-from qemu_test import (BUILD_DIR, QemuSystemTest, Asset, exec_command,
+from qemu_test import (QemuSystemTest, Asset, exec_command,
                        wait_for_console_pattern, get_qemu_img, run_cmd)
 
 
@@ -52,8 +52,8 @@ def test_alpine_virt_tcg_gic_max(self):
                          "mte=on,"
                          "gic-version=max,iommu=smmuv3")
         self.vm.add_args("-smp", "2", "-m", "1024")
-        self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios',
-                                               'edk2-aarch64-code.fd'))
+        self.vm.add_args('-bios', self.build_file('pc-bios',
+                                                  'edk2-aarch64-code.fd'))
         self.vm.add_args("-drive", f"file={iso_path},media=cdrom,format=raw")
         self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0')
         self.vm.add_args('-object', 'rng-random,id=rng0,filename=/dev/urandom')
tests/functional/test_virtio_gpu.py +4 -5
index c4562618d9..39dcf376dd 100755
@@ -6,8 +6,7 @@
 # later.  See the COPYING file in the top-level directory.
 
 
-from qemu_test import (BUILD_DIR, QemuSystemTest, Asset,
-                       wait_for_console_pattern,
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
                        exec_command_and_wait_for_pattern,
                        is_readable_executable_file)
 from qemu.utils import kvm_available
@@ -17,12 +16,12 @@
 import subprocess
 
 
-def pick_default_vug_bin():
+def pick_default_vug_bin(test):
     relative_path = "./contrib/vhost-user-gpu/vhost-user-gpu"
     if is_readable_executable_file(relative_path):
         return relative_path
 
-    bld_dir_path = os.path.join(BUILD_DIR, relative_path)
+    bld_dir_path = test.build_file(relative_path)
     if is_readable_executable_file(bld_dir_path):
         return bld_dir_path
 
@@ -85,7 +84,7 @@ def test_vhost_user_vga_virgl(self):
         # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
         self.require_accelerator('kvm')
 
-        vug = pick_default_vug_bin()
+        vug = pick_default_vug_bin(self)
         if not vug:
             self.skipTest("Could not find vhost-user-gpu")
 
Signature · 1 line
2.46.0
#42 lore raw

PATCH 14/22 tests/functional: remove redundant 'rmtree' call

In reply to Daniel P. Berrangé

Everything in the scratch directory is automatically purged. Calling 'rmtree' again breaks the ability to optionally preserve the scratch directory contents.

---
 tests/functional/test_sh4eb_r2d.py | 3 ---
 1 file changed, 3 deletions(-)
tests/functional/test_sh4eb_r2d.py +0 -3
index dd2500dc33..38ee55cf4c 100755
@@ -4,8 +4,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import shutil
-
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern)
 from qemu_test.utils import archive_extract
@@ -25,7 +23,6 @@ def test_sh4eb_r2d(self):
                            initrd=self.scratch_file('sh4eb', 'initramfs.cpio.gz'),
                            console_index=1, wait_for='Type exit when done')
         exec_command_and_wait_for_pattern(self, 'exit', 'Restarting system')
-        shutil.rmtree(self.scratch_file('sh4eb'))
 
 if __name__ == '__main__':
     LinuxKernelTest.main()
Signature · 1 line
2.46.0
#26 lore raw

PATCH 9/22 tests/functional: switch over to using self.log_file(...)

In reply to Daniel P. Berrangé

This removes direct access of the 'self.logdir' variable.

---
 tests/functional/qemu_test/testcase.py | 9 ++++-----
 tests/functional/test_virtio_gpu.py    | 4 +---
 2 files changed, 5 insertions(+), 8 deletions(-)
tests/functional/qemu_test/testcase.py +4 -5
index fb62052817..5b1e6ba04f 100644
@@ -120,7 +120,7 @@ def scratch_file(self, *args):
     Returns: a pathlib.Path object
     '''
     def log_file(self, *args):
-        return str(Path(self.logdir, *args))
+        return str(Path(self.outputdir, *args))
 
     def setUp(self, bin_prefix):
         self.assertIsNotNone(self.qemu_bin, 'QEMU_TEST_QEMU_BINARY must be set')
@@ -132,8 +132,7 @@ def setUp(self, bin_prefix):
         self.workdir = os.path.join(self.outputdir, 'scratch')
         os.makedirs(self.workdir, exist_ok=True)
 
-        self.logdir = self.outputdir
-        self.log_filename = os.path.join(self.logdir, 'base.log')
+        self.log_filename = self.log_file('base.log')
         self.log = logging.getLogger('qemu-test')
         self.log.setLevel(logging.DEBUG)
         self._log_fh = logging.FileHandler(self.log_filename, mode='w')
@@ -206,7 +205,7 @@ def setUp(self):
 
         console_log = logging.getLogger('console')
         console_log.setLevel(logging.DEBUG)
-        self.console_log_name = os.path.join(self.logdir, 'console.log')
+        self.console_log_name = self.log_file('console.log')
         self._console_log_fh = logging.FileHandler(self.console_log_name,
                                                    mode='w')
         self._console_log_fh.setLevel(logging.DEBUG)
@@ -260,7 +259,7 @@ def _new_vm(self, name, *args):
         vm = QEMUMachine(self.qemu_bin,
                          name=name,
                          base_temp_dir=self.workdir,
-                         log_dir=self.logdir)
+                         log_dir=self.log_file())
         self.log.debug('QEMUMachine "%s" created', name)
         self.log.debug('QEMUMachine "%s" temp_dir: %s', name, vm.temp_dir)
 
tests/functional/test_virtio_gpu.py +1 -3
index bc3b00e497..c4562618d9 100755
@@ -99,9 +99,7 @@ def test_vhost_user_vga_virgl(self):
         os.set_inheritable(qemu_sock.fileno(), True)
         os.set_inheritable(vug_sock.fileno(), True)
 
-        self._vug_log_path = os.path.join(
-            self.logdir, "vhost-user-gpu.log"
-        )
+        self._vug_log_path = self.log_file("vhost-user-gpu.log")
         self._vug_log_file = open(self._vug_log_path, "wb")
         self.log.info('Complete vhost-user-gpu.log file can be '
                       'found at %s', self._vug_log_path)
Signature · 1 line
2.46.0
#1 lore raw

PATCH 1/22 tests/functional: increase timeouts for arm sx1 test

In reply to Daniel P. Berrangé

When under high load the test VM does not complete running in the default 30 second timeout. Double it to give more headroom.

---
 tests/functional/test_arm_sx1.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/functional/test_arm_sx1.py +3 -3
index 2d86405831..2292317946 100755
@@ -44,7 +44,7 @@ def test_arm_sx1_initrd(self):
         self.vm.add_args('-no-reboot')
         self.launch_kernel(zimage_path,
                            initrd=initrd_path)
-        self.vm.wait()
+        self.vm.wait(timeout=60)
 
     def test_arm_sx1_sd(self):
         self.set_machine('sx1')
@@ -55,7 +55,7 @@ def test_arm_sx1_sd(self):
         self.vm.add_args('-snapshot')
         self.vm.add_args('-drive', f'format=raw,if=sd,file={sd_fs_path}')
         self.launch_kernel(zimage_path)
-        self.vm.wait()
+        self.vm.wait(timeout=60)
 
     def test_arm_sx1_flash(self):
         self.set_machine('sx1')
@@ -66,7 +66,7 @@ def test_arm_sx1_flash(self):
         self.vm.add_args('-snapshot')
         self.vm.add_args('-drive', f'format=raw,if=pflash,file={flash_path}')
         self.launch_kernel(zimage_path)
-        self.vm.wait()
+        self.vm.wait(timeout=60)
 
 if __name__ == '__main__':
     LinuxKernelTest.main()
Signature · 1 line
2.46.0
#59 lore raw

PATCH 19/22 tests/functional: convert tests to new archive_extract helper

In reply to Daniel P. Berrangé

Replace use of utils.archive_extract and extract_from_deb with the new archive_extract helper.

---
 tests/functional/qemu_test/linuxkernel.py     | 19 +-------------
 tests/functional/test_aarch64_aspeed.py       |  4 +--
 tests/functional/test_aarch64_raspi3.py       |  8 +-----
 tests/functional/test_aarch64_raspi4.py       | 14 +++++-----
 tests/functional/test_acpi_bits.py            | 15 +++--------
 tests/functional/test_arm_aspeed.py           | 26 +++++--------------
 tests/functional/test_arm_bflt.py             |  3 +--
 tests/functional/test_arm_bpim2u.py           | 22 +++++++---------
 tests/functional/test_arm_canona1100.py       | 10 +++----
 tests/functional/test_arm_collie.py           |  1 -
 tests/functional/test_arm_orangepi.py         | 26 ++++++++-----------
 tests/functional/test_arm_raspi2.py           | 14 +++++-----
 tests/functional/test_arm_sx1.py              |  1 -
 tests/functional/test_arm_vexpress.py         |  4 +--
 tests/functional/test_m68k_mcf5208evb.py      |  4 +--
 tests/functional/test_m68k_q800.py            |  5 ++--
 .../functional/test_microblaze_s3adsp1800.py  |  4 +--
 .../test_microblazeel_s3adsp1800.py           |  4 +--
 tests/functional/test_mips64el_fuloong2e.py   |  6 ++---
 tests/functional/test_mips64el_malta.py       |  6 ++---
 tests/functional/test_mips_malta.py           | 12 ++++-----
 tests/functional/test_mipsel_malta.py         |  5 +---
 tests/functional/test_or1k_sim.py             |  4 +--
 tests/functional/test_ppc64_e500.py           |  4 +--
 tests/functional/test_ppc_amiga.py            |  5 +---
 tests/functional/test_ppc_bamboo.py           |  4 +--
 tests/functional/test_ppc_mac.py              |  5 +---
 tests/functional/test_ppc_mpc8544ds.py        |  7 +++--
 tests/functional/test_ppc_virtex_ml507.py     |  4 +--
 tests/functional/test_sh4_r2d.py              |  5 ++--
 tests/functional/test_sh4eb_r2d.py            |  5 ++--
 tests/functional/test_sparc64_sun4u.py        |  8 +++---
 tests/functional/test_sparc_sun4m.py          |  4 +--
 tests/functional/test_xtensa_lx60.py          |  4 +--
 34 files changed, 90 insertions(+), 182 deletions(-)
tests/functional/qemu_test/linuxkernel.py +1 -18
index fb6a158d36..6a1bfdabba 100644
@@ -7,7 +7,7 @@
 
 from .testcase import QemuSystemTest
 from .cmd import wait_for_console_pattern
-from .utils import deb_extract
+
 
 class LinuxKernelTest(QemuSystemTest):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -28,20 +28,3 @@ def launch_kernel(self, kernel, initrd=None, dtb=None, console_index=0,
         self.vm.launch()
         if wait_for:
                 self.wait_for_console_pattern(wait_for)
-
-    def extract_from_deb(self, deb_path, path):
-        """
-        Extracts a file from a deb package into the test workdir
-
-        :param deb_path: path to the deb archive
-        :param path: path within the deb archive of the file to be extracted
-        :returns: path of the extracted file
-        """
-        relpath = os.path.relpath(path, '/')
-        deb_extract(deb_path, self.workdir, member="." + path)
-        # Return complete path to extracted file.  Because callers to
-        # extract_from_deb() specify 'path' with a leading slash, it is
-        # necessary to use 'relative_to()' to turn it into a relative
-        # path for joining to the scratch dir
-        return os.path.normpath(self.scratch_file(relpath))
-
tests/functional/test_aarch64_aspeed.py +1 -3
index c6c6b74acc..3c2f9bc978 100644
@@ -12,7 +12,6 @@
 from qemu_test import QemuSystemTest, Asset
 from qemu_test import wait_for_console_pattern
 from qemu_test import exec_command_and_wait_for_pattern
-from qemu_test.utils import archive_extract
 
 class AST2x00MachineSDK(QemuSystemTest):
 
@@ -35,8 +34,7 @@ def do_test_aarch64_aspeed_sdk_start(self, image):
     def test_aarch64_ast2700_evb_sdk_v09_02(self):
         self.set_machine('ast2700-evb')
 
-        image_path = self.ASSET_SDK_V902_AST2700.fetch()
-        archive_extract(image_path, self.workdir)
+        self.archive_extract(self.ASSET_SDK_V902_AST2700)
 
         num_cpu = 4
         uboot_size = os.path.getsize(self.scratch_file('ast2700-default',
tests/functional/test_aarch64_raspi3.py +1 -7
index 98ed6f9d56..74f6630ed2 100755
@@ -7,8 +7,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-from zipfile import ZipFile
-
 from qemu_test import LinuxKernelTest, Asset
 
 
@@ -21,11 +19,7 @@ class Aarch64Raspi3Machine(LinuxKernelTest):
 
     def test_aarch64_raspi3_atf(self):
         efi_name = 'RPI_EFI.fd'
-        zip_path = self.ASSET_RPI3_UEFI.fetch()
-
-        with ZipFile(zip_path, 'r') as zf:
-                     zf.extract(efi_name, path=self.workdir)
-        efi_fd = self.scratch_file(efi_name)
+        efi_fd = self.archive_extract(self.ASSET_RPI3_UEFI, member=efi_name)
 
         self.set_machine('raspi3b')
         self.vm.set_console(console_index=1)
tests/functional/test_aarch64_raspi4.py +8 -6
index 6d68411528..4f95a3a61a 100755
@@ -30,9 +30,10 @@ class Aarch64Raspi4Machine(LinuxKernelTest):
         '7c0b16d1853772f6f4c3ca63e789b3b9ff4936efac9c8a01fb0c98c05c7a7648')
 
     def test_arm_raspi4(self):
-        deb_path = self.ASSET_KERNEL_20190215.fetch()
-        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel8.img')
-        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2711-rpi-4-b.dtb')
+        kernel_path = self.archive_extract(self.ASSET_KERNEL_20190215,
+                                           member='/boot/kernel8.img')
+        dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215,
+                                        member='/boot/bcm2711-rpi-4-b.dtb')
 
         self.set_machine('raspi4b')
         self.vm.set_console()
@@ -58,9 +59,10 @@ def test_arm_raspi4(self):
 
 
     def test_arm_raspi4_initrd(self):
-        deb_path = self.ASSET_KERNEL_20190215.fetch()
-        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel8.img')
-        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2711-rpi-4-b.dtb')
+        kernel_path = self.archive_extract(self.ASSET_KERNEL_20190215,
+                                           member='/boot/kernel8.img')
+        dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215,
+                                        member='/boot/bcm2711-rpi-4-b.dtb')
         initrd_path_gz = self.ASSET_INITRD.fetch()
         initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
tests/functional/test_acpi_bits.py +3 -12
index a2872d2ddf..0649fba545 100755
@@ -37,9 +37,7 @@
 import re
 import shutil
 import subprocess
-import tarfile
 import tempfile
-import zipfile
 
 from typing import (
     List,
@@ -262,19 +260,12 @@ def setUp(self): # pylint: disable=arguments-differ
                                           %(self.BITS_INTERNAL_VER,
                                             self.BITS_COMMIT_HASH))
 
-        bitsLocalArtLoc = self.ASSET_BITS.fetch()
-        self.logger.info("downloaded bits artifacts to %s", bitsLocalArtLoc)
-
         # extract the bits artifact in the temp working directory
-        with zipfile.ZipFile(bitsLocalArtLoc, 'r') as zref:
-            zref.extractall(prebuiltDir)
+        self.archive_extract(self.ASSET_BITS, sub_dir='prebuilt', format='zip')
 
         # extract the bits software in the temp working directory
-        with zipfile.ZipFile(bits_zip_file, 'r') as zref:
-            zref.extractall(self.workdir)
-
-        with tarfile.open(grub_tar_file, 'r', encoding='utf-8') as tarball:
-            tarball.extractall(self.workdir)
+        self.archive_extract(bits_zip_file)
+        self.archive_extract(grub_tar_file)
 
         self.copy_test_scripts()
         self.copy_bits_config()
tests/functional/test_arm_aspeed.py +6 -20
index ca223ac8f0..8e8fac9d7a 100755
@@ -15,8 +15,6 @@
                        interrupt_interactive_console_until_pattern,
                        skipIfMissingCommands,
 )
-from qemu_test.utils import archive_extract
-from zipfile import ZipFile
 from unittest import skipUnless
 
 class AST1030Machine(LinuxKernelTest):
@@ -29,12 +27,8 @@ class AST1030Machine(LinuxKernelTest):
     def test_ast1030_zephyros_1_04(self):
         self.set_machine('ast1030-evb')
 
-        zip_file = self.ASSET_ZEPHYR_1_04.fetch()
-
-        kernel_name = "ast1030-evb-demo/zephyr.elf"
-        with ZipFile(zip_file, 'r') as zf:
-                     zf.extract(kernel_name, path=self.workdir)
-        kernel_file = self.scratch_file(kernel_name)
+        kernel_file = self.archive_extract(
+            self.ASSET_ZEPHYR_1_04, member="ast1030-evb-demo/zephyr.elf")
 
         self.vm.set_console()
         self.vm.add_args('-kernel', kernel_file, '-nographic')
@@ -51,12 +45,8 @@ def test_ast1030_zephyros_1_04(self):
     def test_ast1030_zephyros_1_07(self):
         self.set_machine('ast1030-evb')
 
-        zip_file = self.ASSET_ZEPHYR_1_07.fetch()
-
-        kernel_name = "ast1030-evb-demo/zephyr.bin"
-        with ZipFile(zip_file, 'r') as zf:
-                     zf.extract(kernel_name, path=self.workdir)
-        kernel_file = self.scratch_file(kernel_name)
+        kernel_file = self.archive_extract(
+            self.ASSET_ZEPHYR_1_07, member="ast1030-evb-demo/zephyr.bin")
 
         self.vm.set_console()
         self.vm.add_args('-kernel', kernel_file, '-nographic')
@@ -270,9 +260,7 @@ def do_test_arm_aspeed_sdk_start(self, image):
     def test_arm_ast2500_evb_sdk(self):
         self.set_machine('ast2500-evb')
 
-        image_path = self.ASSET_SDK_V806_AST2500.fetch()
-
-        archive_extract(image_path, self.workdir)
+        self.archive_extract(self.ASSET_SDK_V806_AST2500)
 
         self.do_test_arm_aspeed_sdk_start(
             self.scratch_file('ast2500-default', 'image-bmc'))
@@ -286,9 +274,7 @@ def test_arm_ast2500_evb_sdk(self):
     def test_arm_ast2600_evb_sdk(self):
         self.set_machine('ast2600-evb')
 
-        image_path = self.ASSET_SDK_V806_AST2600_A2.fetch()
-
-        archive_extract(image_path, self.workdir)
+        self.archive_extract(self.ASSET_SDK_V806_AST2600_A2)
 
         self.vm.add_args('-device',
             'tmp105,bus=aspeed.i2c.bus.5,address=0x4d,id=tmp-test');
tests/functional/test_arm_bflt.py +1 -2
index c73e0bfa8c..38d8c4b744 100755
@@ -11,7 +11,6 @@
 from qemu_test import QemuUserTest, Asset, has_cmd
 from qemu_test import (QemuUserTest, Asset, skipIfMissingCommands,
                        skipUntrustedTest)
-from qemu_test.utils import cpio_extract
 
 
 class LoadBFLT(QemuUserTest):
@@ -28,7 +27,7 @@ def test_stm32(self):
         busybox_path = self.scratch_file("bin", "busybox")
 
         with bz2.open(rootfs_path_bz2, 'rb') as cpio_handle:
-            cpio_extract(cpio_handle, self.workdir)
+            self.archive_extract(cpio_handle, format="cpio")
 
         res = self.run_cmd(busybox_path)
         ver = 'BusyBox v1.24.0.git (2015-02-03 22:17:13 CET) multi-call binary.'
tests/functional/test_arm_bpim2u.py +10 -12
index 69f6cdaf68..fd30984e6b 100755
@@ -10,7 +10,7 @@
 from qemu_test import (LinuxKernelTest, exec_command_and_wait_for_pattern,
                        Asset, interrupt_interactive_console_until_pattern,
                        skipBigDataTest)
-from qemu_test.utils import (archive_extract, gzip_uncompress, lzma_uncompress,
+from qemu_test.utils import (gzip_uncompress, lzma_uncompress,
                              image_pow2ceil_expand)
 
 
@@ -39,12 +39,11 @@ class BananaPiMachine(LinuxKernelTest):
 
     def test_arm_bpim2u(self):
         self.set_machine('bpim2u')
-        deb_path = self.ASSET_DEB.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinuz-6.6.16-current-sunxi')
+        kernel_path = self.archive_extract(
+            self.ASSET_DEB, member='/boot/vmlinuz-6.6.16-current-sunxi')
         dtb_path = ('/usr/lib/linux-image-6.6.16-current-sunxi/'
                     'sun8i-r40-bananapi-m2-ultra.dtb')
-        dtb_path = self.extract_from_deb(deb_path, dtb_path)
+        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
@@ -61,12 +60,11 @@ def test_arm_bpim2u(self):
 
     def test_arm_bpim2u_initrd(self):
         self.set_machine('bpim2u')
-        deb_path = self.ASSET_DEB.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinuz-6.6.16-current-sunxi')
+        kernel_path = self.archive_extract(
+            self.ASSET_DEB, member='/boot/vmlinuz-6.6.16-current-sunxi')
         dtb_path = ('/usr/lib/linux-image-6.6.16-current-sunxi/'
                     'sun8i-r40-bananapi-m2-ultra.dtb')
-        dtb_path = self.extract_from_deb(deb_path, dtb_path)
+        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
         initrd_path_gz = self.ASSET_INITRD.fetch()
         initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
@@ -100,11 +98,11 @@ def test_arm_bpim2u_gmac(self):
         self.require_netdev('user')
 
         deb_path = self.ASSET_DEB.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinuz-6.6.16-current-sunxi')
+        kernel_path = self.archive_extract(
+            self.ASSET_DEB, member='/boot/vmlinuz-6.6.16-current-sunxi')
         dtb_path = ('/usr/lib/linux-image-6.6.16-current-sunxi/'
                     'sun8i-r40-bananapi-m2-ultra.dtb')
-        dtb_path = self.extract_from_deb(deb_path, dtb_path)
+        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
         rootfs_path_xz = self.ASSET_ROOTFS.fetch()
         rootfs_path = self.scratch_file('rootfs.cpio')
         lzma_uncompress(rootfs_path_xz, rootfs_path)
tests/functional/test_arm_canona1100.py +3 -7
index cee6a23ed1..5cfb6a0ceb 100755
@@ -11,7 +11,6 @@
 # later.  See the COPYING file in the top-level directory.
 
 from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
-from qemu_test.utils import archive_extract
 
 class CanonA1100Machine(QemuSystemTest):
     """Boots the barebox firmware and checks that the console is operational"""
@@ -25,13 +24,10 @@ class CanonA1100Machine(QemuSystemTest):
     def test_arm_canona1100(self):
         self.set_machine('canon-a1100')
 
-        file_path = self.ASSET_BIOS.fetch()
-        archive_extract(file_path, dest_dir=self.workdir,
-                        member="day18/barebox.canon-a1100.bin")
+        bios = self.archive_extract(self.ASSET_BIOS,
+                                    member="day18/barebox.canon-a1100.bin")
         self.vm.set_console()
-        self.vm.add_args('-bios',
-                         self.scratch_file('day18',
-                                           'barebox.canon-a1100.bin'))
+        self.vm.add_args('-bios', bios)
         self.vm.launch()
         wait_for_console_pattern(self, 'running /env/bin/init')
 
tests/functional/test_arm_collie.py +0 -1
index 7e144a0a8f..78fe61dfdf 100755
@@ -6,7 +6,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class CollieTest(LinuxKernelTest):
 
tests/functional/test_arm_orangepi.py +11 -15
index 7b5e7b6ae1..ff3b62e686 100755
@@ -11,7 +11,7 @@
 from qemu_test import (LinuxKernelTest, exec_command_and_wait_for_pattern,
                        Asset, interrupt_interactive_console_until_pattern,
                        wait_for_console_pattern, skipBigDataTest)
-from qemu_test.utils import (archive_extract, gzip_uncompress, lzma_uncompress,
+from qemu_test.utils import (gzip_uncompress, lzma_uncompress,
                              image_pow2ceil_expand)
 
 
@@ -50,11 +50,10 @@ class BananaPiMachine(LinuxKernelTest):
 
     def test_arm_orangepi(self):
         self.set_machine('orangepi-pc')
-        deb_path = self.ASSET_DEB.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinuz-6.6.16-current-sunxi')
+        kernel_path = self.archive_extract(
+            self.ASSET_DEB, member='/boot/vmlinuz-6.6.16-current-sunxi')
         dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun8i-h3-orangepi-pc.dtb'
-        dtb_path = self.extract_from_deb(deb_path, dtb_path)
+        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
@@ -71,11 +70,10 @@ def test_arm_orangepi(self):
 
     def test_arm_orangepi_initrd(self):
         self.set_machine('orangepi-pc')
-        deb_path = self.ASSET_DEB.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinuz-6.6.16-current-sunxi')
+        kernel_path = self.archive_extract(
+            self.ASSET_DEB, member='/boot/vmlinuz-6.6.16-current-sunxi')
         dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun8i-h3-orangepi-pc.dtb'
-        dtb_path = self.extract_from_deb(deb_path, dtb_path)
+        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
         initrd_path_gz = self.ASSET_INITRD.fetch()
         initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
@@ -107,11 +105,10 @@ def test_arm_orangepi_initrd(self):
     def test_arm_orangepi_sd(self):
         self.set_machine('orangepi-pc')
         self.require_netdev('user')
-        deb_path = self.ASSET_DEB.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinuz-6.6.16-current-sunxi')
+        kernel_path = self.archive_extract(
+            self.ASSET_DEB, member='/boot/vmlinuz-6.6.16-current-sunxi')
         dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun8i-h3-orangepi-pc.dtb'
-        dtb_path = self.extract_from_deb(deb_path, dtb_path)
+        dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
         rootfs_path_xz = self.ASSET_ROOTFS.fetch()
         rootfs_path = self.scratch_file('rootfs.cpio')
         lzma_uncompress(rootfs_path_xz, rootfs_path)
@@ -189,13 +186,12 @@ def test_arm_orangepi_armbian(self):
     def test_arm_orangepi_uboot_netbsd9(self):
         self.set_machine('orangepi-pc')
         # This test download a 304MB compressed image and expand it to 2GB
-        deb_path = self.ASSET_UBOOT.fetch()
         # We use the common OrangePi PC 'plus' build of U-Boot for our secondary
         # program loader (SPL). We will then set the path to the more specific
         # OrangePi "PC" device tree blob with 'setenv fdtfile' in U-Boot prompt,
         # before to boot NetBSD.
         uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin'
-        uboot_path = self.extract_from_deb(deb_path, uboot_path)
+        uboot_path = self.archive_extract(self.ASSET_UBOOT, member=uboot_path)
         image_path_gz = self.ASSET_NETBSD.fetch()
         image_path = self.scratch_file('armv7.img')
         gzip_uncompress(image_path_gz, image_path)
tests/functional/test_arm_raspi2.py +8 -6
index c59dd6c066..8724eee010 100755
@@ -35,9 +35,10 @@ def do_test_arm_raspi2(self, uart_id):
         serial_kernel_cmdline = {
             0: 'earlycon=pl011,0x3f201000 console=ttyAMA0',
         }
-        deb_path = self.ASSET_KERNEL_20190215.fetch()
-        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
-        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
+        kernel_path = self.archive_extract(self.ASSET_KERNEL_20190215,
+                                           member='/boot/kernel7.img')
+        dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215,
+                                        member='/boot/bcm2709-rpi-2-b.dtb')
 
         self.set_machine('raspi2b')
         self.vm.set_console()
@@ -59,9 +60,10 @@ def test_arm_raspi2_uart0(self):
         self.do_test_arm_raspi2(0)
 
     def test_arm_raspi2_initrd(self):
-        deb_path = self.ASSET_KERNEL_20190215.fetch()
-        kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
-        dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
+        kernel_path = self.archive_extract(self.ASSET_KERNEL_20190215,
+                                           member='/boot/kernel7.img')
+        dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215,
+                                        member='/boot/bcm2709-rpi-2-b.dtb')
         initrd_path_gz = self.ASSET_INITRD.fetch()
         initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
tests/functional/test_arm_sx1.py +0 -1
index 2292317946..aa08e6fb19 100755
@@ -14,7 +14,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class SX1Test(LinuxKernelTest):
 
tests/functional/test_arm_vexpress.py +1 -3
index b1ac63ac36..3861366325 100755
@@ -6,7 +6,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class VExpressTest(LinuxKernelTest):
 
@@ -16,8 +15,7 @@ class VExpressTest(LinuxKernelTest):
 
     def test_arm_vexpressa9(self):
         self.set_machine('vexpress-a9')
-        file_path = self.ASSET_DAY16.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_DAY16)
         self.launch_kernel(self.scratch_file('day16', 'winter.zImage'),
                            dtb=self.scratch_file('day16',
                                                  'vexpress-v2p-ca9.dtb'),
tests/functional/test_m68k_mcf5208evb.py +1 -3
index 449248c3e8..ae650ae4ca 100755
@@ -6,7 +6,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class Mcf5208EvbTest(LinuxKernelTest):
 
@@ -16,8 +15,7 @@ class Mcf5208EvbTest(LinuxKernelTest):
 
     def test_m68k_mcf5208evb(self):
         self.set_machine('mcf5208evb')
-        file_path = self.ASSET_DAY07.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_DAY07)
         self.vm.set_console()
         self.vm.add_args('-kernel',
                          self.scratch_file('day07', 'sanity-clause.elf'))
tests/functional/test_m68k_q800.py +2 -3
index 3b17244b98..c63f9b6935 100755
@@ -18,9 +18,8 @@ class Q800MachineTest(LinuxKernelTest):
     def test_m68k_q800(self):
         self.set_machine('q800')
 
-        deb_path = self.ASSET_KERNEL.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinux-5.3.0-1-m68k')
+        kernel_path = self.archive_extract(self.ASSET_KERNEL,
+                                           member='/boot/vmlinux-5.3.0-1-m68k')
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
tests/functional/test_microblaze_s3adsp1800.py +1 -3
index aafc375d3c..56e5e082c8 100755
@@ -9,7 +9,6 @@
 
 from qemu_test import (exec_command, exec_command_and_wait_for_pattern,
                        QemuSystemTest, Asset, wait_for_console_pattern)
-from qemu_test.utils import archive_extract
 
 class MicroblazeMachine(QemuSystemTest):
 
@@ -22,8 +21,7 @@ class MicroblazeMachine(QemuSystemTest):
 
     def test_microblaze_s3adsp1800(self):
         self.set_machine('petalogix-s3adsp1800')
-        file_path = self.ASSET_IMAGE.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_IMAGE)
         self.vm.set_console()
         self.vm.add_args('-kernel',
                          self.scratch_file('day17', 'ballerina.bin'))
tests/functional/test_microblazeel_s3adsp1800.py +1 -3
index 9ea9182f42..9cc516ebf3 100755
@@ -10,7 +10,6 @@
 import time
 from qemu_test import (exec_command, exec_command_and_wait_for_pattern,
                        QemuSystemTest, Asset, wait_for_console_pattern)
-from qemu_test.utils import archive_extract
 
 class MicroblazeelMachine(QemuSystemTest):
 
@@ -23,8 +22,7 @@ class MicroblazeelMachine(QemuSystemTest):
     def test_microblazeel_s3adsp1800(self):
         self.require_netdev('user')
         self.set_machine('petalogix-s3adsp1800')
-        file_path = self.ASSET_IMAGE.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_IMAGE)
         self.vm.set_console()
         self.vm.add_args('-kernel', self.scratch_file('day13', 'xmaton.bin'))
         tftproot = self.scratch_file('day13')
tests/functional/test_mips64el_fuloong2e.py +3 -3
index 8d0ae8d1d5..920a7ec881 100755
@@ -27,9 +27,9 @@ class MipsFuloong2e(LinuxKernelTest):
         '2a70f15b397f4ced632b0c15cb22660394190644146d804d60a4796eefbe1f50')
 
     def test_linux_kernel_3_16(self):
-        deb_path = self.ASSET_KERNEL.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinux-3.16.0-6-loongson-2e')
+        kernel_path = self.archive_extract(
+            self.ASSET_KERNEL,
+            member='/boot/vmlinux-3.16.0-6-loongson-2e')
 
         self.set_machine('fuloong2e')
         self.vm.set_console()
tests/functional/test_mips64el_malta.py +3 -3
index cc17f8af1f..d4b3c1eeab 100755
@@ -39,9 +39,9 @@ def test_mips64el_malta(self):
         [2] https://kernel-team.pages.debian.net/kernel-handbook/
             ch-common-tasks.html#s-common-official
         """
-        deb_path = self.ASSET_KERNEL_2_63_2.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinux-2.6.32-5-5kc-malta')
+        kernel_path = self.archive_extract(
+            self.ASSET_KERNEL_2_63_2,
+            member='/boot/vmlinux-2.6.32-5-5kc-malta')
 
         self.set_machine('malta')
         self.vm.set_console()
tests/functional/test_mips_malta.py +6 -6
index a6d80d0012..65300b7ddf 100755
@@ -20,9 +20,9 @@ class MaltaMachineConsole(LinuxKernelTest):
         '16ca524148afb0626f483163e5edf352bc1ab0e4fc7b9f9d473252762f2c7a43')
 
     def test_mips_malta(self):
-        deb_path = self.ASSET_KERNEL_2_63_2.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinux-2.6.32-5-4kc-malta')
+        kernel_path = self.archive_extract(
+            self.ASSET_KERNEL_2_63_2,
+            member='/boot/vmlinux-2.6.32-5-4kc-malta')
 
         self.set_machine('malta')
         self.vm.set_console()
@@ -46,9 +46,9 @@ def test_mips_malta(self):
         'dcfe3a7fe3200da3a00d176b95caaa086495eb158f2bff64afc67d7e1eb2cddc')
 
     def test_mips_malta_cpio(self):
-        deb_path = self.ASSET_KERNEL_4_5_0.fetch()
-        kernel_path = self.extract_from_deb(deb_path,
-                                            '/boot/vmlinux-4.5.0-2-4kc-malta')
+        kernel_path = self.archive_extract(
+            self.ASSET_KERNEL_4_5_0,
+            member='/boot/vmlinux-4.5.0-2-4kc-malta')
         initrd_path_gz = self.ASSET_INITRD.fetch()
         initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
tests/functional/test_mipsel_malta.py +1 -4
index c5bb4f73c8..90747ba2d0 100755
@@ -15,7 +15,6 @@
                        interrupt_interactive_console_until_pattern,
                        wait_for_console_pattern)
 from qemu_test.utils import lzma_uncompress
-from zipfile import ZipFile
 
 
 class MaltaMachineConsole(LinuxKernelTest):
@@ -75,9 +74,7 @@ class MaltaMachineYAMON(QemuSystemTest):
 
     def test_mipsel_malta_yamon(self):
         yamon_bin = 'yamon-02.22.bin'
-        zip_path = self.ASSET_YAMON_ROM.fetch()
-        with ZipFile(zip_path, 'r') as zf:
-            zf.extract(yamon_bin, path=self.workdir)
+        self.archive_extract(self.ASSET_YAMON_ROM)
         yamon_path = self.scratch_file(yamon_bin)
 
         self.set_machine('malta')
tests/functional/test_or1k_sim.py +1 -3
index a5b2b5b1e5..49f2e3467e 100755
@@ -6,7 +6,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class OpenRISC1kSimTest(LinuxKernelTest):
 
@@ -16,8 +15,7 @@ class OpenRISC1kSimTest(LinuxKernelTest):
 
     def test_or1k_sim(self):
         self.set_machine('or1k-sim')
-        file_path = self.ASSET_DAY20.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_DAY20)
         self.vm.set_console()
         self.vm.add_args('-kernel', self.scratch_file('day20', 'vmlinux'))
         self.vm.launch()
tests/functional/test_ppc64_e500.py +1 -3
index bf4a6af9d4..24295646e0 100755
@@ -5,7 +5,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class E500Test(LinuxKernelTest):
 
@@ -16,8 +15,7 @@ class E500Test(LinuxKernelTest):
     def test_ppc64_e500(self):
         self.set_machine('ppce500')
         self.cpu = 'e5500'
-        file_path = self.ASSET_DAY19.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_DAY19)
         self.launch_kernel(self.scratch_file('day19', 'uImage'),
                            wait_for='QEMU advent calendar')
 
tests/functional/test_ppc_amiga.py +1 -4
index 3e1a666c45..8508697456 100755
@@ -10,7 +10,6 @@
 import subprocess
 
 from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern, run_cmd
-from zipfile import ZipFile
 
 class AmigaOneMachine(QemuSystemTest):
 
@@ -25,9 +24,7 @@ def test_ppc_amigaone(self):
         self.require_accelerator("tcg")
         self.set_machine('amigaone')
         tar_name = 'A1Firmware_Floppy_05-Mar-2005.zip'
-        zip_file = self.ASSET_IMAGE.fetch()
-        with ZipFile(zip_file, 'r') as zf:
-            zf.extractall(path=self.workdir)
+        self.archive_extract(self.ASSET_IMAGE, format="zip")
         bios = self.scratch_file("u-boot-amigaone.bin")
         with open(bios, "wb") as bios_fh:
             subprocess.run(['tail', '-c', '524288',
tests/functional/test_ppc_bamboo.py +1 -3
index 7ec173cbcd..2890200b92 100755
@@ -7,7 +7,6 @@
 # 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 qemu_test.utils import archive_extract
 from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
                        exec_command_and_wait_for_pattern)
 
@@ -25,8 +24,7 @@ def test_ppc_bamboo(self):
         self.set_machine('bamboo')
         self.require_accelerator("tcg")
         self.require_netdev('user')
-        file_path = self.ASSET_IMAGE.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_IMAGE)
         self.vm.set_console()
         self.vm.add_args('-kernel',
                          self.scratch_file('system-image-powerpc-440fp',
tests/functional/test_ppc_mac.py +1 -4
index 10812824bd..e6b730c243 100755
@@ -5,7 +5,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class MacTest(LinuxKernelTest):
 
@@ -19,9 +18,7 @@ def do_day15_test(self):
         # we're running kvm_hv or kvm_pr. For now let's disable this test
         # if we don't have TCG support.
         self.require_accelerator("tcg")
-
-        file_path = self.ASSET_DAY15.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_DAY15)
         self.vm.add_args('-M', 'graphics=off')
         self.launch_kernel(self.scratch_file('day15', 'invaders.elf'),
                            wait_for='QEMU advent calendar')
tests/functional/test_ppc_mpc8544ds.py +3 -4
index 1089d5ff5b..8ca2257967 100755
@@ -7,7 +7,6 @@
 # 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 qemu_test.utils import archive_extract
 from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 
 class Mpc8544dsMachine(QemuSystemTest):
@@ -24,10 +23,10 @@ class Mpc8544dsMachine(QemuSystemTest):
     def test_ppc_mpc8544ds(self):
         self.require_accelerator("tcg")
         self.set_machine('mpc8544ds')
-        file_path = self.ASSET_IMAGE.fetch()
-        archive_extract(file_path, self.workdir, member='creek/creek.bin')
+        kernel_file = self.archive_extract(self.ASSET_IMAGE,
+                                           member='creek/creek.bin')
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.scratch_file('creek', 'creek.bin'))
+        self.vm.add_args('-kernel', kernel_file)
         self.vm.launch()
         wait_for_console_pattern(self, 'QEMU advent calendar 2020',
                                  self.panic_message)
tests/functional/test_ppc_virtex_ml507.py +1 -3
index f39dfa5ae4..5f2a22c2c2 100755
@@ -7,7 +7,6 @@
 # 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 qemu_test.utils import archive_extract
 from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 
 class VirtexMl507Machine(QemuSystemTest):
@@ -24,8 +23,7 @@ class VirtexMl507Machine(QemuSystemTest):
     def test_ppc_virtex_ml507(self):
         self.require_accelerator("tcg")
         self.set_machine('virtex-ml507')
-        file_path = self.ASSET_IMAGE.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_IMAGE)
         self.vm.set_console()
         self.vm.add_args('-kernel', self.scratch_file('hippo', 'hippo.linux'),
                          '-dtb', self.scratch_file('hippo',
tests/functional/test_sh4_r2d.py +2 -3
index dca4601392..03a648374c 100755
@@ -5,7 +5,7 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset, skipFlakyTest
-from qemu_test.utils import archive_extract
+
 
 class R2dTest(LinuxKernelTest):
 
@@ -19,8 +19,7 @@ class R2dTest(LinuxKernelTest):
     @skipFlakyTest(bug_url=None)
     def test_r2d(self):
         self.set_machine('r2d')
-        file_path = self.ASSET_DAY09.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_DAY09)
         self.vm.add_args('-append', 'console=ttySC1')
         self.launch_kernel(self.scratch_file('day09', 'zImage'),
                            console_index=1,
tests/functional/test_sh4eb_r2d.py +2 -3
index 38ee55cf4c..7087ab4c92 100755
@@ -6,7 +6,7 @@
 
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern)
-from qemu_test.utils import archive_extract
+
 
 class R2dEBTest(LinuxKernelTest):
 
@@ -16,8 +16,7 @@ class R2dEBTest(LinuxKernelTest):
 
     def test_sh4eb_r2d(self):
         self.set_machine('r2d')
-        file_path = self.ASSET_TGZ.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_TGZ)
         self.vm.add_args('-append', 'console=ttySC1 noiotrap')
         self.launch_kernel(self.scratch_file('sh4eb', 'linux-kernel'),
                            initrd=self.scratch_file('sh4eb', 'initramfs.cpio.gz'),
tests/functional/test_sparc64_sun4u.py +3 -5
index 43617f1aaf..d1261639b4 100755
@@ -11,7 +11,6 @@
 # later. See the COPYING file in the top-level directory.
 
 from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
-from qemu_test.utils import archive_extract
 
 
 class Sun4uMachine(QemuSystemTest):
@@ -26,11 +25,10 @@ class Sun4uMachine(QemuSystemTest):
 
     def test_sparc64_sun4u(self):
         self.set_machine('sun4u')
-        file_path = self.ASSET_IMAGE.fetch()
-        kernel_name = 'day23/vmlinux'
-        archive_extract(file_path, self.workdir, kernel_name)
+        kernel_file = self.archive_extract(self.ASSET_IMAGE,
+                                           member='day23/vmlinux')
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.scratch_file(kernel_name),
+        self.vm.add_args('-kernel', kernel_file,
                          '-append', 'printk.time=0')
         self.vm.launch()
         wait_for_console_pattern(self, 'Starting logging: OK')
tests/functional/test_sparc_sun4m.py +1 -3
index 619c03d36a..468931f3ef 100755
@@ -6,7 +6,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class Sun4mTest(LinuxKernelTest):
 
@@ -16,8 +15,7 @@ class Sun4mTest(LinuxKernelTest):
 
     def test_sparc_ss20(self):
         self.set_machine('SS-20')
-        file_path = self.ASSET_DAY11.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_DAY11)
         self.launch_kernel(self.scratch_file('day11', 'zImage.elf'),
                            wait_for='QEMU advent calendar')
 
tests/functional/test_xtensa_lx60.py +1 -3
index 5048e4c69e..ec59509a34 100755
@@ -6,7 +6,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import archive_extract
 
 class XTensaLX60Test(LinuxKernelTest):
 
@@ -17,8 +16,7 @@ class XTensaLX60Test(LinuxKernelTest):
     def test_xtensa_lx60(self):
         self.set_machine('lx60')
         self.cpu = 'dc233c'
-        file_path = self.ASSET_DAY02.fetch()
-        archive_extract(file_path, self.workdir)
+        self.archive_extract(self.ASSET_DAY02)
         self.launch_kernel(self.scratch_file('day02',
                                              'santas-sleigh-ride.elf'),
                            wait_for='QEMU advent calendar')
Signature · 1 line
2.46.0
#60 lore raw

PATCH 20/22 tests/functional: generalize uncompress

In reply to Daniel P. Berrangé

There are many types of compression that the tests deal with, and it makes sense to have a single helper 'uncompress' that can deal with all.

---
 tests/functional/qemu_test/utils.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
tests/functional/qemu_test/utils.py +17 -0
index 8c1df8f8c2..90c87b3671 100644
@@ -115,6 +115,23 @@ def lzma_uncompress(xz_path, output_path):
             os.remove(output_path)
             raise
 
+def uncompress(input_path, output_path, format=None):
+    if format == "xz":
+        lzma_uncompress(input_path, output_path)
+    elif format == "gz":
+        gzip_uncompress(input_path, output_path)
+    else:
+        raise Exception(f"Unknown compression format {format}")
+
+def guess_uncompress_format(path):
+    (name, ext) = os.path.splitext(path)
+    if ext == ".xz":
+        return "xz"
+    elif ext == ".gz":
+        return "gz"
+    else:
+        raise Exception(f"Unknown compression format for {path}")
+
 def cpio_extract(cpio_handle, output_path):
     cwd = os.getcwd()
     os.chdir(output_path)
Signature · 1 line
2.46.0
#9 lore raw

PATCH 4/22 tests/functional: remove pointless with statement

In reply to Daniel P. Berrangé

The xorriso command directly writes to 'filename', so the surrounding 'with' statement is pointless.

---
 tests/functional/test_ppc64_hv.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
tests/functional/test_ppc64_hv.py +3 -4
index c31432d18d..53bae90401 100755
@@ -72,10 +72,9 @@ def extract_from_iso(self, iso, path):
         cwd = os.getcwd()
         os.chdir(self.workdir)
 
-        with open(filename, "w") as outfile:
-            cmd = "xorriso -osirrox on -indev %s -cpx %s %s" % (iso, path, filename)
-            subprocess.run(cmd.split(),
-                           stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+        cmd = "xorriso -osirrox on -indev %s -cpx %s %s" % (iso, path, filename)
+        subprocess.run(cmd.split(),
+                       stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
 
         os.chmod(filename, 0o600)
         os.chdir(cwd)
Signature · 1 line
2.46.0
#0 lore raw

cover tests/functional: various improvements wrt assets/scratch files

This series is an attempt to bring a little more guaranteed order to asset and scratch file handling in the functional tests. The main highlights are:

* Add custom @skipXXXXX decorators for common scenarios present in QEMU tests

* Add helpers for creating file paths for various well known types of data, or well known locations, to avoid adhoc path manipulation

* Add helpers to simplify uncompressing and extracting archives, from files downloaded as assets

The series overall has a neutral diffstat, but if you look at just test files, as opposed to the shared infra, you'll see a significant reduction of lines of code in the tests, and I believe its easier to read them with less boilerplate.

Daniel P. Berrangé (22):
tests/functional: increase timeouts for arm sx1 test tests/functional: remove unused system imports tests/functional: remove duplicated 'qemu_test' import statements tests/functional: remove pointless with statement tests/functional: remove duplicated 'which' function impl tests/functional: introduce some helpful decorators tests/functional: switch to new test skip decorators tests/functional: add helpers for building file paths tests/functional: switch over to using self.log_file(...) tests/functional: switch over to using self.build_file(...) tests/functional: switch over to using self.data_file(...) tests/functional: switch over to using self.scratch_file() tests/functional: switch over to using self.socket_dir(...) tests/functional: remove redundant 'rmtree' call tests/functional: add common zip_extract helper tests/functional: add common deb_extract helper tests/functional: generalize archive_extract tests/functional: add 'archive_extract' to QemuBaseTest tests/functional: convert tests to new archive_extract helper tests/functional: generalize uncompress tests/functional: add 'uncompress' to QemuBaseTest tests/functional: convert tests to new uncompress helper

 tests/functional/qemu_test/__init__.py        |   5 +-
 tests/functional/qemu_test/cmd.py             |  10 ++
 tests/functional/qemu_test/decorators.py      | 105 ++++++++++++
 tests/functional/qemu_test/linuxkernel.py     |  27 +---
 tests/functional/qemu_test/testcase.py        | 149 +++++++++++++++++-
 tests/functional/qemu_test/tuxruntest.py      |  11 +-
 tests/functional/qemu_test/utils.py           |  66 +++++++-
 tests/functional/test_aarch64_aspeed.py       |  21 +--
 tests/functional/test_aarch64_raspi3.py       |   9 +-
 tests/functional/test_aarch64_raspi4.py       |  25 ++-
 tests/functional/test_aarch64_sbsaref.py      |  16 +-
 .../functional/test_aarch64_sbsaref_alpine.py |   5 +-
 .../test_aarch64_sbsaref_freebsd.py           |   5 +-
 tests/functional/test_aarch64_virt.py         |  12 +-
 tests/functional/test_acpi_bits.py            | 121 +++++---------
 tests/functional/test_alpha_clipper.py        |   6 +-
 tests/functional/test_arm_aspeed.py           |  52 +++---
 tests/functional/test_arm_bflt.py             |  16 +-
 tests/functional/test_arm_bpim2u.py           |  44 +++---
 tests/functional/test_arm_canona1100.py       |  12 +-
 tests/functional/test_arm_collie.py           |   1 -
 tests/functional/test_arm_integratorcp.py     |  31 ++--
 tests/functional/test_arm_orangepi.py         |  53 +++----
 tests/functional/test_arm_raspi2.py           |  25 ++-
 tests/functional/test_arm_sx1.py              |   7 +-
 tests/functional/test_arm_vexpress.py         |   9 +-
 tests/functional/test_linux_initrd.py         |   7 +-
 tests/functional/test_loongarch64_virt.py     |   6 +-
 tests/functional/test_m68k_mcf5208evb.py      |   9 +-
 tests/functional/test_m68k_nextcube.py        |  19 +--
 tests/functional/test_m68k_q800.py            |   5 +-
 .../functional/test_microblaze_s3adsp1800.py  |  13 +-
 .../test_microblazeel_s3adsp1800.py           |  14 +-
 tests/functional/test_mips64el_fuloong2e.py   |  13 +-
 tests/functional/test_mips64el_loongson3v.py  |  10 +-
 tests/functional/test_mips64el_malta.py       |  49 +++---
 tests/functional/test_mips_malta.py           |  19 +--
 tests/functional/test_mipsel_malta.py         |  28 ++--
 tests/functional/test_multiprocess.py         |   4 +-
 tests/functional/test_netdev_ethtool.py       |   3 +-
 tests/functional/test_or1k_sim.py             |   8 +-
 tests/functional/test_ppc64_e500.py           |   6 +-
 tests/functional/test_ppc64_hv.py             |  49 ++----
 tests/functional/test_ppc64_powernv.py        |   3 +-
 tests/functional/test_ppc64_pseries.py        |   3 +-
 tests/functional/test_ppc_405.py              |   6 +-
 tests/functional/test_ppc_40p.py              |   9 +-
 tests/functional/test_ppc_74xx.py             |   3 +-
 tests/functional/test_ppc_amiga.py            |  20 ++-
 tests/functional/test_ppc_bamboo.py           |  20 +--
 tests/functional/test_ppc_mac.py              |   7 +-
 tests/functional/test_ppc_mpc8544ds.py        |  10 +-
 tests/functional/test_ppc_virtex_ml507.py     |  12 +-
 tests/functional/test_riscv_opensbi.py        |   4 +-
 tests/functional/test_rx_gdbsim.py            |  17 +-
 tests/functional/test_s390x_ccw_virtio.py     |  12 +-
 tests/functional/test_s390x_topology.py       |  15 +-
 tests/functional/test_sh4_r2d.py              |  14 +-
 tests/functional/test_sh4_tuxrun.py           |   4 -
 tests/functional/test_sh4eb_r2d.py            |  16 +-
 tests/functional/test_sparc64_sun4u.py        |  12 +-
 tests/functional/test_sparc_sun4m.py          |   6 +-
 tests/functional/test_virtio_gpu.py           |  19 +--
 tests/functional/test_virtio_version.py       |   2 -
 tests/functional/test_xtensa_lx60.py          |   7 +-
 65 files changed, 677 insertions(+), 649 deletions(-)
 create mode 100644 tests/functional/qemu_test/decorators.py
Signature · 1 line
2.46.0
#3 lore raw

PATCH 2/22 tests/functional: remove unused system imports

---
 tests/functional/test_aarch64_sbsaref.py       | 1 -
 tests/functional/test_acpi_bits.py             | 1 -
 tests/functional/test_m68k_mcf5208evb.py       | 2 --
 tests/functional/test_microblaze_s3adsp1800.py | 1 -
 tests/functional/test_mips64el_loongson3v.py   | 1 -
 tests/functional/test_or1k_sim.py              | 2 --
 tests/functional/test_s390x_topology.py        | 1 -
 tests/functional/test_sh4_tuxrun.py            | 4 ----
 tests/functional/test_sh4eb_r2d.py             | 1 -
 tests/functional/test_virtio_version.py        | 2 --
 10 files changed, 16 deletions(-)
tests/functional/test_aarch64_sbsaref.py +0 -1
index 9fda396b3a..6db08da522 100755
@@ -14,7 +14,6 @@
 from qemu_test import wait_for_console_pattern
 from qemu_test import interrupt_interactive_console_until_pattern
 from qemu_test.utils import lzma_uncompress
-from unittest import skipUnless
 
 def fetch_firmware(test):
     """
tests/functional/test_acpi_bits.py +0 -1
index 3498b96787..6fc49a30bc 100755
@@ -39,7 +39,6 @@
 import subprocess
 import tarfile
 import tempfile
-import time
 import zipfile
 
 from pathlib import Path
tests/functional/test_m68k_mcf5208evb.py +0 -2
index 00c59590c3..fb178fde1c 100755
@@ -5,8 +5,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
 from qemu_test import LinuxKernelTest, Asset
 from qemu_test.utils import archive_extract
 
tests/functional/test_microblaze_s3adsp1800.py +0 -1
index 4f692ffdb1..d2be3105a2 100755
@@ -7,7 +7,6 @@
 # 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 time
 from qemu_test import exec_command, exec_command_and_wait_for_pattern
 from qemu_test import QemuSystemTest, Asset
 from qemu_test import wait_for_console_pattern
tests/functional/test_mips64el_loongson3v.py +0 -1
index 55d62928c7..e57ec5499e 100755
@@ -10,7 +10,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 import os
-import time
 
 from unittest import skipUnless
 from qemu_test import QemuSystemTest, Asset
tests/functional/test_or1k_sim.py +0 -2
index 10e0437c50..5b68b6b628 100755
@@ -5,8 +5,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
 from qemu_test import LinuxKernelTest, Asset
 from qemu_test.utils import archive_extract
 
tests/functional/test_s390x_topology.py +0 -1
index 20727f6bdf..c54c7a8177 100755
@@ -11,7 +11,6 @@
 # later.  See the COPYING file in the top-level directory.
 
 import os
-import time
 
 from qemu_test import QemuSystemTest, Asset
 from qemu_test import exec_command
tests/functional/test_sh4_tuxrun.py +0 -4
index b33533fc7e..1748f8c7ef 100755
@@ -11,10 +11,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-import time
-
-from unittest import skipUnless
 from qemu_test import Asset, exec_command_and_wait_for_pattern
 from qemu_test.tuxruntest import TuxRunBaselineTest
 
tests/functional/test_sh4eb_r2d.py +0 -1
index d9c022c8b8..cd46007942 100755
@@ -10,7 +10,6 @@
 from qemu_test import LinuxKernelTest, Asset
 from qemu_test import exec_command_and_wait_for_pattern
 from qemu_test.utils import archive_extract
-from unittest import skipUnless
 
 class R2dEBTest(LinuxKernelTest):
 
tests/functional/test_virtio_version.py +0 -2
index eb23060564..501e0e5397 100755
@@ -9,8 +9,6 @@
 #
 # 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 sys
-import os
 
 from qemu.machine import QEMUMachine
 from qemu_test import QemuSystemTest
Signature · 1 line
2.46.0
#50 lore raw

PATCH 17/22 tests/functional: generalize archive_extract

In reply to Daniel P. Berrangé

There are many types of archives that the tests deal with, and 'archive_extract' suggests it can cope with any, rather than only tar files. Rename the existing method to 'tar_extract' and add a new method that can dynamically extract any zip, tar or cpio file based on file extension.

---
 tests/functional/qemu_test/utils.py | 31 +++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
tests/functional/qemu_test/utils.py +29 -2
index bafe7fb80e..8c1df8f8c2 100644
@@ -14,6 +14,7 @@
 import shutil
 import subprocess
 import tarfile
+import zipfile
 
 from .cmd import run_cmd
 
@@ -38,7 +39,33 @@ def image_pow2ceil_expand(path):
             with open(path, 'ab+') as fd:
                 fd.truncate(size_aligned)
 
-def archive_extract(archive, dest_dir, member=None):
+def archive_extract(archive, dest_dir, format=None, member=None):
+    if format == "tar":
+        tar_extract(archive, dest_dir, member)
+    elif format == "zip":
+        zip_extract(archive, dest_dir, member)
+    elif format == "cpio":
+        if member is not None:
+            raise Exception("Unable to filter cpio extraction")
+        cpio_extract(archive, dest_dir)
+    elif format == "deb":
+        deb_extract(archive, dest_dir, "./" + member)
+    else:
+        raise Exception(f"Unknown archive format {format}")
+
+def guess_archive_format(path):
+    if ".tar." in path or path.endswith("tgz"):
+        return "tar"
+    elif path.endswith(".zip"):
+        return "zip"
+    elif path.endswith(".cpio"):
+        return "cpio"
+    elif path.endswith(".deb") or path.endswith(".udeb"):
+        return "deb"
+    else:
+        raise Exception(f"Unknown archive format for {path}")
+
+def tar_extract(archive, dest_dir, member=None):
     with tarfile.open(archive) as tf:
         if hasattr(tarfile, 'data_filter'):
             tf.extraction_filter = getattr(tarfile, 'data_filter',
@@ -62,7 +89,7 @@ def deb_extract(archive, dest_dir, member=None):
         (stdout, stderr, ret) = run_cmd(['ar', 't', archive])
         file_path = stdout.split()[2]
         run_cmd(['ar', 'x', archive, file_path])
-        archive_extract(file_path, dest_dir, member)
+        archive_extract(file_path, dest_dir, format="tar", member=member)
     finally:
         os.chdir(cwd)
 
Signature · 1 line
2.46.0
#47 lore raw

PATCH 16/22 tests/functional: add common deb_extract helper

In reply to Daniel P. Berrangé

This mirrors the existing archive_extract, cpio_extract and zip_extract helpers

---
 tests/functional/qemu_test/linuxkernel.py | 15 +++++----------
 tests/functional/qemu_test/utils.py       | 13 +++++++++++++
 2 files changed, 18 insertions(+), 10 deletions(-)
tests/functional/qemu_test/linuxkernel.py +5 -10
index a6525f9dd6..fb6a158d36 100644
@@ -6,8 +6,8 @@
 import os
 
 from .testcase import QemuSystemTest
-from .cmd import run_cmd, wait_for_console_pattern
-from .utils import archive_extract
+from .cmd import wait_for_console_pattern
+from .utils import deb_extract
 
 class LinuxKernelTest(QemuSystemTest):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -37,16 +37,11 @@ def extract_from_deb(self, deb_path, path):
         :param path: path within the deb archive of the file to be extracted
         :returns: path of the extracted file
         """
-        cwd = os.getcwd()
-        os.chdir(self.workdir)
-        (stdout, stderr, ret) = run_cmd(['ar', 't', deb_path])
-        file_path = stdout.split()[2]
-        run_cmd(['ar', 'x', deb_path, file_path])
-        archive_extract(file_path, self.workdir)
-        os.chdir(cwd)
+        relpath = os.path.relpath(path, '/')
+        deb_extract(deb_path, self.workdir, member="." + path)
         # Return complete path to extracted file.  Because callers to
         # extract_from_deb() specify 'path' with a leading slash, it is
         # necessary to use 'relative_to()' to turn it into a relative
         # path for joining to the scratch dir
-        return os.path.normpath(self.scratch_file(os.path.relpath(path, '/')))
+        return os.path.normpath(self.scratch_file(relpath))
 
tests/functional/qemu_test/utils.py +13 -0
index 41bd1df666..bafe7fb80e 100644
@@ -15,6 +15,8 @@
 import subprocess
 import tarfile
 
+from .cmd import run_cmd
+
 """
 Round up to next power of 2
 """
@@ -53,6 +55,17 @@ def zip_extract(archive, dest_dir, member=None):
         else:
             zf.extractall(path=dest_dir)
 
+def deb_extract(archive, dest_dir, member=None):
+    cwd = os.getcwd()
+    os.chdir(dest_dir)
+    try:
+        (stdout, stderr, ret) = run_cmd(['ar', 't', archive])
+        file_path = stdout.split()[2]
+        run_cmd(['ar', 'x', archive, file_path])
+        archive_extract(file_path, dest_dir, member)
+    finally:
+        os.chdir(cwd)
+
 def gzip_uncompress(gz_path, output_path):
     if os.path.exists(output_path):
         return
Signature · 1 line
2.46.0
#37 lore raw

PATCH 12/22 tests/functional: switch over to using self.scratch_file()

In reply to Daniel P. Berrangé

Replace any instances of

os.path.join(self.workdir, ".../...")
self.workdir + "/.../..."

with

self.scratch_file("...", "...")

which is more compact and portable

---
 tests/functional/qemu_test/linuxkernel.py     |  7 ++-
 tests/functional/qemu_test/tuxruntest.py      |  2 +-
 tests/functional/test_aarch64_aspeed.py       | 17 ++++---
 tests/functional/test_aarch64_raspi3.py       |  3 +-
 tests/functional/test_aarch64_raspi4.py       |  4 +-
 tests/functional/test_aarch64_sbsaref.py      |  7 ++-
 tests/functional/test_aarch64_virt.py         |  2 +-
 tests/functional/test_acpi_bits.py            | 48 +++++++++----------
 tests/functional/test_alpha_clipper.py        |  4 +-
 tests/functional/test_arm_aspeed.py           | 14 +++---
 tests/functional/test_arm_bflt.py             |  3 +-
 tests/functional/test_arm_bpim2u.py           |  6 +--
 tests/functional/test_arm_canona1100.py       |  3 +-
 tests/functional/test_arm_integratorcp.py     |  3 +-
 tests/functional/test_arm_orangepi.py         |  8 ++--
 tests/functional/test_arm_raspi2.py           |  4 +-
 tests/functional/test_arm_vexpress.py         |  5 +-
 tests/functional/test_m68k_mcf5208evb.py      |  3 +-
 tests/functional/test_m68k_nextcube.py        |  5 +-
 .../functional/test_microblaze_s3adsp1800.py  |  3 +-
 .../test_microblazeel_s3adsp1800.py           |  5 +-
 tests/functional/test_mips64el_malta.py       |  6 +--
 tests/functional/test_mips_malta.py           |  4 +-
 tests/functional/test_mipsel_malta.py         |  4 +-
 tests/functional/test_or1k_sim.py             |  2 +-
 tests/functional/test_ppc64_e500.py           |  2 +-
 tests/functional/test_ppc64_hv.py             | 12 +----
 tests/functional/test_ppc_amiga.py            | 12 +++--
 tests/functional/test_ppc_bamboo.py           | 10 ++--
 tests/functional/test_ppc_mac.py              |  2 +-
 tests/functional/test_ppc_mpc8544ds.py        |  2 +-
 tests/functional/test_ppc_virtex_ml507.py     |  5 +-
 tests/functional/test_rx_gdbsim.py            |  4 +-
 tests/functional/test_s390x_ccw_virtio.py     |  2 +-
 tests/functional/test_s390x_topology.py       |  4 +-
 tests/functional/test_sh4_r2d.py              |  3 +-
 tests/functional/test_sh4eb_r2d.py            |  7 ++-
 tests/functional/test_sparc64_sun4u.py        |  5 +-
 tests/functional/test_sparc_sun4m.py          |  2 +-
 tests/functional/test_xtensa_lx60.py          |  3 +-
 40 files changed, 116 insertions(+), 131 deletions(-)
tests/functional/qemu_test/linuxkernel.py +3 -4
index 2b5b9a5fda..a6525f9dd6 100644
@@ -46,8 +46,7 @@ def extract_from_deb(self, deb_path, path):
         os.chdir(cwd)
         # Return complete path to extracted file.  Because callers to
         # extract_from_deb() specify 'path' with a leading slash, it is
-        # necessary to use os.path.relpath() as otherwise os.path.join()
-        # interprets it as an absolute path and drops the self.workdir part.
-        return os.path.normpath(os.path.join(self.workdir,
-                                             os.path.relpath(path, '/')))
+        # necessary to use 'relative_to()' to turn it into a relative
+        # path for joining to the scratch dir
+        return os.path.normpath(self.scratch_file(os.path.relpath(path, '/')))
 
tests/functional/qemu_test/tuxruntest.py +1 -1
index 7c0456923e..e9a26380be 100644
@@ -78,7 +78,7 @@ def fetch_tuxrun_assets(self, kernel_asset, rootfs_asset, dtb_asset=None):
         kernel_image =  kernel_asset.fetch()
         disk_image_zst = rootfs_asset.fetch()
 
-        disk_image = self.workdir + "/rootfs.ext4"
+        disk_image = self.scratch_file("rootfs.ext4")
 
         run_cmd([self.zstd, "-f", "-d", disk_image_zst,
                  "-o", disk_image])
tests/functional/test_aarch64_aspeed.py +10 -7
index 59916efd71..c6c6b74acc 100644
@@ -39,26 +39,28 @@ def test_aarch64_ast2700_evb_sdk_v09_02(self):
         archive_extract(image_path, self.workdir)
 
         num_cpu = 4
-        image_dir = self.workdir + '/ast2700-default/'
-        uboot_size = os.path.getsize(image_dir + 'u-boot-nodtb.bin')
+        uboot_size = os.path.getsize(self.scratch_file('ast2700-default',
+                                                       'u-boot-nodtb.bin'))
         uboot_dtb_load_addr = hex(0x400000000 + uboot_size)
 
         load_images_list = [
             {
                 'addr': '0x400000000',
-                'file': image_dir + 'u-boot-nodtb.bin'
+                'file': self.scratch_file('ast2700-default',
+                                          'u-boot-nodtb.bin')
             },
             {
                 'addr': str(uboot_dtb_load_addr),
-                'file': image_dir + 'u-boot.dtb'
+                'file': self.scratch_file('ast2700-default', 'u-boot.dtb')
             },
             {
                 'addr': '0x430000000',
-                'file': image_dir + 'bl31.bin'
+                'file': self.scratch_file('ast2700-default', 'bl31.bin')
             },
             {
                 'addr': '0x430080000',
-                'file': image_dir + 'optee/tee-raw.bin'
+                'file': self.scratch_file('ast2700-default', 'optee',
+                                          'tee-raw.bin')
             }
         ]
 
@@ -75,7 +77,8 @@ def test_aarch64_ast2700_evb_sdk_v09_02(self):
         self.vm.add_args('-smp', str(num_cpu))
         self.vm.add_args('-device',
                          'tmp105,bus=aspeed.i2c.bus.1,address=0x4d,id=tmp-test')
-        self.do_test_aarch64_aspeed_sdk_start(image_dir + 'image-bmc')
+        self.do_test_aarch64_aspeed_sdk_start(
+            self.scratch_file('ast2700-default', 'image-bmc'))
 
         wait_for_console_pattern(self, 'ast2700-default login:')
 
tests/functional/test_aarch64_raspi3.py +1 -2
index 369f95a3d9..98ed6f9d56 100755
@@ -7,7 +7,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
 from zipfile import ZipFile
 
 from qemu_test import LinuxKernelTest, Asset
@@ -26,7 +25,7 @@ def test_aarch64_raspi3_atf(self):
 
         with ZipFile(zip_path, 'r') as zf:
                      zf.extract(efi_name, path=self.workdir)
-        efi_fd = os.path.join(self.workdir, efi_name)
+        efi_fd = self.scratch_file(efi_name)
 
         self.set_machine('raspi3b')
         self.vm.set_console(console_index=1)
tests/functional/test_aarch64_raspi4.py +1 -3
index 95e9c8e643..6d68411528 100755
@@ -5,8 +5,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern)
 from qemu_test.utils import gzip_uncompress
@@ -64,7 +62,7 @@ def test_arm_raspi4_initrd(self):
         kernel_path = self.extract_from_deb(deb_path, '/boot/kernel8.img')
         dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2711-rpi-4-b.dtb')
         initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
+        initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
 
         self.set_machine('raspi4b')
tests/functional/test_aarch64_sbsaref.py +3 -4
index 8064b691c7..4c173a0303 100755
@@ -8,12 +8,11 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
 from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
                        interrupt_interactive_console_until_pattern)
 from qemu_test.utils import lzma_uncompress
 
+
 def fetch_firmware(test):
     """
     Flash volumes generated using:
@@ -31,12 +30,12 @@ def fetch_firmware(test):
 
     # Secure BootRom (TF-A code)
     fs0_xz_path = Aarch64SbsarefMachine.ASSET_FLASH0.fetch()
-    fs0_path = os.path.join(test.workdir, "SBSA_FLASH0.fd")
+    fs0_path = test.scratch_file("SBSA_FLASH0.fd")
     lzma_uncompress(fs0_xz_path, fs0_path)
 
     # Non-secure rom (UEFI and EFI variables)
     fs1_xz_path = Aarch64SbsarefMachine.ASSET_FLASH1.fetch()
-    fs1_path = os.path.join(test.workdir, "SBSA_FLASH1.fd")
+    fs1_path = test.scratch_file("SBSA_FLASH1.fd")
     lzma_uncompress(fs1_xz_path, fs1_path)
 
     for path in [fs0_path, fs1_path]:
tests/functional/test_aarch64_virt.py +1 -1
index 29eeb8e32d..66166c0fb0 100755
@@ -94,7 +94,7 @@ def common_aarch64_virt(self, machine):
 
         # Also add a scratch block device
         logger.info('creating scratch qcow2 image')
-        image_path = os.path.join(self.workdir, 'scratch.qcow2')
+        image_path = self.scratch_file('scratch.qcow2')
         qemu_img = get_qemu_img(self)
         run_cmd([qemu_img, 'create', '-f', 'qcow2', image_path, '8M'])
 
tests/functional/test_acpi_bits.py +22 -26

93 lines not on this page · raw message

tests/functional/test_alpha_clipper.py +1 -3
index c1fbf0e395..72cd7b57e6 100755
@@ -5,8 +5,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
 from qemu_test import LinuxKernelTest, Asset
 from qemu_test.utils import gzip_uncompress
 
@@ -22,7 +20,7 @@ def test_alpha_clipper(self):
         self.set_machine('clipper')
         kernel_path = self.ASSET_KERNEL.fetch()
 
-        uncompressed_kernel = os.path.join(self.workdir, 'vmlinux')
+        uncompressed_kernel = self.scratch_file('vmlinux')
         gzip_uncompress(kernel_path, uncompressed_kernel)
 
         self.vm.set_console()
tests/functional/test_arm_aspeed.py +8 -6
index db872ff05e..c4869011db 100755
@@ -35,7 +35,7 @@ def test_ast1030_zephyros_1_04(self):
         kernel_name = "ast1030-evb-demo/zephyr.elf"
         with ZipFile(zip_file, 'r') as zf:
                      zf.extract(kernel_name, path=self.workdir)
-        kernel_file = os.path.join(self.workdir, kernel_name)
+        kernel_file = self.scratch_file(kernel_name)
 
         self.vm.set_console()
         self.vm.add_args('-kernel', kernel_file, '-nographic')
@@ -57,7 +57,7 @@ def test_ast1030_zephyros_1_07(self):
         kernel_name = "ast1030-evb-demo/zephyr.bin"
         with ZipFile(zip_file, 'r') as zf:
                      zf.extract(kernel_name, path=self.workdir)
-        kernel_file = os.path.join(self.workdir, kernel_name)
+        kernel_file = self.scratch_file(kernel_name)
 
         self.vm.set_console()
         self.vm.add_args('-kernel', kernel_file, '-nographic')
@@ -226,14 +226,16 @@ def test_arm_ast2600_evb_buildroot_tpm(self):
 
         image_path = self.ASSET_BR2_202302_AST2600_TPM_FLASH.fetch()
 
-        tpmstate_dir = tempfile.TemporaryDirectory(prefix="qemu_")
+        tpmstate_dir = self.scratch_file('swtpmstate')
+        os.mkdir(tpmstate_dir)
+        socket_dir = tempfile.TemporaryDirectory(prefix="qemu_")
         socket = os.path.join(tpmstate_dir.name, 'swtpm-socket')
 
         # We must put the TPM state dir in /tmp/, not the build dir,
         # because some distros use AppArmor to lock down swtpm and
         # restrict the set of locations it can access files in.
         subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
-                        '--tpmstate', f'dir={tpmstate_dir.name}',
+                        '--tpmstate', f'dir={tpmstate_dir}',
                         '--ctrl', f'type=unixio,path={socket}'])
 
         self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}')
@@ -274,7 +276,7 @@ def test_arm_ast2500_evb_sdk(self):
         archive_extract(image_path, self.workdir)
 
         self.do_test_arm_aspeed_sdk_start(
-            self.workdir + '/ast2500-default/image-bmc')
+            self.scratch_file('ast2500-default', 'image-bmc'))
 
         self.wait_for_console_pattern('ast2500-default login:')
 
@@ -294,7 +296,7 @@ def test_arm_ast2600_evb_sdk(self):
         self.vm.add_args('-device',
             'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
         self.do_test_arm_aspeed_sdk_start(
-            self.workdir + '/ast2600-a2/image-bmc')
+            self.scratch_file('ast2600-a2', 'image-bmc'))
 
         self.wait_for_console_pattern('ast2600-a2 login:')
 
tests/functional/test_arm_bflt.py +1 -2
index 74d04fd381..c73e0bfa8c 100755
@@ -6,7 +6,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
 import bz2
 
 from qemu_test import QemuUserTest, Asset, has_cmd
@@ -26,7 +25,7 @@ class LoadBFLT(QemuUserTest):
     def test_stm32(self):
         # See https://elinux.org/STM32#User_Space
         rootfs_path_bz2 = self.ASSET_ROOTFS.fetch()
-        busybox_path = os.path.join(self.workdir, "bin/busybox")
+        busybox_path = self.scratch_file("bin", "busybox")
 
         with bz2.open(rootfs_path_bz2, 'rb') as cpio_handle:
             cpio_extract(cpio_handle, self.workdir)
tests/functional/test_arm_bpim2u.py +3 -3
index d2108fd4ea..69f6cdaf68 100755
@@ -68,7 +68,7 @@ def test_arm_bpim2u_initrd(self):
                     'sun8i-r40-bananapi-m2-ultra.dtb')
         dtb_path = self.extract_from_deb(deb_path, dtb_path)
         initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
+        initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
 
         self.vm.set_console()
@@ -106,7 +106,7 @@ def test_arm_bpim2u_gmac(self):
                     'sun8i-r40-bananapi-m2-ultra.dtb')
         dtb_path = self.extract_from_deb(deb_path, dtb_path)
         rootfs_path_xz = self.ASSET_ROOTFS.fetch()
-        rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
+        rootfs_path = self.scratch_file('rootfs.cpio')
         lzma_uncompress(rootfs_path_xz, rootfs_path)
         image_pow2ceil_expand(rootfs_path)
 
@@ -150,7 +150,7 @@ def test_arm_bpim2u_openwrt_22_03_3(self):
         # This test download a 8.9 MiB compressed image and expand it
         # to 127 MiB.
         image_path_gz = self.ASSET_SD_IMAGE.fetch()
-        image_path = os.path.join(self.workdir, 'sdcard.img')
+        image_path = self.scratch_file('sdcard.img')
         gzip_uncompress(image_path_gz, image_path)
         image_pow2ceil_expand(image_path)
 
tests/functional/test_arm_canona1100.py +2 -1
index 41e78b7d1b..cee6a23ed1 100755
@@ -30,7 +30,8 @@ def test_arm_canona1100(self):
                         member="day18/barebox.canon-a1100.bin")
         self.vm.set_console()
         self.vm.add_args('-bios',
-                         self.workdir + '/day18/barebox.canon-a1100.bin')
+                         self.scratch_file('day18',
+                                           'barebox.canon-a1100.bin'))
         self.vm.launch()
         wait_for_console_pattern(self, 'running /env/bin/init')
 
tests/functional/test_arm_integratorcp.py +1 -2
index a13e82bd31..e829b6beac 100755
@@ -12,7 +12,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
 import logging
 
 from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
@@ -66,7 +65,7 @@ def test_framebuffer_tux_logo(self):
         import numpy as np
         import cv2
 
-        screendump_path = os.path.join(self.workdir, "screendump.pbm")
+        screendump_path = self.scratch_file("screendump.pbm")
         tuxlogo_path = self.ASSET_TUXLOGO.fetch()
 
         self.boot_integratorcp()
tests/functional/test_arm_orangepi.py +4 -4
index 7974010320..7b5e7b6ae1 100755
@@ -77,7 +77,7 @@ def test_arm_orangepi_initrd(self):
         dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun8i-h3-orangepi-pc.dtb'
         dtb_path = self.extract_from_deb(deb_path, dtb_path)
         initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
+        initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
 
         self.vm.set_console()
@@ -113,7 +113,7 @@ def test_arm_orangepi_sd(self):
         dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun8i-h3-orangepi-pc.dtb'
         dtb_path = self.extract_from_deb(deb_path, dtb_path)
         rootfs_path_xz = self.ASSET_ROOTFS.fetch()
-        rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
+        rootfs_path = self.scratch_file('rootfs.cpio')
         lzma_uncompress(rootfs_path_xz, rootfs_path)
         image_pow2ceil_expand(rootfs_path)
 
@@ -156,7 +156,7 @@ def test_arm_orangepi_armbian(self):
         # to 1036 MiB, but the underlying filesystem is 1552 MiB...
         # As we expand it to 2 GiB we are safe.
         image_path_xz = self.ASSET_ARMBIAN.fetch()
-        image_path = os.path.join(self.workdir, 'armbian.img')
+        image_path = self.scratch_file('armbian.img')
         lzma_uncompress(image_path_xz, image_path)
         image_pow2ceil_expand(image_path)
 
@@ -197,7 +197,7 @@ def test_arm_orangepi_uboot_netbsd9(self):
         uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin'
         uboot_path = self.extract_from_deb(deb_path, uboot_path)
         image_path_gz = self.ASSET_NETBSD.fetch()
-        image_path = os.path.join(self.workdir, 'armv7.img')
+        image_path = self.scratch_file('armv7.img')
         gzip_uncompress(image_path_gz, image_path)
         image_pow2ceil_expand(image_path)
         image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path
tests/functional/test_arm_raspi2.py +1 -3
index 4d31454f8f..c59dd6c066 100755
@@ -7,8 +7,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern)
 from qemu_test.utils import gzip_uncompress
@@ -65,7 +63,7 @@ def test_arm_raspi2_initrd(self):
         kernel_path = self.extract_from_deb(deb_path, '/boot/kernel7.img')
         dtb_path = self.extract_from_deb(deb_path, '/boot/bcm2709-rpi-2-b.dtb')
         initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
+        initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
 
         self.set_machine('raspi2b')
tests/functional/test_arm_vexpress.py +3 -2
index 6bd6290030..b1ac63ac36 100755
@@ -18,8 +18,9 @@ def test_arm_vexpressa9(self):
         self.set_machine('vexpress-a9')
         file_path = self.ASSET_DAY16.fetch()
         archive_extract(file_path, self.workdir)
-        self.launch_kernel(self.workdir + '/day16/winter.zImage',
-                           dtb=self.workdir + '/day16/vexpress-v2p-ca9.dtb',
+        self.launch_kernel(self.scratch_file('day16', 'winter.zImage'),
+                           dtb=self.scratch_file('day16',
+                                                 'vexpress-v2p-ca9.dtb'),
                            wait_for='QEMU advent calendar')
 
 if __name__ == '__main__':
tests/functional/test_m68k_mcf5208evb.py +2 -1
index fb178fde1c..449248c3e8 100755
@@ -19,7 +19,8 @@ def test_m68k_mcf5208evb(self):
         file_path = self.ASSET_DAY07.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.workdir + '/day07/sanity-clause.elf')
+        self.vm.add_args('-kernel',
+                         self.scratch_file('day07', 'sanity-clause.elf'))
         self.vm.launch()
         self.wait_for_console_pattern('QEMU advent calendar')
 
tests/functional/test_m68k_nextcube.py +2 -3
index 82d3d335d0..4003fff584 100755
@@ -7,7 +7,6 @@
 # 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 os
 import time
 
 from qemu_test import QemuSystemTest, Asset, skipIfMissingImports
@@ -39,7 +38,7 @@ def check_bootrom_framebuffer(self, screenshot_path):
     @skipIfMissingImports("PIL")
     def test_bootrom_framebuffer_size(self):
         self.set_machine('next-cube')
-        screenshot_path = os.path.join(self.workdir, "dump.ppm")
+        screenshot_path = self.scratch_file("dump.ppm")
         self.check_bootrom_framebuffer(screenshot_path)
 
         from PIL import Image
@@ -53,7 +52,7 @@ def test_bootrom_framebuffer_size(self):
     @skipUnless(tesseract_available(4), 'tesseract OCR tool not available')
     def test_bootrom_framebuffer_ocr_with_tesseract(self):
         self.set_machine('next-cube')
-        screenshot_path = os.path.join(self.workdir, "dump.ppm")
+        screenshot_path = self.scratch_file("dump.ppm")
         self.check_bootrom_framebuffer(screenshot_path)
         lines = tesseract_ocr(screenshot_path)
         text = '\n'.join(lines)
tests/functional/test_microblaze_s3adsp1800.py +2 -1
index 387feb5dcc..aafc375d3c 100755
@@ -25,7 +25,8 @@ def test_microblaze_s3adsp1800(self):
         file_path = self.ASSET_IMAGE.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.workdir + '/day17/ballerina.bin')
+        self.vm.add_args('-kernel',
+                         self.scratch_file('day17', 'ballerina.bin'))
         self.vm.launch()
         wait_for_console_pattern(self, 'This architecture does not have '
                                        'kernel memory protection')
tests/functional/test_microblazeel_s3adsp1800.py +3 -2
index 875e2ab14c..9ea9182f42 100755
@@ -26,8 +26,9 @@ def test_microblazeel_s3adsp1800(self):
         file_path = self.ASSET_IMAGE.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.workdir + '/day13/xmaton.bin')
-        self.vm.add_args('-nic', 'user,tftp=' + self.workdir + '/day13/')
+        self.vm.add_args('-kernel', self.scratch_file('day13', 'xmaton.bin'))
+        tftproot = self.scratch_file('day13')
+        self.vm.add_args('-nic', f'user,tftp={tftproot}')
         self.vm.launch()
         wait_for_console_pattern(self, 'QEMU Advent Calendar 2023')
         time.sleep(0.1)
tests/functional/test_mips64el_malta.py +3 -3
index ccb9616f68..cc17f8af1f 100755
@@ -68,7 +68,7 @@ def test_mips64el_malta(self):
     def test_mips64el_malta_5KEc_cpio(self):
         kernel_path = self.ASSET_KERNEL_3_19_3.fetch()
         initrd_path_gz = self.ASSET_CPIO_R1.fetch()
-        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
+        initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
 
         self.set_machine('malta')
@@ -117,10 +117,10 @@ def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
         import numpy as np
         import cv2
 
-        screendump_path = os.path.join(self.workdir, 'screendump.pbm')
+        screendump_path = self.scratch_file('screendump.pbm')
 
         kernel_path_gz = self.ASSET_KERNEL_4_7_0.fetch()
-        kernel_path = self.workdir + "/vmlinux"
+        kernel_path = self.scratch_file("vmlinux")
         gzip_uncompress(kernel_path_gz, kernel_path)
 
         tuxlogo_path = self.ASSET_TUXLOGO.fetch()
tests/functional/test_mips_malta.py +1 -3
index a012081382..a6d80d0012 100755
@@ -6,8 +6,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
-
 from qemu_test import LinuxKernelTest, Asset
 from qemu_test import exec_command_and_wait_for_pattern
 from qemu_test.utils import gzip_uncompress
@@ -52,7 +50,7 @@ def test_mips_malta_cpio(self):
         kernel_path = self.extract_from_deb(deb_path,
                                             '/boot/vmlinux-4.5.0-2-4kc-malta')
         initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
+        initrd_path = self.scratch_file('rootfs.cpio')
         gzip_uncompress(initrd_path_gz, initrd_path)
 
         self.set_machine('malta')
tests/functional/test_mipsel_malta.py +2 -2
index af6d280f99..c5bb4f73c8 100755
@@ -37,7 +37,7 @@ class MaltaMachineConsole(LinuxKernelTest):
         'ce21ff4b07a981ecb8a39db2876616f5a2473eb2ab459c6f67465b9914b0c6b6')
 
     def do_test_mips_malta32el_nanomips(self, kernel_path_xz):
-        kernel_path = os.path.join(self.workdir, 'kernel')
+        kernel_path = self.scratch_file('kernel')
         lzma_uncompress(kernel_path_xz, kernel_path)
 
         self.set_machine('malta')
@@ -78,7 +78,7 @@ def test_mipsel_malta_yamon(self):
         zip_path = self.ASSET_YAMON_ROM.fetch()
         with ZipFile(zip_path, 'r') as zf:
             zf.extract(yamon_bin, path=self.workdir)
-        yamon_path = os.path.join(self.workdir, yamon_bin)
+        yamon_path = self.scratch_file(yamon_bin)
 
         self.set_machine('malta')
         self.vm.set_console()
tests/functional/test_or1k_sim.py +1 -1
index 5b68b6b628..a5b2b5b1e5 100755
@@ -19,7 +19,7 @@ def test_or1k_sim(self):
         file_path = self.ASSET_DAY20.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.workdir + '/day20/vmlinux')
+        self.vm.add_args('-kernel', self.scratch_file('day20', 'vmlinux'))
         self.vm.launch()
         self.wait_for_console_pattern('QEMU advent calendar')
 
tests/functional/test_ppc64_e500.py +1 -1
index f1af92373e..bf4a6af9d4 100755
@@ -18,7 +18,7 @@ def test_ppc64_e500(self):
         self.cpu = 'e5500'
         file_path = self.ASSET_DAY19.fetch()
         archive_extract(file_path, self.workdir)
-        self.launch_kernel(self.workdir + '/day19/uImage',
+        self.launch_kernel(self.scratch_file('day19', 'uImage'),
                            wait_for='QEMU advent calendar')
 
 if __name__ == '__main__':
tests/functional/test_ppc64_hv.py +2 -10
index 9ad69b4a15..9cd86bcdf9 100755
@@ -45,23 +45,15 @@ def extract_from_iso(self, iso, path):
         :param path: path within the iso file of the file to be extracted
         :returns: path of the extracted file
         """
-        filename = os.path.basename(path)
-
-        cwd = os.getcwd()
-        os.chdir(self.workdir)
+        filename = self.scratch_file(os.path.basename(path))
 
         cmd = "xorriso -osirrox on -indev %s -cpx %s %s" % (iso, path, filename)
         subprocess.run(cmd.split(),
                        stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
 
         os.chmod(filename, 0o600)
-        os.chdir(cwd)
 
-        # Return complete path to extracted file.  Because callers to
-        # extract_from_iso() specify 'path' with a leading slash, it is
-        # necessary to use os.path.relpath() as otherwise os.path.join()
-        # interprets it as an absolute path and drops the self.workdir part.
-        return os.path.normpath(os.path.join(self.workdir, filename))
+        return filename
 
     def setUp(self):
         super().setUp()
tests/functional/test_ppc_amiga.py +7 -5
index e92489fdb2..3e1a666c45 100755
@@ -28,13 +28,15 @@ def test_ppc_amigaone(self):
         zip_file = self.ASSET_IMAGE.fetch()
         with ZipFile(zip_file, 'r') as zf:
             zf.extractall(path=self.workdir)
-        bios_fh = open(self.workdir + "/u-boot-amigaone.bin", "wb")
-        subprocess.run(['tail', '-c', '524288',
-                        self.workdir + "/floppy_edition/updater.image"],
-                        stdout=bios_fh)
+        bios = self.scratch_file("u-boot-amigaone.bin")
+        with open(bios, "wb") as bios_fh:
+            subprocess.run(['tail', '-c', '524288',
+                            self.scratch_file("floppy_edition",
+                                              "updater.image")],
+                           stdout=bios_fh)
 
         self.vm.set_console()
-        self.vm.add_args('-bios', self.workdir + '/u-boot-amigaone.bin')
+        self.vm.add_args('-bios', bios)
         self.vm.launch()
         wait_for_console_pattern(self, 'FLASH:')
 
tests/functional/test_ppc_bamboo.py +6 -4
index 71b30781f1..7ec173cbcd 100755
@@ -28,10 +28,12 @@ def test_ppc_bamboo(self):
         file_path = self.ASSET_IMAGE.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.workdir +
-                                   '/system-image-powerpc-440fp/linux',
-                         '-initrd', self.workdir +
-                                   '/system-image-powerpc-440fp/rootfs.cpio.gz',
+        self.vm.add_args('-kernel',
+                         self.scratch_file('system-image-powerpc-440fp',
+                                           'linux'),
+                         '-initrd',
+                         self.scratch_file('system-image-powerpc-440fp',
+                                           'rootfs.cpio.gz'),
                          '-nic', 'user,model=rtl8139,restrict=on')
         self.vm.launch()
         wait_for_console_pattern(self, 'Type exit when done')
tests/functional/test_ppc_mac.py +1 -1
index 3f45e37a45..10812824bd 100755
@@ -23,7 +23,7 @@ def do_day15_test(self):
         file_path = self.ASSET_DAY15.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.add_args('-M', 'graphics=off')
-        self.launch_kernel(self.workdir + '/day15/invaders.elf',
+        self.launch_kernel(self.scratch_file('day15', 'invaders.elf'),
                            wait_for='QEMU advent calendar')
 
     def test_ppc_g3beige(self):
tests/functional/test_ppc_mpc8544ds.py +1 -1
index 746efda1ae..1089d5ff5b 100755
@@ -27,7 +27,7 @@ def test_ppc_mpc8544ds(self):
         file_path = self.ASSET_IMAGE.fetch()
         archive_extract(file_path, self.workdir, member='creek/creek.bin')
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.workdir + '/creek/creek.bin')
+        self.vm.add_args('-kernel', self.scratch_file('creek', 'creek.bin'))
         self.vm.launch()
         wait_for_console_pattern(self, 'QEMU advent calendar 2020',
                                  self.panic_message)
tests/functional/test_ppc_virtex_ml507.py +3 -2
index 3c49d41341..f39dfa5ae4 100755
@@ -27,8 +27,9 @@ def test_ppc_virtex_ml507(self):
         file_path = self.ASSET_IMAGE.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.set_console()
-        self.vm.add_args('-kernel', self.workdir + '/hippo/hippo.linux',
-                         '-dtb', self.workdir + '/hippo/virtex440-ml507.dtb',
+        self.vm.add_args('-kernel', self.scratch_file('hippo', 'hippo.linux'),
+                         '-dtb', self.scratch_file('hippo',
+                                                   'virtex440-ml507.dtb'),
                          '-m', '512')
         self.vm.launch()
         wait_for_console_pattern(self, 'QEMU advent calendar 2020',
tests/functional/test_rx_gdbsim.py +1 -3
index 7461be0b46..b7d5d7d062 100755
@@ -10,8 +10,6 @@
 # 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 os
-
 from qemu_test import (QemuSystemTest, Asset,
                        exec_command_and_wait_for_pattern,
                        wait_for_console_pattern, skipFlakyTest)
@@ -40,7 +38,7 @@ def test_uboot(self):
         self.set_machine('gdbsim-r5f562n8')
 
         uboot_path_gz = self.ASSET_UBOOT.fetch()
-        uboot_path = os.path.join(self.workdir, 'u-boot.bin')
+        uboot_path = self.scratch_file('u-boot.bin')
         gzip_uncompress(uboot_path_gz, uboot_path)
 
         self.vm.set_console()
tests/functional/test_s390x_ccw_virtio.py +1 -1
index c9d4730856..e70fffa290 100755
@@ -175,7 +175,7 @@ def test_s390x_fedora(self):
         kernel_path = self.ASSET_F31_KERNEL.fetch()
 
         initrd_path_xz = self.ASSET_F31_INITRD.fetch()
-        initrd_path = os.path.join(self.workdir, 'initrd-raw.img')
+        initrd_path = self.scratch_file('initrd-raw.img')
         lzma_uncompress(initrd_path_xz, initrd_path)
 
         self.vm.set_console()
tests/functional/test_s390x_topology.py +1 -3
index 6bf64f09fe..64276e4f7e 100755
@@ -10,8 +10,6 @@
 # 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 os
-
 from qemu_test import (QemuSystemTest, Asset, exec_command,
                        exec_command_and_wait_for_pattern,
                        wait_for_console_pattern)
@@ -88,7 +86,7 @@ def kernel_init(self):
         self.require_accelerator("kvm")
         kernel_path = self.ASSET_F35_KERNEL.fetch()
         initrd_path_xz = self.ASSET_F35_INITRD.fetch()
-        initrd_path = os.path.join(self.workdir, 'initrd-raw.img')
+        initrd_path = self.scratch_file('initrd-raw.img')
         lzma_uncompress(initrd_path_xz, initrd_path)
 
         self.vm.set_console()
tests/functional/test_sh4_r2d.py +2 -1
index e2fcde2d6b..dca4601392 100755
@@ -22,7 +22,8 @@ def test_r2d(self):
         file_path = self.ASSET_DAY09.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.add_args('-append', 'console=ttySC1')
-        self.launch_kernel(self.workdir + '/day09/zImage', console_index=1,
+        self.launch_kernel(self.scratch_file('day09', 'zImage'),
+                           console_index=1,
                            wait_for='QEMU advent calendar')
 
 if __name__ == '__main__':
tests/functional/test_sh4eb_r2d.py +3 -4
index 66daf8add4..dd2500dc33 100755
@@ -4,7 +4,6 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
 import shutil
 
 from qemu_test import (LinuxKernelTest, Asset,
@@ -22,11 +21,11 @@ def test_sh4eb_r2d(self):
         file_path = self.ASSET_TGZ.fetch()
         archive_extract(file_path, self.workdir)
         self.vm.add_args('-append', 'console=ttySC1 noiotrap')
-        self.launch_kernel(os.path.join(self.workdir, 'sh4eb/linux-kernel'),
-                           initrd=os.path.join(self.workdir, 'sh4eb/initramfs.cpio.gz'),
+        self.launch_kernel(self.scratch_file('sh4eb', 'linux-kernel'),
+                           initrd=self.scratch_file('sh4eb', 'initramfs.cpio.gz'),
                            console_index=1, wait_for='Type exit when done')
         exec_command_and_wait_for_pattern(self, 'exit', 'Restarting system')
-        shutil.rmtree(os.path.join(self.workdir, 'sh4eb'))
+        shutil.rmtree(self.scratch_file('sh4eb'))
 
 if __name__ == '__main__':
     LinuxKernelTest.main()
tests/functional/test_sparc64_sun4u.py +2 -3
index 798d6c3fb5..43617f1aaf 100755
@@ -10,11 +10,10 @@
 # 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 os
-
 from qemu_test import QemuSystemTest, Asset, wait_for_console_pattern
 from qemu_test.utils import archive_extract
 
+
 class Sun4uMachine(QemuSystemTest):
     """Boots the Linux kernel and checks that the console is operational"""
 
@@ -31,7 +30,7 @@ def test_sparc64_sun4u(self):
         kernel_name = 'day23/vmlinux'
         archive_extract(file_path, self.workdir, kernel_name)
         self.vm.set_console()
-        self.vm.add_args('-kernel', os.path.join(self.workdir, kernel_name),
+        self.vm.add_args('-kernel', self.scratch_file(kernel_name),
                          '-append', 'printk.time=0')
         self.vm.launch()
         wait_for_console_pattern(self, 'Starting logging: OK')
tests/functional/test_sparc_sun4m.py +1 -1
index 573f85222a..619c03d36a 100755
@@ -18,7 +18,7 @@ def test_sparc_ss20(self):
         self.set_machine('SS-20')
         file_path = self.ASSET_DAY11.fetch()
         archive_extract(file_path, self.workdir)
-        self.launch_kernel(self.workdir + '/day11/zImage.elf',
+        self.launch_kernel(self.scratch_file('day11', 'zImage.elf'),
                            wait_for='QEMU advent calendar')
 
 if __name__ == '__main__':
tests/functional/test_xtensa_lx60.py +2 -1
index d4ad92dc6c..5048e4c69e 100755
@@ -19,7 +19,8 @@ def test_xtensa_lx60(self):
         self.cpu = 'dc233c'
         file_path = self.ASSET_DAY02.fetch()
         archive_extract(file_path, self.workdir)
-        self.launch_kernel(self.workdir + '/day02/santas-sleigh-ride.elf',
+        self.launch_kernel(self.scratch_file('day02',
+                                             'santas-sleigh-ride.elf'),
                            wait_for='QEMU advent calendar')
 
 if __name__ == '__main__':
Signature · 1 line
2.46.0
#44 lore raw

PATCH 15/22 tests/functional: add common zip_extract helper

In reply to Daniel P. Berrangé

This mirrors the existing archive_extract and cpio_extract helpers

---
 tests/functional/qemu_test/utils.py | 7 +++++++
 1 file changed, 7 insertions(+)
tests/functional/qemu_test/utils.py +7 -0
index 1bf1c410d5..41bd1df666 100644
@@ -46,6 +46,13 @@ def archive_extract(archive, dest_dir, member=None):
         else:
             tf.extractall(path=dest_dir)
 
+def zip_extract(archive, dest_dir, member=None):
+    with zipfile.ZipFile(archive, 'r') as zf:
+        if member:
+            zf.extract(member=member, path=dest_dir)
+        else:
+            zf.extractall(path=dest_dir)
+
 def gzip_uncompress(gz_path, output_path):
     if os.path.exists(output_path):
         return
Signature · 1 line
2.46.0
#23 lore raw

PATCH 8/22 tests/functional: add helpers for building file paths

In reply to Daniel P. Berrangé

Add helper methods that construct paths for

* log files - to be preserved at the end of a test
* scratch files - to be purged at the end of a test
* build files - anything relative to the build root
* data files - anything relative to the functional test source root
* socket files - a short temporary dir to avoid UNIX socket limits

These are to be used instead of direct access to the self.workdir, or self.logdir variables, or any other place where paths are built manually.

---
 tests/functional/qemu_test/testcase.py | 86 ++++++++++++++++++++++++++
 1 file changed, 86 insertions(+)
tests/functional/qemu_test/testcase.py +86 -0
index 90ae59eb54..fb62052817 100644
@@ -13,10 +13,12 @@
 
 import logging
 import os
+from pathlib import Path
 import pycotap
 import shutil
 import subprocess
 import sys
+import tempfile
 import unittest
 import uuid
 
@@ -37,9 +39,93 @@ class QemuBaseTest(unittest.TestCase):
     log = None
     logdir = None
 
+    def socket_dir(self):
+        if self.socketdir is None:
+            self.socketdir = tempfile.TemporaryDirectory(
+                prefix="qemu_func_test_sock_")
+        return self.socketdir
+
+    '''
+    @params args list of zero or more subdirectories or file
+
+    Construct a path for accessing a data file located
+    relative to the source directory that is the root for
+    functional tests.
+
+    @args may be an empty list to reference the root dir
+    itself, may be a single element to reference a file in
+    the root directory, or may be multiple elements to
+    reference a file nested below. The path components
+    will be joined using the platform appropriate path
+    separator.
+
+    Returns: a qualified path
+    '''
+    def data_file(self, *args):
+        return str(Path(Path(__file__).parent.parent, *args))
+
+    '''
+    @params args list of zero or more subdirectories or file
+
+    Construct a path for accessing a data file located
+    relative to the build directory root.
+
+    @args may be an empty list to reference the build dir
+    itself, may be a single element to reference a file in
+    the build directory, or may be multiple elements to
+    reference a file nested below. The path components
+    will be joined using the platform appropriate path
+    separator.
+
+    Returns: a qualified path
+    '''
+    def build_file(self, *args):
+        return str(Path(BUILD_DIR, *args))
+
+    '''
+    @params args list of zero or more subdirectories or file
+
+    Construct a path for accessing/creating a scratch file
+    located relative to a temporary directory dedicated to
+    this test case. The directory and its contents will be
+    purged upon completion of the test.
+
+    @args may be an empty list to reference the scratch dir
+    itself, may be a single element to reference a file in
+    the scratch directory, or may be multiple elements to
+    reference a file nested below. The path components
+    will be joined using the platform appropriate path
+    separator.
+
+    Returns: a qualified path
+    '''
+    def scratch_file(self, *args):
+        return str(Path(self.workdir, *args))
+
+    '''
+    @params args list of zero or more subdirectories or file
+
+    Construct a path for accessing/creating a log file
+    located relative to a temporary directory dedicated to
+    this test case. The directory and its log files will be
+    preserved upon completion of the test.
+
+    @args may be an empty list to reference the log dir
+    itself, may be a single element to reference a file in
+    the log directory, or may be multiple elements to
+    reference a file nested below. The path components
+    will be joined using the platform appropriate path
+    separator.
+
+    Returns: a pathlib.Path object
+    '''
+    def log_file(self, *args):
+        return str(Path(self.logdir, *args))
+
     def setUp(self, bin_prefix):
         self.assertIsNotNone(self.qemu_bin, 'QEMU_TEST_QEMU_BINARY must be set')
         self.arch = self.qemu_bin.split('-')[-1]
+        self.socketdir = None
 
         self.outputdir = os.path.join(BUILD_DIR, 'tests', 'functional',
                                       self.arch, self.id())
Signature · 1 line
2.46.0
#62 lore raw

PATCH 22/22 tests/functional: convert tests to new uncompress helper

In reply to Daniel P. Berrangé

Replace use of lzma_uncompress and gzip_uncompress with the new uncompress helper.

---
 tests/functional/qemu_test/testcase.py    |  2 +-
 tests/functional/test_aarch64_raspi4.py   |  5 +----
 tests/functional/test_aarch64_sbsaref.py  |  9 ++-------
 tests/functional/test_alpha_clipper.py    |  4 +---
 tests/functional/test_arm_bpim2u.py       | 15 ++++-----------
 tests/functional/test_arm_orangepi.py     | 19 +++++--------------
 tests/functional/test_arm_raspi2.py       |  5 +----
 tests/functional/test_mips64el_malta.py   |  9 ++-------
 tests/functional/test_mips_malta.py       |  5 +----
 tests/functional/test_mipsel_malta.py     | 15 +++++----------
 tests/functional/test_rx_gdbsim.py        |  5 +----
 tests/functional/test_s390x_ccw_virtio.py |  6 ++----
 tests/functional/test_s390x_topology.py   |  5 +----
 13 files changed, 27 insertions(+), 77 deletions(-)
tests/functional/qemu_test/testcase.py +1 -1
index 5c088a2442..b91a72cda0 100644
@@ -53,7 +53,7 @@ def uncompress(self, input_path, format=None):
         (name, ext) = os.path.splitext(input_path)
         output_path = self.scratch_file(os.path.basename(name))
 
-        utils_uncompress(input_path, output_path)
+        utils_uncompress(input_path, output_path, format)
 
         return output_path
 
tests/functional/test_aarch64_raspi4.py +1 -4
index 4f95a3a61a..8eca1c5fee 100755
@@ -7,7 +7,6 @@
 
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern)
-from qemu_test.utils import gzip_uncompress
 
 
 class Aarch64Raspi4Machine(LinuxKernelTest):
@@ -63,9 +62,7 @@ def test_arm_raspi4_initrd(self):
                                            member='/boot/kernel8.img')
         dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215,
                                         member='/boot/bcm2711-rpi-4-b.dtb')
-        initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = self.scratch_file('rootfs.cpio')
-        gzip_uncompress(initrd_path_gz, initrd_path)
+        initrd_path = self.uncompress(self.ASSET_INITRD)
 
         self.set_machine('raspi4b')
         self.vm.set_console()
tests/functional/test_aarch64_sbsaref.py +2 -7
index 4c173a0303..38de5f5ba9 100755
@@ -10,7 +10,6 @@
 
 from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
                        interrupt_interactive_console_until_pattern)
-from qemu_test.utils import lzma_uncompress
 
 
 def fetch_firmware(test):
@@ -29,14 +28,10 @@ def fetch_firmware(test):
     """
 
     # Secure BootRom (TF-A code)
-    fs0_xz_path = Aarch64SbsarefMachine.ASSET_FLASH0.fetch()
-    fs0_path = test.scratch_file("SBSA_FLASH0.fd")
-    lzma_uncompress(fs0_xz_path, fs0_path)
+    fs0_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH0)
 
     # Non-secure rom (UEFI and EFI variables)
-    fs1_xz_path = Aarch64SbsarefMachine.ASSET_FLASH1.fetch()
-    fs1_path = test.scratch_file("SBSA_FLASH1.fd")
-    lzma_uncompress(fs1_xz_path, fs1_path)
+    fs1_path = test.uncompress(Aarch64SbsarefMachine.ASSET_FLASH1)
 
     for path in [fs0_path, fs1_path]:
         with open(path, "ab+") as fd:
tests/functional/test_alpha_clipper.py +1 -3
index 72cd7b57e6..c5d7181953 100755
@@ -6,7 +6,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 
 from qemu_test import LinuxKernelTest, Asset
-from qemu_test.utils import gzip_uncompress
 
 
 class AlphaClipperTest(LinuxKernelTest):
@@ -20,8 +19,7 @@ def test_alpha_clipper(self):
         self.set_machine('clipper')
         kernel_path = self.ASSET_KERNEL.fetch()
 
-        uncompressed_kernel = self.scratch_file('vmlinux')
-        gzip_uncompress(kernel_path, uncompressed_kernel)
+        uncompressed_kernel = self.uncompress(self.ASSET_KERNEL, format="gz")
 
         self.vm.set_console()
         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
tests/functional/test_arm_bpim2u.py +4 -11
index fd30984e6b..50ecf7babb 100755
@@ -10,8 +10,7 @@
 from qemu_test import (LinuxKernelTest, exec_command_and_wait_for_pattern,
                        Asset, interrupt_interactive_console_until_pattern,
                        skipBigDataTest)
-from qemu_test.utils import (gzip_uncompress, lzma_uncompress,
-                             image_pow2ceil_expand)
+from qemu_test.utils import (image_pow2ceil_expand)
 
 
 class BananaPiMachine(LinuxKernelTest):
@@ -65,9 +64,7 @@ def test_arm_bpim2u_initrd(self):
         dtb_path = ('/usr/lib/linux-image-6.6.16-current-sunxi/'
                     'sun8i-r40-bananapi-m2-ultra.dtb')
         dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
-        initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = self.scratch_file('rootfs.cpio')
-        gzip_uncompress(initrd_path_gz, initrd_path)
+        initrd_path = self.uncompress(self.ASSET_INITRD)
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
@@ -103,9 +100,7 @@ def test_arm_bpim2u_gmac(self):
         dtb_path = ('/usr/lib/linux-image-6.6.16-current-sunxi/'
                     'sun8i-r40-bananapi-m2-ultra.dtb')
         dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
-        rootfs_path_xz = self.ASSET_ROOTFS.fetch()
-        rootfs_path = self.scratch_file('rootfs.cpio')
-        lzma_uncompress(rootfs_path_xz, rootfs_path)
+        rootfs_path = self.uncompress(self.ASSET_ROOTFS)
         image_pow2ceil_expand(rootfs_path)
 
         self.vm.set_console()
@@ -147,9 +142,7 @@ def test_arm_bpim2u_openwrt_22_03_3(self):
         self.set_machine('bpim2u')
         # This test download a 8.9 MiB compressed image and expand it
         # to 127 MiB.
-        image_path_gz = self.ASSET_SD_IMAGE.fetch()
-        image_path = self.scratch_file('sdcard.img')
-        gzip_uncompress(image_path_gz, image_path)
+        image_path = self.uncompress(self.ASSET_SD_IMAGE)
         image_pow2ceil_expand(image_path)
 
         self.vm.set_console()
tests/functional/test_arm_orangepi.py +5 -14
index ff3b62e686..9c3aad4dbc 100755
@@ -11,8 +11,7 @@
 from qemu_test import (LinuxKernelTest, exec_command_and_wait_for_pattern,
                        Asset, interrupt_interactive_console_until_pattern,
                        wait_for_console_pattern, skipBigDataTest)
-from qemu_test.utils import (gzip_uncompress, lzma_uncompress,
-                             image_pow2ceil_expand)
+from qemu_test.utils import image_pow2ceil_expand
 
 
 class BananaPiMachine(LinuxKernelTest):
@@ -74,9 +73,7 @@ def test_arm_orangepi_initrd(self):
             self.ASSET_DEB, member='/boot/vmlinuz-6.6.16-current-sunxi')
         dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun8i-h3-orangepi-pc.dtb'
         dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
-        initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = self.scratch_file('rootfs.cpio')
-        gzip_uncompress(initrd_path_gz, initrd_path)
+        initrd_path = self.uncompress(self.ASSET_INITRD)
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
@@ -109,9 +106,7 @@ def test_arm_orangepi_sd(self):
             self.ASSET_DEB, member='/boot/vmlinuz-6.6.16-current-sunxi')
         dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun8i-h3-orangepi-pc.dtb'
         dtb_path = self.archive_extract(self.ASSET_DEB, member=dtb_path)
-        rootfs_path_xz = self.ASSET_ROOTFS.fetch()
-        rootfs_path = self.scratch_file('rootfs.cpio')
-        lzma_uncompress(rootfs_path_xz, rootfs_path)
+        rootfs_path = self.uncompress(self.ASSET_ROOTFS)
         image_pow2ceil_expand(rootfs_path)
 
         self.vm.set_console()
@@ -152,9 +147,7 @@ def test_arm_orangepi_armbian(self):
         # This test download a 275 MiB compressed image and expand it
         # to 1036 MiB, but the underlying filesystem is 1552 MiB...
         # As we expand it to 2 GiB we are safe.
-        image_path_xz = self.ASSET_ARMBIAN.fetch()
-        image_path = self.scratch_file('armbian.img')
-        lzma_uncompress(image_path_xz, image_path)
+        iamge_path = self.uncompress(self.ASSET_ARMBIAN)
         image_pow2ceil_expand(image_path)
 
         self.vm.set_console()
@@ -192,9 +185,7 @@ def test_arm_orangepi_uboot_netbsd9(self):
         # before to boot NetBSD.
         uboot_path = '/usr/lib/u-boot/orangepi_plus/u-boot-sunxi-with-spl.bin'
         uboot_path = self.archive_extract(self.ASSET_UBOOT, member=uboot_path)
-        image_path_gz = self.ASSET_NETBSD.fetch()
-        image_path = self.scratch_file('armv7.img')
-        gzip_uncompress(image_path_gz, image_path)
+        image_path = self.uncompress(self.ASSET_NETBSD)
         image_pow2ceil_expand(image_path)
         image_drive_args = 'if=sd,format=raw,snapshot=on,file=' + image_path
 
tests/functional/test_arm_raspi2.py +1 -4
index 8724eee010..8c001568f8 100755
@@ -9,7 +9,6 @@
 
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern)
-from qemu_test.utils import gzip_uncompress
 
 
 class ArmRaspi2Machine(LinuxKernelTest):
@@ -64,9 +63,7 @@ def test_arm_raspi2_initrd(self):
                                            member='/boot/kernel7.img')
         dtb_path = self.archive_extract(self.ASSET_KERNEL_20190215,
                                         member='/boot/bcm2709-rpi-2-b.dtb')
-        initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = self.scratch_file('rootfs.cpio')
-        gzip_uncompress(initrd_path_gz, initrd_path)
+        initrd_path = self.uncompress(self.ASSET_INITRD)
 
         self.set_machine('raspi2b')
         self.vm.set_console()
tests/functional/test_mips64el_malta.py +2 -7
index d4b3c1eeab..7f7da37c0f 100755
@@ -15,7 +15,6 @@
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern,
                        skipIfMissingImports, skipFlakyTest, skipUntrustedTest)
-from qemu_test.utils import gzip_uncompress
 
 
 class MaltaMachineConsole(LinuxKernelTest):
@@ -67,9 +66,7 @@ def test_mips64el_malta(self):
     @skipUntrustedTest()
     def test_mips64el_malta_5KEc_cpio(self):
         kernel_path = self.ASSET_KERNEL_3_19_3.fetch()
-        initrd_path_gz = self.ASSET_CPIO_R1.fetch()
-        initrd_path = self.scratch_file('rootfs.cpio')
-        gzip_uncompress(initrd_path_gz, initrd_path)
+        initrd_path = self.uncompress(self.ASSET_CPIO_R1)
 
         self.set_machine('malta')
         self.vm.set_console()
@@ -119,9 +116,7 @@ def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
 
         screendump_path = self.scratch_file('screendump.pbm')
 
-        kernel_path_gz = self.ASSET_KERNEL_4_7_0.fetch()
-        kernel_path = self.scratch_file("vmlinux")
-        gzip_uncompress(kernel_path_gz, kernel_path)
+        kernel_path = self.uncompress(self.ASSET_KERNEL_4_7_0)
 
         tuxlogo_path = self.ASSET_TUXLOGO.fetch()
 
tests/functional/test_mips_malta.py +1 -4
index 65300b7ddf..3695a9e6a6 100755
@@ -8,7 +8,6 @@
 
 from qemu_test import LinuxKernelTest, Asset
 from qemu_test import exec_command_and_wait_for_pattern
-from qemu_test.utils import gzip_uncompress
 
 
 class MaltaMachineConsole(LinuxKernelTest):
@@ -49,9 +48,7 @@ def test_mips_malta_cpio(self):
         kernel_path = self.archive_extract(
             self.ASSET_KERNEL_4_5_0,
             member='/boot/vmlinux-4.5.0-2-4kc-malta')
-        initrd_path_gz = self.ASSET_INITRD.fetch()
-        initrd_path = self.scratch_file('rootfs.cpio')
-        gzip_uncompress(initrd_path_gz, initrd_path)
+        initrd_path = self.uncompress(self.ASSET_INITRD)
 
         self.set_machine('malta')
         self.vm.set_console()
tests/functional/test_mipsel_malta.py +5 -10
index 90747ba2d0..aed41ac9b9 100755
@@ -14,7 +14,6 @@
 from qemu_test import (QemuSystemTest, LinuxKernelTest, Asset,
                        interrupt_interactive_console_until_pattern,
                        wait_for_console_pattern)
-from qemu_test.utils import lzma_uncompress
 
 
 class MaltaMachineConsole(LinuxKernelTest):
@@ -35,9 +34,8 @@ class MaltaMachineConsole(LinuxKernelTest):
          'generic_nano32r6el_page64k_dbg.xz'),
         'ce21ff4b07a981ecb8a39db2876616f5a2473eb2ab459c6f67465b9914b0c6b6')
 
-    def do_test_mips_malta32el_nanomips(self, kernel_path_xz):
-        kernel_path = self.scratch_file('kernel')
-        lzma_uncompress(kernel_path_xz, kernel_path)
+    def do_test_mips_malta32el_nanomips(self, kernel):
+        kernel_path = self.uncompress(kernel)
 
         self.set_machine('malta')
         self.vm.set_console()
@@ -53,16 +51,13 @@ def do_test_mips_malta32el_nanomips(self, kernel_path_xz):
         self.wait_for_console_pattern(console_pattern)
 
     def test_mips_malta32el_nanomips_4k(self):
-        kernel_path_xz = self.ASSET_KERNEL_4K.fetch()
-        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
+        self.do_test_mips_malta32el_nanomips(self.ASSET_KERNEL_4K)
 
     def test_mips_malta32el_nanomips_16k_up(self):
-        kernel_path_xz = self.ASSET_KERNEL_16K.fetch()
-        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
+        self.do_test_mips_malta32el_nanomips(self.ASSET_KERNEL_16K)
 
     def test_mips_malta32el_nanomips_64k_dbg(self):
-        kernel_path_xz = self.ASSET_KERNEL_16K.fetch()
-        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
+        self.do_test_mips_malta32el_nanomips(self.ASSET_KERNEL_64K)
 
 
 class MaltaMachineYAMON(QemuSystemTest):
tests/functional/test_rx_gdbsim.py +1 -4
index b7d5d7d062..d0238a0fd5 100755
@@ -13,7 +13,6 @@
 from qemu_test import (QemuSystemTest, Asset,
                        exec_command_and_wait_for_pattern,
                        wait_for_console_pattern, skipFlakyTest)
-from qemu_test.utils import gzip_uncompress
 
 
 class RxGdbSimMachine(QemuSystemTest):
@@ -37,9 +36,7 @@ def test_uboot(self):
         """
         self.set_machine('gdbsim-r5f562n8')
 
-        uboot_path_gz = self.ASSET_UBOOT.fetch()
-        uboot_path = self.scratch_file('u-boot.bin')
-        gzip_uncompress(uboot_path_gz, uboot_path)
+        uboot_path = self.uncompress(self.ASSET_UBOOT)
 
         self.vm.set_console()
         self.vm.add_args('-bios', uboot_path,
tests/functional/test_s390x_ccw_virtio.py +2 -4
index e70fffa290..c24747d4a8 100755
@@ -17,7 +17,7 @@
 from qemu_test import (QemuSystemTest, Asset,
                        exec_command_and_wait_for_pattern,
                        wait_for_console_pattern)
-from qemu_test.utils import lzma_uncompress
+
 
 class S390CCWVirtioMachine(QemuSystemTest):
     KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -174,9 +174,7 @@ def test_s390x_fedora(self):
 
         kernel_path = self.ASSET_F31_KERNEL.fetch()
 
-        initrd_path_xz = self.ASSET_F31_INITRD.fetch()
-        initrd_path = self.scratch_file('initrd-raw.img')
-        lzma_uncompress(initrd_path_xz, initrd_path)
+        initrd_path = self.uncompress(self.ASSET_F31_INITRD, format="xz")
 
         self.vm.set_console()
         kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + ' audit=0 '
tests/functional/test_s390x_topology.py +1 -4
index 64276e4f7e..aa6ddb8601 100755
@@ -13,7 +13,6 @@
 from qemu_test import (QemuSystemTest, Asset, exec_command,
                        exec_command_and_wait_for_pattern,
                        wait_for_console_pattern)
-from qemu_test.utils import lzma_uncompress
 
 
 class S390CPUTopology(QemuSystemTest):
@@ -85,9 +84,7 @@ def kernel_init(self):
         """
         self.require_accelerator("kvm")
         kernel_path = self.ASSET_F35_KERNEL.fetch()
-        initrd_path_xz = self.ASSET_F35_INITRD.fetch()
-        initrd_path = self.scratch_file('initrd-raw.img')
-        lzma_uncompress(initrd_path_xz, initrd_path)
+        initrd_path = self.uncompress(self.ASSET_F35_INITRD, format="xz")
 
         self.vm.set_console()
         kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE
Signature · 1 line
2.46.0
#53 lore raw

PATCH 18/22 tests/functional: add 'archive_extract' to QemuBaseTest

In reply to Daniel P. Berrangé

This helper wrappers utils.archive_extract, forcing the use of the scratch directory, to ensure any extracted files are cleaned at test termination. If a specific member is requested, then the path to the extracted file is also returned.

---
 tests/functional/qemu_test/testcase.py | 36 ++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tests/functional/qemu_test/testcase.py +36 -0
index 2f32742387..31d06f0172 100644
@@ -28,6 +28,8 @@
 from .asset import Asset
 from .cmd import run_cmd
 from .config import BUILD_DIR
+from .utils import (archive_extract as utils_archive_extract,
+                    guess_archive_format)
 
 
 class QemuBaseTest(unittest.TestCase):
@@ -39,6 +41,40 @@ class QemuBaseTest(unittest.TestCase):
     log = None
     logdir = None
 
+    '''
+    @params archive: filename, Asset, or file-like object to extract
+    @params sub_dir: optional sub-directory to extract into
+    @params member: optional member file to limit extraction to
+
+    Extracts @archive into the scratch directory, or a
+    directory beneath named by @sub_dir. All files are
+    extracted unless @member specifies a limit.
+
+    If @member is non-None, returns the fully qualified
+    path to @member
+    '''
+    def archive_extract(self, archive, format=None, sub_dir=None, member=None):
+        if type(archive) == Asset:
+            if format is None:
+                format = guess_archive_format(archive.url)
+            archive = archive.fetch()
+        elif format is None:
+            format = guess_archive_format(archive)
+
+        if member is not None:
+            if os.path.isabs(member):
+                member = os.path.relpath(member, '/')
+
+        if sub_dir is None:
+            utils_archive_extract(archive, self.scratch_file(), format, member)
+        else:
+            utils_archive_extract(archive, self.scratch_file(sub_dir),
+                                  format, member)
+
+        if member is not None:
+            return self.scratch_file(member)
+        return None
+
     def socket_dir(self):
         if self.socketdir is None:
             self.socketdir = tempfile.TemporaryDirectory(
Signature · 1 line
2.46.0
#17 lore raw

PATCH 6/22 tests/functional: introduce some helpful decorators

In reply to Daniel P. Berrangé

Reduce repeated boilerplate with some helper decorators:

@skipIfNotPlatform("x86_64", "aarch64")

=> Skip unless the build host platform matches

@skipIfMissingCommands("mkisofs", "losetup")

=> Skips unless all listed commands are found in $PATH

@skipIfMissingImports("numpy", "cv2")

=> Skips unless all listed modules can be imported

@skipFlakyTest("https://gitlab.com/qemu-project/qemu/-/issues/NNN")

=> Skips unless env var requests flaky tests with the
reason documented in the referenced gitlab bug

@skipBigData

=> Skips unless env var permits tests creating big data files

@skipUntrustedTest

=> Skips unless env var permits tests which are potentially
dangerous to the host

---
 tests/functional/qemu_test/__init__.py   |   3 +
 tests/functional/qemu_test/decorators.py | 105 +++++++++++++++++++++++
 2 files changed, 108 insertions(+)
 create mode 100644 tests/functional/qemu_test/decorators.py
tests/functional/qemu_test/__init__.py +3 -0
index 8fddddbe67..7dee3522f2 100644
@@ -13,3 +13,6 @@
     exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
 from .testcase import QemuBaseTest, QemuUserTest, QemuSystemTest
 from .linuxkernel import LinuxKernelTest
+from .decorators import skipIfMissingCommands, skipIfNotMachine, \
+    skipFlakyTest, skipUntrustedTest, skipBigDataTest, \
+    skipIfMissingImports
tests/functional/qemu_test/decorators.py new file +105 -0

105 lines not on this page · raw message

Signature · 1 line
2.46.0
#61 lore raw

PATCH 21/22 tests/functional: add 'uncompress' to QemuBaseTest

In reply to Daniel P. Berrangé

This helper wrappers utils.uncompress, forcing the use of the scratch directory, to ensure any uncompressed files are cleaned at test termination.

---
 tests/functional/qemu_test/testcase.py | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
tests/functional/qemu_test/testcase.py +17 -1
index 31d06f0172..5c088a2442 100644
@@ -29,7 +29,8 @@
 from .cmd import run_cmd
 from .config import BUILD_DIR
 from .utils import (archive_extract as utils_archive_extract,
-                    guess_archive_format)
+                    uncompress as utils_uncompress,
+                    guess_archive_format, guess_uncompress_format)
 
 
 class QemuBaseTest(unittest.TestCase):
@@ -41,6 +42,21 @@ class QemuBaseTest(unittest.TestCase):
     log = None
     logdir = None
 
+    def uncompress(self, input_path, format=None):
+        if type(input_path) == Asset:
+            if format is None:
+                format = guess_uncompress_format(input_path.url)
+            input_path = input_path.fetch()
+        elif format is None:
+            format = guess_uncompress_format(input_path)
+
+        (name, ext) = os.path.splitext(input_path)
+        output_path = self.scratch_file(os.path.basename(name))
+
+        utils_uncompress(input_path, output_path)
+
+        return output_path
+
     '''
     @params archive: filename, Asset, or file-like object to extract
     @params sub_dir: optional sub-directory to extract into
Signature · 1 line
2.46.0
#11 lore raw

PATCH 5/22 tests/functional: remove duplicated 'which' function impl

In reply to Daniel P. Berrangé

Put the 'which' function into shared code.

---
 tests/functional/qemu_test/__init__.py |  2 +-
 tests/functional/qemu_test/cmd.py      | 10 ++++++++++
 tests/functional/test_acpi_bits.py     | 13 +------------
 tests/functional/test_ppc64_hv.py      | 13 +------------
 4 files changed, 13 insertions(+), 25 deletions(-)
tests/functional/qemu_test/__init__.py +1 -1
index 67f87be9c4..8fddddbe67 100644
@@ -10,6 +10,6 @@
 from .config import BUILD_DIR
 from .cmd import has_cmd, has_cmds, run_cmd, is_readable_executable_file, \
     interrupt_interactive_console_until_pattern, wait_for_console_pattern, \
-    exec_command, exec_command_and_wait_for_pattern, get_qemu_img
+    exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
 from .testcase import QemuBaseTest, QemuUserTest, QemuSystemTest
 from .linuxkernel import LinuxKernelTest
tests/functional/qemu_test/cmd.py +10 -0
index 11c8334a7c..4106f1ee7c 100644
@@ -18,6 +18,16 @@
 
 from .config import BUILD_DIR
 
+def which(tool):
+    """ looks up the full path for @tool, returns None if not found
+        or if @tool does not have executable permissions.
+    """
+    paths=os.getenv('PATH')
+    for p in paths.split(os.path.pathsep):
+        p = os.path.join(p, tool)
+        if os.path.exists(p) and os.access(p, os.X_OK):
+            return p
+    return None
 
 def has_cmd(name, args=None):
     """
tests/functional/test_acpi_bits.py +1 -12
index 6fc49a30bc..4162faf414 100755
@@ -49,7 +49,7 @@
 )
 from qemu.machine import QEMUMachine
 from unittest import skipIf
-from qemu_test import QemuBaseTest, Asset
+from qemu_test import QemuBaseTest, Asset, which
 
 deps = ["xorriso", "mformat"] # dependent tools needed in the test setup/box.
 supported_platforms = ['x86_64'] # supported test platforms.
@@ -57,17 +57,6 @@
 # default timeout of 120 secs is sometimes not enough for bits test.
 BITS_TIMEOUT = 200
 
-def which(tool):
-    """ looks up the full path for @tool, returns None if not found
-        or if @tool does not have executable permissions.
-    """
-    paths=os.getenv('PATH')
-    for p in paths.split(os.path.pathsep):
-        p = os.path.join(p, tool)
-        if os.path.exists(p) and os.access(p, os.X_OK):
-            return p
-    return None
-
 def missing_deps():
     """ returns True if any of the test dependent tools are absent.
     """
tests/functional/test_ppc64_hv.py +1 -12
index 53bae90401..cc77cd22b1 100755
@@ -11,7 +11,7 @@
 
 from unittest import skipIf, skipUnless
 from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
-                       exec_command)
+                       exec_command, which)
 import os
 import time
 import subprocess
@@ -19,17 +19,6 @@
 
 deps = ["xorriso"] # dependent tools needed in the test setup/box.
 
-def which(tool):
-    """ looks up the full path for @tool, returns None if not found
-        or if @tool does not have executable permissions.
-    """
-    paths=os.getenv('PATH')
-    for p in paths.split(os.path.pathsep):
-        p = os.path.join(p, tool)
-        if os.path.exists(p) and os.access(p, os.X_OK):
-            return p
-    return None
-
 def missing_deps():
     """ returns True if any of the test dependent tools are absent.
     """
Signature · 1 line
2.46.0
#40 lore raw

PATCH 13/22 tests/functional: switch over to using self.socket_dir(...)

In reply to Daniel P. Berrangé

This removes direct creation of temporary dirs

---
 tests/functional/test_arm_aspeed.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
tests/functional/test_arm_aspeed.py +2 -3
index c4869011db..ca223ac8f0 100755
@@ -9,7 +9,6 @@
 import os
 import time
 import subprocess
-import tempfile
 
 from qemu_test import (LinuxKernelTest, Asset,
                        exec_command_and_wait_for_pattern,
@@ -228,8 +227,8 @@ def test_arm_ast2600_evb_buildroot_tpm(self):
 
         tpmstate_dir = self.scratch_file('swtpmstate')
         os.mkdir(tpmstate_dir)
-        socket_dir = tempfile.TemporaryDirectory(prefix="qemu_")
-        socket = os.path.join(tpmstate_dir.name, 'swtpm-socket')
+        socket_dir = self.socket_dir()
+        socket = os.path.join(socket_dir.name, 'swtpm-socket')
 
         # We must put the TPM state dir in /tmp/, not the build dir,
         # because some distros use AppArmor to lock down swtpm and
Signature · 1 line
2.46.0
Reviewed-by on v1 1/22
#2 lore raw

Re: [PATCH 01/22] tests/functional: increase timeouts for arm sx1 test

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

When under high load the test VM does not complete running in the default 30 second timeout. Double it to give more headroom.

---
  tests/functional/test_arm_sx1.py | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
tests/functional/test_arm_sx1.py +2 -2
index 2d86405831..2292317946 100755
@@ -44,7 +44,7 @@ def test_arm_sx1_initrd(self):
          self.vm.add_args('-no-reboot')
          self.launch_kernel(zimage_path,
                             initrd=initrd_path)
-        self.vm.wait()
+        self.vm.wait(timeout=60)
 
      def test_arm_sx1_sd(self):
          self.set_machine('sx1')
@@ -55,7 +55,7 @@ def test_arm_sx1_sd(self):
          self.vm.add_args('-snapshot')
          self.vm.add_args('-drive', f'format=raw,if=sd,file={sd_fs_path}')
          self.launch_kernel(zimage_path)
-        self.vm.wait()
+        self.vm.wait(timeout=60)
 
      def test_arm_sx1_flash(self):
          self.set_machine('sx1')

tests/functional/test_arm_sx1.py def test_arm_sx1_flash(self): · line 69

Quoted 5 lines
tests/functional/test_arm_sx1.py +1 -1
@@ -66,7 +66,7 @@ def test_arm_sx1_flash(self):
          self.vm.add_args('-snapshot')
          self.vm.add_args('-drive', f'format=raw,if=pflash,file={flash_path}')
          self.launch_kernel(zimage_path)
-        self.vm.wait()
+        self.vm.wait(timeout=60)

Ah! I think I've seen this test sometimes failing, too, good to know that it was likely just this simple reason!

Reviewed-by on v1 2/22
#4 lore raw

Re: [PATCH 02/22] tests/functional: remove unused system imports

In reply to Daniel P. Berrangé
Quoted 13 lines · Daniel P. Berrangé
---
  tests/functional/test_aarch64_sbsaref.py       | 1 -
  tests/functional/test_acpi_bits.py             | 1 -
  tests/functional/test_m68k_mcf5208evb.py       | 2 --
  tests/functional/test_microblaze_s3adsp1800.py | 1 -
  tests/functional/test_mips64el_loongson3v.py   | 1 -
  tests/functional/test_or1k_sim.py              | 2 --
  tests/functional/test_s390x_topology.py        | 1 -
  tests/functional/test_sh4_tuxrun.py            | 4 ----
  tests/functional/test_sh4eb_r2d.py             | 1 -
  tests/functional/test_virtio_version.py        | 2 --
  10 files changed, 16 deletions(-)

Out of curiosity: Is there a way to check for this with a program, or did you check it manually?

#7 lore raw

Re: [PATCH 03/22] tests/functional: remove duplicated 'qemu_test' import statements

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

Group all imports that originate in the 'qemu_test' package into one statement.

---
  tests/functional/qemu_test/tuxruntest.py         |  9 +++++----
  tests/functional/test_aarch64_raspi4.py          |  4 ++--
  tests/functional/test_aarch64_sbsaref.py         |  5 ++---
  tests/functional/test_aarch64_sbsaref_alpine.py  |  5 ++---
  tests/functional/test_aarch64_sbsaref_freebsd.py |  5 ++---
  tests/functional/test_aarch64_virt.py            |  6 ++----
  tests/functional/test_arm_aspeed.py              |  7 +++----
  tests/functional/test_arm_bflt.py                |  3 +--
  tests/functional/test_arm_bpim2u.py              |  8 ++++----
  tests/functional/test_arm_canona1100.py          |  3 +--
  tests/functional/test_arm_integratorcp.py        |  3 +--
  tests/functional/test_arm_orangepi.py            | 10 +++++-----
  tests/functional/test_arm_raspi2.py              |  4 ++--
  tests/functional/test_loongarch64_virt.py        |  6 +++---
  tests/functional/test_microblaze_s3adsp1800.py   |  5 ++---
  tests/functional/test_microblazeel_s3adsp1800.py |  5 ++---
  tests/functional/test_mips64el_fuloong2e.py      |  7 ++++---
  tests/functional/test_mips64el_loongson3v.py     |  3 +--
  tests/functional/test_mips64el_malta.py          |  4 ++--
  tests/functional/test_mipsel_malta.py            |  6 +++---
  tests/functional/test_multiprocess.py            |  4 ++--
  tests/functional/test_netdev_ethtool.py          |  3 +--
  tests/functional/test_ppc64_hv.py                |  4 ++--
  tests/functional/test_ppc64_powernv.py           |  3 +--
  tests/functional/test_ppc64_pseries.py           |  3 +--
  tests/functional/test_ppc_405.py                 |  6 +++---
  tests/functional/test_ppc_40p.py                 |  3 +--
  tests/functional/test_ppc_74xx.py                |  3 +--
  tests/functional/test_ppc_amiga.py               |  3 +--
  tests/functional/test_ppc_bamboo.py              |  6 +++---
  tests/functional/test_ppc_mpc8544ds.py           |  3 +--
  tests/functional/test_ppc_virtex_ml507.py        |  3 +--
  tests/functional/test_riscv_opensbi.py           |  4 ++--
  tests/functional/test_rx_gdbsim.py               |  6 +++---
  tests/functional/test_s390x_ccw_virtio.py        |  6 +++---
  tests/functional/test_s390x_topology.py          |  7 +++----
  tests/functional/test_sh4eb_r2d.py               |  4 ++--
  tests/functional/test_sparc64_sun4u.py           |  3 +--
  tests/functional/test_virtio_gpu.py              | 10 ++++------
  39 files changed, 85 insertions(+), 107 deletions(-)
tests/functional/qemu_test/tuxruntest.py +0 -0
index ab3b27da43..7c0456923e 100644
@@ -13,10 +13,11 @@
  import stat

tests/functional/qemu_test/tuxruntest.py line 19

Quoted 10 lines
tests/functional/qemu_test/tuxruntest.py +4 -4
  import time
 
-from qemu_test import QemuSystemTest
-from qemu_test import exec_command, exec_command_and_wait_for_pattern
-from qemu_test import wait_for_console_pattern
-from qemu_test import has_cmd, run_cmd, get_qemu_img
+from qemu_test import (QemuSystemTest, exec_command,
+                       exec_command_and_wait_for_pattern,
+                       wait_for_console_pattern,
+                       has_cmd, run_cmd, get_qemu_img)

Is there a real advantage in writing it this way? For most files, this not seem to reduce the lines of code, so at a quick glance, it rather looks like unnecessary code churn to me...?

Thomas

Reviewed-by on v1 4/22
#10 lore raw

Re: [PATCH 04/22] tests/functional: remove pointless with statement

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

The xorriso command directly writes to 'filename', so the surrounding 'with' statement is pointless.

---
  tests/functional/test_ppc64_hv.py | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
tests/functional/test_ppc64_hv.py +0 -0
index c31432d18d..53bae90401 100755
@@ -72,10 +72,9 @@ def extract_from_iso(self, iso, path):
          cwd = os.getcwd()
          os.chdir(self.workdir)
 

tests/functional/test_ppc64_hv.py def extract_from_iso(self, iso, path): · line 80

Quoted 10 lines
tests/functional/test_ppc64_hv.py +3 -4
-        with open(filename, "w") as outfile:
-            cmd = "xorriso -osirrox on -indev %s -cpx %s %s" % (iso, path, filename)
-            subprocess.run(cmd.split(),
-                           stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+        cmd = "xorriso -osirrox on -indev %s -cpx %s %s" % (iso, path, filename)
+        subprocess.run(cmd.split(),
+                       stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
 
          os.chmod(filename, 0o600)
          os.chdir(cwd)
#12 lore raw

Re: [PATCH 05/22] tests/functional: remove duplicated 'which' function impl

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

Put the 'which' function into shared code.

---
  tests/functional/qemu_test/__init__.py |  2 +-
  tests/functional/qemu_test/cmd.py      | 10 ++++++++++
  tests/functional/test_acpi_bits.py     | 13 +------------
  tests/functional/test_ppc64_hv.py      | 13 +------------
  4 files changed, 13 insertions(+), 25 deletions(-)

None of the callers really seem to be interested in the location of the command, only whether it is available in the $PATH or not ... so could we maybe rather drop this function and use the has_cmd() function everywhere instead?

Hmm, thinking about it twice - has_cmd() uses the "which" program internally, but AFAIK this program is optional in Linux installations nowadays ... so maybe it's still a good idea to move our Python which() to cmd.py, but has_cmd() should maybe rather be changed to use it, too?

Thomas

Reviewed-by on v1 14/22
#43 lore raw

Re: [PATCH 14/22] tests/functional: remove redundant 'rmtree' call

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

Everything in the scratch directory is automatically purged. Calling 'rmtree' again breaks the ability to optionally preserve the scratch directory contents.

---
  tests/functional/test_sh4eb_r2d.py | 3 ---
  1 file changed, 3 deletions(-)
tests/functional/test_sh4eb_r2d.py +0 -2
index dd2500dc33..38ee55cf4c 100755
@@ -4,8 +4,6 @@
  #
  # SPDX-License-Identifier: GPL-2.0-or-later
 
-import shutil
-
  from qemu_test import (LinuxKernelTest, Asset,
                         exec_command_and_wait_for_pattern)
  from qemu_test.utils import archive_extract

tests/functional/test_sh4eb_r2d.py def test_sh4eb_r2d(self): · line 28

Quoted 4 lines
tests/functional/test_sh4eb_r2d.py +0 -1
@@ -25,7 +23,6 @@ def test_sh4eb_r2d(self):
                             initrd=self.scratch_file('sh4eb', 'initramfs.cpio.gz'),
                             console_index=1, wait_for='Type exit when done')
          exec_command_and_wait_for_pattern(self, 'exit', 'Restarting system')
-        shutil.rmtree(self.scratch_file('sh4eb'))
Reviewed-by on v1 5/22
#15 lore raw

Re: [PATCH 05/22] tests/functional: remove duplicated 'which' function impl

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

Put the 'which' function into shared code.

---
  tests/functional/qemu_test/__init__.py |  2 +-
  tests/functional/qemu_test/cmd.py      | 10 ++++++++++
  tests/functional/test_acpi_bits.py     | 13 +------------
  tests/functional/test_ppc64_hv.py      | 13 +------------
  4 files changed, 13 insertions(+), 25 deletions(-)

As code movement,

tests/functional/qemu_test/cmd.py line 28

Quoted 8 lines
tests/functional/qemu_test/cmd.py +8 -0
+def which(tool):
+    """ looks up the full path for @tool, returns None if not found
+        or if @tool does not have executable permissions.
+    """
+    paths=os.getenv('PATH')
+    for p in paths.split(os.path.pathsep):
+        p = os.path.join(p, tool)
+        if os.path.exists(p) and os.access(p, os.X_OK):

But surely exists() is redundant with access()?

r~

#18 lore raw

Re: [PATCH 06/22] tests/functional: introduce some helpful decorators

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

Reduce repeated boilerplate with some helper decorators:

@skipIfNotPlatform("x86_64", "aarch64")

=> Skip unless the build host platform matches

@skipIfMissingCommands("mkisofs", "losetup")

=> Skips unless all listed commands are found in $PATH

@skipIfMissingImports("numpy", "cv2")

=> Skips unless all listed modules can be imported

@skipFlakyTest("https://gitlab.com/qemu-project/qemu/-/issues/NNN")

=> Skips unless env var requests flaky tests with the
reason documented in the referenced gitlab bug

Quoted 8 lines

@skipBigData

=> Skips unless env var permits tests creating big data files

@skipUntrustedTest

=> Skips unless env var permits tests which are potentially
dangerous to the host

That are good ideas! And certainly less error prone than specifying the names of the environment variables over and over again.

Quoted 33 lines
tests/functional/qemu_test/__init__.py +3 -0
index 8fddddbe67..7dee3522f2 100644
@@ -13,3 +13,6 @@
      exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
  from .testcase import QemuBaseTest, QemuUserTest, QemuSystemTest
  from .linuxkernel import LinuxKernelTest
+from .decorators import skipIfMissingCommands, skipIfNotMachine, \
+    skipFlakyTest, skipUntrustedTest, skipBigDataTest, \
+    skipIfMissingImports
tests/functional/qemu_test/decorators.py new file +16 -0
new file mode 100644
index 0000000000..d25fec7b2d
@@ -0,0 +1,105 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Decorators useful in functional tests
+
+import os
+import platform
+from unittest import skipUnless
+
+from .cmd import which
+
+'''
+Decorator to skip execution of a test if the list
+of command binaries is not available in $PATH.
+Example:
+
+  @skipIfMissingCommands("mkisofs", "losetup")

tests/functional/qemu_test/decorators.py line 26

Quoted 10 lines
tests/functional/qemu_test/decorators.py new file +10 -0
+'''
+def skipIfMissingCommands(*args):
+    def has_cmds(cmdlist):
+        for cmd in cmdlist:
+            if not which(cmd):
+                return False
+        return True
+
+    return skipUnless(lambda: has_cmds(args),
+                      'required commands(s) "%s" not installed' %

s/commands(s)/command(s)/ ?

tests/functional/qemu_test/decorators.py line 39

Quoted 13 lines
tests/functional/qemu_test/decorators.py new file +13 -0
+                      ", ".join(args))
+
+'''
+Decorator to skip execution of a test if the current
+host machine does not match one of the permitted
+machines.
+Example
+
+  @skipIfNotMachine("x86_64", "aarch64")
+'''
+def skipIfNotMachine(*args):
+    return skipUnless(lambda: platform.machine() in args,
+                        'not running on required machine(s) "%s"' %

plural sounds strange here (like all machines would be required at the same time), I'd maybe say "not running on one of the required machine(s)" ?

tests/functional/qemu_test/decorators.py line 44

Quoted 5 lines
tests/functional/qemu_test/decorators.py new file +5 -0
+                        ", ".join(args))
+
+'''
+Decorator to skip execution of flaky tests, unless
+the $QEMU_TEST_FLAKY_TESTS env var is set. A bug URL

Since it is the "official" documentation of this decorator, I'd maybe rather use the full words: "environment variable" instead of "env var"

Quoted 10 lines
tests/functional/qemu_test/decorators.py new file +10 -0
+must be provided that documents the observed failure
+behaviour, so it can be tracked & re-evaluated in future.
+
+Historical tests may be providing "None" as the bug_url
+but this should not be done for new test.
+
+Example:
+
+  @skipFlakyTest("https://gitlab.com/qemu-project/qemu/-/issues/NNN")
+'''

tests/functional/qemu_test/decorators.py line 64

Quoted 10 lines
tests/functional/qemu_test/decorators.py new file +10 -0
+def skipFlakyTest(bug_url):
+    if bug_url is None:
+        bug_url = "FIXME: reproduce flaky test and file bug report or remove"
+    return skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'),
+                      f'Test is unstable: {bug_url}')
+
+'''
+Decorator to skip execution of tests which are likely
+to execute untrusted commands on the host, or commands
+which process untrusted code, unles the

s/unles/unless/

tests/functional/qemu_test/decorators.py line 77

Quoted 13 lines
tests/functional/qemu_test/decorators.py new file +13 -0
+$QEMU_TEST_ALLOW_UNTRUSTED_CODE env var is set.
+Example:
+
+  @skipUntrustedTest()
+'''
+def skipUntrustedTest():
+    return skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'),
+                      'Test runs untrusted code / processes untrusted data')
+
+'''
+Decorator to skip execution of tests which need large
+data storage on the host, unless the
+$QEMU_TEST_ALLOW_LARGE_STORAGE env var is set

Maybe we should also provide some direction what is meant with large storage. I've seen some tests that are skipped since they create a disk file with 128 MiB. And others are always executed though they create a disk file with 512 MiB or even more. What would be a good recommendation here? (My gut feeling is maybe ~ 1 GiB? Or better less?)

tests/functional/qemu_test/decorators.py line 85

Quoted 7 lines
tests/functional/qemu_test/decorators.py new file +7 -0
+Example:
+
+  @skipBigDataTest()
+'''
+def skipBigDataTest():
+    return skipUnless(os.getenv('QEMU_TEST_ALLOW_LARGE_STORAGE'),
+                      'Test required large host storage space')

s/required/requires/ ?
(the other decorators use present tense, too)

Quoted 8 lines
tests/functional/qemu_test/decorators.py new file +8 -0
+'''
+Decorator to skip execution of a test if the list
+of python imports is not available.
+Example:
+
+  @skipIfMissingImports("numpy", "cv2")
+'''
+def skipIfMissingImports(*args):

tests/functional/qemu_test/decorators.py line 104

Quoted 10 lines
tests/functional/qemu_test/decorators.py new file +10 -0
+    def has_imports(importlist):
+        for impname in importlist:
+            try:
+                import impname
+            except ImportError:
+                return False
+        return True
+
+    return skipUnless(lambda: has_imports(args),
+                      'required imports(s) "%s" not installed' %

s/imports(s)/import(s)/ ?

tests/functional/qemu_test/decorators.py line 103

Quoted 1 line
tests/functional/qemu_test/decorators.py new file +1 -0
+                      ", ".join(args))

Thomas

Reviewed-by on v1 7/22
#21 lore raw

Re: [PATCH 07/22] tests/functional: switch to new test skip decorators

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

This ensures consistency of behaviour across all the tests, and requires that we provide gitlab bug links when marking a test to be skipped due to unreliability.

---

tests/functional/test_arm_aspeed.py +0 -0
index 068740a813..db872ff05e 100755

tests/functional/test_arm_aspeed.py line 18

Quoted 7 lines
tests/functional/test_arm_aspeed.py +3 -1
@@ -13,7 +13,9 @@
 
  from qemu_test import (LinuxKernelTest, Asset,
                         exec_command_and_wait_for_pattern,
-                       interrupt_interactive_console_until_pattern, has_cmd)
+                       interrupt_interactive_console_until_pattern,
+                       skipIfMissingCommands,
+)

In the other files, you placed the final ")" at the end of the previous line instead?

Quoted 10 lines
tests/functional/test_m68k_nextcube.py +0 -2
index 0124622c40..82d3d335d0 100755
@@ -10,16 +10,9 @@
  import os
  import time
 
-from qemu_test import QemuSystemTest, Asset
-from unittest import skipUnless

tests/functional/test_m68k_nextcube.py line 15

Quoted 10 lines
tests/functional/test_m68k_nextcube.py +2 -7
-
+from qemu_test import QemuSystemTest, Asset, skipIfMissingImports
  from qemu_test.tesseract import tesseract_available, tesseract_ocr
-
-PIL_AVAILABLE = True
-try:
-    from PIL import Image
-except ImportError:
-    PIL_AVAILABLE = False
+from unittest import skipUnless

I think you could also replace the other skipUnless() in this file nowadays: The version check here was only useful in the days when most distros still shipped Tesseract v3, but these days are gone, we don't support any of those distros anymore. So I think it should be fine to use skipIfMissingCommands here now instead.

Anyway, I'm also fine if we keep it for now (we still can adjust it later), so with at least the ")" nit fixed:

Quoted 16 lines
tests/functional/test_m68k_nextcube.py +2 -1
  class NextCubeMachine(QemuSystemTest):
@@ -43,12 +36,13 @@ def check_bootrom_framebuffer(self, screenshot_path):
          self.vm.cmd('human-monitor-command',
                      command_line='screendump %s' % screenshot_path)
 
-    @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
+    @skipIfMissingImports("PIL")
      def test_bootrom_framebuffer_size(self):
          self.set_machine('next-cube')
          screenshot_path = os.path.join(self.workdir, "dump.ppm")
          self.check_bootrom_framebuffer(screenshot_path)
 
+        from PIL import Image
          width, height = Image.open(screenshot_path).size
          self.assertEqual(width, 1120)
          self.assertEqual(height, 832)

...

#24 lore raw

Re: [PATCH 08/22] tests/functional: add helpers for building file paths

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

Add helper methods that construct paths for

* log files - to be preserved at the end of a test
* scratch files - to be purged at the end of a test
* build files - anything relative to the build root
* data files - anything relative to the functional test source root
* socket files - a short temporary dir to avoid UNIX socket limits

These are to be used instead of direct access to the self.workdir, or self.logdir variables, or any other place where paths are built manually.

---
  tests/functional/qemu_test/testcase.py | 86 ++++++++++++++++++++++++++
  1 file changed, 86 insertions(+)
tests/functional/qemu_test/testcase.py +71 -0
index 90ae59eb54..fb62052817 100644
@@ -13,10 +13,12 @@
 
  import logging
  import os
+from pathlib import Path
  import pycotap
  import shutil
  import subprocess
  import sys
+import tempfile
  import unittest
  import uuid
 
@@ -37,9 +39,93 @@ class QemuBaseTest(unittest.TestCase):
      log = None
      logdir = None
 
+    def socket_dir(self):
+        if self.socketdir is None:
+            self.socketdir = tempfile.TemporaryDirectory(
+                prefix="qemu_func_test_sock_")
+        return self.socketdir
+
+    '''
+    @params args list of zero or more subdirectories or file
+
+    Construct a path for accessing a data file located
+    relative to the source directory that is the root for
+    functional tests.
+
+    @args may be an empty list to reference the root dir
+    itself, may be a single element to reference a file in
+    the root directory, or may be multiple elements to
+    reference a file nested below. The path components
+    will be joined using the platform appropriate path
+    separator.
+
+    Returns: a qualified path
+    '''
+    def data_file(self, *args):
+        return str(Path(Path(__file__).parent.parent, *args))
+
+    '''
+    @params args list of zero or more subdirectories or file
+
+    Construct a path for accessing a data file located
+    relative to the build directory root.
+
+    @args may be an empty list to reference the build dir
+    itself, may be a single element to reference a file in
+    the build directory, or may be multiple elements to
+    reference a file nested below. The path components
+    will be joined using the platform appropriate path
+    separator.
+
+    Returns: a qualified path
+    '''
+    def build_file(self, *args):
+        return str(Path(BUILD_DIR, *args))
+
+    '''
+    @params args list of zero or more subdirectories or file
+
+    Construct a path for accessing/creating a scratch file
+    located relative to a temporary directory dedicated to
+    this test case. The directory and its contents will be
+    purged upon completion of the test.
+
+    @args may be an empty list to reference the scratch dir
+    itself, may be a single element to reference a file in
+    the scratch directory, or may be multiple elements to
+    reference a file nested below. The path components
+    will be joined using the platform appropriate path
+    separator.
+
+    Returns: a qualified path
+    '''
+    def scratch_file(self, *args):
+        return str(Path(self.workdir, *args))
+
+    '''
+    @params args list of zero or more subdirectories or file
+
+    Construct a path for accessing/creating a log file
+    located relative to a temporary directory dedicated to
+    this test case. The directory and its log files will be

tests/functional/qemu_test/testcase.py class QemuBaseTest(unittest.TestCase): · line 120

Quoted 10 lines
tests/functional/qemu_test/testcase.py +10 -0
+    preserved upon completion of the test.
+
+    @args may be an empty list to reference the log dir
+    itself, may be a single element to reference a file in
+    the log directory, or may be multiple elements to
+    reference a file nested below. The path components
+    will be joined using the platform appropriate path
+    separator.
+
+    Returns: a pathlib.Path object

Looks like it is rather returning a string?

tests/functional/qemu_test/testcase.py class QemuBaseTest(unittest.TestCase): · line 128

Quoted 8 lines
tests/functional/qemu_test/testcase.py +5 -0
+    '''
+    def log_file(self, *args):
+        return str(Path(self.logdir, *args))
+
      def setUp(self, bin_prefix):
          self.assertIsNotNone(self.qemu_bin, 'QEMU_TEST_QEMU_BINARY must be set')
          self.arch = self.qemu_bin.split('-')[-1]
+        self.socketdir = None

Should we also delete the socketdir during teardown again?

Thomas

#5 lore raw

Re: [PATCH 02/22] tests/functional: remove unused system imports

In reply to Thomas Huth
Quoted 15 lines · Thomas Huth
Quoted 13 lines · Daniel P. Berrangé
---
  tests/functional/test_aarch64_sbsaref.py       | 1 -
  tests/functional/test_acpi_bits.py             | 1 -
  tests/functional/test_m68k_mcf5208evb.py       | 2 --
  tests/functional/test_microblaze_s3adsp1800.py | 1 -
  tests/functional/test_mips64el_loongson3v.py   | 1 -
  tests/functional/test_or1k_sim.py              | 2 --
  tests/functional/test_s390x_topology.py        | 1 -
  tests/functional/test_sh4_tuxrun.py            | 4 ----
  tests/functional/test_sh4eb_r2d.py             | 1 -
  tests/functional/test_virtio_version.py        | 2 --
  10 files changed, 16 deletions(-)
Quoted 2 lines

Out of curiosity: Is there a way to check for this with a program, or did you check it manually?

IIRC, pylint can check this sort of thing, but I performed a horror show with grep, sed and awk.

We really ought to get black, pylint, flake8, integrated into meson.build, so we can add checks to python code around the tree more easily.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Reviewed-by on v1 9/22
#27 lore raw

Re: [PATCH 09/22] tests/functional: switch over to using self.log_file(...)

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

This removes direct access of the 'self.logdir' variable.

---
  tests/functional/qemu_test/testcase.py | 9 ++++-----
  tests/functional/test_virtio_gpu.py    | 4 +---
  2 files changed, 5 insertions(+), 8 deletions(-)
Reviewed-by on v1 10/22
#29 lore raw

Re: [PATCH 10/22] tests/functional: switch over to using self.build_file(...)

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

This removes direct access of the 'BUILD_DIR' variable.

---
  tests/functional/qemu_test/testcase.py | 4 ++--
  tests/functional/test_aarch64_virt.py  | 6 +++---
  tests/functional/test_virtio_gpu.py    | 9 ++++-----
  3 files changed, 9 insertions(+), 10 deletions(-)
tests/functional/qemu_test/testcase.py +2 -2
index 5b1e6ba04f..2f32742387 100644
@@ -127,8 +127,8 @@ def setUp(self, bin_prefix):
          self.arch = self.qemu_bin.split('-')[-1]
          self.socketdir = None
 
-        self.outputdir = os.path.join(BUILD_DIR, 'tests', 'functional',
-                                      self.arch, self.id())
+        self.outputdir = self.build_file('tests', 'functional',
+                                         self.arch, self.id())
          self.workdir = os.path.join(self.outputdir, 'scratch')
          os.makedirs(self.workdir, exist_ok=True)
 
tests/functional/test_aarch64_virt.py +3 -3
index 07b78f6a84..29eeb8e32d 100755
@@ -14,7 +14,7 @@
  import os
  import logging
 
-from qemu_test import (BUILD_DIR, QemuSystemTest, Asset, exec_command,
+from qemu_test import (QemuSystemTest, Asset, exec_command,
                         wait_for_console_pattern, get_qemu_img, run_cmd)
 
 
@@ -52,8 +52,8 @@ def test_alpine_virt_tcg_gic_max(self):
                           "mte=on,"
                           "gic-version=max,iommu=smmuv3")
          self.vm.add_args("-smp", "2", "-m", "1024")
-        self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios',
-                                               'edk2-aarch64-code.fd'))
+        self.vm.add_args('-bios', self.build_file('pc-bios',
+                                                  'edk2-aarch64-code.fd'))
          self.vm.add_args("-drive", f"file={iso_path},media=cdrom,format=raw")
          self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0')
          self.vm.add_args('-object', 'rng-random,id=rng0,filename=/dev/urandom')
tests/functional/test_virtio_gpu.py +1 -2
index c4562618d9..39dcf376dd 100755
@@ -6,8 +6,7 @@
  # later.  See the COPYING file in the top-level directory.
 
 
-from qemu_test import (BUILD_DIR, QemuSystemTest, Asset,
-                       wait_for_console_pattern,
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
                         exec_command_and_wait_for_pattern,
                         is_readable_executable_file)
  from qemu.utils import kvm_available

tests/functional/test_virtio_gpu.py line 22

Quoted 8 lines
tests/functional/test_virtio_gpu.py +1 -1
@@ -17,12 +16,12 @@
  import subprocess
 
 
-def pick_default_vug_bin():
+def pick_default_vug_bin(test):
      relative_path = "./contrib/vhost-user-gpu/vhost-user-gpu"
      if is_readable_executable_file(relative_path):
          return relative_path

I wonder whether we should drop the above two lines of special casing and always use the code below instead?

tests/functional/test_virtio_gpu.py line 24

Quoted 2 lines
tests/functional/test_virtio_gpu.py +1 -1
-    bld_dir_path = os.path.join(BUILD_DIR, relative_path)
+    bld_dir_path = test.build_file(relative_path)

... then you could also get rid of the hard-coded slashes in relative_path?

tests/functional/test_virtio_gpu.py def test_vhost_user_vga_virgl(self): · line 90

Quoted 12 lines
tests/functional/test_virtio_gpu.py +1 -1
      if is_readable_executable_file(bld_dir_path):
          return bld_dir_path
 
@@ -85,7 +84,7 @@ def test_vhost_user_vga_virgl(self):
          # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
          self.require_accelerator('kvm')
 
-        vug = pick_default_vug_bin()
+        vug = pick_default_vug_bin(self)
          if not vug:
              self.skipTest("Could not find vhost-user-gpu")
 

Anyway:

Reviewed-by on v1 11/22
#32 lore raw

Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)

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

This removes direct path manipulation to figure out the source dir

---
  tests/functional/test_acpi_bits.py | 22 +++++++---------------
  1 file changed, 7 insertions(+), 15 deletions(-)
tests/functional/test_acpi_bits.py +7 -13
index 4de5fae37e..948b134b16 100755
@@ -41,7 +41,6 @@
  import tempfile
  import zipfile
 
-from pathlib import Path
  from typing import (
      List,
      Optional,
@@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          self._vm = None
-        self._baseDir = None
 
          self._debugcon_addr = '0x403'
          self._debugcon_log = 'debugcon-log.txt'
@@ -137,26 +135,22 @@ def _print_log(self, log):
      def copy_bits_config(self):
          """ copies the bios bits config file into bits.
          """
-        config_file = 'bits-cfg.txt'
-        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                       'bits-config')
+        bits_config_file = self.data_file('acpi-bits',
+                                          'bits-config',
+                                          'bits-cfg.txt')
          target_config_dir = os.path.join(self.workdir,
                                           'bits-%d' %self.BITS_INTERNAL_VER,
                                           'boot')
-        self.assertTrue(os.path.exists(bits_config_dir))
+        self.assertTrue(os.path.exists(bits_config_file))
          self.assertTrue(os.path.exists(target_config_dir))
-        self.assertTrue(os.access(os.path.join(bits_config_dir,
-                                               config_file), os.R_OK))
-        shutil.copy2(os.path.join(bits_config_dir, config_file),
-                     target_config_dir)
+        shutil.copy2(bits_config_file, target_config_dir)
          self.logger.info('copied config file %s to %s',
-                         config_file, target_config_dir)
+                         bits_config_file, target_config_dir)
 
      def copy_test_scripts(self):
          """copies the python test scripts into bits. """
 
-        bits_test_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                     'bits-tests')
+        bits_test_dir = self.data_file('acpi-bits', 'bits-tests')
          target_test_dir = os.path.join(self.workdir,
                                         'bits-%d' %self.BITS_INTERNAL_VER,
                                         'boot', 'python')

tests/functional/test_acpi_bits.py def setUp(self): # pylint: disable=arguments-differ · line 258

Quoted 8 lines
tests/functional/test_acpi_bits.py +0 -2
@@ -259,8 +253,6 @@ def setUp(self): # pylint: disable=arguments-differ
          super().setUp('qemu-system-')
          self.logger = self.log
 
-        self._baseDir = Path(__file__).parent
-
          prebuiltDir = os.path.join(self.workdir, 'prebuilt')
          if not os.path.isdir(prebuiltDir):
              os.mkdir(prebuiltDir, mode=0o775)
#38 lore raw

Re: [PATCH 12/22] tests/functional: switch over to using self.scratch_file()

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

Replace any instances of

   os.path.join(self.workdir, ".../...")
   self.workdir + "/.../..."

with

   self.scratch_file("...", "...")

which is more compact and portable

---

...

tests/functional/qemu_test/linuxkernel.py def extract_from_deb(self, deb_path, path): · line 49

Quoted 13 lines
tests/functional/qemu_test/linuxkernel.py +1 -4
index 2b5b9a5fda..a6525f9dd6 100644
@@ -46,8 +46,7 @@ def extract_from_deb(self, deb_path, path):
          os.chdir(cwd)
          # Return complete path to extracted file.  Because callers to
          # extract_from_deb() specify 'path' with a leading slash, it is
-        # necessary to use os.path.relpath() as otherwise os.path.join()
-        # interprets it as an absolute path and drops the self.workdir part.
-        return os.path.normpath(os.path.join(self.workdir,
-                                             os.path.relpath(path, '/')))
+        # necessary to use 'relative_to()' to turn it into a relative

Here you mention "relative_to()" ....

tests/functional/qemu_test/linuxkernel.py def extract_from_deb(self, deb_path, path): · line 51

Quoted 2 lines
tests/functional/qemu_test/linuxkernel.py +2 -0
+        # path for joining to the scratch dir
+        return os.path.normpath(self.scratch_file(os.path.relpath(path, '/')))

... but the code still uses relpath() instead?

tests/functional/test_aarch64_aspeed.py def test_aarch64_ast2700_evb_sdk_v09_02(self): · line 42

Quoted 9 lines
tests/functional/test_aarch64_aspeed.py +0 -1
index 59916efd71..c6c6b74acc 100644
@@ -39,26 +39,28 @@ def test_aarch64_ast2700_evb_sdk_v09_02(self):
          archive_extract(image_path, self.workdir)
 
          num_cpu = 4
-        image_dir = self.workdir + '/ast2700-default/'

I'd maybe just change image_dir and keep the code below as it is, so you can avoid specifying 'ast2700-default' again and again.

Quoted 53 lines
tests/functional/test_aarch64_aspeed.py +10 -6
-        uboot_size = os.path.getsize(image_dir + 'u-boot-nodtb.bin')
+        uboot_size = os.path.getsize(self.scratch_file('ast2700-default',
+                                                       'u-boot-nodtb.bin'))
          uboot_dtb_load_addr = hex(0x400000000 + uboot_size)
 
          load_images_list = [
              {
                  'addr': '0x400000000',
-                'file': image_dir + 'u-boot-nodtb.bin'
+                'file': self.scratch_file('ast2700-default',
+                                          'u-boot-nodtb.bin')
              },
              {
                  'addr': str(uboot_dtb_load_addr),
-                'file': image_dir + 'u-boot.dtb'
+                'file': self.scratch_file('ast2700-default', 'u-boot.dtb')
              },
              {
                  'addr': '0x430000000',
-                'file': image_dir + 'bl31.bin'
+                'file': self.scratch_file('ast2700-default', 'bl31.bin')
              },
              {
                  'addr': '0x430080000',
-                'file': image_dir + 'optee/tee-raw.bin'
+                'file': self.scratch_file('ast2700-default', 'optee',
+                                          'tee-raw.bin')
              }
          ]
 
@@ -75,7 +77,8 @@ def test_aarch64_ast2700_evb_sdk_v09_02(self):
          self.vm.add_args('-smp', str(num_cpu))
          self.vm.add_args('-device',
                           'tmp105,bus=aspeed.i2c.bus.1,address=0x4d,id=tmp-test')
-        self.do_test_aarch64_aspeed_sdk_start(image_dir + 'image-bmc')
+        self.do_test_aarch64_aspeed_sdk_start(
+            self.scratch_file('ast2700-default', 'image-bmc'))
 
          wait_for_console_pattern(self, 'ast2700-default login:')
 
tests/functional/test_aarch64_raspi3.py +0 -1
index 369f95a3d9..98ed6f9d56 100755
@@ -7,7 +7,6 @@
  #
  # SPDX-License-Identifier: GPL-2.0-or-later
 
-import os
  from zipfile import ZipFile
 
  from qemu_test import LinuxKernelTest, Asset

tests/functional/test_aarch64_raspi3.py def test_aarch64_raspi3_atf(self): · line 27

Quoted 3 lines
tests/functional/test_aarch64_raspi3.py +0 -0
@@ -26,7 +25,7 @@ def test_aarch64_raspi3_atf(self):
 
          with ZipFile(zip_path, 'r') as zf:
                       zf.extract(efi_name, path=self.workdir)

Should that self.workdir above get replaced with self.scratch_file(), too?

Quoted 5 lines
tests/functional/test_aarch64_raspi3.py +1 -1
-        efi_fd = os.path.join(self.workdir, efi_name)
+        efi_fd = self.scratch_file(efi_name)
 
          self.set_machine('raspi3b')
          self.vm.set_console(console_index=1)

...

Quoted 23 lines
tests/functional/test_arm_aspeed.py +2 -2
index db872ff05e..c4869011db 100755
@@ -35,7 +35,7 @@ def test_ast1030_zephyros_1_04(self):
          kernel_name = "ast1030-evb-demo/zephyr.elf"
          with ZipFile(zip_file, 'r') as zf:
                       zf.extract(kernel_name, path=self.workdir)
-        kernel_file = os.path.join(self.workdir, kernel_name)
+        kernel_file = self.scratch_file(kernel_name)
 
          self.vm.set_console()
          self.vm.add_args('-kernel', kernel_file, '-nographic')
@@ -57,7 +57,7 @@ def test_ast1030_zephyros_1_07(self):
          kernel_name = "ast1030-evb-demo/zephyr.bin"
          with ZipFile(zip_file, 'r') as zf:
                       zf.extract(kernel_name, path=self.workdir)
-        kernel_file = os.path.join(self.workdir, kernel_name)
+        kernel_file = self.scratch_file(kernel_name)
 
          self.vm.set_console()
          self.vm.add_args('-kernel', kernel_file, '-nographic')

tests/functional/test_arm_aspeed.py def test_arm_ast2600_evb_buildroot_tpm(self): · line 231

Quoted 7 lines
tests/functional/test_arm_aspeed.py +3 -1
@@ -226,14 +226,16 @@ def test_arm_ast2600_evb_buildroot_tpm(self):
 
          image_path = self.ASSET_BR2_202302_AST2600_TPM_FLASH.fetch()
 
-        tpmstate_dir = tempfile.TemporaryDirectory(prefix="qemu_")
+        tpmstate_dir = self.scratch_file('swtpmstate')
+        os.mkdir(tpmstate_dir)
+        socket_dir = tempfile.TemporaryDirectory(prefix="qemu_")

You don't seem to use socket_dir in any of your changes below?

Also, shouldn't this rather be using self.socket_dir() now? (maybe rather something for a separate patch?)

Quoted 21 lines
tests/functional/test_arm_aspeed.py +2 -2
          socket = os.path.join(tpmstate_dir.name, 'swtpm-socket')
 
          # We must put the TPM state dir in /tmp/, not the build dir,
          # because some distros use AppArmor to lock down swtpm and
          # restrict the set of locations it can access files in.
          subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
-                        '--tpmstate', f'dir={tpmstate_dir.name}',
+                        '--tpmstate', f'dir={tpmstate_dir}',
                          '--ctrl', f'type=unixio,path={socket}'])
 
          self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}')
@@ -274,7 +276,7 @@ def test_arm_ast2500_evb_sdk(self):
          archive_extract(image_path, self.workdir)
 
          self.do_test_arm_aspeed_sdk_start(
-            self.workdir + '/ast2500-default/image-bmc')
+            self.scratch_file('ast2500-default', 'image-bmc'))
 
          self.wait_for_console_pattern('ast2500-default login:')
 

tests/functional/test_arm_aspeed.py def test_arm_ast2600_evb_sdk(self): · line 302

Quoted 8 lines
tests/functional/test_arm_aspeed.py +1 -1
@@ -294,7 +296,7 @@ def test_arm_ast2600_evb_sdk(self):
          self.vm.add_args('-device',
              'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
          self.do_test_arm_aspeed_sdk_start(
-            self.workdir + '/ast2600-a2/image-bmc')
+            self.scratch_file('ast2600-a2', 'image-bmc'))
 
          self.wait_for_console_pattern('ast2600-a2 login:')
 

...

Thomas

#41 lore raw

Re: [PATCH 13/22] tests/functional: switch over to using self.socket_dir(...)

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

This removes direct creation of temporary dirs

---
  tests/functional/test_arm_aspeed.py | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
tests/functional/test_arm_aspeed.py +0 -1
index c4869011db..ca223ac8f0 100755
@@ -9,7 +9,6 @@
  import os
  import time
  import subprocess
-import tempfile
 
  from qemu_test import (LinuxKernelTest, Asset,
                         exec_command_and_wait_for_pattern,

tests/functional/test_arm_aspeed.py def test_arm_ast2600_evb_buildroot_tpm(self): · line 231

Quoted 7 lines
tests/functional/test_arm_aspeed.py +2 -2
@@ -228,8 +227,8 @@ def test_arm_ast2600_evb_buildroot_tpm(self):
 
          tpmstate_dir = self.scratch_file('swtpmstate')
          os.mkdir(tpmstate_dir)
-        socket_dir = tempfile.TemporaryDirectory(prefix="qemu_")
-        socket = os.path.join(tpmstate_dir.name, 'swtpm-socket')
+        socket_dir = self.socket_dir()
+        socket = os.path.join(socket_dir.name, 'swtpm-socket')

Ah, here it gets fixed again! ... maybe squash this into the previous patch?

Thomas

#45 lore raw

Re: [PATCH 15/22] tests/functional: add common zip_extract helper

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

This mirrors the existing archive_extract and cpio_extract helpers

---
  tests/functional/qemu_test/utils.py | 7 +++++++
  1 file changed, 7 insertions(+)
tests/functional/qemu_test/utils.py +0 -0
index 1bf1c410d5..41bd1df666 100644

tests/functional/qemu_test/utils.py def archive_extract(archive, dest_dir, member=None): · line 54

Quoted 9 lines
tests/functional/qemu_test/utils.py +6 -0
@@ -46,6 +46,13 @@ def archive_extract(archive, dest_dir, member=None):
          else:
              tf.extractall(path=dest_dir)
 
+def zip_extract(archive, dest_dir, member=None):
+    with zipfile.ZipFile(archive, 'r') as zf:
+        if member:
+            zf.extract(member=member, path=dest_dir)
+        else:
+            zf.extractall(path=dest_dir)

Don't you need to "import zipfile" here now, too?

Thomas

#48 lore raw

Re: [PATCH 16/22] tests/functional: add common deb_extract helper

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

This mirrors the existing archive_extract, cpio_extract and zip_extract helpers

---
  tests/functional/qemu_test/linuxkernel.py | 15 +++++----------
  tests/functional/qemu_test/utils.py       | 13 +++++++++++++
  2 files changed, 18 insertions(+), 10 deletions(-)
tests/functional/qemu_test/linuxkernel.py +5 -10
index a6525f9dd6..fb6a158d36 100644
@@ -6,8 +6,8 @@
  import os
 
  from .testcase import QemuSystemTest
-from .cmd import run_cmd, wait_for_console_pattern
-from .utils import archive_extract
+from .cmd import wait_for_console_pattern
+from .utils import deb_extract
 
  class LinuxKernelTest(QemuSystemTest):
      KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
@@ -37,16 +37,11 @@ def extract_from_deb(self, deb_path, path):
          :param path: path within the deb archive of the file to be extracted
          :returns: path of the extracted file
          """
-        cwd = os.getcwd()
-        os.chdir(self.workdir)
-        (stdout, stderr, ret) = run_cmd(['ar', 't', deb_path])
-        file_path = stdout.split()[2]
-        run_cmd(['ar', 'x', deb_path, file_path])
-        archive_extract(file_path, self.workdir)
-        os.chdir(cwd)
+        relpath = os.path.relpath(path, '/')
+        deb_extract(deb_path, self.workdir, member="." + path)
          # Return complete path to extracted file.  Because callers to
          # extract_from_deb() specify 'path' with a leading slash, it is
          # necessary to use 'relative_to()' to turn it into a relative
          # path for joining to the scratch dir
-        return os.path.normpath(self.scratch_file(os.path.relpath(path, '/')))
+        return os.path.normpath(self.scratch_file(relpath))
 
tests/functional/qemu_test/utils.py +2 -0
index 41bd1df666..bafe7fb80e 100644
@@ -15,6 +15,8 @@
  import subprocess
  import tarfile
 
+from .cmd import run_cmd
+
  """
  Round up to next power of 2
  """
@@ -53,6 +55,17 @@ def zip_extract(archive, dest_dir, member=None):
          else:
              zf.extractall(path=dest_dir)
 

tests/functional/qemu_test/utils.py def zip_extract(archive, dest_dir, member=None): · line 67

Quoted 10 lines
tests/functional/qemu_test/utils.py +10 -0
+def deb_extract(archive, dest_dir, member=None):
+    cwd = os.getcwd()
+    os.chdir(dest_dir)
+    try:
+        (stdout, stderr, ret) = run_cmd(['ar', 't', archive])
+        file_path = stdout.split()[2]
+        run_cmd(['ar', 'x', archive, file_path])
+        archive_extract(file_path, dest_dir, member)
+    finally:
+        os.chdir(cwd)

Not sure whether we really need this ... extracting .deb files is very specific to running Linux kernels in the guest, so IMHO it should be sufficient to have it in linuxkernel.py.

Anyway, if we add more and more *_extract functions, we should maybe consider to move the extraction functions out of utils.py into an archive.py file, what do you think?

Thomas

#51 lore raw

Re: [PATCH 17/22] tests/functional: generalize archive_extract

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

There are many types of archives that the tests deal with, and 'archive_extract' suggests it can cope with any, rather than only tar files. Rename the existing method to 'tar_extract' and add a new method that can dynamically extract any zip, tar or cpio file based on file extension.

---
  tests/functional/qemu_test/utils.py | 31 +++++++++++++++++++++++++++--
  1 file changed, 29 insertions(+), 2 deletions(-)
tests/functional/qemu_test/utils.py +1 -0
index bafe7fb80e..8c1df8f8c2 100644
@@ -14,6 +14,7 @@
  import shutil
  import subprocess
  import tarfile
+import zipfile
 
  from .cmd import run_cmd
 

tests/functional/qemu_test/utils.py def image_pow2ceil_expand(path): · line 42

Quoted 5 lines
tests/functional/qemu_test/utils.py +1 -1
@@ -38,7 +39,33 @@ def image_pow2ceil_expand(path):
              with open(path, 'ab+') as fd:
                  fd.truncate(size_aligned)
 
-def archive_extract(archive, dest_dir, member=None):
+def archive_extract(archive, dest_dir, format=None, member=None):

Why not doing "if not format: format = guess_archive_format(archive)" here?
Otherwise this helper function is rather useless - if you have to know the format, you could directly call the appropriate function anyway.

Thomas

Quoted 38 lines
tests/functional/qemu_test/utils.py +27 -1
+    if format == "tar":
+        tar_extract(archive, dest_dir, member)
+    elif format == "zip":
+        zip_extract(archive, dest_dir, member)
+    elif format == "cpio":
+        if member is not None:
+            raise Exception("Unable to filter cpio extraction")
+        cpio_extract(archive, dest_dir)
+    elif format == "deb":
+        deb_extract(archive, dest_dir, "./" + member)
+    else:
+        raise Exception(f"Unknown archive format {format}")
+
+def guess_archive_format(path):
+    if ".tar." in path or path.endswith("tgz"):
+        return "tar"
+    elif path.endswith(".zip"):
+        return "zip"
+    elif path.endswith(".cpio"):
+        return "cpio"
+    elif path.endswith(".deb") or path.endswith(".udeb"):
+        return "deb"
+    else:
+        raise Exception(f"Unknown archive format for {path}")
+
+def tar_extract(archive, dest_dir, member=None):
      with tarfile.open(archive) as tf:
          if hasattr(tarfile, 'data_filter'):
              tf.extraction_filter = getattr(tarfile, 'data_filter',
@@ -62,7 +89,7 @@ def deb_extract(archive, dest_dir, member=None):
          (stdout, stderr, ret) = run_cmd(['ar', 't', archive])
          file_path = stdout.split()[2]
          run_cmd(['ar', 'x', archive, file_path])
-        archive_extract(file_path, dest_dir, member)
+        archive_extract(file_path, dest_dir, format="tar", member=member)
      finally:
          os.chdir(cwd)
 
#54 lore raw

Re: [PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest

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

This helper wrappers utils.archive_extract, forcing the use of the scratch directory, to ensure any extracted files are cleaned at test termination. If a specific member is requested, then the path to the extracted file is also returned.

---
  tests/functional/qemu_test/testcase.py | 36 ++++++++++++++++++++++++++
  1 file changed, 36 insertions(+)
tests/functional/qemu_test/testcase.py +25 -0
index 2f32742387..31d06f0172 100644
@@ -28,6 +28,8 @@
  from .asset import Asset
  from .cmd import run_cmd
  from .config import BUILD_DIR
+from .utils import (archive_extract as utils_archive_extract,
+                    guess_archive_format)
 
 
  class QemuBaseTest(unittest.TestCase):
@@ -39,6 +41,40 @@ class QemuBaseTest(unittest.TestCase):
      log = None
      logdir = None
 
+    '''
+    @params archive: filename, Asset, or file-like object to extract
+    @params sub_dir: optional sub-directory to extract into
+    @params member: optional member file to limit extraction to
+
+    Extracts @archive into the scratch directory, or a
+    directory beneath named by @sub_dir. All files are
+    extracted unless @member specifies a limit.
+
+    If @member is non-None, returns the fully qualified
+    path to @member
+    '''
+    def archive_extract(self, archive, format=None, sub_dir=None, member=None):
+        if type(archive) == Asset:
+            if format is None:
+                format = guess_archive_format(archive.url)
+            archive = archive.fetch()
+        elif format is None:
+            format = guess_archive_format(archive)
+
+        if member is not None:
+            if os.path.isabs(member):
+                member = os.path.relpath(member, '/')

tests/functional/qemu_test/testcase.py class QemuBaseTest(unittest.TestCase): · line 76

Quoted 10 lines
tests/functional/qemu_test/testcase.py +10 -0
+
+        if sub_dir is None:
+            utils_archive_extract(archive, self.scratch_file(), format, member)
+        else:
+            utils_archive_extract(archive, self.scratch_file(sub_dir),
+                                  format, member)
+
+        if member is not None:
+            return self.scratch_file(member)
+        return None

Ah, ok, so the guessing is done here ...

But somehow it feels wrong to have a "archive_extract" function in the QemuBaseTest class that also does asset fetching under the hood.

Could you maybe rather move this into the asset.py file and rename the function to "fetch_and_extract()" to make it clearer what it does?

Thomas

#8 lore raw

Re: [PATCH 03/22] tests/functional: remove duplicated 'qemu_test' import statements

In reply to Thomas Huth
Quoted 58 lines · Thomas Huth
Quoted 57 lines · Daniel P. Berrangé

Group all imports that originate in the 'qemu_test' package into one statement.

---
  tests/functional/qemu_test/tuxruntest.py         |  9 +++++----
  tests/functional/test_aarch64_raspi4.py          |  4 ++--
  tests/functional/test_aarch64_sbsaref.py         |  5 ++---
  tests/functional/test_aarch64_sbsaref_alpine.py  |  5 ++---
  tests/functional/test_aarch64_sbsaref_freebsd.py |  5 ++---
  tests/functional/test_aarch64_virt.py            |  6 ++----
  tests/functional/test_arm_aspeed.py              |  7 +++----
  tests/functional/test_arm_bflt.py                |  3 +--
  tests/functional/test_arm_bpim2u.py              |  8 ++++----
  tests/functional/test_arm_canona1100.py          |  3 +--
  tests/functional/test_arm_integratorcp.py        |  3 +--
  tests/functional/test_arm_orangepi.py            | 10 +++++-----
  tests/functional/test_arm_raspi2.py              |  4 ++--
  tests/functional/test_loongarch64_virt.py        |  6 +++---
  tests/functional/test_microblaze_s3adsp1800.py   |  5 ++---
  tests/functional/test_microblazeel_s3adsp1800.py |  5 ++---
  tests/functional/test_mips64el_fuloong2e.py      |  7 ++++---
  tests/functional/test_mips64el_loongson3v.py     |  3 +--
  tests/functional/test_mips64el_malta.py          |  4 ++--
  tests/functional/test_mipsel_malta.py            |  6 +++---
  tests/functional/test_multiprocess.py            |  4 ++--
  tests/functional/test_netdev_ethtool.py          |  3 +--
  tests/functional/test_ppc64_hv.py                |  4 ++--
  tests/functional/test_ppc64_powernv.py           |  3 +--
  tests/functional/test_ppc64_pseries.py           |  3 +--
  tests/functional/test_ppc_405.py                 |  6 +++---
  tests/functional/test_ppc_40p.py                 |  3 +--
  tests/functional/test_ppc_74xx.py                |  3 +--
  tests/functional/test_ppc_amiga.py               |  3 +--
  tests/functional/test_ppc_bamboo.py              |  6 +++---
  tests/functional/test_ppc_mpc8544ds.py           |  3 +--
  tests/functional/test_ppc_virtex_ml507.py        |  3 +--
  tests/functional/test_riscv_opensbi.py           |  4 ++--
  tests/functional/test_rx_gdbsim.py               |  6 +++---
  tests/functional/test_s390x_ccw_virtio.py        |  6 +++---
  tests/functional/test_s390x_topology.py          |  7 +++----
  tests/functional/test_sh4eb_r2d.py               |  4 ++--
  tests/functional/test_sparc64_sun4u.py           |  3 +--
  tests/functional/test_virtio_gpu.py              | 10 ++++------
  39 files changed, 85 insertions(+), 107 deletions(-)
tests/functional/qemu_test/tuxruntest.py +0 -4
index ab3b27da43..7c0456923e 100644
@@ -13,10 +13,11 @@
  import stat
  import time
-from qemu_test import QemuSystemTest
-from qemu_test import exec_command, exec_command_and_wait_for_pattern
-from qemu_test import wait_for_console_pattern
-from qemu_test import has_cmd, run_cmd, get_qemu_img
Quoted 8 lines

tests/functional/qemu_test/tuxruntest.py line 19

Quoted 4 lines
tests/functional/qemu_test/tuxruntest.py +4 -0
+from qemu_test import (QemuSystemTest, exec_command,
+                       exec_command_and_wait_for_pattern,
+                       wait_for_console_pattern,
+                       has_cmd, run_cmd, get_qemu_img)

Is there a real advantage in writing it this way? For most files, this not seem to reduce the lines of code, so at a quick glance, it rather looks like unnecessary code churn to me...?

I guess I just didn't like the wall of repeated imports, but i'm not that fussed either way. So I'll drop this.

With regards,
Daniel

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

Re: [PATCH 05/22] tests/functional: remove duplicated 'which' function impl

In reply to Thomas Huth
Quoted 16 lines · Thomas Huth
Quoted 9 lines · Daniel P. Berrangé

Put the 'which' function into shared code.

---
  tests/functional/qemu_test/__init__.py |  2 +-
  tests/functional/qemu_test/cmd.py      | 10 ++++++++++
  tests/functional/test_acpi_bits.py     | 13 +------------
  tests/functional/test_ppc64_hv.py      | 13 +------------
  4 files changed, 13 insertions(+), 25 deletions(-)

None of the callers really seem to be interested in the location of the command, only whether it is available in the $PATH or not ... so could we maybe rather drop this function and use the has_cmd() function everywhere instead?

Quoted 4 lines

Hmm, thinking about it twice - has_cmd() uses the "which" program internally, but AFAIK this program is optional in Linux installations nowadays ... so maybe it's still a good idea to move our Python which() to cmd.py, but has_cmd() should maybe rather be changed to use it, too?

This reminds me I meant to ask about 'has_cmd' - it looks rather over-engineered to me to be trying to invoke the command with args.

Perhaps there was some reason to check support for individual args in the past, but none of the current tests need that AFAICT.

So if anything I'd be looking to delete 'has_cmd' and 'has_cmds' entirely, and rely only on the pure python 'which'.

With regards,
Daniel

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

Re: [PATCH 05/22] tests/functional: remove duplicated 'which' function impl

In reply to Richard Henderson
Quoted 23 lines · Richard Henderson
Quoted 9 lines · Daniel P. Berrangé

Put the 'which' function into shared code.

---
  tests/functional/qemu_test/__init__.py |  2 +-
  tests/functional/qemu_test/cmd.py      | 10 ++++++++++
  tests/functional/test_acpi_bits.py     | 13 +------------
  tests/functional/test_ppc64_hv.py      | 13 +------------
  4 files changed, 13 insertions(+), 25 deletions(-)

As code movement,

tests/functional/qemu_test/cmd.py line 28

Quoted 8 lines
tests/functional/qemu_test/cmd.py +8 -0
+def which(tool):
+    """ looks up the full path for @tool, returns None if not found
+        or if @tool does not have executable permissions.
+    """
+    paths=os.getenv('PATH')
+    for p in paths.split(os.path.pathsep):
+        p = os.path.join(p, tool)
+        if os.path.exists(p) and os.access(p, os.X_OK):
Quoted 1 line

But surely exists() is redundant with access()?

Agreed, will simplify that.

With regards,
Daniel

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

Re: [PATCH 06/22] tests/functional: introduce some helpful decorators

In reply to Thomas Huth
Quoted 30 lines · Thomas Huth
Quoted 27 lines · Daniel P. Berrangé

Reduce repeated boilerplate with some helper decorators:

@skipIfNotPlatform("x86_64", "aarch64")

=> Skip unless the build host platform matches

@skipIfMissingCommands("mkisofs", "losetup")

=> Skips unless all listed commands are found in $PATH

@skipIfMissingImports("numpy", "cv2")

=> Skips unless all listed modules can be imported

@skipFlakyTest("https://gitlab.com/qemu-project/qemu/-/issues/NNN")

=> Skips unless env var requests flaky tests with the
reason documented in the referenced gitlab bug

@skipBigData

=> Skips unless env var permits tests creating big data files

@skipUntrustedTest

=> Skips unless env var permits tests which are potentially
dangerous to the host

Quoted 10 lines

tests/functional/qemu_test/decorators.py line 77

Quoted 4 lines

+'''

tests/functional/qemu_test/decorators.py new file +3 -0
+Decorator to skip execution of tests which need large
+data storage on the host, unless the
+$QEMU_TEST_ALLOW_LARGE_STORAGE env var is set

Maybe we should also provide some direction what is meant with large storage. I've seen some tests that are skipped since they create a disk file with 128 MiB. And others are always executed though they create a disk file with 512 MiB or even more. What would be a good recommendation here? (My gut feeling is maybe ~ 1 GiB? Or better less?)

We're quite limited on disk space in the FreeBSD CI runner, so if we take account of fact that tests can run in parallel, we definitely want to err on the smaller side, while maximising coverage available by default. 128 MB is too small, too many tests would get excluded. I guess 512MB - 1GB is probably the rough range we should give guidance for.

With regards,
Daniel

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

Re: [PATCH 07/22] tests/functional: switch to new test skip decorators

In reply to Thomas Huth
Quoted 39 lines · Thomas Huth
Quoted 11 lines · Daniel P. Berrangé

This ensures consistency of behaviour across all the tests, and requires that we provide gitlab bug links when marking a test to be skipped due to unreliability.

---

tests/functional/test_arm_aspeed.py +0 -0
index 068740a813..db872ff05e 100755

tests/functional/test_arm_aspeed.py line 17

Quoted 6 lines
tests/functional/test_arm_aspeed.py +3 -1
@@ -13,7 +13,9 @@
  from qemu_test import (LinuxKernelTest, Asset,
                         exec_command_and_wait_for_pattern,
-                       interrupt_interactive_console_until_pattern, has_cmd)
+                       interrupt_interactive_console_until_pattern,
+                       skipIfMissingCommands,
+)

In the other files, you placed the final ")" at the end of the previous line instead?

Quoted 17 lines
tests/functional/test_m68k_nextcube.py +1 -8
index 0124622c40..82d3d335d0 100755
@@ -10,16 +10,9 @@
  import os
  import time
-from qemu_test import QemuSystemTest, Asset
-from unittest import skipUnless
-
+from qemu_test import QemuSystemTest, Asset, skipIfMissingImports
  from qemu_test.tesseract import tesseract_available, tesseract_ocr
-
-PIL_AVAILABLE = True
-try:
-    from PIL import Image
-except ImportError:
Quoted 8 lines

tests/functional/test_m68k_nextcube.py line 15

Quoted 2 lines
tests/functional/test_m68k_nextcube.py +1 -1
-    PIL_AVAILABLE = False
+from unittest import skipUnless

I think you could also replace the other skipUnless() in this file nowadays:
The version check here was only useful in the days when most distros still shipped Tesseract v3, but these days are gone, we don't support any of those distros anymore. So I think it should be fine to use skipIfMissingCommands here now instead.

Ah good, if we can drop that special case its nice.

Quoted 6 lines

Anyway, I'm also fine if we keep it for now (we still can adjust it later), so with at least the ")" nit fixed:

Quoted 16 lines
Quoted 14 lines
tests/functional/test_m68k_nextcube.py +2 -1
  class NextCubeMachine(QemuSystemTest):
@@ -43,12 +36,13 @@ def check_bootrom_framebuffer(self, screenshot_path):
          self.vm.cmd('human-monitor-command',
                      command_line='screendump %s' % screenshot_path)
-    @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
+    @skipIfMissingImports("PIL")
      def test_bootrom_framebuffer_size(self):
          self.set_machine('next-cube')
          screenshot_path = os.path.join(self.workdir, "dump.ppm")
          self.check_bootrom_framebuffer(screenshot_path)
+        from PIL import Image
          width, height = Image.open(screenshot_path).size
          self.assertEqual(width, 1120)
          self.assertEqual(height, 832)

...

With regards,
Daniel

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

Re: [PATCH 10/22] tests/functional: switch over to using self.build_file(...)

In reply to Thomas Huth
Quoted 67 lines · Thomas Huth
Quoted 56 lines · Daniel P. Berrangé

This removes direct access of the 'BUILD_DIR' variable.

---
  tests/functional/qemu_test/testcase.py | 4 ++--
  tests/functional/test_aarch64_virt.py  | 6 +++---
  tests/functional/test_virtio_gpu.py    | 9 ++++-----
  3 files changed, 9 insertions(+), 10 deletions(-)
tests/functional/qemu_test/testcase.py +2 -2
index 5b1e6ba04f..2f32742387 100644
@@ -127,8 +127,8 @@ def setUp(self, bin_prefix):
          self.arch = self.qemu_bin.split('-')[-1]
          self.socketdir = None
-        self.outputdir = os.path.join(BUILD_DIR, 'tests', 'functional',
-                                      self.arch, self.id())
+        self.outputdir = self.build_file('tests', 'functional',
+                                         self.arch, self.id())
          self.workdir = os.path.join(self.outputdir, 'scratch')
          os.makedirs(self.workdir, exist_ok=True)
tests/functional/test_aarch64_virt.py +3 -3
index 07b78f6a84..29eeb8e32d 100755
@@ -14,7 +14,7 @@
  import os
  import logging
-from qemu_test import (BUILD_DIR, QemuSystemTest, Asset, exec_command,
+from qemu_test import (QemuSystemTest, Asset, exec_command,
                         wait_for_console_pattern, get_qemu_img, run_cmd)
@@ -52,8 +52,8 @@ def test_alpine_virt_tcg_gic_max(self):
                           "mte=on,"
                           "gic-version=max,iommu=smmuv3")
          self.vm.add_args("-smp", "2", "-m", "1024")
-        self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios',
-                                               'edk2-aarch64-code.fd'))
+        self.vm.add_args('-bios', self.build_file('pc-bios',
+                                                  'edk2-aarch64-code.fd'))
          self.vm.add_args("-drive", f"file={iso_path},media=cdrom,format=raw")
          self.vm.add_args('-device', 'virtio-rng-pci,rng=rng0')
          self.vm.add_args('-object', 'rng-random,id=rng0,filename=/dev/urandom')
tests/functional/test_virtio_gpu.py +1 -2
index c4562618d9..39dcf376dd 100755
@@ -6,8 +6,7 @@
  # later.  See the COPYING file in the top-level directory.
-from qemu_test import (BUILD_DIR, QemuSystemTest, Asset,
-                       wait_for_console_pattern,
+from qemu_test import (QemuSystemTest, Asset, wait_for_console_pattern,
                         exec_command_and_wait_for_pattern,
                         is_readable_executable_file)
  from qemu.utils import kvm_available

tests/functional/test_virtio_gpu.py line 20

Quoted 6 lines
tests/functional/test_virtio_gpu.py +1 -1
@@ -17,12 +16,12 @@
  import subprocess
-def pick_default_vug_bin():
+def pick_default_vug_bin(test):
      relative_path = "./contrib/vhost-user-gpu/vhost-user-gpu"
      if is_readable_executable_file(relative_path):
          return relative_path

I wonder whether we should drop the above two lines of special casing and always use the code below instead?

Quoted 4 lines

tests/functional/test_virtio_gpu.py line 24

Quoted 2 lines
tests/functional/test_virtio_gpu.py +1 -1
-    bld_dir_path = os.path.join(BUILD_DIR, relative_path)
+    bld_dir_path = test.build_file(relative_path)

... then you could also get rid of the hard-coded slashes in relative_path?

Hmmm, yes, the first check is rather redundant, will cull it.

Quoted 12 lines

tests/functional/test_virtio_gpu.py def test_vhost_user_vga_virgl(self): · line 88

Quoted 10 lines
tests/functional/test_virtio_gpu.py +1 -1
      if is_readable_executable_file(bld_dir_path):
          return bld_dir_path
@@ -85,7 +84,7 @@ def test_vhost_user_vga_virgl(self):
          # FIXME: should check presence of vhost-user-gpu, virgl, memfd etc
          self.require_accelerator('kvm')
-        vug = pick_default_vug_bin()
+        vug = pick_default_vug_bin(self)
          if not vug:
              self.skipTest("Could not find vhost-user-gpu")

Anyway:

Quoted 2 lines

With regards,
Daniel

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

Re: [PATCH 12/22] tests/functional: switch over to using self.scratch_file()

In reply to Thomas Huth
Quoted 15 lines · Thomas Huth
Quoted 13 lines · Daniel P. Berrangé

Replace any instances of

   os.path.join(self.workdir, ".../...")
   self.workdir + "/.../..."

with

   self.scratch_file("...", "...")

which is more compact and portable

---

...

Quoted 15 lines

tests/functional/qemu_test/linuxkernel.py def extract_from_deb(self, deb_path, path): · line 49

Quoted 13 lines
tests/functional/qemu_test/linuxkernel.py +1 -4
index 2b5b9a5fda..a6525f9dd6 100644
@@ -46,8 +46,7 @@ def extract_from_deb(self, deb_path, path):
          os.chdir(cwd)
          # Return complete path to extracted file.  Because callers to
          # extract_from_deb() specify 'path' with a leading slash, it is
-        # necessary to use os.path.relpath() as otherwise os.path.join()
-        # interprets it as an absolute path and drops the self.workdir part.
-        return os.path.normpath(os.path.join(self.workdir,
-                                             os.path.relpath(path, '/')))
+        # necessary to use 'relative_to()' to turn it into a relative

Here you mention "relative_to()" ....

Opps, traces of an aborted switch to pathlib there.

Quoted 6 lines

tests/functional/qemu_test/linuxkernel.py def extract_from_deb(self, deb_path, path): · line 51

Quoted 3 lines
tests/functional/qemu_test/linuxkernel.py +2 -0
+        # path for joining to the scratch dir
+        return os.path.normpath(self.scratch_file(os.path.relpath(path, '/')))

... but the code still uses relpath() instead?

Quoted 11 lines

tests/functional/test_aarch64_aspeed.py def test_aarch64_ast2700_evb_sdk_v09_02(self): · line 41

Quoted 8 lines
tests/functional/test_aarch64_aspeed.py +0 -1
index 59916efd71..c6c6b74acc 100644
@@ -39,26 +39,28 @@ def test_aarch64_ast2700_evb_sdk_v09_02(self):
          archive_extract(image_path, self.workdir)
          num_cpu = 4
-        image_dir = self.workdir + '/ast2700-default/'

I'd maybe just change image_dir and keep the code below as it is, so you can avoid specifying 'ast2700-default' again and again.

Yeah, there's a little repetititon, but I was aiming to avoid doing manual path concatenatation

Quoted 32 lines
Quoted 29 lines
tests/functional/test_aarch64_aspeed.py +8 -5
-        uboot_size = os.path.getsize(image_dir + 'u-boot-nodtb.bin')
+        uboot_size = os.path.getsize(self.scratch_file('ast2700-default',
+                                                       'u-boot-nodtb.bin'))
          uboot_dtb_load_addr = hex(0x400000000 + uboot_size)
          load_images_list = [
              {
                  'addr': '0x400000000',
-                'file': image_dir + 'u-boot-nodtb.bin'
+                'file': self.scratch_file('ast2700-default',
+                                          'u-boot-nodtb.bin')
              },
              {
                  'addr': str(uboot_dtb_load_addr),
-                'file': image_dir + 'u-boot.dtb'
+                'file': self.scratch_file('ast2700-default', 'u-boot.dtb')
              },
              {
                  'addr': '0x430000000',
-                'file': image_dir + 'bl31.bin'
+                'file': self.scratch_file('ast2700-default', 'bl31.bin')
              },
              {
                  'addr': '0x430080000',
-                'file': image_dir + 'optee/tee-raw.bin'
+                'file': self.scratch_file('ast2700-default', 'optee',
+                                          'tee-raw.bin')
              }
          ]
Quoted 15 lines

tests/functional/test_aarch64_raspi3.py def test_aarch64_raspi3_atf(self): · line 26

Quoted 13 lines
tests/functional/test_aarch64_raspi3.py +0 -1
index 369f95a3d9..98ed6f9d56 100755
@@ -7,7 +7,6 @@
  #
  # SPDX-License-Identifier: GPL-2.0-or-later
-import os
  from zipfile import ZipFile
  from qemu_test import LinuxKernelTest, Asset
@@ -26,7 +25,7 @@ def test_aarch64_raspi3_atf(self):
          with ZipFile(zip_path, 'r') as zf:
                       zf.extract(efi_name, path=self.workdir)

Should that self.workdir above get replaced with self.scratch_file(), too?

This comes later in the series, when I add helpers for archive extraction that avoid ned to refer to paths directly.

Quoted 9 lines

tests/functional/test_aarch64_raspi3.py def test_arm_ast2600_evb_buildroot_tpm(self): · line 229

Quoted 6 lines
tests/functional/test_aarch64_raspi3.py +3 -1
@@ -226,14 +226,16 @@ def test_arm_ast2600_evb_buildroot_tpm(self):
          image_path = self.ASSET_BR2_202302_AST2600_TPM_FLASH.fetch()
-        tpmstate_dir = tempfile.TemporaryDirectory(prefix="qemu_")
+        tpmstate_dir = self.scratch_file('swtpmstate')
+        os.mkdir(tpmstate_dir)
+        socket_dir = tempfile.TemporaryDirectory(prefix="qemu_")

You don't seem to use socket_dir in any of your changes below?

Quoted 4 lines

Also, shouldn't this rather be using self.socket_dir() now? (maybe rather something for a separate patch?)

Quoted 1 line
tests/functional/test_aarch64_raspi3.py +0 -0
          socket = os.path.join(tpmstate_dir.name, 'swtpm-socket')

This should have been 'socket_dir.name'

Quoted 23 lines
Quoted 21 lines
tests/functional/test_aarch64_raspi3.py +3 -3
          # We must put the TPM state dir in /tmp/, not the build dir,
          # because some distros use AppArmor to lock down swtpm and
          # restrict the set of locations it can access files in.
          subprocess.run(['swtpm', 'socket', '-d', '--tpm2',
-                        '--tpmstate', f'dir={tpmstate_dir.name}',
+                        '--tpmstate', f'dir={tpmstate_dir}',
                          '--ctrl', f'type=unixio,path={socket}'])
          self.vm.add_args('-chardev', f'socket,id=chrtpm,path={socket}')
@@ -274,7 +276,7 @@ def test_arm_ast2500_evb_sdk(self):
          archive_extract(image_path, self.workdir)
          self.do_test_arm_aspeed_sdk_start(
-            self.workdir + '/ast2500-default/image-bmc')
+            self.scratch_file('ast2500-default', 'image-bmc'))
          self.wait_for_console_pattern('ast2500-default login:')
@@ -294,7 +296,7 @@ def test_arm_ast2600_evb_sdk(self):
          self.vm.add_args('-device',
              'ds1338,bus=aspeed.i2c.bus.5,address=0x32');
          self.do_test_arm_aspeed_sdk_start(
-            self.workdir + '/ast2600-a2/image-bmc')
+            self.scratch_file('ast2600-a2', 'image-bmc'))
          self.wait_for_console_pattern('ast2600-a2 login:')

...

Quoted 2 lines

Thomas

With regards,
Daniel

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

Re: [PATCH 15/22] tests/functional: add common zip_extract helper

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

This mirrors the existing archive_extract and cpio_extract helpers

---
  tests/functional/qemu_test/utils.py | 7 +++++++
  1 file changed, 7 insertions(+)
Quoted 15 lines

tests/functional/qemu_test/utils.py def archive_extract(archive, dest_dir, member=None): · line 53

Quoted 13 lines
tests/functional/qemu_test/utils.py +6 -0
index 1bf1c410d5..41bd1df666 100644
@@ -46,6 +46,13 @@ def archive_extract(archive, dest_dir, member=None):
          else:
              tf.extractall(path=dest_dir)
+def zip_extract(archive, dest_dir, member=None):
+    with zipfile.ZipFile(archive, 'r') as zf:
+        if member:
+            zf.extract(member=member, path=dest_dir)
+        else:
+            zf.extractall(path=dest_dir)

Don't you need to "import zipfile" here now, too?

Yes, now I'm wondering how my testing passed - wonder if this is only being used from some skipped tests that I forgot to exercise.

With regards,
Daniel

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

Re: [PATCH 16/22] tests/functional: add common deb_extract helper

In reply to Thomas Huth
Quoted 26 lines · Thomas Huth
Quoted 14 lines · Daniel P. Berrangé

This mirrors the existing archive_extract, cpio_extract and zip_extract helpers

---
  tests/functional/qemu_test/linuxkernel.py | 15 +++++----------
  tests/functional/qemu_test/utils.py       | 13 +++++++++++++
  2 files changed, 18 insertions(+), 10 deletions(-)
tests/functional/qemu_test/linuxkernel.py +0 -0
index a6525f9dd6..fb6a158d36 100644
 

tests/functional/qemu_test/linuxkernel.py

Quoted 10 lines
tests/functional/qemu_test/linuxkernel.py +10 -0
+def deb_extract(archive, dest_dir, member=None):
+    cwd = os.getcwd()
+    os.chdir(dest_dir)
+    try:
+        (stdout, stderr, ret) = run_cmd(['ar', 't', archive])
+        file_path = stdout.split()[2]
+        run_cmd(['ar', 'x', archive, file_path])
+        archive_extract(file_path, dest_dir, member)
+    finally:
+        os.chdir(cwd)
Quoted 3 lines

Not sure whether we really need this ... extracting .deb files is very specific to running Linux kernels in the guest, so IMHO it should be sufficient to have it in linuxkernel.py.

You've probably seen the motivation in later patches now - the desire is to have a standardized "archive_extract" method that handles all types of archive, automatically setting the dest_dir to 'workdir'. I didn't want deb_extract to remain an exception to the pattern, because it is used quite widely.

Quoted 3 lines

Anyway, if we add more and more *_extract functions, we should maybe consider to move the extraction functions out of utils.py into an archive.py file, what do you think?

Yeah, good point. I temporarily forgot my general rule that files / dirs called 'util' end up being a general "dumping ground" for unrelated stuff, and more specialized files are a better idea.

With regards,
Daniel

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

Re: [PATCH 17/22] tests/functional: generalize archive_extract

In reply to Thomas Huth
Quoted 23 lines · Thomas Huth
Quoted 22 lines · Daniel P. Berrangé

There are many types of archives that the tests deal with, and 'archive_extract' suggests it can cope with any, rather than only tar files. Rename the existing method to 'tar_extract' and add a new method that can dynamically extract any zip, tar or cpio file based on file extension.

---
  tests/functional/qemu_test/utils.py | 31 +++++++++++++++++++++++++++--
  1 file changed, 29 insertions(+), 2 deletions(-)
tests/functional/qemu_test/utils.py +1 -0
index bafe7fb80e..8c1df8f8c2 100644
@@ -14,6 +14,7 @@
  import shutil
  import subprocess
  import tarfile
+import zipfile
  from .cmd import run_cmd
@@ -38,7 +39,33 @@ def image_pow2ceil_expand(path):
Quoted 8 lines

tests/functional/qemu_test/utils.py def image_pow2ceil_expand(path): · line 42

Quoted 4 lines
tests/functional/qemu_test/utils.py +1 -1
              with open(path, 'ab+') as fd:
                  fd.truncate(size_aligned)
-def archive_extract(archive, dest_dir, member=None):
+def archive_extract(archive, dest_dir, format=None, member=None):

Why not doing "if not format: format = guess_archive_format(archive)" here? Otherwise this helper function is rather useless - if you have to know the format, you could directly call the appropriate function anyway.

That's how I had things at first, but then I hit the problem that about 80% of the files we're extracting are cached assets, and the asset filenames are just a hash digest, so there's no file extension to query.

I guess I could make this work by pushing the Asset object instance right down into this method, rather than converting from Asset -> filename in the caller.

With regards,
Daniel

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

Re: [PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest

In reply to Thomas Huth
Quoted 61 lines · Thomas Huth
Quoted 47 lines · Daniel P. Berrangé

This helper wrappers utils.archive_extract, forcing the use of the scratch directory, to ensure any extracted files are cleaned at test termination. If a specific member is requested, then the path to the extracted file is also returned.

---
  tests/functional/qemu_test/testcase.py | 36 ++++++++++++++++++++++++++
  1 file changed, 36 insertions(+)
tests/functional/qemu_test/testcase.py +25 -0
index 2f32742387..31d06f0172 100644
@@ -28,6 +28,8 @@
  from .asset import Asset
  from .cmd import run_cmd
  from .config import BUILD_DIR
+from .utils import (archive_extract as utils_archive_extract,
+                    guess_archive_format)
  class QemuBaseTest(unittest.TestCase):
@@ -39,6 +41,40 @@ class QemuBaseTest(unittest.TestCase):
      log = None
      logdir = None
+    '''
+    @params archive: filename, Asset, or file-like object to extract
+    @params sub_dir: optional sub-directory to extract into
+    @params member: optional member file to limit extraction to
+
+    Extracts @archive into the scratch directory, or a
+    directory beneath named by @sub_dir. All files are
+    extracted unless @member specifies a limit.
+
+    If @member is non-None, returns the fully qualified
+    path to @member
+    '''
+    def archive_extract(self, archive, format=None, sub_dir=None, member=None):
+        if type(archive) == Asset:
+            if format is None:
+                format = guess_archive_format(archive.url)
+            archive = archive.fetch()
+        elif format is None:
+            format = guess_archive_format(archive)
+
+        if member is not None:
+            if os.path.isabs(member):
+                member = os.path.relpath(member, '/')

tests/functional/qemu_test/testcase.py class QemuBaseTest(unittest.TestCase): · line 75

Quoted 10 lines
tests/functional/qemu_test/testcase.py +10 -0
+
+        if sub_dir is None:
+            utils_archive_extract(archive, self.scratch_file(), format, member)
+        else:
+            utils_archive_extract(archive, self.scratch_file(sub_dir),
+                                  format, member)
+
+        if member is not None:
+            return self.scratch_file(member)
+        return None

Ah, ok, so the guessing is done here ...

Quoted 5 lines

But somehow it feels wrong to have a "archive_extract" function in the QemuBaseTest class that also does asset fetching under the hood.

Could you maybe rather move this into the asset.py file and rename the function to "fetch_and_extract()" to make it clearer what it does?

We can't move it into asset.py because not all callers are passing in an Asset object - there are some cases where we've just got a local file. eg when the asset we extracted contains other archives that need to be extracted.

Per comments on the previous patch though, I could push this logic down into the lower method.

With regards,
Daniel

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

Re: [PATCH 05/22] tests/functional: remove duplicated 'which' function impl

In reply to Daniel P. Berrangé
Quoted 26 lines · Daniel P. Berrangé
Quoted 16 lines · Thomas Huth
Quoted 9 lines · Daniel P. Berrangé

Put the 'which' function into shared code.

---
   tests/functional/qemu_test/__init__.py |  2 +-
   tests/functional/qemu_test/cmd.py      | 10 ++++++++++
   tests/functional/test_acpi_bits.py     | 13 +------------
   tests/functional/test_ppc64_hv.py      | 13 +------------
   4 files changed, 13 insertions(+), 25 deletions(-)

None of the callers really seem to be interested in the location of the command, only whether it is available in the $PATH or not ... so could we maybe rather drop this function and use the has_cmd() function everywhere instead?

Quoted 4 lines

Hmm, thinking about it twice - has_cmd() uses the "which" program internally, but AFAIK this program is optional in Linux installations nowadays ... so maybe it's still a good idea to move our Python which() to cmd.py, but has_cmd() should maybe rather be changed to use it, too?

This reminds me I meant to ask about 'has_cmd' - it looks rather over-engineered to me to be trying to invoke the command with args.

Quoted 5 lines

Perhaps there was some reason to check support for individual args in the past, but none of the current tests need that AFAICT.

So if anything I'd be looking to delete 'has_cmd' and 'has_cmds' entirely, and rely only on the pure python 'which'.

Deleting has_cmd is fine for me, too! Especially since this function already caused confusion in the past (see https://gitlab.com/qemu-project/qemu/-/commit/59d100243d23451e66d2274d34edab7be6dab473 ).

Thomas

#56 lore raw

Re: [PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest

In reply to Daniel P. Berrangé
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Thomas Huth
Quoted 47 lines · Daniel P. Berrangé

This helper wrappers utils.archive_extract, forcing the use of the scratch directory, to ensure any extracted files are cleaned at test termination. If a specific member is requested, then the path to the extracted file is also returned.

---
   tests/functional/qemu_test/testcase.py | 36 ++++++++++++++++++++++++++
   1 file changed, 36 insertions(+)
tests/functional/qemu_test/testcase.py +25 -0
index 2f32742387..31d06f0172 100644
@@ -28,6 +28,8 @@
   from .asset import Asset
   from .cmd import run_cmd
   from .config import BUILD_DIR
+from .utils import (archive_extract as utils_archive_extract,
+                    guess_archive_format)
   class QemuBaseTest(unittest.TestCase):
@@ -39,6 +41,40 @@ class QemuBaseTest(unittest.TestCase):
       log = None
       logdir = None
+    '''
+    @params archive: filename, Asset, or file-like object to extract
+    @params sub_dir: optional sub-directory to extract into
+    @params member: optional member file to limit extraction to
+
+    Extracts @archive into the scratch directory, or a
+    directory beneath named by @sub_dir. All files are
+    extracted unless @member specifies a limit.
+
+    If @member is non-None, returns the fully qualified
+    path to @member
+    '''
+    def archive_extract(self, archive, format=None, sub_dir=None, member=None):
+        if type(archive) == Asset:
+            if format is None:
+                format = guess_archive_format(archive.url)
+            archive = archive.fetch()
+        elif format is None:
+            format = guess_archive_format(archive)
+
+        if member is not None:
+            if os.path.isabs(member):
+                member = os.path.relpath(member, '/')

tests/functional/qemu_test/testcase.py class QemuBaseTest(unittest.TestCase): · line 75

Quoted 10 lines
tests/functional/qemu_test/testcase.py +10 -0
+
+        if sub_dir is None:
+            utils_archive_extract(archive, self.scratch_file(), format, member)
+        else:
+            utils_archive_extract(archive, self.scratch_file(sub_dir),
+                                  format, member)
+
+        if member is not None:
+            return self.scratch_file(member)
+        return None

Ah, ok, so the guessing is done here ...

But somehow it feels wrong to have a "archive_extract" function in the QemuBaseTest class that also does asset fetching under the hood.

Quoted 7 lines
Quoted 2 lines

Could you maybe rather move this into the asset.py file and rename the function to "fetch_and_extract()" to make it clearer what it does?

We can't move it into asset.py because not all callers are passing in an Asset object - there are some cases where we've just got a local file. eg when the asset we extracted contains other archives that need to be extracted.

Couldn't those spots rather use the function from utils.py directly for the second extraction?

Anyway, I guess now it's likely better to keep it here since you want to have access to self.scratch_file() in this function, too. But maybe you could still at least rename it to fetch_and_extract() to make it more obvious what it all about?

Thomas

Quoted 5 lines

Per comments on the previous patch though, I could push this logic down into the lower method.

With regards,
Daniel

#57 lore raw

Re: [PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest

Quoted 74 lines · Thomas Huth
Quoted 65 lines · Daniel P. Berrangé
Quoted 64 lines · Thomas Huth
Quoted 47 lines · Daniel P. Berrangé

This helper wrappers utils.archive_extract, forcing the use of the scratch directory, to ensure any extracted files are cleaned at test termination. If a specific member is requested, then the path to the extracted file is also returned.

---
   tests/functional/qemu_test/testcase.py | 36 ++++++++++++++++++++++++++
   1 file changed, 36 insertions(+)
tests/functional/qemu_test/testcase.py +25 -0
index 2f32742387..31d06f0172 100644
@@ -28,6 +28,8 @@
   from .asset import Asset
   from .cmd import run_cmd
   from .config import BUILD_DIR
+from .utils import (archive_extract as utils_archive_extract,
+                    guess_archive_format)
   class QemuBaseTest(unittest.TestCase):
@@ -39,6 +41,40 @@ class QemuBaseTest(unittest.TestCase):
       log = None
       logdir = None
+    '''
+    @params archive: filename, Asset, or file-like object to extract
+    @params sub_dir: optional sub-directory to extract into
+    @params member: optional member file to limit extraction to
+
+    Extracts @archive into the scratch directory, or a
+    directory beneath named by @sub_dir. All files are
+    extracted unless @member specifies a limit.
+
+    If @member is non-None, returns the fully qualified
+    path to @member
+    '''
+    def archive_extract(self, archive, format=None, sub_dir=None, member=None):
+        if type(archive) == Asset:
+            if format is None:
+                format = guess_archive_format(archive.url)
+            archive = archive.fetch()
+        elif format is None:
+            format = guess_archive_format(archive)
+
+        if member is not None:
+            if os.path.isabs(member):
+                member = os.path.relpath(member, '/')

tests/functional/qemu_test/testcase.py class QemuBaseTest(unittest.TestCase): · line 75

Quoted 10 lines
tests/functional/qemu_test/testcase.py +10 -0
+
+        if sub_dir is None:
+            utils_archive_extract(archive, self.scratch_file(), format, member)
+        else:
+            utils_archive_extract(archive, self.scratch_file(sub_dir),
+                                  format, member)
+
+        if member is not None:
+            return self.scratch_file(member)
+        return None

Ah, ok, so the guessing is done here ...

But somehow it feels wrong to have a "archive_extract" function in the QemuBaseTest class that also does asset fetching under the hood.

Quoted 7 lines
Quoted 2 lines

Could you maybe rather move this into the asset.py file and rename the function to "fetch_and_extract()" to make it clearer what it does?

We can't move it into asset.py because not all callers are passing in an Asset object - there are some cases where we've just got a local file. eg when the asset we extracted contains other archives that need to be extracted.

Quoted 7 lines

Couldn't those spots rather use the function from utils.py directly for the second extraction?

Anyway, I guess now it's likely better to keep it here since you want to have access to self.scratch_file() in this function, too.
But maybe you could still at least rename it to fetch_and_extract() to make it more obvious what it all about?

I wanted to de-emphasize the 'fetch' concept, to make use of assets look and work no different from local files.

In practice they are all local files, with no fetching taking place, as the test suite arranges for everything to be pre-fetched into the local cache. THe only time a "fetch" would ever happen during execution is if you had directly invoked a python file, with an empt ycache.

IOW, from the POV of the executing test case, an Asset object is no more than a wrapper around a local filename.

Hmm, in fact I wonder if we shouldn't implement the 'str' method to directly return the local filename, so we can pass Asset object instances to any method that expects a filename.

With regards,
Daniel

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

Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)

In reply to Thomas Huth
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Daniel P. Berrangé

This removes direct path manipulation to figure out the source dir

---
  tests/functional/test_acpi_bits.py | 22 +++++++---------------
  1 file changed, 7 insertions(+), 15 deletions(-)
tests/functional/test_acpi_bits.py +0 -2
index 4de5fae37e..948b134b16 100755
@@ -41,7 +41,6 @@
  import tempfile
  import zipfile
 
-from pathlib import Path
  from typing import (
      List,
      Optional,
@@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          self._vm = None
-        self._baseDir = None
 
Quoted 10 lines

tests/functional/test_acpi_bits.py def _print_log(self, log): · line 138

Quoted 10 lines
tests/functional/test_acpi_bits.py +1 -3
          self._debugcon_addr = '0x403'
          self._debugcon_log = 'debugcon-log.txt'
@@ -137,26 +135,22 @@ def _print_log(self, log):
      def copy_bits_config(self):
          """ copies the bios bits config file into bits.
          """
-        config_file = 'bits-cfg.txt'
-        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                       'bits-config')
+        bits_config_file = self.data_file('acpi-bits',

I do not understand, Where is data_file coming from? AFAICS its not there in QemuBaseTest or QemuSystemTest or unittest.TestCase
https://docs.python.org/3/library/unittest.html#unittest.TestCase

what am I missing or failing to see?

#34 lore raw

Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)

Quoted 43 lines · Ani Sinha
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Daniel P. Berrangé

This removes direct path manipulation to figure out the source dir

---
  tests/functional/test_acpi_bits.py | 22 +++++++---------------
  1 file changed, 7 insertions(+), 15 deletions(-)
tests/functional/test_acpi_bits.py +0 -2
index 4de5fae37e..948b134b16 100755
@@ -41,7 +41,6 @@
  import tempfile
  import zipfile
 
-from pathlib import Path
  from typing import (
      List,
      Optional,
@@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
      def __init__(self, *args, **kwargs):
          super().__init__(*args, **kwargs)
          self._vm = None
-        self._baseDir = None
 
Quoted 10 lines

tests/functional/test_acpi_bits.py def _print_log(self, log): · line 138

Quoted 10 lines
tests/functional/test_acpi_bits.py +1 -3
          self._debugcon_addr = '0x403'
          self._debugcon_log = 'debugcon-log.txt'
@@ -137,26 +135,22 @@ def _print_log(self, log):
      def copy_bits_config(self):
          """ copies the bios bits config file into bits.
          """
-        config_file = 'bits-cfg.txt'
-        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                       'bits-config')
+        bits_config_file = self.data_file('acpi-bits',

I do not understand, Where is data_file coming from? AFAICS its not there in QemuBaseTest or QemuSystemTest or unittest.TestCase
https://docs.python.org/3/library/unittest.html#unittest.TestCase

Quoted 1 line

what am I missing or failing to see?

It is coming from patch 6 :-)

With regards,
Daniel

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

Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)

Quoted 44 lines · Daniel P. Berrangé
Quoted 43 lines · Ani Sinha
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Daniel P. Berrangé

This removes direct path manipulation to figure out the source dir

---
   tests/functional/test_acpi_bits.py | 22 +++++++---------------
   1 file changed, 7 insertions(+), 15 deletions(-)
tests/functional/test_acpi_bits.py +0 -2
index 4de5fae37e..948b134b16 100755
@@ -41,7 +41,6 @@
   import tempfile
   import zipfile
 
-from pathlib import Path
   from typing import (
       List,
       Optional,
@@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
       def __init__(self, *args, **kwargs):
           super().__init__(*args, **kwargs)
           self._vm = None
-        self._baseDir = None
 
Quoted 10 lines

tests/functional/test_acpi_bits.py def _print_log(self, log): · line 138

Quoted 10 lines
tests/functional/test_acpi_bits.py +1 -3
           self._debugcon_addr = '0x403'
           self._debugcon_log = 'debugcon-log.txt'
@@ -137,26 +135,22 @@ def _print_log(self, log):
       def copy_bits_config(self):
           """ copies the bios bits config file into bits.
           """
-        config_file = 'bits-cfg.txt'
-        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                       'bits-config')
+        bits_config_file = self.data_file('acpi-bits',

I do not understand, Where is data_file coming from? AFAICS its not there in QemuBaseTest or QemuSystemTest or unittest.TestCase
https://docs.python.org/3/library/unittest.html#unittest.TestCase

Quoted 3 lines
Quoted 1 line

what am I missing or failing to see?

It is coming from patch 6 :-)

Sorry, my bad, I put Ani just on CC: for this patch here, but he was not on CC: on the others :-/

Thomas

#36 lore raw

Re: [PATCH 11/22] tests/functional: switch over to using self.data_file(...)

Quoted 46 lines · Thomas Huth
Quoted 44 lines · Daniel P. Berrangé
Quoted 43 lines · Ani Sinha
Quoted 27 lines · Thomas Huth
Quoted 25 lines · Daniel P. Berrangé

This removes direct path manipulation to figure out the source dir

---
   tests/functional/test_acpi_bits.py | 22 +++++++---------------
   1 file changed, 7 insertions(+), 15 deletions(-)
tests/functional/test_acpi_bits.py +0 -2
index 4de5fae37e..948b134b16 100755
@@ -41,7 +41,6 @@
   import tempfile
   import zipfile
 
-from pathlib import Path
   from typing import (
       List,
       Optional,
@@ -122,7 +121,6 @@ class AcpiBitsTest(QemuBaseTest): #pylint: disable=too-many-instance-attributes
       def __init__(self, *args, **kwargs):
           super().__init__(*args, **kwargs)
           self._vm = None
-        self._baseDir = None
 
Quoted 10 lines

tests/functional/test_acpi_bits.py def _print_log(self, log): · line 138

Quoted 10 lines
tests/functional/test_acpi_bits.py +1 -3
           self._debugcon_addr = '0x403'
           self._debugcon_log = 'debugcon-log.txt'
@@ -137,26 +135,22 @@ def _print_log(self, log):
       def copy_bits_config(self):
           """ copies the bios bits config file into bits.
           """
-        config_file = 'bits-cfg.txt'
-        bits_config_dir = os.path.join(self._baseDir, 'acpi-bits',
-                                       'bits-config')
+        bits_config_file = self.data_file('acpi-bits',

I do not understand, Where is data_file coming from? AFAICS its not there in QemuBaseTest or QemuSystemTest or unittest.TestCase
https://docs.python.org/3/library/unittest.html#unittest.TestCase

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

what am I missing or failing to see?

It is coming from patch 6 :-)

Sorry, my bad, I put Ani just on CC: for this patch here, but he was not on
CC: on the others :-/

Now it all makes sense :-)

Quoted 3 lines

Thomas

#25 lore raw

Re: [PATCH 08/22] tests/functional: add helpers for building file paths

In reply to Thomas Huth
Quoted 27 lines · Thomas Huth
Quoted 17 lines · Daniel P. Berrangé

Add helper methods that construct paths for

* log files - to be preserved at the end of a test
* scratch files - to be purged at the end of a test
* build files - anything relative to the build root
* data files - anything relative to the functional test source root
* socket files - a short temporary dir to avoid UNIX socket limits

These are to be used instead of direct access to the self.workdir, or self.logdir variables, or any other place where paths are built manually.

---
  tests/functional/qemu_test/testcase.py | 86 ++++++++++++++++++++++++++
  1 file changed, 86 insertions(+)

tests/functional/qemu_test/testcase.py class QemuBaseTest(unittest.TestCase): · line 128

Quoted 8 lines
tests/functional/qemu_test/testcase.py +5 -0
+    '''
+    def log_file(self, *args):
+        return str(Path(self.logdir, *args))
+
      def setUp(self, bin_prefix):
          self.assertIsNotNone(self.qemu_bin, 'QEMU_TEST_QEMU_BINARY must be set')
          self.arch = self.qemu_bin.split('-')[-1]
+        self.socketdir = None
Quoted 1 line

Should we also delete the socketdir during teardown again?

Yes, we should be purging this object and deleting the dir

With regards,
Daniel

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

Re: [PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest

In reply to Thomas Huth
Quoted 71 lines · Thomas Huth
Quoted 70 lines · Daniel P. Berrangé
Quoted 68 lines · Thomas Huth
Quoted 51 lines · Daniel P. Berrangé

This helper wrappers utils.archive_extract, forcing the use of the scratch directory, to ensure any extracted files are cleaned at test termination. If a specific member is requested, then the path to the extracted file is also returned.

---
   tests/functional/qemu_test/testcase.py | 36 ++++++++++++++++++++++++++

   1 file changed, 36 insertions(+)
tests/functional/qemu_test/testcase.py +0 -0
index 2f32742387..31d06f0172 100644
@@ -28,6 +28,8 @@

   from .asset import Asset
   from .cmd import run_cmd
   from .config import BUILD_DIR
+from .utils import (archive_extract as utils_archive_extract, +                    guess_archive_format)
   class QemuBaseTest(unittest.TestCase):

tests/functional/qemu_test/testcase.py +0 -0
@@ -39,6 +41,40 @@ class QemuBaseTest(unittest.TestCase):

       log = None
       logdir = None
+    '''
+    @params archive: filename, Asset, or file-like object to extract +    @params sub_dir: optional sub-directory to extract into +    @params member: optional member file to limit extraction to

tests/functional/qemu_test/testcase.py +9 -0
+
+    Extracts @archive into the scratch directory, or a
+    directory beneath named by @sub_dir. All files are
+    extracted unless @member specifies a limit.
+
+    If @member is non-None, returns the fully qualified
+    path to @member
+    '''
+    def archive_extract(self, archive, format=None, sub_dir=None, 

member=None):
+        if type(archive) == Asset:
+            if format is None:
+                format = guess_archive_format(archive.url) +            archive = archive.fetch()
+        elif format is None:
+            format = guess_archive_format(archive)

tests/functional/qemu_test/testcase.py +7 -0
+
+        if member is not None:
+            if os.path.isabs(member):
+                member = os.path.relpath(member, '/')
+
+        if sub_dir is None:
+            utils_archive_extract(archive, self.scratch_file(), format, 
Quoted 8 lines

member)
+        else:
+            utils_archive_extract(archive, self.scratch_file(sub_dir), +                                  format, member)
+
+        if member is not None:
+            return self.scratch_file(member)
+        return None

Ah, ok, so the guessing is done here ...

But somehow it feels wrong to have a "archive_extract" function in the QemuBaseTest class that also does asset fetching under the hood.

Could you maybe rather move this into the asset.py file and rename the function to "fetch_and_extract()" to make it clearer what it does?

Quoted 8 lines
Quoted 4 lines

We can't move it into asset.py because not all callers are passing in an Asset object - there are some cases where we've just got a local file. eg when the asset we extracted contains other archives that need to be extracted.

Couldn't those spots rather use the function from utils.py directly for the second extraction?

Anyway, I guess now it's likely better to keep it here since you want to have access to self.scratch_file() in this function, too.

FWIW, I think I just hit another reason for having the function in testcase.py: We want to skip tests if the download of an asset failed with a temporary server failure - for this we need a test object reference for calling skipTest(). Checking for HTTP errors within assets.py does not work since we cannot call skipTest() there without a reference to a test object. So please keep the function in testcase.py!

Thomas