All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oliver.upton@linux.dev>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, seanjc@google.com, Oliver Upton <oupton@google.com>
Subject: [PATCH 2/3] selftests: KVM: Provide descriptive assertions in kvm_binary_stats_test
Date: Tue, 19 Jul 2022 14:31:33 +0000	[thread overview]
Message-ID: <20220719143134.3246798-3-oliver.upton@linux.dev> (raw)
In-Reply-To: <20220719143134.3246798-1-oliver.upton@linux.dev>

From: Oliver Upton <oupton@google.com>

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>
---
 .../selftests/kvm/kvm_binary_stats_test.c     | 24 ++++++++++++-------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/kvm/kvm_binary_stats_test.c b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
index 40227ad9ba0c..3237c7c94bf0 100644
--- a/tools/testing/selftests/kvm/kvm_binary_stats_test.c
+++ b/tools/testing/selftests/kvm/kvm_binary_stats_test.c
@@ -31,6 +31,7 @@ static void stats_test(int stats_fd)
 	struct kvm_stats_desc *stats_desc;
 	u64 *stats_data;
 	struct kvm_stats_desc *pdesc;
+	u32 type, unit, base;
 
 	/* Read kvm stats header */
 	read_stats_header(stats_fd, &header);
@@ -72,18 +73,21 @@ static void stats_test(int stats_fd)
 	/* Sanity check for fields in descriptors */
 	for (i = 0; i < header.num_desc; ++i) {
 		pdesc = get_stats_descriptor(stats_desc, i, &header);
+		type = pdesc->flags & KVM_STATS_TYPE_MASK;
+		unit = pdesc->flags & KVM_STATS_UNIT_MASK;
+		base = pdesc->flags & KVM_STATS_BASE_MASK;
 
 		/* Check name string */
 		TEST_ASSERT(strlen(pdesc->name) < header.name_size,
 			    "KVM stats name (index: %d) too long", i);
 
 		/* Check type,unit,base boundaries */
-		TEST_ASSERT((pdesc->flags & KVM_STATS_TYPE_MASK) <= KVM_STATS_TYPE_MAX,
-			    "Unknown KVM stats type");
-		TEST_ASSERT((pdesc->flags & KVM_STATS_UNIT_MASK) <= 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(type <= KVM_STATS_TYPE_MAX,
+			    "Unknown KVM stats (%s) type: %u", pdesc->name, type);
+		TEST_ASSERT(unit <= KVM_STATS_UNIT_MAX,
+			    "Unknown KVM stats (%s) unit: %u", pdesc->name, unit);
+		TEST_ASSERT(base <= KVM_STATS_BASE_MAX,
+			    "Unknown KVM stats (%s) base: %u", pdesc->name, base);
 
 		/*
 		 * Check exponent for stats unit
@@ -97,10 +101,14 @@ static void stats_test(int stats_fd)
 		case KVM_STATS_UNIT_NONE:
 		case KVM_STATS_UNIT_BYTES:
 		case KVM_STATS_UNIT_CYCLES:
-			TEST_ASSERT(pdesc->exponent >= 0, "Unsupported KVM stats unit");
+			TEST_ASSERT(pdesc->exponent >= 0,
+				    "Unsupported KVM stats (%s) exponent: %i",
+				    pdesc->name, pdesc->exponent);
 			break;
 		case KVM_STATS_UNIT_SECONDS:
-			TEST_ASSERT(pdesc->exponent <= 0, "Unsupported KVM stats unit");
+			TEST_ASSERT(pdesc->exponent <= 0,
+				    "Unsupported KVM stats (%s) exponent: %i",
+				    pdesc->name, pdesc->exponent);
 			break;
 		}
 
-- 
2.37.0.170.g444d1eabd0-goog


  parent reply	other threads:[~2022-07-19 14:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19 14:31 [PATCH 0/3] selftests: KVM: Improvements to binary stats test Oliver Upton
2022-07-19 14:31 ` [PATCH 1/3] selftests: KVM: Check stat name before other fields Oliver Upton
2022-07-19 14:31 ` Oliver Upton [this message]
2022-07-19 14:31 ` [PATCH 3/3] selftests: KVM: Add exponent check for boolean stats Oliver Upton
2022-07-19 16:09 ` [PATCH 0/3] selftests: KVM: Improvements to binary stats test Andrew Jones
2022-07-19 17:53   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220719143134.3246798-3-oliver.upton@linux.dev \
    --to=oliver.upton@linux.dev \
    --cc=kvm@vger.kernel.org \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.