Skip to content

Commit 5ef2f3d

Browse files
atishp04avpatel
authored andcommitted
KVM: riscv: selftests: Add commandline option for SBI PMU test
SBI PMU test comprises of multiple tests and user may want to run only a subset depending on the platform. The most common case would be to run all to validate all the tests. However, some platform may not support all events or all ISA extensions. The commandline option allows user to disable any set of tests if they want to. Suggested-by: Andrew Jones <[email protected]> Signed-off-by: Atish Patra <[email protected]> Reviewed-by: Anup Patel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent 4ace257 commit 5ef2f3d

File tree

1 file changed

+64
-9
lines changed

1 file changed

+64
-9
lines changed

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

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ static unsigned long counter_mask_available;
3333

3434
static bool illegal_handler_invoked;
3535

36+
#define SBI_PMU_TEST_BASIC BIT(0)
37+
#define SBI_PMU_TEST_EVENTS BIT(1)
38+
#define SBI_PMU_TEST_SNAPSHOT BIT(2)
39+
#define SBI_PMU_TEST_OVERFLOW BIT(3)
40+
41+
static int disabled_tests;
42+
3643
unsigned long pmu_csr_read_num(int csr_num)
3744
{
3845
#define switchcase_csr_read(__csr_num, __val) {\
@@ -608,19 +615,67 @@ static void test_vm_events_overflow(void *guest_code)
608615
test_vm_destroy(vm);
609616
}
610617

611-
int main(void)
618+
static void test_print_help(char *name)
619+
{
620+
pr_info("Usage: %s [-h] [-d <test name>]\n", name);
621+
pr_info("\t-d: Test to disable. Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");
622+
pr_info("\t-h: print this help screen\n");
623+
}
624+
625+
static bool parse_args(int argc, char *argv[])
626+
{
627+
int opt;
628+
629+
while ((opt = getopt(argc, argv, "hd:")) != -1) {
630+
switch (opt) {
631+
case 'd':
632+
if (!strncmp("basic", optarg, 5))
633+
disabled_tests |= SBI_PMU_TEST_BASIC;
634+
else if (!strncmp("events", optarg, 6))
635+
disabled_tests |= SBI_PMU_TEST_EVENTS;
636+
else if (!strncmp("snapshot", optarg, 8))
637+
disabled_tests |= SBI_PMU_TEST_SNAPSHOT;
638+
else if (!strncmp("overflow", optarg, 8))
639+
disabled_tests |= SBI_PMU_TEST_OVERFLOW;
640+
else
641+
goto done;
642+
break;
643+
case 'h':
644+
default:
645+
goto done;
646+
}
647+
}
648+
649+
return true;
650+
done:
651+
test_print_help(argv[0]);
652+
return false;
653+
}
654+
655+
int main(int argc, char *argv[])
612656
{
613-
test_vm_basic_test(test_pmu_basic_sanity);
614-
pr_info("SBI PMU basic test : PASS\n");
657+
if (!parse_args(argc, argv))
658+
exit(KSFT_SKIP);
659+
660+
if (!(disabled_tests & SBI_PMU_TEST_BASIC)) {
661+
test_vm_basic_test(test_pmu_basic_sanity);
662+
pr_info("SBI PMU basic test : PASS\n");
663+
}
615664

616-
test_vm_events_test(test_pmu_events);
617-
pr_info("SBI PMU event verification test : PASS\n");
665+
if (!(disabled_tests & SBI_PMU_TEST_EVENTS)) {
666+
test_vm_events_test(test_pmu_events);
667+
pr_info("SBI PMU event verification test : PASS\n");
668+
}
618669

619-
test_vm_events_snapshot_test(test_pmu_events_snaphost);
620-
pr_info("SBI PMU event verification with snapshot test : PASS\n");
670+
if (!(disabled_tests & SBI_PMU_TEST_SNAPSHOT)) {
671+
test_vm_events_snapshot_test(test_pmu_events_snaphost);
672+
pr_info("SBI PMU event verification with snapshot test : PASS\n");
673+
}
621674

622-
test_vm_events_overflow(test_pmu_events_overflow);
623-
pr_info("SBI PMU event verification with overflow test : PASS\n");
675+
if (!(disabled_tests & SBI_PMU_TEST_OVERFLOW)) {
676+
test_vm_events_overflow(test_pmu_events_overflow);
677+
pr_info("SBI PMU event verification with overflow test : PASS\n");
678+
}
624679

625680
return 0;
626681
}

0 commit comments

Comments
 (0)