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