diff options
Diffstat (limited to 'tools/perf/tests')
34 files changed, 747 insertions, 256 deletions
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 3e8394be15ae..af67f8ef74b4 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -20,7 +20,6 @@ perf-test-y += hists_link.o  perf-test-y += hists_filter.o  perf-test-y += hists_output.o  perf-test-y += hists_cumulate.o -perf-test-y += python-use.o  perf-test-y += bp_signal.o  perf-test-y += bp_signal_overflow.o  perf-test-y += bp_account.o @@ -75,7 +74,6 @@ ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc))  perf-test-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o  endif -CFLAGS_python-use.o   += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))"  CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls  perf-test-y += workloads/ diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 85142dfb3e01..0d2fb7a4ae5b 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -84,7 +84,6 @@ static struct test_suite *generic_tests[] = {  	&suite__syscall_openat_tp_fields,  #endif  	&suite__hists_link, -	&suite__python_use,  	&suite__bp_signal,  	&suite__bp_signal_overflow,  	&suite__bp_accounting, @@ -152,6 +151,7 @@ static struct test_workload *workloads[] = {  	&workload__brstack,  	&workload__datasym,  	&workload__landlock, +	&workload__traploop,  };  #define workloads__for_each(workload) \ diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c index 9c2091310191..4c9fbf6965c4 100644 --- a/tools/perf/tests/code-reading.c +++ b/tools/perf/tests/code-reading.c @@ -2,6 +2,7 @@  #include <errno.h>  #include <linux/kconfig.h>  #include <linux/kernel.h> +#include <linux/rbtree.h>  #include <linux/types.h>  #include <inttypes.h>  #include <stdlib.h> @@ -39,11 +40,64 @@  #define BUFSZ	1024  #define READLEN	128 -struct state { -	u64 done[1024]; -	size_t done_cnt; +struct tested_section { +	struct rb_node rb_node; +	u64 addr; +	char path[PATH_MAX];  }; +static bool tested_code_insert_or_exists(const char *path, u64 addr, +					 struct rb_root *tested_sections) +{ +	struct rb_node **node = &tested_sections->rb_node; +	struct rb_node *parent = NULL; +	struct tested_section *data; + +	while (*node) { +		int cmp; + +		parent = *node; +		data = rb_entry(*node, struct tested_section, rb_node); +		cmp = strcmp(path, data->path); +		if (!cmp) { +			if (addr < data->addr) +				cmp = -1; +			else if (addr > data->addr) +				cmp = 1; +			else +				return true; /* already tested */ +		} + +		if (cmp < 0) +			node = &(*node)->rb_left; +		else +			node = &(*node)->rb_right; +	} + +	data = zalloc(sizeof(*data)); +	if (!data) +		return true; + +	data->addr = addr; +	strlcpy(data->path, path, sizeof(data->path)); +	rb_link_node(&data->rb_node, parent, node); +	rb_insert_color(&data->rb_node, tested_sections); +	return false; +} + +static void tested_sections__free(struct rb_root *root) +{ +	while (!RB_EMPTY_ROOT(root)) { +		struct rb_node *node = rb_first(root); +		struct tested_section *ts = rb_entry(node, +						     struct tested_section, +						     rb_node); + +		rb_erase(node, root); +		free(ts); +	} +} +  static size_t read_objdump_chunk(const char **line, unsigned char **buf,  				 size_t *buf_len)  { @@ -316,13 +370,15 @@ static void dump_buf(unsigned char *buf, size_t len)  }  static int read_object_code(u64 addr, size_t len, u8 cpumode, -			    struct thread *thread, struct state *state) +			    struct thread *thread, +			    struct rb_root *tested_sections)  {  	struct addr_location al;  	unsigned char buf1[BUFSZ] = {0};  	unsigned char buf2[BUFSZ] = {0};  	size_t ret_len;  	u64 objdump_addr; +	u64 skip_addr;  	const char *objdump_name;  	char decomp_name[KMOD_DECOMP_LEN];  	bool decomp = false; @@ -350,6 +406,18 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,  		goto out;  	} +	/* +	 * Don't retest the same addresses. objdump struggles with kcore - try +	 * each map only once even if the address is different. +	 */ +	skip_addr = dso__is_kcore(dso) ? map__start(al.map) : al.addr; +	if (tested_code_insert_or_exists(dso__long_name(dso), skip_addr, +					 tested_sections)) { +		pr_debug("Already tested %s @ %#"PRIx64" - skipping\n", +			 dso__long_name(dso), skip_addr); +		goto out; +	} +  	pr_debug("On file address is: %#"PRIx64"\n", al.addr);  	if (len > BUFSZ) @@ -387,24 +455,6 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,  		goto out;  	} -	/* objdump struggles with kcore - try each map only once */ -	if (dso__is_kcore(dso)) { -		size_t d; - -		for (d = 0; d < state->done_cnt; d++) { -			if (state->done[d] == map__start(al.map)) { -				pr_debug("kcore map tested already"); -				pr_debug(" - skipping\n"); -				goto out; -			} -		} -		if (state->done_cnt >= ARRAY_SIZE(state->done)) { -			pr_debug("Too many kcore maps - skipping\n"); -			goto out; -		} -		state->done[state->done_cnt++] = map__start(al.map); -	} -  	objdump_name = dso__long_name(dso);  	if (dso__needs_decompress(dso)) {  		if (dso__decompress_kmodule_path(dso, objdump_name, @@ -471,9 +521,9 @@ out:  	return err;  } -static int process_sample_event(struct machine *machine, -				struct evlist *evlist, -				union perf_event *event, struct state *state) +static int process_sample_event(struct machine *machine, struct evlist *evlist, +				union perf_event *event, +				struct rb_root *tested_sections)  {  	struct perf_sample sample;  	struct thread *thread; @@ -494,7 +544,8 @@ static int process_sample_event(struct machine *machine,  		goto out;  	} -	ret = read_object_code(sample.ip, READLEN, sample.cpumode, thread, state); +	ret = read_object_code(sample.ip, READLEN, sample.cpumode, thread, +			       tested_sections);  	thread__put(thread);  out:  	perf_sample__exit(&sample); @@ -502,10 +553,11 @@ out:  }  static int process_event(struct machine *machine, struct evlist *evlist, -			 union perf_event *event, struct state *state) +			 union perf_event *event, struct rb_root *tested_sections)  {  	if (event->header.type == PERF_RECORD_SAMPLE) -		return process_sample_event(machine, evlist, event, state); +		return process_sample_event(machine, evlist, event, +					    tested_sections);  	if (event->header.type == PERF_RECORD_THROTTLE ||  	    event->header.type == PERF_RECORD_UNTHROTTLE) @@ -525,7 +577,7 @@ static int process_event(struct machine *machine, struct evlist *evlist,  }  static int process_events(struct machine *machine, struct evlist *evlist, -			  struct state *state) +			  struct rb_root *tested_sections)  {  	union perf_event *event;  	struct mmap *md; @@ -537,7 +589,7 @@ static int process_events(struct machine *machine, struct evlist *evlist,  			continue;  		while ((event = perf_mmap__read_event(&md->core)) != NULL) { -			ret = process_event(machine, evlist, event, state); +			ret = process_event(machine, evlist, event, tested_sections);  			perf_mmap__consume(&md->core);  			if (ret < 0)  				return ret; @@ -637,9 +689,7 @@ static int do_test_code_reading(bool try_kcore)  			.uses_mmap   = true,  		},  	}; -	struct state state = { -		.done_cnt = 0, -	}; +	struct rb_root tested_sections = RB_ROOT;  	struct perf_thread_map *threads = NULL;  	struct perf_cpu_map *cpus = NULL;  	struct evlist *evlist = NULL; @@ -773,7 +823,7 @@ static int do_test_code_reading(bool try_kcore)  	evlist__disable(evlist); -	ret = process_events(machine, evlist, &state); +	ret = process_events(machine, evlist, &tested_sections);  	if (ret < 0)  		goto out_put; @@ -793,6 +843,7 @@ out_err:  	perf_thread_map__put(threads);  	machine__delete(machine);  	perf_env__exit(&host_env); +	tested_sections__free(&tested_sections);  	return err;  } diff --git a/tools/perf/tests/make b/tools/perf/tests/make index c574a678c28a..b650ce8864ed 100644 --- a/tools/perf/tests/make +++ b/tools/perf/tests/make @@ -73,9 +73,9 @@ make_extra_tests    := EXTRA_TESTS=1  make_jevents_all    := JEVENTS_ARCH=all  make_no_bpf_skel    := BUILD_BPF_SKEL=0  make_gen_vmlinux_h  := GEN_VMLINUX_H=1 -make_no_libperl     := NO_LIBPERL=1 +make_libperl        := LIBPERL=1  make_no_libpython   := NO_LIBPYTHON=1 -make_no_scripts     := NO_LIBPYTHON=1 NO_LIBPERL=1 +make_no_scripts     := NO_LIBPYTHON=1  make_no_slang       := NO_SLANG=1  make_no_gtk2        := NO_GTK2=1  make_no_ui          := NO_SLANG=1 NO_GTK2=1 @@ -118,7 +118,7 @@ make_install_prefix_slash := install prefix=/tmp/krava/  make_static         := LDFLAGS=-static NO_PERF_READ_VDSO32=1 NO_PERF_READ_VDSOX32=1 NO_JVMTI=1 NO_LIBTRACEEVENT=1 NO_LIBELF=1  # all the NO_* variable combined -make_minimal        := NO_LIBPERL=1 NO_LIBPYTHON=1 NO_GTK2=1 +make_minimal        := NO_LIBPYTHON=1 NO_GTK2=1  make_minimal        += NO_DEMANGLE=1 NO_LIBELF=1 NO_BACKTRACE=1  make_minimal        += NO_LIBNUMA=1 NO_LIBBIONIC=1 NO_LIBDW=1  make_minimal        += NO_LIBDW_DWARF_UNWIND=1 NO_AUXTRACE=1 NO_LIBBPF=1 @@ -143,7 +143,7 @@ run += make_extra_tests  run += make_jevents_all  run += make_no_bpf_skel  run += make_gen_vmlinux_h -run += make_no_libperl +run += make_libperl  run += make_no_libpython  run += make_no_scripts  run += make_no_slang diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c index bb8004397650..67550cc60555 100644 --- a/tools/perf/tests/parse-events.c +++ b/tools/perf/tests/parse-events.c @@ -1736,6 +1736,53 @@ static int test__intel_pt(struct evlist *evlist)  	return TEST_OK;  } +static bool test__acr_valid(void) +{ +	struct perf_pmu *pmu = NULL; + +	while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { +		if (perf_pmu__has_format(pmu, "acr_mask")) +			return true; +	} + +	return false; +} + +static int test__ratio_to_prev(struct evlist *evlist) +{ +	struct evsel *evsel; +	int ret; + +	TEST_ASSERT_VAL("wrong number of entries", 2 * perf_pmus__num_core_pmus() == evlist->core.nr_entries); + +	 evlist__for_each_entry(evlist, evsel) { +		if (!perf_pmu__has_format(evsel->pmu, "acr_mask")) +			return TEST_OK; + +		if (evsel == evlist__first(evlist)) { +			TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2); +			TEST_ASSERT_VAL("wrong leader", evsel__is_group_leader(evsel)); +			TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2); +			TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 0); +			ret = assert_hw(&evsel->core, PERF_COUNT_HW_CPU_CYCLES, "cycles"); +		} else { +			TEST_ASSERT_VAL("wrong config2", 0 == evsel->core.attr.config2); +			TEST_ASSERT_VAL("wrong leader", !evsel__is_group_leader(evsel)); +			TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 0); +			TEST_ASSERT_VAL("wrong group_idx", evsel__group_idx(evsel) == 1); +			ret = assert_hw(&evsel->core, PERF_COUNT_HW_INSTRUCTIONS, "instructions"); +		} +		if (ret) +			return ret; +		/* +		 * The period value gets configured within evlist__config, +		 * while this test executes only parse events method. +		 */ +		TEST_ASSERT_VAL("wrong period", 0 == evsel->core.attr.sample_period); +	} +	return TEST_OK; +} +  static int test__checkevent_complex_name(struct evlist *evlist)  {  	struct evsel *evsel = evlist__first(evlist); @@ -2249,6 +2296,13 @@ static const struct evlist_test test__events[] = {  		.check = test__checkevent_tracepoint,  		/* 4 */  	}, +	{ +		.name  = "{cycles,instructions/period=200000,ratio-to-prev=2.0/}", +		.valid = test__acr_valid, +		.check = test__ratio_to_prev, +		/* 5 */ +	}, +  };  static const struct evlist_test test__events_pmu[] = { diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c index 0b3c37e66871..efbd9cd60c63 100644 --- a/tools/perf/tests/perf-record.c +++ b/tools/perf/tests/perf-record.c @@ -13,15 +13,19 @@  #include "tests.h"  #include "util/mmap.h"  #include "util/sample.h" +#include "util/cpumap.h"  static int sched__get_first_possible_cpu(pid_t pid, cpu_set_t *maskp)  { -	int i, cpu = -1, nrcpus = 1024; +	int i, cpu = -1; +	int nrcpus = cpu__max_cpu().cpu; +	size_t size = CPU_ALLOC_SIZE(nrcpus); +  realloc: -	CPU_ZERO(maskp); +	CPU_ZERO_S(size, maskp); -	if (sched_getaffinity(pid, sizeof(*maskp), maskp) == -1) { -		if (errno == EINVAL && nrcpus < (1024 << 8)) { +	if (sched_getaffinity(pid, size, maskp) == -1) { +		if (errno == EINVAL && nrcpus < (cpu__max_cpu().cpu << 8)) {  			nrcpus = nrcpus << 2;  			goto realloc;  		} @@ -30,11 +34,11 @@ realloc:  	}  	for (i = 0; i < nrcpus; i++) { -		if (CPU_ISSET(i, maskp)) { +		if (CPU_ISSET_S(i, size, maskp)) {  			if (cpu == -1)  				cpu = i;  			else -				CPU_CLR(i, maskp); +				CPU_CLR_S(i, size, maskp);  		}  	} @@ -50,8 +54,9 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest  		.no_buffering = true,  		.mmap_pages   = 256,  	}; -	cpu_set_t cpu_mask; -	size_t cpu_mask_size = sizeof(cpu_mask); +	int nrcpus = cpu__max_cpu().cpu; +	cpu_set_t *cpu_mask; +	size_t cpu_mask_size;  	struct evlist *evlist = evlist__new_dummy();  	struct evsel *evsel;  	struct perf_sample sample; @@ -69,12 +74,22 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest  	int total_events = 0, nr_events[PERF_RECORD_MAX] = { 0, };  	char sbuf[STRERR_BUFSIZE]; +	cpu_mask = CPU_ALLOC(nrcpus); +	if (!cpu_mask) { +		pr_debug("failed to create cpumask\n"); +		goto out; +	} + +	cpu_mask_size = CPU_ALLOC_SIZE(nrcpus); +	CPU_ZERO_S(cpu_mask_size, cpu_mask); +  	perf_sample__init(&sample, /*all=*/false);  	if (evlist == NULL) /* Fallback for kernels lacking PERF_COUNT_SW_DUMMY */  		evlist = evlist__new_default();  	if (evlist == NULL) {  		pr_debug("Not enough memory to create evlist\n"); +		CPU_FREE(cpu_mask);  		goto out;  	} @@ -111,10 +126,11 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest  	evsel__set_sample_bit(evsel, TIME);  	evlist__config(evlist, &opts, NULL); -	err = sched__get_first_possible_cpu(evlist->workload.pid, &cpu_mask); +	err = sched__get_first_possible_cpu(evlist->workload.pid, cpu_mask);  	if (err < 0) {  		pr_debug("sched__get_first_possible_cpu: %s\n",  			 str_error_r(errno, sbuf, sizeof(sbuf))); +		evlist__cancel_workload(evlist);  		goto out_delete_evlist;  	} @@ -123,9 +139,10 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest  	/*  	 * So that we can check perf_sample.cpu on all the samples.  	 */ -	if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, &cpu_mask) < 0) { +	if (sched_setaffinity(evlist->workload.pid, cpu_mask_size, cpu_mask) < 0) {  		pr_debug("sched_setaffinity: %s\n",  			 str_error_r(errno, sbuf, sizeof(sbuf))); +		evlist__cancel_workload(evlist);  		goto out_delete_evlist;  	} @@ -137,6 +154,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest  	if (err < 0) {  		pr_debug("perf_evlist__open: %s\n",  			 str_error_r(errno, sbuf, sizeof(sbuf))); +		evlist__cancel_workload(evlist);  		goto out_delete_evlist;  	} @@ -149,6 +167,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest  	if (err < 0) {  		pr_debug("evlist__mmap: %s\n",  			 str_error_r(errno, sbuf, sizeof(sbuf))); +		evlist__cancel_workload(evlist);  		goto out_delete_evlist;  	} @@ -328,6 +347,7 @@ found_exit:  		++errs;  	}  out_delete_evlist: +	CPU_FREE(cpu_mask);  	evlist__delete(evlist);  out:  	perf_sample__exit(&sample); diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c deleted file mode 100644 index 0ebc22ac8d5b..000000000000 --- a/tools/perf/tests/python-use.c +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Just test if we can load the python binding. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <linux/compiler.h> -#include "tests.h" -#include "util/debug.h" - -static int test__python_use(struct test_suite *test __maybe_unused, int subtest __maybe_unused) -{ -	char *cmd; -	int ret; - -	if (asprintf(&cmd, "echo \"import sys ; sys.path.insert(0, '%s'); import perf\" | %s %s", -		     PYTHONPATH, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0) -		return -1; - -	pr_debug("python usage test: \"%s\"\n", cmd); -	ret = system(cmd) ? -1 : 0; -	free(cmd); -	return ret; -} - -DEFINE_SUITE("'import perf' in python", python_use); diff --git a/tools/perf/tests/shell/amd-ibs-swfilt.sh b/tools/perf/tests/shell/amd-ibs-swfilt.sh index 7045ec72ba4c..e7f66df05c4b 100755 --- a/tools/perf/tests/shell/amd-ibs-swfilt.sh +++ b/tools/perf/tests/shell/amd-ibs-swfilt.sh @@ -1,6 +1,10 @@  #!/bin/bash  # AMD IBS software filtering +ParanoidAndNotRoot() { +  [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] +} +  echo "check availability of IBS swfilt"  # check if IBS PMU is available @@ -16,6 +20,7 @@ if [ ! -f /sys/bus/event_source/devices/ibs_op/format/swfilt ]; then  fi  echo "run perf record with modifier and swfilt" +err=0  # setting any modifiers should fail  perf record -B -e ibs_op//u -o /dev/null true 2> /dev/null @@ -31,11 +36,17 @@ if [ $? -ne 0 ]; then      exit 1  fi -# setting it with swfilt=1 should be fine -perf record -B -e ibs_op/swfilt=1/k -o /dev/null true -if [ $? -ne 0 ]; then -    echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user" -    exit 1 +if ! ParanoidAndNotRoot 1 +then +    # setting it with swfilt=1 should be fine +    perf record -B -e ibs_op/swfilt=1/k -o /dev/null true +    if [ $? -ne 0 ]; then +        echo "[FAIL] IBS op PMU cannot handle swfilt for exclude_user" +        exit 1 +    fi +else +    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user" +    err=2  fi  # check ibs_fetch PMU as well @@ -46,10 +57,16 @@ if [ $? -ne 0 ]; then  fi  # check system wide recording -perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true -if [ $? -ne 0 ]; then -    echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode" -    exit 1 +if ! ParanoidAndNotRoot 0 +then +    perf record -aB --synth=no -e ibs_op/swfilt/k -o /dev/null true +    if [ $? -ne 0 ]; then +        echo "[FAIL] IBS op PMU cannot handle swfilt in system-wide mode" +        exit 1 +    fi +else +    echo "[SKIP] not root and perf_event_paranoid too high for system-wide/exclude_user" +    err=2  fi  echo "check number of samples with swfilt" @@ -60,8 +77,16 @@ if [ ${kernel_sample} -ne 0 ]; then      exit 1  fi -user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U) -if [ ${user_sample} -ne 0 ]; then -    echo "[FAIL] unexpected user samples: " ${user_sample} -    exit 1 +if ! ParanoidAndNotRoot 1 +then +    user_sample=$(perf record -e ibs_fetch/swfilt/k -o- true | perf script -i- -F misc | grep -c ^U) +    if [ ${user_sample} -ne 0 ]; then +        echo "[FAIL] unexpected user samples: " ${user_sample} +        exit 1 +    fi +else +    echo "[SKIP] not root and perf_event_paranoid too high for exclude_user" +    err=2  fi + +exit $err diff --git a/tools/perf/tests/shell/attr/test-stat-default b/tools/perf/tests/shell/attr/test-stat-default index e47fb4944679..8dd27c1fb661 100644 --- a/tools/perf/tests/shell/attr/test-stat-default +++ b/tools/perf/tests/shell/attr/test-stat-default @@ -227,3 +227,10 @@ fd=28  type=4  config=270  optional=1 + +# PERF_TYPE_RAW / INT_MISC.UOP_DROPPING +[event29:base-stat] +fd=29 +type=4 +config=4269 +optional=1
\ No newline at end of file diff --git a/tools/perf/tests/shell/attr/test-stat-detailed-1 b/tools/perf/tests/shell/attr/test-stat-detailed-1 index 3d500d3e0c5c..12a2ebf4e64a 100644 --- a/tools/perf/tests/shell/attr/test-stat-detailed-1 +++ b/tools/perf/tests/shell/attr/test-stat-detailed-1 @@ -269,3 +269,10 @@ fd=32  type=3  config=65538  optional=1 + +# PERF_TYPE_RAW / INT_MISC.UOP_DROPPING +[event33:base-stat] +fd=33 +type=4 +config=4269 +optional=1
\ No newline at end of file diff --git a/tools/perf/tests/shell/attr/test-stat-detailed-2 b/tools/perf/tests/shell/attr/test-stat-detailed-2 index 01777a63752f..66ea25b7d38f 100644 --- a/tools/perf/tests/shell/attr/test-stat-detailed-2 +++ b/tools/perf/tests/shell/attr/test-stat-detailed-2 @@ -329,3 +329,10 @@ fd=38  type=3  config=65540  optional=1 + +# PERF_TYPE_RAW / INT_MISC.UOP_DROPPING +[event39:base-stat] +fd=39 +type=4 +config=4269 +optional=1
\ No newline at end of file diff --git a/tools/perf/tests/shell/attr/test-stat-detailed-3 b/tools/perf/tests/shell/attr/test-stat-detailed-3 index 8400abd7e1e4..4a27bbfb9f87 100644 --- a/tools/perf/tests/shell/attr/test-stat-detailed-3 +++ b/tools/perf/tests/shell/attr/test-stat-detailed-3 @@ -349,3 +349,10 @@ fd=40  type=3  config=66048  optional=1 + +# PERF_TYPE_RAW / INT_MISC.UOP_DROPPING +[event41:base-stat] +fd=41 +type=4 +config=4269 +optional=1
\ No newline at end of file diff --git a/tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh b/tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh index 8226449ac5c3..f74aab5c5d7f 100755 --- a/tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh +++ b/tools/perf/tests/shell/base_probe/test_adding_blacklisted.sh @@ -13,11 +13,12 @@  #	they must be skipped.  # -# include working environment -. ../common/init.sh - +DIR_PATH="$(dirname $0)"  TEST_RESULT=0 +# include working environment +. "$DIR_PATH/../common/init.sh" +  # skip if not supported  BLACKFUNC_LIST=`head -n 5 /sys/kernel/debug/kprobes/blacklist 2> /dev/null | cut -f2`  if [ -z "$BLACKFUNC_LIST" ]; then @@ -53,7 +54,8 @@ for BLACKFUNC in $BLACKFUNC_LIST; do  	PERF_EXIT_CODE=$?  	# check for bad DWARF polluting the result -	../common/check_all_patterns_found.pl "$REGEX_MISSING_DECL_LINE" >/dev/null < $LOGS_DIR/adding_blacklisted.err +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"$REGEX_MISSING_DECL_LINE" >/dev/null < $LOGS_DIR/adding_blacklisted.err  	if [ $? -eq 0 ]; then  		SKIP_DWARF=1 @@ -73,7 +75,11 @@ for BLACKFUNC in $BLACKFUNC_LIST; do  			fi  		fi  	else -		../common/check_all_lines_matched.pl "$REGEX_SKIP_MESSAGE" "$REGEX_NOT_FOUND_MESSAGE" "$REGEX_ERROR_MESSAGE" "$REGEX_SCOPE_FAIL" "$REGEX_INVALID_ARGUMENT" "$REGEX_SYMBOL_FAIL" "$REGEX_OUT_SECTION" < $LOGS_DIR/adding_blacklisted.err +		"$DIR_PATH/../common/check_all_lines_matched.pl" \ +			"$REGEX_SKIP_MESSAGE" "$REGEX_NOT_FOUND_MESSAGE" \ +			"$REGEX_ERROR_MESSAGE" "$REGEX_SCOPE_FAIL" \ +			"$REGEX_INVALID_ARGUMENT" "$REGEX_SYMBOL_FAIL" \ +			"$REGEX_OUT_SECTION" < $LOGS_DIR/adding_blacklisted.err  		CHECK_EXIT_CODE=$?  		SKIP_DWARF=0 @@ -94,7 +100,9 @@ fi  $CMD_PERF list probe:\* > $LOGS_DIR/adding_blacklisted_list.log  PERF_EXIT_CODE=$? -../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" < $LOGS_DIR/adding_blacklisted_list.log +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" \ +	< $LOGS_DIR/adding_blacklisted_list.log  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing blacklisted probe (should NOT be listed)" diff --git a/tools/perf/tests/shell/base_probe/test_adding_kernel.sh b/tools/perf/tests/shell/base_probe/test_adding_kernel.sh index df288cf90cd6..555a825d55f2 100755 --- a/tools/perf/tests/shell/base_probe/test_adding_kernel.sh +++ b/tools/perf/tests/shell/base_probe/test_adding_kernel.sh @@ -13,13 +13,14 @@  #		and removing.  # -# include working environment -. ../common/init.sh - +DIR_PATH="$(dirname $0)"  TEST_RESULT=0 +# include working environment +. "$DIR_PATH/../common/init.sh" +  # shellcheck source=lib/probe_vfs_getname.sh -. "$(dirname "$0")/../lib/probe_vfs_getname.sh" +. "$DIR_PATH/../lib/probe_vfs_getname.sh"  TEST_PROBE=${TEST_PROBE:-"inode_permission"} @@ -44,7 +45,9 @@ for opt in "" "-a" "--add"; do  	$CMD_PERF probe $opt $TEST_PROBE 2> $LOGS_DIR/adding_kernel_add$opt.err  	PERF_EXIT_CODE=$? -	../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_add$opt.err +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" \ +		< $LOGS_DIR/adding_kernel_add$opt.err  	CHECK_EXIT_CODE=$?  	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "adding probe $TEST_PROBE :: $opt" @@ -58,7 +61,10 @@ done  $CMD_PERF list probe:\* > $LOGS_DIR/adding_kernel_list.log  PERF_EXIT_CODE=$? -../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "List of pre-defined events" "probe:${TEST_PROBE}(?:_\d+)?\s+\[Tracepoint event\]" "Metric Groups:" < $LOGS_DIR/adding_kernel_list.log +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"$RE_LINE_EMPTY" "List of pre-defined events" \ +	"probe:${TEST_PROBE}(?:_\d+)?\s+\[Tracepoint event\]" \ +	"Metric Groups:" < $LOGS_DIR/adding_kernel_list.log  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing added probe :: perf list" @@ -71,7 +77,9 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing added probe :: perf list  $CMD_PERF probe -l > $LOGS_DIR/adding_kernel_list-l.log  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "\s*probe:${TEST_PROBE}(?:_\d+)?\s+\(on ${TEST_PROBE}(?:[:\+]$RE_NUMBER_HEX)?@.+\)" < $LOGS_DIR/adding_kernel_list-l.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"\s*probe:${TEST_PROBE}(?:_\d+)?\s+\(on ${TEST_PROBE}(?:[:\+]$RE_NUMBER_HEX)?@.+\)" \ +	< $LOGS_DIR/adding_kernel_list-l.log  CHECK_EXIT_CODE=$?  if [ $NO_DEBUGINFO ] ; then @@ -93,9 +101,13 @@ REGEX_STAT_VALUES="\s*\d+\s+probe:$TEST_PROBE"  # the value should be greater than 1  REGEX_STAT_VALUE_NONZERO="\s*[1-9][0-9]*\s+probe:$TEST_PROBE"  REGEX_STAT_TIME="\s*$RE_NUMBER\s+seconds (?:time elapsed|user|sys)" -../common/check_all_lines_matched.pl "$REGEX_STAT_HEADER" "$REGEX_STAT_VALUES" "$REGEX_STAT_TIME" "$RE_LINE_COMMENT" "$RE_LINE_EMPTY" < $LOGS_DIR/adding_kernel_using_probe.log +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"$REGEX_STAT_HEADER" "$REGEX_STAT_VALUES" "$REGEX_STAT_TIME" \ +	"$RE_LINE_COMMENT" "$RE_LINE_EMPTY" < $LOGS_DIR/adding_kernel_using_probe.log  CHECK_EXIT_CODE=$? -../common/check_all_patterns_found.pl "$REGEX_STAT_HEADER" "$REGEX_STAT_VALUE_NONZERO" "$REGEX_STAT_TIME" < $LOGS_DIR/adding_kernel_using_probe.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$REGEX_STAT_HEADER" "$REGEX_STAT_VALUE_NONZERO" "$REGEX_STAT_TIME" \ +	< $LOGS_DIR/adding_kernel_using_probe.log  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "using added probe" @@ -108,7 +120,8 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "using added probe"  $CMD_PERF probe -d $TEST_PROBE\* 2> $LOGS_DIR/adding_kernel_removing.err  PERF_EXIT_CODE=$? -../common/check_all_lines_matched.pl "Removed event: probe:$TEST_PROBE" < $LOGS_DIR/adding_kernel_removing.err +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"Removed event: probe:$TEST_PROBE" < $LOGS_DIR/adding_kernel_removing.err  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "deleting added probe" @@ -121,7 +134,9 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "deleting added probe"  $CMD_PERF list probe:\* > $LOGS_DIR/adding_kernel_list_removed.log  PERF_EXIT_CODE=$? -../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" < $LOGS_DIR/adding_kernel_list_removed.log +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"$RE_LINE_EMPTY" "List of pre-defined events" "Metric Groups:" \ +	< $LOGS_DIR/adding_kernel_list_removed.log  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing removed probe (should NOT be listed)" @@ -135,7 +150,9 @@ $CMD_PERF probe -n --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_dryrun.err  PERF_EXIT_CODE=$?  # check for the output (should be the same as usual) -../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_dryrun.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" \ +	< $LOGS_DIR/adding_kernel_dryrun.err  CHECK_EXIT_CODE=$?  # check that no probe was added in real @@ -152,7 +169,9 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "dry run :: adding probe"  $CMD_PERF probe --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_01.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_forceadd_01.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE" \ +	< $LOGS_DIR/adding_kernel_forceadd_01.err  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: first probe adding" @@ -162,7 +181,9 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: first pro  ! $CMD_PERF probe --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_02.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "Error: event \"$TEST_PROBE\" already exists." "Error: Failed to add events." < $LOGS_DIR/adding_kernel_forceadd_02.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"Error: event \"$TEST_PROBE\" already exists." \ +	"Error: Failed to add events." < $LOGS_DIR/adding_kernel_forceadd_02.err  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: second probe adding (without force)" @@ -173,7 +194,9 @@ NO_OF_PROBES=`$CMD_PERF probe -l $TEST_PROBE| wc -l`  $CMD_PERF probe --force --add $TEST_PROBE 2> $LOGS_DIR/adding_kernel_forceadd_03.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "Added new events?:" "probe:${TEST_PROBE}_${NO_OF_PROBES}" "on $TEST_PROBE" < $LOGS_DIR/adding_kernel_forceadd_03.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"Added new events?:" "probe:${TEST_PROBE}_${NO_OF_PROBES}" \ +	"on $TEST_PROBE" < $LOGS_DIR/adding_kernel_forceadd_03.err  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "force-adding probes :: second probe adding (with force)" @@ -187,7 +210,9 @@ $CMD_PERF stat -e probe:$TEST_PROBE -e probe:${TEST_PROBE}_${NO_OF_PROBES} -x';'  PERF_EXIT_CODE=$?  REGEX_LINE="$RE_NUMBER;+probe:${TEST_PROBE}_?(?:$NO_OF_PROBES)?;$RE_NUMBER;$RE_NUMBER" -../common/check_all_lines_matched.pl "$REGEX_LINE" "$RE_LINE_EMPTY" "$RE_LINE_COMMENT" < $LOGS_DIR/adding_kernel_using_two.log +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"$REGEX_LINE" "$RE_LINE_EMPTY" "$RE_LINE_COMMENT" \ +	< $LOGS_DIR/adding_kernel_using_two.log  CHECK_EXIT_CODE=$?  VALUE_1=`grep "$TEST_PROBE;" $LOGS_DIR/adding_kernel_using_two.log | awk -F';' '{print $1}'` @@ -205,7 +230,9 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "using doubled probe"  $CMD_PERF probe --del \* 2> $LOGS_DIR/adding_kernel_removing_wildcard.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "Removed event: probe:$TEST_PROBE" "Removed event: probe:${TEST_PROBE}_1" < $LOGS_DIR/adding_kernel_removing_wildcard.err +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"Removed event: probe:$TEST_PROBE" \ +	"Removed event: probe:${TEST_PROBE}_1" < $LOGS_DIR/adding_kernel_removing_wildcard.err  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "removing multiple probes" @@ -217,7 +244,9 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "removing multiple probes"  $CMD_PERF probe -nf --max-probes=512 -a 'vfs_* $params' 2> $LOGS_DIR/adding_kernel_adding_wildcard.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "probe:vfs_mknod" "probe:vfs_create" "probe:vfs_rmdir" "probe:vfs_link" "probe:vfs_write" < $LOGS_DIR/adding_kernel_adding_wildcard.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"probe:vfs_mknod" "probe:vfs_create" "probe:vfs_rmdir" \ +	"probe:vfs_link" "probe:vfs_write" < $LOGS_DIR/adding_kernel_adding_wildcard.err  CHECK_EXIT_CODE=$?  if [ $NO_DEBUGINFO ] ; then @@ -240,13 +269,22 @@ test $PERF_EXIT_CODE -ne 139 -a $PERF_EXIT_CODE -ne 0  PERF_EXIT_CODE=$?  # check that the error message is reasonable -../common/check_all_patterns_found.pl "Failed to find" "somenonexistingrandomstuffwhichisalsoprettylongorevenlongertoexceed64" < $LOGS_DIR/adding_kernel_nonexisting.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"Failed to find" \ +	"somenonexistingrandomstuffwhichisalsoprettylongorevenlongertoexceed64" \ +	< $LOGS_DIR/adding_kernel_nonexisting.err  CHECK_EXIT_CODE=$? -../common/check_all_patterns_found.pl "in this function|at this address" "Error" "Failed to add events" < $LOGS_DIR/adding_kernel_nonexisting.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"in this function|at this address" "Error" "Failed to add events" \ +	< $LOGS_DIR/adding_kernel_nonexisting.err  (( CHECK_EXIT_CODE += $? )) -../common/check_all_lines_matched.pl "Failed to find" "Error" "Probe point .+ not found" "optimized out" "Use.+\-\-range option to show.+location range" < $LOGS_DIR/adding_kernel_nonexisting.err +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"Failed to find" "Error" "Probe point .+ not found" "optimized out" \ +	"Use.+\-\-range option to show.+location range" \ +	< $LOGS_DIR/adding_kernel_nonexisting.err  (( CHECK_EXIT_CODE += $? )) -../common/check_no_patterns_found.pl "$RE_SEGFAULT" < $LOGS_DIR/adding_kernel_nonexisting.err +"$DIR_PATH/../common/check_no_patterns_found.pl" \ +	"$RE_SEGFAULT" < $LOGS_DIR/adding_kernel_nonexisting.err  (( CHECK_EXIT_CODE += $? ))  if [ $NO_DEBUGINFO ]; then @@ -264,7 +302,10 @@ fi  $CMD_PERF probe --add "$TEST_PROBE%return \$retval" 2> $LOGS_DIR/adding_kernel_func_retval_add.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "Added new events?:" "probe:$TEST_PROBE" "on $TEST_PROBE%return with \\\$retval" < $LOGS_DIR/adding_kernel_func_retval_add.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"Added new events?:" "probe:$TEST_PROBE" \ +	"on $TEST_PROBE%return with \\\$retval" \ +	< $LOGS_DIR/adding_kernel_func_retval_add.err  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function with retval :: add" @@ -274,7 +315,9 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function with retval :: add"  $CMD_PERF record -e probe:$TEST_PROBE\* -o $CURRENT_TEST_DIR/perf.data -- cat /proc/cpuinfo > /dev/null 2> $LOGS_DIR/adding_kernel_func_retval_record.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/adding_kernel_func_retval_record.err +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" \ +	< $LOGS_DIR/adding_kernel_func_retval_record.err  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function with retval :: record" @@ -285,9 +328,11 @@ $CMD_PERF script -i $CURRENT_TEST_DIR/perf.data > $LOGS_DIR/adding_kernel_func_r  PERF_EXIT_CODE=$?  REGEX_SCRIPT_LINE="\s*cat\s+$RE_NUMBER\s+\[$RE_NUMBER\]\s+$RE_NUMBER:\s+probe:$TEST_PROBE\w*:\s+\($RE_NUMBER_HEX\s+<\-\s+$RE_NUMBER_HEX\)\s+arg1=$RE_NUMBER_HEX" -../common/check_all_lines_matched.pl "$REGEX_SCRIPT_LINE" < $LOGS_DIR/adding_kernel_func_retval_script.log +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"$REGEX_SCRIPT_LINE" < $LOGS_DIR/adding_kernel_func_retval_script.log  CHECK_EXIT_CODE=$? -../common/check_all_patterns_found.pl "$REGEX_SCRIPT_LINE" < $LOGS_DIR/adding_kernel_func_retval_script.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$REGEX_SCRIPT_LINE" < $LOGS_DIR/adding_kernel_func_retval_script.log  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "function argument probing :: script" diff --git a/tools/perf/tests/shell/base_probe/test_basic.sh b/tools/perf/tests/shell/base_probe/test_basic.sh index 9d8b5afbeddd..162838ddc974 100755 --- a/tools/perf/tests/shell/base_probe/test_basic.sh +++ b/tools/perf/tests/shell/base_probe/test_basic.sh @@ -12,11 +12,12 @@  #		This test tests basic functionality of perf probe command.  # -# include working environment -. ../common/init.sh - +DIR_PATH="$(dirname $0)"  TEST_RESULT=0 +# include working environment +. "$DIR_PATH/../common/init.sh" +  if ! check_kprobes_available; then  	print_overall_skipped  	exit 2 @@ -30,15 +31,25 @@ if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then  	$CMD_PERF probe --help > $LOGS_DIR/basic_helpmsg.log 2> $LOGS_DIR/basic_helpmsg.err  	PERF_EXIT_CODE=$? -	../common/check_all_patterns_found.pl "PERF-PROBE" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" "PROBE\s+SYNTAX" "PROBE\s+ARGUMENT" "LINE\s+SYNTAX" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"PERF-PROBE" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" \ +		"PROBE\s+SYNTAX" "PROBE\s+ARGUMENT" "LINE\s+SYNTAX" \ +		< $LOGS_DIR/basic_helpmsg.log  	CHECK_EXIT_CODE=$? -	../common/check_all_patterns_found.pl "LAZY\s+MATCHING" "FILTER\s+PATTERN" "EXAMPLES" "SEE\s+ALSO" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"LAZY\s+MATCHING" "FILTER\s+PATTERN" "EXAMPLES" "SEE\s+ALSO" \ +		< $LOGS_DIR/basic_helpmsg.log  	(( CHECK_EXIT_CODE += $? )) -	../common/check_all_patterns_found.pl "vmlinux" "module=" "source=" "verbose" "quiet" "add=" "del=" "list.*EVENT" "line=" "vars=" "externs" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"vmlinux" "module=" "source=" "verbose" "quiet" "add=" "del=" \ +		"list.*EVENT" "line=" "vars=" "externs" < $LOGS_DIR/basic_helpmsg.log  	(( CHECK_EXIT_CODE += $? )) -	../common/check_all_patterns_found.pl "no-inlines" "funcs.*FILTER" "filter=FILTER" "force" "dry-run" "max-probes" "exec=" "demangle-kernel" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"no-inlines" "funcs.*FILTER" "filter=FILTER" "force" "dry-run" \ +		"max-probes" "exec=" "demangle-kernel" < $LOGS_DIR/basic_helpmsg.log  	(( CHECK_EXIT_CODE += $? )) -	../common/check_no_patterns_found.pl "No manual entry for" < $LOGS_DIR/basic_helpmsg.err +	"$DIR_PATH/../common/check_no_patterns_found.pl" \ +		"No manual entry for" < $LOGS_DIR/basic_helpmsg.err  	(( CHECK_EXIT_CODE += $? ))  	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "help message" @@ -53,7 +64,9 @@ fi  # without any args perf-probe should print usage  $CMD_PERF probe 2> $LOGS_DIR/basic_usage.log > /dev/null -../common/check_all_patterns_found.pl "[Uu]sage" "perf probe" "verbose" "quiet" "add" "del" "force" "line" "vars" "externs" "range" < $LOGS_DIR/basic_usage.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"[Uu]sage" "perf probe" "verbose" "quiet" "add" "del" "force" \ +	"line" "vars" "externs" "range" < $LOGS_DIR/basic_usage.log  CHECK_EXIT_CODE=$?  print_results 0 $CHECK_EXIT_CODE "usage message" diff --git a/tools/perf/tests/shell/base_probe/test_invalid_options.sh b/tools/perf/tests/shell/base_probe/test_invalid_options.sh index 92f7254eb32a..44a3ae014bfa 100755 --- a/tools/perf/tests/shell/base_probe/test_invalid_options.sh +++ b/tools/perf/tests/shell/base_probe/test_invalid_options.sh @@ -12,11 +12,12 @@  #		This test checks whether the invalid and incompatible options are reported  # -# include working environment -. ../common/init.sh - +DIR_PATH="$(dirname $0)"  TEST_RESULT=0 +# include working environment +. "$DIR_PATH/../common/init.sh" +  if ! check_kprobes_available; then  	print_overall_skipped  	exit 2 @@ -33,7 +34,9 @@ for opt in '-a' '-d' '-L' '-V'; do  	! $CMD_PERF probe $opt 2> $LOGS_DIR/invalid_options_missing_argument$opt.err  	PERF_EXIT_CODE=$? -	../common/check_all_patterns_found.pl "Error: switch .* requires a value" < $LOGS_DIR/invalid_options_missing_argument$opt.err +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"Error: switch .* requires a value" \ +		< $LOGS_DIR/invalid_options_missing_argument$opt.err  	CHECK_EXIT_CODE=$?  	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "missing argument for $opt" @@ -66,7 +69,8 @@ for opt in '-a xxx -d xxx' '-a xxx -L foo' '-a xxx -V foo' '-a xxx -l' '-a xxx -  	! $CMD_PERF probe $opt > /dev/null 2> $LOGS_DIR/aux.log  	PERF_EXIT_CODE=$? -	../common/check_all_patterns_found.pl "Error: switch .+ cannot be used with switch .+" < $LOGS_DIR/aux.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"Error: switch .+ cannot be used with switch .+" < $LOGS_DIR/aux.log  	CHECK_EXIT_CODE=$?  	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "mutually exclusive options :: $opt" diff --git a/tools/perf/tests/shell/base_probe/test_line_semantics.sh b/tools/perf/tests/shell/base_probe/test_line_semantics.sh index 20435b6bf6bc..576442d87a44 100755 --- a/tools/perf/tests/shell/base_probe/test_line_semantics.sh +++ b/tools/perf/tests/shell/base_probe/test_line_semantics.sh @@ -13,11 +13,12 @@  #		arguments are properly reported.  # -# include working environment -. ../common/init.sh - +DIR_PATH="$(dirname $0)"  TEST_RESULT=0 +# include working environment +. "$DIR_PATH/../common/init.sh" +  if ! check_kprobes_available; then  	print_overall_skipped  	exit 2 diff --git a/tools/perf/tests/shell/base_report/setup.sh b/tools/perf/tests/shell/base_report/setup.sh index 8634e7e0dda6..bb49b0fabb11 100755 --- a/tools/perf/tests/shell/base_report/setup.sh +++ b/tools/perf/tests/shell/base_report/setup.sh @@ -12,8 +12,10 @@  #  # +DIR_PATH="$(dirname $0)" +  # include working environment -. ../common/init.sh +. "$DIR_PATH/../common/init.sh"  TEST_RESULT=0 @@ -24,7 +26,8 @@ SW_EVENT="cpu-clock"  $CMD_PERF record -asdg -e $SW_EVENT -o $CURRENT_TEST_DIR/perf.data -- $CMD_LONGER_SLEEP 2> $LOGS_DIR/setup.log  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup.log  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "prepare the perf.data file" @@ -38,7 +41,8 @@ echo ==================  cat $LOGS_DIR/setup-latency.log  echo ================== -../common/check_all_patterns_found.pl "$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup-latency.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$RE_LINE_RECORD1" "$RE_LINE_RECORD2" < $LOGS_DIR/setup-latency.log  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "prepare the perf.data.1 file" diff --git a/tools/perf/tests/shell/base_report/test_basic.sh b/tools/perf/tests/shell/base_report/test_basic.sh index adfd8713b8f8..0dfe7e5fd1ca 100755 --- a/tools/perf/tests/shell/base_report/test_basic.sh +++ b/tools/perf/tests/shell/base_report/test_basic.sh @@ -12,11 +12,12 @@  #  # -# include working environment -. ../common/init.sh - +DIR_PATH="$(dirname $0)"  TEST_RESULT=0 +# include working environment +. "$DIR_PATH/../common/init.sh" +  ### help message @@ -25,19 +26,37 @@ if [ "$PARAM_GENERAL_HELP_TEXT_CHECK" = "y" ]; then  	$CMD_PERF report --help > $LOGS_DIR/basic_helpmsg.log 2> $LOGS_DIR/basic_helpmsg.err  	PERF_EXIT_CODE=$? -	../common/check_all_patterns_found.pl "PERF-REPORT" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" "OVERHEAD\s+CALCULATION" "SEE ALSO" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"PERF-REPORT" "NAME" "SYNOPSIS" "DESCRIPTION" "OPTIONS" \ +		"OVERHEAD\s+CALCULATION" "SEE ALSO" < $LOGS_DIR/basic_helpmsg.log  	CHECK_EXIT_CODE=$? -	../common/check_all_patterns_found.pl "input" "verbose" "show-nr-samples" "show-cpu-utilization" "threads" "comms" "pid" "tid" "dsos" "symbols" "symbol-filter" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"input" "verbose" "show-nr-samples" "show-cpu-utilization" \ +		"threads" "comms" "pid" "tid" "dsos" "symbols" "symbol-filter" \ +		< $LOGS_DIR/basic_helpmsg.log  	(( CHECK_EXIT_CODE += $? )) -	../common/check_all_patterns_found.pl "hide-unresolved" "sort" "fields" "parent" "exclude-other" "column-widths" "field-separator" "dump-raw-trace" "children" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"hide-unresolved" "sort" "fields" "parent" "exclude-other" \ +		"column-widths" "field-separator" "dump-raw-trace" "children" \ +		< $LOGS_DIR/basic_helpmsg.log  	(( CHECK_EXIT_CODE += $? )) -	../common/check_all_patterns_found.pl "call-graph" "max-stack" "inverted" "ignore-callees" "pretty" "stdio" "tui" "gtk" "vmlinux" "kallsyms" "modules" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"call-graph" "max-stack" "inverted" "ignore-callees" "pretty" \ +		"stdio" "tui" "gtk" "vmlinux" "kallsyms" "modules" \ +		< $LOGS_DIR/basic_helpmsg.log  	(( CHECK_EXIT_CODE += $? )) -	../common/check_all_patterns_found.pl "force" "symfs" "cpu" "disassembler-style" "source" "asm-raw" "show-total-period" "show-info" "branch-stack" "group" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"force" "symfs" "cpu" "disassembler-style" "source" "asm-raw" \ +		"show-total-period" "show-info" "branch-stack" "group" \ +		< $LOGS_DIR/basic_helpmsg.log  	(( CHECK_EXIT_CODE += $? )) -	../common/check_all_patterns_found.pl "branch-history" "objdump" "demangle" "percent-limit" "percentage" "header" "itrace" "full-source-path" "show-ref-call-graph" < $LOGS_DIR/basic_helpmsg.log +	"$DIR_PATH/../common/check_all_patterns_found.pl" \ +		"branch-history" "objdump" "demangle" "percent-limit" "percentage" \ +		"header" "itrace" "full-source-path" "show-ref-call-graph" \ +		< $LOGS_DIR/basic_helpmsg.log  	(( CHECK_EXIT_CODE += $? )) -	../common/check_no_patterns_found.pl "No manual entry for" < $LOGS_DIR/basic_helpmsg.err +	"$DIR_PATH/../common/check_no_patterns_found.pl" \ +		"No manual entry for" < $LOGS_DIR/basic_helpmsg.err  	(( CHECK_EXIT_CODE += $? ))  	print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "help message" @@ -57,9 +76,12 @@ REGEX_LOST_SAMPLES_INFO="#\s*Total Lost Samples:\s+$RE_NUMBER"  REGEX_SAMPLES_INFO="#\s*Samples:\s+(?:$RE_NUMBER)\w?\s+of\s+event\s+'$RE_EVENT_ANY'"  REGEX_LINES_HEADER="#\s*Children\s+Self\s+Command\s+Shared Object\s+Symbol"  REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+" -../common/check_all_patterns_found.pl "$REGEX_LOST_SAMPLES_INFO" "$REGEX_SAMPLES_INFO" "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_basic.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$REGEX_LOST_SAMPLES_INFO" "$REGEX_SAMPLES_INFO" \ +	"$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_basic.log  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_basic.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_basic.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "basic execution" @@ -74,9 +96,11 @@ PERF_EXIT_CODE=$?  REGEX_LINES_HEADER="#\s*Children\s+Self\s+Samples\s+Command\s+Shared Object\s+Symbol"  REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+" -../common/check_all_patterns_found.pl "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_nrsamples.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_nrsamples.log  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_nrsamples.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_nrsamples.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "number of samples" @@ -98,7 +122,10 @@ REGEX_LINE_CPUS_ONLINE="#\s+nrcpus online\s*:\s*$MY_CPUS_ONLINE"  REGEX_LINE_CPUS_AVAIL="#\s+nrcpus avail\s*:\s*$MY_CPUS_AVAILABLE"  # disable precise check for "nrcpus avail" in BASIC runmode  test $PERFTOOL_TESTSUITE_RUNMODE -lt $RUNMODE_STANDARD && REGEX_LINE_CPUS_AVAIL="#\s+nrcpus avail\s*:\s*$RE_NUMBER" -../common/check_all_patterns_found.pl "$REGEX_LINE_TIMESTAMP" "$REGEX_LINE_HOSTNAME" "$REGEX_LINE_KERNEL" "$REGEX_LINE_PERF" "$REGEX_LINE_ARCH" "$REGEX_LINE_CPUS_ONLINE" "$REGEX_LINE_CPUS_AVAIL" < $LOGS_DIR/basic_header.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$REGEX_LINE_TIMESTAMP" "$REGEX_LINE_HOSTNAME" "$REGEX_LINE_KERNEL" \ +	"$REGEX_LINE_PERF" "$REGEX_LINE_ARCH" "$REGEX_LINE_CPUS_ONLINE" \ +	"$REGEX_LINE_CPUS_AVAIL" < $LOGS_DIR/basic_header.log  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "header" @@ -129,9 +156,11 @@ PERF_EXIT_CODE=$?  REGEX_LINES_HEADER="#\s*Children\s+Self\s+sys\s+usr\s+Command\s+Shared Object\s+Symbol"  REGEX_LINES="\s*$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER%\s+$RE_NUMBER%\s+\S+\s+\[kernel\.(?:vmlinux)|(?:kallsyms)\]\s+\[[k\.]\]\s+\w+" -../common/check_all_patterns_found.pl "$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_cpuut.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"$REGEX_LINES_HEADER" "$REGEX_LINES" < $LOGS_DIR/basic_cpuut.log  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_cpuut.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_cpuut.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "show CPU utilization" @@ -144,9 +173,11 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "show CPU utilization"  $CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --pid=1 > $LOGS_DIR/basic_pid.log 2> $LOGS_DIR/basic_pid.err  PERF_EXIT_CODE=$? -grep -P -v '^#' $LOGS_DIR/basic_pid.log | grep -P '\s+[\d\.]+%' | ../common/check_all_lines_matched.pl "systemd|init" +grep -P -v '^#' $LOGS_DIR/basic_pid.log | grep -P '\s+[\d\.]+%' | \ +	"$DIR_PATH/../common/check_all_lines_matched.pl" "systemd|init"  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_pid.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_pid.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "pid" @@ -159,9 +190,11 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "pid"  $CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --symbols=dummynonexistingsymbol > $LOGS_DIR/basic_symbols.log 2> $LOGS_DIR/basic_symbols.err  PERF_EXIT_CODE=$? -../common/check_all_lines_matched.pl "$RE_LINE_EMPTY" "$RE_LINE_COMMENT" < $LOGS_DIR/basic_symbols.log +"$DIR_PATH/../common/check_all_lines_matched.pl" \ +	"$RE_LINE_EMPTY" "$RE_LINE_COMMENT" < $LOGS_DIR/basic_symbols.log  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_symbols.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_symbols.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing symbol" @@ -174,9 +207,11 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing symbol"  $CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data --symbol-filter=map > $LOGS_DIR/basic_symbolfilter.log 2> $LOGS_DIR/basic_symbolfilter.err  PERF_EXIT_CODE=$? -grep -P -v '^#' $LOGS_DIR/basic_symbolfilter.log | grep -P '\s+[\d\.]+%' | ../common/check_all_lines_matched.pl "\[[k\.]\]\s+.*map" +grep -P -v '^#' $LOGS_DIR/basic_symbolfilter.log | grep -P '\s+[\d\.]+%' | \ +	"$DIR_PATH/../common/check_all_lines_matched.pl" "\[[k\.]\]\s+.*map"  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/basic_symbolfilter.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"$DIR_PATH/stderr-whitelist.txt" < $LOGS_DIR/basic_symbolfilter.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "symbol filter" @@ -189,7 +224,8 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "symbol filter"  $CMD_PERF report -i $CURRENT_TEST_DIR/perf.data.1 --stdio --header-only > $LOGS_DIR/latency_header.log  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl ", context_switch = 1, " < $LOGS_DIR/latency_header.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	", context_switch = 1, " < $LOGS_DIR/latency_header.log  CHECK_EXIT_CODE=$?  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "latency header" @@ -200,9 +236,11 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "latency header"  $CMD_PERF report --stdio -i $CURRENT_TEST_DIR/perf.data.1 > $LOGS_DIR/latency_default.log 2> $LOGS_DIR/latency_default.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "# Overhead   Latency  Command" < $LOGS_DIR/latency_default.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"# Overhead   Latency  Command" < $LOGS_DIR/latency_default.log  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/latency_default.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"stderr-whitelist.txt" < $LOGS_DIR/latency_default.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "default report for latency profile" @@ -213,9 +251,11 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "default report for latency profi  $CMD_PERF report --latency --stdio -i $CURRENT_TEST_DIR/perf.data.1 > $LOGS_DIR/latency_latency.log 2> $LOGS_DIR/latency_latency.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "#  Latency  Overhead  Command" < $LOGS_DIR/latency_latency.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"#  Latency  Overhead  Command" < $LOGS_DIR/latency_latency.log  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/latency_latency.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"stderr-whitelist.txt" < $LOGS_DIR/latency_latency.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "latency report for latency profile" @@ -226,9 +266,12 @@ print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "latency report for latency profi  $CMD_PERF report --hierarchy --sort latency,parallelism,comm,symbol --parallelism=1,2 --stdio -i $CURRENT_TEST_DIR/perf.data.1 > $LOGS_DIR/parallelism_hierarchy.log 2> $LOGS_DIR/parallelism_hierarchy.err  PERF_EXIT_CODE=$? -../common/check_all_patterns_found.pl "#           Latency  Parallelism / Command / Symbol" < $LOGS_DIR/parallelism_hierarchy.log +"$DIR_PATH/../common/check_all_patterns_found.pl" \ +	"#           Latency  Parallelism / Command / Symbol" \ +	< $LOGS_DIR/parallelism_hierarchy.log  CHECK_EXIT_CODE=$? -../common/check_errors_whitelisted.pl "stderr-whitelist.txt" < $LOGS_DIR/parallelism_hierarchy.err +"$DIR_PATH/../common/check_errors_whitelisted.pl" \ +	"stderr-whitelist.txt" < $LOGS_DIR/parallelism_hierarchy.err  (( CHECK_EXIT_CODE += $? ))  print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "parallelism histogram" diff --git a/tools/perf/tests/shell/common/init.sh b/tools/perf/tests/shell/common/init.sh index 26c7525651e0..cbfc78bec974 100644 --- a/tools/perf/tests/shell/common/init.sh +++ b/tools/perf/tests/shell/common/init.sh @@ -11,8 +11,8 @@  # -. ../common/settings.sh -. ../common/patterns.sh +. "$(dirname $0)/../common/settings.sh" +. "$(dirname $0)/../common/patterns.sh"  THIS_TEST_NAME=`basename $0 .sh` diff --git a/tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c b/tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c index 5f886cd09e6b..7e879217be30 100644 --- a/tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c +++ b/tools/perf/tests/shell/coresight/memcpy_thread/memcpy_thread.c @@ -27,6 +27,8 @@ static void *thrfn(void *arg)  	}  	for (i = 0; i < len; i++)  		memcpy(dst, src, a->size * 1024); + +	return NULL;  }  static pthread_t new_thr(void *(*fn) (void *arg), void *arg) diff --git a/tools/perf/tests/shell/coresight/thread_loop/thread_loop.c b/tools/perf/tests/shell/coresight/thread_loop/thread_loop.c index e05a559253ca..86f3f548b006 100644 --- a/tools/perf/tests/shell/coresight/thread_loop/thread_loop.c +++ b/tools/perf/tests/shell/coresight/thread_loop/thread_loop.c @@ -34,8 +34,8 @@ static void *thrfn(void *arg)  	}  	asm volatile(  		"loop:\n" -		"add %[i], %[i], #1\n" -		"cmp %[i], %[len]\n" +		"add %w[i], %w[i], #1\n" +		"cmp %w[i], %w[len]\n"  		"blt loop\n"  		: /* out */  		: /* in */ [i] "r" (i), [len] "r" (len) diff --git a/tools/perf/tests/shell/coresight/unroll_loop_thread/unroll_loop_thread.c b/tools/perf/tests/shell/coresight/unroll_loop_thread/unroll_loop_thread.c index 0fc7bf1a25af..8f4e1c985ca3 100644 --- a/tools/perf/tests/shell/coresight/unroll_loop_thread/unroll_loop_thread.c +++ b/tools/perf/tests/shell/coresight/unroll_loop_thread/unroll_loop_thread.c @@ -20,7 +20,7 @@ static void *thrfn(void *arg)  	for (i = 0; i < 10000; i++) {  		asm volatile (  // force an unroll of thia add instruction so we can test long runs of code -#define SNIP1 "add %[in], %[in], #1\n" +#define SNIP1 "add %w[in], %w[in], #1\n"  // 10  #define SNIP2 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1 SNIP1  // 100 @@ -36,6 +36,8 @@ static void *thrfn(void *arg)  			: /* clobber */  		);  	} + +	return NULL;  }  static pthread_t new_thr(void *(*fn) (void *arg), void *arg) diff --git a/tools/perf/tests/shell/lock_contention.sh b/tools/perf/tests/shell/lock_contention.sh index d33d9e4392b0..7248a74ca2a3 100755 --- a/tools/perf/tests/shell/lock_contention.sh +++ b/tools/perf/tests/shell/lock_contention.sh @@ -7,14 +7,17 @@ set -e  err=0  perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX)  result=$(mktemp /tmp/__perf_test.result.XXXXX) +errout=$(mktemp /tmp/__perf_test.errout.XXXXX)  cleanup() {  	rm -f ${perfdata}  	rm -f ${result} +	rm -f ${errout}  	trap - EXIT TERM INT  }  trap_cleanup() { +	echo "Unexpected signal in ${FUNCNAME[1]}"  	cleanup  	exit ${err}  } @@ -75,10 +78,12 @@ test_bpf()  test_record_concurrent()  {  	echo "Testing perf lock record and perf lock contention at the same time" -	perf lock record -o- -- perf bench sched messaging -p 2> /dev/null | \ +	perf lock record -o- -- perf bench sched messaging -p 2> ${errout} | \  	perf lock contention -i- -E 1 -q 2> ${result}  	if [ "$(cat "${result}" | wc -l)" != "1" ]; then  		echo "[Fail] Recorded result count is not 1:" "$(cat "${result}" | wc -l)" +		cat ${errout} +		cat ${result}  		err=1  		exit  	fi diff --git a/tools/perf/tests/shell/python-use.sh b/tools/perf/tests/shell/python-use.sh new file mode 100755 index 000000000000..fd2ee5390060 --- /dev/null +++ b/tools/perf/tests/shell/python-use.sh @@ -0,0 +1,36 @@ +#!/bin/bash +# 'import perf' in python +# SPDX-License-Identifier: GPL-2.0 +# Just test if we can load the python binding. +set -e + +shelldir=$(dirname "$0") +# shellcheck source=lib/setup_python.sh +. "${shelldir}"/lib/setup_python.sh + +MODULE_DIR=$(dirname "$(which perf)")/python + +if [ -d "$MODULE_DIR" ] +then +    CMD=$(cat <<EOF +import sys +sys.path.insert(0, '$MODULE_DIR') +import perf +print('success!') +EOF +    ) +else +    CMD=$(cat <<EOF +import perf +print('success!') +EOF +    ) +fi + +echo -e "Testing 'import perf' with:\n$CMD" + +if ! echo "$CMD" | $PYTHON | grep -q "success!" +then +  exit 1 +fi +exit 0 diff --git a/tools/perf/tests/shell/record.sh b/tools/perf/tests/shell/record.sh index b1ad24fb3b33..0f5841c479e7 100755 --- a/tools/perf/tests/shell/record.sh +++ b/tools/perf/tests/shell/record.sh @@ -388,6 +388,45 @@ test_callgraph() {    echo "Callgraph test [Success]"  } +test_ratio_to_prev() { +  echo "ratio-to-prev test" +  if ! perf record -o /dev/null -e "{instructions, cycles/period=100000,ratio-to-prev=0.5/}" \ +     true 2> /dev/null +  then +    echo "ratio-to-prev [Skipped not supported]" +    return +  fi +  if ! perf record -o /dev/null -e "instructions, cycles/period=100000,ratio-to-prev=0.5/" \ +     true |& grep -q 'Invalid use of ratio-to-prev term without preceding element in group' +  then +    echo "ratio-to-prev test [Failed elements must be in same group]" +    err=1 +    return +  fi +  if ! perf record -o /dev/null -e "{instructions,dummy,cycles/period=100000,ratio-to-prev=0.5/}" \ +     true |& grep -q 'must have same PMU' +  then +    echo "ratio-to-prev test [Failed elements must have same PMU]" +    err=1 +    return +  fi +  if ! perf record -o /dev/null -e "{instructions,cycles/ratio-to-prev=0.5/}" \ +     true |& grep -q 'Event period term or count (-c) must be set when using ratio-to-prev term.' +  then +    echo "ratio-to-prev test [Failed period must be set]" +    err=1 +    return +  fi +  if ! perf record -o /dev/null -e "{cycles/ratio-to-prev=0.5/}" \ +     true |& grep -q 'Invalid use of ratio-to-prev term without preceding element in group' +  then +    echo "ratio-to-prev test [Failed need 2+ events]" +    err=1 +    return +  fi +  echo "Basic ratio-to-prev record test [Success]" +} +  # raise the limit of file descriptors to minimum  if [[ $default_fd_limit -lt $min_fd_limit ]]; then         ulimit -Sn $min_fd_limit @@ -404,6 +443,7 @@ test_leader_sampling  test_topdown_leader_sampling  test_precise_max  test_callgraph +test_ratio_to_prev  # restore the default value  ulimit -Sn $default_fd_limit diff --git a/tools/perf/tests/shell/record_lbr.sh b/tools/perf/tests/shell/record_lbr.sh index 6fcb5e52b9b4..78a02e90ece1 100755 --- a/tools/perf/tests/shell/record_lbr.sh +++ b/tools/perf/tests/shell/record_lbr.sh @@ -4,6 +4,10 @@  set -e +ParanoidAndNotRoot() { +  [ "$(id -u)" != 0 ] && [ "$(cat /proc/sys/kernel/perf_event_paranoid)" -gt $1 ] +} +  if [ ! -f /sys/bus/event_source/devices/cpu/caps/branches ] &&     [ ! -f /sys/bus/event_source/devices/cpu_core/caps/branches ]  then @@ -23,6 +27,7 @@ cleanup() {  }  trap_cleanup() { +  echo "Unexpected signal in ${FUNCNAME[1]}"    cleanup    exit 1  } @@ -123,8 +128,11 @@ lbr_test "-j ind_call" "any indirect call" 2  lbr_test "-j ind_jmp" "any indirect jump" 100  lbr_test "-j call" "direct calls" 2  lbr_test "-j ind_call,u" "any indirect user call" 100 -lbr_test "-a -b" "system wide any branch" 2 -lbr_test "-a -j any_call" "system wide any call" 2 +if ! ParanoidAndNotRoot 1 +then +  lbr_test "-a -b" "system wide any branch" 2 +  lbr_test "-a -j any_call" "system wide any call" 2 +fi  # Parallel  parallel_lbr_test "-b" "parallel any branch" 100 & @@ -141,10 +149,16 @@ parallel_lbr_test "-j call" "parallel direct calls" 100 &  pid6=$!  parallel_lbr_test "-j ind_call,u" "parallel any indirect user call" 100 &  pid7=$! -parallel_lbr_test "-a -b" "parallel system wide any branch" 100 & -pid8=$! -parallel_lbr_test "-a -j any_call" "parallel system wide any call" 100 & -pid9=$! +if ParanoidAndNotRoot 1 +then +  pid8= +  pid9= +else +  parallel_lbr_test "-a -b" "parallel system wide any branch" 100 & +  pid8=$! +  parallel_lbr_test "-a -j any_call" "parallel system wide any call" 100 & +  pid9=$! +fi  for pid in $pid1 $pid2 $pid3 $pid4 $pid5 $pid6 $pid7 $pid8 $pid9  do diff --git a/tools/perf/tests/shell/stat+event_uniquifying.sh b/tools/perf/tests/shell/stat+event_uniquifying.sh index bf54bd6c3e2e..b5dec6b6da36 100755 --- a/tools/perf/tests/shell/stat+event_uniquifying.sh +++ b/tools/perf/tests/shell/stat+event_uniquifying.sh @@ -4,74 +4,63 @@  set -e -stat_output=$(mktemp /tmp/__perf_test.stat_output.XXXXX) -perf_tool=perf  err=0 +stat_output=$(mktemp /tmp/__perf_test.stat_output.XXXXX) -test_event_uniquifying() { -  # We use `clockticks` in `uncore_imc` to verify the uniquify behavior. -  pmu="uncore_imc" -  event="clockticks" - -  # If the `-A` option is added, the event should be uniquified. -  # -  # $perf list -v clockticks -  # -  # List of pre-defined events (to be used in -e or -M): -  # -  #   uncore_imc_0/clockticks/                           [Kernel PMU event] -  #   uncore_imc_1/clockticks/                           [Kernel PMU event] -  #   uncore_imc_2/clockticks/                           [Kernel PMU event] -  #   uncore_imc_3/clockticks/                           [Kernel PMU event] -  #   uncore_imc_4/clockticks/                           [Kernel PMU event] -  #   uncore_imc_5/clockticks/                           [Kernel PMU event] -  # -  #   ... -  # -  # $perf stat -e clockticks -A -- true -  # -  #  Performance counter stats for 'system wide': -  # -  # CPU0            3,773,018      uncore_imc_0/clockticks/ -  # CPU0            3,609,025      uncore_imc_1/clockticks/ -  # CPU0                    0      uncore_imc_2/clockticks/ -  # CPU0            3,230,009      uncore_imc_3/clockticks/ -  # CPU0            3,049,897      uncore_imc_4/clockticks/ -  # CPU0                    0      uncore_imc_5/clockticks/ -  # -  #        0.002029828 seconds time elapsed - -  echo "stat event uniquifying test" -  uniquified_event_array=() +cleanup() { +  rm -f "${stat_output}" -  # Skip if the machine does not have `uncore_imc` device. -  if ! ${perf_tool} list pmu | grep -q ${pmu}; then -    echo "Target does not support PMU ${pmu} [Skipped]" -    err=2 -    return -  fi +  trap - EXIT TERM INT +} -  # Check how many uniquified events. -  while IFS= read -r line; do -    uniquified_event=$(echo "$line" | awk '{print $1}') -    uniquified_event_array+=("${uniquified_event}") -  done < <(${perf_tool} list -v ${event} | grep ${pmu}) +trap_cleanup() { +  echo "Unexpected signal in ${FUNCNAME[1]}" +  cleanup +  exit 1 +} +trap trap_cleanup EXIT TERM INT -  perf_command="${perf_tool} stat -e $event -A -o ${stat_output} -- true" -  $perf_command +test_event_uniquifying() { +  echo "Uniquification of PMU sysfs events test" -  # Check the output contains all uniquified events. -  for uniquified_event in "${uniquified_event_array[@]}"; do -    if ! cat "${stat_output}" | grep -q "${uniquified_event}"; then -      echo "Event is not uniquified [Failed]" -      echo "${perf_command}" -      cat "${stat_output}" -      err=1 -      break -    fi +  # Read events from perf list with and without -v. With -v the duplicate PMUs +  # aren't deduplicated. Note, json events are listed by perf list without a +  # PMU. +  read -ra pmu_events <<< "$(perf list --raw pmu)" +  read -ra pmu_v_events <<< "$(perf list -v --raw pmu)" +  # For all non-deduplicated events. +  for pmu_v_event in "${pmu_v_events[@]}"; do +    # If the event matches an event in the deduplicated events then it musn't +    # be an event with duplicate PMUs, continue the outer loop. +    for pmu_event in "${pmu_events[@]}"; do +      if [[ "$pmu_v_event" == "$pmu_event" ]]; then +        continue 2 +      fi +    done +    # Strip the suffix from the non-deduplicated event's PMU. +    event=$(echo "$pmu_v_event" | sed -E 's/_[0-9]+//') +    for pmu_event in "${pmu_events[@]}"; do +      if [[ "$event" == "$pmu_event" ]]; then +        echo "Testing event ${event} is uniquified to ${pmu_v_event}" +        if ! perf stat -e "$event" -A -o ${stat_output} -- true; then +          echo "Error running perf stat for event '$event'  [Skip]" +          if [ $err = 0 ]; then +            err=2 +          fi +          continue +        fi +        # Ensure the non-deduplicated event appears in the output. +        if ! grep -q "${pmu_v_event}" "${stat_output}"; then +          echo "Uniquification of PMU sysfs events test [Failed]" +          cat "${stat_output}" +          err=1 +        fi +        break +      fi +    done    done  }  test_event_uniquifying -rm -f "${stat_output}" +cleanup  exit $err diff --git a/tools/perf/tests/shell/stat+std_output.sh b/tools/perf/tests/shell/stat+std_output.sh index 6fee67693ba7..ec41f24299d9 100755 --- a/tools/perf/tests/shell/stat+std_output.sh +++ b/tools/perf/tests/shell/stat+std_output.sh @@ -90,7 +90,11 @@ function commachecker()  		}  	done < "${stat_output}" -	[ $metric_only -eq 1 ] && exit 1 +	if [ $metric_only -ne 1 ] +	then +		echo "Missing metric only output in:" +		cat "${stat_output}" +	fi  	return 0  } diff --git a/tools/perf/tests/shell/test_brstack.sh b/tools/perf/tests/shell/test_brstack.sh index 9138fa83bf36..85233d435be6 100755 --- a/tools/perf/tests/shell/test_brstack.sh +++ b/tools/perf/tests/shell/test_brstack.sh @@ -34,6 +34,17 @@ trap_cleanup() {  }  trap trap_cleanup EXIT TERM INT +is_arm64() { +	[ "$(uname -m)" = "aarch64" ]; +} + +check_branches() { +	if ! tr -s ' ' '\n' < "$TMPDIR/perf.script" | grep -E -m1 -q "$1"; then +		echo "Branches missing $1" +		err=1 +	fi +} +  test_user_branches() {  	echo "Testing user branch stack sampling" @@ -55,14 +66,67 @@ test_user_branches() {  	)  	for x in "${expected[@]}"  	do -		if ! tr -s ' ' '\n' < "$TMPDIR/perf.script" | grep -E -m1 -q "$x" -		then -			echo "Branches missing $x" -			err=1 -		fi +		check_branches "$x"  	done + +	# Dump addresses only this time +	perf script -i "$TMPDIR/perf.data" --fields brstack | \ +		tr ' ' '\n' > "$TMPDIR/perf.script" + +	# There should be no kernel addresses with the u option, in either +	# source or target addresses. +	if grep -E -m1 "0x[89a-f][0-9a-f]{15}" $TMPDIR/perf.script; then +		echo "ERROR: Kernel address found in user mode" +		err=1 +	fi  	# some branch types are still not being tested: -	# IND COND_CALL COND_RET SYSCALL SYSRET IRQ SERROR NO_TX +	# IND COND_CALL COND_RET SYSRET SERROR NO_TX +} + +test_trap_eret_branches() { +	echo "Testing trap & eret branches" +	if ! is_arm64; then +		echo "skip: not arm64" +	else +		perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u,k -- \ +			perf test -w traploop 1000 +		perf script -i $TMPDIR/perf.data --fields brstacksym | \ +			tr ' ' '\n' > $TMPDIR/perf.script + +		# BRBINF<n>.TYPE == TRAP are mapped to PERF_BR_IRQ by the BRBE driver +		check_branches "^trap_bench\+[^ ]+/[^ ]/IRQ/" +		check_branches "^[^ ]+/trap_bench\+[^ ]+/ERET/" +	fi +} + +test_kernel_branches() { +	echo "Testing that k option only includes kernel source addresses" + +	if ! perf record --branch-filter any,k -o- -- true > /dev/null; then +		echo "skip: not enough privileges" +	else +		perf record -o $TMPDIR/perf.data --branch-filter any,k -- \ +			perf bench syscall basic --loop 1000 +		perf script -i $TMPDIR/perf.data --fields brstack | \ +			tr ' ' '\n' > $TMPDIR/perf.script + +		# Example of branch entries: +		#       "0xffffffff93bda241/0xffffffff93bda20f/M/-/-/..." +		# Source addresses come first and target address can be either +		# userspace or kernel even with k option, as long as the source +		# is in kernel. + +		#Look for source addresses with top bit set +		if ! grep -E -m1 "^0x[89a-f][0-9a-f]{15}" $TMPDIR/perf.script; then +			echo "ERROR: Kernel branches missing" +			err=1 +		fi +		# Look for no source addresses without top bit set +		if grep -E -m1 "^0x[0-7][0-9a-f]{0,15}" $TMPDIR/perf.script; then +			echo "ERROR: User branches found with kernel filter" +			err=1 +		fi +	fi  }  # first argument <arg0> is the argument passed to "--branch-stack <arg0>,save_type,u" @@ -97,18 +161,42 @@ test_filter() {  	fi  } +test_syscall() { +	echo "Testing syscalls" +	# skip if perf doesn't have enough privileges +	if ! perf record --branch-filter any,k -o- -- true > /dev/null; then +		echo "skip: not enough privileges" +	else +		perf record -o $TMPDIR/perf.data --branch-filter \ +			any_call,save_type,u,k -c 10000 -- \ +			perf bench syscall basic --loop 1000 +		perf script -i $TMPDIR/perf.data --fields brstacksym | \ +			tr ' ' '\n' > $TMPDIR/perf.script + +		check_branches "getppid[^ ]*/SYSCALL/" +	fi +}  set -e  test_user_branches +test_syscall +test_kernel_branches +test_trap_eret_branches + +any_call="CALL|IND_CALL|COND_CALL|SYSCALL|IRQ" + +if is_arm64; then +	any_call="$any_call|FAULT_DATA|FAULT_INST" +fi -test_filter "any_call"	"CALL|IND_CALL|COND_CALL|SYSCALL|IRQ" +test_filter "any_call" "$any_call"  test_filter "call"	"CALL|SYSCALL"  test_filter "cond"	"COND"  test_filter "any_ret"	"RET|COND_RET|SYSRET|ERET"  test_filter "call,cond"		"CALL|SYSCALL|COND" -test_filter "any_call,cond"		"CALL|IND_CALL|COND_CALL|IRQ|SYSCALL|COND" -test_filter "cond,any_call,any_ret"	"COND|CALL|IND_CALL|COND_CALL|SYSCALL|IRQ|RET|COND_RET|SYSRET|ERET" +test_filter "any_call,cond"	    "$any_call|COND" +test_filter "any_call,cond,any_ret" "$any_call|COND|RET|COND_RET"  cleanup  exit $err diff --git a/tools/perf/tests/shell/trace_btf_enum.sh b/tools/perf/tests/shell/trace_btf_enum.sh index 572001d75d78..03e9f680a4a6 100755 --- a/tools/perf/tests/shell/trace_btf_enum.sh +++ b/tools/perf/tests/shell/trace_btf_enum.sh @@ -23,6 +23,14 @@ check_vmlinux() {    fi  } +check_permissions() { +  if perf trace -e $syscall $TESTPROG 2>&1 | grep -q "Operation not permitted" +  then +    echo "trace+enum test [Skipped permissions]" +    err=2 +  fi +} +  trace_landlock() {    echo "Tracing syscall ${syscall}" @@ -56,6 +64,9 @@ trace_non_syscall() {  }  check_vmlinux +if [ $err = 0 ]; then +  check_permissions +fi  if [ $err = 0 ]; then    trace_landlock diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h index 97e62db8764a..33de16dde737 100644 --- a/tools/perf/tests/tests.h +++ b/tools/perf/tests/tests.h @@ -120,7 +120,6 @@ DECLARE_SUITE(dso_data_cache);  DECLARE_SUITE(dso_data_reopen);  DECLARE_SUITE(parse_events);  DECLARE_SUITE(hists_link); -DECLARE_SUITE(python_use);  DECLARE_SUITE(bp_signal);  DECLARE_SUITE(bp_signal_overflow);  DECLARE_SUITE(bp_accounting); @@ -239,6 +238,7 @@ DECLARE_WORKLOAD(sqrtloop);  DECLARE_WORKLOAD(brstack);  DECLARE_WORKLOAD(datasym);  DECLARE_WORKLOAD(landlock); +DECLARE_WORKLOAD(traploop);  extern const char *dso_to_test;  extern const char *test_objdump_path; diff --git a/tools/perf/tests/workloads/Build b/tools/perf/tests/workloads/Build index 5af17206f04d..fb1012cc4fc3 100644 --- a/tools/perf/tests/workloads/Build +++ b/tools/perf/tests/workloads/Build @@ -7,8 +7,10 @@ perf-test-y += sqrtloop.o  perf-test-y += brstack.o  perf-test-y += datasym.o  perf-test-y += landlock.o +perf-test-y += traploop.o  CFLAGS_sqrtloop.o         = -g -O0 -fno-inline -U_FORTIFY_SOURCE  CFLAGS_leafloop.o         = -g -O0 -fno-inline -fno-omit-frame-pointer -U_FORTIFY_SOURCE  CFLAGS_brstack.o          = -g -O0 -fno-inline -U_FORTIFY_SOURCE  CFLAGS_datasym.o          = -g -O0 -fno-inline -U_FORTIFY_SOURCE +CFLAGS_traploop.o         = -g -O0 -fno-inline -U_FORTIFY_SOURCE diff --git a/tools/perf/tests/workloads/traploop.c b/tools/perf/tests/workloads/traploop.c new file mode 100644 index 000000000000..68dec399a735 --- /dev/null +++ b/tools/perf/tests/workloads/traploop.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +#include <stdlib.h> +#include "../tests.h" + +#define BENCH_RUNS 999999 + +#ifdef __aarch64__ +static void trap_bench(void) +{ +	unsigned long val; + +	asm("mrs %0, ID_AA64ISAR0_EL1" : "=r" (val));   /* TRAP + ERET */ +} +#else +static void trap_bench(void) { } +#endif + +static int traploop(int argc, const char **argv) +{ +	int num_loops = BENCH_RUNS; + +	if (argc > 0) +		num_loops = atoi(argv[0]); + +	for (int i = 0; i < num_loops; i++) +		trap_bench(); + +	return 0; +} + +DEFINE_WORKLOAD(traploop);  | 
