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