All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "QEMU Developers" <qemu-devel@nongnu.org>,
	"Thomas Huth" <thuth@redhat.com>,
	"Phil Mathieu-Daudé" <philmd@linaro.org>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>
Subject: Re: should the functional-testing scratch_file() utility guarantee that the path it returns doesn't exist?
Date: Mon, 8 Sep 2025 14:42:34 +0100	[thread overview]
Message-ID: <aL7dSumeu9RI6-5O@redhat.com> (raw)
In-Reply-To: <CAFEAcA9kGOre7sWjjEi1jAGkkNB4EVQnvq3u5fY79HZjSzSZHQ@mail.gmail.com>

On Mon, Sep 08, 2025 at 02:13:54PM +0100, Peter Maydell wrote:
> The functional testing framework includes a utility function
> scratch_file() which you can use to get a path for a scratch
> file to use in the test. However, it doesn't do anything to
> ensure that the path it returns doesn't already exist.
> Should it?

No, we need to be able to use scratch_file() to refer to
previously created resources. For example, when we extract
files from an archive, we want to then reference those, or
when we uncompress a file.

> I ran into this with the aarch64/test_rme_sbsaref.py test:
> this does:
>         rme_stack = self.scratch_file('.')
> to get a scratch path, and then uses it both to place
> specific files:
>         pflash0 = join(rme_stack, 'out', 'SBSA_FLASH0.fd')
> and to place subdirectories:
>         efi = join(rme_stack, 'out', 'EFI')
>         os.makedirs(efi, exist_ok=True)
> 
> In the original version of this test we used os.mkdir(efi),
> but this fails sometimes because the directory already exists
> (typically if the test was interrupted during a previous run);
> see this email for the error log:
> https://lore.kernel.org/qemu-devel/CAFEAcA_ZQ13qMRUQsieJiEPV=ULrDbz8=EJaW4_kw=yEysob0w@mail.gmail.co/m

We have a tearDown function which purges everything under the
scratch dir location, so if a test is interrupted in a "normal"
way we should be safe on re-run. Only if python is hard-terminated
would the tearDown method fail to get run.

Perhaps we should proactively purge the scratch location in
the setUp method too, as a safety net against previous unclean
shutdown, as the intent of the 'scratch file' concept is that
the test should have a clean environment when it starts running.


> Secondary question: is it OK to pass '.' to this function
> and then construct filenames based on the return value,
> or would it be better to call scratch_file('out', 'SBSA_FLASH0.fd')
> etc and have the utility function construct the whole path?

My recommendation  / preferred coding style for func tests is to
always pass the set of sub-dir/file components to scratch_file(),
and never try to manually construct file paths using 'join'.

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 :|



  reply	other threads:[~2025-09-08 13:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08 13:13 should the functional-testing scratch_file() utility guarantee that the path it returns doesn't exist? Peter Maydell
2025-09-08 13:42 ` Daniel P. Berrangé [this message]
2025-09-08 13:48   ` Peter Maydell

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=aL7dSumeu9RI6-5O@redhat.com \
    --to=berrange@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.