Commit 1d438b3b authored by Sean Christopherson's avatar Sean Christopherson Committed by Paolo Bonzini

KVM: selftests: Split vcpu_set_nested_state() into two helpers

Split vcpu_nested_state_set() into a wrapper that asserts, and an inner
helper that does not.  Passing a bool is all kinds of awful as it's
unintuitive for readers and requires returning an 'int' from a function
that for most users can never return anything other than "success".
Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 2ab2c307
...@@ -261,8 +261,10 @@ void vcpu_events_set(struct kvm_vm *vm, uint32_t vcpuid, ...@@ -261,8 +261,10 @@ void vcpu_events_set(struct kvm_vm *vm, uint32_t vcpuid,
#ifdef __x86_64__ #ifdef __x86_64__
void vcpu_nested_state_get(struct kvm_vm *vm, uint32_t vcpuid, void vcpu_nested_state_get(struct kvm_vm *vm, uint32_t vcpuid,
struct kvm_nested_state *state); struct kvm_nested_state *state);
int vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid, int __vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
struct kvm_nested_state *state, bool ignore_error); struct kvm_nested_state *state);
void vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
struct kvm_nested_state *state);
#endif #endif
void *vcpu_map_dirty_ring(struct kvm_vm *vm, uint32_t vcpuid); void *vcpu_map_dirty_ring(struct kvm_vm *vm, uint32_t vcpuid);
......
...@@ -1826,22 +1826,22 @@ void vcpu_nested_state_get(struct kvm_vm *vm, uint32_t vcpuid, ...@@ -1826,22 +1826,22 @@ void vcpu_nested_state_get(struct kvm_vm *vm, uint32_t vcpuid,
ret, errno); ret, errno);
} }
int vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid, int __vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
struct kvm_nested_state *state, bool ignore_error) struct kvm_nested_state *state)
{ {
struct vcpu *vcpu = vcpu_find(vm, vcpuid); struct vcpu *vcpu = vcpu_find(vm, vcpuid);
int ret;
TEST_ASSERT(vcpu != NULL, "vcpu not found, vcpuid: %u", vcpuid); TEST_ASSERT(vcpu != NULL, "vcpu not found, vcpuid: %u", vcpuid);
ret = ioctl(vcpu->fd, KVM_SET_NESTED_STATE, state); return ioctl(vcpu->fd, KVM_SET_NESTED_STATE, state);
if (!ignore_error) { }
TEST_ASSERT(ret == 0,
"KVM_SET_NESTED_STATE failed, ret: %i errno: %i",
ret, errno);
}
return ret; void vcpu_nested_state_set(struct kvm_vm *vm, uint32_t vcpuid,
struct kvm_nested_state *state)
{
int ret = __vcpu_nested_state_set(vm, vcpuid, state);
TEST_ASSERT(!ret, "KVM_SET_NESTED_STATE failed, ret: %i errno: %i", ret, errno);
} }
#endif #endif
......
...@@ -29,7 +29,7 @@ bool have_evmcs; ...@@ -29,7 +29,7 @@ bool have_evmcs;
void test_nested_state(struct kvm_vm *vm, struct kvm_nested_state *state) void test_nested_state(struct kvm_vm *vm, struct kvm_nested_state *state)
{ {
vcpu_nested_state_set(vm, VCPU_ID, state, false); vcpu_nested_state_set(vm, VCPU_ID, state);
} }
void test_nested_state_expect_errno(struct kvm_vm *vm, void test_nested_state_expect_errno(struct kvm_vm *vm,
...@@ -38,7 +38,7 @@ void test_nested_state_expect_errno(struct kvm_vm *vm, ...@@ -38,7 +38,7 @@ void test_nested_state_expect_errno(struct kvm_vm *vm,
{ {
int rv; int rv;
rv = vcpu_nested_state_set(vm, VCPU_ID, state, true); rv = __vcpu_nested_state_set(vm, VCPU_ID, state);
TEST_ASSERT(rv == -1 && errno == expected_errno, TEST_ASSERT(rv == -1 && errno == expected_errno,
"Expected %s (%d) from vcpu_nested_state_set but got rv: %i errno: %s (%d)", "Expected %s (%d) from vcpu_nested_state_set but got rv: %i errno: %s (%d)",
strerror(expected_errno), expected_errno, rv, strerror(errno), strerror(expected_errno), expected_errno, rv, strerror(errno),
......
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