[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230711230131.648752-4-seanjc@google.com>
Date: Tue, 11 Jul 2023 16:01:27 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: Paolo Bonzini <pbonzini@...hat.com>
Cc: kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
Zheng Zhang <zheng.zhang@...il.ucr.edu>,
Kees Cook <keescook@...omium.org>,
Sean Christopherson <seanjc@...gle.com>
Subject: [PATCH 3/7] 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@...gle.com>
---
.../selftests/kvm/kvm_binary_stats_test.c | 22 ++++---------------
1 file changed, 4 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
index eae99d0e8377..f02663711c90 100644
--- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c
+++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
@@ -167,23 +167,7 @@ static void stats_test(int stats_fd)
free(stats_data);
free(stats_desc);
free(id);
-}
-
-static void vm_stats_test(struct kvm_vm *vm)
-{
- int stats_fd = vm_get_stats_fd(vm);
-
- stats_test(stats_fd);
- close(stats_fd);
- TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");
-}
-
-static void vcpu_stats_test(struct kvm_vcpu *vcpu)
-{
- int stats_fd = vcpu_get_stats_fd(vcpu);
-
- stats_test(stats_fd);
close(stats_fd);
TEST_ASSERT(fcntl(stats_fd, F_GETFD) == -1, "Stats fd not freed");
}
@@ -241,9 +225,11 @@ int main(int argc, char *argv[])
/* Check stats read for every VM and VCPU */
for (i = 0; i < max_vm; ++i) {
- vm_stats_test(vms[i]);
+ stats_test(vm_get_stats_fd(vms[i]));
+
for (j = 0; j < max_vcpu; ++j)
- vcpu_stats_test(vcpus[i * max_vcpu + j]);
+ stats_test(vcpu_get_stats_fd(vcpus[i * max_vcpu + j]));
+
ksft_test_result_pass("vm%i\n", i);
}
--
2.41.0.255.g8b1d071c50-goog
Powered by blists - more mailing lists