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
19if [ ! -f set_event -o ! -d events/sched ]; then
20    echo "event tracing is not supported"
21    exit_unsupported
22fi
23
24if [ ! -f set_event_pid ]; then
25    echo "event pid filtering is not supported"
26    exit_unsupported
27fi
28
29echo 0 > options/event-fork
30
31echo 1 > events/sched/sched_switch/enable
32
33yield
34
35count=`cat trace | grep sched_switch | wc -l`
36if [ $count -eq 0 ]; then
37    fail "sched_switch events are not recorded"
38fi
39
40do_reset
41
42read mypid rest < /proc/self/stat
43
44echo $mypid > set_event_pid
45grep -q $mypid set_event_pid
46echo 'sched:sched_switch' > set_event
47
48yield
49
50count=`cat trace | grep sched_switch | grep -v "pid=$mypid" | wc -l`
51if [ $count -ne 0 ]; then
52    fail "sched_switch events from other task are recorded"
53fi
54
55do_reset
56
57echo $mypid > set_event_pid
58echo 1 > options/event-fork
59echo 1 > events/sched/sched_switch/enable
60
61yield
62
63count=`cat trace | grep sched_switch | grep -v "pid=$mypid" | wc -l`
64if [ $count -eq 0 ]; then
65    fail "sched_switch events from other task are not recorded"
66fi
67
68do_reset
69
70exit 0
71