1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# description: event tracing - restricts events based on pid notrace filtering 4# flags: instance 5 6do_reset() { 7 echo > set_event 8 echo > set_event_pid 9 echo > set_event_notrace_pid 10 echo 0 > options/event-fork 11 echo 0 > events/enable 12 clear_trace 13 echo 1 > tracing_on 14} 15 16fail() { #msg 17 cat trace 18 do_reset 19 echo $1 20 exit_fail 21} 22 23count_pid() { 24 pid=$@ 25 cat trace | grep -v '^#' | sed -e 's/[^-]*-\([0-9]*\).*/\1/' | grep $pid | wc -l 26} 27 28count_no_pid() { 29 pid=$1 30 cat trace | grep -v '^#' | sed -e 's/[^-]*-\([0-9]*\).*/\1/' | grep -v $pid | wc -l 31} 32 33enable_system() { 34 system=$1 35 36 if [ -d events/$system ]; then 37 echo 1 > events/$system/enable 38 fi 39} 40 41enable_events() { 42 echo 0 > tracing_on 43 # Enable common groups of events, as all events can allow for 44 # events to be traced via scheduling that we don't care to test. 45 enable_system syscalls 46 enable_system rcu 47 enable_system block 48 enable_system exceptions 49 enable_system irq 50 enable_system net 51 enable_system power 52 enable_system signal 53 enable_system sock 54 enable_system timer 55 enable_system thermal 56 echo 1 > tracing_on 57} 58 59if [ ! -f set_event -o ! -d events/sched ]; then 60 echo "event tracing is not supported" 61 exit_unsupported 62fi 63 64if [ ! -f set_event_pid -o ! -f set_event_notrace_pid ]; then 65 echo "event pid notrace filtering is not supported" 66 exit_unsupported 67fi 68 69echo 0 > options/event-fork 70 71do_reset 72 73read mypid rest < /proc/self/stat 74 75echo $mypid > set_event_notrace_pid 76grep -q $mypid set_event_notrace_pid 77 78enable_events 79 80yield 81 82echo 0 > tracing_on 83 84cnt=`count_pid $mypid` 85if [ $cnt -ne 0 ]; then 86 fail "Filtered out task has events" 87fi 88 89cnt=`count_no_pid $mypid` 90if [ $cnt -eq 0 ]; then 91 fail "No other events were recorded" 92fi 93 94do_reset 95 96echo $mypid > set_event_notrace_pid 97echo 1 > options/event-fork 98 99enable_events 100 101yield & 102child=$! 103echo "child = $child" 104wait $child 105 106echo 0 > tracing_on 107 108cnt=`count_pid $mypid` 109if [ $cnt -ne 0 ]; then 110 fail "Filtered out task has events" 111fi 112 113cnt=`count_pid $child` 114if [ $cnt -ne 0 ]; then 115 fail "Child of filtered out taskhas events" 116fi 117 118cnt=`count_no_pid $mypid` 119if [ $cnt -eq 0 ]; then 120 fail "No other events were recorded" 121fi 122 123do_reset 124 125exit 0 126