docs: Add supported versions and fix-backport policy
[lttng-tools.git] / tests / regression / tools / exclusion / test_exclusion
1 #!/bin/bash
2 #
3 # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
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/$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 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $sess_name -x "$exclusion" > /dev/null
30 }
31
32 function run_apps
33 {
34 $TESTAPP_BIN --iter $NR_ITER --wait $NR_USEC_WAIT >/dev/null 2>&1
35 ok $? "Running test application"
36 }
37
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.
42 function dry_run
43 {
44 local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
45
46 # Create session
47 create_lttng_session_ok $SESSION_NAME $trace_path
48
49 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $SESSION_NAME > /dev/null
50 ok $? "Enabling events without exclusion"
51
52 # Trace apps
53 start_lttng_tracing_ok $SESSION_NAME
54 run_apps
55 stop_lttng_tracing_ok $SESSION_NAME
56
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"
60 else
61 fail "No events were found during the dry run without exclusion"
62 fi
63
64 rm -rf $trace_path
65
66 # Destroy session
67 destroy_lttng_session_ok $SESSION_NAME
68 }
69
70 function test_exclusion
71 {
72 local exclusions="$1"
73 local event_name_expected_to_be_missing="$2"
74 local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
75
76 # Create session
77 create_lttng_session_ok $SESSION_NAME $trace_path
78
79 enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
80 ok $? "Enable lttng event with event \"$exclusions\" excluded"
81
82 # Trace apps
83 start_lttng_tracing_ok $SESSION_NAME
84 run_apps
85 stop_lttng_tracing_ok $SESSION_NAME
86
87 # Destroy session
88 destroy_lttng_session_ok $SESSION_NAME
89
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!"
93 else
94 ok 0 "Validate trace exclusion output"
95 rm -rf $trace_path
96 fi
97 }
98
99 function test_exclusion_tracing_started
100 {
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")
106
107 # Create session
108 create_lttng_session_ok $SESSION_NAME $trace_path
109
110 # Enable a dummy event so that the session is active after we start the
111 # session.
112 enable_ust_lttng_event_ok $SESSION_NAME "non-existent-event"
113
114 # Start the tracing
115 start_lttng_tracing_ok $SESSION_NAME
116
117 # Launch the test app and make it create a sync file once it's in the
118 # main function.
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 &
122
123 while [ ! -f "${file_create_in_main}" ]; do
124 sleep 0.5
125 done
126
127 # Enable an event with an exclusion once the tracing is active in the
128 # UST app.
129 enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
130 ok $? "Enable lttng event with event \"$exclusions\" excluded"
131
132 # Create the sync file so that the test app starts generating events.
133 touch ${file_wait_before_first}
134
135 # Wait for the testapp to finish.
136 wait
137
138 stop_lttng_tracing_ok $SESSION_NAME
139
140 # Destroy session
141 destroy_lttng_session_ok $SESSION_NAME
142
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!"
146 else
147 ok 0 "Validate trace exclusion output"
148 rm -rf $trace_path
149 fi
150
151 rm -f $file_wait_before_first
152 rm -f $file_create_in_main
153 }
154
155 function test_exclusion_fail
156 {
157 event_name="$1"
158 exclusions="$2"
159
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
162 res=$?
163 destroy_lttng_session_ok $SESSION_NAME
164
165 if [ $res -eq 0 ]; then
166 fail "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" passes"
167 return 1
168 else
169 pass "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" fails"
170 return 0
171 fi
172 }
173
174 plan_tests $NUM_TESTS
175
176 print_test_banner "$TEST_DESC"
177
178 bail_out_if_no_babeltrace
179
180 start_lttng_sessiond
181
182 diag "Enable event without exclusion"
183 dry_run
184
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'
208
209 test_exclusion_tracing_started 'tp:tptest1' 'tp:tptest1'
210
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"
215
216 diag "Exclusion name excludes all possible event names"
217 test_exclusion_fail "allo*" "all*"
218 test_exclusion_fail "allo*" "ze,all*,yes"
219
220 stop_lttng_sessiond
This page took 0.034069 seconds and 5 git commands to generate.