Skip to content

Commit 7eebae7

Browse files
ouptonbonzini
authored andcommitted
selftests: KVM: Provide descriptive assertions in kvm_binary_stats_test
As it turns out, tests sometimes fail. When that is the case, packing the test assertion with as much relevant information helps track down the problem more quickly. Sharpen up the stat descriptor assertions in kvm_binary_stats_test to more precisely describe the reason for the test assertion and which stat is to blame. Signed-off-by: Oliver Upton <oupton@google.com> Reviewed-by: Andrew Jones <andrew.jones@linux.dev> Message-Id: <20220719143134.3246798-3-oliver.upton@linux.dev> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent ad5b072 commit 7eebae7

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

tools/testing/selftests/kvm/kvm_binary_stats_test.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static void stats_test(int stats_fd)
3131
struct kvm_stats_desc *stats_desc;
3232
u64 *stats_data;
3333
struct kvm_stats_desc *pdesc;
34+
u32 type, unit, base;
3435

3536
/* Read kvm stats header */
3637
read_stats_header(stats_fd, &header);
@@ -72,18 +73,21 @@ static void stats_test(int stats_fd)
7273
/* Sanity check for fields in descriptors */
7374
for (i = 0; i < header.num_desc; ++i) {
7475
pdesc = get_stats_descriptor(stats_desc, i, &header);
76+
type = pdesc->flags & KVM_STATS_TYPE_MASK;
77+
unit = pdesc->flags & KVM_STATS_UNIT_MASK;
78+
base = pdesc->flags & KVM_STATS_BASE_MASK;
7579

7680
/* Check name string */
7781
TEST_ASSERT(strlen(pdesc->name) < header.name_size,
7882
"KVM stats name (index: %d) too long", i);
7983

8084
/* Check type,unit,base boundaries */
81-
TEST_ASSERT((pdesc->flags & KVM_STATS_TYPE_MASK) <= KVM_STATS_TYPE_MAX,
82-
"Unknown KVM stats type");
83-
TEST_ASSERT((pdesc->flags & KVM_STATS_UNIT_MASK) <= KVM_STATS_UNIT_MAX,
84-
"Unknown KVM stats unit");
85-
TEST_ASSERT((pdesc->flags & KVM_STATS_BASE_MASK) <= KVM_STATS_BASE_MAX,
86-
"Unknown KVM stats base");
85+
TEST_ASSERT(type <= KVM_STATS_TYPE_MAX,
86+
"Unknown KVM stats (%s) type: %u", pdesc->name, type);
87+
TEST_ASSERT(unit <= KVM_STATS_UNIT_MAX,
88+
"Unknown KVM stats (%s) unit: %u", pdesc->name, unit);
89+
TEST_ASSERT(base <= KVM_STATS_BASE_MAX,
90+
"Unknown KVM stats (%s) base: %u", pdesc->name, base);
8791

8892
/*
8993
* Check exponent for stats unit
@@ -97,10 +101,14 @@ static void stats_test(int stats_fd)
97101
case KVM_STATS_UNIT_NONE:
98102
case KVM_STATS_UNIT_BYTES:
99103
case KVM_STATS_UNIT_CYCLES:
100-
TEST_ASSERT(pdesc->exponent >= 0, "Unsupported KVM stats unit");
104+
TEST_ASSERT(pdesc->exponent >= 0,
105+
"Unsupported KVM stats (%s) exponent: %i",
106+
pdesc->name, pdesc->exponent);
101107
break;
102108
case KVM_STATS_UNIT_SECONDS:
103-
TEST_ASSERT(pdesc->exponent <= 0, "Unsupported KVM stats unit");
109+
TEST_ASSERT(pdesc->exponent <= 0,
110+
"Unsupported KVM stats (%s) exponent: %i",
111+
pdesc->name, pdesc->exponent);
104112
break;
105113
}
106114

0 commit comments

Comments
 (0)