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 BT2_PLUGINS_DIR
="${TESTDIR}/utils/bt2_plugins"
14 SESSION_NAME
="test-exclusion"
15 TESTAPP_PATH
="$TESTDIR/utils/testapp"
16 TESTAPP_NAME
="gen-ust-nevents"
17 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
22 source $TESTDIR/utils
/utils.sh
24 function enable_ust_lttng_all_event_exclusion
()
29 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
-u "tp:*" -s $sess_name -x "$exclusion" > /dev
/null
34 $TESTAPP_BIN --iter $NR_ITER --wait $NR_USEC_WAIT >/dev
/null
2>&1
35 ok $?
"Running test application"
38 # Testing for the absence of an event when testing exclusion is tricky. An
39 # event could be absent because our exclusion mechanism works but also because
40 # the event was not generate in the first place. This function test the ability
41 # of our test suite to generate events.
44 local trace_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
47 create_lttng_session_ok
$SESSION_NAME $trace_path
49 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
-u "tp:*" -s $SESSION_NAME > /dev
/null
50 ok $?
"Enabling events without exclusion"
53 start_lttng_tracing_ok
$SESSION_NAME
55 stop_lttng_tracing_ok
$SESSION_NAME
57 nb_events
=$
("$BABELTRACE_BIN" $trace_path |
wc -l)
58 if [ "$nb_events" -ne "0" ]; then
59 ok
0 "Events were found during the dry run without exclusion"
61 fail
"No events were found during the dry run without exclusion"
67 destroy_lttng_session_ok
$SESSION_NAME
70 function test_exclusion
73 local event_name_expected_to_be_missing
="$2"
74 local trace_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
77 create_lttng_session_ok
$SESSION_NAME $trace_path
79 enable_ust_lttng_all_event_exclusion
$SESSION_NAME "$exclusions"
80 ok $?
"Enable lttng event with event \"$exclusions\" excluded"
83 start_lttng_tracing_ok
$SESSION_NAME
85 stop_lttng_tracing_ok
$SESSION_NAME
88 destroy_lttng_session_ok
$SESSION_NAME
90 stats
=$
("$BABELTRACE_BIN" --plugin-path "${BT2_PLUGINS_DIR}" "${trace_path}" -c filter.lttngtest.event_name -p "names=[\"${event_name_expected_to_be_missing}\"]" -c sink.lttngtest.field_stats |
grep -v index
2> /dev
/null
)
91 if [ ! -z "$stats" ]; then
92 fail
"Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
94 ok
0 "Validate trace exclusion output"
99 function test_exclusion_tracing_started
101 local exclusions
="$1"
102 local event_name_expected_to_be_missing
="$2"
103 local trace_path
=$
(mktemp
-d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
104 local file_wait_before_first
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}_sync_before_first.XXXXXX")
105 local file_create_in_main
=$
(mktemp
-u -t "tmp.${FUNCNAME[0]}_sync_create_in_main.XXXXXX")
108 create_lttng_session_ok
$SESSION_NAME $trace_path
110 # Enable a dummy event so that the session is active after we start the
112 enable_ust_lttng_event_ok
$SESSION_NAME "non-existent-event"
115 start_lttng_tracing_ok
$SESSION_NAME
117 # Launch the test app and make it create a sync file once it's in the
119 $TESTAPP_BIN -i 1 -w 10000 \
120 --create-in-main ${file_create_in_main} \
121 --wait-before-first-event ${file_wait_before_first} 2>&1 &
123 while [ ! -f "${file_create_in_main}" ]; do
127 # Enable an event with an exclusion once the tracing is active in the
129 enable_ust_lttng_all_event_exclusion
$SESSION_NAME "$exclusions"
130 ok $?
"Enable lttng event with event \"$exclusions\" excluded"
132 # Create the sync file so that the test app starts generating events.
133 touch ${file_wait_before_first}
135 # Wait for the testapp to finish.
138 stop_lttng_tracing_ok
$SESSION_NAME
141 destroy_lttng_session_ok
$SESSION_NAME
143 stats
=$
("$BABELTRACE_BIN" --plugin-path "${BT2_PLUGINS_DIR}" "${trace_path}" -c filter.lttngtest.event_name -p "names=[\"${event_name_expected_to_be_missing}\"]" -c sink.lttngtest.field_stats |
grep -v index
2> /dev
/null
)
144 if [ ! -z "$stats" ]; then
145 fail
"Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
147 ok
0 "Validate trace exclusion output"
151 rm -f $file_wait_before_first
152 rm -f $file_create_in_main
155 function test_exclusion_fail
160 create_lttng_session_ok
$SESSION_NAME $trace_path
161 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
-u "$event_name" -s $sess_name -x "$exclusions" >/dev
/null
2>&1
163 destroy_lttng_session_ok
$SESSION_NAME
165 if [ $res -eq 0 ]; then
166 fail
"Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" passes"
169 pass
"Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" fails"
174 plan_tests
$NUM_TESTS
176 print_test_banner
"$TEST_DESC"
178 bail_out_if_no_babeltrace
182 diag
"Enable event without exclusion"
185 diag
"Enable event with exclusion"
186 test_exclusion
'tp:tptest2' 'tp:tptest2'
187 test_exclusion
'tp:tptest3' 'tp:tptest3'
188 test_exclusion
'tp:tptest*' 'tp:tptest1'
189 test_exclusion
'tp:tptest*' 'tp:tptest2'
190 test_exclusion
'tp:tptest*' 'tp:tptest3'
191 test_exclusion
'tp:tptest*' 'tp:tptest4'
192 test_exclusion
'tp:tptest*' 'tp:tptest5'
193 test_exclusion
'tp*tptest*' 'tp:tptest1'
194 test_exclusion
'tp*tptest*' 'tp:tptest2'
195 test_exclusion
'tp*tptest*' 'tp:tptest3'
196 test_exclusion
'tp*tptest*' 'tp:tptest4'
197 test_exclusion
'tp*tptest*' 'tp:tptest5'
198 test_exclusion
'*test2' 'tp:tptest2'
199 test_exclusion
'*test5' 'tp:tptest5'
200 test_exclusion
'*p*test*' 'tp:tptest1'
201 test_exclusion
'*p*test*' 'tp:tptest2'
202 test_exclusion
'*p*test*' 'tp:tptest3'
203 test_exclusion
'*p***test*' 'tp:tptest4'
204 test_exclusion
'*p*test*' 'tp:tptest5'
205 test_exclusion
'*3' 'tp:tptest3'
206 test_exclusion
'tp*test3,*2' 'tp:tptest2'
207 test_exclusion
'**tp*test3,*2' 'tp:tptest3'
209 test_exclusion_tracing_started
'tp:tptest1' 'tp:tptest1'
211 diag
"Cannot use exclusions with non-globbing event name"
212 test_exclusion_fail
"allo" "lol"
213 test_exclusion_fail
"allo" "meow,lol"
214 test_exclusion_fail
"allo" "z*em"
216 diag
"Exclusion name excludes all possible event names"
217 test_exclusion_fail
"allo*" "all*"
218 test_exclusion_fail
"allo*" "ze,all*,yes"