Skip to content

Commit

Permalink
KVM: selftests: Convert steal_time test to printf style GUEST_ASSERT
Browse files Browse the repository at this point in the history
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/20230729003643.1053367-20-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
  • Loading branch information
sean-jc committed Aug 2, 2023
1 parent 9291c9c commit 3d9bd83
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions tools/testing/selftests/kvm/steal_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*
* Copyright (C) 2020, Red Hat, Inc.
*/
#define USE_GUEST_ASSERT_PRINTF 1

#define _GNU_SOURCE
#include <stdio.h>
#include <time.h>
Expand Down Expand Up @@ -31,16 +33,16 @@ static uint64_t guest_stolen_time[NR_VCPUS];
static void check_status(struct kvm_steal_time *st)
{
GUEST_ASSERT(!(READ_ONCE(st->version) & 1));
GUEST_ASSERT(READ_ONCE(st->flags) == 0);
GUEST_ASSERT(READ_ONCE(st->preempted) == 0);
GUEST_ASSERT_EQ(READ_ONCE(st->flags), 0);
GUEST_ASSERT_EQ(READ_ONCE(st->preempted), 0);
}

static void guest_code(int cpu)
{
struct kvm_steal_time *st = st_gva[cpu];
uint32_t version;

GUEST_ASSERT(rdmsr(MSR_KVM_STEAL_TIME) == ((uint64_t)st_gva[cpu] | KVM_MSR_ENABLED));
GUEST_ASSERT_EQ(rdmsr(MSR_KVM_STEAL_TIME), ((uint64_t)st_gva[cpu] | KVM_MSR_ENABLED));

memset(st, 0, sizeof(*st));
GUEST_SYNC(0);
Expand Down Expand Up @@ -122,8 +124,8 @@ static int64_t smccc(uint32_t func, uint64_t arg)

static void check_status(struct st_time *st)
{
GUEST_ASSERT(READ_ONCE(st->rev) == 0);
GUEST_ASSERT(READ_ONCE(st->attr) == 0);
GUEST_ASSERT_EQ(READ_ONCE(st->rev), 0);
GUEST_ASSERT_EQ(READ_ONCE(st->attr), 0);
}

static void guest_code(int cpu)
Expand All @@ -132,15 +134,15 @@ static void guest_code(int cpu)
int64_t status;

status = smccc(SMCCC_ARCH_FEATURES, PV_TIME_FEATURES);
GUEST_ASSERT(status == 0);
GUEST_ASSERT_EQ(status, 0);
status = smccc(PV_TIME_FEATURES, PV_TIME_FEATURES);
GUEST_ASSERT(status == 0);
GUEST_ASSERT_EQ(status, 0);
status = smccc(PV_TIME_FEATURES, PV_TIME_ST);
GUEST_ASSERT(status == 0);
GUEST_ASSERT_EQ(status, 0);

status = smccc(PV_TIME_ST, 0);
GUEST_ASSERT(status != -1);
GUEST_ASSERT(status == (ulong)st_gva[cpu]);
GUEST_ASSERT_NE(status, -1);
GUEST_ASSERT_EQ(status, (ulong)st_gva[cpu]);

st = (struct st_time *)status;
GUEST_SYNC(0);
Expand Down

0 comments on commit 3d9bd83

Please sign in to comment.