builtin-test.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293
  1. /*
  2. * builtin-test.c
  3. *
  4. * Builtin regression testing command: ever growing number of sanity tests
  5. */
  6. #include "builtin.h"
  7. #include "util/cache.h"
  8. #include "util/debug.h"
  9. #include "util/debugfs.h"
  10. #include "util/evlist.h"
  11. #include "util/parse-options.h"
  12. #include "util/parse-events.h"
  13. #include "util/symbol.h"
  14. #include "util/thread_map.h"
  15. #include "../../include/linux/hw_breakpoint.h"
  16. static int vmlinux_matches_kallsyms_filter(struct map *map __used, struct symbol *sym)
  17. {
  18. bool *visited = symbol__priv(sym);
  19. *visited = true;
  20. return 0;
  21. }
  22. static int test__vmlinux_matches_kallsyms(void)
  23. {
  24. int err = -1;
  25. struct rb_node *nd;
  26. struct symbol *sym;
  27. struct map *kallsyms_map, *vmlinux_map;
  28. struct machine kallsyms, vmlinux;
  29. enum map_type type = MAP__FUNCTION;
  30. long page_size = sysconf(_SC_PAGE_SIZE);
  31. struct ref_reloc_sym ref_reloc_sym = { .name = "_stext", };
  32. /*
  33. * Step 1:
  34. *
  35. * Init the machines that will hold kernel, modules obtained from
  36. * both vmlinux + .ko files and from /proc/kallsyms split by modules.
  37. */
  38. machine__init(&kallsyms, "", HOST_KERNEL_ID);
  39. machine__init(&vmlinux, "", HOST_KERNEL_ID);
  40. /*
  41. * Step 2:
  42. *
  43. * Create the kernel maps for kallsyms and the DSO where we will then
  44. * load /proc/kallsyms. Also create the modules maps from /proc/modules
  45. * and find the .ko files that match them in /lib/modules/`uname -r`/.
  46. */
  47. if (machine__create_kernel_maps(&kallsyms) < 0) {
  48. pr_debug("machine__create_kernel_maps ");
  49. return -1;
  50. }
  51. /*
  52. * Step 3:
  53. *
  54. * Load and split /proc/kallsyms into multiple maps, one per module.
  55. */
  56. if (machine__load_kallsyms(&kallsyms, "/proc/kallsyms", type, NULL) <= 0) {
  57. pr_debug("dso__load_kallsyms ");
  58. goto out;
  59. }
  60. /*
  61. * Step 4:
  62. *
  63. * kallsyms will be internally on demand sorted by name so that we can
  64. * find the reference relocation * symbol, i.e. the symbol we will use
  65. * to see if the running kernel was relocated by checking if it has the
  66. * same value in the vmlinux file we load.
  67. */
  68. kallsyms_map = machine__kernel_map(&kallsyms, type);
  69. sym = map__find_symbol_by_name(kallsyms_map, ref_reloc_sym.name, NULL);
  70. if (sym == NULL) {
  71. pr_debug("dso__find_symbol_by_name ");
  72. goto out;
  73. }
  74. ref_reloc_sym.addr = sym->start;
  75. /*
  76. * Step 5:
  77. *
  78. * Now repeat step 2, this time for the vmlinux file we'll auto-locate.
  79. */
  80. if (machine__create_kernel_maps(&vmlinux) < 0) {
  81. pr_debug("machine__create_kernel_maps ");
  82. goto out;
  83. }
  84. vmlinux_map = machine__kernel_map(&vmlinux, type);
  85. map__kmap(vmlinux_map)->ref_reloc_sym = &ref_reloc_sym;
  86. /*
  87. * Step 6:
  88. *
  89. * Locate a vmlinux file in the vmlinux path that has a buildid that
  90. * matches the one of the running kernel.
  91. *
  92. * While doing that look if we find the ref reloc symbol, if we find it
  93. * we'll have its ref_reloc_symbol.unrelocated_addr and then
  94. * maps__reloc_vmlinux will notice and set proper ->[un]map_ip routines
  95. * to fixup the symbols.
  96. */
  97. if (machine__load_vmlinux_path(&vmlinux, type,
  98. vmlinux_matches_kallsyms_filter) <= 0) {
  99. pr_debug("machine__load_vmlinux_path ");
  100. goto out;
  101. }
  102. err = 0;
  103. /*
  104. * Step 7:
  105. *
  106. * Now look at the symbols in the vmlinux DSO and check if we find all of them
  107. * in the kallsyms dso. For the ones that are in both, check its names and
  108. * end addresses too.
  109. */
  110. for (nd = rb_first(&vmlinux_map->dso->symbols[type]); nd; nd = rb_next(nd)) {
  111. struct symbol *pair, *first_pair;
  112. bool backwards = true;
  113. sym = rb_entry(nd, struct symbol, rb_node);
  114. if (sym->start == sym->end)
  115. continue;
  116. first_pair = machine__find_kernel_symbol(&kallsyms, type, sym->start, NULL, NULL);
  117. pair = first_pair;
  118. if (pair && pair->start == sym->start) {
  119. next_pair:
  120. if (strcmp(sym->name, pair->name) == 0) {
  121. /*
  122. * kallsyms don't have the symbol end, so we
  123. * set that by using the next symbol start - 1,
  124. * in some cases we get this up to a page
  125. * wrong, trace_kmalloc when I was developing
  126. * this code was one such example, 2106 bytes
  127. * off the real size. More than that and we
  128. * _really_ have a problem.
  129. */
  130. s64 skew = sym->end - pair->end;
  131. if (llabs(skew) < page_size)
  132. continue;
  133. pr_debug("%#" PRIx64 ": diff end addr for %s v: %#" PRIx64 " k: %#" PRIx64 "\n",
  134. sym->start, sym->name, sym->end, pair->end);
  135. } else {
  136. struct rb_node *nnd;
  137. detour:
  138. nnd = backwards ? rb_prev(&pair->rb_node) :
  139. rb_next(&pair->rb_node);
  140. if (nnd) {
  141. struct symbol *next = rb_entry(nnd, struct symbol, rb_node);
  142. if (next->start == sym->start) {
  143. pair = next;
  144. goto next_pair;
  145. }
  146. }
  147. if (backwards) {
  148. backwards = false;
  149. pair = first_pair;
  150. goto detour;
  151. }
  152. pr_debug("%#" PRIx64 ": diff name v: %s k: %s\n",
  153. sym->start, sym->name, pair->name);
  154. }
  155. } else
  156. pr_debug("%#" PRIx64 ": %s not on kallsyms\n", sym->start, sym->name);
  157. err = -1;
  158. }
  159. if (!verbose)
  160. goto out;
  161. pr_info("Maps only in vmlinux:\n");
  162. for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) {
  163. struct map *pos = rb_entry(nd, struct map, rb_node), *pair;
  164. /*
  165. * If it is the kernel, kallsyms is always "[kernel.kallsyms]", while
  166. * the kernel will have the path for the vmlinux file being used,
  167. * so use the short name, less descriptive but the same ("[kernel]" in
  168. * both cases.
  169. */
  170. pair = map_groups__find_by_name(&kallsyms.kmaps, type,
  171. (pos->dso->kernel ?
  172. pos->dso->short_name :
  173. pos->dso->name));
  174. if (pair)
  175. pair->priv = 1;
  176. else
  177. map__fprintf(pos, stderr);
  178. }
  179. pr_info("Maps in vmlinux with a different name in kallsyms:\n");
  180. for (nd = rb_first(&vmlinux.kmaps.maps[type]); nd; nd = rb_next(nd)) {
  181. struct map *pos = rb_entry(nd, struct map, rb_node), *pair;
  182. pair = map_groups__find(&kallsyms.kmaps, type, pos->start);
  183. if (pair == NULL || pair->priv)
  184. continue;
  185. if (pair->start == pos->start) {
  186. pair->priv = 1;
  187. pr_info(" %" PRIx64 "-%" PRIx64 " %" PRIx64 " %s in kallsyms as",
  188. pos->start, pos->end, pos->pgoff, pos->dso->name);
  189. if (pos->pgoff != pair->pgoff || pos->end != pair->end)
  190. pr_info(": \n*%" PRIx64 "-%" PRIx64 " %" PRIx64 "",
  191. pair->start, pair->end, pair->pgoff);
  192. pr_info(" %s\n", pair->dso->name);
  193. pair->priv = 1;
  194. }
  195. }
  196. pr_info("Maps only in kallsyms:\n");
  197. for (nd = rb_first(&kallsyms.kmaps.maps[type]);
  198. nd; nd = rb_next(nd)) {
  199. struct map *pos = rb_entry(nd, struct map, rb_node);
  200. if (!pos->priv)
  201. map__fprintf(pos, stderr);
  202. }
  203. out:
  204. return err;
  205. }
  206. #include "util/cpumap.h"
  207. #include "util/evsel.h"
  208. #include <sys/types.h>
  209. static int trace_event__id(const char *evname)
  210. {
  211. char *filename;
  212. int err = -1, fd;
  213. if (asprintf(&filename,
  214. "%s/syscalls/%s/id",
  215. tracing_events_path, evname) < 0)
  216. return -1;
  217. fd = open(filename, O_RDONLY);
  218. if (fd >= 0) {
  219. char id[16];
  220. if (read(fd, id, sizeof(id)) > 0)
  221. err = atoi(id);
  222. close(fd);
  223. }
  224. free(filename);
  225. return err;
  226. }
  227. static int test__open_syscall_event(void)
  228. {
  229. int err = -1, fd;
  230. struct thread_map *threads;
  231. struct perf_evsel *evsel;
  232. struct perf_event_attr attr;
  233. unsigned int nr_open_calls = 111, i;
  234. int id = trace_event__id("sys_enter_open");
  235. if (id < 0) {
  236. pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
  237. return -1;
  238. }
  239. threads = thread_map__new(-1, getpid());
  240. if (threads == NULL) {
  241. pr_debug("thread_map__new\n");
  242. return -1;
  243. }
  244. memset(&attr, 0, sizeof(attr));
  245. attr.type = PERF_TYPE_TRACEPOINT;
  246. attr.config = id;
  247. evsel = perf_evsel__new(&attr, 0);
  248. if (evsel == NULL) {
  249. pr_debug("perf_evsel__new\n");
  250. goto out_thread_map_delete;
  251. }
  252. if (perf_evsel__open_per_thread(evsel, threads, false, NULL) < 0) {
  253. pr_debug("failed to open counter: %s, "
  254. "tweak /proc/sys/kernel/perf_event_paranoid?\n",
  255. strerror(errno));
  256. goto out_evsel_delete;
  257. }
  258. for (i = 0; i < nr_open_calls; ++i) {
  259. fd = open("/etc/passwd", O_RDONLY);
  260. close(fd);
  261. }
  262. if (perf_evsel__read_on_cpu(evsel, 0, 0) < 0) {
  263. pr_debug("perf_evsel__read_on_cpu\n");
  264. goto out_close_fd;
  265. }
  266. if (evsel->counts->cpu[0].val != nr_open_calls) {
  267. pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls, got %" PRIu64 "\n",
  268. nr_open_calls, evsel->counts->cpu[0].val);
  269. goto out_close_fd;
  270. }
  271. err = 0;
  272. out_close_fd:
  273. perf_evsel__close_fd(evsel, 1, threads->nr);
  274. out_evsel_delete:
  275. perf_evsel__delete(evsel);
  276. out_thread_map_delete:
  277. thread_map__delete(threads);
  278. return err;
  279. }
  280. #include <sched.h>
  281. static int test__open_syscall_event_on_all_cpus(void)
  282. {
  283. int err = -1, fd, cpu;
  284. struct thread_map *threads;
  285. struct cpu_map *cpus;
  286. struct perf_evsel *evsel;
  287. struct perf_event_attr attr;
  288. unsigned int nr_open_calls = 111, i;
  289. cpu_set_t cpu_set;
  290. int id = trace_event__id("sys_enter_open");
  291. if (id < 0) {
  292. pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
  293. return -1;
  294. }
  295. threads = thread_map__new(-1, getpid());
  296. if (threads == NULL) {
  297. pr_debug("thread_map__new\n");
  298. return -1;
  299. }
  300. cpus = cpu_map__new(NULL);
  301. if (cpus == NULL) {
  302. pr_debug("cpu_map__new\n");
  303. goto out_thread_map_delete;
  304. }
  305. CPU_ZERO(&cpu_set);
  306. memset(&attr, 0, sizeof(attr));
  307. attr.type = PERF_TYPE_TRACEPOINT;
  308. attr.config = id;
  309. evsel = perf_evsel__new(&attr, 0);
  310. if (evsel == NULL) {
  311. pr_debug("perf_evsel__new\n");
  312. goto out_thread_map_delete;
  313. }
  314. if (perf_evsel__open(evsel, cpus, threads, false, NULL) < 0) {
  315. pr_debug("failed to open counter: %s, "
  316. "tweak /proc/sys/kernel/perf_event_paranoid?\n",
  317. strerror(errno));
  318. goto out_evsel_delete;
  319. }
  320. for (cpu = 0; cpu < cpus->nr; ++cpu) {
  321. unsigned int ncalls = nr_open_calls + cpu;
  322. /*
  323. * XXX eventually lift this restriction in a way that
  324. * keeps perf building on older glibc installations
  325. * without CPU_ALLOC. 1024 cpus in 2010 still seems
  326. * a reasonable upper limit tho :-)
  327. */
  328. if (cpus->map[cpu] >= CPU_SETSIZE) {
  329. pr_debug("Ignoring CPU %d\n", cpus->map[cpu]);
  330. continue;
  331. }
  332. CPU_SET(cpus->map[cpu], &cpu_set);
  333. if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
  334. pr_debug("sched_setaffinity() failed on CPU %d: %s ",
  335. cpus->map[cpu],
  336. strerror(errno));
  337. goto out_close_fd;
  338. }
  339. for (i = 0; i < ncalls; ++i) {
  340. fd = open("/etc/passwd", O_RDONLY);
  341. close(fd);
  342. }
  343. CPU_CLR(cpus->map[cpu], &cpu_set);
  344. }
  345. /*
  346. * Here we need to explicitely preallocate the counts, as if
  347. * we use the auto allocation it will allocate just for 1 cpu,
  348. * as we start by cpu 0.
  349. */
  350. if (perf_evsel__alloc_counts(evsel, cpus->nr) < 0) {
  351. pr_debug("perf_evsel__alloc_counts(ncpus=%d)\n", cpus->nr);
  352. goto out_close_fd;
  353. }
  354. err = 0;
  355. for (cpu = 0; cpu < cpus->nr; ++cpu) {
  356. unsigned int expected;
  357. if (cpus->map[cpu] >= CPU_SETSIZE)
  358. continue;
  359. if (perf_evsel__read_on_cpu(evsel, cpu, 0) < 0) {
  360. pr_debug("perf_evsel__read_on_cpu\n");
  361. err = -1;
  362. break;
  363. }
  364. expected = nr_open_calls + cpu;
  365. if (evsel->counts->cpu[cpu].val != expected) {
  366. pr_debug("perf_evsel__read_on_cpu: expected to intercept %d calls on cpu %d, got %" PRIu64 "\n",
  367. expected, cpus->map[cpu], evsel->counts->cpu[cpu].val);
  368. err = -1;
  369. }
  370. }
  371. out_close_fd:
  372. perf_evsel__close_fd(evsel, 1, threads->nr);
  373. out_evsel_delete:
  374. perf_evsel__delete(evsel);
  375. out_thread_map_delete:
  376. thread_map__delete(threads);
  377. return err;
  378. }
  379. /*
  380. * This test will generate random numbers of calls to some getpid syscalls,
  381. * then establish an mmap for a group of events that are created to monitor
  382. * the syscalls.
  383. *
  384. * It will receive the events, using mmap, use its PERF_SAMPLE_ID generated
  385. * sample.id field to map back to its respective perf_evsel instance.
  386. *
  387. * Then it checks if the number of syscalls reported as perf events by
  388. * the kernel corresponds to the number of syscalls made.
  389. */
  390. static int test__basic_mmap(void)
  391. {
  392. int err = -1;
  393. union perf_event *event;
  394. struct thread_map *threads;
  395. struct cpu_map *cpus;
  396. struct perf_evlist *evlist;
  397. struct perf_event_attr attr = {
  398. .type = PERF_TYPE_TRACEPOINT,
  399. .read_format = PERF_FORMAT_ID,
  400. .sample_type = PERF_SAMPLE_ID,
  401. .watermark = 0,
  402. };
  403. cpu_set_t cpu_set;
  404. const char *syscall_names[] = { "getsid", "getppid", "getpgrp",
  405. "getpgid", };
  406. pid_t (*syscalls[])(void) = { (void *)getsid, getppid, getpgrp,
  407. (void*)getpgid };
  408. #define nsyscalls ARRAY_SIZE(syscall_names)
  409. int ids[nsyscalls];
  410. unsigned int nr_events[nsyscalls],
  411. expected_nr_events[nsyscalls], i, j;
  412. struct perf_evsel *evsels[nsyscalls], *evsel;
  413. int sample_size = __perf_evsel__sample_size(attr.sample_type);
  414. for (i = 0; i < nsyscalls; ++i) {
  415. char name[64];
  416. snprintf(name, sizeof(name), "sys_enter_%s", syscall_names[i]);
  417. ids[i] = trace_event__id(name);
  418. if (ids[i] < 0) {
  419. pr_debug("Is debugfs mounted on /sys/kernel/debug?\n");
  420. return -1;
  421. }
  422. nr_events[i] = 0;
  423. expected_nr_events[i] = random() % 257;
  424. }
  425. threads = thread_map__new(-1, getpid());
  426. if (threads == NULL) {
  427. pr_debug("thread_map__new\n");
  428. return -1;
  429. }
  430. cpus = cpu_map__new(NULL);
  431. if (cpus == NULL) {
  432. pr_debug("cpu_map__new\n");
  433. goto out_free_threads;
  434. }
  435. CPU_ZERO(&cpu_set);
  436. CPU_SET(cpus->map[0], &cpu_set);
  437. sched_setaffinity(0, sizeof(cpu_set), &cpu_set);
  438. if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) {
  439. pr_debug("sched_setaffinity() failed on CPU %d: %s ",
  440. cpus->map[0], strerror(errno));
  441. goto out_free_cpus;
  442. }
  443. evlist = perf_evlist__new(cpus, threads);
  444. if (evlist == NULL) {
  445. pr_debug("perf_evlist__new\n");
  446. goto out_free_cpus;
  447. }
  448. /* anonymous union fields, can't be initialized above */
  449. attr.wakeup_events = 1;
  450. attr.sample_period = 1;
  451. for (i = 0; i < nsyscalls; ++i) {
  452. attr.config = ids[i];
  453. evsels[i] = perf_evsel__new(&attr, i);
  454. if (evsels[i] == NULL) {
  455. pr_debug("perf_evsel__new\n");
  456. goto out_free_evlist;
  457. }
  458. perf_evlist__add(evlist, evsels[i]);
  459. if (perf_evsel__open(evsels[i], cpus, threads, false, NULL) < 0) {
  460. pr_debug("failed to open counter: %s, "
  461. "tweak /proc/sys/kernel/perf_event_paranoid?\n",
  462. strerror(errno));
  463. goto out_close_fd;
  464. }
  465. }
  466. if (perf_evlist__mmap(evlist, 128, true) < 0) {
  467. pr_debug("failed to mmap events: %d (%s)\n", errno,
  468. strerror(errno));
  469. goto out_close_fd;
  470. }
  471. for (i = 0; i < nsyscalls; ++i)
  472. for (j = 0; j < expected_nr_events[i]; ++j) {
  473. int foo = syscalls[i]();
  474. ++foo;
  475. }
  476. while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) {
  477. struct perf_sample sample;
  478. if (event->header.type != PERF_RECORD_SAMPLE) {
  479. pr_debug("unexpected %s event\n",
  480. perf_event__name(event->header.type));
  481. goto out_munmap;
  482. }
  483. err = perf_event__parse_sample(event, attr.sample_type, sample_size,
  484. false, &sample, false);
  485. if (err) {
  486. pr_err("Can't parse sample, err = %d\n", err);
  487. goto out_munmap;
  488. }
  489. evsel = perf_evlist__id2evsel(evlist, sample.id);
  490. if (evsel == NULL) {
  491. pr_debug("event with id %" PRIu64
  492. " doesn't map to an evsel\n", sample.id);
  493. goto out_munmap;
  494. }
  495. nr_events[evsel->idx]++;
  496. }
  497. list_for_each_entry(evsel, &evlist->entries, node) {
  498. if (nr_events[evsel->idx] != expected_nr_events[evsel->idx]) {
  499. pr_debug("expected %d %s events, got %d\n",
  500. expected_nr_events[evsel->idx],
  501. event_name(evsel), nr_events[evsel->idx]);
  502. goto out_munmap;
  503. }
  504. }
  505. err = 0;
  506. out_munmap:
  507. perf_evlist__munmap(evlist);
  508. out_close_fd:
  509. for (i = 0; i < nsyscalls; ++i)
  510. perf_evsel__close_fd(evsels[i], 1, threads->nr);
  511. out_free_evlist:
  512. perf_evlist__delete(evlist);
  513. out_free_cpus:
  514. cpu_map__delete(cpus);
  515. out_free_threads:
  516. thread_map__delete(threads);
  517. return err;
  518. #undef nsyscalls
  519. }
  520. #define TEST_ASSERT_VAL(text, cond) \
  521. do { \
  522. if (!cond) { \
  523. pr_debug("FAILED %s:%d %s\n", __FILE__, __LINE__, text); \
  524. return -1; \
  525. } \
  526. } while (0)
  527. static int test__checkevent_tracepoint(struct perf_evlist *evlist)
  528. {
  529. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  530. struct perf_evsel, node);
  531. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  532. TEST_ASSERT_VAL("wrong type", PERF_TYPE_TRACEPOINT == evsel->attr.type);
  533. TEST_ASSERT_VAL("wrong sample_type",
  534. (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU) ==
  535. evsel->attr.sample_type);
  536. TEST_ASSERT_VAL("wrong sample_period", 1 == evsel->attr.sample_period);
  537. return 0;
  538. }
  539. static int test__checkevent_tracepoint_multi(struct perf_evlist *evlist)
  540. {
  541. struct perf_evsel *evsel;
  542. TEST_ASSERT_VAL("wrong number of entries", evlist->nr_entries > 1);
  543. list_for_each_entry(evsel, &evlist->entries, node) {
  544. TEST_ASSERT_VAL("wrong type",
  545. PERF_TYPE_TRACEPOINT == evsel->attr.type);
  546. TEST_ASSERT_VAL("wrong sample_type",
  547. (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME | PERF_SAMPLE_CPU)
  548. == evsel->attr.sample_type);
  549. TEST_ASSERT_VAL("wrong sample_period",
  550. 1 == evsel->attr.sample_period);
  551. }
  552. return 0;
  553. }
  554. static int test__checkevent_raw(struct perf_evlist *evlist)
  555. {
  556. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  557. struct perf_evsel, node);
  558. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  559. TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
  560. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  561. return 0;
  562. }
  563. static int test__checkevent_numeric(struct perf_evlist *evlist)
  564. {
  565. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  566. struct perf_evsel, node);
  567. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  568. TEST_ASSERT_VAL("wrong type", 1 == evsel->attr.type);
  569. TEST_ASSERT_VAL("wrong config", 1 == evsel->attr.config);
  570. return 0;
  571. }
  572. static int test__checkevent_symbolic_name(struct perf_evlist *evlist)
  573. {
  574. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  575. struct perf_evsel, node);
  576. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  577. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HARDWARE == evsel->attr.type);
  578. TEST_ASSERT_VAL("wrong config",
  579. PERF_COUNT_HW_INSTRUCTIONS == evsel->attr.config);
  580. return 0;
  581. }
  582. static int test__checkevent_symbolic_alias(struct perf_evlist *evlist)
  583. {
  584. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  585. struct perf_evsel, node);
  586. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  587. TEST_ASSERT_VAL("wrong type", PERF_TYPE_SOFTWARE == evsel->attr.type);
  588. TEST_ASSERT_VAL("wrong config",
  589. PERF_COUNT_SW_PAGE_FAULTS == evsel->attr.config);
  590. return 0;
  591. }
  592. static int test__checkevent_genhw(struct perf_evlist *evlist)
  593. {
  594. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  595. struct perf_evsel, node);
  596. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  597. TEST_ASSERT_VAL("wrong type", PERF_TYPE_HW_CACHE == evsel->attr.type);
  598. TEST_ASSERT_VAL("wrong config", (1 << 16) == evsel->attr.config);
  599. return 0;
  600. }
  601. static int test__checkevent_breakpoint(struct perf_evlist *evlist)
  602. {
  603. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  604. struct perf_evsel, node);
  605. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  606. TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
  607. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  608. TEST_ASSERT_VAL("wrong bp_type", (HW_BREAKPOINT_R | HW_BREAKPOINT_W) ==
  609. evsel->attr.bp_type);
  610. TEST_ASSERT_VAL("wrong bp_len", HW_BREAKPOINT_LEN_4 ==
  611. evsel->attr.bp_len);
  612. return 0;
  613. }
  614. static int test__checkevent_breakpoint_x(struct perf_evlist *evlist)
  615. {
  616. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  617. struct perf_evsel, node);
  618. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  619. TEST_ASSERT_VAL("wrong type", PERF_TYPE_BREAKPOINT == evsel->attr.type);
  620. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  621. TEST_ASSERT_VAL("wrong bp_type",
  622. HW_BREAKPOINT_X == evsel->attr.bp_type);
  623. TEST_ASSERT_VAL("wrong bp_len", sizeof(long) == evsel->attr.bp_len);
  624. return 0;
  625. }
  626. static int test__checkevent_breakpoint_r(struct perf_evlist *evlist)
  627. {
  628. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  629. struct perf_evsel, node);
  630. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  631. TEST_ASSERT_VAL("wrong type",
  632. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  633. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  634. TEST_ASSERT_VAL("wrong bp_type",
  635. HW_BREAKPOINT_R == evsel->attr.bp_type);
  636. TEST_ASSERT_VAL("wrong bp_len",
  637. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  638. return 0;
  639. }
  640. static int test__checkevent_breakpoint_w(struct perf_evlist *evlist)
  641. {
  642. struct perf_evsel *evsel = list_entry(evlist->entries.next,
  643. struct perf_evsel, node);
  644. TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
  645. TEST_ASSERT_VAL("wrong type",
  646. PERF_TYPE_BREAKPOINT == evsel->attr.type);
  647. TEST_ASSERT_VAL("wrong config", 0 == evsel->attr.config);
  648. TEST_ASSERT_VAL("wrong bp_type",
  649. HW_BREAKPOINT_W == evsel->attr.bp_type);
  650. TEST_ASSERT_VAL("wrong bp_len",
  651. HW_BREAKPOINT_LEN_4 == evsel->attr.bp_len);
  652. return 0;
  653. }
  654. static struct test__event_st {
  655. const char *name;
  656. __u32 type;
  657. int (*check)(struct perf_evlist *evlist);
  658. } test__events[] = {
  659. {
  660. .name = "syscalls:sys_enter_open",
  661. .check = test__checkevent_tracepoint,
  662. },
  663. {
  664. .name = "syscalls:*",
  665. .check = test__checkevent_tracepoint_multi,
  666. },
  667. {
  668. .name = "r1",
  669. .check = test__checkevent_raw,
  670. },
  671. {
  672. .name = "1:1",
  673. .check = test__checkevent_numeric,
  674. },
  675. {
  676. .name = "instructions",
  677. .check = test__checkevent_symbolic_name,
  678. },
  679. {
  680. .name = "faults",
  681. .check = test__checkevent_symbolic_alias,
  682. },
  683. {
  684. .name = "L1-dcache-load-miss",
  685. .check = test__checkevent_genhw,
  686. },
  687. {
  688. .name = "mem:0",
  689. .check = test__checkevent_breakpoint,
  690. },
  691. {
  692. .name = "mem:0:x",
  693. .check = test__checkevent_breakpoint_x,
  694. },
  695. {
  696. .name = "mem:0:r",
  697. .check = test__checkevent_breakpoint_r,
  698. },
  699. {
  700. .name = "mem:0:w",
  701. .check = test__checkevent_breakpoint_w,
  702. },
  703. };
  704. #define TEST__EVENTS_CNT (sizeof(test__events) / sizeof(struct test__event_st))
  705. static int test__parse_events(void)
  706. {
  707. struct perf_evlist *evlist;
  708. u_int i;
  709. int ret = 0;
  710. for (i = 0; i < TEST__EVENTS_CNT; i++) {
  711. struct test__event_st *e = &test__events[i];
  712. evlist = perf_evlist__new(NULL, NULL);
  713. if (evlist == NULL)
  714. break;
  715. ret = parse_events(evlist, e->name, 0);
  716. if (ret) {
  717. pr_debug("failed to parse event '%s', err %d\n",
  718. e->name, ret);
  719. break;
  720. }
  721. ret = e->check(evlist);
  722. if (ret)
  723. break;
  724. perf_evlist__delete(evlist);
  725. }
  726. return ret;
  727. }
  728. static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t **maskp,
  729. size_t *sizep)
  730. {
  731. cpu_set_t *mask;
  732. size_t size;
  733. int i, cpu = -1, nrcpus = 1024;
  734. realloc:
  735. mask = CPU_ALLOC(nrcpus);
  736. size = CPU_ALLOC_SIZE(nrcpus);
  737. CPU_ZERO_S(size, mask);
  738. if (sched_getaffinity(pid, size, mask) == -1) {
  739. CPU_FREE(mask);
  740. if (errno == EINVAL && nrcpus < (1024 << 8)) {
  741. nrcpus = nrcpus << 2;
  742. goto realloc;
  743. }
  744. perror("sched_getaffinity");
  745. return -1;
  746. }
  747. for (i = 0; i < nrcpus; i++) {
  748. if (CPU_ISSET_S(i, size, mask)) {
  749. if (cpu == -1) {
  750. cpu = i;
  751. *maskp = mask;
  752. *sizep = size;
  753. } else
  754. CPU_CLR_S(i, size, mask);
  755. }
  756. }
  757. if (cpu == -1)
  758. CPU_FREE(mask);
  759. return cpu;
  760. }
  761. static int test__PERF_RECORD(void)
  762. {
  763. struct perf_record_opts opts = {
  764. .target_pid = -1,
  765. .target_tid = -1,
  766. .no_delay = true,
  767. .freq = 10,
  768. .mmap_pages = 256,
  769. .sample_id_all_avail = true,
  770. };
  771. cpu_set_t *cpu_mask = NULL;
  772. size_t cpu_mask_size = 0;
  773. struct perf_evlist *evlist = perf_evlist__new(NULL, NULL);
  774. struct perf_evsel *evsel;
  775. struct perf_sample sample;
  776. const char *cmd = "sleep";
  777. const char *argv[] = { cmd, "1", NULL, };
  778. char *bname;
  779. u64 sample_type, prev_time = 0;
  780. bool found_cmd_mmap = false,
  781. found_libc_mmap = false,
  782. found_vdso_mmap = false,
  783. found_ld_mmap = false;
  784. int err = -1, errs = 0, i, wakeups = 0, sample_size;
  785. u32 cpu;
  786. int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, };
  787. if (evlist == NULL || argv == NULL) {
  788. pr_debug("Not enough memory to create evlist\n");
  789. goto out;
  790. }
  791. /*
  792. * We need at least one evsel in the evlist, use the default
  793. * one: "cycles".
  794. */
  795. err = perf_evlist__add_default(evlist);
  796. if (err < 0) {
  797. pr_debug("Not enough memory to create evsel\n");
  798. goto out_delete_evlist;
  799. }
  800. /*
  801. * Create maps of threads and cpus to monitor. In this case
  802. * we start with all threads and cpus (-1, -1) but then in
  803. * perf_evlist__prepare_workload we'll fill in the only thread
  804. * we're monitoring, the one forked there.
  805. */
  806. err = perf_evlist__create_maps(evlist, opts.target_pid,
  807. opts.target_tid, opts.cpu_list);
  808. if (err < 0) {
  809. pr_debug("Not enough memory to create thread/cpu maps\n");
  810. goto out_delete_evlist;
  811. }
  812. /*
  813. * Prepare the workload in argv[] to run, it'll fork it, and then wait
  814. * for perf_evlist__start_workload() to exec it. This is done this way
  815. * so that we have time to open the evlist (calling sys_perf_event_open
  816. * on all the fds) and then mmap them.
  817. */
  818. err = perf_evlist__prepare_workload(evlist, &opts, argv);
  819. if (err < 0) {
  820. pr_debug("Couldn't run the workload!\n");
  821. goto out_delete_evlist;
  822. }
  823. /*
  824. * Config the evsels, setting attr->comm on the first one, etc.
  825. */
  826. evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
  827. evsel->attr.sample_type |= PERF_SAMPLE_CPU;
  828. evsel->attr.sample_type |= PERF_SAMPLE_TID;
  829. evsel->attr.sample_type |= PERF_SAMPLE_TIME;
  830. perf_evlist__config_attrs(evlist, &opts);
  831. err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask,
  832. &cpu_mask_size);
  833. if (err < 0) {
  834. pr_debug("sched__get_first_possible_cpu: %s\n", strerror(errno));
  835. goto out_delete_evlist;
  836. }
  837. cpu = err;
  838. /*
  839. * So that we can check perf_sample.cpu on all the samples.
  840. */
  841. if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, cpu_mask) < 0) {
  842. pr_debug("sched_setaffinity: %s\n", strerror(errno));
  843. goto out_free_cpu_mask;
  844. }
  845. /*
  846. * Call sys_perf_event_open on all the fds on all the evsels,
  847. * grouping them if asked to.
  848. */
  849. err = perf_evlist__open(evlist, opts.group);
  850. if (err < 0) {
  851. pr_debug("perf_evlist__open: %s\n", strerror(errno));
  852. goto out_delete_evlist;
  853. }
  854. /*
  855. * mmap the first fd on a given CPU and ask for events for the other
  856. * fds in the same CPU to be injected in the same mmap ring buffer
  857. * (using ioctl(PERF_EVENT_IOC_SET_OUTPUT)).
  858. */
  859. err = perf_evlist__mmap(evlist, opts.mmap_pages, false);
  860. if (err < 0) {
  861. pr_debug("perf_evlist__mmap: %s\n", strerror(errno));
  862. goto out_delete_evlist;
  863. }
  864. /*
  865. * We'll need these two to parse the PERF_SAMPLE_* fields in each
  866. * event.
  867. */
  868. sample_type = perf_evlist__sample_type(evlist);
  869. sample_size = __perf_evsel__sample_size(sample_type);
  870. /*
  871. * Now that all is properly set up, enable the events, they will
  872. * count just on workload.pid, which will start...
  873. */
  874. perf_evlist__enable(evlist);
  875. /*
  876. * Now!
  877. */
  878. perf_evlist__start_workload(evlist);
  879. while (1) {
  880. int before = total_events;
  881. for (i = 0; i < evlist->nr_mmaps; i++) {
  882. union perf_event *event;
  883. while ((event = perf_evlist__mmap_read(evlist, i)) != NULL) {
  884. const u32 type = event->header.type;
  885. const char *name = perf_event__name(type);
  886. ++total_events;
  887. if (type < PERF_RECORD_MAX)
  888. nr_events[type]++;
  889. err = perf_event__parse_sample(event, sample_type,
  890. sample_size, true,
  891. &sample, false);
  892. if (err < 0) {
  893. if (verbose)
  894. perf_event__fprintf(event, stderr);
  895. pr_debug("Couldn't parse sample\n");
  896. goto out_err;
  897. }
  898. if (verbose) {
  899. pr_info("%" PRIu64" %d ", sample.time, sample.cpu);
  900. perf_event__fprintf(event, stderr);
  901. }
  902. if (prev_time > sample.time) {
  903. pr_debug("%s going backwards in time, prev=%" PRIu64 ", curr=%" PRIu64 "\n",
  904. name, prev_time, sample.time);
  905. ++errs;
  906. }
  907. prev_time = sample.time;
  908. if (sample.cpu != cpu) {
  909. pr_debug("%s with unexpected cpu, expected %d, got %d\n",
  910. name, cpu, sample.cpu);
  911. ++errs;
  912. }
  913. if ((pid_t)sample.pid != evlist->workload.pid) {
  914. pr_debug("%s with unexpected pid, expected %d, got %d\n",
  915. name, evlist->workload.pid, sample.pid);
  916. ++errs;
  917. }
  918. if ((pid_t)sample.tid != evlist->workload.pid) {
  919. pr_debug("%s with unexpected tid, expected %d, got %d\n",
  920. name, evlist->workload.pid, sample.tid);
  921. ++errs;
  922. }
  923. if ((type == PERF_RECORD_COMM ||
  924. type == PERF_RECORD_MMAP ||
  925. type == PERF_RECORD_FORK ||
  926. type == PERF_RECORD_EXIT) &&
  927. (pid_t)event->comm.pid != evlist->workload.pid) {
  928. pr_debug("%s with unexpected pid/tid\n", name);
  929. ++errs;
  930. }
  931. if ((type == PERF_RECORD_COMM ||
  932. type == PERF_RECORD_MMAP) &&
  933. event->comm.pid != event->comm.tid) {
  934. pr_debug("%s with different pid/tid!\n", name);
  935. ++errs;
  936. }
  937. switch (type) {
  938. case PERF_RECORD_COMM:
  939. if (strcmp(event->comm.comm, cmd)) {
  940. pr_debug("%s with unexpected comm!\n", name);
  941. ++errs;
  942. }
  943. break;
  944. case PERF_RECORD_EXIT:
  945. goto found_exit;
  946. case PERF_RECORD_MMAP:
  947. bname = strrchr(event->mmap.filename, '/');
  948. if (bname != NULL) {
  949. if (!found_cmd_mmap)
  950. found_cmd_mmap = !strcmp(bname + 1, cmd);
  951. if (!found_libc_mmap)
  952. found_libc_mmap = !strncmp(bname + 1, "libc", 4);
  953. if (!found_ld_mmap)
  954. found_ld_mmap = !strncmp(bname + 1, "ld", 2);
  955. } else if (!found_vdso_mmap)
  956. found_vdso_mmap = !strcmp(event->mmap.filename, "[vdso]");
  957. break;
  958. case PERF_RECORD_SAMPLE:
  959. /* Just ignore samples for now */
  960. break;
  961. default:
  962. pr_debug("Unexpected perf_event->header.type %d!\n",
  963. type);
  964. ++errs;
  965. }
  966. }
  967. }
  968. /*
  969. * We don't use poll here because at least at 3.1 times the
  970. * PERF_RECORD_{!SAMPLE} events don't honour
  971. * perf_event_attr.wakeup_events, just PERF_EVENT_SAMPLE does.
  972. */
  973. if (total_events == before && false)
  974. poll(evlist->pollfd, evlist->nr_fds, -1);
  975. sleep(1);
  976. if (++wakeups > 5) {
  977. pr_debug("No PERF_RECORD_EXIT event!\n");
  978. break;
  979. }
  980. }
  981. found_exit:
  982. if (nr_events[PERF_RECORD_COMM] > 1) {
  983. pr_debug("Excessive number of PERF_RECORD_COMM events!\n");
  984. ++errs;
  985. }
  986. if (nr_events[PERF_RECORD_COMM] == 0) {
  987. pr_debug("Missing PERF_RECORD_COMM for %s!\n", cmd);
  988. ++errs;
  989. }
  990. if (!found_cmd_mmap) {
  991. pr_debug("PERF_RECORD_MMAP for %s missing!\n", cmd);
  992. ++errs;
  993. }
  994. if (!found_libc_mmap) {
  995. pr_debug("PERF_RECORD_MMAP for %s missing!\n", "libc");
  996. ++errs;
  997. }
  998. if (!found_ld_mmap) {
  999. pr_debug("PERF_RECORD_MMAP for %s missing!\n", "ld");
  1000. ++errs;
  1001. }
  1002. if (!found_vdso_mmap) {
  1003. pr_debug("PERF_RECORD_MMAP for %s missing!\n", "[vdso]");
  1004. ++errs;
  1005. }
  1006. out_err:
  1007. perf_evlist__munmap(evlist);
  1008. out_free_cpu_mask:
  1009. CPU_FREE(cpu_mask);
  1010. out_delete_evlist:
  1011. perf_evlist__delete(evlist);
  1012. out:
  1013. return (err < 0 || errs > 0) ? -1 : 0;
  1014. }
  1015. static struct test {
  1016. const char *desc;
  1017. int (*func)(void);
  1018. } tests[] = {
  1019. {
  1020. .desc = "vmlinux symtab matches kallsyms",
  1021. .func = test__vmlinux_matches_kallsyms,
  1022. },
  1023. {
  1024. .desc = "detect open syscall event",
  1025. .func = test__open_syscall_event,
  1026. },
  1027. {
  1028. .desc = "detect open syscall event on all cpus",
  1029. .func = test__open_syscall_event_on_all_cpus,
  1030. },
  1031. {
  1032. .desc = "read samples using the mmap interface",
  1033. .func = test__basic_mmap,
  1034. },
  1035. {
  1036. .desc = "parse events tests",
  1037. .func = test__parse_events,
  1038. },
  1039. {
  1040. .desc = "Validate PERF_RECORD_* events & perf_sample fields",
  1041. .func = test__PERF_RECORD,
  1042. },
  1043. {
  1044. .func = NULL,
  1045. },
  1046. };
  1047. static bool perf_test__matches(int curr, int argc, const char *argv[])
  1048. {
  1049. int i;
  1050. if (argc == 0)
  1051. return true;
  1052. for (i = 0; i < argc; ++i) {
  1053. char *end;
  1054. long nr = strtoul(argv[i], &end, 10);
  1055. if (*end == '\0') {
  1056. if (nr == curr + 1)
  1057. return true;
  1058. continue;
  1059. }
  1060. if (strstr(tests[curr].desc, argv[i]))
  1061. return true;
  1062. }
  1063. return false;
  1064. }
  1065. static int __cmd_test(int argc, const char *argv[])
  1066. {
  1067. int i = 0;
  1068. while (tests[i].func) {
  1069. int curr = i++, err;
  1070. if (!perf_test__matches(curr, argc, argv))
  1071. continue;
  1072. pr_info("%2d: %s:", i, tests[curr].desc);
  1073. pr_debug("\n--- start ---\n");
  1074. err = tests[curr].func();
  1075. pr_debug("---- end ----\n%s:", tests[curr].desc);
  1076. pr_info(" %s\n", err ? "FAILED!\n" : "Ok");
  1077. }
  1078. return 0;
  1079. }
  1080. static int perf_test__list(int argc, const char **argv)
  1081. {
  1082. int i = 0;
  1083. while (tests[i].func) {
  1084. int curr = i++;
  1085. if (argc > 1 && !strstr(tests[curr].desc, argv[1]))
  1086. continue;
  1087. pr_info("%2d: %s\n", i, tests[curr].desc);
  1088. }
  1089. return 0;
  1090. }
  1091. int cmd_test(int argc, const char **argv, const char *prefix __used)
  1092. {
  1093. const char * const test_usage[] = {
  1094. "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
  1095. NULL,
  1096. };
  1097. const struct option test_options[] = {
  1098. OPT_INTEGER('v', "verbose", &verbose,
  1099. "be more verbose (show symbol address, etc)"),
  1100. OPT_END()
  1101. };
  1102. argc = parse_options(argc, argv, test_options, test_usage, 0);
  1103. if (argc >= 1 && !strcmp(argv[0], "list"))
  1104. return perf_test__list(argc, argv);
  1105. symbol_conf.priv_size = sizeof(int);
  1106. symbol_conf.sort_by_name = true;
  1107. symbol_conf.try_vmlinux_path = true;
  1108. if (symbol__init() < 0)
  1109. return -1;
  1110. setup_pager();
  1111. return __cmd_test(argc, argv);
  1112. }