xref: /linux/tools/testing/selftests/ftrace/test.d/event/event-pid.tc (revision e58e871becec2d3b04ed91c0c16fe8deac9c9dfa)
1#!/bin/sh
2# description: event tracing - restricts events based on pid
3# flags: instance
4
5do_reset() {
6    echo > set_event
7    echo > set_event_pid
8    echo 0 > options/event-fork
9    clear_trace
10}
11
12fail() { #msg
13    do_reset
14    echo $1
15    exit $FAIL
16}
17
18yield() {
19    ping localhost -c 1 || sleep .001 || usleep 1 || sleep 1
20}
21
22if [ ! -f set_event -o ! -d events/sched ]; then
23    echo "event tracing is not supported"
24    exit_unsupported
25fi
26
27if [ ! -f set_event_pid ]; then
28    echo "event pid filtering is not supported"
29    exit_unsupported
30fi
31
32reset_tracer
33do_reset
34
35echo 1 > events/sched/sched_switch/enable
36
37yield
38
39count=`cat trace | grep sched_switch | wc -l`
40if [ $count -eq 0 ]; then
41    fail "sched_switch events are not recorded"
42fi
43
44do_reset
45
46read mypid rest < /proc/self/stat
47
48echo $mypid > set_event_pid
49echo 'sched:sched_switch' > set_event
50
51yield
52
53count=`cat trace | grep sched_switch | grep -v "pid=$mypid" | wc -l`
54if [ $count -ne 0 ]; then
55    fail "sched_switch events from other task are recorded"
56fi
57
58do_reset
59
60echo $mypid > set_event_pid
61echo 1 > options/event-fork
62echo 1 > events/sched/sched_switch/enable
63
64yield
65
66count=`cat trace | grep sched_switch | grep -v "pid=$mypid" | wc -l`
67if [ $count -eq 0 ]; then
68    fail "sched_switch events from other task are not recorded"
69fi
70
71do_reset
72
73exit 0
74