Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Replace brstack test workload

So that it can get rid of requirement of a compiler. Also rename the
symbols to match with the perf test workload.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Tested-by: James Clark <james.clark@arm.com>
Acked-by: German Gomez <german.gomez@arm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zhengjun Xing <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221116233854.1596378-11-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
7bc1dd96 a104f0ea

+12 -54
+12 -54
tools/perf/tests/shell/test_brstack.sh
··· 4 4 # SPDX-License-Identifier: GPL-2.0 5 5 # German Gomez <german.gomez@arm.com>, 2022 6 6 7 - # we need a C compiler to build the test programs 8 - # so bail if none is found 9 - if ! [ -x "$(command -v cc)" ]; then 10 - echo "failed: no compiler, install gcc" 11 - exit 2 12 - fi 13 - 14 7 # skip the test if the hardware doesn't support branch stack sampling 15 8 # and if the architecture doesn't support filter types: any,save_type,u 16 9 if ! perf record -o- --no-buildid --branch-filter any,save_type,u -- true > /dev/null 2>&1 ; then ··· 12 19 fi 13 20 14 21 TMPDIR=$(mktemp -d /tmp/__perf_test.program.XXXXX) 22 + TESTPROG="perf test -w brstack" 15 23 16 24 cleanup() { 17 25 rm -rf $TMPDIR ··· 20 26 21 27 trap cleanup exit term int 22 28 23 - gen_test_program() { 24 - # generate test program 25 - cat << EOF > $1 26 - #define BENCH_RUNS 999999 27 - int cnt; 28 - void bar(void) { 29 - } /* return */ 30 - void foo(void) { 31 - bar(); /* call */ 32 - } /* return */ 33 - void bench(void) { 34 - void (*foo_ind)(void) = foo; 35 - if ((cnt++) % 3) /* branch (cond) */ 36 - foo(); /* call */ 37 - bar(); /* call */ 38 - foo_ind(); /* call (ind) */ 39 - } 40 - int main(void) 41 - { 42 - int cnt = 0; 43 - while (1) { 44 - if ((cnt++) > BENCH_RUNS) 45 - break; 46 - bench(); /* call */ 47 - } /* branch (uncond) */ 48 - return 0; 49 - } 50 - EOF 51 - } 52 - 53 29 test_user_branches() { 54 30 echo "Testing user branch stack sampling" 55 31 56 - gen_test_program "$TEMPDIR/program.c" 57 - cc -fno-inline -g "$TEMPDIR/program.c" -o $TMPDIR/a.out 58 - 59 - perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u -- $TMPDIR/a.out > /dev/null 2>&1 32 + perf record -o $TMPDIR/perf.data --branch-filter any,save_type,u -- ${TESTPROG} > /dev/null 2>&1 60 33 perf script -i $TMPDIR/perf.data --fields brstacksym | xargs -n1 > $TMPDIR/perf.script 61 34 62 35 # example of branch entries: 63 - # foo+0x14/bar+0x40/P/-/-/0/CALL 36 + # brstack_foo+0x14/brstack_bar+0x40/P/-/-/0/CALL 64 37 65 38 set -x 66 - egrep -m1 "^bench\+[^ ]*/foo\+[^ ]*/IND_CALL$" $TMPDIR/perf.script 67 - egrep -m1 "^foo\+[^ ]*/bar\+[^ ]*/CALL$" $TMPDIR/perf.script 68 - egrep -m1 "^bench\+[^ ]*/foo\+[^ ]*/CALL$" $TMPDIR/perf.script 69 - egrep -m1 "^bench\+[^ ]*/bar\+[^ ]*/CALL$" $TMPDIR/perf.script 70 - egrep -m1 "^bar\+[^ ]*/foo\+[^ ]*/RET$" $TMPDIR/perf.script 71 - egrep -m1 "^foo\+[^ ]*/bench\+[^ ]*/RET$" $TMPDIR/perf.script 72 - egrep -m1 "^bench\+[^ ]*/bench\+[^ ]*/COND$" $TMPDIR/perf.script 73 - egrep -m1 "^main\+[^ ]*/main\+[^ ]*/UNCOND$" $TMPDIR/perf.script 39 + egrep -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/IND_CALL$" $TMPDIR/perf.script 40 + egrep -m1 "^brstack_foo\+[^ ]*/brstack_bar\+[^ ]*/CALL$" $TMPDIR/perf.script 41 + egrep -m1 "^brstack_bench\+[^ ]*/brstack_foo\+[^ ]*/CALL$" $TMPDIR/perf.script 42 + egrep -m1 "^brstack_bench\+[^ ]*/brstack_bar\+[^ ]*/CALL$" $TMPDIR/perf.script 43 + egrep -m1 "^brstack_bar\+[^ ]*/brstack_foo\+[^ ]*/RET$" $TMPDIR/perf.script 44 + egrep -m1 "^brstack_foo\+[^ ]*/brstack_bench\+[^ ]*/RET$" $TMPDIR/perf.script 45 + egrep -m1 "^brstack_bench\+[^ ]*/brstack_bench\+[^ ]*/COND$" $TMPDIR/perf.script 46 + egrep -m1 "^brstack\+[^ ]*/brstack\+[^ ]*/UNCOND$" $TMPDIR/perf.script 74 47 set +x 75 48 76 49 # some branch types are still not being tested: ··· 52 91 53 92 echo "Testing branch stack filtering permutation ($filter,$expect)" 54 93 55 - gen_test_program "$TEMPDIR/program.c" 56 - cc -fno-inline -g "$TEMPDIR/program.c" -o $TMPDIR/a.out 57 - 58 - perf record -o $TMPDIR/perf.data --branch-filter $filter,save_type,u -- $TMPDIR/a.out > /dev/null 2>&1 94 + perf record -o $TMPDIR/perf.data --branch-filter $filter,save_type,u -- ${TESTPROG} > /dev/null 2>&1 59 95 perf script -i $TMPDIR/perf.data --fields brstack | xargs -n1 > $TMPDIR/perf.script 60 96 61 97 # fail if we find any branch type that doesn't match any of the expected ones