1#!/bin/sh 2# perf trace exit race 3# SPDX-License-Identifier: GPL-2.0 4 5# Check that the last events of a perf trace'd subprocess are not 6# lost. Specifically, trace the exiting syscall of "true" 10 times and ensure 7# the output contains 10 correct lines. 8 9# shellcheck source=lib/probe.sh 10. "$(dirname $0)"/lib/probe.sh 11 12skip_if_no_perf_trace || exit 2 13 14if [ "$1" = "-v" ]; then 15 verbose="1" 16fi 17 18iter=10 19regexp=" +[0-9]+\.[0-9]+ [0-9]+ syscalls:sys_enter_exit_group\(\)$" 20 21trace_shutdown_race() { 22 for _ in $(seq $iter); do 23 perf trace --no-comm -e syscalls:sys_enter_exit_group true 2>>$file 24 done 25 result="$(grep -c -E "$regexp" $file)" 26 [ $result = $iter ] 27} 28 29 30file=$(mktemp /tmp/temporary_file.XXXXX) 31 32# Do not use whatever ~/.perfconfig file, it may change the output 33# via trace.{show_timestamp,show_prefix,etc} 34export PERF_CONFIG=/dev/null 35 36trace_shutdown_race 37err=$? 38 39if [ $err != 0 ] && [ "${verbose}" = "1" ]; then 40 lines_not_matching=$(mktemp /tmp/temporary_file.XXXXX) 41 if grep -v -E "$regexp" $file > $lines_not_matching ; then 42 echo "Lines not matching the expected regexp: '$regexp':" 43 cat $lines_not_matching 44 else 45 echo "Missing output, expected $iter but only got $result" 46 fi 47 rm -f $lines_not_matching 48fi 49 50rm -f ${file} 51exit $err 52