Debian Codegraph @

tests/regression/tools/exclusion/test_exclusion

raw symbols SCIP
1 #!/bin/bash
2 #
3 # SPDX-FileCopyrightText: 2012 Christian Babeux <[email protected]>
4 #
5 # SPDX-License-Identifier: GPL-2.0-only
6 #
7
8 TEST_DESC="Event exclusion"
9
10 CURDIR=$(dirname $0)/
11 TESTDIR=$CURDIR/../../..
12 BT2_PLUGINS_DIR="${TESTDIR}/utils/bt2_plugins"
13
14 SESSION_NAME="test-exclusion"
15 TESTAPP_PATH="$TESTDIR/utils/testapp"
16 TESTAPP_NAME="gen-ust-nevents"
17 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME"
18 NR_ITER=100
19 NR_USEC_WAIT=1
20 NUM_TESTS=185
21
22 source $TESTDIR/utils/utils.sh
23
24 function enable_ust_lttng_all_event_exclusion()
25 {
26 sess_name="$1"
27 exclusion="$2"
28
29 _run_lttng_cmd "$(lttng_client_log_file)" "$(lttng_client_err_file)" \
30 enable-event --userspace "tp:*" --session "$sess_name" \
31 --exclude "$exclusion"
32 }
33
34 function run_apps
35 {
36 $TESTAPP_BIN --iter $NR_ITER --wait $NR_USEC_WAIT >/dev/null 2>&1
37 ok $? "Running test application"
38 }
39
40 # Testing for the absence of an event when testing exclusion is tricky. An
41 # event could be absent because our exclusion mechanism works but also because
42 # the event was not generate in the first place. This function test the ability
43 # of our test suite to generate events.
44 function dry_run
45 {
46 local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
47
48 # Create session
49 create_lttng_session_ok $SESSION_NAME $trace_path
50
51 _run_lttng_cmd "$(lttng_client_log_file)" "$(lttng_client_err_file)" \
52 enable-event --userspace "tp:*" --session "$SESSION_NAME"
53 ok $? "Enabling events without exclusion"
54
55 # Trace apps
56 start_lttng_tracing_ok $SESSION_NAME
57 run_apps
58 stop_lttng_tracing_ok $SESSION_NAME
59
60 nb_events=$("_run_babeltrace_cmd" $trace_path | wc -l)
61 if [ "$nb_events" -ne "0" ]; then
62 ok 0 "Events were found during the dry run without exclusion"
63 else
64 fail "No events were found during the dry run without exclusion"
65 fi
66
67 rm -rf $trace_path
68
69 # Destroy session
70 destroy_lttng_session_ok $SESSION_NAME
71 }
72
73 function test_exclusion
74 {
75 local exclusions="$1"
76 local event_name_expected_to_be_missing="$2"
77 local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
78
79 # Create session
80 create_lttng_session_ok $SESSION_NAME $trace_path
81
82 enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
83 ok $? "Enable lttng event with event \"$exclusions\" excluded"
84
85 # Trace apps
86 start_lttng_tracing_ok $SESSION_NAME
87 run_apps
88 stop_lttng_tracing_ok $SESSION_NAME
89
90 # Destroy session
91 destroy_lttng_session_ok $SESSION_NAME
92
93 stats=$("_run_babeltrace_cmd" --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)
94 if [ ! -z "$stats" ]; then
95 fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
96 else
97 ok 0 "Validate trace exclusion output"
98 rm -rf $trace_path
99 fi
100 }
101
102 function test_exclusion_tracing_started
103 {
104 local exclusions="$1"
105 local event_name_expected_to_be_missing="$2"
106 local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
107 local file_sync_before_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_first.XXXXXX")
108 local file_sync_app_in_main_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_app_in_main.XXXXXX")
109
110 # Create session
111 create_lttng_session_ok $SESSION_NAME $trace_path
112
113 # Enable a dummy event so that the session is active after we start the
114 # session.
115 enable_ust_lttng_event_ok $SESSION_NAME "non-existent-event"
116
117 # Start the tracing
118 start_lttng_tracing_ok $SESSION_NAME
119
120 # Launch the test app and make it create a sync file once it's in the
121 # main function.
122 $TESTAPP_BIN -i 1 -w 10000 \
123 --sync-application-in-main-touch ${file_sync_app_in_main_touch} \
124 --sync-before-first-event ${file_sync_before_first} 2>&1 &
125 tracee_pids+=("${!}")
126
127 while [ ! -f "${file_sync_app_in_main_touch}" ]; do
128 sleep 0.5
129 done
130
131 # Enable an event with an exclusion once the tracing is active in the
132 # UST app.
133 enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
134 ok $? "Enable lttng event with event \"$exclusions\" excluded"
135
136 # Create the sync file so that the test app starts generating events.
137 touch ${file_sync_before_first}
138
139 # Wait for the testapp to finish.
140 wait "${tracee_pids[@]}"
141 tracee_pids=()
142
143 stop_lttng_tracing_ok $SESSION_NAME
144
145 # Destroy session
146 destroy_lttng_session_ok $SESSION_NAME
147
148 stats=$("_run_babeltrace_cmd" --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)
149 if [ ! -z "$stats" ]; then
150 fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
151 else
152 ok 0 "Validate trace exclusion output"
153 rm -rf $trace_path
154 fi
155
156 rm -f $file_sync_before_first
157 rm -f $file_sync_app_in_main_touch
158 }
159
160 function test_exclusion_fail
161 {
162 event_name="$1"
163 exclusions="$2"
164
165 create_lttng_session_ok $SESSION_NAME $trace_path
166 _run_lttng_cmd "$(lttng_client_log_file)" "$(lttng_client_err_file)" \
167 enable-event --userspace "$event_name" --session "$sess_name" \
168 --exclude "$exclusions"
169 res=$?
170 destroy_lttng_session_ok $SESSION_NAME
171
172 if [ $res -eq 0 ]; then
173 fail "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" passes"
174 return 1
175 else
176 pass "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" fails"
177 return 0
178 fi
179 }
180
181 plan_tests $NUM_TESTS
182
183 print_test_banner "$TEST_DESC"
184
185 bail_out_if_no_babeltrace
186
187 start_lttng_sessiond
188 tracee_pids=()
189
190 diag "Enable event without exclusion"
191 dry_run
192
193 diag "Enable event with exclusion"
194 test_exclusion 'tp:tptest2' 'tp:tptest2'
195 test_exclusion 'tp:tptest3' 'tp:tptest3'
196 test_exclusion 'tp:tptest*' 'tp:tptest1'
197 test_exclusion 'tp:tptest*' 'tp:tptest2'
198 test_exclusion 'tp:tptest*' 'tp:tptest3'
199 test_exclusion 'tp:tptest*' 'tp:tptest4'
200 test_exclusion 'tp:tptest*' 'tp:tptest5'
201 test_exclusion 'tp*tptest*' 'tp:tptest1'
202 test_exclusion 'tp*tptest*' 'tp:tptest2'
203 test_exclusion 'tp*tptest*' 'tp:tptest3'
204 test_exclusion 'tp*tptest*' 'tp:tptest4'
205 test_exclusion 'tp*tptest*' 'tp:tptest5'
206 test_exclusion '*test2' 'tp:tptest2'
207 test_exclusion '*test5' 'tp:tptest5'
208 test_exclusion '*p*test*' 'tp:tptest1'
209 test_exclusion '*p*test*' 'tp:tptest2'
210 test_exclusion '*p*test*' 'tp:tptest3'
211 test_exclusion '*p***test*' 'tp:tptest4'
212 test_exclusion '*p*test*' 'tp:tptest5'
213 test_exclusion '*3' 'tp:tptest3'
214 test_exclusion 'tp*test3,*2' 'tp:tptest2'
215 test_exclusion '**tp*test3,*2' 'tp:tptest3'
216
217 test_exclusion_tracing_started 'tp:tptest1' 'tp:tptest1'
218
219 diag "Cannot use exclusions with non-globbing event name"
220 test_exclusion_fail "allo" "lol"
221 test_exclusion_fail "allo" "meow,lol"
222 test_exclusion_fail "allo" "z*em"
223
224 diag "Exclusion name excludes all possible event names"
225 test_exclusion_fail "allo*" "all*"
226 test_exclusion_fail "allo*" "ze,all*,yes"
227
228 stop_lttng_sessiond