Skip to content

Commit

Permalink
KVM: selftests: Convert aarch_timer to printf style GUEST_ASSERT
Browse files Browse the repository at this point in the history
Convert ARM's aarch_timer test to use printf-based GUEST_ASSERT().
To maintain existing functionality, manually print the host information,
e.g. stage and iteration, to stderr prior to reporting the guest assert.

Link: https://lore.kernel.org/r/20230729003643.1053367-11-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
  • Loading branch information
sean-jc committed Aug 2, 2023
1 parent 5d1d46f commit db44e1c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions tools/testing/selftests/kvm/aarch64/arch_timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
* Copyright (c) 2021, Google LLC.
*/
#define USE_GUEST_ASSERT_PRINTF 1

#define _GNU_SOURCE

Expand Down Expand Up @@ -155,11 +156,13 @@ static void guest_validate_irq(unsigned int intid,
xcnt_diff_us = cycles_to_usec(xcnt - shared_data->xcnt);

/* Make sure we are dealing with the correct timer IRQ */
GUEST_ASSERT_2(intid == timer_irq, intid, timer_irq);
GUEST_ASSERT_EQ(intid, timer_irq);

/* Basic 'timer condition met' check */
GUEST_ASSERT_3(xcnt >= cval, xcnt, cval, xcnt_diff_us);
GUEST_ASSERT_1(xctl & CTL_ISTATUS, xctl);
__GUEST_ASSERT(xcnt >= cval,
"xcnt = 0x%llx, cval = 0x%llx, xcnt_diff_us = 0x%llx",
xcnt, cval, xcnt_diff_us);
__GUEST_ASSERT(xctl & CTL_ISTATUS, "xcnt = 0x%llx", xcnt);

WRITE_ONCE(shared_data->nr_iter, shared_data->nr_iter + 1);
}
Expand Down Expand Up @@ -192,8 +195,7 @@ static void guest_run_stage(struct test_vcpu_shared_data *shared_data,
TIMER_TEST_ERR_MARGIN_US);

irq_iter = READ_ONCE(shared_data->nr_iter);
GUEST_ASSERT_2(config_iter + 1 == irq_iter,
config_iter + 1, irq_iter);
GUEST_ASSERT_EQ(config_iter + 1, irq_iter);
}
}

Expand Down Expand Up @@ -243,13 +245,9 @@ static void *test_vcpu_run(void *arg)
break;
case UCALL_ABORT:
sync_global_from_guest(vm, *shared_data);
REPORT_GUEST_ASSERT_N(uc, "values: %lu, %lu; %lu, vcpu %u; stage; %u; iter: %u",
GUEST_ASSERT_ARG(uc, 0),
GUEST_ASSERT_ARG(uc, 1),
GUEST_ASSERT_ARG(uc, 2),
vcpu_idx,
shared_data->guest_stage,
shared_data->nr_iter);
fprintf(stderr, "Guest assert failed, vcpu %u; stage; %u; iter: %u\n",
vcpu_idx, shared_data->guest_stage, shared_data->nr_iter);
REPORT_GUEST_ASSERT(uc);
break;
default:
TEST_FAIL("Unexpected guest exit\n");
Expand Down

0 comments on commit db44e1c

Please sign in to comment.