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 }, 118*90fa9debSJean Pihet #if defined(__x86_64__) || defined(__i386__) || defined(__arm__) 1199ff125d1SJiri 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 { 1273c3cfd99SNamhyung Kim .desc = "Test filtering hist entries", 1283c3cfd99SNamhyung Kim .func = test__hists_filter, 1293c3cfd99SNamhyung Kim }, 1303c3cfd99SNamhyung Kim { 1314e85edfcSJiri Olsa .desc = "Test mmap thread lookup", 1324e85edfcSJiri Olsa .func = test__mmap_thread_lookup, 1334e85edfcSJiri Olsa }, 1344e85edfcSJiri Olsa { 135fabf0123SJiri Olsa .desc = "Test thread mg sharing", 136fabf0123SJiri Olsa .func = test__thread_mg_share, 137fabf0123SJiri Olsa }, 138fabf0123SJiri Olsa { 139945aea22SJiri Olsa .func = NULL, 140945aea22SJiri Olsa }, 141945aea22SJiri Olsa }; 142945aea22SJiri Olsa 143945aea22SJiri Olsa static bool perf_test__matches(int curr, int argc, const char *argv[]) 144945aea22SJiri Olsa { 145945aea22SJiri Olsa int i; 146945aea22SJiri Olsa 147945aea22SJiri Olsa if (argc == 0) 148945aea22SJiri Olsa return true; 149945aea22SJiri Olsa 150945aea22SJiri Olsa for (i = 0; i < argc; ++i) { 151945aea22SJiri Olsa char *end; 152945aea22SJiri Olsa long nr = strtoul(argv[i], &end, 10); 153945aea22SJiri Olsa 154945aea22SJiri Olsa if (*end == '\0') { 155945aea22SJiri Olsa if (nr == curr + 1) 156945aea22SJiri Olsa return true; 157945aea22SJiri Olsa continue; 158945aea22SJiri Olsa } 159945aea22SJiri Olsa 160945aea22SJiri Olsa if (strstr(tests[curr].desc, argv[i])) 161945aea22SJiri Olsa return true; 162945aea22SJiri Olsa } 163945aea22SJiri Olsa 164945aea22SJiri Olsa return false; 165945aea22SJiri Olsa } 166945aea22SJiri Olsa 1672ae82878SArnaldo Carvalho de Melo static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist) 168945aea22SJiri Olsa { 169945aea22SJiri Olsa int i = 0; 170945aea22SJiri Olsa int width = 0; 171945aea22SJiri Olsa 172945aea22SJiri Olsa while (tests[i].func) { 173945aea22SJiri Olsa int len = strlen(tests[i].desc); 174945aea22SJiri Olsa 175945aea22SJiri Olsa if (width < len) 176945aea22SJiri Olsa width = len; 177945aea22SJiri Olsa ++i; 178945aea22SJiri Olsa } 179945aea22SJiri Olsa 180945aea22SJiri Olsa i = 0; 181945aea22SJiri Olsa while (tests[i].func) { 182945aea22SJiri Olsa int curr = i++, err; 183945aea22SJiri Olsa 184945aea22SJiri Olsa if (!perf_test__matches(curr, argc, argv)) 185945aea22SJiri Olsa continue; 186945aea22SJiri Olsa 187945aea22SJiri Olsa pr_info("%2d: %-*s:", i, width, tests[curr].desc); 1882ae82878SArnaldo Carvalho de Melo 1892ae82878SArnaldo Carvalho de Melo if (intlist__find(skiplist, i)) { 1902ae82878SArnaldo Carvalho de Melo color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n"); 1912ae82878SArnaldo Carvalho de Melo continue; 1922ae82878SArnaldo Carvalho de Melo } 1932ae82878SArnaldo Carvalho de Melo 194945aea22SJiri Olsa pr_debug("\n--- start ---\n"); 195945aea22SJiri Olsa err = tests[curr].func(); 196945aea22SJiri Olsa pr_debug("---- end ----\n%s:", tests[curr].desc); 197f4c1ea5fSJiri Olsa 198f4c1ea5fSJiri Olsa switch (err) { 199f4c1ea5fSJiri Olsa case TEST_OK: 200945aea22SJiri Olsa pr_info(" Ok\n"); 201f4c1ea5fSJiri Olsa break; 202f4c1ea5fSJiri Olsa case TEST_SKIP: 203f4c1ea5fSJiri Olsa color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n"); 204f4c1ea5fSJiri Olsa break; 205f4c1ea5fSJiri Olsa case TEST_FAIL: 206f4c1ea5fSJiri Olsa default: 207f4c1ea5fSJiri Olsa color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n"); 208f4c1ea5fSJiri Olsa break; 209f4c1ea5fSJiri Olsa } 210945aea22SJiri Olsa } 211945aea22SJiri Olsa 212945aea22SJiri Olsa return 0; 213945aea22SJiri Olsa } 214945aea22SJiri Olsa 215945aea22SJiri Olsa static int perf_test__list(int argc, const char **argv) 216945aea22SJiri Olsa { 217945aea22SJiri Olsa int i = 0; 218945aea22SJiri Olsa 219945aea22SJiri Olsa while (tests[i].func) { 220945aea22SJiri Olsa int curr = i++; 221945aea22SJiri Olsa 222945aea22SJiri Olsa if (argc > 1 && !strstr(tests[curr].desc, argv[1])) 223945aea22SJiri Olsa continue; 224945aea22SJiri Olsa 225945aea22SJiri Olsa pr_info("%2d: %s\n", i, tests[curr].desc); 226945aea22SJiri Olsa } 227945aea22SJiri Olsa 228945aea22SJiri Olsa return 0; 229945aea22SJiri Olsa } 230945aea22SJiri Olsa 231945aea22SJiri Olsa int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused) 232945aea22SJiri Olsa { 233945aea22SJiri Olsa const char * const test_usage[] = { 234945aea22SJiri Olsa "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]", 235945aea22SJiri Olsa NULL, 236945aea22SJiri Olsa }; 2372ae82878SArnaldo Carvalho de Melo const char *skip = NULL; 238945aea22SJiri Olsa const struct option test_options[] = { 2392ae82878SArnaldo Carvalho de Melo OPT_STRING('s', "skip", &skip, "tests", "tests to skip"), 240945aea22SJiri Olsa OPT_INCR('v', "verbose", &verbose, 241945aea22SJiri Olsa "be more verbose (show symbol address, etc)"), 242945aea22SJiri Olsa OPT_END() 243945aea22SJiri Olsa }; 2442ae82878SArnaldo Carvalho de Melo struct intlist *skiplist = NULL; 245945aea22SJiri Olsa 246945aea22SJiri Olsa argc = parse_options(argc, argv, test_options, test_usage, 0); 247945aea22SJiri Olsa if (argc >= 1 && !strcmp(argv[0], "list")) 248945aea22SJiri Olsa return perf_test__list(argc, argv); 249945aea22SJiri Olsa 250945aea22SJiri Olsa symbol_conf.priv_size = sizeof(int); 251945aea22SJiri Olsa symbol_conf.sort_by_name = true; 252945aea22SJiri Olsa symbol_conf.try_vmlinux_path = true; 253945aea22SJiri Olsa 254945aea22SJiri Olsa if (symbol__init() < 0) 255945aea22SJiri Olsa return -1; 256945aea22SJiri Olsa 2572ae82878SArnaldo Carvalho de Melo if (skip != NULL) 2582ae82878SArnaldo Carvalho de Melo skiplist = intlist__new(skip); 2592ae82878SArnaldo Carvalho de Melo 2602ae82878SArnaldo Carvalho de Melo return __cmd_test(argc, argv, skiplist); 261945aea22SJiri Olsa } 262