diff options
Diffstat (limited to 'tools/perf/tests')
-rw-r--r-- | tools/perf/tests/Build | 3 | ||||
-rw-r--r-- | tools/perf/tests/attr.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/backward-ring-buffer.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/bpf.c | 50 | ||||
-rw-r--r-- | tools/perf/tests/builtin-test.c | 115 | ||||
-rw-r--r-- | tools/perf/tests/clang.c | 46 | ||||
-rw-r--r-- | tools/perf/tests/code-reading.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/fdarray.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/llvm.c | 12 | ||||
-rw-r--r-- | tools/perf/tests/llvm.h | 7 | ||||
-rw-r--r-- | tools/perf/tests/make | 8 | ||||
-rw-r--r-- | tools/perf/tests/parse-events.c | 10 | ||||
-rw-r--r-- | tools/perf/tests/parse-no-sample-id-all.c | 19 | ||||
-rw-r--r-- | tools/perf/tests/perf-hooks.c | 48 | ||||
-rw-r--r-- | tools/perf/tests/perf-record.c | 6 | ||||
-rw-r--r-- | tools/perf/tests/python-use.c | 2 | ||||
-rw-r--r-- | tools/perf/tests/tests.h | 6 | ||||
-rw-r--r-- | tools/perf/tests/thread-map.c | 44 | ||||
-rw-r--r-- | tools/perf/tests/topology.c | 4 | ||||
-rw-r--r-- | tools/perf/tests/unit_number__scnprintf.c | 37 | ||||
-rw-r--r-- | tools/perf/tests/vmlinux-kallsyms.c | 2 |
21 files changed, 339 insertions, 88 deletions
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 8a4ce492f7b2..1cb3d9b540e9 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -42,6 +42,9 @@ perf-y += backward-ring-buffer.o perf-y += sdt.o perf-y += is_printable_array.o perf-y += bitmap.o +perf-y += perf-hooks.o +perf-y += clang.o +perf-y += unit_number__scnprintf.o $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build $(call rule_mkdir) diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c index 28d1605b0338..88dc51f4c27b 100644 --- a/tools/perf/tests/attr.c +++ b/tools/perf/tests/attr.c @@ -144,7 +144,7 @@ static int run_dir(const char *d, const char *perf) int vcnt = min(verbose, (int) sizeof(v) - 1); char cmd[3*PATH_MAX]; - if (verbose) + if (verbose > 0) vcnt++; snprintf(cmd, 3*PATH_MAX, PYTHON " %s/attr.py -d %s/attr/ -p %s %.*s", diff --git a/tools/perf/tests/backward-ring-buffer.c b/tools/perf/tests/backward-ring-buffer.c index e6d1816e431a..42e892b1e979 100644 --- a/tools/perf/tests/backward-ring-buffer.c +++ b/tools/perf/tests/backward-ring-buffer.c @@ -97,7 +97,7 @@ int test__backward_ring_buffer(int subtest __maybe_unused) evlist = perf_evlist__new(); if (!evlist) { - pr_debug("No enough memory to create evlist\n"); + pr_debug("Not enough memory to create evlist\n"); return TEST_FAIL; } diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c index 2673e86ed50f..1a04fe77487d 100644 --- a/tools/perf/tests/bpf.c +++ b/tools/perf/tests/bpf.c @@ -5,11 +5,13 @@ #include <util/evlist.h> #include <linux/bpf.h> #include <linux/filter.h> +#include <api/fs/fs.h> #include <bpf/bpf.h> #include "tests.h" #include "llvm.h" #include "debug.h" #define NR_ITERS 111 +#define PERF_TEST_BPF_PATH "/sys/fs/bpf/perf_test" #ifdef HAVE_LIBBPF_SUPPORT @@ -54,35 +56,49 @@ static struct { const char *msg_load_fail; int (*target_func)(void); int expect_result; + bool pin; } bpf_testcase_table[] = { { LLVM_TESTCASE_BASE, - "Test basic BPF filtering", + "Basic BPF filtering", "[basic_bpf_test]", "fix 'perf test LLVM' first", "load bpf object failed", &epoll_wait_loop, (NR_ITERS + 1) / 2, + false, + }, + { + LLVM_TESTCASE_BASE, + "BPF pinning", + "[bpf_pinning]", + "fix kbuild first", + "check your vmlinux setting?", + &epoll_wait_loop, + (NR_ITERS + 1) / 2, + true, }, #ifdef HAVE_BPF_PROLOGUE { LLVM_TESTCASE_BPF_PROLOGUE, - "Test BPF prologue generation", + "BPF prologue generation", "[bpf_prologue_test]", "fix kbuild first", "check your vmlinux setting?", &llseek_loop, (NR_ITERS + 1) / 4, + false, }, #endif { LLVM_TESTCASE_BPF_RELOCATION, - "Test BPF relocation checker", + "BPF relocation checker", "[bpf_relocation_test]", "fix 'perf test LLVM' first", "libbpf error when dealing with relocation", NULL, 0, + false, }, }; @@ -125,7 +141,7 @@ static int do_test(struct bpf_object *obj, int (*func)(void), /* Instead of perf_evlist__new_default, don't add default events */ evlist = perf_evlist__new(); if (!evlist) { - pr_debug("No enough memory to create evlist\n"); + pr_debug("Not enough memory to create evlist\n"); return TEST_FAIL; } @@ -226,10 +242,34 @@ static int __test__bpf(int idx) goto out; } - if (obj) + if (obj) { ret = do_test(obj, bpf_testcase_table[idx].target_func, bpf_testcase_table[idx].expect_result); + if (ret != TEST_OK) + goto out; + if (bpf_testcase_table[idx].pin) { + int err; + + if (!bpf_fs__mount()) { + pr_debug("BPF filesystem not mounted\n"); + ret = TEST_FAIL; + goto out; + } + err = mkdir(PERF_TEST_BPF_PATH, 0777); + if (err && errno != EEXIST) { + pr_debug("Failed to make perf_test dir: %s\n", + strerror(errno)); + ret = TEST_FAIL; + goto out; + } + if (bpf_object__pin(obj, PERF_TEST_BPF_PATH)) + ret = TEST_FAIL; + if (rm_rf(PERF_TEST_BPF_PATH)) + ret = TEST_FAIL; + } + } + out: bpf__clear(); return ret; diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 778668a2a966..83c4669cbc5b 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -28,119 +28,119 @@ static struct test generic_tests[] = { .func = test__vmlinux_matches_kallsyms, }, { - .desc = "detect openat syscall event", + .desc = "Detect openat syscall event", .func = test__openat_syscall_event, }, { - .desc = "detect openat syscall event on all cpus", + .desc = "Detect openat syscall event on all cpus", .func = test__openat_syscall_event_on_all_cpus, }, { - .desc = "read samples using the mmap interface", + .desc = "Read samples using the mmap interface", .func = test__basic_mmap, }, { - .desc = "parse events tests", + .desc = "Parse event definition strings", .func = test__parse_events, }, { - .desc = "Validate PERF_RECORD_* events & perf_sample fields", + .desc = "PERF_RECORD_* events & perf_sample fields", .func = test__PERF_RECORD, }, { - .desc = "Test perf pmu format parsing", + .desc = "Parse perf pmu format", .func = test__pmu, }, { - .desc = "Test dso data read", + .desc = "DSO data read", .func = test__dso_data, }, { - .desc = "Test dso data cache", + .desc = "DSO data cache", .func = test__dso_data_cache, }, { - .desc = "Test dso data reopen", + .desc = "DSO data reopen", .func = test__dso_data_reopen, }, { - .desc = "roundtrip evsel->name check", + .desc = "Roundtrip evsel->name", .func = test__perf_evsel__roundtrip_name_test, }, { - .desc = "Check parsing of sched tracepoints fields", + .desc = "Parse sched tracepoints fields", .func = test__perf_evsel__tp_sched_test, }, { - .desc = "Generate and check syscalls:sys_enter_openat event fields", + .desc = "syscalls:sys_enter_openat event fields", .func = test__syscall_openat_tp_fields, }, { - .desc = "struct perf_event_attr setup", + .desc = "Setup struct perf_event_attr", .func = test__attr, }, { - .desc = "Test matching and linking multiple hists", + .desc = "Match and link multiple hists", .func = test__hists_link, }, { - .desc = "Try 'import perf' in python, checking link problems", + .desc = "'import perf' in python", .func = test__python_use, }, { - .desc = "Test breakpoint overflow signal handler", + .desc = "Breakpoint overflow signal handler", .func = test__bp_signal, }, { - .desc = "Test breakpoint overflow sampling", + .desc = "Breakpoint overflow sampling", .func = test__bp_signal_overflow, }, { - .desc = "Test number of exit event of a simple workload", + .desc = "Number of exit events of a simple workload", .func = test__task_exit, }, { - .desc = "Test software clock events have valid period values", + .desc = "Software clock events period values", .func = test__sw_clock_freq, }, { - .desc = "Test object code reading", + .desc = "Object code reading", .func = test__code_reading, }, { - .desc = "Test sample parsing", + .desc = "Sample parsing", .func = test__sample_parsing, }, { - .desc = "Test using a dummy software event to keep tracking", + .desc = "Use a dummy software event to keep tracking", .func = test__keep_tracking, }, { - .desc = "Test parsing with no sample_id_all bit set", + .desc = "Parse with no sample_id_all bit set", .func = test__parse_no_sample_id_all, }, { - .desc = "Test filtering hist entries", + .desc = "Filter hist entries", .func = test__hists_filter, }, { - .desc = "Test mmap thread lookup", + .desc = "Lookup mmap thread", .func = test__mmap_thread_lookup, }, { - .desc = "Test thread mg sharing", + .desc = "Share thread mg", .func = test__thread_mg_share, }, { - .desc = "Test output sorting of hist entries", + .desc = "Sort output of hist entries", .func = test__hists_output, }, { - .desc = "Test cumulation of child hist entries", + .desc = "Cumulate child hist entries", .func = test__hists_cumulate, }, { - .desc = "Test tracking with sched_switch", + .desc = "Track with sched_switch", .func = test__switch_tracking, }, { @@ -152,15 +152,15 @@ static struct test generic_tests[] = { .func = test__fdarray__add, }, { - .desc = "Test kmod_path__parse function", + .desc = "kmod_path__parse", .func = test__kmod_path__parse, }, { - .desc = "Test thread map", + .desc = "Thread map", .func = test__thread_map, }, { - .desc = "Test LLVM searching and compiling", + .desc = "LLVM search and compile", .func = test__llvm, .subtest = { .skip_if_fail = true, @@ -169,11 +169,11 @@ static struct test generic_tests[] = { }, }, { - .desc = "Test topology in session", + .desc = "Session topology", .func = test_session_topology, }, { - .desc = "Test BPF filter", + .desc = "BPF filter", .func = test__bpf, .subtest = { .skip_if_fail = true, @@ -182,54 +182,75 @@ static struct test generic_tests[] = { }, }, { - .desc = "Test thread map synthesize", + .desc = "Synthesize thread map", .func = test__thread_map_synthesize, }, { - .desc = "Test cpu map synthesize", + .desc = "Remove thread map", + .func = test__thread_map_remove, + }, + { + .desc = "Synthesize cpu map", .func = test__cpu_map_synthesize, }, { - .desc = "Test stat config synthesize", + .desc = "Synthesize stat config", .func = test__synthesize_stat_config, }, { - .desc = "Test stat synthesize", + .desc = "Synthesize stat", .func = test__synthesize_stat, }, { - .desc = "Test stat round synthesize", + .desc = "Synthesize stat round", .func = test__synthesize_stat_round, }, { - .desc = "Test attr update synthesize", + .desc = "Synthesize attr update", .func = test__event_update, }, { - .desc = "Test events times", + .desc = "Event times", .func = test__event_times, }, { - .desc = "Test backward reading from ring buffer", + .desc = "Read backward ring buffer", .func = test__backward_ring_buffer, }, { - .desc = "Test cpu map print", + .desc = "Print cpu map", .func = test__cpu_map_print, }, { - .desc = "Test SDT event probing", + .desc = "Probe SDT events", .func = test__sdt_event, }, { - .desc = "Test is_printable_array function", + .desc = "is_printable_array", .func = test__is_printable_array, }, { - .desc = "Test bitmap print", + .desc = "Print bitmap", .func = test__bitmap_print, }, { + .desc = "perf hooks", + .func = test__perf_hooks, + }, + { + .desc = "builtin clang support", + .func = test__clang, + .subtest = { + .skip_if_fail = true, + .get_nr = test__clang_subtest_get_nr, + .get_desc = test__clang_subtest_get_desc, + } + }, + { + .desc = "unit_number__scnprintf", + .func = test__unit_number__scnprint, + }, + { .func = NULL, }, }; @@ -278,7 +299,7 @@ static int run_test(struct test *test, int subtest) if (!dont_fork) { pr_debug("test child forked, pid %d\n", getpid()); - if (!verbose) { + if (verbose <= 0) { int nullfd = open("/dev/null", O_WRONLY); if (nullfd >= 0) { diff --git a/tools/perf/tests/clang.c b/tools/perf/tests/clang.c new file mode 100644 index 000000000000..f853e242a86c --- /dev/null +++ b/tools/perf/tests/clang.c @@ -0,0 +1,46 @@ +#include "tests.h" +#include "debug.h" +#include "util.h" +#include "c++/clang-c.h" + +static struct { + int (*func)(void); + const char *desc; +} clang_testcase_table[] = { +#ifdef HAVE_LIBCLANGLLVM_SUPPORT + { + .func = test__clang_to_IR, + .desc = "builtin clang compile C source to IR", + }, + { + .func = test__clang_to_obj, + .desc = "builtin clang compile C source to ELF object", + }, +#endif +}; + +int test__clang_subtest_get_nr(void) +{ + return (int)ARRAY_SIZE(clang_testcase_table); +} + +const char *test__clang_subtest_get_desc(int i) +{ + if (i < 0 || i >= (int)ARRAY_SIZE(clang_testcase_table)) + return NULL; + return clang_testcase_table[i].desc; +} + +#ifndef HAVE_LIBCLANGLLVM_SUPPORT +int test__clang(int i __maybe_unused) +{ + return TEST_SKIP; +} +#else +int test__clang(int i) +{ + if (i < 0 || i >= (int)ARRAY_SIZE(clang_testcase_table)) + return TEST_FAIL; + return clang_testcase_table[i].func(); +} +#endif diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index ff5bc6363a79..d1f693041324 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -599,7 +599,7 @@ static int do_test_code_reading(bool try_kcore) continue; } - if (verbose) { + if (verbose > 0) { char errbuf[512]; perf_evlist__strerror_open(evlist, errno, errbuf, sizeof(errbuf)); pr_debug("perf_evlist__open() failed!\n%s\n", errbuf); diff --git a/tools/perf/tests/fdarray.c b/tools/perf/tests/fdarray.c index a2b5ff9bf83d..bc5982f42dc3 100644 --- a/tools/perf/tests/fdarray.c +++ b/tools/perf/tests/fdarray.c @@ -19,7 +19,7 @@ static int fdarray__fprintf_prefix(struct fdarray *fda, const char *prefix, FILE { int printed = 0; - if (!verbose) + if (verbose <= 0) return 0; printed += fprintf(fp, "\n%s: ", prefix); diff --git a/tools/perf/tests/llvm.c b/tools/perf/tests/llvm.c index b798a4bfd238..482b5365e68d 100644 --- a/tools/perf/tests/llvm.c +++ b/tools/perf/tests/llvm.c @@ -13,7 +13,7 @@ static int test__bpf_parsing(void *obj_buf, size_t obj_buf_sz) struct bpf_object *obj; obj = bpf_object__open_buffer(obj_buf, obj_buf_sz, NULL); - if (IS_ERR(obj)) + if (libbpf_get_error(obj)) return TEST_FAIL; bpf_object__close(obj); return TEST_OK; @@ -34,19 +34,19 @@ static struct { } bpf_source_table[__LLVM_TESTCASE_MAX] = { [LLVM_TESTCASE_BASE] = { .source = test_llvm__bpf_base_prog, - .desc = "Basic BPF llvm compiling test", + .desc = "Basic BPF llvm compile", }, [LLVM_TESTCASE_KBUILD] = { .source = test_llvm__bpf_test_kbuild_prog, - .desc = "Test kbuild searching", + .desc = "kbuild searching", }, [LLVM_TESTCASE_BPF_PROLOGUE] = { .source = test_llvm__bpf_test_prologue_prog, - .desc = "Compile source for BPF prologue generation test", + .desc = "Compile source for BPF prologue generation", }, [LLVM_TESTCASE_BPF_RELOCATION] = { .source = test_llvm__bpf_test_relocation, - .desc = "Compile source for BPF relocation test", + .desc = "Compile source for BPF relocation", .should_load_fail = true, }, }; @@ -76,7 +76,7 @@ test_llvm__fetch_bpf_obj(void **p_obj_buf, * Skip this test if user's .perfconfig doesn't set [llvm] section * and clang is not found in $PATH, and this is not perf test -v */ - if (!force && (verbose == 0 && + if (!force && (verbose <= 0 && !llvm_param.user_set_param && llvm__search_clang())) { pr_debug("No clang and no verbosive, skip this test\n"); diff --git a/tools/perf/tests/llvm.h b/tools/perf/tests/llvm.h index 0eaa604be99d..b83571758d83 100644 --- a/tools/perf/tests/llvm.h +++ b/tools/perf/tests/llvm.h @@ -1,6 +1,10 @@ #ifndef PERF_TEST_LLVM_H #define PERF_TEST_LLVM_H +#ifdef __cplusplus +extern "C" { +#endif + #include <stddef.h> /* for size_t */ #include <stdbool.h> /* for bool */ @@ -20,4 +24,7 @@ enum test_llvm__testcase { int test_llvm__fetch_bpf_obj(void **p_obj_buf, size_t *p_obj_buf_sz, enum test_llvm__testcase index, bool force, bool *should_load_fail); +#ifdef __cplusplus +} +#endif #endif diff --git a/tools/perf/tests/make b/tools/perf/tests/make index 143f4d549769..e46723568516 100644 --- a/tools/perf/tests/make +++ b/tools/perf/tests/make @@ -42,7 +42,7 @@ LC_NUMERIC=C export LC_COLLATE LC_NUMERIC ifeq ($(srctree),) -srctree := $(patsubst %/,%,$(dir $(shell pwd))) +srctree := $(patsubst %/,%,$(dir $(CURDIR))) srctree := $(patsubst %/,%,$(dir $(srctree))) #$(info Determined 'srctree' to be $(srctree)) endif @@ -83,6 +83,7 @@ make_no_libbpf := NO_LIBBPF=1 make_no_libcrypto := NO_LIBCRYPTO=1 make_with_babeltrace:= LIBBABELTRACE=1 make_no_sdt := NO_SDT=1 +make_with_clangllvm := LIBCLANGLLVM=1 make_tags := tags make_cscope := cscope make_help := help @@ -106,7 +107,7 @@ make_minimal := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_NEWT=1 NO_GTK2=1 make_minimal += NO_DEMANGLE=1 NO_LIBELF=1 NO_LIBUNWIND=1 NO_BACKTRACE=1 make_minimal += NO_LIBNUMA=1 NO_LIBAUDIT=1 NO_LIBBIONIC=1 make_minimal += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 -make_minimal += NO_LIBCRYPTO=1 NO_SDT=1 +make_minimal += NO_LIBCRYPTO=1 NO_SDT=1 NO_JVMTI=1 # $(run) contains all available tests run := make_pure @@ -139,6 +140,7 @@ run += make_no_libbionic run += make_no_auxtrace run += make_no_libbpf run += make_with_babeltrace +run += make_with_clangllvm run += make_help run += make_doc run += make_perf_o @@ -278,7 +280,7 @@ endif MAKEFLAGS := --no-print-directory -clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null) +clean := @(cd $(PERF); $(MAKE_F) -s $(O_OPT) clean >/dev/null && $(MAKE) -s $(O_OPT) -C ../build clean >/dev/null) $(run): $(call clean) diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index 20c2e641c422..1dc838014422 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -1779,15 +1779,14 @@ static int test_pmu_events(void) } while (!ret && (ent = readdir(dir))) { -#define MAX_NAME 100 struct evlist_test e; - char name[MAX_NAME]; + char name[2 * NAME_MAX + 1 + 12 + 3]; /* Names containing . are special and cannot be used directly */ if (strchr(ent->d_name, '.')) continue; - snprintf(name, MAX_NAME, "cpu/event=%s/u", ent->d_name); + snprintf(name, sizeof(name), "cpu/event=%s/u", ent->d_name); e.name = name; e.check = test__checkevent_pmu_events; @@ -1795,11 +1794,10 @@ static int test_pmu_events(void) ret = test_event(&e); if (ret) break; - snprintf(name, MAX_NAME, "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name); + snprintf(name, sizeof(name), "%s:u,cpu/event=%s/u", ent->d_name, ent->d_name); e.name = name; e.check = test__checkevent_pmu_events_mix; ret = test_event(&e); -#undef MAX_NAME } closedir(dir); @@ -1810,7 +1808,7 @@ static void debug_warn(const char *warn, va_list params) { char msg[1024]; - if (!verbose) + if (verbose <= 0) return; vsnprintf(msg, sizeof(msg), warn, params); diff --git a/tools/perf/tests/parse-no-sample-id-all.c b/tools/perf/tests/parse-no-sample-id-all.c index 81c6eeaca0f5..65dcf48a92fb 100644 --- a/tools/perf/tests/parse-no-sample-id-all.c +++ b/tools/perf/tests/parse-no-sample-id-all.c @@ -50,7 +50,8 @@ static int process_events(union perf_event **events, size_t count) } struct test_attr_event { - struct attr_event attr; + struct perf_event_header header; + struct perf_event_attr attr; u64 id; }; @@ -71,20 +72,16 @@ int test__parse_no_sample_id_all(int subtest __maybe_unused) int err; struct test_attr_event event1 = { - .attr = { - .header = { - .type = PERF_RECORD_HEADER_ATTR, - .size = sizeof(struct test_attr_event), - }, + .header = { + .type = PERF_RECORD_HEADER_ATTR, + .size = sizeof(struct test_attr_event), }, .id = 1, }; struct test_attr_event event2 = { - .attr = { - .header = { - .type = PERF_RECORD_HEADER_ATTR, - .size = sizeof(struct test_attr_event), - }, + .header = { + .type = PERF_RECORD_HEADER_ATTR, + .size = sizeof(struct test_attr_event), }, .id = 2, }; diff --git a/tools/perf/tests/perf-hooks.c b/tools/perf/tests/perf-hooks.c new file mode 100644 index 000000000000..665ecc19671c --- /dev/null +++ b/tools/perf/tests/perf-hooks.c @@ -0,0 +1,48 @@ +#include <signal.h> +#include <stdlib.h> + +#include "tests.h" +#include "debug.h" +#include "util.h" +#include "perf-hooks.h" + +static void sigsegv_handler(int sig __maybe_unused) +{ + pr_debug("SIGSEGV is observed as expected, try to recover.\n"); + perf_hooks__recover(); + signal(SIGSEGV, SIG_DFL); + raise(SIGSEGV); + exit(-1); +} + + +static void the_hook(void *_hook_flags) +{ + int *hook_flags = _hook_flags; + int *p = NULL; + + *hook_flags = 1234; + + /* Generate a segfault, test perf_hooks__recover */ + *p = 0; +} + +int test__perf_hooks(int subtest __maybe_unused) +{ + int hook_flags = 0; + + signal(SIGSEGV, sigsegv_handler); + perf_hooks__set_hook("test", the_hook, &hook_flags); + perf_hooks__invoke_test(); + + /* hook is triggered? */ + if (hook_flags != 1234) { + pr_debug("Setting failed: %d (%p)\n", hook_flags, &hook_flags); + return TEST_FAIL; + } + + /* the buggy hook is removed? */ + if (perf_hooks__get_hook("test")) + return TEST_FAIL; + return TEST_OK; +} diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 8f2e1de6d0ea..87893f3ba5f1 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -66,7 +66,7 @@ int test__PERF_RECORD(int subtest __maybe_unused) if (evlist == NULL) /* Fallback for kernels lacking PERF_COUNT_SW_DUMMY */ evlist = perf_evlist__new_default(); - if (evlist == NULL || argv == NULL) { + if (evlist == NULL) { pr_debug("Not enough memory to create evlist\n"); goto out; } @@ -172,13 +172,13 @@ int test__PERF_RECORD(int subtest __maybe_unused) err = perf_evlist__parse_sample(evlist, event, &sample); if (err < 0) { - if (verbose) + if (verbose > 0) perf_event__fprintf(event, stderr); pr_debug("Couldn't parse sample\n"); goto out_delete_evlist; } - if (verbose) { + if (verbose > 0) { pr_info("%" PRIu64" %d ", sample.time, sample.cpu); perf_event__fprintf(event, stderr); } diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c index 7a52834ee0d0..fa79509da535 100644 --- a/tools/perf/tests/python-use.c +++ b/tools/perf/tests/python-use.c @@ -15,7 +15,7 @@ int test__python_use(int subtest __maybe_unused) int ret; if (asprintf(&cmd, "echo \"import sys ; sys.path.append('%s'); import perf\" | %s %s", - PYTHONPATH, PYTHON, verbose ? "" : "2> /dev/null") < 0) + PYTHONPATH, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0) return -1; ret = system(cmd) ? -1 : 0; diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 7c196c585472..1fa9b9d83aa5 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -80,6 +80,7 @@ const char *test__bpf_subtest_get_desc(int subtest); int test__bpf_subtest_get_nr(void); int test_session_topology(int subtest); int test__thread_map_synthesize(int subtest); +int test__thread_map_remove(int subtest); int test__cpu_map_synthesize(int subtest); int test__synthesize_stat_config(int subtest); int test__synthesize_stat(int subtest); @@ -91,6 +92,11 @@ int test__cpu_map_print(int subtest); int test__sdt_event(int subtest); int test__is_printable_array(int subtest); int test__bitmap_print(int subtest); +int test__perf_hooks(int subtest); +int test__clang(int subtest); +const char *test__clang_subtest_get_desc(int subtest); +int test__clang_subtest_get_nr(void); +int test__unit_number__scnprint(int subtest); #if defined(__arm__) || defined(__aarch64__) #ifdef HAVE_DWARF_UNWIND_SUPPORT diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c index cee2a2cdc933..f2d2e542d0ee 100644 --- a/tools/perf/tests/thread-map.c +++ b/tools/perf/tests/thread-map.c @@ -1,3 +1,4 @@ +#include <stdlib.h> #include <sys/types.h> #include <unistd.h> #include <sys/prctl.h> @@ -93,3 +94,46 @@ int test__thread_map_synthesize(int subtest __maybe_unused) return 0; } + +int test__thread_map_remove(int subtest __maybe_unused) +{ + struct thread_map *threads; + char *str; + int i; + + TEST_ASSERT_VAL("failed to allocate map string", + asprintf(&str, "%d,%d", getpid(), getppid()) >= 0); + + threads = thread_map__new_str(str, NULL, 0); + + TEST_ASSERT_VAL("failed to allocate thread_map", + threads); + + if (verbose > 0) + thread_map__fprintf(threads, stderr); + + TEST_ASSERT_VAL("failed to remove thread", + !thread_map__remove(threads, 0)); + + TEST_ASSERT_VAL("thread_map count != 1", threads->nr == 1); + + if (verbose > 0) + thread_map__fprintf(threads, stderr); + + TEST_ASSERT_VAL("failed to remove thread", + !thread_map__remove(threads, 0)); + + TEST_ASSERT_VAL("thread_map count != 0", threads->nr == 0); + + if (verbose > 0) + thread_map__fprintf(threads, stderr); + + TEST_ASSERT_VAL("failed to not remove thread", + thread_map__remove(threads, 0)); + + for (i = 0; i < threads->nr; i++) + free(threads->map[i].comm); + + free(threads); + return 0; +} diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 98fe69ac553c..803f893550d6 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -65,7 +65,9 @@ static int check_cpu_topology(char *path, struct cpu_map *map) session = perf_session__new(&file, false, NULL); TEST_ASSERT_VAL("can't get session", session); - for (i = 0; i < session->header.env.nr_cpus_online; i++) { + for (i = 0; i < session->header.env.nr_cpus_avail; i++) { + if (!cpu_map__has(map, i)) + continue; pr_debug("CPU %d, core %d, socket %d\n", i, session->header.env.cpu[i].core_id, session->header.env.cpu[i].socket_id); diff --git a/tools/perf/tests/unit_number__scnprintf.c b/tools/perf/tests/unit_number__scnprintf.c new file mode 100644 index 000000000000..623c2aa53c4a --- /dev/null +++ b/tools/perf/tests/unit_number__scnprintf.c @@ -0,0 +1,37 @@ +#include <linux/compiler.h> +#include <linux/types.h> +#include "tests.h" +#include "util.h" +#include "debug.h" + +int test__unit_number__scnprint(int subtest __maybe_unused) +{ + struct { + u64 n; + const char *str; + } test[] = { + { 1, "1B" }, + { 10*1024, "10K" }, + { 20*1024*1024, "20M" }, + { 30*1024*1024*1024ULL, "30G" }, + { 0, "0B" }, + { 0, NULL }, + }; + unsigned i = 0; + + while (test[i].str) { + char buf[100]; + + unit_number__scnprintf(buf, sizeof(buf), test[i].n); + + pr_debug("n %" PRIu64 ", str '%s', buf '%s'\n", + test[i].n, test[i].str, buf); + + if (strcmp(test[i].str, buf)) + return TEST_FAIL; + + i++; + } + + return TEST_OK; +} diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c index a5082331f246..862b043e5924 100644 --- a/tools/perf/tests/vmlinux-kallsyms.c +++ b/tools/perf/tests/vmlinux-kallsyms.c @@ -168,7 +168,7 @@ next_pair: err = -1; } - if (!verbose) + if (verbose <= 0) goto out; header_printed = false; |