1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3# description: event trigger - test multiple histogram triggers
4# flags: instance
5
6do_reset() {
7    reset_trigger
8    echo > set_event
9    clear_trace
10}
11
12fail() { #msg
13    do_reset
14    echo $1
15    exit_fail
16}
17
18if [ ! -f set_event -o ! -d events/sched ]; then
19    echo "event tracing is not supported"
20    exit_unsupported
21fi
22
23if [ ! -f events/sched/sched_process_fork/trigger ]; then
24    echo "event trigger is not supported"
25    exit_unsupported
26fi
27
28if [ ! -f events/sched/sched_process_fork/hist ]; then
29    echo "hist trigger is not supported"
30    exit_unsupported
31fi
32
33reset_tracer
34do_reset
35
36reset_trigger
37
38echo "Test histogram multiple tiggers"
39
40echo 'hist:keys=parent_pid:vals=child_pid' > events/sched/sched_process_fork/trigger
41echo 'hist:keys=parent_comm:vals=child_pid' >> events/sched/sched_process_fork/trigger
42for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
43grep parent_pid events/sched/sched_process_fork/hist > /dev/null || \
44    fail "hist trigger on sched_process_fork did not work"
45grep child events/sched/sched_process_fork/hist > /dev/null || \
46    fail "hist trigger on sched_process_fork did not work"
47COMM=`cat /proc/$$/comm`
48grep "parent_comm: $COMM" events/sched/sched_process_fork/hist > /dev/null || \
49    fail "string key on sched_process_fork did not work"
50
51reset_trigger
52
53echo "Test histogram with its name"
54
55echo 'hist:name=test_hist:keys=common_pid' > events/sched/sched_process_fork/trigger
56for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
57grep test_hist events/sched/sched_process_fork/hist > /dev/null || \
58    fail "named event on sched_process_fork did not work"
59
60echo "Test same named histogram on different events"
61
62echo 'hist:name=test_hist:keys=common_pid' > events/sched/sched_process_exit/trigger
63for i in `seq 1 10` ; do ( echo "forked" > /dev/null); done
64grep test_hist events/sched/sched_process_exit/hist > /dev/null || \
65    fail "named event on sched_process_fork did not work"
66
67diffs=`diff events/sched/sched_process_exit/hist events/sched/sched_process_fork/hist | wc -l`
68test $diffs -eq 0 || fail "Same name histograms are not same"
69
70reset_trigger
71
72do_reset
73
74exit 0
75