Skip to content

Commit 4b506ad

Browse files
atishp04avpatel
authored andcommitted
KVM: riscv: selftests: Change command line option
The PMU test commandline option takes an argument to disable a certain test. The initial assumption behind this was a common use case is just to run all the test most of the time. However, running a single test seems more useful instead. Especially, the overflow test has been helpful to validate PMU virtualizaiton interrupt changes. Switching the command line option to run a single test instead of disabling a single test also allows to provide additional test specific arguments to the test. The default without any options remains unchanged which continues to run all the tests. Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Link: https://lore.kernel.org/r/20250303-kvm_pmu_improve-v2-3-41d177e45929@rivosinc.com Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 1f6bbe1 commit 4b506ad

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

tools/testing/selftests/kvm/riscv/sbi_pmu_test.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ static bool illegal_handler_invoked;
3939
#define SBI_PMU_TEST_SNAPSHOT BIT(2)
4040
#define SBI_PMU_TEST_OVERFLOW BIT(3)
4141

42-
static int disabled_tests;
42+
struct test_args {
43+
int disabled_tests;
44+
};
45+
46+
static struct test_args targs;
4347

4448
unsigned long pmu_csr_read_num(int csr_num)
4549
{
@@ -604,7 +608,11 @@ static void test_vm_events_overflow(void *guest_code)
604608
vcpu_init_vector_tables(vcpu);
605609
/* Initialize guest timer frequency. */
606610
timer_freq = vcpu_get_reg(vcpu, RISCV_TIMER_REG(frequency));
611+
612+
/* Export the shared variables to the guest */
607613
sync_global_to_guest(vm, timer_freq);
614+
sync_global_to_guest(vm, vcpu_shared_irq_count);
615+
sync_global_to_guest(vm, targs);
608616

609617
run_vcpu(vcpu);
610618

@@ -613,28 +621,30 @@ static void test_vm_events_overflow(void *guest_code)
613621

614622
static void test_print_help(char *name)
615623
{
616-
pr_info("Usage: %s [-h] [-d <test name>]\n", name);
617-
pr_info("\t-d: Test to disable. Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");
624+
pr_info("Usage: %s [-h] [-t <test name>]\n", name);
625+
pr_info("\t-t: Test to run (default all). Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");
618626
pr_info("\t-h: print this help screen\n");
619627
}
620628

621629
static bool parse_args(int argc, char *argv[])
622630
{
623631
int opt;
624-
625-
while ((opt = getopt(argc, argv, "hd:")) != -1) {
632+
int temp_disabled_tests = SBI_PMU_TEST_BASIC | SBI_PMU_TEST_EVENTS | SBI_PMU_TEST_SNAPSHOT |
633+
SBI_PMU_TEST_OVERFLOW;
634+
while ((opt = getopt(argc, argv, "ht:")) != -1) {
626635
switch (opt) {
627-
case 'd':
636+
case 't':
628637
if (!strncmp("basic", optarg, 5))
629-
disabled_tests |= SBI_PMU_TEST_BASIC;
638+
temp_disabled_tests &= ~SBI_PMU_TEST_BASIC;
630639
else if (!strncmp("events", optarg, 6))
631-
disabled_tests |= SBI_PMU_TEST_EVENTS;
640+
temp_disabled_tests &= ~SBI_PMU_TEST_EVENTS;
632641
else if (!strncmp("snapshot", optarg, 8))
633-
disabled_tests |= SBI_PMU_TEST_SNAPSHOT;
642+
temp_disabled_tests &= ~SBI_PMU_TEST_SNAPSHOT;
634643
else if (!strncmp("overflow", optarg, 8))
635-
disabled_tests |= SBI_PMU_TEST_OVERFLOW;
644+
temp_disabled_tests &= ~SBI_PMU_TEST_OVERFLOW;
636645
else
637646
goto done;
647+
targs.disabled_tests = temp_disabled_tests;
638648
break;
639649
case 'h':
640650
default:
@@ -650,25 +660,27 @@ static bool parse_args(int argc, char *argv[])
650660

651661
int main(int argc, char *argv[])
652662
{
663+
targs.disabled_tests = 0;
664+
653665
if (!parse_args(argc, argv))
654666
exit(KSFT_SKIP);
655667

656-
if (!(disabled_tests & SBI_PMU_TEST_BASIC)) {
668+
if (!(targs.disabled_tests & SBI_PMU_TEST_BASIC)) {
657669
test_vm_basic_test(test_pmu_basic_sanity);
658670
pr_info("SBI PMU basic test : PASS\n");
659671
}
660672

661-
if (!(disabled_tests & SBI_PMU_TEST_EVENTS)) {
673+
if (!(targs.disabled_tests & SBI_PMU_TEST_EVENTS)) {
662674
test_vm_events_test(test_pmu_events);
663675
pr_info("SBI PMU event verification test : PASS\n");
664676
}
665677

666-
if (!(disabled_tests & SBI_PMU_TEST_SNAPSHOT)) {
678+
if (!(targs.disabled_tests & SBI_PMU_TEST_SNAPSHOT)) {
667679
test_vm_events_snapshot_test(test_pmu_events_snaphost);
668680
pr_info("SBI PMU event verification with snapshot test : PASS\n");
669681
}
670682

671-
if (!(disabled_tests & SBI_PMU_TEST_OVERFLOW)) {
683+
if (!(targs.disabled_tests & SBI_PMU_TEST_OVERFLOW)) {
672684
test_vm_events_overflow(test_pmu_events_overflow);
673685
pr_info("SBI PMU event verification with overflow test : PASS\n");
674686
}

0 commit comments

Comments
 (0)