KVM: selftests: Replace assert() with TEST_ASSERT_EQ()
authorPratik R. Sampat <prsampat@amd.com>
Wed, 5 Mar 2025 22:59:55 +0000 (16:59 -0600)
committerSean Christopherson <seanjc@google.com>
Fri, 2 May 2025 19:32:33 +0000 (12:32 -0700)
For SEV tests, assert() failures on VM type or fd do not provide
sufficient error reporting. Replace assert() with TEST_ASSERT_EQ() to
obtain more detailed information on the assertion condition failure,
including the call stack.

Signed-off-by: Pratik R. Sampat <prsampat@amd.com>
Link: https://lore.kernel.org/r/20250305230000.231025-6-prsampat@amd.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/lib/x86/sev.c

index e9535ee20b7fcb7c328cfae0ec868af07d6a0295..60d7a03dc1c250a14295fd6514987330fe2de88c 100644 (file)
@@ -37,12 +37,12 @@ static void encrypt_region(struct kvm_vm *vm, struct userspace_mem_region *regio
 void sev_vm_init(struct kvm_vm *vm)
 {
        if (vm->type == KVM_X86_DEFAULT_VM) {
-               assert(vm->arch.sev_fd == -1);
+               TEST_ASSERT_EQ(vm->arch.sev_fd, -1);
                vm->arch.sev_fd = open_sev_dev_path_or_exit();
                vm_sev_ioctl(vm, KVM_SEV_INIT, NULL);
        } else {
                struct kvm_sev_init init = { 0 };
-               assert(vm->type == KVM_X86_SEV_VM);
+               TEST_ASSERT_EQ(vm->type, KVM_X86_SEV_VM);
                vm_sev_ioctl(vm, KVM_SEV_INIT2, &init);
        }
 }
@@ -50,12 +50,12 @@ void sev_vm_init(struct kvm_vm *vm)
 void sev_es_vm_init(struct kvm_vm *vm)
 {
        if (vm->type == KVM_X86_DEFAULT_VM) {
-               assert(vm->arch.sev_fd == -1);
+               TEST_ASSERT_EQ(vm->arch.sev_fd, -1);
                vm->arch.sev_fd = open_sev_dev_path_or_exit();
                vm_sev_ioctl(vm, KVM_SEV_ES_INIT, NULL);
        } else {
                struct kvm_sev_init init = { 0 };
-               assert(vm->type == KVM_X86_SEV_ES_VM);
+               TEST_ASSERT_EQ(vm->type, KVM_X86_SEV_ES_VM);
                vm_sev_ioctl(vm, KVM_SEV_INIT2, &init);
        }
 }