KVM: selftests: Add GUEST_ASSERT variants to pass values to host
authorSean Christopherson <sean.j.christopherson@intel.com>
Fri, 10 Apr 2020 23:17:01 +0000 (16:17 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 15 Apr 2020 16:08:43 +0000 (12:08 -0400)
Add variants of GUEST_ASSERT to pass values back to the host, e.g. to
help debug/understand a failure when the the cause of the assert isn't
necessarily binary.

It'd probably be possible to auto-calculate the number of arguments and
just have a single GUEST_ASSERT, but there are a limited number of
variants and silently eating arguments could lead to subtle code bugs.

Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
Message-Id: <20200410231707.7128-5-sean.j.christopherson@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/include/kvm_util.h

index d4c3e4d..e38d91b 100644 (file)
@@ -313,11 +313,26 @@ uint64_t get_ucall(struct kvm_vm *vm, uint32_t vcpu_id, struct ucall *uc);
 
 #define GUEST_SYNC(stage)      ucall(UCALL_SYNC, 2, "hello", stage)
 #define GUEST_DONE()           ucall(UCALL_DONE, 0)
-#define GUEST_ASSERT(_condition) do {                  \
-       if (!(_condition))                              \
-               ucall(UCALL_ABORT, 2                  \
-                       "Failed guest assert: "         \
-                       #_condition, __LINE__);         \
+#define __GUEST_ASSERT(_condition, _nargs, _args...) do {      \
+       if (!(_condition))                                      \
+               ucall(UCALL_ABORT, 2 + _nargs,                  \
+                       "Failed guest assert: "                 \
+                       #_condition, __LINE__, _args);          \
 } while (0)
 
+#define GUEST_ASSERT(_condition) \
+       __GUEST_ASSERT((_condition), 0, 0)
+
+#define GUEST_ASSERT_1(_condition, arg1) \
+       __GUEST_ASSERT((_condition), 1, (arg1))
+
+#define GUEST_ASSERT_2(_condition, arg1, arg2) \
+       __GUEST_ASSERT((_condition), 2, (arg1), (arg2))
+
+#define GUEST_ASSERT_3(_condition, arg1, arg2, arg3) \
+       __GUEST_ASSERT((_condition), 3, (arg1), (arg2), (arg3))
+
+#define GUEST_ASSERT_4(_condition, arg1, arg2, arg3, arg4) \
+       __GUEST_ASSERT((_condition), 4, (arg1), (arg2), (arg3), (arg4))
+
 #endif /* SELFTEST_KVM_UTIL_H */