Re: [PATCH v15 34/41] KVM: selftests: Add ex_str() to print human friendly name of exception vectors

Chao Gao
2025-09-15T09:07:16Z

On Fri, Sep 12, 2025 at 04:23:12PM -0700, Sean Christopherson wrote:
>Steal exception_mnemonic() from KVM-Unit-Tests as ex_str() (to keep line
>lengths reasonable) and use it in assert messages that currently print the
>raw vector number.
>
>Signed-off-by: Sean Christopherson <seanjc@google.com>

There are two more assert messages still printing the raw numbers. Feel free to
squash the below patch into yours.

assert_ucall_vector() in nested_exceptions_test.c could be converted as well but
its use of FAKE_TRIPLE_FAULT_VECTOR makes me hesitant to do that (e.g., we need
to assign a name to the faked vector in the common code).

From 90c502e97be6acc37f84a086c50ecb180719ea46 Mon Sep 17 00:00:00 2001
From: Chao Gao <chao.gao@intel.com>
Date: Mon, 15 Sep 2025 01:41:03 -0700
Subject: [PATCH] KVM: selftests: Use ex_str() to print human friendly name of
exception vectors

Convert assert messages that are still printing the raw vector numbers to
print human-friendly names.

Signed-off-by: Chao Gao <chao.gao@intel.com>
---
tools/testing/selftests/kvm/x86/monitor_mwait_test.c | 8 ++++----
tools/testing/selftests/kvm/x86/pmu_counters_test.c | 4 ++--
2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/kvm/x86/monitor_mwait_test.c b/tools/testing/selftests/kvm/x86/monitor_mwait_test.c
index 0eb371c62ab8..e45c028d2a7e 100644
--- a/tools/testing/selftests/kvm/x86/monitor_mwait_test.c
+++ b/tools/testing/selftests/kvm/x86/monitor_mwait_test.c
@@ -30,12 +30,12 @@ do { \
\
if (fault_wanted) \
__GUEST_ASSERT((vector) == UD_VECTOR, \
- "Expected #UD on " insn " for testcase '0x%x', got '0x%x'", \
- testcase, vector); \
+ "Expected #UD on " insn " for testcase '0x%x', got %s", \
+ testcase, ex_str(vector)); \
else \
__GUEST_ASSERT(!(vector), \
- "Expected success on " insn " for testcase '0x%x', got '0x%x'", \
- testcase, vector); \
+ "Expected success on " insn " for testcase '0x%x', got %s", \
+ testcase, ex_str(vector)); \
} while (0)

static void guest_monitor_wait(void *arg)
diff --git a/tools/testing/selftests/kvm/x86/pmu_counters_test.c b/tools/testing/selftests/kvm/x86/pmu_counters_test.c
index 8aaaf25b6111..36eb2658f891 100644
--- a/tools/testing/selftests/kvm/x86/pmu_counters_test.c
+++ b/tools/testing/selftests/kvm/x86/pmu_counters_test.c
@@ -344,8 +344,8 @@ static void test_arch_events(uint8_t pmu_version, uint64_t perf_capabilities,

#define GUEST_ASSERT_PMC_MSR_ACCESS(insn, msr, expect_gp, vector) \
__GUEST_ASSERT(expect_gp ? vector == GP_VECTOR : !vector, \
- "Expected %s on " #insn "(0x%x), got vector %u", \
- expect_gp ? "#GP" : "no fault", msr, vector) \
+ "Expected %s on " #insn "(0x%x), got %s", \
+ expect_gp ? "#GP" : "no fault", msr, ex_str(vector)) \

#define GUEST_ASSERT_PMC_VALUE(insn, msr, val, expected) \
__GUEST_ASSERT(val == expected, \
--
2.47.3