Skip to content

Commit 3d9bd83

Browse files
committed
KVM: selftests: Convert steal_time test to printf style GUEST_ASSERT
Convert the steal_time test to use printf-based GUEST_ASERT. Opportunistically use GUEST_ASSERT_EQ() and GUEST_ASSERT_NE() so that the test spits out debug information on failure. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 9291c9c commit 3d9bd83

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

tools/testing/selftests/kvm/steal_time.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*
55
* Copyright (C) 2020, Red Hat, Inc.
66
*/
7+
#define USE_GUEST_ASSERT_PRINTF 1
8+
79
#define _GNU_SOURCE
810
#include <stdio.h>
911
#include <time.h>
@@ -31,16 +33,16 @@ static uint64_t guest_stolen_time[NR_VCPUS];
3133
static void check_status(struct kvm_steal_time *st)
3234
{
3335
GUEST_ASSERT(!(READ_ONCE(st->version) & 1));
34-
GUEST_ASSERT(READ_ONCE(st->flags) == 0);
35-
GUEST_ASSERT(READ_ONCE(st->preempted) == 0);
36+
GUEST_ASSERT_EQ(READ_ONCE(st->flags), 0);
37+
GUEST_ASSERT_EQ(READ_ONCE(st->preempted), 0);
3638
}
3739

3840
static void guest_code(int cpu)
3941
{
4042
struct kvm_steal_time *st = st_gva[cpu];
4143
uint32_t version;
4244

43-
GUEST_ASSERT(rdmsr(MSR_KVM_STEAL_TIME) == ((uint64_t)st_gva[cpu] | KVM_MSR_ENABLED));
45+
GUEST_ASSERT_EQ(rdmsr(MSR_KVM_STEAL_TIME), ((uint64_t)st_gva[cpu] | KVM_MSR_ENABLED));
4446

4547
memset(st, 0, sizeof(*st));
4648
GUEST_SYNC(0);
@@ -122,8 +124,8 @@ static int64_t smccc(uint32_t func, uint64_t arg)
122124

123125
static void check_status(struct st_time *st)
124126
{
125-
GUEST_ASSERT(READ_ONCE(st->rev) == 0);
126-
GUEST_ASSERT(READ_ONCE(st->attr) == 0);
127+
GUEST_ASSERT_EQ(READ_ONCE(st->rev), 0);
128+
GUEST_ASSERT_EQ(READ_ONCE(st->attr), 0);
127129
}
128130

129131
static void guest_code(int cpu)
@@ -132,15 +134,15 @@ static void guest_code(int cpu)
132134
int64_t status;
133135

134136
status = smccc(SMCCC_ARCH_FEATURES, PV_TIME_FEATURES);
135-
GUEST_ASSERT(status == 0);
137+
GUEST_ASSERT_EQ(status, 0);
136138
status = smccc(PV_TIME_FEATURES, PV_TIME_FEATURES);
137-
GUEST_ASSERT(status == 0);
139+
GUEST_ASSERT_EQ(status, 0);
138140
status = smccc(PV_TIME_FEATURES, PV_TIME_ST);
139-
GUEST_ASSERT(status == 0);
141+
GUEST_ASSERT_EQ(status, 0);
140142

141143
status = smccc(PV_TIME_ST, 0);
142-
GUEST_ASSERT(status != -1);
143-
GUEST_ASSERT(status == (ulong)st_gva[cpu]);
144+
GUEST_ASSERT_NE(status, -1);
145+
GUEST_ASSERT_EQ(status, (ulong)st_gva[cpu]);
144146

145147
st = (struct st_time *)status;
146148
GUEST_SYNC(0);

0 commit comments

Comments
 (0)