1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: event tracing - restricts events based on pid
4# requires: set_event set_event_pid events/sched
5# flags: instance
6
7do_reset() {
8    echo > set_event
9    echo > set_event_pid
10    echo 0 > options/event-fork
11    clear_trace
12}
13
14fail() { #msg
15    do_reset
16    echo $1
17    exit_fail
18}
19
20echo 0 > options/event-fork
21
22echo 1 > events/sched/sched_switch/enable
23
24yield
25
26count=`cat trace | grep sched_switch | wc -l`
27if [ $count -eq 0 ]; then
28    fail "sched_switch events are not recorded"
29fi
30
31do_reset
32
33read mypid rest < /proc/self/stat
34
35echo $mypid > set_event_pid
36grep -q $mypid set_event_pid
37echo 'sched:sched_switch' > set_event
38
39yield
40
41count=`cat trace | grep sched_switch | grep -v "pid=$mypid" | wc -l`
42if [ $count -ne 0 ]; then
43    fail "sched_switch events from other task are recorded"
44fi
45
46do_reset
47
48echo $mypid > set_event_pid
49echo 1 > options/event-fork
50echo 1 > events/sched/sched_switch/enable
51
52yield
53
54count=`cat trace | grep sched_switch | grep -v "pid=$mypid" | wc -l`
55if [ $count -eq 0 ]; then
56    fail "sched_switch events from other task are not recorded"
57fi
58
59do_reset
60
61exit 0
62