Skip to content

Commit c96f57b

Browse files
shvipinbonzini
authored andcommitted
KVM: selftests: Make vCPU exit reason test assertion common
Make TEST_ASSERT_KVM_EXIT_REASON() macro and replace all exit reason test assert statements with it. No functional changes intended. Signed-off-by: Vipin Sharma <[email protected]> Reviewed-by: David Matlack <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent e6239a4 commit c96f57b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+69
-293
lines changed

tools/testing/selftests/kvm/aarch64/psci_test.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ static void host_test_system_suspend(void)
180180

181181
enter_guest(source);
182182

183-
TEST_ASSERT(run->exit_reason == KVM_EXIT_SYSTEM_EVENT,
184-
"Unhandled exit reason: %u (%s)",
185-
run->exit_reason, exit_reason_str(run->exit_reason));
183+
TEST_ASSERT_KVM_EXIT_REASON(source, KVM_EXIT_SYSTEM_EVENT);
186184
TEST_ASSERT(run->system_event.type == KVM_SYSTEM_EVENT_SUSPEND,
187185
"Unhandled system event: %u (expected: %u)",
188186
run->system_event.type, KVM_SYSTEM_EVENT_SUSPEND);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ void test_assert(bool exp, const char *exp_str,
6363
#a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \
6464
} while (0)
6565

66+
#define TEST_ASSERT_KVM_EXIT_REASON(vcpu, expected) do { \
67+
__u32 exit_reason = (vcpu)->run->exit_reason; \
68+
\
69+
TEST_ASSERT(exit_reason == (expected), \
70+
"Unexpected exit reason: %u (%s)", \
71+
exit_reason, exit_reason_str(exit_reason)); \
72+
} while (0)
73+
6674
#define TEST_FAIL(fmt, ...) do { \
6775
TEST_ASSERT(false, fmt, ##__VA_ARGS__); \
6876
__builtin_unreachable(); \

tools/testing/selftests/kvm/lib/s390x/diag318_test_handler.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ static uint64_t diag318_handler(void)
3535
vcpu_run(vcpu);
3636
run = vcpu->run;
3737

38-
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC,
39-
"DIAGNOSE 0x0318 instruction was not intercepted");
38+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
4039
TEST_ASSERT(run->s390_sieic.icptcode == ICPT_INSTRUCTION,
4140
"Unexpected intercept code: 0x%x", run->s390_sieic.icptcode);
4241
TEST_ASSERT((run->s390_sieic.ipa & 0xff00) == IPA0_DIAG,

tools/testing/selftests/kvm/s390x/sync_regs_test.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ void test_req_and_verify_all_valid_regs(struct kvm_vcpu *vcpu)
126126
run->kvm_valid_regs = TEST_SYNC_FIELDS;
127127
rv = _vcpu_run(vcpu);
128128
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
129-
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC,
130-
"Unexpected exit reason: %u (%s)\n",
131-
run->exit_reason,
132-
exit_reason_str(run->exit_reason));
129+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
133130
TEST_ASSERT(run->s390_sieic.icptcode == 4 &&
134131
(run->s390_sieic.ipa >> 8) == 0x83 &&
135132
(run->s390_sieic.ipb >> 16) == 0x501,
@@ -165,10 +162,7 @@ void test_set_and_verify_various_reg_values(struct kvm_vcpu *vcpu)
165162

166163
rv = _vcpu_run(vcpu);
167164
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
168-
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC,
169-
"Unexpected exit reason: %u (%s)\n",
170-
run->exit_reason,
171-
exit_reason_str(run->exit_reason));
165+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
172166
TEST_ASSERT(run->s.regs.gprs[11] == 0xBAD1DEA + 1,
173167
"r11 sync regs value incorrect 0x%llx.",
174168
run->s.regs.gprs[11]);
@@ -200,10 +194,7 @@ void test_clear_kvm_dirty_regs_bits(struct kvm_vcpu *vcpu)
200194
run->s.regs.diag318 = 0x4B1D;
201195
rv = _vcpu_run(vcpu);
202196
TEST_ASSERT(rv == 0, "vcpu_run failed: %d\n", rv);
203-
TEST_ASSERT(run->exit_reason == KVM_EXIT_S390_SIEIC,
204-
"Unexpected exit reason: %u (%s)\n",
205-
run->exit_reason,
206-
exit_reason_str(run->exit_reason));
197+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_S390_SIEIC);
207198
TEST_ASSERT(run->s.regs.gprs[11] != 0xDEADBEEF,
208199
"r11 sync regs value incorrect 0x%llx.",
209200
run->s.regs.gprs[11]);

tools/testing/selftests/kvm/set_memory_region_test.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ static void test_delete_memory_region(void)
308308
static void test_zero_memory_regions(void)
309309
{
310310
struct kvm_vcpu *vcpu;
311-
struct kvm_run *run;
312311
struct kvm_vm *vm;
313312

314313
pr_info("Testing KVM_RUN with zero added memory regions\n");
@@ -318,10 +317,7 @@ static void test_zero_memory_regions(void)
318317

319318
vm_ioctl(vm, KVM_SET_NR_MMU_PAGES, (void *)64ul);
320319
vcpu_run(vcpu);
321-
322-
run = vcpu->run;
323-
TEST_ASSERT(run->exit_reason == KVM_EXIT_INTERNAL_ERROR,
324-
"Unexpected exit_reason = %u\n", run->exit_reason);
320+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR);
325321

326322
kvm_vm_free(vm);
327323
}

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ int main(int argc, char *argv[])
241241
struct kvm_regs regs1, regs2;
242242
struct kvm_vcpu *vcpu;
243243
struct kvm_vm *vm;
244-
struct kvm_run *run;
245244
struct kvm_x86_state *state;
246245
int xsave_restore_size;
247246
vm_vaddr_t amx_cfg, tiledata, xsavedata;
@@ -268,7 +267,6 @@ int main(int argc, char *argv[])
268267
"KVM should enumerate max XSAVE size when XSAVE is supported");
269268
xsave_restore_size = kvm_cpu_property(X86_PROPERTY_XSTATE_MAX_SIZE);
270269

271-
run = vcpu->run;
272270
vcpu_regs_get(vcpu, &regs1);
273271

274272
/* Register #NM handler */
@@ -291,10 +289,7 @@ int main(int argc, char *argv[])
291289

292290
for (stage = 1; ; stage++) {
293291
vcpu_run(vcpu);
294-
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
295-
"Stage %d: unexpected exit reason: %u (%s),\n",
296-
stage, run->exit_reason,
297-
exit_reason_str(run->exit_reason));
292+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
298293

299294
switch (get_ucall(vcpu, &uc)) {
300295
case UCALL_ABORT:
@@ -350,7 +345,6 @@ int main(int argc, char *argv[])
350345
/* Restore state in a new VM. */
351346
vcpu = vm_recreate_with_one_vcpu(vm);
352347
vcpu_load_state(vcpu, state);
353-
run = vcpu->run;
354348
kvm_x86_state_cleanup(state);
355349

356350
memset(&regs2, 0, sizeof(regs2));

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,17 @@ static void guest_code(void)
5050
int main(int argc, char *argv[])
5151
{
5252
struct kvm_vcpu *vcpu;
53-
struct kvm_run *run;
5453
struct kvm_vm *vm;
5554
struct kvm_sregs sregs;
5655
struct ucall uc;
5756

5857
TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XSAVE));
5958

6059
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
61-
run = vcpu->run;
6260

6361
while (1) {
6462
vcpu_run(vcpu);
65-
66-
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
67-
"Unexpected exit reason: %u (%s),\n",
68-
run->exit_reason,
69-
exit_reason_str(run->exit_reason));
63+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
7064

7165
switch (get_ucall(vcpu, &uc)) {
7266
case UCALL_SYNC:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int main(void)
204204
vcpu_guest_debug_set(vcpu, &debug);
205205

206206
vcpu_run(vcpu);
207-
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO, "KVM_EXIT_IO");
207+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
208208
cmd = get_ucall(vcpu, &uc);
209209
TEST_ASSERT(cmd == UCALL_DONE, "UCALL_DONE");
210210

tools/testing/selftests/kvm/x86_64/flds_emulation.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ static inline void handle_flds_emulation_failure_exit(struct kvm_vcpu *vcpu)
2424
uint8_t *insn_bytes;
2525
uint64_t flags;
2626

27-
TEST_ASSERT(run->exit_reason == KVM_EXIT_INTERNAL_ERROR,
28-
"Unexpected exit reason: %u (%s)",
29-
run->exit_reason,
30-
exit_reason_str(run->exit_reason));
27+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTERNAL_ERROR);
3128

3229
TEST_ASSERT(run->emulation_failure.suberror == KVM_INTERNAL_ERROR_EMULATION,
3330
"Unexpected suberror: %u",

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,11 @@ int main(void)
207207
{
208208
struct kvm_vcpu *vcpu;
209209
struct kvm_vm *vm;
210-
struct kvm_run *run;
211210
struct ucall uc;
212211
vm_vaddr_t tsc_page_gva;
213212
int stage;
214213

215214
vm = vm_create_with_one_vcpu(&vcpu, guest_main);
216-
run = vcpu->run;
217215

218216
vcpu_set_hv_cpuid(vcpu);
219217

@@ -227,10 +225,7 @@ int main(void)
227225

228226
for (stage = 1;; stage++) {
229227
vcpu_run(vcpu);
230-
TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
231-
"Stage %d: unexpected exit reason: %u (%s),\n",
232-
stage, run->exit_reason,
233-
exit_reason_str(run->exit_reason));
228+
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
234229

235230
switch (get_ucall(vcpu, &uc)) {
236231
case UCALL_ABORT:

0 commit comments

Comments
 (0)