Skip to content

Commit 21337f2

Browse files
xzpeterakpm00
authored andcommitted
selftests/mm: add a few options for uffd-unit-test
Namely: "-f": add a wildcard filter for tests to run "-l": list tests rather than running any "-h": help msg Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Peter Xu <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Cc: Andrea Arcangeli <[email protected]> Cc: Axel Rasmussen <[email protected]> Cc: Mika Penttilä <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: Nadav Amit <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 0f230bc commit 21337f2

File tree

1 file changed

+45
-7
lines changed

1 file changed

+45
-7
lines changed

tools/testing/selftests/mm/uffd-unit-tests.c

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -909,28 +909,65 @@ uffd_test_case_t uffd_tests[] = {
909909
},
910910
};
911911

912+
static void usage(const char *prog)
913+
{
914+
printf("usage: %s [-f TESTNAME]\n", prog);
915+
puts("");
916+
puts(" -f: test name to filter (e.g., event)");
917+
puts(" -h: show the help msg");
918+
puts(" -l: list tests only");
919+
puts("");
920+
exit(KSFT_FAIL);
921+
}
922+
912923
int main(int argc, char *argv[])
913924
{
914925
int n_tests = sizeof(uffd_tests) / sizeof(uffd_test_case_t);
915926
int n_mems = sizeof(mem_types) / sizeof(mem_type_t);
927+
const char *test_filter = NULL;
928+
bool list_only = false;
916929
uffd_test_case_t *test;
917930
mem_type_t *mem_type;
918931
uffd_test_args_t args;
919932
char test_name[128];
920933
const char *errmsg;
921-
int has_uffd;
934+
int has_uffd, opt;
922935
int i, j;
923936

924-
has_uffd = test_uffd_api(false);
925-
has_uffd |= test_uffd_api(true);
937+
while ((opt = getopt(argc, argv, "f:hl")) != -1) {
938+
switch (opt) {
939+
case 'f':
940+
test_filter = optarg;
941+
break;
942+
case 'l':
943+
list_only = true;
944+
break;
945+
case 'h':
946+
default:
947+
/* Unknown */
948+
usage(argv[0]);
949+
break;
950+
}
951+
}
952+
953+
if (!test_filter && !list_only) {
954+
has_uffd = test_uffd_api(false);
955+
has_uffd |= test_uffd_api(true);
926956

927-
if (!has_uffd) {
928-
printf("Userfaultfd not supported or unprivileged, skip all tests\n");
929-
exit(KSFT_SKIP);
957+
if (!has_uffd) {
958+
printf("Userfaultfd not supported or unprivileged, skip all tests\n");
959+
exit(KSFT_SKIP);
960+
}
930961
}
931962

932963
for (i = 0; i < n_tests; i++) {
933964
test = &uffd_tests[i];
965+
if (test_filter && !strstr(test->name, test_filter))
966+
continue;
967+
if (list_only) {
968+
printf("%s\n", test->name);
969+
continue;
970+
}
934971
for (j = 0; j < n_mems; j++) {
935972
mem_type = &mem_types[j];
936973
if (!(test->mem_targets & mem_type->mem_flag))
@@ -952,7 +989,8 @@ int main(int argc, char *argv[])
952989
}
953990
}
954991

955-
uffd_test_report();
992+
if (!list_only)
993+
uffd_test_report();
956994

957995
return ksft_get_fail_cnt() ? KSFT_FAIL : KSFT_PASS;
958996
}

0 commit comments

Comments
 (0)