^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * builtin-test.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Builtin regression testing command: ever growing number of sanity tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <dirent.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <sys/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "builtin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "hist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "intlist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "color.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <subcmd/parse-options.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "string2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "symbol.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "util/rlimit.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <subcmd/exec-cmd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static bool dont_fork;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct test __weak arch_tests[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .func = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static struct test generic_tests[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .desc = "vmlinux symtab matches kallsyms",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .func = test__vmlinux_matches_kallsyms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) .desc = "Detect openat syscall event",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .func = test__openat_syscall_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .desc = "Detect openat syscall event on all cpus",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) .func = test__openat_syscall_event_on_all_cpus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .desc = "Read samples using the mmap interface",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .func = test__basic_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .desc = "Test data source output",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .func = test__mem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .desc = "Parse event definition strings",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .func = test__parse_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .desc = "Simple expression parser",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) .func = test__expr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) .desc = "PERF_RECORD_* events & perf_sample fields",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .func = test__PERF_RECORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) .desc = "Parse perf pmu format",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .func = test__pmu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .desc = "PMU events",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .func = test__pmu_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .subtest = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .skip_if_fail = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .get_nr = test__pmu_events_subtest_get_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .get_desc = test__pmu_events_subtest_get_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .skip_reason = test__pmu_events_subtest_skip_reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .desc = "DSO data read",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .func = test__dso_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .desc = "DSO data cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .func = test__dso_data_cache,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .desc = "DSO data reopen",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .func = test__dso_data_reopen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .desc = "Roundtrip evsel->name",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .func = test__perf_evsel__roundtrip_name_test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .desc = "Parse sched tracepoints fields",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .func = test__perf_evsel__tp_sched_test,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .desc = "syscalls:sys_enter_openat event fields",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .func = test__syscall_openat_tp_fields,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .desc = "Setup struct perf_event_attr",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .func = test__attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .desc = "Match and link multiple hists",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .func = test__hists_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .desc = "'import perf' in python",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .func = test__python_use,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .desc = "Breakpoint overflow signal handler",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .func = test__bp_signal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .is_supported = test__bp_signal_is_supported,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .desc = "Breakpoint overflow sampling",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .func = test__bp_signal_overflow,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .is_supported = test__bp_signal_is_supported,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .desc = "Breakpoint accounting",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) .func = test__bp_accounting,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .is_supported = test__bp_account_is_supported,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .desc = "Watchpoint",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .func = test__wp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .is_supported = test__wp_is_supported,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .subtest = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .skip_if_fail = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .get_nr = test__wp_subtest_get_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .get_desc = test__wp_subtest_get_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .desc = "Number of exit events of a simple workload",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .func = test__task_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .desc = "Software clock events period values",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .func = test__sw_clock_freq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .desc = "Object code reading",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .func = test__code_reading,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .desc = "Sample parsing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .func = test__sample_parsing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) .desc = "Use a dummy software event to keep tracking",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .func = test__keep_tracking,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .desc = "Parse with no sample_id_all bit set",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .func = test__parse_no_sample_id_all,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .desc = "Filter hist entries",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .func = test__hists_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .desc = "Lookup mmap thread",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .func = test__mmap_thread_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) .desc = "Share thread maps",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) .func = test__thread_maps_share,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .desc = "Sort output of hist entries",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .func = test__hists_output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) .desc = "Cumulate child hist entries",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) .func = test__hists_cumulate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) .desc = "Track with sched_switch",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) .func = test__switch_tracking,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .desc = "Filter fds with revents mask in a fdarray",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) .func = test__fdarray__filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) .desc = "Add fd to a fdarray, making it autogrow",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .func = test__fdarray__add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .desc = "kmod_path__parse",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .func = test__kmod_path__parse,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .desc = "Thread map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .func = test__thread_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .desc = "LLVM search and compile",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .func = test__llvm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) .subtest = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) .skip_if_fail = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .get_nr = test__llvm_subtest_get_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .get_desc = test__llvm_subtest_get_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .desc = "Session topology",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) .func = test__session_topology,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .desc = "BPF filter",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .func = test__bpf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) .subtest = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .skip_if_fail = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .get_nr = test__bpf_subtest_get_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) .get_desc = test__bpf_subtest_get_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) .desc = "Synthesize thread map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) .func = test__thread_map_synthesize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .desc = "Remove thread map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .func = test__thread_map_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .desc = "Synthesize cpu map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .func = test__cpu_map_synthesize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) .desc = "Synthesize stat config",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) .func = test__synthesize_stat_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) .desc = "Synthesize stat",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) .func = test__synthesize_stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .desc = "Synthesize stat round",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .func = test__synthesize_stat_round,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) .desc = "Synthesize attr update",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .func = test__event_update,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .desc = "Event times",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .func = test__event_times,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .desc = "Read backward ring buffer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .func = test__backward_ring_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .desc = "Print cpu map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) .func = test__cpu_map_print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) .desc = "Merge cpu map",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .func = test__cpu_map_merge,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .desc = "Probe SDT events",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .func = test__sdt_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) .desc = "is_printable_array",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) .func = test__is_printable_array,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) .desc = "Print bitmap",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) .func = test__bitmap_print,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .desc = "perf hooks",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .func = test__perf_hooks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) .desc = "builtin clang support",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) .func = test__clang,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) .subtest = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) .skip_if_fail = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) .get_nr = test__clang_subtest_get_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) .get_desc = test__clang_subtest_get_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) .desc = "unit_number__scnprintf",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) .func = test__unit_number__scnprint,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) .desc = "mem2node",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) .func = test__mem2node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) .desc = "time utils",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) .func = test__time_utils,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) .desc = "Test jit_write_elf",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) .func = test__jit_write_elf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .desc = "Test libpfm4 support",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) .func = test__pfm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) .subtest = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .skip_if_fail = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .get_nr = test__pfm_subtest_get_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) .get_desc = test__pfm_subtest_get_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .desc = "Test api io",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .func = test__api_io,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .desc = "maps__merge_in",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) .func = test__maps__merge_in,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) .desc = "Demangle Java",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) .func = test__demangle_java,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) .desc = "Parse and process metrics",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) .func = test__parse_metric,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .desc = "PE file support",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .func = test__pe_file_parsing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) .desc = "Event expansion for cgroups",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .func = test__expand_cgroup_events,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) .func = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static struct test *tests[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) generic_tests,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) arch_tests,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static bool perf_test__matches(const char *desc, int curr, int argc, const char *argv[])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (argc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) for (i = 0; i < argc; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) char *end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) long nr = strtoul(argv[i], &end, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (*end == '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (nr == curr + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (strcasestr(desc, argv[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static int run_test(struct test *test, int subtest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) int status, err = -1, child = dont_fork ? 0 : fork();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) char sbuf[STRERR_BUFSIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (child < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) pr_err("failed to fork test: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) str_error_r(errno, sbuf, sizeof(sbuf)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (!child) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (!dont_fork) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) pr_debug("test child forked, pid %d\n", getpid());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (verbose <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int nullfd = open("/dev/null", O_WRONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (nullfd >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) close(STDERR_FILENO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) close(STDOUT_FILENO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) dup2(nullfd, STDOUT_FILENO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) dup2(STDOUT_FILENO, STDERR_FILENO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) close(nullfd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) signal(SIGSEGV, sighandler_dump_stack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) signal(SIGFPE, sighandler_dump_stack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) err = test->func(test, subtest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (!dont_fork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) exit(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (!dont_fork) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) wait(&status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (WIFEXITED(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) err = (signed char)WEXITSTATUS(status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) pr_debug("test child finished with %d\n", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) } else if (WIFSIGNALED(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) err = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) pr_debug("test child interrupted\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) #define for_each_test(j, t) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) for (j = 0; j < ARRAY_SIZE(tests); j++) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) for (t = &tests[j][0]; t->func; t++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) static int test_and_print(struct test *t, bool force_skip, int subtest)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (!force_skip) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) pr_debug("\n--- start ---\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) err = run_test(t, subtest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) pr_debug("---- end ----\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) pr_debug("\n--- force skipped ---\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) err = TEST_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (!t->subtest.get_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) pr_debug("%s:", t->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) pr_debug("%s subtest %d:", t->desc, subtest + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) switch (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) case TEST_OK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) pr_info(" Ok\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) case TEST_SKIP: {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) const char *skip_reason = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (t->subtest.skip_reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) skip_reason = t->subtest.skip_reason(subtest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (skip_reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (%s)\n", skip_reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) case TEST_FAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) color_fprintf(stderr, PERF_COLOR_RED, " FAILED!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static const char *shell_test__description(char *description, size_t size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) const char *path, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) FILE *fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) char filename[PATH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) path__join(filename, sizeof(filename), path, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) fp = fopen(filename, "r");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (!fp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) /* Skip shebang */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) while (fgetc(fp) != '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) description = fgets(description, size, fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) fclose(fp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) return description ? strim(description + 1) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) #define for_each_shell_test(dir, base, ent) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) while ((ent = readdir(dir)) != NULL) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if (!is_directory(base, ent) && ent->d_name[0] != '.')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static const char *shell_tests__dir(char *path, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) const char *devel_dirs[] = { "./tools/perf/tests", "./tests", };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) char *exec_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) for (i = 0; i < ARRAY_SIZE(devel_dirs); ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct stat st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (!lstat(devel_dirs[i], &st)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) scnprintf(path, size, "%s/shell", devel_dirs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (!lstat(devel_dirs[i], &st))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) /* Then installed path. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) exec_path = get_argv_exec_path();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) scnprintf(path, size, "%s/tests/shell", exec_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) free(exec_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) return path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) static int shell_tests__max_desc_width(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) DIR *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) struct dirent *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) char path_dir[PATH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) const char *path = shell_tests__dir(path_dir, sizeof(path_dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) int width = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) if (path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) dir = opendir(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (!dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) for_each_shell_test(dir, path, ent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) char bf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) const char *desc = shell_test__description(bf, sizeof(bf), path, ent->d_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) int len = strlen(desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (width < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) width = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) closedir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) return width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct shell_test {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) const char *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) const char *file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static int shell_test__run(struct test *test, int subdir __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) char script[PATH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) struct shell_test *st = test->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) path__join(script, sizeof(script), st->dir, st->file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) err = system(script);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) return TEST_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return WEXITSTATUS(err) == 2 ? TEST_SKIP : TEST_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static int run_shell_tests(int argc, const char *argv[], int i, int width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) DIR *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct dirent *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) char path_dir[PATH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct shell_test st = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) .dir = shell_tests__dir(path_dir, sizeof(path_dir)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (st.dir == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) dir = opendir(st.dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (!dir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) pr_err("failed to open shell test directory: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) st.dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) for_each_shell_test(dir, st.dir, ent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) int curr = i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) char desc[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) struct test test = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) .desc = shell_test__description(desc, sizeof(desc), st.dir, ent->d_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) .func = shell_test__run,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) .priv = &st,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (!perf_test__matches(test.desc, curr, argc, argv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) st.file = ent->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) pr_info("%2d: %-*s:", i, width, test.desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) test_and_print(&test, false, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) closedir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct test *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) unsigned int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) int width = shell_tests__max_desc_width();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) for_each_test(j, t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) int len = strlen(t->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (width < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) width = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) for_each_test(j, t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int curr = i++, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) int subi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (!perf_test__matches(t->desc, curr, argc, argv)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) bool skip = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) int subn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (!t->subtest.get_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) subn = t->subtest.get_nr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) for (subi = 0; subi < subn; subi++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) if (perf_test__matches(t->subtest.get_desc(subi), curr, argc, argv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) skip = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (skip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) if (t->is_supported && !t->is_supported()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) pr_debug("%2d: %-*s: Disabled\n", i, width, t->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) pr_info("%2d: %-*s:", i, width, t->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) if (intlist__find(skiplist, i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) color_fprintf(stderr, PERF_COLOR_YELLOW, " Skip (user override)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (!t->subtest.get_nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) test_and_print(t, false, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) int subn = t->subtest.get_nr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) * minus 2 to align with normal testcases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) * For subtest we print additional '.x' in number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * for example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) * 35: Test LLVM searching and compiling :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * 35.1: Basic BPF llvm compiling test : Ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) int subw = width > 2 ? width - 2 : width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) bool skip = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (subn <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) color_fprintf(stderr, PERF_COLOR_YELLOW,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) " Skip (not compiled in)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) pr_info("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) for (subi = 0; subi < subn; subi++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) int len = strlen(t->subtest.get_desc(subi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (subw < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) subw = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) for (subi = 0; subi < subn; subi++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) if (!perf_test__matches(t->subtest.get_desc(subi), curr, argc, argv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) pr_info("%2d.%1d: %-*s:", i, subi + 1, subw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) t->subtest.get_desc(subi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) err = test_and_print(t, skip, subi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (err != TEST_OK && t->subtest.skip_if_fail)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) skip = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) return run_shell_tests(argc, argv, i, width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) static int perf_test__list_shell(int argc, const char **argv, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) DIR *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) struct dirent *ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) char path_dir[PATH_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) const char *path = shell_tests__dir(path_dir, sizeof(path_dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) dir = opendir(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (!dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) for_each_shell_test(dir, path, ent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) int curr = i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) char bf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) struct test t = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) .desc = shell_test__description(bf, sizeof(bf), path, ent->d_name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (!perf_test__matches(t.desc, curr, argc, argv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) pr_info("%2d: %s\n", i, t.desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) closedir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) static int perf_test__list(int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) unsigned int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct test *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) for_each_test(j, t) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) int curr = i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (!perf_test__matches(t->desc, curr, argc, argv) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) (t->is_supported && !t->is_supported()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) pr_info("%2d: %s\n", i, t->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (t->subtest.get_nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) int subn = t->subtest.get_nr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) int subi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) for (subi = 0; subi < subn; subi++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) pr_info("%2d:%1d: %s\n", i, subi + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) t->subtest.get_desc(subi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) perf_test__list_shell(argc, argv, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) int cmd_test(int argc, const char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) const char *test_usage[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) "perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) const char *skip = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) const struct option test_options[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) OPT_INCR('v', "verbose", &verbose,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) "be more verbose (show symbol address, etc)"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) OPT_BOOLEAN('F', "dont-fork", &dont_fork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) "Do not fork for testcase"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) OPT_END()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) const char * const test_subcommands[] = { "list", NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) struct intlist *skiplist = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) int ret = hists__init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) if (argc >= 1 && !strcmp(argv[0], "list"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) return perf_test__list(argc - 1, argv + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) symbol_conf.priv_size = sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) symbol_conf.sort_by_name = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) symbol_conf.try_vmlinux_path = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (symbol__init(NULL) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (skip != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) skiplist = intlist__new(skip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * Tests that create BPF maps, for instance, need more than the 64K
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) rlimit__bump_memlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) return __cmd_test(argc, argv, skiplist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) }