From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: qemu-devel@nongnu.org,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [PATCH 12/22] tests/functional: switch over to using self.scratch_file()
Date: Mon, 2 Dec 2024 12:03:30 +0000 [thread overview]
Message-ID: <Z02iEnx_abqr6PL_@redhat.com> (raw)
In-Reply-To: <575eb674-7b07-40c0-a537-da34549edcd2@redhat.com>
On Mon, Dec 02, 2024 at 10:56:32AM +0100, Thomas Huth wrote:
> 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()" ....
Opps, traces of an aborted switch to pathlib there.
>
> > + # 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.
Yeah, there's a little repetititon, but I was aiming to avoid doing
manual path concatenatation
>
> > - 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')
> > }
> > ]
> > 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?
This comes later in the series, when I add helpers for archive extraction
that avoid ned to refer to paths directly.
> > @@ -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')
This should have been 'socket_dir.name'
> > # 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
>
With regards,
Daniel
--
|: 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 :|
next prev parent reply other threads:[~2024-12-02 12:04 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-29 17:30 [PATCH 00/22 for 10.0] tests/functional: various improvements wrt assets/scratch files Daniel P. Berrangé
2024-11-29 17:30 ` [PATCH 01/22] tests/functional: increase timeouts for arm sx1 test Daniel P. Berrangé
2024-11-30 9:55 ` Thomas Huth
2024-11-29 17:31 ` [PATCH 02/22] tests/functional: remove unused system imports Daniel P. Berrangé
2024-11-30 9:59 ` Thomas Huth
2024-12-02 9:22 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 03/22] tests/functional: remove duplicated 'qemu_test' import statements Daniel P. Berrangé
2024-11-30 10:09 ` Thomas Huth
2024-12-02 11:40 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 04/22] tests/functional: remove pointless with statement Daniel P. Berrangé
2024-11-30 10:10 ` Thomas Huth
2024-11-29 17:31 ` [PATCH 05/22] tests/functional: remove duplicated 'which' function impl Daniel P. Berrangé
2024-11-30 10:16 ` Thomas Huth
2024-12-02 11:44 ` Daniel P. Berrangé
2024-12-02 12:45 ` Thomas Huth
2024-11-30 15:08 ` Richard Henderson
2024-12-02 11:45 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 06/22] tests/functional: introduce some helpful decorators Daniel P. Berrangé
2024-12-02 8:27 ` Thomas Huth
2024-12-02 11:49 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 07/22] tests/functional: switch to new test skip decorators Daniel P. Berrangé
2024-12-02 8:57 ` Thomas Huth
2024-12-02 11:51 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 08/22] tests/functional: add helpers for building file paths Daniel P. Berrangé
2024-12-02 9:19 ` Thomas Huth
2024-12-03 13:53 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 09/22] tests/functional: switch over to using self.log_file(...) Daniel P. Berrangé
2024-12-02 9:22 ` Thomas Huth
2024-11-29 17:31 ` [PATCH 10/22] tests/functional: switch over to using self.build_file(...) Daniel P. Berrangé
2024-12-02 9:26 ` Thomas Huth
2024-12-02 12:00 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 11/22] tests/functional: switch over to using self.data_file(...) Daniel P. Berrangé
2024-12-02 9:32 ` Thomas Huth
2024-12-03 5:39 ` Ani Sinha
2024-12-03 8:11 ` Daniel P. Berrangé
2024-12-03 8:50 ` Thomas Huth
2024-12-03 9:05 ` Ani Sinha
2024-11-29 17:31 ` [PATCH 12/22] tests/functional: switch over to using self.scratch_file() Daniel P. Berrangé
2024-12-02 9:56 ` Thomas Huth
2024-12-02 12:03 ` Daniel P. Berrangé [this message]
2024-11-29 17:31 ` [PATCH 13/22] tests/functional: switch over to using self.socket_dir(...) Daniel P. Berrangé
2024-12-02 9:59 ` Thomas Huth
2024-11-29 17:31 ` [PATCH 14/22] tests/functional: remove redundant 'rmtree' call Daniel P. Berrangé
2024-11-30 10:32 ` Thomas Huth
2024-11-29 17:31 ` [PATCH 15/22] tests/functional: add common zip_extract helper Daniel P. Berrangé
2024-12-02 10:04 ` Thomas Huth
2024-12-02 12:04 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 16/22] tests/functional: add common deb_extract helper Daniel P. Berrangé
2024-12-02 10:14 ` Thomas Huth
2024-12-02 12:08 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 17/22] tests/functional: generalize archive_extract Daniel P. Berrangé
2024-12-02 10:20 ` Thomas Huth
2024-12-02 12:11 ` Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 18/22] tests/functional: add 'archive_extract' to QemuBaseTest Daniel P. Berrangé
2024-12-02 10:30 ` Thomas Huth
2024-12-02 12:13 ` Daniel P. Berrangé
2024-12-02 12:52 ` Thomas Huth
2024-12-02 13:28 ` Daniel P. Berrangé
2024-12-06 13:10 ` Thomas Huth
2024-11-29 17:31 ` [PATCH 19/22] tests/functional: convert tests to new archive_extract helper Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 20/22] tests/functional: generalize uncompress Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 21/22] tests/functional: add 'uncompress' to QemuBaseTest Daniel P. Berrangé
2024-11-29 17:31 ` [PATCH 22/22] tests/functional: convert tests to new uncompress helper Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z02iEnx_abqr6PL_@redhat.com \
--to=berrange@redhat.com \
--cc=alex.bennee@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).