Commit | Line | Data |
---|---|---|
345121ec DG |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com> |
345121ec | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: GPL-2.0-only |
345121ec | 6 | # |
345121ec DG |
7 | |
8 | TEST_DESC="Event exclusion" | |
9 | ||
10 | CURDIR=$(dirname $0)/ | |
11 | TESTDIR=$CURDIR/../../.. | |
9f263671 KS |
12 | BT2_PLUGINS_DIR="${TESTDIR}/utils/bt2_plugins" |
13 | ||
345121ec | 14 | SESSION_NAME="test-exclusion" |
345121ec DG |
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 | |
e4598313 | 20 | NUM_TESTS=185 |
345121ec DG |
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 | ||
a0e115d5 | 29 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $sess_name -x "$exclusion" > /dev/null |
345121ec DG |
30 | } |
31 | ||
32 | function run_apps | |
33 | { | |
8db430e7 | 34 | $TESTAPP_BIN --iter $NR_ITER --wait $NR_USEC_WAIT >/dev/null 2>&1 |
afa7d3f1 FD |
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 | { | |
8d5a3312 | 44 | local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
afa7d3f1 FD |
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 | ||
c125de8f | 57 | nb_events=$("$BABELTRACE_BIN" $trace_path | wc -l) |
afa7d3f1 FD |
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 | |
345121ec DG |
68 | } |
69 | ||
70 | function test_exclusion | |
71 | { | |
33e55711 FD |
72 | local exclusions="$1" |
73 | local event_name_expected_to_be_missing="$2" | |
8d5a3312 | 74 | local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
345121ec DG |
75 | |
76 | # Create session | |
bf6ae429 | 77 | create_lttng_session_ok $SESSION_NAME $trace_path |
345121ec | 78 | |
062f6132 PP |
79 | enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions" |
80 | ok $? "Enable lttng event with event \"$exclusions\" excluded" | |
345121ec DG |
81 | |
82 | # Trace apps | |
e563bbdb | 83 | start_lttng_tracing_ok $SESSION_NAME |
345121ec | 84 | run_apps |
96340a01 | 85 | stop_lttng_tracing_ok $SESSION_NAME |
345121ec DG |
86 | |
87 | # Destroy session | |
67b4c664 | 88 | destroy_lttng_session_ok $SESSION_NAME |
345121ec | 89 | |
9f263671 | 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) |
345121ec | 91 | if [ ! -z "$stats" ]; then |
062f6132 | 92 | fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!" |
345121ec DG |
93 | else |
94 | ok 0 "Validate trace exclusion output" | |
95 | rm -rf $trace_path | |
96 | fi | |
97 | } | |
98 | ||
e4598313 FD |
99 | function test_exclusion_tracing_started |
100 | { | |
101 | local exclusions="$1" | |
102 | local event_name_expected_to_be_missing="$2" | |
8d5a3312 MJ |
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") | |
e4598313 FD |
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 | ||
9f263671 | 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) |
e4598313 FD |
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 | |
0d0386e0 FD |
150 | |
151 | rm -f $file_wait_before_first | |
152 | rm -f $file_create_in_main | |
e4598313 FD |
153 | } |
154 | ||
062f6132 PP |
155 | function test_exclusion_fail |
156 | { | |
157 | event_name="$1" | |
158 | exclusions="$2" | |
159 | ||
160 | create_lttng_session_ok $SESSION_NAME $trace_path | |
6efba076 | 161 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "$event_name" -s $sess_name -x "$exclusions" >/dev/null 2>&1 |
062f6132 PP |
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 | ||
345121ec DG |
174 | plan_tests $NUM_TESTS |
175 | ||
a0e115d5 | 176 | print_test_banner "$TEST_DESC" |
345121ec | 177 | |
c125de8f FD |
178 | bail_out_if_no_babeltrace |
179 | ||
345121ec DG |
180 | start_lttng_sessiond |
181 | ||
a0e115d5 | 182 | diag "Enable event without exclusion" |
afa7d3f1 FD |
183 | dry_run |
184 | ||
a0e115d5 | 185 | diag "Enable event with exclusion" |
062f6132 PP |
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 | ||
e4598313 FD |
209 | test_exclusion_tracing_started 'tp:tptest1' 'tp:tptest1' |
210 | ||
a0e115d5 | 211 | diag "Cannot use exclusions with non-globbing event name" |
062f6132 PP |
212 | test_exclusion_fail "allo" "lol" |
213 | test_exclusion_fail "allo" "meow,lol" | |
214 | test_exclusion_fail "allo" "z*em" | |
215 | ||
a0e115d5 | 216 | diag "Exclusion name excludes all possible event names" |
062f6132 PP |
217 | test_exclusion_fail "allo*" "all*" |
218 | test_exclusion_fail "allo*" "ze,all*,yes" | |
345121ec DG |
219 | |
220 | stop_lttng_sessiond |