KVM: selftests: Use consistent message for test skipping
authorAndrew Jones <drjones@redhat.com>
Tue, 10 Mar 2020 09:15:56 +0000 (10:15 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Mon, 16 Mar 2020 16:59:05 +0000 (17:59 +0100)
Signed-off-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
18 files changed:
tools/testing/selftests/kvm/demand_paging_test.c
tools/testing/selftests/kvm/dirty_log_test.c
tools/testing/selftests/kvm/include/test_util.h
tools/testing/selftests/kvm/lib/assert.c
tools/testing/selftests/kvm/lib/kvm_util.c
tools/testing/selftests/kvm/lib/test_util.c
tools/testing/selftests/kvm/lib/x86_64/svm.c
tools/testing/selftests/kvm/lib/x86_64/vmx.c
tools/testing/selftests/kvm/s390x/memop.c
tools/testing/selftests/kvm/s390x/sync_regs_test.c
tools/testing/selftests/kvm/x86_64/cr4_cpuid_sync_test.c
tools/testing/selftests/kvm/x86_64/evmcs_test.c
tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c
tools/testing/selftests/kvm/x86_64/mmio_warning_test.c
tools/testing/selftests/kvm/x86_64/platform_info_test.c
tools/testing/selftests/kvm/x86_64/sync_regs_test.c
tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c
tools/testing/selftests/kvm/x86_64/xss_msr_test.c

index 8d99b6d..c4fc96b 100644 (file)
@@ -660,8 +660,8 @@ int main(int argc, char *argv[])
 
 int main(void)
 {
-        printf("skip: Skipping userfaultfd test (missing __NR_userfaultfd)\n");
-        return KSFT_SKIP;
+       print_skip("__NR_userfaultfd must be present for userfaultfd test");
+       return KSFT_SKIP;
 }
 
 #endif /* __NR_userfaultfd */
index 8a79f5d..051791e 100644 (file)
@@ -437,8 +437,7 @@ int main(int argc, char *argv[])
        dirty_log_manual_caps =
                kvm_check_cap(KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2);
        if (!dirty_log_manual_caps) {
-               fprintf(stderr, "KVM_CLEAR_DIRTY_LOG not available, "
-                               "skipping tests\n");
+               print_skip("KVM_CLEAR_DIRTY_LOG not available");
                exit(KSFT_SKIP);
        }
        dirty_log_manual_caps &= (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE |
index 0782374..1e1487a 100644 (file)
@@ -32,6 +32,8 @@ static inline int _no_printf(const char *format, ...) { return 0; }
 #define pr_info(...) _no_printf(__VA_ARGS__)
 #endif
 
+void print_skip(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
+
 ssize_t test_write(int fd, const void *buf, size_t count);
 ssize_t test_read(int fd, void *buf, size_t count);
 int test_seq_read(const char *path, char **bufp, size_t *sizep);
index d1cf9f6..5ebbd0d 100644 (file)
@@ -82,8 +82,10 @@ test_assert(bool exp, const char *exp_str,
                }
                va_end(ap);
 
-               if (errno == EACCES)
-                       ksft_exit_skip("Access denied - Exiting.\n");
+               if (errno == EACCES) {
+                       print_skip("Access denied - Exiting");
+                       exit(KSFT_SKIP);
+               }
                exit(254);
        }
 
index b29c5d3..aa76972 100644 (file)
@@ -92,7 +92,7 @@ static void vm_open(struct kvm_vm *vm, int perm)
                exit(KSFT_SKIP);
 
        if (!kvm_check_cap(KVM_CAP_IMMEDIATE_EXIT)) {
-               fprintf(stderr, "immediate_exit not available, skipping test\n");
+               print_skip("immediate_exit not available");
                exit(KSFT_SKIP);
        }
 
index 1c0d45a..26fb3d7 100644 (file)
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <ctype.h>
 #include <limits.h>
+#include <assert.h>
 #include "test_util.h"
 
 /*
@@ -69,3 +70,14 @@ struct timespec timespec_diff(struct timespec start, struct timespec end)
 
        return temp;
 }
+
+void print_skip(const char *fmt, ...)
+{
+       va_list ap;
+
+       assert(fmt);
+       va_start(ap, fmt);
+       vprintf(fmt, ap);
+       va_end(ap);
+       puts(", skipping test");
+}
index 6e05a8f..c424010 100644 (file)
@@ -154,7 +154,7 @@ void nested_svm_check_supported(void)
                kvm_get_supported_cpuid_entry(0x80000001);
 
        if (!(entry->ecx & CPUID_SVM)) {
-               fprintf(stderr, "nested SVM not enabled, skipping test\n");
+               print_skip("nested SVM not enabled");
                exit(KSFT_SKIP);
        }
 }
index 7aaa99c..ff0a657 100644 (file)
@@ -381,7 +381,7 @@ void nested_vmx_check_supported(void)
        struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1);
 
        if (!(entry->ecx & CPUID_VMX)) {
-               fprintf(stderr, "nested VMX not enabled, skipping test\n");
+               print_skip("nested VMX not enabled");
                exit(KSFT_SKIP);
        }
 }
index 9edaa9a..9f49ead 100644 (file)
@@ -40,7 +40,7 @@ int main(int argc, char *argv[])
 
        maxsize = kvm_check_cap(KVM_CAP_S390_MEM_OP);
        if (!maxsize) {
-               fprintf(stderr, "CAP_S390_MEM_OP not supported -> skip test\n");
+               print_skip("CAP_S390_MEM_OP not supported");
                exit(KSFT_SKIP);
        }
        if (maxsize > sizeof(mem1))
index 70a5658..5731ccf 100644 (file)
@@ -86,7 +86,7 @@ int main(int argc, char *argv[])
 
        cap = kvm_check_cap(KVM_CAP_SYNC_REGS);
        if (!cap) {
-               fprintf(stderr, "CAP_SYNC_REGS not supported, skipping test\n");
+               print_skip("CAP_SYNC_REGS not supported");
                exit(KSFT_SKIP);
        }
 
index 003d142..a646843 100644 (file)
@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
 
        entry = kvm_get_supported_cpuid_entry(1);
        if (!(entry->ecx & X86_FEATURE_XSAVE)) {
-               printf("XSAVE feature not supported, skipping test\n");
+               print_skip("XSAVE feature not supported");
                return 0;
        }
 
index 464a552..15241dc 100644 (file)
@@ -87,7 +87,7 @@ int main(int argc, char *argv[])
 
        if (!kvm_check_cap(KVM_CAP_NESTED_STATE) ||
            !kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) {
-               printf("capabilities not available, skipping test\n");
+               print_skip("capabilities not available");
                exit(KSFT_SKIP);
        }
 
index 3edf3b5..83323f3 100644 (file)
@@ -141,8 +141,7 @@ int main(int argc, char *argv[])
 
        rv = kvm_check_cap(KVM_CAP_HYPERV_CPUID);
        if (!rv) {
-               fprintf(stderr,
-                       "KVM_CAP_HYPERV_CPUID not supported, skip test\n");
+               print_skip("KVM_CAP_HYPERV_CPUID not supported");
                exit(KSFT_SKIP);
        }
 
@@ -160,8 +159,7 @@ int main(int argc, char *argv[])
        free(hv_cpuid_entries);
 
        if (!kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) {
-               fprintf(stderr,
-                       "Enlightened VMCS is unsupported, skip related test\n");
+               print_skip("Enlightened VMCS is unsupported");
                goto vm_free;
        }
 
index 5350c2d..e6480fd 100644 (file)
@@ -93,12 +93,12 @@ int main(void)
        int warnings_before, warnings_after;
 
        if (!is_intel_cpu()) {
-               printf("Must be run on an Intel CPU, skipping test\n");
+               print_skip("Must be run on an Intel CPU");
                exit(KSFT_SKIP);
        }
 
        if (vm_is_unrestricted_guest(NULL)) {
-               printf("Unrestricted guest must be disabled, skipping test\n");
+               print_skip("Unrestricted guest must be disabled");
                exit(KSFT_SKIP);
        }
 
index 54a960f..1e89688 100644 (file)
@@ -88,8 +88,7 @@ int main(int argc, char *argv[])
 
        rv = kvm_check_cap(KVM_CAP_MSR_PLATFORM_INFO);
        if (!rv) {
-               fprintf(stderr,
-                       "KVM_CAP_MSR_PLATFORM_INFO not supported, skip test\n");
+               print_skip("KVM_CAP_MSR_PLATFORM_INFO not supported");
                exit(KSFT_SKIP);
        }
 
index 5c82242..d672f0a 100644 (file)
@@ -91,11 +91,11 @@ int main(int argc, char *argv[])
 
        cap = kvm_check_cap(KVM_CAP_SYNC_REGS);
        if ((cap & TEST_SYNC_FIELDS) != TEST_SYNC_FIELDS) {
-               fprintf(stderr, "KVM_CAP_SYNC_REGS not supported, skipping test\n");
+               print_skip("KVM_CAP_SYNC_REGS not supported");
                exit(KSFT_SKIP);
        }
        if ((cap & INVALID_SYNC_FIELD) != 0) {
-               fprintf(stderr, "The \"invalid\" field is not invalid, skipping test\n");
+               print_skip("The \"invalid\" field is not invalid");
                exit(KSFT_SKIP);
        }
 
index 7962f2f..54cdefd 100644 (file)
@@ -228,7 +228,7 @@ int main(int argc, char *argv[])
        have_evmcs = kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS);
 
        if (!kvm_check_cap(KVM_CAP_NESTED_STATE)) {
-               printf("KVM_CAP_NESTED_STATE not available, skipping test\n");
+               print_skip("KVM_CAP_NESTED_STATE not available");
                exit(KSFT_SKIP);
        }
 
index fc8328d..3529376 100644 (file)
@@ -51,7 +51,7 @@ int main(int argc, char *argv[])
                xss_supported = entry && !!(entry->eax & X86_FEATURE_XSAVES);
        }
        if (!xss_supported) {
-               printf("IA32_XSS is not supported by the vCPU, skipping test\n");
+               print_skip("IA32_XSS is not supported by the vCPU");
                exit(KSFT_SKIP);
        }