SoW-2020-0002: Trace Hit Counters: trigger error reporting integration
[lttng-tools.git] / tests / regression / tools / notification / util_event_generator.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2020 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 GENERATOR_CURDIR=$(dirname "$0")/
8 GENERATOR_TESTDIR=$GENERATOR_CURDIR/../../../
9 TESTAPP_PATH=${TESTAPP_PATH:-"$GENERATOR_TESTDIR/utils/testapp"}
10
11 SYSCALL_TESTAPP_NAME=${SYSCALL_TESTAPP_NAME:-"gen-syscall-events"}
12 SYSCALL_TESTAPP_BIN=${SYSCALL_TESTAPP_BIN:-"$TESTAPP_PATH/$SYSCALL_TESTAPP_NAME/$SYSCALL_TESTAPP_NAME"}
13
14 USERSPACE_PROBE_ELF_TESTAPP_NAME=${USERSPACE_PROBE_ELF_TESTAPP_NAME:-"userspace-probe-elf-binary"}
15 USERSPACE_PROBE_ELF_TESTAPP_BIN=${USERSPACE_PROBE_ELF_TESTAPP_BIN:-"$TESTAPP_PATH/$USERSPACE_PROBE_ELF_TESTAPP_NAME/.libs/$USERSPACE_PROBE_ELF_TESTAPP_NAME"}
16
17 function generate_filter_events
18 {
19 local nr=$1
20 /bin/echo -n "$nr" > /proc/lttng-test-filter-event 2> /dev/null
21 }
22
23 function generate_syscalls
24 {
25 local nr=$1
26 shift
27
28 for i in $(seq 1 "$nr"); do
29 # Pass /dev/null so to generate the syscall right away.
30 $SYSCALL_TESTAPP_BIN /dev/null "$@"
31 done
32 }
33
34 function userspace_probe_testapp
35 {
36 local nr=$1
37 shift
38
39 for i in $(seq 1 "$nr"); do
40 $USERSPACE_PROBE_ELF_TESTAPP_BIN "$@"
41 done
42 }
43
44 function ust_event_generator_toggle_state
45 {
46 ust_event_generator_suspended=$((ust_event_generator_suspended==0))
47 }
48
49 function generator_quit
50 {
51 generator_quit=0
52 }
53
54 # Note: Only one generator can be used at a time per domain type
55 function ust_event_generator_run_once_per_transition
56 {
57 # Used by the signal trap
58 ust_event_generator_suspended=0
59 # Used by the signal trap for SIGUSR2 to end the generator
60 generator_quit=1
61
62 local test_app=$1
63 local state_file=$2
64 local nr_iter=$3
65 local nr_usec_wait=$4
66 local run=false
67
68 # Pass any of the remaining arguments to the generator.
69 shift 4
70
71 trap ust_event_generator_toggle_state SIGUSR1
72 trap generator_quit SIGUSR2
73
74 while [ $generator_quit -ne 0 ]; do
75 if [[ $ust_event_generator_suspended -eq "1" ]]; then
76 touch "$state_file"
77 # Reset the "run" state
78 run=true
79 sleep 0.5
80 elif [ "$run" = true ]; then
81 taskset -c 0 "$test_app" -i "$nr_iter" -w "$nr_usec_wait" "$@"> /dev/null 2>&1
82 run=false;
83 if [[ -f $state_file ]]; then
84 rm -rf "$state_file" 2> /dev/null
85 fi
86 else
87 # Wait for a "suspend" to reset the run state
88 sleep 0.1
89 fi
90 done
91 }
92
93 # Note: Only one generator can be used at a time per domain type
94 function ust_event_generator
95 {
96 # Used by the signal trap
97 ust_event_generator_suspended=0
98 # Used by the signal trap for SIGUSR2 to end the generator
99 generator_quit=1
100
101 local test_app=$1
102 local state_file=$2
103 local nr_iter=1000
104 local nr_usec_wait=5
105
106 # Pass any of the remaining arguments to the generator.
107 shift 2
108
109 trap ust_event_generator_toggle_state SIGUSR1
110 trap generator_quit SIGUSR2
111
112 while [ $generator_quit -ne 0 ]; do
113 if [[ $ust_event_generator_suspended -eq "1" ]]; then
114 touch "$state_file"
115 # Reset the "run" state
116 sleep 0.5
117 else
118 taskset -c 0 "$test_app" -i $nr_iter -w $nr_usec_wait "$@" > /dev/null 2>&1
119 if [[ -f $state_file ]]; then
120 rm -rf "$state_file" 2> /dev/null
121 fi
122 fi
123 done
124 }
125
126 function kernel_event_generator_toggle_state
127 {
128 kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
129
130 }
131
132 function kernel_event_generator_run_once_per_transition
133 {
134 # Used by the signal trap
135 kernel_event_generator_suspended=0
136 # Used by the signal trap for SIGUSR2 to end the generator
137 generator_quit=1
138
139 local generator=$1
140 local state_file=$2
141 local nr_iter=$3
142
143 # Pass any of the remaining arguments to the generator.
144 shift 3
145
146 local run=false
147 trap kernel_event_generator_toggle_state SIGUSR1
148 trap generator_quit SIGUSR2
149
150 while [ $generator_quit -ne 0 ]; do
151 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
152 touch "$state_file"
153 run=true
154 sleep 0.5
155 elif [ "$run" = true ]; then
156 $generator "$nr_iter" "$@"
157 run=false
158 if [[ -f $state_file ]]; then
159 rm "$state_file" 2> /dev/null
160 fi
161 else
162 # Wait for a "suspend" to reset the run state
163 sleep 0.1
164 fi
165 done
166 }
167
168 function kernel_event_generator
169 {
170 # Used by the signal trap
171 kernel_event_generator_suspended=0
172 # Used by the signal trap for SIGUSR2 to end the generator
173 generator_quit=1
174
175 local generator=$1
176 local state_file=$2
177
178 # Pass any of the remaining arguments to the generator.
179 shift 2
180
181 trap kernel_event_generator_toggle_state SIGUSR1
182 trap generator_quit SIGUSR2
183
184 while [ $generator_quit -ne 0 ]; do
185 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
186 touch "$state_file"
187 sleep 0.5
188 else
189 $generator "10" "$@"
190 if [[ -f $state_file ]]; then
191 rm "$state_file" 2> /dev/null
192 fi
193 fi
194 done
195 }
This page took 0.050167 seconds and 5 git commands to generate.