3 # Copyright (C) 2020 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 GENERATOR_CURDIR
=$
(dirname "$0")/
8 GENERATOR_TESTDIR
=$GENERATOR_CURDIR/..
/..
/..
/
9 TESTAPP_PATH
=${TESTAPP_PATH:-"$GENERATOR_TESTDIR/utils/testapp"}
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"}
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"}
17 # shellcheck source=../utils/utils.sh
18 source "$GENERATOR_TESTDIR/utils/utils.sh"
20 function generate_filter_events
23 /bin
/echo -n "$nr" > /proc
/lttng-test-filter-event
2> /dev
/null
26 function generate_syscalls
31 for _
in $
(seq 1 "$nr"); do
32 # Pass /dev/null so to generate the syscall right away.
33 $SYSCALL_TESTAPP_BIN /dev
/null
"$@"
37 function userspace_probe_testapp
42 for _
in $
(seq 1 "$nr"); do
43 # This userspace probe test has to instrument the actual elf
44 # binary and not the generated libtool wrapper. However, we
45 # can't invoke the wrapper either since it will re-link the test
46 # application binary on its first invocation, resulting in a new
47 # binary with an 'lt-*' prefix under the .libs folder. The
48 # relinking stage adds the .libs folder to the 'lt-*' binary's
51 # To ensure the binary (inode) that instrumented is the same as
52 # what is running, set LD_LIBRARY_PATH to find the .libs folder
53 # that contains the libfoo.so library and invoke the binary
55 LD_LIBRARY_PATH
="$LD_LIBRARY_PATH:$TESTDIR/utils/testapp/userspace-probe-elf-binary/.libs" $USERSPACE_PROBE_ELF_TESTAPP_BIN "$@"
59 function ust_event_generator_toggle_state
61 ust_event_generator_suspended
=$
((ust_event_generator_suspended
==0))
64 function generator_quit
69 # Note: Only one generator can be used at a time per domain type
70 function ust_event_generator_run_once_per_transition
72 # Used by the signal trap
73 ust_event_generator_suspended
=0
74 # Used by the signal trap for SIGUSR2 to end the generator
83 # Pass any of the remaining arguments to the generator.
86 trap ust_event_generator_toggle_state SIGUSR1
87 trap generator_quit SIGUSR2
89 while [ $generator_quit -ne 0 ]; do
90 if [[ $ust_event_generator_suspended -eq "1" ]]; then
92 # Reset the "run" state
95 elif [ "$run" = true
]; then
96 taskset
-c "$(get_any_available_cpu)" "$test_app" -i "$nr_iter" -w "$nr_usec_wait" "$@"> /dev
/null
2>&1
98 if [[ -f $state_file ]]; then
99 rm -rf "$state_file" 2> /dev
/null
102 # Wait for a "suspend" to reset the run state
108 # Note: Only one generator can be used at a time per domain type
109 function ust_event_generator
111 # Used by the signal trap
112 ust_event_generator_suspended
=0
113 # Used by the signal trap for SIGUSR2 to end the generator
121 # Pass any of the remaining arguments to the generator.
124 trap ust_event_generator_toggle_state SIGUSR1
125 trap generator_quit SIGUSR2
127 while [ $generator_quit -ne 0 ]; do
128 if [[ $ust_event_generator_suspended -eq "1" ]]; then
130 # Reset the "run" state
133 taskset
-c "$(get_any_available_cpu)" "$test_app" -i $nr_iter -w $nr_usec_wait "$@" > /dev
/null
2>&1
134 if [[ -f $state_file ]]; then
135 rm -rf "$state_file" 2> /dev
/null
141 function kernel_event_generator_toggle_state
143 kernel_event_generator_suspended
=$
((kernel_event_generator_suspended
==0))
146 function kernel_event_generator_run_once_per_transition
148 # Used by the signal trap
149 kernel_event_generator_suspended
=0
150 # Used by the signal trap for SIGUSR2 to end the generator
157 # Pass any of the remaining arguments to the generator.
161 trap kernel_event_generator_toggle_state SIGUSR1
162 trap generator_quit SIGUSR2
164 while [ $generator_quit -ne 0 ]; do
165 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
169 elif [ "$run" = true
]; then
170 $generator "$nr_iter" "$@"
172 if [[ -f $state_file ]]; then
173 rm "$state_file" 2> /dev
/null
176 # Wait for a "suspend" to reset the run state
182 function kernel_event_generator
184 # Used by the signal trap
185 kernel_event_generator_suspended
=0
186 # Used by the signal trap for SIGUSR2 to end the generator
192 # Pass any of the remaining arguments to the generator.
195 trap kernel_event_generator_toggle_state SIGUSR1
196 trap generator_quit SIGUSR2
198 while [ $generator_quit -ne 0 ]; do
199 if [[ $kernel_event_generator_suspended -eq "1" ]]; then
204 if [[ -f $state_file ]]; then
205 rm "$state_file" 2> /dev
/null