1945aea22SJiri Olsa /* 2945aea22SJiri Olsa * builtin-test.c 3945aea22SJiri Olsa * 4945aea22SJiri Olsa * Builtin regression testing command: ever growing number of sanity tests 5945aea22SJiri Olsa */ 6945aea22SJiri Olsa #include "builtin.h" 72ae82878SArnaldo Carvalho de Melo #include "intlist.h" 80a4e1ae6SJiri Olsa #include "tests.h" 9c81251e8SJiri Olsa #include "debug.h" 10c81251e8SJiri Olsa #include "color.h" 11c81251e8SJiri Olsa #include "parse-options.h" 12c81251e8SJiri Olsa #include "symbol.h" 13945aea22SJiri Olsa 14945aea22SJiri Olsa static struct test { 15945aea22SJiri Olsa const char *desc; 16945aea22SJiri Olsa int (*func)(void); 17945aea22SJiri Olsa } tests[] = { 18945aea22SJiri Olsa { 19945aea22SJiri Olsa .desc = "vmlinux symtab matches kallsyms", 20945aea22SJiri Olsa .func = test__vmlinux_matches_kallsyms, 21945aea22SJiri Olsa }, 22945aea22SJiri Olsa { 23945aea22SJiri Olsa .desc = "detect open syscall event", 24945aea22SJiri Olsa .func = test__open_syscall_event, 25945aea22SJiri Olsa }, 26945aea22SJiri Olsa { 27945aea22SJiri Olsa .desc = "detect open syscall event on all cpus", 28945aea22SJiri Olsa .func = test__open_syscall_event_on_all_cpus, 29945aea22SJiri Olsa }, 30945aea22SJiri Olsa { 31945aea22SJiri Olsa .desc = "read samples using the mmap interface", 32945aea22SJiri Olsa .func = test__basic_mmap, 33945aea22SJiri Olsa }, 34945aea22SJiri Olsa { 35945aea22SJiri Olsa .desc = "parse events tests", 36c81251e8SJiri Olsa .func = test__parse_events, 37945aea22SJiri Olsa }, 38945aea22SJiri Olsa #if defined(__x86_64__) || defined(__i386__) 39945aea22SJiri Olsa { 40945aea22SJiri Olsa .desc = "x86 rdpmc test", 41945aea22SJiri Olsa .func = test__rdpmc, 42945aea22SJiri Olsa }, 43945aea22SJiri Olsa #endif 44945aea22SJiri Olsa { 45945aea22SJiri Olsa .desc = "Validate PERF_RECORD_* events & perf_sample fields", 46945aea22SJiri Olsa .func = test__PERF_RECORD, 47945aea22SJiri Olsa }, 48945aea22SJiri Olsa { 49945aea22SJiri Olsa .desc = "Test perf pmu format parsing", 50cff7f956SJiri Olsa .func = test__pmu, 51945aea22SJiri Olsa }, 52945aea22SJiri Olsa { 53945aea22SJiri Olsa .desc = "Test dso data interface", 54c81251e8SJiri Olsa .func = test__dso_data, 55945aea22SJiri Olsa }, 56945aea22SJiri Olsa { 57945aea22SJiri Olsa .desc = "roundtrip evsel->name check", 58cfffae2eSJiri Olsa .func = test__perf_evsel__roundtrip_name_test, 59945aea22SJiri Olsa }, 60945aea22SJiri Olsa { 61945aea22SJiri Olsa .desc = "Check parsing of sched tracepoints fields", 625e24a090SJiri Olsa .func = test__perf_evsel__tp_sched_test, 63945aea22SJiri Olsa }, 64945aea22SJiri Olsa { 65945aea22SJiri Olsa .desc = "Generate and check syscalls:sys_enter_open event fields", 66945aea22SJiri Olsa .func = test__syscall_open_tp_fields, 67945aea22SJiri Olsa }, 68945aea22SJiri Olsa { 69d898b241SJiri Olsa .desc = "struct perf_event_attr setup", 70c81251e8SJiri Olsa .func = test__attr, 71d898b241SJiri Olsa }, 72d898b241SJiri Olsa { 73ffcbaa14SArnaldo Carvalho de Melo .desc = "Test matching and linking multiple hists", 74f8ebb0cdSNamhyung Kim .func = test__hists_link, 75f8ebb0cdSNamhyung Kim }, 76f8ebb0cdSNamhyung Kim { 7754359d33SArnaldo Carvalho de Melo .desc = "Try 'use perf' in python, checking link problems", 7854359d33SArnaldo Carvalho de Melo .func = test__python_use, 7954359d33SArnaldo Carvalho de Melo }, 8054359d33SArnaldo Carvalho de Melo { 815a6bef47SJiri Olsa .desc = "Test breakpoint overflow signal handler", 825a6bef47SJiri Olsa .func = test__bp_signal, 835a6bef47SJiri Olsa }, 845a6bef47SJiri Olsa { 8506933e3aSJiri Olsa .desc = "Test breakpoint overflow sampling", 8606933e3aSJiri Olsa .func = test__bp_signal_overflow, 8706933e3aSJiri Olsa }, 8806933e3aSJiri Olsa { 89d723a550SNamhyung Kim .desc = "Test number of exit event of a simple workload", 90d723a550SNamhyung Kim .func = test__task_exit, 91d723a550SNamhyung Kim }, 92d723a550SNamhyung Kim { 93bc96b361SNamhyung Kim .desc = "Test software clock events have valid period values", 94bc96b361SNamhyung Kim .func = test__sw_clock_freq, 95bc96b361SNamhyung Kim }, 963bd5a5fcSAdrian Hunter #if defined(__x86_64__) || defined(__i386__) 973bd5a5fcSAdrian Hunter { 983bd5a5fcSAdrian Hunter .desc = "Test converting perf time to TSC", 993bd5a5fcSAdrian Hunter .func = test__perf_time_to_tsc, 1003bd5a5fcSAdrian Hunter }, 1013bd5a5fcSAdrian Hunter #endif 102bc96b361SNamhyung Kim { 103b55ae0a9SAdrian Hunter .desc = "Test object code reading", 104b55ae0a9SAdrian Hunter .func = test__code_reading, 105b55ae0a9SAdrian Hunter }, 106b55ae0a9SAdrian Hunter { 107045f8cd8SAdrian Hunter .desc = "Test sample parsing", 108045f8cd8SAdrian Hunter .func = test__sample_parsing, 109045f8cd8SAdrian Hunter }, 110045f8cd8SAdrian Hunter { 111395c3070SAdrian Hunter .desc = "Test using a dummy software event to keep tracking", 112395c3070SAdrian Hunter .func = test__keep_tracking, 113395c3070SAdrian Hunter }, 114395c3070SAdrian Hunter { 11553a277e5SAdrian Hunter .desc = "Test parsing with no sample_id_all bit set", 11653a277e5SAdrian Hunter .func = test__parse_no_sample_id_all, 11753a277e5SAdrian Hunter }, 118aa16b81fSJiri Olsa #if defined(__x86_64__) || defined(__i386__) 119*9ff125d1SJiri Olsa #ifdef HAVE_DWARF_UNWIND_SUPPORT 120aa16b81fSJiri Olsa { 121aa16b81fSJiri Olsa .desc = "Test dwarf unwind", 122aa16b81fSJiri Olsa .func = test__dwarf_unwind, 123aa16b81fSJiri Olsa }, 124aa16b81fSJiri Olsa #endif 125aa16b81fSJiri Olsa #endif 12653a277e5SAdrian Hunter { 127945aea22SJiri Olsa .func = NULL, 128945aea22SJiri Olsa }, 129945aea22SJiri Olsa }; 130945aea22SJiri Olsa 131945aea22SJiri Olsa static bool perf_test__matches(int curr, int argc, const char *argv[]) 132945aea22SJiri Olsa { 133945aea22SJiri Olsa int i; 134945aea22SJiri Olsa 135945aea22SJiri Olsa if (argc == 0) 136945aea22SJiri Olsa return true; 137945aea22SJiri Olsa 138945aea22SJiri Olsa for (i = 0; i < argc; ++i) { 139945aea22SJiri Olsa char *end; 140945aea22SJiri Olsa long nr = strtoul(argv[i], &end, 10); 141945aea22SJiri Olsa 142945aea22SJiri Olsa if (*end == '\0') { 143945aea22SJiri Olsa if (nr == curr + 1) 144945aea22SJiri Olsa return true; 145945aea22SJiri Olsa continue; 146945aea22SJiri Olsa } 147945aea22SJiri Olsa 148945aea22SJiri Olsa if (strstr(tests[curr].desc, argv[i])) 149945aea22SJiri Olsa return true; 150945aea22SJiri Olsa } 151945aea22SJiri Olsa 152945aea22SJiri Olsa return false; 153945aea22SJiri Olsa } 154945aea22SJiri Olsa 1552ae82878SArnaldo Carvalho de Melo static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) 156945aea22SJiri Olsa { 157945aea22SJiri Olsa int i = 0; 158945aea22SJiri Olsa int width = 0; 159945aea22SJiri Olsa 160945aea22SJiri Olsa while (tests[i].func) { 161945aea22SJiri Olsa int len = strlen(tests[i].desc); 162945aea22SJiri Olsa 163945aea22SJiri Olsa if (width < len) 164945aea22SJiri Olsa width = len; 165945aea22SJiri Olsa ++i; 166945aea22SJiri Olsa } 167945aea22SJiri Olsa 168945aea22SJiri Olsa i = 0; 169945aea22SJiri Olsa while (tests[i].func) { 170945aea22SJiri Olsa int curr = i++, err; 171945aea22SJiri Olsa 172945aea22SJiri Olsa if (!perf_test__matches(curr, argc, argv)) 173945aea22SJiri Olsa continue; 174945aea22SJiri Olsa 175945aea22SJiri Olsa pr_info("%2d: %-*s:", i, width, tests[curr].desc); 1762ae82878SArnaldo Carvalho de Melo 1772ae82878SArnaldo Carvalho de Melo if (intlist__find(skiplist, i)) { 1782ae82878SArnaldo Carvalho de Melo color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n"); 1792ae82878SArnaldo Carvalho de Melo continue; 1802ae82878SArnaldo Carvalho de Melo } 1812ae82878SArnaldo Carvalho de Melo 182945aea22SJiri Olsa pr_debug("\n--- start ---\n"); 183945aea22SJiri Olsa err = tests[curr].func(); 184945aea22SJiri Olsa pr_debug("---- end ----\n%s:", tests[curr].desc); 185f4c1ea5fSJiri Olsa 186f4c1ea5fSJiri Olsa switch (err) { 187f4c1ea5fSJiri Olsa case TEST_OK: 188945aea22SJiri Olsa pr_info(" Ok\n"); 189f4c1ea5fSJiri Olsa break; 190f4c1ea5fSJiri Olsa case TEST_SKIP: 191f4c1ea5fSJiri Olsa color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); 192f4c1ea5fSJiri Olsa break; 193f4c1ea5fSJiri Olsa case TEST_FAIL: 194f4c1ea5fSJiri Olsa default: 195f4c1ea5fSJiri Olsa color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); 196f4c1ea5fSJiri Olsa break; 197f4c1ea5fSJiri Olsa } 198945aea22SJiri Olsa } 199945aea22SJiri Olsa 200945aea22SJiri Olsa return 0; 201945aea22SJiri Olsa } 202945aea22SJiri Olsa 203945aea22SJiri Olsa static int perf_test__list(int argc, const char **argv) 204945aea22SJiri Olsa { 205945aea22SJiri Olsa int i = 0; 206945aea22SJiri Olsa 207945aea22SJiri Olsa while (tests[i].func) { 208945aea22SJiri Olsa int curr = i++; 209945aea22SJiri Olsa 210945aea22SJiri Olsa if (argc > 1 && !strstr(tests[curr].desc, argv[1])) 211945aea22SJiri Olsa continue; 212945aea22SJiri Olsa 213945aea22SJiri Olsa pr_info("%2d: %s\n", i, tests[curr].desc); 214945aea22SJiri Olsa } 215945aea22SJiri Olsa 216945aea22SJiri Olsa return 0; 217945aea22SJiri Olsa } 218945aea22SJiri Olsa 219945aea22SJiri Olsa int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused) 220945aea22SJiri Olsa { 221945aea22SJiri Olsa const char * const test_usage[] = { 222945aea22SJiri Olsa "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]", 223945aea22SJiri Olsa NULL, 224945aea22SJiri Olsa }; 2252ae82878SArnaldo Carvalho de Melo const char *skip = NULL; 226945aea22SJiri Olsa const struct option test_options[] = { 2272ae82878SArnaldo Carvalho de Melo OPT_STRING('s', "skip", &skip, "tests", "tests to skip"), 228945aea22SJiri Olsa OPT_INCR('v', "verbose", &verbose, 229945aea22SJiri Olsa "be more verbose (show symbol address, etc)"), 230945aea22SJiri Olsa OPT_END() 231945aea22SJiri Olsa }; 2322ae82878SArnaldo Carvalho de Melo struct intlist *skiplist = NULL; 233945aea22SJiri Olsa 234945aea22SJiri Olsa argc = parse_options(argc, argv, test_options, test_usage, 0); 235945aea22SJiri Olsa if (argc >= 1 && !strcmp(argv[0], "list")) 236945aea22SJiri Olsa return perf_test__list(argc, argv); 237945aea22SJiri Olsa 238945aea22SJiri Olsa symbol_conf.priv_size = sizeof(int); 239945aea22SJiri Olsa symbol_conf.sort_by_name = true; 240945aea22SJiri Olsa symbol_conf.try_vmlinux_path = true; 241945aea22SJiri Olsa 242945aea22SJiri Olsa if (symbol__init() < 0) 243945aea22SJiri Olsa return -1; 244945aea22SJiri Olsa 2452ae82878SArnaldo Carvalho de Melo if (skip != NULL) 2462ae82878SArnaldo Carvalho de Melo skiplist = intlist__new(skip); 2472ae82878SArnaldo Carvalho de Melo 2482ae82878SArnaldo Carvalho de Melo return __cmd_test(argc, argv, skiplist); 249945aea22SJiri Olsa } 250