diff options
author | Sean Christopherson <seanjc@google.com> | 2023-07-12 02:01:26 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2023-07-29 18:05:28 +0300 |
commit | 625646aede90554fed8d46fd0e081238e071ac5e (patch) | |
tree | 53f583f6e0648242005678c531de2efb7c24673e /tools/testing/selftests/kvm/kvm_binary_stats_test.c | |
parent | eed3013faa401aae662398709410a59bb0646e32 (diff) | |
download | linux-625646aede90554fed8d46fd0e081238e071ac5e.tar.xz |
KVM: selftests: Use pread() to read binary stats header
Use pread() with an explicit offset when reading the header and the header
name for a binary stats fd so that the common helper and the binary stats
test don't subtly rely on the file effectively being untouched, e.g. to
allow multiple reads of the header, name, etc.
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20230711230131.648752-3-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'tools/testing/selftests/kvm/kvm_binary_stats_test.c')
-rw-r--r-- | tools/testing/selftests/kvm/kvm_binary_stats_test.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c index a7001e29dc06..eae99d0e8377 100644 --- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c +++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c @@ -43,8 +43,10 @@ static void stats_test(int stats_fd) id = malloc(header.name_size); TEST_ASSERT(id, "Allocate memory for id string"); - ret = read(stats_fd, id, header.name_size); - TEST_ASSERT(ret == header.name_size, "Read id string"); + ret = pread(stats_fd, id, header.name_size, sizeof(header)); + TEST_ASSERT(ret == header.name_size, + "Expected header size '%u', read '%lu' bytes", + header.name_size, ret); /* Check id string, that should start with "kvm" */ TEST_ASSERT(!strncmp(id, "kvm", 3) && strlen(id) < header.name_size, |