Skip to content

Commit

Permalink
KVM: selftests: Rename the ASSERT_EQ macro
Browse files Browse the repository at this point in the history
There is already an ASSERT_EQ macro in the file
tools/testing/selftests/kselftest_harness.h, so currently KVM selftests
can't include test_util.h from the KVM selftests together with that file.
Rename the macro in the KVM selftests to TEST_ASSERT_EQ to avoid the
problem - it is also more similar to the other macros in test_util.h that
way.

Suggested-by: Sean Christopherson <[email protected]>
Signed-off-by: Thomas Huth <[email protected]>
Reviewed-by: Philippe Mathieu-Daudé <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Sean Christopherson <[email protected]>
  • Loading branch information
huth authored and sean-jc committed Aug 2, 2023
1 parent 7e4966e commit 6d85f51
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 103 deletions.
8 changes: 4 additions & 4 deletions tools/testing/selftests/kvm/aarch64/aarch32_id_regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void test_user_raz_wi(struct kvm_vcpu *vcpu)
uint64_t val;

vcpu_get_reg(vcpu, reg_id, &val);
ASSERT_EQ(val, 0);
TEST_ASSERT_EQ(val, 0);

/*
* Expect the ioctl to succeed with no effect on the register
Expand All @@ -107,7 +107,7 @@ static void test_user_raz_wi(struct kvm_vcpu *vcpu)
vcpu_set_reg(vcpu, reg_id, BAD_ID_REG_VAL);

vcpu_get_reg(vcpu, reg_id, &val);
ASSERT_EQ(val, 0);
TEST_ASSERT_EQ(val, 0);
}
}

Expand All @@ -127,14 +127,14 @@ static void test_user_raz_invariant(struct kvm_vcpu *vcpu)
uint64_t val;

vcpu_get_reg(vcpu, reg_id, &val);
ASSERT_EQ(val, 0);
TEST_ASSERT_EQ(val, 0);

r = __vcpu_set_reg(vcpu, reg_id, BAD_ID_REG_VAL);
TEST_ASSERT(r < 0 && errno == EINVAL,
"unexpected KVM_SET_ONE_REG error: r=%d, errno=%d", r, errno);

vcpu_get_reg(vcpu, reg_id, &val);
ASSERT_EQ(val, 0);
TEST_ASSERT_EQ(val, 0);
}
}

Expand Down
10 changes: 5 additions & 5 deletions tools/testing/selftests/kvm/aarch64/page_fault_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ static int uffd_generic_handler(int uffd_mode, int uffd, struct uffd_msg *msg,

TEST_ASSERT(uffd_mode == UFFDIO_REGISTER_MODE_MISSING,
"The only expected UFFD mode is MISSING");
ASSERT_EQ(addr, (uint64_t)args->hva);
TEST_ASSERT_EQ(addr, (uint64_t)args->hva);

pr_debug("uffd fault: addr=%p write=%d\n",
(void *)addr, !!(flags & UFFD_PAGEFAULT_FLAG_WRITE));
Expand Down Expand Up @@ -432,7 +432,7 @@ static void mmio_on_test_gpa_handler(struct kvm_vm *vm, struct kvm_run *run)
region = vm_get_mem_region(vm, MEM_REGION_TEST_DATA);
hva = (void *)region->region.userspace_addr;

ASSERT_EQ(run->mmio.phys_addr, region->region.guest_phys_addr);
TEST_ASSERT_EQ(run->mmio.phys_addr, region->region.guest_phys_addr);

memcpy(hva, run->mmio.data, run->mmio.len);
events.mmio_exits += 1;
Expand Down Expand Up @@ -631,9 +631,9 @@ static void setup_default_handlers(struct test_desc *test)

static void check_event_counts(struct test_desc *test)
{
ASSERT_EQ(test->expected_events.uffd_faults, events.uffd_faults);
ASSERT_EQ(test->expected_events.mmio_exits, events.mmio_exits);
ASSERT_EQ(test->expected_events.fail_vcpu_runs, events.fail_vcpu_runs);
TEST_ASSERT_EQ(test->expected_events.uffd_faults, events.uffd_faults);
TEST_ASSERT_EQ(test->expected_events.mmio_exits, events.mmio_exits);
TEST_ASSERT_EQ(test->expected_events.fail_vcpu_runs, events.fail_vcpu_runs);
}

static void print_test_banner(enum vm_guest_mode mode, struct test_params *p)
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/kvm/include/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ void test_assert(bool exp, const char *exp_str,
#define TEST_ASSERT(e, fmt, ...) \
test_assert((e), #e, __FILE__, __LINE__, fmt, ##__VA_ARGS__)

#define ASSERT_EQ(a, b) do { \
#define TEST_ASSERT_EQ(a, b) do { \
typeof(a) __a = (a); \
typeof(b) __b = (b); \
TEST_ASSERT(__a == __b, \
"ASSERT_EQ(%s, %s) failed.\n" \
"TEST_ASSERT_EQ(%s, %s) failed.\n" \
"\t%s is %#lx\n" \
"\t%s is %#lx", \
#a, #b, #a, (unsigned long) __a, #b, (unsigned long) __b); \
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/lib/kvm_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
if (src_type == VM_MEM_SRC_ANONYMOUS_THP)
alignment = max(backing_src_pagesz, alignment);

ASSERT_EQ(guest_paddr, align_up(guest_paddr, backing_src_pagesz));
TEST_ASSERT_EQ(guest_paddr, align_up(guest_paddr, backing_src_pagesz));

/* Add enough memory to align up if necessary */
if (alignment > 1)
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/selftests/kvm/max_guest_memory_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static void rendezvous_with_boss(void)
static void run_vcpu(struct kvm_vcpu *vcpu)
{
vcpu_run(vcpu);
ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_DONE);
TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_DONE);
}

static void *vcpu_worker(void *data)
Expand Down
62 changes: 31 additions & 31 deletions tools/testing/selftests/kvm/s390x/cmma_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ static void test_get_cmma_basic(void)

/* GET_CMMA_BITS without CMMA enabled should fail */
rc = vm_get_cmma_bits(vm, 0, &errno_out);
ASSERT_EQ(rc, -1);
ASSERT_EQ(errno_out, ENXIO);
TEST_ASSERT_EQ(rc, -1);
TEST_ASSERT_EQ(errno_out, ENXIO);

enable_cmma(vm);
vcpu = vm_vcpu_add(vm, 1, guest_do_one_essa);
Expand All @@ -247,31 +247,31 @@ static void test_get_cmma_basic(void)

/* GET_CMMA_BITS without migration mode and without peeking should fail */
rc = vm_get_cmma_bits(vm, 0, &errno_out);
ASSERT_EQ(rc, -1);
ASSERT_EQ(errno_out, EINVAL);
TEST_ASSERT_EQ(rc, -1);
TEST_ASSERT_EQ(errno_out, EINVAL);

/* GET_CMMA_BITS without migration mode and with peeking should work */
rc = vm_get_cmma_bits(vm, KVM_S390_CMMA_PEEK, &errno_out);
ASSERT_EQ(rc, 0);
ASSERT_EQ(errno_out, 0);
TEST_ASSERT_EQ(rc, 0);
TEST_ASSERT_EQ(errno_out, 0);

enable_dirty_tracking(vm);
enable_migration_mode(vm);

/* GET_CMMA_BITS with invalid flags */
rc = vm_get_cmma_bits(vm, 0xfeedc0fe, &errno_out);
ASSERT_EQ(rc, -1);
ASSERT_EQ(errno_out, EINVAL);
TEST_ASSERT_EQ(rc, -1);
TEST_ASSERT_EQ(errno_out, EINVAL);

kvm_vm_free(vm);
}

static void assert_exit_was_hypercall(struct kvm_vcpu *vcpu)
{
ASSERT_EQ(vcpu->run->exit_reason, 13);
ASSERT_EQ(vcpu->run->s390_sieic.icptcode, 4);
ASSERT_EQ(vcpu->run->s390_sieic.ipa, 0x8300);
ASSERT_EQ(vcpu->run->s390_sieic.ipb, 0x5010000);
TEST_ASSERT_EQ(vcpu->run->exit_reason, 13);
TEST_ASSERT_EQ(vcpu->run->s390_sieic.icptcode, 4);
TEST_ASSERT_EQ(vcpu->run->s390_sieic.ipa, 0x8300);
TEST_ASSERT_EQ(vcpu->run->s390_sieic.ipb, 0x5010000);
}

static void test_migration_mode(void)
Expand All @@ -283,8 +283,8 @@ static void test_migration_mode(void)

/* enabling migration mode on a VM without memory should fail */
rc = __enable_migration_mode(vm);
ASSERT_EQ(rc, -1);
ASSERT_EQ(errno, EINVAL);
TEST_ASSERT_EQ(rc, -1);
TEST_ASSERT_EQ(errno, EINVAL);
TEST_ASSERT(!is_migration_mode_on(vm), "migration mode should still be off");
errno = 0;

Expand All @@ -304,8 +304,8 @@ static void test_migration_mode(void)

/* migration mode when memslots have dirty tracking off should fail */
rc = __enable_migration_mode(vm);
ASSERT_EQ(rc, -1);
ASSERT_EQ(errno, EINVAL);
TEST_ASSERT_EQ(rc, -1);
TEST_ASSERT_EQ(errno, EINVAL);
TEST_ASSERT(!is_migration_mode_on(vm), "migration mode should still be off");
errno = 0;

Expand All @@ -314,7 +314,7 @@ static void test_migration_mode(void)

/* enabling migration mode should work now */
rc = __enable_migration_mode(vm);
ASSERT_EQ(rc, 0);
TEST_ASSERT_EQ(rc, 0);
TEST_ASSERT(is_migration_mode_on(vm), "migration mode should be on");
errno = 0;

Expand Down Expand Up @@ -350,7 +350,7 @@ static void test_migration_mode(void)
*/
vm_mem_region_set_flags(vm, TEST_DATA_TWO_MEMSLOT, KVM_MEM_LOG_DIRTY_PAGES);
rc = __enable_migration_mode(vm);
ASSERT_EQ(rc, 0);
TEST_ASSERT_EQ(rc, 0);
TEST_ASSERT(is_migration_mode_on(vm), "migration mode should be on");
errno = 0;

Expand Down Expand Up @@ -394,9 +394,9 @@ static void assert_all_slots_cmma_dirty(struct kvm_vm *vm)
};
memset(cmma_value_buf, 0xff, sizeof(cmma_value_buf));
vm_ioctl(vm, KVM_S390_GET_CMMA_BITS, &args);
ASSERT_EQ(args.count, MAIN_PAGE_COUNT);
ASSERT_EQ(args.remaining, TEST_DATA_PAGE_COUNT);
ASSERT_EQ(args.start_gfn, 0);
TEST_ASSERT_EQ(args.count, MAIN_PAGE_COUNT);
TEST_ASSERT_EQ(args.remaining, TEST_DATA_PAGE_COUNT);
TEST_ASSERT_EQ(args.start_gfn, 0);

/* ...and then - after a hole - the TEST_DATA memslot should follow */
args = (struct kvm_s390_cmma_log){
Expand All @@ -407,9 +407,9 @@ static void assert_all_slots_cmma_dirty(struct kvm_vm *vm)
};
memset(cmma_value_buf, 0xff, sizeof(cmma_value_buf));
vm_ioctl(vm, KVM_S390_GET_CMMA_BITS, &args);
ASSERT_EQ(args.count, TEST_DATA_PAGE_COUNT);
ASSERT_EQ(args.start_gfn, TEST_DATA_START_GFN);
ASSERT_EQ(args.remaining, 0);
TEST_ASSERT_EQ(args.count, TEST_DATA_PAGE_COUNT);
TEST_ASSERT_EQ(args.start_gfn, TEST_DATA_START_GFN);
TEST_ASSERT_EQ(args.remaining, 0);

/* ...and nothing else should be there */
args = (struct kvm_s390_cmma_log){
Expand All @@ -420,9 +420,9 @@ static void assert_all_slots_cmma_dirty(struct kvm_vm *vm)
};
memset(cmma_value_buf, 0xff, sizeof(cmma_value_buf));
vm_ioctl(vm, KVM_S390_GET_CMMA_BITS, &args);
ASSERT_EQ(args.count, 0);
ASSERT_EQ(args.start_gfn, 0);
ASSERT_EQ(args.remaining, 0);
TEST_ASSERT_EQ(args.count, 0);
TEST_ASSERT_EQ(args.start_gfn, 0);
TEST_ASSERT_EQ(args.remaining, 0);
}

/**
Expand Down Expand Up @@ -498,11 +498,11 @@ static void assert_cmma_dirty(u64 first_dirty_gfn,
u64 dirty_gfn_count,
const struct kvm_s390_cmma_log *res)
{
ASSERT_EQ(res->start_gfn, first_dirty_gfn);
ASSERT_EQ(res->count, dirty_gfn_count);
TEST_ASSERT_EQ(res->start_gfn, first_dirty_gfn);
TEST_ASSERT_EQ(res->count, dirty_gfn_count);
for (size_t i = 0; i < dirty_gfn_count; i++)
ASSERT_EQ(cmma_value_buf[0], 0x0); /* stable state */
ASSERT_EQ(cmma_value_buf[dirty_gfn_count], 0xff); /* not touched */
TEST_ASSERT_EQ(cmma_value_buf[0], 0x0); /* stable state */
TEST_ASSERT_EQ(cmma_value_buf[dirty_gfn_count], 0xff); /* not touched */
}

static void test_get_skip_holes(void)
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/kvm/s390x/memop.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ enum stage {
if (uc.cmd == UCALL_ABORT) { \
REPORT_GUEST_ASSERT_2(uc, "hints: %lu, %lu"); \
} \
ASSERT_EQ(uc.cmd, UCALL_SYNC); \
ASSERT_EQ(uc.args[1], __stage); \
TEST_ASSERT_EQ(uc.cmd, UCALL_SYNC); \
TEST_ASSERT_EQ(uc.args[1], __stage); \
}) \

static void prepare_mem12(void)
Expand Down Expand Up @@ -808,7 +808,7 @@ static void test_termination(void)
HOST_SYNC(t.vcpu, STAGE_IDLED);
MOP(t.vm, ABSOLUTE, READ, &teid, sizeof(teid), GADDR(prefix + 168));
/* Bits 56, 60, 61 form a code, 0 being the only one allowing for termination */
ASSERT_EQ(teid & teid_mask, 0);
TEST_ASSERT_EQ(teid & teid_mask, 0);

kvm_vm_free(t.kvm_vm);
}
Expand Down
4 changes: 2 additions & 2 deletions tools/testing/selftests/kvm/s390x/tprot.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ static void guest_code(void)
get_ucall(__vcpu, &uc); \
if (uc.cmd == UCALL_ABORT) \
REPORT_GUEST_ASSERT_2(uc, "hints: %lu, %lu"); \
ASSERT_EQ(uc.cmd, UCALL_SYNC); \
ASSERT_EQ(uc.args[1], __stage); \
TEST_ASSERT_EQ(uc.cmd, UCALL_SYNC); \
TEST_ASSERT_EQ(uc.args[1], __stage); \
})

#define HOST_SYNC(vcpu, stage) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static void vcpu_worker(struct memstress_vcpu_args *vcpu_args)

vcpu_run(vcpu);

ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_SYNC);
TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_SYNC);

vcpu_last_completed_iteration[vcpu_idx] = current_iteration;

Expand Down Expand Up @@ -179,22 +179,22 @@ static void run_test(enum vm_guest_mode mode, void *unused)
* with that capability.
*/
if (dirty_log_manual_caps) {
ASSERT_EQ(stats_clear_pass[0].hugepages, 0);
ASSERT_EQ(stats_clear_pass[0].pages_4k, total_4k_pages);
ASSERT_EQ(stats_dirty_logging_enabled.hugepages, stats_populated.hugepages);
TEST_ASSERT_EQ(stats_clear_pass[0].hugepages, 0);
TEST_ASSERT_EQ(stats_clear_pass[0].pages_4k, total_4k_pages);
TEST_ASSERT_EQ(stats_dirty_logging_enabled.hugepages, stats_populated.hugepages);
} else {
ASSERT_EQ(stats_dirty_logging_enabled.hugepages, 0);
ASSERT_EQ(stats_dirty_logging_enabled.pages_4k, total_4k_pages);
TEST_ASSERT_EQ(stats_dirty_logging_enabled.hugepages, 0);
TEST_ASSERT_EQ(stats_dirty_logging_enabled.pages_4k, total_4k_pages);
}

/*
* Once dirty logging is disabled and the vCPUs have touched all their
* memory again, the page counts should be the same as they were
* right after initial population of memory.
*/
ASSERT_EQ(stats_populated.pages_4k, stats_repopulated.pages_4k);
ASSERT_EQ(stats_populated.pages_2m, stats_repopulated.pages_2m);
ASSERT_EQ(stats_populated.pages_1g, stats_repopulated.pages_1g);
TEST_ASSERT_EQ(stats_populated.pages_4k, stats_repopulated.pages_4k);
TEST_ASSERT_EQ(stats_populated.pages_2m, stats_repopulated.pages_2m);
TEST_ASSERT_EQ(stats_populated.pages_1g, stats_repopulated.pages_1g);
}

static void help(char *name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ int main(int argc, char *argv[])
vcpu_run(vcpu);
handle_flds_emulation_failure_exit(vcpu);
vcpu_run(vcpu);
ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_DONE);
TEST_ASSERT_EQ(get_ucall(vcpu, NULL), UCALL_DONE);

kvm_vm_free(vm);
return 0;
Expand Down
12 changes: 6 additions & 6 deletions tools/testing/selftests/kvm/x86_64/nested_exceptions_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ int main(int argc, char *argv[])

/* Verify the pending events comes back out the same as it went in. */
vcpu_events_get(vcpu, &events);
ASSERT_EQ(events.flags & KVM_VCPUEVENT_VALID_PAYLOAD,
KVM_VCPUEVENT_VALID_PAYLOAD);
ASSERT_EQ(events.exception.pending, true);
ASSERT_EQ(events.exception.nr, SS_VECTOR);
ASSERT_EQ(events.exception.has_error_code, true);
ASSERT_EQ(events.exception.error_code, SS_ERROR_CODE);
TEST_ASSERT_EQ(events.flags & KVM_VCPUEVENT_VALID_PAYLOAD,
KVM_VCPUEVENT_VALID_PAYLOAD);
TEST_ASSERT_EQ(events.exception.pending, true);
TEST_ASSERT_EQ(events.exception.nr, SS_VECTOR);
TEST_ASSERT_EQ(events.exception.has_error_code, true);
TEST_ASSERT_EQ(events.exception.error_code, SS_ERROR_CODE);

/*
* Run for real with the pending #SS, L1 should get a VM-Exit due to
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/kvm/x86_64/recalc_apic_map_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ int main(void)
for (i = 0; i < KVM_MAX_VCPUS; i++)
vcpu_set_msr(vcpus[i], MSR_IA32_APICBASE, LAPIC_X2APIC);

ASSERT_EQ(pthread_create(&thread, NULL, race, vcpus[0]), 0);
TEST_ASSERT_EQ(pthread_create(&thread, NULL, race, vcpus[0]), 0);

vcpuN = vcpus[KVM_MAX_VCPUS - 1];
for (t = time(NULL) + TIMEOUT; time(NULL) < t;) {
vcpu_set_msr(vcpuN, MSR_IA32_APICBASE, LAPIC_X2APIC);
vcpu_set_msr(vcpuN, MSR_IA32_APICBASE, LAPIC_DISABLED);
}

ASSERT_EQ(pthread_cancel(thread), 0);
ASSERT_EQ(pthread_join(thread, NULL), 0);
TEST_ASSERT_EQ(pthread_cancel(thread), 0);
TEST_ASSERT_EQ(pthread_join(thread, NULL), 0);

kvm_vm_free(vm);

Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/kvm/x86_64/sync_regs_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static void race_sync_regs(void *racer)
!!(run->s.regs.sregs.cr4 & X86_CR4_PAE),
!!(run->s.regs.sregs.efer & EFER_LME));

ASSERT_EQ(pthread_create(&thread, NULL, racer, (void *)run), 0);
TEST_ASSERT_EQ(pthread_create(&thread, NULL, racer, (void *)run), 0);

for (t = time(NULL) + TIMEOUT; time(NULL) < t;) {
__vcpu_run(vcpu);
Expand All @@ -187,8 +187,8 @@ static void race_sync_regs(void *racer)
}
}

ASSERT_EQ(pthread_cancel(thread), 0);
ASSERT_EQ(pthread_join(thread, NULL), 0);
TEST_ASSERT_EQ(pthread_cancel(thread), 0);
TEST_ASSERT_EQ(pthread_join(thread, NULL), 0);

kvm_vm_free(vm);
}
Expand Down
Loading

0 comments on commit 6d85f51

Please sign in to comment.