hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/tools/perf/tests/builtin-test.c
....@@ -8,6 +8,7 @@
88 #include <errno.h>
99 #include <unistd.h>
1010 #include <string.h>
11
+#include <stdlib.h>
1112 #include <sys/types.h>
1213 #include <dirent.h>
1314 #include <sys/wait.h>
....@@ -21,7 +22,9 @@
2122 #include <subcmd/parse-options.h>
2223 #include "string2.h"
2324 #include "symbol.h"
25
+#include "util/rlimit.h"
2426 #include <linux/kernel.h>
27
+#include <linux/string.h>
2528 #include <subcmd/exec-cmd.h>
2629
2730 static bool dont_fork;
....@@ -68,6 +71,17 @@
6871 {
6972 .desc = "Parse perf pmu format",
7073 .func = test__pmu,
74
+ },
75
+ {
76
+ .desc = "PMU events",
77
+ .func = test__pmu_events,
78
+ .subtest = {
79
+ .skip_if_fail = false,
80
+ .get_nr = test__pmu_events_subtest_get_nr,
81
+ .get_desc = test__pmu_events_subtest_get_desc,
82
+ .skip_reason = test__pmu_events_subtest_skip_reason,
83
+ },
84
+
7185 },
7286 {
7387 .desc = "DSO data read",
....@@ -118,7 +132,17 @@
118132 {
119133 .desc = "Breakpoint accounting",
120134 .func = test__bp_accounting,
121
- .is_supported = test__bp_signal_is_supported,
135
+ .is_supported = test__bp_account_is_supported,
136
+ },
137
+ {
138
+ .desc = "Watchpoint",
139
+ .func = test__wp,
140
+ .is_supported = test__wp_is_supported,
141
+ .subtest = {
142
+ .skip_if_fail = false,
143
+ .get_nr = test__wp_subtest_get_nr,
144
+ .get_desc = test__wp_subtest_get_desc,
145
+ },
122146 },
123147 {
124148 .desc = "Number of exit events of a simple workload",
....@@ -153,8 +177,8 @@
153177 .func = test__mmap_thread_lookup,
154178 },
155179 {
156
- .desc = "Share thread mg",
157
- .func = test__thread_mg_share,
180
+ .desc = "Share thread maps",
181
+ .func = test__thread_maps_share,
158182 },
159183 {
160184 .desc = "Sort output of hist entries",
....@@ -247,6 +271,11 @@
247271 .func = test__cpu_map_print,
248272 },
249273 {
274
+ .desc = "Merge cpu map",
275
+ .func = test__cpu_map_merge,
276
+ },
277
+
278
+ {
250279 .desc = "Probe SDT events",
251280 .func = test__sdt_event,
252281 },
....@@ -280,6 +309,47 @@
280309 .func = test__mem2node,
281310 },
282311 {
312
+ .desc = "time utils",
313
+ .func = test__time_utils,
314
+ },
315
+ {
316
+ .desc = "Test jit_write_elf",
317
+ .func = test__jit_write_elf,
318
+ },
319
+ {
320
+ .desc = "Test libpfm4 support",
321
+ .func = test__pfm,
322
+ .subtest = {
323
+ .skip_if_fail = true,
324
+ .get_nr = test__pfm_subtest_get_nr,
325
+ .get_desc = test__pfm_subtest_get_desc,
326
+ }
327
+ },
328
+ {
329
+ .desc = "Test api io",
330
+ .func = test__api_io,
331
+ },
332
+ {
333
+ .desc = "maps__merge_in",
334
+ .func = test__maps__merge_in,
335
+ },
336
+ {
337
+ .desc = "Demangle Java",
338
+ .func = test__demangle_java,
339
+ },
340
+ {
341
+ .desc = "Parse and process metrics",
342
+ .func = test__parse_metric,
343
+ },
344
+ {
345
+ .desc = "PE file support",
346
+ .func = test__pe_file_parsing,
347
+ },
348
+ {
349
+ .desc = "Event expansion for cgroups",
350
+ .func = test__expand_cgroup_events,
351
+ },
352
+ {
283353 .func = NULL,
284354 },
285355 };
....@@ -289,7 +359,7 @@
289359 arch_tests,
290360 };
291361
292
-static bool perf_test__matches(struct test *test, int curr, int argc, const char *argv[])
362
+static bool perf_test__matches(const char *desc, int curr, int argc, const char *argv[])
293363 {
294364 int i;
295365
....@@ -306,7 +376,7 @@
306376 continue;
307377 }
308378
309
- if (strcasestr(test->desc, argv[i]))
379
+ if (strcasestr(desc, argv[i]))
310380 return true;
311381 }
312382
....@@ -391,8 +461,15 @@
391461 case TEST_OK:
392462 pr_info(" Ok\n");
393463 break;
394
- case TEST_SKIP:
395
- color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
464
+ case TEST_SKIP: {
465
+ const char *skip_reason = NULL;
466
+ if (t->subtest.skip_reason)
467
+ skip_reason = t->subtest.skip_reason(subtest);
468
+ if (skip_reason)
469
+ color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (%s)\n", skip_reason);
470
+ else
471
+ color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
472
+ }
396473 break;
397474 case TEST_FAIL:
398475 default:
....@@ -414,10 +491,13 @@
414491 if (!fp)
415492 return NULL;
416493
494
+ /* Skip shebang */
495
+ while (fgetc(fp) != '\n');
496
+
417497 description = fgets(description, size, fp);
418498 fclose(fp);
419499
420
- return description ? trim(description + 1) : NULL;
500
+ return description ? strim(description + 1) : NULL;
421501 }
422502
423503 #define for_each_shell_test(dir, base, ent) \
....@@ -510,8 +590,11 @@
510590 return -1;
511591
512592 dir = opendir(st.dir);
513
- if (!dir)
593
+ if (!dir) {
594
+ pr_err("failed to open shell test directory: %s\n",
595
+ st.dir);
514596 return -1;
597
+ }
515598
516599 for_each_shell_test(dir, st.dir, ent) {
517600 int curr = i++;
....@@ -522,7 +605,7 @@
522605 .priv = &st,
523606 };
524607
525
- if (!perf_test__matches(&test, curr, argc, argv))
608
+ if (!perf_test__matches(test.desc, curr, argc, argv))
526609 continue;
527610
528611 st.file = ent->d_name;
....@@ -550,9 +633,25 @@
550633
551634 for_each_test(j, t) {
552635 int curr = i++, err;
636
+ int subi;
553637
554
- if (!perf_test__matches(t, curr, argc, argv))
555
- continue;
638
+ if (!perf_test__matches(t->desc, curr, argc, argv)) {
639
+ bool skip = true;
640
+ int subn;
641
+
642
+ if (!t->subtest.get_nr)
643
+ continue;
644
+
645
+ subn = t->subtest.get_nr();
646
+
647
+ for (subi = 0; subi < subn; subi++) {
648
+ if (perf_test__matches(t->subtest.get_desc(subi), curr, argc, argv))
649
+ skip = false;
650
+ }
651
+
652
+ if (skip)
653
+ continue;
654
+ }
556655
557656 if (t->is_supported && !t->is_supported()) {
558657 pr_debug("%2d: %-*s: Disabled\n", i, width, t->desc);
....@@ -580,7 +679,6 @@
580679 */
581680 int subw = width > 2 ? width - 2 : width;
582681 bool skip = false;
583
- int subi;
584682
585683 if (subn <= 0) {
586684 color_fprintf(stderr, PERF_COLOR_YELLOW,
....@@ -597,6 +695,9 @@
597695 }
598696
599697 for (subi = 0; subi < subn; subi++) {
698
+ if (!perf_test__matches(t->subtest.get_desc(subi), curr, argc, argv))
699
+ continue;
700
+
600701 pr_info("%2d.%1d: %-*s:", i, subi + 1, subw,
601702 t->subtest.get_desc(subi));
602703 err = test_and_print(t, skip, subi);
....@@ -630,7 +731,7 @@
630731 .desc = shell_test__description(bf, sizeof(bf), path, ent->d_name),
631732 };
632733
633
- if (!perf_test__matches(&t, curr, argc, argv))
734
+ if (!perf_test__matches(t.desc, curr, argc, argv))
634735 continue;
635736
636737 pr_info("%2d: %s\n", i, t.desc);
....@@ -649,7 +750,7 @@
649750 for_each_test(j, t) {
650751 int curr = i++;
651752
652
- if (!perf_test__matches(t, curr, argc, argv) ||
753
+ if (!perf_test__matches(t->desc, curr, argc, argv) ||
653754 (t->is_supported && !t->is_supported()))
654755 continue;
655756
....@@ -705,6 +806,11 @@
705806
706807 if (skip != NULL)
707808 skiplist = intlist__new(skip);
809
+ /*
810
+ * Tests that create BPF maps, for instance, need more than the 64K
811
+ * default:
812
+ */
813
+ rlimit__bump_memlock();
708814
709815 return __cmd_test(argc, argv, skiplist);
710816 }