Commit | Line | Data |
---|---|---|
4c80129b JR |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> |
4c80129b | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: LGPL-2.1-only |
4c80129b | 6 | # |
4c80129b JR |
7 | |
8 | TEST_DESC="LTTng-crash & shm testing" | |
9 | ||
10 | CURDIR=$(dirname $0)/ | |
11 | TESTDIR=$CURDIR/../../../ | |
12 | CRASH_BIN="lttng-crash" | |
13 | ||
14 | # Test app for ust event | |
15 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
16 | TESTAPP_NAME="gen-ust-events" | |
17 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
18 | NR_USEC_WAIT=0 | |
19 | NR_ITER=-1 | |
20 | ||
21 | # Temp file output | |
7539dcec | 22 | OUTPUT_DIR=$(mktemp -d --tmpdir tmp.test_crash_shm.XXXXXX) |
4c80129b | 23 | |
44e941b7 MD |
24 | LAST_APP_PID= |
25 | ||
c02a94c4 | 26 | NUM_TESTS=77 |
4c80129b JR |
27 | |
28 | source $TESTDIR/utils/utils.sh | |
29 | ||
30 | # Global declaration for simplification | |
31 | LTTNG_CRASH=$TESTDIR/../src/bin/lttng-crash/$CRASH_BIN | |
32 | ||
33 | # MUST set TESTDIR before calling those functions | |
34 | plan_tests $NUM_TESTS | |
35 | ||
36 | print_test_banner "$TEST_DESC" | |
37 | ||
38 | function start_test_app() | |
39 | { | |
7539dcec | 40 | local tmp_file=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}.XXXXXX") |
4c80129b JR |
41 | |
42 | # Start application with a temporary file. | |
6c4a91d6 | 43 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file & |
4c80129b | 44 | ret=$? |
44e941b7 | 45 | LAST_APP_PID="${!}" |
4c80129b JR |
46 | APPS_PID="${APPS_PID} ${!}" |
47 | ok $ret "Start application to trace" | |
48 | ||
49 | # Wait for the application file to appear indicating that at least one | |
50 | # tracepoint has been fired. | |
51 | while [ ! -f "$tmp_file" ]; do | |
52 | sleep 0.5 | |
53 | done | |
54 | diag "Removing test app temporary file $tmp_file" | |
55 | rm -rf $tmp_file | |
56 | } | |
57 | ||
58 | function stop_test_apps() | |
59 | { | |
60 | diag "Stopping $TESTAPP_NAME" | |
61 | for p in ${APPS_PID}; do | |
62 | diag "Stopping $p" | |
63 | kill ${p} 2>/dev/null | |
64 | wait ${p} 2>/dev/null | |
65 | diag "Stopped $p" | |
66 | done | |
67 | APPS_PID= | |
68 | } | |
69 | ||
70 | function stop_test_app() | |
71 | { | |
72 | local pid="$1" | |
73 | for p in ${pid}; do | |
74 | diag "Stopping $p" | |
75 | kill ${p} 2>/dev/null | |
76 | wait ${p} 2>/dev/null | |
44e941b7 | 77 | diag "Stopped $p" |
4c80129b JR |
78 | done |
79 | } | |
80 | ||
81 | function verify_path_dont_exists() | |
82 | { | |
83 | local path=$1 | |
4c80129b JR |
84 | |
85 | while find $path -mindepth 1 -maxdepth 1 &>/dev/null ; do | |
91d98ef4 | 86 | sleep 2 |
4c80129b | 87 | done |
91d98ef4 | 88 | return 0 |
4c80129b JR |
89 | } |
90 | ||
91 | function test_shm_path_per_pid() | |
92 | { | |
93 | diag "Shm: ust per-pid test" | |
94 | local session_name=shm_path_per_pid | |
95 | local channel_name=channel_per_pid | |
7539dcec | 96 | local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm.XXXXXX") |
4c80129b JR |
97 | |
98 | # Build up | |
99 | start_lttng_sessiond | |
100 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" | |
101 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid" | |
102 | ||
c02a94c4 MD |
103 | start_lttng_tracing_ok $session_name |
104 | ||
4c80129b JR |
105 | diag "Shm: clean state" |
106 | file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l) | |
107 | test $file_count -eq "0" | |
108 | ok $? "No file created on set-up" | |
109 | ||
110 | # Look for per-pid folder structure | |
111 | # Start first test app | |
112 | diag "Shm: check folder creation and structure" | |
113 | ||
114 | start_test_app | |
44e941b7 | 115 | first_app_pid=$LAST_APP_PID |
4c80129b JR |
116 | shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1) |
117 | ||
118 | file_count=$(echo "$shm_session_path"| wc -l) | |
119 | test $file_count -eq "1" | |
120 | ok $? "Path $shm_session_path created on application creation" | |
121 | ||
122 | first_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1) | |
123 | ok $? "Pid path exists: $first_pid_path" | |
124 | ||
125 | file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l) | |
126 | test $file_count -eq "1" | |
127 | ok $? "Expect 1 pid registration folder got $file_count" | |
128 | ||
129 | # Check for buffer and metadata presence in ust/pid/appfolder | |
130 | file_count=$(find $first_pid_path/ -mindepth 1 -maxdepth 1 | wc -l) | |
131 | test $file_count -ne "0" | |
132 | ok $? "Expect > 0 buffer and metadata files got $file_count" | |
133 | ||
134 | # Start second application pid | |
135 | diag "Shm: check basic creation of second ust application" | |
136 | ||
137 | start_test_app | |
44e941b7 | 138 | second_app_pid=$LAST_APP_PID |
4c80129b JR |
139 | second_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1) |
140 | ok $? "Pid path exist found $second_pid_path" | |
141 | ||
142 | file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l) | |
143 | test $file_count -eq "2" | |
144 | ok $? "Expect 2 pid registration folder got $file_count" | |
145 | ||
146 | # Stop first test application and check for cleanup | |
147 | stop_test_app "$first_app_pid" | |
44e941b7 | 148 | APPS_PID="$second_app_pid" |
4c80129b JR |
149 | verify_path_dont_exists "$first_pid_path" |
150 | ok $? "First pid cleanup" | |
151 | ||
152 | # Stop all applications and check for full cleanup | |
153 | stop_test_apps | |
154 | verify_path_dont_exists "$shm_session_path" | |
155 | ok $? "Full cleanup" | |
156 | ||
157 | # Tear down | |
158 | destroy_lttng_session_ok $session_name | |
159 | stop_lttng_sessiond | |
160 | rm -rf $shm_path | |
161 | } | |
162 | ||
163 | function test_shm_path_per_uid() | |
164 | { | |
165 | diag "Shm: ust per-uid test" | |
166 | local session_name=shm_path_per_uid | |
167 | local channel_name=channel_per_uid | |
7539dcec FD |
168 | set -x |
169 | local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX") | |
170 | set +x | |
4c80129b JR |
171 | |
172 | # Build up | |
173 | start_lttng_sessiond | |
174 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" | |
175 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" | |
176 | ||
c02a94c4 MD |
177 | start_lttng_tracing_ok $session_name |
178 | ||
4c80129b JR |
179 | diag "Shm: test clean state" |
180 | file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l) | |
181 | test $file_count -eq "0" | |
182 | ok $? "No files created on set-up" | |
183 | ||
184 | # Look for per-pid folder structure | |
185 | # Start first test app | |
186 | diag "Shm: check folder creation and structure" | |
187 | ||
188 | start_test_app | |
189 | shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1) | |
190 | file_count=$(echo "$shm_session_path"| wc -l) | |
191 | test $file_count -eq "1" | |
192 | ok $? "Path $shm_session_path created on application creation" | |
193 | ||
194 | uid_path=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1) | |
195 | ok $? "uid path exist found $uid_path" | |
196 | ||
197 | file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l) | |
198 | test $file_count -eq "1" | |
199 | ok $? "Expect 1 uid registration folder got $file_count" | |
200 | ||
201 | # Stop all applications and check for uid presence | |
202 | stop_test_apps | |
203 | file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l) | |
204 | test $file_count -eq "1" | |
205 | ok $? "Expect 1 uid registration folder got $file_count" | |
206 | ||
207 | # Test full cleanup | |
208 | destroy_lttng_session_ok $session_name | |
209 | verify_path_dont_exists "$shm_session_path" | |
210 | ok $? "Full cleanup" | |
211 | ||
212 | stop_lttng_sessiond | |
213 | rm -rf $shm_path | |
214 | } | |
215 | ||
216 | function test_lttng_crash() | |
217 | { | |
218 | diag "Lttng-crash: basic recuperation" | |
219 | local session_name=crash_test | |
220 | local channel_name=channel_crash | |
7539dcec FD |
221 | local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX") |
222 | local shm_path_symlink=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path_symlink.XXXXXX") | |
4c80129b JR |
223 | local event_name="tp:tptest" |
224 | ||
225 | # Create a session in snapshot mode to deactivate any use of consumerd | |
226 | start_lttng_sessiond | |
227 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot" | |
228 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" | |
229 | enable_ust_lttng_event_ok $session_name $event_name $channel_name | |
230 | start_lttng_tracing_ok $session_name | |
231 | ||
232 | # Generate 10 events | |
6c4a91d6 | 233 | $TESTAPP_BIN -i 10 -w 0 |
7fe98a98 | 234 | stop_lttng_tracing_ok |
4c80129b JR |
235 | |
236 | crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l) | |
237 | test $crash_recup_count -eq "10" | |
238 | ok $? "Expect 10 recup event from buffers got $crash_recup_count" | |
239 | ||
93c4b583 JR |
240 | # Test with symlink |
241 | cp -rs $shm_path/. $shm_path_symlink | |
242 | crash_recup_count=$($LTTNG_CRASH $shm_path_symlink | wc -l) | |
243 | test $crash_recup_count -eq "10" | |
244 | ok $? "Expect 10 recup event from symlink buffers got $crash_recup_count" | |
245 | ||
4c80129b JR |
246 | # Tear down |
247 | destroy_lttng_session_ok $session_name | |
248 | stop_lttng_sessiond | |
249 | rm -rf $shm_path | |
93c4b583 | 250 | rm -rf $shm_path_symlink |
4c80129b JR |
251 | } |
252 | ||
253 | function test_lttng_crash_extraction() | |
254 | { | |
255 | diag "Lttng-crash: extraction to path" | |
256 | local session_name=crash_test | |
257 | local channel_name=channel_crash | |
7539dcec FD |
258 | local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX") |
259 | local extraction_dir_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_extraction_dir_path.XXXXXX") | |
4c80129b JR |
260 | local extraction_path=$extraction_dir_path/extract |
261 | local event_name="tp:tptest" | |
262 | ||
263 | # Create a session in snapshot mode to deactivate any use of consumerd | |
264 | start_lttng_sessiond | |
265 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot" | |
266 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" | |
267 | enable_ust_lttng_event_ok $session_name $event_name $channel_name | |
268 | ||
269 | start_lttng_tracing_ok $session_name | |
270 | # Generate 10 events | |
6c4a91d6 | 271 | $TESTAPP_BIN -i 10 -w 0 |
7fe98a98 | 272 | stop_lttng_tracing_ok |
4c80129b JR |
273 | |
274 | $LTTNG_CRASH -x $extraction_path $shm_path | |
275 | ok $? "Extraction of crashed buffers to path" | |
276 | ||
277 | # Test extracted trace | |
278 | trace_match_only $event_name 10 $extraction_path | |
279 | ||
280 | # Tear down | |
281 | destroy_lttng_session_ok $session_name | |
282 | stop_lttng_sessiond | |
283 | rm -rf $shm_path | |
284 | rm -rf $extraction_dir_path | |
285 | } | |
286 | ||
287 | function test_shm_path_per_pid_sigint() | |
288 | { | |
289 | diag "Shm: ust per-pid test sigint" | |
290 | local session_name=shm_path_per_pid | |
291 | local channel_name=channel_per_pid | |
7539dcec | 292 | local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX") |
4c80129b JR |
293 | local num_files=0 |
294 | ||
295 | # Build up | |
296 | start_lttng_sessiond | |
297 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" | |
298 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid" | |
299 | ||
c02a94c4 MD |
300 | start_lttng_tracing_ok $session_name |
301 | ||
4c80129b JR |
302 | start_test_app |
303 | start_test_app | |
304 | shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1) | |
305 | ||
306 | # Stop sessiond with sigint | |
307 | stop_lttng_sessiond SIGINT | |
308 | ||
309 | # Looking for a full cleanup | |
310 | verify_path_dont_exists "$shm_session_path" | |
311 | ok $? "Full cleanup on sigint" | |
312 | ||
313 | # Tear down | |
314 | stop_test_apps | |
315 | rm -rf $shm_path | |
316 | } | |
317 | ||
318 | function test_shm_path_per_uid_sigint() | |
319 | { | |
320 | diag "Shm: ust per-uid test sigint" | |
321 | local session_name=shm_path_per_uid_sigint | |
322 | local channel_name=channel_per_uid_sigint | |
7539dcec | 323 | local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX") |
4c80129b JR |
324 | local ret=0 |
325 | ||
326 | # Build up | |
327 | start_lttng_sessiond | |
328 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" | |
329 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" | |
330 | ||
c02a94c4 MD |
331 | start_lttng_tracing_ok $session_name |
332 | ||
4c80129b JR |
333 | start_test_app |
334 | start_test_app | |
335 | shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1) | |
336 | ||
337 | # Test full cleanup on SIGINT | |
338 | stop_lttng_sessiond SIGINT | |
339 | ||
340 | # Looking for a full cleanup | |
341 | verify_path_dont_exists "$shm_session_path" | |
342 | ok $? "Full cleanup on sigint" | |
343 | ||
344 | # Tear down | |
345 | stop_test_apps | |
346 | rm -rf $shm_path | |
347 | } | |
348 | ||
349 | function test_lttng_crash_extraction_sigkill() | |
350 | { | |
351 | diag "Lttng-crash: extraction with sigkill" | |
352 | local session_name=crash_test | |
353 | local channel_name=channel_crash | |
7539dcec FD |
354 | local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX") |
355 | local extraction_dir_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_extraction_dir_path.XXXXXX") | |
4c80129b JR |
356 | local extraction_path=$extraction_dir_path/extract |
357 | local event_name="tp:tptest" | |
358 | local ret=0 | |
359 | ||
360 | start_lttng_sessiond | |
361 | create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path" | |
362 | enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid" | |
363 | enable_ust_lttng_event_ok $session_name $event_name $channel_name | |
364 | start_lttng_tracing_ok $session_name | |
365 | ||
366 | # Generate 10 events | |
6c4a91d6 | 367 | $TESTAPP_BIN -i 10 -w 0 |
4c80129b | 368 | |
8490897a MD |
369 | sigstop_lttng_sessiond |
370 | sigstop_lttng_consumerd | |
371 | ||
4c80129b JR |
372 | # Kill the consumers then sessiond with sigkill |
373 | stop_lttng_consumerd SIGKILL | |
374 | stop_lttng_sessiond SIGKILL | |
375 | ||
376 | $LTTNG_CRASH -x $extraction_path $shm_path | |
377 | ret=$? | |
378 | ok $ret "Extraction of crashed buffers to path $extraction_path" | |
379 | ||
380 | # Test extracted trace | |
381 | trace_match_only $event_name 10 $extraction_path | |
382 | ||
383 | # Tear down | |
384 | stop_test_apps | |
385 | rm -rf $shm_path | |
386 | rm -rf $extraction_dir_path | |
387 | } | |
388 | ||
3e46b4ca JG |
389 | function interrupt_cleanup() |
390 | { | |
391 | diag "*** Cleaning-up test ***" | |
392 | stop_test_apps | |
3be453c9 | 393 | full_cleanup |
3e46b4ca JG |
394 | } |
395 | ||
4c80129b | 396 | TESTS=( |
4c80129b | 397 | test_shm_path_per_pid |
7539dcec | 398 | test_shm_path_per_uid |
4c80129b JR |
399 | test_shm_path_per_pid_sigint |
400 | test_shm_path_per_uid_sigint | |
93c4b583 JR |
401 | test_lttng_crash |
402 | test_lttng_crash_extraction | |
4c80129b JR |
403 | test_lttng_crash_extraction_sigkill |
404 | ) | |
405 | ||
3e46b4ca | 406 | trap interrupt_cleanup SIGTERM SIGINT |
4c80129b JR |
407 | |
408 | for fct_test in ${TESTS[@]}; | |
409 | do | |
410 | ${fct_test} | |
411 | if [ $? -ne 0 ]; then | |
412 | break; | |
413 | fi | |
414 | done | |
415 | rm -rf $OUTPUT_DIR | |
416 | ||
417 | OUTPUT_DEST=/dev/null 2>&1 |