Message ID | 20240124164855.2564824-2-vkuznets@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] KVM: selftests: Avoid infinite loop in hyperv_features when invtsc is missing | expand |
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.
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); + TEST_ASSERT(fd >= 0, "%s not available (errno: %d)", path, errno); return fd; }
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(-)