@@ -77,6 +77,8 @@ static void stats_test(int stats_fd)
<= KVM_STATS_UNIT_MAX, "Unknown KVM stats unit");
TEST_ASSERT((pdesc->flags & KVM_STATS_BASE_MASK)
<= KVM_STATS_BASE_MAX, "Unknown KVM stats base");
+ TEST_ASSERT((pdesc->flags & KVM_STATS_MODE_MASK)
+ <= KVM_STATS_MODE_MAX, "Unknown KVM stats mode");
/* Check exponent for stats unit
* Exponent for counter should be greater than or equal to 0
* Exponent for unit bytes should be greater than or equal to 0
@@ -106,11 +108,18 @@ static void stats_test(int stats_fd)
}
/* Check overlap */
TEST_ASSERT(header->data_offset >= header->desc_offset
- || header->data_offset + size_data <= header->desc_offset,
- "Data block is overlapped with Descriptor block");
+ || header->data_offset + size_data <= header->desc_offset,
+ "Data block is overlapped with Descriptor block");
/* Check validity of all stats data size */
TEST_ASSERT(size_data >= header->count * sizeof(stats_data->value[0]),
"Data size is not correct");
+ /* Check stats offset */
+ for (i = 0; i < header->count; ++i) {
+ pdesc = (void *)stats_desc + i * size_desc;
+ TEST_ASSERT(pdesc->offset < size_data,
+ "Invalid offset (%u) for stats: %s",
+ pdesc->offset, pdesc->name);
+ }
/* Allocate memory for stats data */
stats_data = malloc(size_data);
Update binary stats selftest to support sanity test for stats read/write mode and offset. Signed-off-by: Jing Zhang <jingzhangos@google.com> --- tools/testing/selftests/kvm/kvm_binary_stats_test.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)