2010-04-29 18:58:32 -03:00
|
|
|
/*
|
|
|
|
|
* builtin-test.c
|
|
|
|
|
*
|
|
|
|
|
* Builtin regression testing command: ever growing number of sanity tests
|
|
|
|
|
*/
|
|
|
|
|
#include "builtin.h"
|
2013-01-24 16:22:55 -03:00
|
|
|
#include "intlist.h"
|
2012-11-10 01:46:41 +01:00
|
|
|
#include "tests.h"
|
2012-11-10 01:46:51 +01:00
|
|
|
#include "debug.h"
|
|
|
|
|
#include "color.h"
|
|
|
|
|
#include "parse-options.h"
|
|
|
|
|
#include "symbol.h"
|
2011-01-04 11:55:27 -02:00
|
|
|
|
2010-04-29 18:58:32 -03:00
|
|
|
static struct test {
|
|
|
|
|
const char *desc;
|
|
|
|
|
int (*func)(void);
|
|
|
|
|
} tests[] = {
|
|
|
|
|
{
|
|
|
|
|
.desc = "vmlinux symtab matches kallsyms",
|
|
|
|
|
.func = test__vmlinux_matches_kallsyms,
|
|
|
|
|
},
|
2011-01-04 00:16:20 -02:00
|
|
|
{
|
|
|
|
|
.desc = "detect open syscall event",
|
|
|
|
|
.func = test__open_syscall_event,
|
|
|
|
|
},
|
2011-01-04 11:55:27 -02:00
|
|
|
{
|
|
|
|
|
.desc = "detect open syscall event on all cpus",
|
|
|
|
|
.func = test__open_syscall_event_on_all_cpus,
|
|
|
|
|
},
|
2011-01-15 10:42:46 -02:00
|
|
|
{
|
|
|
|
|
.desc = "read samples using the mmap interface",
|
|
|
|
|
.func = test__basic_mmap,
|
|
|
|
|
},
|
2011-07-14 11:25:33 +02:00
|
|
|
{
|
|
|
|
|
.desc = "parse events tests",
|
2012-11-10 01:46:51 +01:00
|
|
|
.func = test__parse_events,
|
2011-07-14 11:25:33 +02:00
|
|
|
},
|
2011-11-21 14:42:47 +01:00
|
|
|
#if defined(__x86_64__) || defined(__i386__)
|
|
|
|
|
{
|
|
|
|
|
.desc = "x86 rdpmc test",
|
|
|
|
|
.func = test__rdpmc,
|
|
|
|
|
},
|
|
|
|
|
#endif
|
2011-12-02 11:13:50 -02:00
|
|
|
{
|
|
|
|
|
.desc = "Validate PERF_RECORD_* events & perf_sample fields",
|
|
|
|
|
.func = test__PERF_RECORD,
|
|
|
|
|
},
|
2012-03-15 20:09:17 +01:00
|
|
|
{
|
|
|
|
|
.desc = "Test perf pmu format parsing",
|
2012-11-10 01:46:50 +01:00
|
|
|
.func = test__pmu,
|
2012-03-15 20:09:17 +01:00
|
|
|
},
|
2012-07-22 14:14:40 +02:00
|
|
|
{
|
|
|
|
|
.desc = "Test dso data interface",
|
2012-11-10 01:46:51 +01:00
|
|
|
.func = test__dso_data,
|
2012-07-22 14:14:40 +02:00
|
|
|
},
|
2012-09-06 13:11:18 -03:00
|
|
|
{
|
|
|
|
|
.desc = "roundtrip evsel->name check",
|
2012-11-10 01:46:47 +01:00
|
|
|
.func = test__perf_evsel__roundtrip_name_test,
|
2012-09-06 13:11:18 -03:00
|
|
|
},
|
2012-09-18 11:56:28 -03:00
|
|
|
{
|
|
|
|
|
.desc = "Check parsing of sched tracepoints fields",
|
2012-11-10 01:46:48 +01:00
|
|
|
.func = test__perf_evsel__tp_sched_test,
|
2012-09-18 11:56:28 -03:00
|
|
|
},
|
2012-09-26 13:23:10 -03:00
|
|
|
{
|
|
|
|
|
.desc = "Generate and check syscalls:sys_enter_open event fields",
|
|
|
|
|
.func = test__syscall_open_tp_fields,
|
|
|
|
|
},
|
2012-10-30 23:02:05 +01:00
|
|
|
{
|
|
|
|
|
.desc = "struct perf_event_attr setup",
|
2012-11-10 01:46:51 +01:00
|
|
|
.func = test__attr,
|
2012-10-30 23:02:05 +01:00
|
|
|
},
|
2012-12-10 17:29:57 +09:00
|
|
|
{
|
|
|
|
|
.desc = "Test matching and linking mutliple hists",
|
|
|
|
|
.func = test__hists_link,
|
|
|
|
|
},
|
2012-12-14 13:06:13 -03:00
|
|
|
{
|
|
|
|
|
.desc = "Try 'use perf' in python, checking link problems",
|
|
|
|
|
.func = test__python_use,
|
|
|
|
|
},
|
2013-03-10 19:41:10 +01:00
|
|
|
{
|
|
|
|
|
.desc = "Test breakpoint overflow signal handler",
|
|
|
|
|
.func = test__bp_signal,
|
|
|
|
|
},
|
2010-04-29 18:58:32 -03:00
|
|
|
{
|
|
|
|
|
.func = NULL,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
2011-11-29 12:52:07 -02:00
|
|
|
static bool perf_test__matches(int curr, int argc, const char *argv[])
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < argc; ++i) {
|
|
|
|
|
char *end;
|
|
|
|
|
long nr = strtoul(argv[i], &end, 10);
|
|
|
|
|
|
|
|
|
|
if (*end == '\0') {
|
|
|
|
|
if (nr == curr + 1)
|
|
|
|
|
return true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (strstr(tests[curr].desc, argv[i]))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-24 16:22:55 -03:00
|
|
|
static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
|
2010-04-29 18:58:32 -03:00
|
|
|
{
|
|
|
|
|
int i = 0;
|
2012-10-24 15:44:41 -02:00
|
|
|
int width = 0;
|
2010-04-29 18:58:32 -03:00
|
|
|
|
2012-10-24 15:44:41 -02:00
|
|
|
while (tests[i].func) {
|
|
|
|
|
int len = strlen(tests[i].desc);
|
|
|
|
|
|
|
|
|
|
if (width < len)
|
|
|
|
|
width = len;
|
|
|
|
|
++i;
|
|
|
|
|
}
|
2012-10-30 23:01:43 +01:00
|
|
|
|
2012-10-24 15:44:41 -02:00
|
|
|
i = 0;
|
2010-04-29 18:58:32 -03:00
|
|
|
while (tests[i].func) {
|
2011-11-29 12:52:07 -02:00
|
|
|
int curr = i++, err;
|
|
|
|
|
|
|
|
|
|
if (!perf_test__matches(curr, argc, argv))
|
|
|
|
|
continue;
|
|
|
|
|
|
2012-10-24 15:44:41 -02:00
|
|
|
pr_info("%2d: %-*s:", i, width, tests[curr].desc);
|
2013-01-24 16:22:55 -03:00
|
|
|
|
|
|
|
|
if (intlist__find(skiplist, i)) {
|
|
|
|
|
color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-29 18:58:32 -03:00
|
|
|
pr_debug("\n--- start ---\n");
|
2011-11-29 12:52:07 -02:00
|
|
|
err = tests[curr].func();
|
|
|
|
|
pr_debug("---- end ----\n%s:", tests[curr].desc);
|
2012-12-19 11:33:39 -03:00
|
|
|
|
|
|
|
|
switch (err) {
|
|
|
|
|
case TEST_OK:
|
2012-10-24 15:44:41 -02:00
|
|
|
pr_info(" Ok\n");
|
2012-12-19 11:33:39 -03:00
|
|
|
break;
|
|
|
|
|
case TEST_SKIP:
|
|
|
|
|
color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
|
|
|
|
|
break;
|
|
|
|
|
case TEST_FAIL:
|
|
|
|
|
default:
|
|
|
|
|
color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-04-29 18:58:32 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-29 12:52:07 -02:00
|
|
|
static int perf_test__list(int argc, const char **argv)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
2010-04-29 18:58:32 -03:00
|
|
|
|
2011-11-29 12:52:07 -02:00
|
|
|
while (tests[i].func) {
|
|
|
|
|
int curr = i++;
|
|
|
|
|
|
|
|
|
|
if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
pr_info("%2d: %s\n", i, tests[curr].desc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-04-29 18:58:32 -03:00
|
|
|
|
2012-09-11 01:15:03 +03:00
|
|
|
int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
|
2010-04-29 18:58:32 -03:00
|
|
|
{
|
2011-11-29 12:52:07 -02:00
|
|
|
const char * const test_usage[] = {
|
|
|
|
|
"perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
2013-01-24 16:22:55 -03:00
|
|
|
const char *skip = NULL;
|
2011-11-29 12:52:07 -02:00
|
|
|
const struct option test_options[] = {
|
2013-01-24 16:22:55 -03:00
|
|
|
OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
|
2012-01-08 02:25:26 +09:00
|
|
|
OPT_INCR('v', "verbose", &verbose,
|
2011-11-29 12:52:07 -02:00
|
|
|
"be more verbose (show symbol address, etc)"),
|
|
|
|
|
OPT_END()
|
|
|
|
|
};
|
2013-01-24 16:22:55 -03:00
|
|
|
struct intlist *skiplist = NULL;
|
2011-11-29 12:52:07 -02:00
|
|
|
|
2010-04-29 18:58:32 -03:00
|
|
|
argc = parse_options(argc, argv, test_options, test_usage, 0);
|
2011-11-29 12:52:07 -02:00
|
|
|
if (argc >= 1 && !strcmp(argv[0], "list"))
|
|
|
|
|
return perf_test__list(argc, argv);
|
2010-04-29 18:58:32 -03:00
|
|
|
|
|
|
|
|
symbol_conf.priv_size = sizeof(int);
|
|
|
|
|
symbol_conf.sort_by_name = true;
|
|
|
|
|
symbol_conf.try_vmlinux_path = true;
|
|
|
|
|
|
|
|
|
|
if (symbol__init() < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2013-01-24 16:22:55 -03:00
|
|
|
if (skip != NULL)
|
|
|
|
|
skiplist = intlist__new(skip);
|
|
|
|
|
|
|
|
|
|
return __cmd_test(argc, argv, skiplist);
|
2010-04-29 18:58:32 -03:00
|
|
|
}
|