3 # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
8 TEST_DESC
="Event exclusion"
11 TESTDIR
=$CURDIR/..
/..
/..
12 STATS_BIN
="$TESTDIR/utils/babelstats.pl"
13 SESSION_NAME
="test-exclusion"
14 TESTAPP_PATH
="$TESTDIR/utils/testapp"
15 TESTAPP_NAME
="gen-ust-nevents"
16 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
21 source $TESTDIR/utils
/utils.sh
23 function enable_ust_lttng_all_event_exclusion
()
28 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
-u "tp:*" -s $sess_name -x "$exclusion" > /dev
/null
33 $TESTAPP_BIN --iter $NR_ITER --wait $NR_USEC_WAIT >/dev
/null
2>&1
34 ok $?
"Running test application"
37 # Testing for the absence of an event when testing exclusion is tricky. An
38 # event could be absent because our exclusion mechanism works but also because
39 # the event was not generate in the first place. This function test the ability
40 # of our test suite to generate events.
43 trace_path
=$
(mktemp
-d)
46 create_lttng_session_ok
$SESSION_NAME $trace_path
48 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
-u "tp:*" -s $SESSION_NAME > /dev
/null
49 ok $?
"Enabling events without exclusion"
52 start_lttng_tracing_ok
$SESSION_NAME
54 stop_lttng_tracing_ok
$SESSION_NAME
56 nb_events
=$
(babeltrace
$trace_path |
wc -l)
57 if [ "$nb_events" -ne "0" ]; then
58 ok
0 "Events were found during the dry run without exclusion"
60 fail
"No events were found during the dry run without exclusion"
66 destroy_lttng_session_ok
$SESSION_NAME
69 function test_exclusion
72 event_name_expected_to_be_missing
="$2"
73 trace_path
=$
(mktemp
-d)
76 create_lttng_session_ok
$SESSION_NAME $trace_path
78 enable_ust_lttng_all_event_exclusion
$SESSION_NAME "$exclusions"
79 ok $?
"Enable lttng event with event \"$exclusions\" excluded"
82 start_lttng_tracing_ok
$SESSION_NAME
84 stop_lttng_tracing_ok
$SESSION_NAME
87 destroy_lttng_session_ok
$SESSION_NAME
89 stats
=`babeltrace $trace_path | $STATS_BIN --tracepoint "$event_name_expected_to_be_missing" | grep -v index 2> /dev/null`
90 if [ ! -z "$stats" ]; then
91 fail
"Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
93 ok
0 "Validate trace exclusion output"
98 function test_exclusion_tracing_started
100 local exclusions
="$1"
101 local event_name_expected_to_be_missing
="$2"
102 local trace_path
=$
(mktemp
-d)
103 local file_wait_before_first
=$
(mktemp
-u)
104 local file_create_in_main
=$
(mktemp
-u)
107 create_lttng_session_ok
$SESSION_NAME $trace_path
109 # Enable a dummy event so that the session is active after we start the
111 enable_ust_lttng_event_ok
$SESSION_NAME "non-existent-event"
114 start_lttng_tracing_ok
$SESSION_NAME
116 # Launch the test app and make it create a sync file once it's in the
118 $TESTAPP_BIN -i 1 -w 10000 \
119 --create-in-main ${file_create_in_main} \
120 --wait-before-first-event ${file_wait_before_first} 2>&1 &
122 while [ ! -f "${file_create_in_main}" ]; do
126 # Enable an event with an exclusion once the tracing is active in the
128 enable_ust_lttng_all_event_exclusion
$SESSION_NAME "$exclusions"
129 ok $?
"Enable lttng event with event \"$exclusions\" excluded"
131 # Create the sync file so that the test app starts generating events.
132 touch ${file_wait_before_first}
134 # Wait for the testapp to finish.
137 stop_lttng_tracing_ok
$SESSION_NAME
140 destroy_lttng_session_ok
$SESSION_NAME
142 stats
=$
(babeltrace
$trace_path |
$STATS_BIN --tracepoint "$event_name_expected_to_be_missing" |
grep -v index
2> /dev
/null
)
143 if [ ! -z "$stats" ]; then
144 fail
"Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
146 ok
0 "Validate trace exclusion output"
151 function test_exclusion_fail
156 create_lttng_session_ok
$SESSION_NAME $trace_path
157 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
-u "$event_name" -s $sess_name -x "$exclusions" >/dev
/null
2>&1
159 destroy_lttng_session_ok
$SESSION_NAME
161 if [ $res -eq 0 ]; then
162 fail
"Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" passes"
165 pass
"Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" fails"
170 plan_tests
$NUM_TESTS
172 print_test_banner
"$TEST_DESC"
176 diag
"Enable event without exclusion"
179 diag
"Enable event with exclusion"
180 test_exclusion
'tp:tptest2' 'tp:tptest2'
181 test_exclusion
'tp:tptest3' 'tp:tptest3'
182 test_exclusion
'tp:tptest*' 'tp:tptest1'
183 test_exclusion
'tp:tptest*' 'tp:tptest2'
184 test_exclusion
'tp:tptest*' 'tp:tptest3'
185 test_exclusion
'tp:tptest*' 'tp:tptest4'
186 test_exclusion
'tp:tptest*' 'tp:tptest5'
187 test_exclusion
'tp*tptest*' 'tp:tptest1'
188 test_exclusion
'tp*tptest*' 'tp:tptest2'
189 test_exclusion
'tp*tptest*' 'tp:tptest3'
190 test_exclusion
'tp*tptest*' 'tp:tptest4'
191 test_exclusion
'tp*tptest*' 'tp:tptest5'
192 test_exclusion
'*test2' 'tp:tptest2'
193 test_exclusion
'*test5' 'tp:tptest5'
194 test_exclusion
'*p*test*' 'tp:tptest1'
195 test_exclusion
'*p*test*' 'tp:tptest2'
196 test_exclusion
'*p*test*' 'tp:tptest3'
197 test_exclusion
'*p***test*' 'tp:tptest4'
198 test_exclusion
'*p*test*' 'tp:tptest5'
199 test_exclusion
'*3' 'tp:tptest3'
200 test_exclusion
'tp*test3,*2' 'tp:tptest2'
201 test_exclusion
'**tp*test3,*2' 'tp:tptest3'
203 test_exclusion_tracing_started
'tp:tptest1' 'tp:tptest1'
205 diag
"Cannot use exclusions with non-globbing event name"
206 test_exclusion_fail
"allo" "lol"
207 test_exclusion_fail
"allo" "meow,lol"
208 test_exclusion_fail
"allo" "z*em"
210 diag
"Exclusion name excludes all possible event names"
211 test_exclusion_fail
"allo*" "all*"
212 test_exclusion_fail
"allo*" "ze,all*,yes"