diff options
Diffstat (limited to 'tools/perf/tests/shell')
| -rwxr-xr-x | tools/perf/tests/shell/annotate.sh | 10 | ||||
| -rwxr-xr-x | tools/perf/tests/shell/base_probe/test_adding_kernel.sh | 31 | ||||
| -rwxr-xr-x | tools/perf/tests/shell/stat_bpf_counters.sh | 36 | ||||
| -rwxr-xr-x | tools/perf/tests/shell/test_arm_callgraph_fp.sh | 27 | ||||
| -rwxr-xr-x | tools/perf/tests/shell/test_uprobe_from_different_cu.sh | 2 |
5 files changed, 64 insertions, 42 deletions
diff --git a/tools/perf/tests/shell/annotate.sh b/tools/perf/tests/shell/annotate.sh index 1db1e8113d99..b072d9b97387 100755 --- a/tools/perf/tests/shell/annotate.sh +++ b/tools/perf/tests/shell/annotate.sh @@ -15,12 +15,13 @@ skip_test_missing_symbol ${testsym} err=0 perfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) +perfout=$(mktemp /tmp/__perf_test.perf.out.XXXXX) testprog="perf test -w noploop" # disassembly format: "percent : offset: instruction (operands ...)" disasm_regex="[0-9]*\.[0-9]* *: *\w*: *\w*" cleanup() { - rm -rf "${perfdata}" + rm -rf "${perfdata}" "${perfout}" rm -rf "${perfdata}".old trap - EXIT TERM INT @@ -41,8 +42,11 @@ test_basic() { return fi + # Generate the annotated output file + perf annotate -i "${perfdata}" --stdio 2> /dev/null > "${perfout}" + # check if it has the target symbol - if ! perf annotate -i "${perfdata}" 2> /dev/null | grep "${testsym}" + if ! grep "${testsym}" "${perfout}" then echo "Basic annotate [Failed: missing target symbol]" err=1 @@ -50,7 +54,7 @@ test_basic() { fi # check if it has the disassembly lines - if ! perf annotate -i "${perfdata}" 2> /dev/null | grep "${disasm_regex}" + if ! grep "${disasm_regex}" "${perfout}" then echo "Basic annotate [Failed: missing disasm output from default disassembler]" err=1 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 63bb8974b38e..187dc8d4b163 100755 --- a/tools/perf/tests/shell/base_probe/test_adding_kernel.sh +++ b/tools/perf/tests/shell/base_probe/test_adding_kernel.sh @@ -21,8 +21,18 @@ THIS_TEST_NAME=`basename $0 .sh` TEST_RESULT=0 +# shellcheck source=lib/probe_vfs_getname.sh +. "$(dirname "$0")/../lib/probe_vfs_getname.sh" + TEST_PROBE=${TEST_PROBE:-"inode_permission"} +# set NO_DEBUGINFO to skip testcase if debuginfo is not present +# skip_if_no_debuginfo returns 2 if debuginfo is not present +skip_if_no_debuginfo +if [ $? -eq 2 ]; then + NO_DEBUGINFO=1 +fi + check_kprobes_available if [ $? -ne 0 ]; then print_overall_skipped @@ -67,7 +77,12 @@ 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 CHECK_EXIT_CODE=$? -print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing added probe :: perf probe -l" +if [ $NO_DEBUGINFO ] ; then + print_testcase_skipped $NO_DEBUGINFO $NO_DEBUGINFO "Skipped due to missing debuginfo" +else + print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "listing added probe :: perf probe -l" +fi + (( TEST_RESULT += $? )) @@ -208,7 +223,12 @@ 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 CHECK_EXIT_CODE=$? -print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "wildcard adding support" +if [ $NO_DEBUGINFO ] ; then + print_testcase_skipped $NO_DEBUGINFO $NO_DEBUGINFO "Skipped due to missing debuginfo" +else + print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "wildcard adding support" +fi + (( TEST_RESULT += $? )) @@ -232,7 +252,12 @@ CHECK_EXIT_CODE=$? ../common/check_no_patterns_found.pl "$RE_SEGFAULT" < $LOGS_DIR/adding_kernel_nonexisting.err (( CHECK_EXIT_CODE += $? )) -print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing variable" +if [ $NO_DEBUGINFO ]; then + print_testcase_skipped $NO_DEBUGINFO $NO_DEBUGINFO "Skipped due to missing debuginfo" +else + print_results $PERF_EXIT_CODE $CHECK_EXIT_CODE "non-existing variable" +fi + (( TEST_RESULT += $? )) diff --git a/tools/perf/tests/shell/stat_bpf_counters.sh b/tools/perf/tests/shell/stat_bpf_counters.sh index 61f8149d854e..f250b7d6f773 100755 --- a/tools/perf/tests/shell/stat_bpf_counters.sh +++ b/tools/perf/tests/shell/stat_bpf_counters.sh @@ -4,7 +4,7 @@ set -e -workload="perf bench sched messaging -g 1 -l 100 -t" +workload="perf test -w brstack" # check whether $2 is within +/- 20% of $1 compare_number() @@ -25,15 +25,15 @@ compare_number() check_counts() { - base_cycles=$1 - bpf_cycles=$2 + base_instructions=$1 + bpf_instructions=$2 - if [ "$base_cycles" = "<not" ]; then - echo "Skipping: cycles event not counted" + if [ "$base_instructions" = "<not" ]; then + echo "Skipping: instructions event not counted" exit 2 fi - if [ "$bpf_cycles" = "<not" ]; then - echo "Failed: cycles not counted with --bpf-counters" + if [ "$bpf_instructions" = "<not" ]; then + echo "Failed: instructions not counted with --bpf-counters" exit 1 fi } @@ -41,29 +41,29 @@ check_counts() test_bpf_counters() { printf "Testing --bpf-counters " - base_cycles=$(perf stat --no-big-num -e cycles -- $workload 2>&1 | awk '/cycles/ {print $1}') - bpf_cycles=$(perf stat --no-big-num --bpf-counters -e cycles -- $workload 2>&1 | awk '/cycles/ {print $1}') - check_counts $base_cycles $bpf_cycles - compare_number $base_cycles $bpf_cycles + base_instructions=$(perf stat --no-big-num -e instructions -- $workload 2>&1 | awk '/instructions/ {print $1}') + bpf_instructions=$(perf stat --no-big-num --bpf-counters -e instructions -- $workload 2>&1 | awk '/instructions/ {print $1}') + check_counts $base_instructions $bpf_instructions + compare_number $base_instructions $bpf_instructions echo "[Success]" } test_bpf_modifier() { printf "Testing bpf event modifier " - stat_output=$(perf stat --no-big-num -e cycles/name=base_cycles/,cycles/name=bpf_cycles/b -- $workload 2>&1) - base_cycles=$(echo "$stat_output"| awk '/base_cycles/ {print $1}') - bpf_cycles=$(echo "$stat_output"| awk '/bpf_cycles/ {print $1}') - check_counts $base_cycles $bpf_cycles - compare_number $base_cycles $bpf_cycles + stat_output=$(perf stat --no-big-num -e instructions/name=base_instructions/,instructions/name=bpf_instructions/b -- $workload 2>&1) + base_instructions=$(echo "$stat_output"| awk '/base_instructions/ {print $1}') + bpf_instructions=$(echo "$stat_output"| awk '/bpf_instructions/ {print $1}') + check_counts $base_instructions $bpf_instructions + compare_number $base_instructions $bpf_instructions echo "[Success]" } # skip if --bpf-counters is not supported -if ! perf stat -e cycles --bpf-counters true > /dev/null 2>&1; then +if ! perf stat -e instructions --bpf-counters true > /dev/null 2>&1; then if [ "$1" = "-v" ]; then echo "Skipping: --bpf-counters not supported" - perf --no-pager stat -e cycles --bpf-counters true || true + perf --no-pager stat -e instructions --bpf-counters true || true fi exit 2 fi diff --git a/tools/perf/tests/shell/test_arm_callgraph_fp.sh b/tools/perf/tests/shell/test_arm_callgraph_fp.sh index 61898e256616..9caa36130175 100755 --- a/tools/perf/tests/shell/test_arm_callgraph_fp.sh +++ b/tools/perf/tests/shell/test_arm_callgraph_fp.sh @@ -28,28 +28,21 @@ cleanup_files() trap cleanup_files EXIT TERM INT -# Add a 1 second delay to skip samples that are not in the leaf() function # shellcheck disable=SC2086 -perf record -o "$PERF_DATA" --call-graph fp -e cycles//u -D 1000 --user-callchains -- $TEST_PROGRAM 2> /dev/null & -PID=$! +perf record -o "$PERF_DATA" --call-graph fp -e cycles//u --user-callchains -- $TEST_PROGRAM -echo " + Recording (PID=$PID)..." -sleep 2 -echo " + Stopping perf-record..." - -kill $PID -wait $PID +# Try opening the file so any immediate errors are visible in the log +perf script -i "$PERF_DATA" -F comm,ip,sym | head -n4 -# expected perf-script output: +# expected perf-script output if 'leaf' has been inserted correctly: # -# program +# perf # 728 leaf # 753 parent # 76c leafloop -# ... +# ... remaining stack to main() ... -perf script -i "$PERF_DATA" -F comm,ip,sym | head -n4 -perf script -i "$PERF_DATA" -F comm,ip,sym | head -n4 | \ - awk '{ if ($2 != "") sym[i++] = $2 } END { if (sym[0] != "leaf" || - sym[1] != "parent" || - sym[2] != "leafloop") exit 1 }' +# Each frame is separated by a tab, some spaces and an address +SEP="[[:space:]]+ [[:xdigit:]]+" +perf script -i "$PERF_DATA" -F comm,ip,sym | tr '\n' ' ' | \ + grep -E -q "perf $SEP leaf $SEP parent $SEP leafloop" diff --git a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh index 319f36ebb9a4..82bc774a078a 100755 --- a/tools/perf/tests/shell/test_uprobe_from_different_cu.sh +++ b/tools/perf/tests/shell/test_uprobe_from_different_cu.sh @@ -77,7 +77,7 @@ gcc -g -Og -flto -c ${temp_dir}/testfile-foo.c -o ${temp_dir}/testfile-foo.o gcc -g -Og -c ${temp_dir}/testfile-main.c -o ${temp_dir}/testfile-main.o gcc -g -Og -o ${temp_dir}/testfile ${temp_dir}/testfile-foo.o ${temp_dir}/testfile-main.o -perf probe -x ${temp_dir}/testfile --funcs foo +perf probe -x ${temp_dir}/testfile --funcs foo | grep "foo" perf probe -x ${temp_dir}/testfile foo cleanup |