124f378e6SIan Rogers#!/bin/sh 224f378e6SIan Rogers# perf record tests 324f378e6SIan Rogers# SPDX-License-Identifier: GPL-2.0 424f378e6SIan Rogers 524f378e6SIan Rogersset -e 624f378e6SIan Rogers 76b7e02abSNamhyung Kimshelldir=$(dirname "$0") 86b7e02abSNamhyung Kim. "${shelldir}"/lib/waiting.sh 96b7e02abSNamhyung Kim 1024f378e6SIan Rogerserr=0 11280c36d2SIan Rogersperfdata=$(mktemp /tmp/__perf_test.perf.data.XXXXX) 120b8ff0baSNamhyung Kimtestprog="perf test -w thloop" 134321ad4eSNamhyung Kimtestsym="test_loop" 14280c36d2SIan Rogers 15280c36d2SIan Rogerscleanup() { 167f4ed3f0SNamhyung Kim rm -rf "${perfdata}" 177f4ed3f0SNamhyung Kim rm -rf "${perfdata}".old 184321ad4eSNamhyung Kim 199e455f4fSNamhyung Kim trap - EXIT TERM INT 20280c36d2SIan Rogers} 21280c36d2SIan Rogers 22280c36d2SIan Rogerstrap_cleanup() { 23280c36d2SIan Rogers cleanup 24280c36d2SIan Rogers exit 1 25280c36d2SIan Rogers} 269e455f4fSNamhyung Kimtrap trap_cleanup EXIT TERM INT 27280c36d2SIan Rogers 2824f378e6SIan Rogerstest_per_thread() { 2924f378e6SIan Rogers echo "Basic --per-thread mode test" 304321ad4eSNamhyung Kim if ! perf record -o /dev/null --quiet ${testprog} 2> /dev/null 31280c36d2SIan Rogers then 32439dbef2SNamhyung Kim echo "Per-thread record [Skipped event not supported]" 33280c36d2SIan Rogers return 34280c36d2SIan Rogers fi 354321ad4eSNamhyung Kim if ! perf record --per-thread -o "${perfdata}" ${testprog} 2> /dev/null 36280c36d2SIan Rogers then 37439dbef2SNamhyung Kim echo "Per-thread record [Failed record]" 38280c36d2SIan Rogers err=1 39280c36d2SIan Rogers return 40280c36d2SIan Rogers fi 414321ad4eSNamhyung Kim if ! perf report -i "${perfdata}" -q | grep -q "${testsym}" 42280c36d2SIan Rogers then 43280c36d2SIan Rogers echo "Per-thread record [Failed missing output]" 44280c36d2SIan Rogers err=1 45280c36d2SIan Rogers return 46280c36d2SIan Rogers fi 476b7e02abSNamhyung Kim 480b8ff0baSNamhyung Kim # run the test program in background (for 30 seconds) 490b8ff0baSNamhyung Kim ${testprog} 30 & 506b7e02abSNamhyung Kim TESTPID=$! 516b7e02abSNamhyung Kim 526b7e02abSNamhyung Kim rm -f "${perfdata}" 536b7e02abSNamhyung Kim 546b7e02abSNamhyung Kim wait_for_threads ${TESTPID} 2 556b7e02abSNamhyung Kim perf record -p "${TESTPID}" --per-thread -o "${perfdata}" sleep 1 2> /dev/null 566b7e02abSNamhyung Kim kill ${TESTPID} 576b7e02abSNamhyung Kim 586b7e02abSNamhyung Kim if [ ! -e "${perfdata}" ] 596b7e02abSNamhyung Kim then 606b7e02abSNamhyung Kim echo "Per-thread record [Failed record -p]" 616b7e02abSNamhyung Kim err=1 626b7e02abSNamhyung Kim return 636b7e02abSNamhyung Kim fi 646b7e02abSNamhyung Kim if ! perf report -i "${perfdata}" -q | grep -q "${testsym}" 656b7e02abSNamhyung Kim then 666b7e02abSNamhyung Kim echo "Per-thread record [Failed -p missing output]" 676b7e02abSNamhyung Kim err=1 686b7e02abSNamhyung Kim return 696b7e02abSNamhyung Kim fi 706b7e02abSNamhyung Kim 7124f378e6SIan Rogers echo "Basic --per-thread mode test [Success]" 7224f378e6SIan Rogers} 7324f378e6SIan Rogers 7424f378e6SIan Rogerstest_register_capture() { 7524f378e6SIan Rogers echo "Register capture test" 769e455f4fSNamhyung Kim if ! perf list | grep -q 'br_inst_retired.near_call' 7724f378e6SIan Rogers then 78439dbef2SNamhyung Kim echo "Register capture test [Skipped missing event]" 7924f378e6SIan Rogers return 8024f378e6SIan Rogers fi 819e455f4fSNamhyung Kim if ! perf record --intr-regs=\? 2>&1 | grep -q 'available registers: AX BX CX DX SI DI BP SP IP FLAGS CS SS R8 R9 R10 R11 R12 R13 R14 R15' 8224f378e6SIan Rogers then 8324f378e6SIan Rogers echo "Register capture test [Skipped missing registers]" 8424f378e6SIan Rogers return 8524f378e6SIan Rogers fi 86*2e9f5bdaSMichael Petlan if ! perf record -o - --intr-regs=di,r8,dx,cx -e br_inst_retired.near_call \ 874321ad4eSNamhyung Kim -c 1000 --per-thread ${testprog} 2> /dev/null \ 8824f378e6SIan Rogers | perf script -F ip,sym,iregs -i - 2> /dev/null \ 899e455f4fSNamhyung Kim | grep -q "DI:" 9024f378e6SIan Rogers then 9124f378e6SIan Rogers echo "Register capture test [Failed missing output]" 9224f378e6SIan Rogers err=1 9324f378e6SIan Rogers return 9424f378e6SIan Rogers fi 9524f378e6SIan Rogers echo "Register capture test [Success]" 9624f378e6SIan Rogers} 9724f378e6SIan Rogers 982cadf2c7SNamhyung Kimtest_system_wide() { 992cadf2c7SNamhyung Kim echo "Basic --system-wide mode test" 1002cadf2c7SNamhyung Kim if ! perf record -aB --synth=no -o "${perfdata}" ${testprog} 2> /dev/null 1012cadf2c7SNamhyung Kim then 1022cadf2c7SNamhyung Kim echo "System-wide record [Skipped not supported]" 1032cadf2c7SNamhyung Kim return 1042cadf2c7SNamhyung Kim fi 1052cadf2c7SNamhyung Kim if ! perf report -i "${perfdata}" -q | grep -q "${testsym}" 1062cadf2c7SNamhyung Kim then 1072cadf2c7SNamhyung Kim echo "System-wide record [Failed missing output]" 1082cadf2c7SNamhyung Kim err=1 1092cadf2c7SNamhyung Kim return 1102cadf2c7SNamhyung Kim fi 1117f4ed3f0SNamhyung Kim if ! perf record -aB --synth=no -e cpu-clock,cs --threads=cpu \ 1127f4ed3f0SNamhyung Kim -o "${perfdata}" ${testprog} 2> /dev/null 1137f4ed3f0SNamhyung Kim then 1147f4ed3f0SNamhyung Kim echo "System-wide record [Failed record --threads option]" 1157f4ed3f0SNamhyung Kim err=1 1167f4ed3f0SNamhyung Kim return 1177f4ed3f0SNamhyung Kim fi 1187f4ed3f0SNamhyung Kim if ! perf report -i "${perfdata}" -q | grep -q "${testsym}" 1197f4ed3f0SNamhyung Kim then 1207f4ed3f0SNamhyung Kim echo "System-wide record [Failed --threads missing output]" 1217f4ed3f0SNamhyung Kim err=1 1227f4ed3f0SNamhyung Kim return 1237f4ed3f0SNamhyung Kim fi 1242cadf2c7SNamhyung Kim echo "Basic --system-wide mode test [Success]" 1252cadf2c7SNamhyung Kim} 1262cadf2c7SNamhyung Kim 127c8c93567SNamhyung Kimtest_workload() { 128c8c93567SNamhyung Kim echo "Basic target workload test" 129c8c93567SNamhyung Kim if ! perf record -o "${perfdata}" ${testprog} 2> /dev/null 130c8c93567SNamhyung Kim then 131c8c93567SNamhyung Kim echo "Workload record [Failed record]" 132c8c93567SNamhyung Kim err=1 133c8c93567SNamhyung Kim return 134c8c93567SNamhyung Kim fi 135c8c93567SNamhyung Kim if ! perf report -i "${perfdata}" -q | grep -q "${testsym}" 136c8c93567SNamhyung Kim then 137c8c93567SNamhyung Kim echo "Workload record [Failed missing output]" 138c8c93567SNamhyung Kim err=1 139c8c93567SNamhyung Kim return 140c8c93567SNamhyung Kim fi 1417f4ed3f0SNamhyung Kim if ! perf record -e cpu-clock,cs --threads=package \ 1427f4ed3f0SNamhyung Kim -o "${perfdata}" ${testprog} 2> /dev/null 1437f4ed3f0SNamhyung Kim then 1447f4ed3f0SNamhyung Kim echo "Workload record [Failed record --threads option]" 1457f4ed3f0SNamhyung Kim err=1 1467f4ed3f0SNamhyung Kim return 1477f4ed3f0SNamhyung Kim fi 1487f4ed3f0SNamhyung Kim if ! perf report -i "${perfdata}" -q | grep -q "${testsym}" 1497f4ed3f0SNamhyung Kim then 1507f4ed3f0SNamhyung Kim echo "Workload record [Failed --threads missing output]" 1517f4ed3f0SNamhyung Kim err=1 1527f4ed3f0SNamhyung Kim return 1537f4ed3f0SNamhyung Kim fi 154c8c93567SNamhyung Kim echo "Basic target workload test [Success]" 155c8c93567SNamhyung Kim} 156c8c93567SNamhyung Kim 15724f378e6SIan Rogerstest_per_thread 15824f378e6SIan Rogerstest_register_capture 1592cadf2c7SNamhyung Kimtest_system_wide 160c8c93567SNamhyung Kimtest_workload 161280c36d2SIan Rogers 162280c36d2SIan Rogerscleanup 16324f378e6SIan Rogersexit $err 164