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

Replace any instances of

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

with

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

which is more compact and portable

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20241217155953.3950506-15-berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Daniel P. Berrangé
2024-12-17 19:39:53 +01:00
committed by Thomas Huth
parent bd96e460d3
commit beaf88c895
45 changed files with 118 additions and 139 deletions
+3 -4
View File
@@ -46,8 +46,7 @@ class LinuxKernelTest(QemuSystemTest):
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 os.path.relpath() as otherwise scratch_file()
# interprets it as an absolute path and drops the required prefix
return os.path.normpath(self.scratch_file(os.path.relpath(path, '/')))
+1 -1
View File
@@ -74,7 +74,7 @@ class TuxRunBaselineTest(QemuSystemTest):
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(['zstd', "-f", "-d", disk_image_zst,
"-o", disk_image])
+10 -7
View File
@@ -38,26 +38,28 @@ class AST2x00MachineSDK(QemuSystemTest):
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')
}
]
@@ -74,7 +76,8 @@ class AST2x00MachineSDK(QemuSystemTest):
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:')
+1 -2
View File
@@ -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 @@ class Aarch64Raspi3Machine(LinuxKernelTest):
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)
+1 -3
View File
@@ -5,8 +5,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
@@ -64,7 +62,7 @@ class Aarch64Raspi4Machine(LinuxKernelTest):
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')
+2 -4
View File
@@ -8,8 +8,6 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
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
@@ -32,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]:
+1 -2
View File
@@ -11,7 +11,6 @@
# SPDX-License-Identifier: GPL-2.0-or-later
import time
import os
import logging
from qemu_test import QemuSystemTest, Asset
@@ -95,7 +94,7 @@ class Aarch64VirtMachine(QemuSystemTest):
# 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'])
+23 -26
View File
@@ -135,9 +135,9 @@ class AcpiBitsTest(QemuSystemTest): #pylint: disable=too-many-instance-attribute
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')
target_config_dir = self.scratch_file('bits-%d' %
self.BITS_INTERNAL_VER,
'boot')
self.assertTrue(os.path.exists(bits_config_file))
self.assertTrue(os.path.exists(target_config_dir))
shutil.copy2(bits_config_file, target_config_dir)
@@ -148,9 +148,8 @@ class AcpiBitsTest(QemuSystemTest): #pylint: disable=too-many-instance-attribute
"""copies the python test scripts into bits. """
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')
target_test_dir = self.scratch_file('bits-%d' % self.BITS_INTERNAL_VER,
'boot', 'python')
self.assertTrue(os.path.exists(bits_test_dir))
self.assertTrue(os.path.exists(target_test_dir))
@@ -187,8 +186,8 @@ class AcpiBitsTest(QemuSystemTest): #pylint: disable=too-many-instance-attribute
the directory where we have extracted our pre-built bits grub
tarball.
"""
grub_x86_64_mods = os.path.join(self.workdir, 'grub-inst-x86_64-efi')
grub_i386_mods = os.path.join(self.workdir, 'grub-inst')
grub_x86_64_mods = self.scratch_file('grub-inst-x86_64-efi')
grub_i386_mods = self.scratch_file('grub-inst')
self.assertTrue(os.path.exists(grub_x86_64_mods))
self.assertTrue(os.path.exists(grub_i386_mods))
@@ -209,13 +208,11 @@ class AcpiBitsTest(QemuSystemTest): #pylint: disable=too-many-instance-attribute
""" Uses grub-mkrescue to generate a fresh bits iso with the python
test scripts
"""
bits_dir = os.path.join(self.workdir,
'bits-%d' %self.BITS_INTERNAL_VER)
iso_file = os.path.join(self.workdir,
'bits-%d.iso' %self.BITS_INTERNAL_VER)
mkrescue_script = os.path.join(self.workdir,
'grub-inst-x86_64-efi', 'bin',
'grub-mkrescue')
bits_dir = self.scratch_file('bits-%d' % self.BITS_INTERNAL_VER)
iso_file = self.scratch_file('bits-%d.iso' % self.BITS_INTERNAL_VER)
mkrescue_script = self.scratch_file('grub-inst-x86_64-efi',
'bin',
'grub-mkrescue')
self.assertTrue(os.access(mkrescue_script,
os.R_OK | os.W_OK | os.X_OK))
@@ -250,17 +247,18 @@ class AcpiBitsTest(QemuSystemTest): #pylint: disable=too-many-instance-attribute
super().setUp()
self.logger = self.log
prebuiltDir = os.path.join(self.workdir, 'prebuilt')
prebuiltDir = self.scratch_file('prebuilt')
if not os.path.isdir(prebuiltDir):
os.mkdir(prebuiltDir, mode=0o775)
bits_zip_file = os.path.join(prebuiltDir, 'bits-%d-%s.zip'
%(self.BITS_INTERNAL_VER,
self.BITS_COMMIT_HASH))
grub_tar_file = os.path.join(prebuiltDir,
'bits-%d-%s-grub.tar.gz'
%(self.BITS_INTERNAL_VER,
self.BITS_COMMIT_HASH))
bits_zip_file = self.scratch_file('prebuilt',
'bits-%d-%s.zip'
%(self.BITS_INTERNAL_VER,
self.BITS_COMMIT_HASH))
grub_tar_file = self.scratch_file('prebuilt',
'bits-%d-%s-grub.tar.gz'
%(self.BITS_INTERNAL_VER,
self.BITS_COMMIT_HASH))
bitsLocalArtLoc = self.ASSET_BITS.fetch()
self.logger.info("downloaded bits artifacts to %s", bitsLocalArtLoc)
@@ -284,7 +282,7 @@ class AcpiBitsTest(QemuSystemTest): #pylint: disable=too-many-instance-attribute
"""parse the log generated by running bits tests and
check for failures.
"""
debugconf = os.path.join(self.workdir, self._debugcon_log)
debugconf = self.scratch_file(self._debugcon_log)
log = ""
with open(debugconf, 'r', encoding='utf-8') as filehandle:
log = filehandle.read()
@@ -316,8 +314,7 @@ class AcpiBitsTest(QemuSystemTest): #pylint: disable=too-many-instance-attribute
"""The main test case implementation."""
self.set_machine('pc')
iso_file = os.path.join(self.workdir,
'bits-%d.iso' %self.BITS_INTERNAL_VER)
iso_file = self.scratch_file('bits-%d.iso' % self.BITS_INTERNAL_VER)
self.assertTrue(os.access(iso_file, os.R_OK))
+1 -3
View File
@@ -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 @@ class AlphaClipperTest(LinuxKernelTest):
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()
+2 -4
View File
@@ -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 zipfile import ZipFile
@@ -27,7 +25,7 @@ class AST1030Machine(LinuxKernelTest):
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')
@@ -49,7 +47,7 @@ class AST1030Machine(LinuxKernelTest):
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')
+1 -1
View File
@@ -50,7 +50,7 @@ class AST2500Machine(AspeedTest):
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:')
+1 -1
View File
@@ -114,7 +114,7 @@ class AST2600Machine(AspeedTest):
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:')
+1 -2
View File
@@ -6,7 +6,6 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
import os
import bz2
from qemu_test import QemuUserTest, Asset
@@ -25,7 +24,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)
+3 -3
View File
@@ -68,7 +68,7 @@ class BananaPiMachine(LinuxKernelTest):
'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 @@ class BananaPiMachine(LinuxKernelTest):
'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 @@ class BananaPiMachine(LinuxKernelTest):
# 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)
+2 -1
View File
@@ -31,7 +31,8 @@ class CanonA1100Machine(QemuSystemTest):
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')
+3 -3
View File
@@ -44,7 +44,7 @@ class CubieboardMachine(LinuxKernelTest):
dtb_path = '/usr/lib/linux-image-6.6.16-current-sunxi/sun4i-a10-cubieboard.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()
@@ -78,7 +78,7 @@ class CubieboardMachine(LinuxKernelTest):
dtb_path = self.extract_from_deb(deb_path, dtb_path)
rootfs_path_gz = self.ASSET_SATA_ROOTFS.fetch()
rootfs_path = os.path.join(self.workdir, 'rootfs.cpio')
rootfs_path = self.scratch_file('rootfs.cpio')
gzip_uncompress(rootfs_path_gz, rootfs_path)
self.vm.set_console()
@@ -112,7 +112,7 @@ class CubieboardMachine(LinuxKernelTest):
# to 126 MiB.
self.set_machine('cubieboard')
image_path_gz = self.ASSET_OPENWRT.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)
+1 -1
View File
@@ -28,7 +28,7 @@ class EmcraftSf2Machine(LinuxKernelTest):
uboot_path = self.ASSET_UBOOT.fetch()
spi_path = self.ASSET_SPI.fetch()
spi_path_rw = os.path.join(self.workdir, 'spi.bin')
spi_path_rw = self.scratch_file('spi.bin')
shutil.copy(spi_path, spi_path_rw)
os.chmod(spi_path_rw, 0o600)
+1 -2
View File
@@ -12,7 +12,6 @@
#
# SPDX-License-Identifier: GPL-2.0-or-later
import os
import logging
from qemu_test import QemuSystemTest, Asset
@@ -67,7 +66,7 @@ class IntegratorMachine(QemuSystemTest):
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()
+4 -4
View File
@@ -77,7 +77,7 @@ class BananaPiMachine(LinuxKernelTest):
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 @@ class BananaPiMachine(LinuxKernelTest):
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 @@ class BananaPiMachine(LinuxKernelTest):
# 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 @@ class BananaPiMachine(LinuxKernelTest):
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
+1 -3
View File
@@ -7,8 +7,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
@@ -65,7 +63,7 @@ class ArmRaspi2Machine(LinuxKernelTest):
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')

Some files were not shown because too many files have changed in this diff Show More