qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Thomas Huth
Subject: Re: [PATCH 12/22] tests/functional: switch over to using self.scratch_file()
Date: Mon, 2 Dec 2024 10:56:32 +0100
User-agent: Mozilla Thunderbird

On 29/11/2024 18.31, Daniel P. Berrangé wrote:
Replace any instances of

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

with

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

which is more compact and portable

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
...
diff --git a/tests/functional/qemu_test/linuxkernel.py 
b/tests/functional/qemu_test/linuxkernel.py
index 2b5b9a5fda..a6525f9dd6 100644
--- a/tests/functional/qemu_test/linuxkernel.py
+++ b/tests/functional/qemu_test/linuxkernel.py
@@ -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()" ....

+        # 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?

diff --git a/tests/functional/test_aarch64_aspeed.py 
b/tests/functional/test_aarch64_aspeed.py
index 59916efd71..c6c6b74acc 100644
--- a/tests/functional/test_aarch64_aspeed.py
+++ b/tests/functional/test_aarch64_aspeed.py
@@ -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.

-        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:') diff --git a/tests/functional/test_aarch64_raspi3.py b/tests/functional/test_aarch64_raspi3.py
index 369f95a3d9..98ed6f9d56 100755
--- a/tests/functional/test_aarch64_raspi3.py
+++ b/tests/functional/test_aarch64_raspi3.py
@@ -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?

-        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)
...
diff --git a/tests/functional/test_arm_aspeed.py 
b/tests/functional/test_arm_aspeed.py
index db872ff05e..c4869011db 100755
--- a/tests/functional/test_arm_aspeed.py
+++ b/tests/functional/test_arm_aspeed.py
@@ -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_")

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?)

          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:')
...

 Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]