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[ "$(id -u)" = 0 ] || exit 2 14 15if [ "$1" = "-v" ]; then 16 verbose="1" 17fi 18 19iter=10 20regexp=" +[0-9]+\.[0-9]+ [0-9]+ syscalls:sys_enter_exit_group\(\)$" 21 22trace_shutdown_race() { 23 for _ in $(seq $iter); do 24 perf trace --no-comm -e syscalls:sys_enter_exit_group true 2>>$file 25 done 26 result="$(grep -c -E "$regexp" $file)" 27 [ $result = $iter ] 28} 29 30 31file=$(mktemp /tmp/temporary_file.XXXXX) 32 33# Do not use whatever ~/.perfconfig file, it may change the output 34# via trace.{show_timestamp,show_prefix,etc} 35export PERF_CONFIG=/dev/null 36 37trace_shutdown_race 38err=$? 39 40if [ $err != 0 ] && [ "${verbose}" = "1" ]; then 41 lines_not_matching=$(mktemp /tmp/temporary_file.XXXXX) 42 if grep -v -E "$regexp" $file > $lines_not_matching ; then 43 echo "Lines not matching the expected regexp: '$regexp':" 44 cat $lines_not_matching 45 else 46 echo "Missing output, expected $iter but only got $result" 47 fi 48 rm -f $lines_not_matching 49fi 50 51rm -f ${file} 52exit $err 53