Skip to content

Commit 4e15c38

Browse files
committed
KVM: selftests: Convert x86's XCR0 test to use printf-based guest asserts
Convert x86's XCR0 vs. CPUID test to use printf-based guest asserts. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 30a6e0b commit 4e15c38

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

tools/testing/selftests/kvm/x86_64/xcr0_cpuid_test.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Copyright (C) 2022, Google LLC.
66
*/
7+
#define USE_GUEST_ASSERT_PRINTF 1
78

89
#include <fcntl.h>
910
#include <stdio.h>
@@ -20,13 +21,14 @@
2021
* Assert that architectural dependency rules are satisfied, e.g. that AVX is
2122
* supported if and only if SSE is supported.
2223
*/
23-
#define ASSERT_XFEATURE_DEPENDENCIES(supported_xcr0, xfeatures, dependencies) \
24-
do { \
25-
uint64_t __supported = (supported_xcr0) & ((xfeatures) | (dependencies)); \
26-
\
27-
GUEST_ASSERT_3((__supported & (xfeatures)) != (xfeatures) || \
28-
__supported == ((xfeatures) | (dependencies)), \
29-
__supported, (xfeatures), (dependencies)); \
24+
#define ASSERT_XFEATURE_DEPENDENCIES(supported_xcr0, xfeatures, dependencies) \
25+
do { \
26+
uint64_t __supported = (supported_xcr0) & ((xfeatures) | (dependencies)); \
27+
\
28+
__GUEST_ASSERT((__supported & (xfeatures)) != (xfeatures) || \
29+
__supported == ((xfeatures) | (dependencies)), \
30+
"supported = 0x%llx, xfeatures = 0x%llx, dependencies = 0x%llx", \
31+
__supported, (xfeatures), (dependencies)); \
3032
} while (0)
3133

3234
/*
@@ -41,7 +43,8 @@ do { \
4143
do { \
4244
uint64_t __supported = (supported_xcr0) & (xfeatures); \
4345
\
44-
GUEST_ASSERT_2(!__supported || __supported == (xfeatures), \
46+
__GUEST_ASSERT(!__supported || __supported == (xfeatures), \
47+
"supported = 0x%llx, xfeatures = 0x%llx", \
4548
__supported, (xfeatures)); \
4649
} while (0)
4750

@@ -79,14 +82,18 @@ static void guest_code(void)
7982
XFEATURE_MASK_XTILE);
8083

8184
vector = xsetbv_safe(0, supported_xcr0);
82-
GUEST_ASSERT_2(!vector, supported_xcr0, vector);
85+
__GUEST_ASSERT(!vector,
86+
"Expected success on XSETBV(0x%llx), got vector '0x%x'",
87+
supported_xcr0, vector);
8388

8489
for (i = 0; i < 64; i++) {
8590
if (supported_xcr0 & BIT_ULL(i))
8691
continue;
8792

8893
vector = xsetbv_safe(0, supported_xcr0 | BIT_ULL(i));
89-
GUEST_ASSERT_3(vector == GP_VECTOR, supported_xcr0, vector, BIT_ULL(i));
94+
__GUEST_ASSERT(vector == GP_VECTOR,
95+
"Expected #GP on XSETBV(0x%llx), supported XCR0 = %llx, got vector '0x%x'",
96+
BIT_ULL(i), supported_xcr0, vector);
9097
}
9198

9299
GUEST_DONE();
@@ -117,7 +124,7 @@ int main(int argc, char *argv[])
117124

118125
switch (get_ucall(vcpu, &uc)) {
119126
case UCALL_ABORT:
120-
REPORT_GUEST_ASSERT_3(uc, "0x%lx 0x%lx 0x%lx");
127+
REPORT_GUEST_ASSERT(uc);
121128
break;
122129
case UCALL_DONE:
123130
goto done;

0 commit comments

Comments
 (0)