Files
linux-apfs/tools/perf/tests/builtin-test.c
T

340 lines
6.7 KiB
C
Raw Normal View History

/*
* builtin-test.c
*
* Builtin regression testing command: ever growing number of sanity tests
*/
2014-05-10 17:22:30 +02:00
#include <unistd.h>
#include <string.h>
#include "builtin.h"
2014-10-09 16:16:00 -03:00
#include "hist.h"
2013-01-24 16:22:55 -03:00
#include "intlist.h"
#include "tests.h"
#include "debug.h"
#include "color.h"
#include "parse-options.h"
#include "symbol.h"
2015-10-05 15:40:19 +01:00
struct test __weak arch_tests[] = {
{
.func = NULL,
},
};
static struct test generic_tests[] = {
{
.desc = "vmlinux symtab matches kallsyms",
.func = test__vmlinux_matches_kallsyms,
},
{
2015-04-16 16:52:53 +03:00
.desc = "detect openat syscall event",
.func = test__openat_syscall_event,
},
{
2015-04-16 16:52:53 +03:00
.desc = "detect openat syscall event on all cpus",
.func = test__openat_syscall_event_on_all_cpus,
},
{
.desc = "read samples using the mmap interface",
.func = test__basic_mmap,
},
{
.desc = "parse events tests",
.func = test__parse_events,
},
{
.desc = "Validate PERF_RECORD_* events & perf_sample fields",
.func = test__PERF_RECORD,
},
{
.desc = "Test perf pmu format parsing",
.func = test__pmu,
},
2012-07-22 14:14:40 +02:00
{
.desc = "Test dso data read",
.func = test__dso_data,
2012-07-22 14:14:40 +02:00
},
{
.desc = "Test dso data cache",
.func = test__dso_data_cache,
},
{
.desc = "Test dso data reopen",
.func = test__dso_data_reopen,
},
{
.desc = "roundtrip evsel->name check",
.func = test__perf_evsel__roundtrip_name_test,
},
{
.desc = "Check parsing of sched tracepoints fields",
.func = test__perf_evsel__tp_sched_test,
},
{
2015-04-16 16:52:53 +03:00
.desc = "Generate and check syscalls:sys_enter_openat event fields",
.func = test__syscall_openat_tp_fields,
},
{
.desc = "struct perf_event_attr setup",
.func = test__attr,
},
{
2013-05-23 12:08:38 +02:00
.desc = "Test matching and linking multiple hists",
.func = test__hists_link,
},
{
2014-11-12 16:27:05 +08:00
.desc = "Try 'import perf' in python, checking link problems",
.func = test__python_use,
},
{
.desc = "Test breakpoint overflow signal handler",
.func = test__bp_signal,
},
{
.desc = "Test breakpoint overflow sampling",
.func = test__bp_signal_overflow,
},
{
.desc = "Test number of exit event of a simple workload",
.func = test__task_exit,
},
{
.desc = "Test software clock events have valid period values",
.func = test__sw_clock_freq,
},
{
.desc = "Test object code reading",
.func = test__code_reading,
},
2013-08-27 11:23:13 +03:00
{
.desc = "Test sample parsing",
.func = test__sample_parsing,
},
2013-08-31 21:50:53 +03:00
{
.desc = "Test using a dummy software event to keep tracking",
.func = test__keep_tracking,
},
{
.desc = "Test parsing with no sample_id_all bit set",
.func = test__parse_no_sample_id_all,
},
{
.desc = "Test filtering hist entries",
.func = test__hists_filter,
},
{
.desc = "Test mmap thread lookup",
.func = test__mmap_thread_lookup,
},
{
.desc = "Test thread mg sharing",
.func = test__thread_mg_share,
},
{
.desc = "Test output sorting of hist entries",
.func = test__hists_output,
},
{
.desc = "Test cumulation of child hist entries",
.func = test__hists_cumulate,
},
{
.desc = "Test tracking with sched_switch",
.func = test__switch_tracking,
},
{
.desc = "Filter fds with revents mask in a fdarray",
.func = test__fdarray__filter,
},
2014-08-18 16:49:00 -03:00
{
.desc = "Add fd to a fdarray, making it autogrow",
.func = test__fdarray__add,
2014-08-18 16:49:00 -03:00
},
2015-02-05 15:40:25 +01:00
{
.desc = "Test kmod_path__parse function",
.func = test__kmod_path__parse,
},
2015-06-26 11:29:08 +02:00
{
.desc = "Test thread map",
.func = test__thread_map,
},
{
.desc = "Test LLVM searching and compiling",
.func = test__llvm,
},
2015-09-04 04:58:31 -04:00
{
.desc = "Test topology in session",
.func = test_session_topology,
},
2015-11-06 13:49:43 +00:00
{
.desc = "Test BPF filter",
.func = test__bpf,
},
{
.func = NULL,
},
};
2015-10-05 15:40:19 +01:00
static struct test *tests[] = {
generic_tests,
arch_tests,
};
static bool perf_test__matches(struct test *test, 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(test->desc, argv[i]))
return true;
}
return false;
}
2014-05-10 17:22:30 +02:00
static int run_test(struct test *test)
{
int status, err = -1, child = fork();
char sbuf[STRERR_BUFSIZE];
2014-05-10 17:22:30 +02:00
if (child < 0) {
pr_err("failed to fork test: %s\n",
strerror_r(errno, sbuf, sizeof(sbuf)));
2014-05-10 17:22:30 +02:00
return -1;
}
if (!child) {
pr_debug("test child forked, pid %d\n", getpid());
err = test->func();
exit(err);
}
wait(&status);
if (WIFEXITED(status)) {
2015-05-11 12:28:35 +00:00
err = (signed char)WEXITSTATUS(status);
2014-05-10 17:22:30 +02:00
pr_debug("test child finished with %d\n", err);
} else if (WIFSIGNALED(status)) {
err = -1;
pr_debug("test child interrupted\n");
}
return err;
}
2015-10-05 15:40:19 +01:00
#define for_each_test(j, t) \
for (j = 0; j < ARRAY_SIZE(tests); j++) \
for (t = &tests[j][0]; t->func; t++)
2013-01-24 16:22:55 -03:00
static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
{
struct test *t;
2015-10-05 15:40:19 +01:00
unsigned int j;
int i = 0;
int width = 0;
2015-10-05 15:40:19 +01:00
for_each_test(j, t) {
int len = strlen(t->desc);
if (width < len)
width = len;
}
2015-10-05 15:40:19 +01:00
for_each_test(j, t) {
int curr = i++, err;
if (!perf_test__matches(t, curr, argc, argv))
continue;
pr_info("%2d: %-*s:", i, width, t->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;
}
pr_debug("\n--- start ---\n");
err = run_test(t);
pr_debug("---- end ----\n%s:", t->desc);
switch (err) {
case TEST_OK:
pr_info(" Ok\n");
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;
}
}
return 0;
}
static int perf_test__list(int argc, const char **argv)
{
2015-10-05 15:40:19 +01:00
unsigned int j;
struct test *t;
int i = 0;
2015-10-05 15:40:19 +01:00
for_each_test(j, t) {
if (argc > 1 && !strstr(t->desc, argv[1]))
continue;
pr_info("%2d: %s\n", ++i, t->desc);
}
return 0;
}
int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
{
const char *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;
const struct option test_options[] = {
2013-01-24 16:22:55 -03:00
OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show symbol address, etc)"),
OPT_END()
};
const char * const test_subcommands[] = { "list", NULL };
2013-01-24 16:22:55 -03:00
struct intlist *skiplist = NULL;
2014-10-09 16:16:00 -03:00
int ret = hists__init();
if (ret < 0)
return ret;
argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
if (argc >= 1 && !strcmp(argv[0], "list"))
return perf_test__list(argc, argv);
symbol_conf.priv_size = sizeof(int);
symbol_conf.sort_by_name = true;
symbol_conf.try_vmlinux_path = true;
if (symbol__init(NULL) < 0)
return -1;
2013-01-24 16:22:55 -03:00
if (skip != NULL)
skiplist = intlist__new(skip);
return __cmd_test(argc, argv, skiplist);
}