Skip to content

Commit 6e1cce7

Browse files
committed
KVM: selftests: Add __open_path_or_exit() variant to provide extra help info
Add an inner __open_path_or_exit() API to let the caller provide additional information on ENOENT to try and help the user figure out why the test is being skipped, e.g. for files like the page_idle bitmap needed by the access tracking perf, which is dependent on a Kconfig. Immediately convert /dev/kvm to the new API, both as an example and because users might not know that some architectures/setups require loading KVM. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent fcab107 commit 6e1cce7

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

tools/testing/selftests/kvm/include/kvm_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ struct vm_guest_mode_params {
253253
};
254254
extern const struct vm_guest_mode_params vm_guest_mode_params[];
255255

256+
int __open_path_or_exit(const char *path, int flags, const char *enoent_help);
256257
int open_path_or_exit(const char *path, int flags);
257258
int open_kvm_dev_path_or_exit(void);
258259

tools/testing/selftests/kvm/lib/kvm_util.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,26 @@ static uint32_t last_guest_seed;
2626

2727
static int vcpu_mmap_sz(void);
2828

29-
int open_path_or_exit(const char *path, int flags)
29+
int __open_path_or_exit(const char *path, int flags, const char *enoent_help)
3030
{
3131
int fd;
3232

3333
fd = open(path, flags);
34-
__TEST_REQUIRE(fd >= 0 || errno != ENOENT, "Cannot open %s: %s", path, strerror(errno));
35-
TEST_ASSERT(fd >= 0, "Failed to open '%s'", path);
34+
if (fd < 0)
35+
goto error;
3636

3737
return fd;
38+
39+
error:
40+
if (errno == ENOENT)
41+
ksft_exit_skip("- Cannot open '%s': %s. %s\n",
42+
path, strerror(errno), enoent_help);
43+
TEST_FAIL("Failed to open '%s'", path);
44+
}
45+
46+
int open_path_or_exit(const char *path, int flags)
47+
{
48+
return __open_path_or_exit(path, flags, "");
3849
}
3950

4051
/*
@@ -48,7 +59,7 @@ int open_path_or_exit(const char *path, int flags)
4859
*/
4960
static int _open_kvm_dev_path_or_exit(int flags)
5061
{
51-
return open_path_or_exit(KVM_DEV_PATH, flags);
62+
return __open_path_or_exit(KVM_DEV_PATH, flags, "Is KVM loaded and enabled?");
5263
}
5364

5465
int open_kvm_dev_path_or_exit(void)

0 commit comments

Comments
 (0)