Tests: rotation: add a per-pid size-based rotation test
[lttng-tools.git] / tests / regression / tools / notification / util_event_generator.sh
CommitLineData
25cb2044
JR
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
7GENERATOR_CURDIR=$(dirname "$0")/
8GENERATOR_TESTDIR=$GENERATOR_CURDIR/../../../
9TESTAPP_PATH=${TESTAPP_PATH:-"$GENERATOR_TESTDIR/utils/testapp"}
10
11SYSCALL_TESTAPP_NAME=${SYSCALL_TESTAPP_NAME:-"gen-syscall-events"}
12SYSCALL_TESTAPP_BIN=${SYSCALL_TESTAPP_BIN:-"$TESTAPP_PATH/$SYSCALL_TESTAPP_NAME/$SYSCALL_TESTAPP_NAME"}
13
14USERSPACE_PROBE_ELF_TESTAPP_NAME=${USERSPACE_PROBE_ELF_TESTAPP_NAME:-"userspace-probe-elf-binary"}
15USERSPACE_PROBE_ELF_TESTAPP_BIN=${USERSPACE_PROBE_ELF_TESTAPP_BIN:-"$TESTAPP_PATH/$USERSPACE_PROBE_ELF_TESTAPP_NAME/.libs/$USERSPACE_PROBE_ELF_TESTAPP_NAME"}
16
17function generate_filter_events
18{
19 local nr=$1
20 /bin/echo -n "$nr" > /proc/lttng-test-filter-event 2> /dev/null
21}
22
23function 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
34function 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
44function ust_event_generator_toggle_state
45{
46 ust_event_generator_suspended=$((ust_event_generator_suspended==0))
47}
48
49function generator_quit
50{
51 generator_quit=0
52}
53
54# Note: Only one generator can be used at a time per domain type
55function 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
94function 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
126function kernel_event_generator_toggle_state
127{
128 kernel_event_generator_suspended=$((kernel_event_generator_suspended==0))
129}
130
131function kernel_event_generator_run_once_per_transition
132{
133 # Used by the signal trap
134 kernel_event_generator_suspended=0
135 # Used by the signal trap for SIGUSR2 to end the generator
136 generator_quit=1
137
138 local generator=$1
139 local state_file=$2
140 local nr_iter=$3
141
142 # Pass any of the remaining arguments to the generator.
143 shift 3
144
145 local run=false
146 trap kernel_event_generator_toggle_state SIGUSR1
147 trap generator_quit SIGUSR2
148
149 while [ $generator_quit -ne 0 ]; do
150 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
151 touch "$state_file"
152 run=true
153 sleep 0.5
154 elif [ "$run" = true ]; then
155 $generator "$nr_iter" "$@"
156 run=false
157 if [[ -f $state_file ]]; then
158 rm "$state_file" 2> /dev/null
159 fi
160 else
161 # Wait for a "suspend" to reset the run state
162 sleep 0.1
163 fi
164 done
165}
166
167function kernel_event_generator
168{
169 # Used by the signal trap
170 kernel_event_generator_suspended=0
171 # Used by the signal trap for SIGUSR2 to end the generator
172 generator_quit=1
173
174 local generator=$1
175 local state_file=$2
176
177 # Pass any of the remaining arguments to the generator.
178 shift 2
179
180 trap kernel_event_generator_toggle_state SIGUSR1
181 trap generator_quit SIGUSR2
182
183 while [ $generator_quit -ne 0 ]; do
184 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
185 touch "$state_file"
186 sleep 0.5
187 else
188 $generator "10" "$@"
189 if [[ -f $state_file ]]; then
190 rm "$state_file" 2> /dev/null
191 fi
192 fi
193 done
194}
This page took 0.038603 seconds and 4 git commands to generate.