Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Oliver Upton and committed by
Paolo Bonzini
7eebae78 ad5b0727

+16 -8
+16 -8
tools/testing/selftests/kvm/kvm_binary_stats_test.c
··· 31 31 struct kvm_stats_desc *stats_desc; 32 32 u64 *stats_data; 33 33 struct kvm_stats_desc *pdesc; 34 + u32 type, unit, base; 34 35 35 36 /* Read kvm stats header */ 36 37 read_stats_header(stats_fd, &header); ··· 73 72 /* Sanity check for fields in descriptors */ 74 73 for (i = 0; i < header.num_desc; ++i) { 75 74 pdesc = get_stats_descriptor(stats_desc, i, &header); 75 + type = pdesc->flags & KVM_STATS_TYPE_MASK; 76 + unit = pdesc->flags & KVM_STATS_UNIT_MASK; 77 + base = pdesc->flags & KVM_STATS_BASE_MASK; 76 78 77 79 /* Check name string */ 78 80 TEST_ASSERT(strlen(pdesc->name) < header.name_size, 79 81 "KVM stats name (index: %d) too long", i); 80 82 81 83 /* Check type,unit,base boundaries */ 82 - TEST_ASSERT((pdesc->flags & KVM_STATS_TYPE_MASK) <= KVM_STATS_TYPE_MAX, 83 - "Unknown KVM stats type"); 84 - TEST_ASSERT((pdesc->flags & KVM_STATS_UNIT_MASK) <= KVM_STATS_UNIT_MAX, 85 - "Unknown KVM stats unit"); 86 - TEST_ASSERT((pdesc->flags & KVM_STATS_BASE_MASK) <= KVM_STATS_BASE_MAX, 87 - "Unknown KVM stats base"); 84 + TEST_ASSERT(type <= KVM_STATS_TYPE_MAX, 85 + "Unknown KVM stats (%s) type: %u", pdesc->name, type); 86 + TEST_ASSERT(unit <= KVM_STATS_UNIT_MAX, 87 + "Unknown KVM stats (%s) unit: %u", pdesc->name, unit); 88 + TEST_ASSERT(base <= KVM_STATS_BASE_MAX, 89 + "Unknown KVM stats (%s) base: %u", pdesc->name, base); 88 90 89 91 /* 90 92 * Check exponent for stats unit ··· 101 97 case KVM_STATS_UNIT_NONE: 102 98 case KVM_STATS_UNIT_BYTES: 103 99 case KVM_STATS_UNIT_CYCLES: 104 - TEST_ASSERT(pdesc->exponent >= 0, "Unsupported KVM stats unit"); 100 + TEST_ASSERT(pdesc->exponent >= 0, 101 + "Unsupported KVM stats (%s) exponent: %i", 102 + pdesc->name, pdesc->exponent); 105 103 break; 106 104 case KVM_STATS_UNIT_SECONDS: 107 - TEST_ASSERT(pdesc->exponent <= 0, "Unsupported KVM stats unit"); 105 + TEST_ASSERT(pdesc->exponent <= 0, 106 + "Unsupported KVM stats (%s) exponent: %i", 107 + pdesc->name, pdesc->exponent); 108 108 break; 109 109 } 110 110