Skip to content

Commit 9291c9c

Browse files
committed
KVM: selftests: Convert set_memory_region_test to printf-based GUEST_ASSERT
Convert set_memory_region_test to print-based GUEST_ASSERT, using a combo of newfangled macros to report (hopefully) useful information. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 5f82bba commit 9291c9c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

tools/testing/selftests/kvm/set_memory_region_test.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
2+
#define USE_GUEST_ASSERT_PRINTF 1
3+
24
#define _GNU_SOURCE /* for program_invocation_short_name */
35
#include <fcntl.h>
46
#include <pthread.h>
@@ -88,7 +90,7 @@ static void *vcpu_worker(void *data)
8890
}
8991

9092
if (run->exit_reason == KVM_EXIT_IO && cmd == UCALL_ABORT)
91-
REPORT_GUEST_ASSERT_1(uc, "val = %lu");
93+
REPORT_GUEST_ASSERT(uc);
9294

9395
return NULL;
9496
}
@@ -156,19 +158,22 @@ static void guest_code_move_memory_region(void)
156158
* window where the memslot is invalid is usually quite small.
157159
*/
158160
val = guest_spin_on_val(0);
159-
GUEST_ASSERT_1(val == 1 || val == MMIO_VAL, val);
161+
__GUEST_ASSERT(val == 1 || val == MMIO_VAL,
162+
"Expected '1' or MMIO ('%llx'), got '%llx'", MMIO_VAL, val);
160163

161164
/* Spin until the misaligning memory region move completes. */
162165
val = guest_spin_on_val(MMIO_VAL);
163-
GUEST_ASSERT_1(val == 1 || val == 0, val);
166+
__GUEST_ASSERT(val == 1 || val == 0,
167+
"Expected '0' or '1' (no MMIO), got '%llx'", val);
164168

165169
/* Spin until the memory region starts to get re-aligned. */
166170
val = guest_spin_on_val(0);
167-
GUEST_ASSERT_1(val == 1 || val == MMIO_VAL, val);
171+
__GUEST_ASSERT(val == 1 || val == MMIO_VAL,
172+
"Expected '1' or MMIO ('%llx'), got '%llx'", MMIO_VAL, val);
168173

169174
/* Spin until the re-aligning memory region move completes. */
170175
val = guest_spin_on_val(MMIO_VAL);
171-
GUEST_ASSERT_1(val == 1, val);
176+
GUEST_ASSERT_EQ(val, 1);
172177

173178
GUEST_DONE();
174179
}
@@ -224,15 +229,15 @@ static void guest_code_delete_memory_region(void)
224229

225230
/* Spin until the memory region is deleted. */
226231
val = guest_spin_on_val(0);
227-
GUEST_ASSERT_1(val == MMIO_VAL, val);
232+
GUEST_ASSERT_EQ(val, MMIO_VAL);
228233

229234
/* Spin until the memory region is recreated. */
230235
val = guest_spin_on_val(MMIO_VAL);
231-
GUEST_ASSERT_1(val == 0, val);
236+
GUEST_ASSERT_EQ(val, 0);
232237

233238
/* Spin until the memory region is deleted. */
234239
val = guest_spin_on_val(0);
235-
GUEST_ASSERT_1(val == MMIO_VAL, val);
240+
GUEST_ASSERT_EQ(val, MMIO_VAL);
236241

237242
asm("1:\n\t"
238243
".pushsection .rodata\n\t"
@@ -249,7 +254,7 @@ static void guest_code_delete_memory_region(void)
249254
"final_rip_end: .quad 1b\n\t"
250255
".popsection");
251256

252-
GUEST_ASSERT_1(0, 0);
257+
GUEST_ASSERT(0);
253258
}
254259

255260
static void test_delete_memory_region(void)

0 commit comments

Comments
 (0)