OSDN Git Service

KVM: selftests: Read binary stats header in lib
authorBen Gardon <bgardon@google.com>
Mon, 13 Jun 2022 21:25:15 +0000 (21:25 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 24 Jun 2022 08:51:43 +0000 (04:51 -0400)
Move the code to read the binary stats header to the KVM selftests
library. It will be re-used by other tests to check KVM behavior.

No functional change intended.

Reviewed-by: David Matlack <dmatlack@google.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Ben Gardon <bgardon@google.com>
Message-Id: <20220613212523.3436117-3-bgardon@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
tools/testing/selftests/kvm/include/kvm_util_base.h
tools/testing/selftests/kvm/kvm_binary_stats_test.c

index 7ebfc8c..669fe4b 100644 (file)
@@ -308,6 +308,14 @@ static inline int vm_get_stats_fd(struct kvm_vm *vm)
        return fd;
 }
 
+static inline void read_stats_header(int stats_fd, struct kvm_stats_header *header)
+{
+       ssize_t ret;
+
+       ret = read(stats_fd, header, sizeof(*header));
+       TEST_ASSERT(ret == sizeof(*header), "Read stats header");
+}
+
 void vm_create_irqchip(struct kvm_vm *vm);
 
 void vm_set_user_memory_region(struct kvm_vm *vm, uint32_t slot, uint32_t flags,
index ac5c3d0..2a90b62 100644 (file)
@@ -33,8 +33,8 @@ static void stats_test(int stats_fd)
        struct kvm_stats_desc *pdesc;
 
        /* Read kvm stats header */
-       ret = read(stats_fd, &header, sizeof(header));
-       TEST_ASSERT(ret == sizeof(header), "Read stats header");
+       read_stats_header(stats_fd, &header);
+
        size_desc = sizeof(*stats_desc) + header.name_size;
 
        /* Read kvm stats id string */