2010-04-29 18:58:32 -03:00
|
|
|
/*
|
|
|
|
|
* builtin-test.c
|
|
|
|
|
*
|
|
|
|
|
* Builtin regression testing command: ever growing number of sanity tests
|
|
|
|
|
*/
|
|
|
|
|
#include "builtin.h"
|
|
|
|
|
|
|
|
|
|
#include "util/cache.h"
|
2012-10-24 15:44:41 -02:00
|
|
|
#include "util/color.h"
|
2010-04-29 18:58:32 -03:00
|
|
|
#include "util/debug.h"
|
2011-11-16 14:03:07 -02:00
|
|
|
#include "util/debugfs.h"
|
2011-01-15 10:42:46 -02:00
|
|
|
#include "util/evlist.h"
|
2012-11-09 11:32:52 -03:00
|
|
|
#include "util/machine.h"
|
2010-04-29 18:58:32 -03:00
|
|
|
#include "util/parse-options.h"
|
2011-01-15 10:42:46 -02:00
|
|
|
#include "util/parse-events.h"
|
2010-04-29 18:58:32 -03:00
|
|
|
#include "util/symbol.h"
|
2011-01-18 15:15:24 -02:00
|
|
|
#include "util/thread_map.h"
|
2012-03-15 20:09:17 +01:00
|
|
|
#include "util/pmu.h"
|
2012-09-18 11:56:28 -03:00
|
|
|
#include "event-parse.h"
|
2011-07-14 11:25:33 +02:00
|
|
|
#include "../../include/linux/hw_breakpoint.h"
|
2010-04-29 18:58:32 -03:00
|
|
|
|
2011-11-21 14:42:47 +01:00
|
|
|
#include <sys/mman.h>
|
|
|
|
|
|
2011-01-04 11:55:27 -02:00
|
|
|
#include "util/cpumap.h"
|
2011-01-04 00:16:20 -02:00
|
|
|
#include "util/evsel.h"
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
2012-11-10 01:46:41 +01:00
|
|
|
#include "tests.h"
|
|
|
|
|
|
2011-01-04 11:55:27 -02:00
|
|
|
#include <sched.h>
|
|
|
|
|
|
|
|
|
|
|
2012-03-15 20:09:17 +01:00
|
|
|
static int test__perf_pmu(void)
|
|
|
|
|
{
|
|
|
|
|
return perf_pmu__test();
|
|
|
|
|
}
|
|
|
|
|
|
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-05-21 09:12:49 +02:00
|
|
|
.func = parse_events__test,
|
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",
|
|
|
|
|
.func = test__perf_pmu,
|
|
|
|
|
},
|
2012-07-22 14:14:40 +02:00
|
|
|
{
|
|
|
|
|
.desc = "Test dso data interface",
|
|
|
|
|
.func = dso__test_data,
|
|
|
|
|
},
|
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",
|
|
|
|
|
.func = test_attr__run,
|
|
|
|
|
},
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __cmd_test(int argc, const char *argv[])
|
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);
|
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-10-24 15:44:41 -02:00
|
|
|
if (err)
|
|
|
|
|
color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
|
|
|
|
|
else
|
|
|
|
|
pr_info(" Ok\n");
|
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,
|
|
|
|
|
};
|
|
|
|
|
const struct option test_options[] = {
|
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()
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
|
|
|
|
|
2011-11-29 12:52:07 -02:00
|
|
|
return __cmd_test(argc, argv);
|
2010-04-29 18:58:32 -03:00
|
|
|
}
|