Commit 352be2c5 authored by Wainer dos Santos Moschetta's avatar Wainer dos Santos Moschetta Committed by Paolo Bonzini

selftests: kvm: Uses TEST_FAIL in tests/utilities

Changed all tests and utilities to use TEST_FAIL macro
instead of TEST_ASSERT(false,...).
Signed-off-by: default avatarWainer dos Santos Moschetta <wainersm@redhat.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent a46f8a63
...@@ -166,10 +166,9 @@ static void *vcpu_worker(void *data) ...@@ -166,10 +166,9 @@ static void *vcpu_worker(void *data)
pages_count += TEST_PAGES_PER_LOOP; pages_count += TEST_PAGES_PER_LOOP;
generate_random_array(guest_array, TEST_PAGES_PER_LOOP); generate_random_array(guest_array, TEST_PAGES_PER_LOOP);
} else { } else {
TEST_ASSERT(false, TEST_FAIL("Invalid guest sync status: "
"Invalid guest sync status: " "exit_reason=%s\n",
"exit_reason=%s\n", exit_reason_str(run->exit_reason));
exit_reason_str(run->exit_reason));
} }
} }
......
...@@ -130,7 +130,7 @@ void _virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr, ...@@ -130,7 +130,7 @@ void _virt_pg_map(struct kvm_vm *vm, uint64_t vaddr, uint64_t paddr,
ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pte_index(vm, vaddr) * 8; ptep = addr_gpa2hva(vm, pte_addr(vm, *ptep)) + pte_index(vm, vaddr) * 8;
break; break;
default: default:
TEST_ASSERT(false, "Page table levels must be 2, 3, or 4"); TEST_FAIL("Page table levels must be 2, 3, or 4");
} }
*ptep = paddr | 3; *ptep = paddr | 3;
...@@ -173,14 +173,13 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) ...@@ -173,14 +173,13 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
goto unmapped_gva; goto unmapped_gva;
break; break;
default: default:
TEST_ASSERT(false, "Page table levels must be 2, 3, or 4"); TEST_FAIL("Page table levels must be 2, 3, or 4");
} }
return pte_addr(vm, *ptep) + (gva & (vm->page_size - 1)); return pte_addr(vm, *ptep) + (gva & (vm->page_size - 1));
unmapped_gva: unmapped_gva:
TEST_ASSERT(false, "No mapping for vm virtual address, " TEST_FAIL("No mapping for vm virtual address, gva: 0x%lx", gva);
"gva: 0x%lx", gva);
exit(1); exit(1);
} }
...@@ -262,11 +261,11 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *ini ...@@ -262,11 +261,11 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *ini
switch (vm->mode) { switch (vm->mode) {
case VM_MODE_P52V48_4K: case VM_MODE_P52V48_4K:
TEST_ASSERT(false, "AArch64 does not support 4K sized pages " TEST_FAIL("AArch64 does not support 4K sized pages "
"with 52-bit physical address ranges"); "with 52-bit physical address ranges");
case VM_MODE_PXXV48_4K: case VM_MODE_PXXV48_4K:
TEST_ASSERT(false, "AArch64 does not support 4K sized pages " TEST_FAIL("AArch64 does not support 4K sized pages "
"with ANY-bit physical address ranges"); "with ANY-bit physical address ranges");
case VM_MODE_P52V48_64K: case VM_MODE_P52V48_64K:
tcr_el1 |= 1ul << 14; /* TG0 = 64KB */ tcr_el1 |= 1ul << 14; /* TG0 = 64KB */
tcr_el1 |= 6ul << 32; /* IPS = 52 bits */ tcr_el1 |= 6ul << 32; /* IPS = 52 bits */
...@@ -288,7 +287,7 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *ini ...@@ -288,7 +287,7 @@ void aarch64_vcpu_setup(struct kvm_vm *vm, int vcpuid, struct kvm_vcpu_init *ini
tcr_el1 |= 2ul << 32; /* IPS = 40 bits */ tcr_el1 |= 2ul << 32; /* IPS = 40 bits */
break; break;
default: default:
TEST_ASSERT(false, "Unknown guest mode, mode: 0x%x", vm->mode); TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode);
} }
sctlr_el1 |= (1 << 0) | (1 << 2) | (1 << 12) /* M | C | I */; sctlr_el1 |= (1 << 0) | (1 << 2) | (1 << 12) /* M | C | I */;
......
...@@ -62,7 +62,7 @@ void ucall_init(struct kvm_vm *vm, void *arg) ...@@ -62,7 +62,7 @@ void ucall_init(struct kvm_vm *vm, void *arg)
if (ucall_mmio_init(vm, start + offset)) if (ucall_mmio_init(vm, start + offset))
return; return;
} }
TEST_ASSERT(false, "Can't find a ucall mmio address"); TEST_FAIL("Can't find a ucall mmio address");
} }
void ucall_uninit(struct kvm_vm *vm) void ucall_uninit(struct kvm_vm *vm)
......
...@@ -61,9 +61,9 @@ ssize_t test_write(int fd, const void *buf, size_t count) ...@@ -61,9 +61,9 @@ ssize_t test_write(int fd, const void *buf, size_t count)
continue; continue;
case 0: case 0:
TEST_ASSERT(false, "Unexpected EOF,\n" TEST_FAIL("Unexpected EOF,\n"
" rc: %zi num_written: %zi num_left: %zu", " rc: %zi num_written: %zi num_left: %zu",
rc, num_written, num_left); rc, num_written, num_left);
break; break;
default: default:
...@@ -138,9 +138,9 @@ ssize_t test_read(int fd, void *buf, size_t count) ...@@ -138,9 +138,9 @@ ssize_t test_read(int fd, void *buf, size_t count)
break; break;
case 0: case 0:
TEST_ASSERT(false, "Unexpected EOF,\n" TEST_FAIL("Unexpected EOF,\n"
" rc: %zi num_read: %zi num_left: %zu", " rc: %zi num_read: %zi num_left: %zu",
rc, num_read, num_left); rc, num_read, num_left);
break; break;
default: default:
......
...@@ -198,12 +198,11 @@ struct kvm_vm *_vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm) ...@@ -198,12 +198,11 @@ struct kvm_vm *_vm_create(enum vm_guest_mode mode, uint64_t phy_pages, int perm)
vm->pa_bits); vm->pa_bits);
vm->pgtable_levels = 4; vm->pgtable_levels = 4;
#else #else
TEST_ASSERT(false, "VM_MODE_PXXV48_4K not supported on " TEST_FAIL("VM_MODE_PXXV48_4K not supported on non-x86 platforms");
"non-x86 platforms");
#endif #endif
break; break;
default: default:
TEST_ASSERT(false, "Unknown guest mode, mode: 0x%x", mode); TEST_FAIL("Unknown guest mode, mode: 0x%x", mode);
} }
#ifdef __aarch64__ #ifdef __aarch64__
...@@ -603,7 +602,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, ...@@ -603,7 +602,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
region = (struct userspace_mem_region *) userspace_mem_region_find( region = (struct userspace_mem_region *) userspace_mem_region_find(
vm, guest_paddr, (guest_paddr + npages * vm->page_size) - 1); vm, guest_paddr, (guest_paddr + npages * vm->page_size) - 1);
if (region != NULL) if (region != NULL)
TEST_ASSERT(false, "overlapping userspace_mem_region already " TEST_FAIL("overlapping userspace_mem_region already "
"exists\n" "exists\n"
" requested guest_paddr: 0x%lx npages: 0x%lx " " requested guest_paddr: 0x%lx npages: 0x%lx "
"page_size: 0x%x\n" "page_size: 0x%x\n"
...@@ -619,7 +618,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm, ...@@ -619,7 +618,7 @@ void vm_userspace_mem_region_add(struct kvm_vm *vm,
break; break;
} }
if (region != NULL) if (region != NULL)
TEST_ASSERT(false, "A mem region with the requested slot " TEST_FAIL("A mem region with the requested slot "
"already exists.\n" "already exists.\n"
" requested slot: %u paddr: 0x%lx npages: 0x%lx\n" " requested slot: %u paddr: 0x%lx npages: 0x%lx\n"
" existing slot: %u paddr: 0x%lx size: 0x%lx", " existing slot: %u paddr: 0x%lx size: 0x%lx",
...@@ -723,7 +722,7 @@ memslot2region(struct kvm_vm *vm, uint32_t memslot) ...@@ -723,7 +722,7 @@ memslot2region(struct kvm_vm *vm, uint32_t memslot)
" requested slot: %u\n", memslot); " requested slot: %u\n", memslot);
fputs("---- vm dump ----\n", stderr); fputs("---- vm dump ----\n", stderr);
vm_dump(stderr, vm, 2); vm_dump(stderr, vm, 2);
TEST_ASSERT(false, "Mem region not found"); TEST_FAIL("Mem region not found");
} }
return region; return region;
...@@ -841,7 +840,7 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid) ...@@ -841,7 +840,7 @@ void vm_vcpu_add(struct kvm_vm *vm, uint32_t vcpuid)
/* Confirm a vcpu with the specified id doesn't already exist. */ /* Confirm a vcpu with the specified id doesn't already exist. */
vcpu = vcpu_find(vm, vcpuid); vcpu = vcpu_find(vm, vcpuid);
if (vcpu != NULL) if (vcpu != NULL)
TEST_ASSERT(false, "vcpu with the specified id " TEST_FAIL("vcpu with the specified id "
"already exists,\n" "already exists,\n"
" requested vcpuid: %u\n" " requested vcpuid: %u\n"
" existing vcpuid: %u state: %p", " existing vcpuid: %u state: %p",
...@@ -934,8 +933,7 @@ static vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz, ...@@ -934,8 +933,7 @@ static vm_vaddr_t vm_vaddr_unused_gap(struct kvm_vm *vm, size_t sz,
} while (pgidx_start != 0); } while (pgidx_start != 0);
no_va_found: no_va_found:
TEST_ASSERT(false, "No vaddr of specified pages available, " TEST_FAIL("No vaddr of specified pages available, pages: 0x%lx", pages);
"pages: 0x%lx", pages);
/* NOT REACHED */ /* NOT REACHED */
return -1; return -1;
...@@ -1070,7 +1068,7 @@ void *addr_gpa2hva(struct kvm_vm *vm, vm_paddr_t gpa) ...@@ -1070,7 +1068,7 @@ void *addr_gpa2hva(struct kvm_vm *vm, vm_paddr_t gpa)
+ (gpa - region->region.guest_phys_addr)); + (gpa - region->region.guest_phys_addr));
} }
TEST_ASSERT(false, "No vm physical memory at 0x%lx", gpa); TEST_FAIL("No vm physical memory at 0x%lx", gpa);
return NULL; return NULL;
} }
...@@ -1104,8 +1102,7 @@ vm_paddr_t addr_hva2gpa(struct kvm_vm *vm, void *hva) ...@@ -1104,8 +1102,7 @@ vm_paddr_t addr_hva2gpa(struct kvm_vm *vm, void *hva)
+ (hva - (uintptr_t) region->host_mem)); + (hva - (uintptr_t) region->host_mem));
} }
TEST_ASSERT(false, "No mapping to a guest physical address, " TEST_FAIL("No mapping to a guest physical address, hva: %p", hva);
"hva: %p", hva);
return -1; return -1;
} }
......
...@@ -506,8 +506,7 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva) ...@@ -506,8 +506,7 @@ vm_paddr_t addr_gva2gpa(struct kvm_vm *vm, vm_vaddr_t gva)
return (pte[index[0]].address * vm->page_size) + (gva & 0xfffu); return (pte[index[0]].address * vm->page_size) + (gva & 0xfffu);
unmapped_gva: unmapped_gva:
TEST_ASSERT(false, "No mapping for vm virtual address, " TEST_FAIL("No mapping for vm virtual address, gva: 0x%lx", gva);
"gva: 0x%lx", gva);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
...@@ -564,7 +563,7 @@ static void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_m ...@@ -564,7 +563,7 @@ static void vcpu_setup(struct kvm_vm *vm, int vcpuid, int pgd_memslot, int gdt_m
break; break;
default: default:
TEST_ASSERT(false, "Unknown guest mode, mode: 0x%x", vm->mode); TEST_FAIL("Unknown guest mode, mode: 0x%x", vm->mode);
} }
sregs.cr3 = vm->pgd; sregs.cr3 = vm->pgd;
......
...@@ -101,12 +101,12 @@ int main(int argc, char *argv[]) ...@@ -101,12 +101,12 @@ int main(int argc, char *argv[])
vcpu_sregs_set(vm, VCPU_ID, &sregs); vcpu_sregs_set(vm, VCPU_ID, &sregs);
break; break;
case UCALL_ABORT: case UCALL_ABORT:
TEST_ASSERT(false, "Guest CR4 bit (OSXSAVE) unsynchronized with CPUID bit."); TEST_FAIL("Guest CR4 bit (OSXSAVE) unsynchronized with CPUID bit.");
break; break;
case UCALL_DONE: case UCALL_DONE:
goto done; goto done;
default: default:
TEST_ASSERT(false, "Unknown ucall %lu", uc.cmd); TEST_FAIL("Unknown ucall %lu", uc.cmd);
} }
} }
......
...@@ -109,15 +109,15 @@ int main(int argc, char *argv[]) ...@@ -109,15 +109,15 @@ int main(int argc, char *argv[])
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vm, VCPU_ID, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
TEST_ASSERT(false, "%s at %s:%ld", (const char *)uc.args[0], TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0],
__FILE__, uc.args[1]); __FILE__, uc.args[1]);
/* NOT REACHED */ /* NOT REACHED */
case UCALL_SYNC: case UCALL_SYNC:
break; break;
case UCALL_DONE: case UCALL_DONE:
goto done; goto done;
default: default:
TEST_ASSERT(false, "Unknown ucall %lu", uc.cmd); TEST_FAIL("Unknown ucall %lu", uc.cmd);
} }
/* UCALL_SYNC is handled here. */ /* UCALL_SYNC is handled here. */
......
...@@ -152,15 +152,15 @@ int main(int argc, char *argv[]) ...@@ -152,15 +152,15 @@ int main(int argc, char *argv[])
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vm, VCPU_ID, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
TEST_ASSERT(false, "%s at %s:%ld", (const char *)uc.args[0], TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0],
__FILE__, uc.args[1]); __FILE__, uc.args[1]);
/* NOT REACHED */ /* NOT REACHED */
case UCALL_SYNC: case UCALL_SYNC:
break; break;
case UCALL_DONE: case UCALL_DONE:
goto done; goto done;
default: default:
TEST_ASSERT(false, "Unknown ucall %lu", uc.cmd); TEST_FAIL("Unknown ucall %lu", uc.cmd);
} }
/* UCALL_SYNC is handled here. */ /* UCALL_SYNC is handled here. */
......
...@@ -61,15 +61,14 @@ int main(int argc, char *argv[]) ...@@ -61,15 +61,14 @@ int main(int argc, char *argv[])
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vm, VCPU_ID, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
TEST_ASSERT(false, "%s", TEST_FAIL("%s", (const char *)uc.args[0]);
(const char *)uc.args[0]);
/* NOT REACHED */ /* NOT REACHED */
case UCALL_SYNC: case UCALL_SYNC:
break; break;
case UCALL_DONE: case UCALL_DONE:
goto done; goto done;
default: default:
TEST_ASSERT(false, "Unknown ucall 0x%lx.", uc.cmd); TEST_FAIL("Unknown ucall 0x%lx.", uc.cmd);
} }
} }
done: done:
......
...@@ -78,10 +78,10 @@ int main(int argc, char *argv[]) ...@@ -78,10 +78,10 @@ int main(int argc, char *argv[])
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vm, VCPU_ID, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
TEST_ASSERT(false, "%s", (const char *)uc.args[0]); TEST_FAIL("%s", (const char *)uc.args[0]);
/* NOT REACHED */ /* NOT REACHED */
default: default:
TEST_ASSERT(false, "Unknown ucall %lu", uc.cmd); TEST_FAIL("Unknown ucall %lu", uc.cmd);
} }
} }
} }
...@@ -125,8 +125,8 @@ int main(int argc, char *argv[]) ...@@ -125,8 +125,8 @@ int main(int argc, char *argv[])
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vm, VCPU_ID, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
TEST_ASSERT(false, "%s at %s:%ld", (const char *)uc.args[0], TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0],
__FILE__, uc.args[1]); __FILE__, uc.args[1]);
/* NOT REACHED */ /* NOT REACHED */
case UCALL_SYNC: case UCALL_SYNC:
/* /*
...@@ -151,7 +151,7 @@ int main(int argc, char *argv[]) ...@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
done = true; done = true;
break; break;
default: default:
TEST_ASSERT(false, "Unknown ucall %lu", uc.cmd); TEST_FAIL("Unknown ucall %lu", uc.cmd);
} }
} }
} }
...@@ -150,7 +150,7 @@ int main(int argc, char *argv[]) ...@@ -150,7 +150,7 @@ int main(int argc, char *argv[])
switch (get_ucall(vm, VCPU_ID, &uc)) { switch (get_ucall(vm, VCPU_ID, &uc)) {
case UCALL_ABORT: case UCALL_ABORT:
TEST_ASSERT(false, "%s", (const char *)uc.args[0]); TEST_FAIL("%s", (const char *)uc.args[0]);
/* NOT REACHED */ /* NOT REACHED */
case UCALL_SYNC: case UCALL_SYNC:
report(uc.args[1]); report(uc.args[1]);
...@@ -158,7 +158,7 @@ int main(int argc, char *argv[]) ...@@ -158,7 +158,7 @@ int main(int argc, char *argv[])
case UCALL_DONE: case UCALL_DONE:
goto done; goto done;
default: default:
TEST_ASSERT(false, "Unknown ucall %lu", uc.cmd); TEST_FAIL("Unknown ucall %lu", uc.cmd);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment