Skip to content

Commit 87d5358

Browse files
sean-jcbonzini
authored andcommitted
KVM: selftests: Clean up stats fd in common stats_test() helper
Move the stats fd cleanup code into stats_test() and drop the superfluous vm_stats_test() and vcpu_stats_test() helpers in order to decouple creation of the stats file from consuming/testing the file (deduping code is a bonus). This will make it easier to test various edge cases related to stats, e.g. that userspace can dup() a stats fd, that userspace can have multiple stats files for a singleVM/vCPU, etc. Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20230711230131.648752-4-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 625646a commit 87d5358

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

tools/testing/selftests/kvm/kvm_binary_stats_test.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,7 @@ static void stats_test(int stats_fd)
167167
free(stats_data);
168168
free(stats_desc);
169169
free(id);
170-
}
171-
172-
173-
static void vm_stats_test(struct kvm_vm *vm)
174-
{
175-
int stats_fd = vm_get_stats_fd(vm);
176-
177-
stats_test(stats_fd);
178-
close(stats_fd);
179-
TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");
180-
}
181-
182-
static void vcpu_stats_test(struct kvm_vcpu *vcpu)
183-
{
184-
int stats_fd = vcpu_get_stats_fd(vcpu);
185170

186-
stats_test(stats_fd);
187171
close(stats_fd);
188172
TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");
189173
}
@@ -241,9 +225,11 @@ int main(int argc, char *argv[])
241225

242226
/* Check stats read for every VM and VCPU */
243227
for (i = 0; i < max_vm; ++i) {
244-
vm_stats_test(vms[i]);
228+
stats_test(vm_get_stats_fd(vms[i]));
229+
245230
for (j = 0; j < max_vcpu; ++j)
246-
vcpu_stats_test(vcpus[i * max_vcpu + j]);
231+
stats_test(vcpu_get_stats_fd(vcpus[i * max_vcpu + j]));
232+
247233
ksft_test_result_pass("vm%i\n", i);
248234
}
249235

0 commit comments

Comments
 (0)