KVM: selftests: Read binary stats header in lib

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>
This commit is contained in:
Ben Gardon 2022-06-13 21:25:15 +00:00 committed by Paolo Bonzini
parent fcd48a213f
commit 32faa0647c
2 changed files with 10 additions and 2 deletions

View 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,

View 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 */