Skip to content

Commit e60770a

Browse files
committed
perf test: Allow running just a subset of the available tests
To obtain a list of available tests: [root@emilia linux]# perf test list 1: vmlinux symtab matches kallsyms 2: detect open syscall event 3: detect open syscall event on all cpus 4: read samples using the mmap interface 5: parse events tests [root@emilia linux]# To list just a subset: [root@emilia linux]# perf test list syscall 2: detect open syscall event 3: detect open syscall event on all cpus [root@emilia linux]# To run a subset: [root@emilia linux]# perf test detect 2: detect open syscall event: Ok 3: detect open syscall event on all cpus: Ok [root@emilia linux]# Specific tests can be chosen by number: [root@emilia linux]# perf test 1 3 parse 1: vmlinux symtab matches kallsyms: Ok 3: detect open syscall event on all cpus: Ok 5: parse events tests: Ok [root@emilia linux]# Now to write more tests! Suggested-by: Peter Zijlstra <peterz@infradead.org> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/n/tip-nqec2145qfxdgimux28aw7v8@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 806fb63 commit e60770a

2 files changed

Lines changed: 67 additions & 22 deletions

File tree

‎tools/perf/Documentation/perf-test.txt‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ perf-test - Runs sanity tests.
88
SYNOPSIS
99
--------
1010
[verse]
11-
'perf test <options>'
11+
'perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]'
1212

1313
DESCRIPTION
1414
-----------
1515
This command does assorted sanity tests, initially through linked routines but
1616
also will look for a directory with more tests in the form of scripts.
1717

18+
To get a list of available tests use 'perf test list', specifying a test name
19+
fragment will show all tests that have it.
20+
21+
To run just specific tests, inform test name fragments or the numbers obtained
22+
from 'perf test list'.
23+
1824
OPTIONS
1925
-------
2026
-v::

‎tools/perf/builtin-test.c‎

Lines changed: 60 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include "util/thread_map.h"
1616
#include "../../include/linux/hw_breakpoint.h"
1717

18-
static long page_size;
19-
2018
static int vmlinux_matches_kallsyms_filter(struct map *map __used, struct symbol *sym)
2119
{
2220
bool *visited = symbol__priv(sym);
@@ -32,6 +30,7 @@ static int test__vmlinux_matches_kallsyms(void)
3230
struct map *kallsyms_map, *vmlinux_map;
3331
struct machine kallsyms, vmlinux;
3432
enum map_type type = MAP__FUNCTION;
33+
long page_size = sysconf(_SC_PAGE_SIZE);
3534
struct ref_reloc_sym ref_reloc_sym = { .name = "_stext", };
3635

3736
/*
@@ -871,41 +870,81 @@ static struct test {
871870
},
872871
};
873872

874-
static int __cmd_test(void)
873+
static bool perf_test__matches(int curr, int argc, const char *argv[])
875874
{
876-
int i = 0;
875+
int i;
876+
877+
if (argc == 0)
878+
return true;
879+
880+
for (i = 0; i < argc; ++i) {
881+
char *end;
882+
long nr = strtoul(argv[i], &end, 10);
883+
884+
if (*end == '\0') {
885+
if (nr == curr + 1)
886+
return true;
887+
continue;
888+
}
877889

878-
page_size = sysconf(_SC_PAGE_SIZE);
890+
if (strstr(tests[curr].desc, argv[i]))
891+
return true;
892+
}
893+
894+
return false;
895+
}
896+
897+
static int __cmd_test(int argc, const char *argv[])
898+
{
899+
int i = 0;
879900

880901
while (tests[i].func) {
881-
int err;
882-
pr_info("%2d: %s:", i + 1, tests[i].desc);
902+
int curr = i++, err;
903+
904+
if (!perf_test__matches(curr, argc, argv))
905+
continue;
906+
907+
pr_info("%2d: %s:", i, tests[curr].desc);
883908
pr_debug("\n--- start ---\n");
884-
err = tests[i].func();
885-
pr_debug("---- end ----\n%s:", tests[i].desc);
909+
err = tests[curr].func();
910+
pr_debug("---- end ----\n%s:", tests[curr].desc);
886911
pr_info(" %s\n", err ? "FAILED!\n" : "Ok");
887-
++i;
888912
}
889913

890914
return 0;
891915
}
892916

893-
static const char * const test_usage[] = {
894-
"perf test [<options>]",
895-
NULL,
896-
};
917+
static int perf_test__list(int argc, const char **argv)
918+
{
919+
int i = 0;
920+
921+
while (tests[i].func) {
922+
int curr = i++;
923+
924+
if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
925+
continue;
926+
927+
pr_info("%2d: %s\n", i, tests[curr].desc);
928+
}
929+
930+
return 0;
931+
}
897932

898-
static const struct option test_options[] = {
933+
int cmd_test(int argc, const char **argv, const char *prefix __used)
934+
{
935+
const char * const test_usage[] = {
936+
"perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
937+
NULL,
938+
};
939+
const struct option test_options[] = {
899940
OPT_INTEGER('v', "verbose", &verbose,
900941
"be more verbose (show symbol address, etc)"),
901942
OPT_END()
902-
};
943+
};
903944

904-
int cmd_test(int argc, const char **argv, const char *prefix __used)
905-
{
906945
argc = parse_options(argc, argv, test_options, test_usage, 0);
907-
if (argc)
908-
usage_with_options(test_usage, test_options);
946+
if (argc >= 1 && !strcmp(argv[0], "list"))
947+
return perf_test__list(argc, argv);
909948

910949
symbol_conf.priv_size = sizeof(int);
911950
symbol_conf.sort_by_name = true;
@@ -916,5 +955,5 @@ int cmd_test(int argc, const char **argv, const char *prefix __used)
916955

917956
setup_pager();
918957

919-
return __cmd_test();
958+
return __cmd_test(argc, argv);
920959
}

0 commit comments

Comments
 (0)