From: Sean Christopherson <seanjc@google.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH 2/2] KVM: selftests: Fail tests when open() fails with !ENOENT
Date: Wed, 24 Jan 2024 09:28:34 -0800 [thread overview]
Message-ID: <ZbFIwjfgWiv9XrDO@google.com> (raw)
In-Reply-To: <20240124164855.2564824-2-vkuznets@redhat.com>
On Wed, Jan 24, 2024, Vitaly Kuznetsov wrote:
> open_path_or_exit() is used for '/dev/kvm', '/dev/sev', and
> '/sys/module/%s/parameters/%s' and skipping test when the entry is missing
> is completely reasonable. Other errors, however, may indicate a real issue
> which is easy to miss. E.g. when 'hyperv_features' test was entering an
> infinite loop the output was:
>
> ./hyperv_features
> Testing access to Hyper-V specific MSRs
> 1..0 # SKIP - /dev/kvm not available (errno: 24)
>
> and this can easily get overlooked.
>
> Keep ENOENT case 'special' for skipping tests and fail when open() results
> in any other errno.
>
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
> tools/testing/selftests/kvm/lib/kvm_util.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c
> index e066d584c656..f3dfd0d38b7f 100644
> --- a/tools/testing/selftests/kvm/lib/kvm_util.c
> +++ b/tools/testing/selftests/kvm/lib/kvm_util.c
> @@ -27,7 +27,8 @@ int open_path_or_exit(const char *path, int flags)
> int fd;
>
> fd = open(path, flags);
> - __TEST_REQUIRE(fd >= 0, "%s not available (errno: %d)", path, errno);
> + __TEST_REQUIRE(fd >= 0 || errno != ENOENT, "%s not present", path);
Rather than make up our own error messages, can we use strerror()?
> + TEST_ASSERT(fd >= 0, "%s not available (errno: %d)", path, errno);
And then here just say "Failed to open '%s'" and let test_assert() fill in the
strerror() information.
prev parent reply other threads:[~2024-01-24 17:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-24 16:48 [PATCH 1/2] KVM: selftests: Avoid infinite loop in hyperv_features when invtsc is missing Vitaly Kuznetsov
2024-01-24 16:48 ` [PATCH 2/2] KVM: selftests: Fail tests when open() fails with !ENOENT Vitaly Kuznetsov
2024-01-24 17:28 ` Sean Christopherson [this message]
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=ZbFIwjfgWiv9XrDO@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=vkuznets@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