|
| 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 | + |
| 6 | +do_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 | + |
| 16 | +fail() { #msg |
| 17 | + cat trace |
| 18 | + do_reset |
| 19 | + echo $1 |
| 20 | + exit_fail |
| 21 | +} |
| 22 | + |
| 23 | +count_pid() { |
| 24 | + pid=$@ |
| 25 | + cat trace | grep -v '^#' | sed -e 's/[^-]*-\([0-9]*\).*/\1/' | grep $pid | wc -l |
| 26 | +} |
| 27 | + |
| 28 | +count_no_pid() { |
| 29 | + pid=$1 |
| 30 | + cat trace | grep -v '^#' | sed -e 's/[^-]*-\([0-9]*\).*/\1/' | grep -v $pid | wc -l |
| 31 | +} |
| 32 | + |
| 33 | +enable_system() { |
| 34 | + system=$1 |
| 35 | + |
| 36 | + if [ -d events/$system ]; then |
| 37 | + echo 1 > events/$system/enable |
| 38 | + fi |
| 39 | +} |
| 40 | + |
| 41 | +enable_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 | + |
| 59 | +if [ ! -f set_event -o ! -d events/sched ]; then |
| 60 | + echo "event tracing is not supported" |
| 61 | + exit_unsupported |
| 62 | +fi |
| 63 | + |
| 64 | +if [ ! -f set_event_pid -o ! -f set_event_notrace_pid ]; then |
| 65 | + echo "event pid notrace filtering is not supported" |
| 66 | + exit_unsupported |
| 67 | +fi |
| 68 | + |
| 69 | +echo 0 > options/event-fork |
| 70 | + |
| 71 | +do_reset |
| 72 | + |
| 73 | +read mypid rest < /proc/self/stat |
| 74 | + |
| 75 | +echo $mypid > set_event_notrace_pid |
| 76 | +grep -q $mypid set_event_notrace_pid |
| 77 | + |
| 78 | +enable_events |
| 79 | + |
| 80 | +yield |
| 81 | + |
| 82 | +echo 0 > tracing_on |
| 83 | + |
| 84 | +cnt=`count_pid $mypid` |
| 85 | +if [ $cnt -ne 0 ]; then |
| 86 | + fail "Filtered out task has events" |
| 87 | +fi |
| 88 | + |
| 89 | +cnt=`count_no_pid $mypid` |
| 90 | +if [ $cnt -eq 0 ]; then |
| 91 | + fail "No other events were recorded" |
| 92 | +fi |
| 93 | + |
| 94 | +do_reset |
| 95 | + |
| 96 | +echo $mypid > set_event_notrace_pid |
| 97 | +echo 1 > options/event-fork |
| 98 | + |
| 99 | +enable_events |
| 100 | + |
| 101 | +yield & |
| 102 | +child=$! |
| 103 | +echo "child = $child" |
| 104 | +wait $child |
| 105 | + |
| 106 | +echo 0 > tracing_on |
| 107 | + |
| 108 | +cnt=`count_pid $mypid` |
| 109 | +if [ $cnt -ne 0 ]; then |
| 110 | + fail "Filtered out task has events" |
| 111 | +fi |
| 112 | + |
| 113 | +cnt=`count_pid $child` |
| 114 | +if [ $cnt -ne 0 ]; then |
| 115 | + fail "Child of filtered out taskhas events" |
| 116 | +fi |
| 117 | + |
| 118 | +cnt=`count_no_pid $mypid` |
| 119 | +if [ $cnt -eq 0 ]; then |
| 120 | + fail "No other events were recorded" |
| 121 | +fi |
| 122 | + |
| 123 | +do_reset |
| 124 | + |
| 125 | +exit 0 |
0 commit comments