tests: Move to kernel style SPDX license identifiers
[lttng-tools.git] / tests / regression / tools / crash / test_crash
CommitLineData
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
8TEST_DESC="LTTng-crash & shm testing"
9
10CURDIR=$(dirname $0)/
11TESTDIR=$CURDIR/../../../
12CRASH_BIN="lttng-crash"
13
14# Test app for ust event
15TESTAPP_PATH="$TESTDIR/utils/testapp"
16TESTAPP_NAME="gen-ust-events"
17TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
18NR_USEC_WAIT=0
19NR_ITER=-1
20
21# Temp file output
22OUTPUT_DIR=$(mktemp -d)
23
44e941b7
MD
24LAST_APP_PID=
25
c02a94c4 26NUM_TESTS=77
4c80129b
JR
27
28source $TESTDIR/utils/utils.sh
29
30# Global declaration for simplification
31LTTNG_CRASH=$TESTDIR/../src/bin/lttng-crash/$CRASH_BIN
32
33# MUST set TESTDIR before calling those functions
34plan_tests $NUM_TESTS
35
36print_test_banner "$TEST_DESC"
37
38function start_test_app()
39{
40 local tmp_file=$(mktemp -u)
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
58function 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
70function 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
81function 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
91function 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
96 local shm_path=$(mktemp -d)
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
163function 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
168 local shm_path=$(mktemp -d)
169
170 # Build up
171 start_lttng_sessiond
172 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
173 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
174
c02a94c4
MD
175 start_lttng_tracing_ok $session_name
176
4c80129b
JR
177 diag "Shm: test clean state"
178 file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
179 test $file_count -eq "0"
180 ok $? "No files created on set-up"
181
182 # Look for per-pid folder structure
183 # Start first test app
184 diag "Shm: check folder creation and structure"
185
186 start_test_app
187 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
188 file_count=$(echo "$shm_session_path"| wc -l)
189 test $file_count -eq "1"
190 ok $? "Path $shm_session_path created on application creation"
191
192 uid_path=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1)
193 ok $? "uid path exist found $uid_path"
194
195 file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l)
196 test $file_count -eq "1"
197 ok $? "Expect 1 uid registration folder got $file_count"
198
199 # Stop all applications and check for uid presence
200 stop_test_apps
201 file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l)
202 test $file_count -eq "1"
203 ok $? "Expect 1 uid registration folder got $file_count"
204
205 # Test full cleanup
206 destroy_lttng_session_ok $session_name
207 verify_path_dont_exists "$shm_session_path"
208 ok $? "Full cleanup"
209
210 stop_lttng_sessiond
211 rm -rf $shm_path
212}
213
214function test_lttng_crash()
215{
216 diag "Lttng-crash: basic recuperation"
217 local session_name=crash_test
218 local channel_name=channel_crash
219 local shm_path=$(mktemp -d)
93c4b583 220 local shm_path_symlink=$(mktemp -d)
4c80129b
JR
221 local event_name="tp:tptest"
222
223 # Create a session in snapshot mode to deactivate any use of consumerd
224 start_lttng_sessiond
225 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
226 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
227 enable_ust_lttng_event_ok $session_name $event_name $channel_name
228 start_lttng_tracing_ok $session_name
229
230 # Generate 10 events
6c4a91d6 231 $TESTAPP_BIN -i 10 -w 0
7fe98a98 232 stop_lttng_tracing_ok
4c80129b
JR
233
234 crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l)
235 test $crash_recup_count -eq "10"
236 ok $? "Expect 10 recup event from buffers got $crash_recup_count"
237
93c4b583
JR
238 # Test with symlink
239 cp -rs $shm_path/. $shm_path_symlink
240 crash_recup_count=$($LTTNG_CRASH $shm_path_symlink | wc -l)
241 test $crash_recup_count -eq "10"
242 ok $? "Expect 10 recup event from symlink buffers got $crash_recup_count"
243
4c80129b
JR
244 # Tear down
245 destroy_lttng_session_ok $session_name
246 stop_lttng_sessiond
247 rm -rf $shm_path
93c4b583 248 rm -rf $shm_path_symlink
4c80129b
JR
249}
250
251function test_lttng_crash_extraction()
252{
253 diag "Lttng-crash: extraction to path"
254 local session_name=crash_test
255 local channel_name=channel_crash
256 local shm_path=$(mktemp -d)
257 local extraction_dir_path=$(mktemp -d)
258 local extraction_path=$extraction_dir_path/extract
259 local event_name="tp:tptest"
260
261 # Create a session in snapshot mode to deactivate any use of consumerd
262 start_lttng_sessiond
263 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
264 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
265 enable_ust_lttng_event_ok $session_name $event_name $channel_name
266
267 start_lttng_tracing_ok $session_name
268 # Generate 10 events
6c4a91d6 269 $TESTAPP_BIN -i 10 -w 0
7fe98a98 270 stop_lttng_tracing_ok
4c80129b
JR
271
272 $LTTNG_CRASH -x $extraction_path $shm_path
273 ok $? "Extraction of crashed buffers to path"
274
275 # Test extracted trace
276 trace_match_only $event_name 10 $extraction_path
277
278 # Tear down
279 destroy_lttng_session_ok $session_name
280 stop_lttng_sessiond
281 rm -rf $shm_path
282 rm -rf $extraction_dir_path
283}
284
285function test_shm_path_per_pid_sigint()
286{
287 diag "Shm: ust per-pid test sigint"
288 local session_name=shm_path_per_pid
289 local channel_name=channel_per_pid
290 local shm_path=$(mktemp -d)
291 local num_files=0
292
293 # Build up
294 start_lttng_sessiond
295 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
296 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
297
c02a94c4
MD
298 start_lttng_tracing_ok $session_name
299
4c80129b
JR
300 start_test_app
301 start_test_app
302 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
303
304 # Stop sessiond with sigint
305 stop_lttng_sessiond SIGINT
306
307 # Looking for a full cleanup
308 verify_path_dont_exists "$shm_session_path"
309 ok $? "Full cleanup on sigint"
310
311 # Tear down
312 stop_test_apps
313 rm -rf $shm_path
314}
315
316function test_shm_path_per_uid_sigint()
317{
318 diag "Shm: ust per-uid test sigint"
319 local session_name=shm_path_per_uid_sigint
320 local channel_name=channel_per_uid_sigint
321 local shm_path=$(mktemp -d)
322 local ret=0
323
324 # Build up
325 start_lttng_sessiond
326 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
327 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
328
c02a94c4
MD
329 start_lttng_tracing_ok $session_name
330
4c80129b
JR
331 start_test_app
332 start_test_app
333 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
334
335 # Test full cleanup on SIGINT
336 stop_lttng_sessiond SIGINT
337
338 # Looking for a full cleanup
339 verify_path_dont_exists "$shm_session_path"
340 ok $? "Full cleanup on sigint"
341
342 # Tear down
343 stop_test_apps
344 rm -rf $shm_path
345}
346
347function test_lttng_crash_extraction_sigkill()
348{
349 diag "Lttng-crash: extraction with sigkill"
350 local session_name=crash_test
351 local channel_name=channel_crash
352 local shm_path=$(mktemp -d)
353 local extraction_dir_path=$(mktemp -d)
354 local extraction_path=$extraction_dir_path/extract
355 local event_name="tp:tptest"
356 local ret=0
357
358 start_lttng_sessiond
359 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
360 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
361 enable_ust_lttng_event_ok $session_name $event_name $channel_name
362 start_lttng_tracing_ok $session_name
363
364 # Generate 10 events
6c4a91d6 365 $TESTAPP_BIN -i 10 -w 0
4c80129b 366
8490897a
MD
367 sigstop_lttng_sessiond
368 sigstop_lttng_consumerd
369
4c80129b
JR
370 # Kill the consumers then sessiond with sigkill
371 stop_lttng_consumerd SIGKILL
372 stop_lttng_sessiond SIGKILL
373
374 $LTTNG_CRASH -x $extraction_path $shm_path
375 ret=$?
376 ok $ret "Extraction of crashed buffers to path $extraction_path"
377
378 # Test extracted trace
379 trace_match_only $event_name 10 $extraction_path
380
381 # Tear down
382 stop_test_apps
383 rm -rf $shm_path
384 rm -rf $extraction_dir_path
385}
386
3e46b4ca
JG
387function interrupt_cleanup()
388{
389 diag "*** Cleaning-up test ***"
390 stop_test_apps
3be453c9 391 full_cleanup
3e46b4ca
JG
392}
393
4c80129b
JR
394TESTS=(
395 test_shm_path_per_uid
396 test_shm_path_per_pid
4c80129b
JR
397 test_shm_path_per_pid_sigint
398 test_shm_path_per_uid_sigint
93c4b583
JR
399 test_lttng_crash
400 test_lttng_crash_extraction
4c80129b
JR
401 test_lttng_crash_extraction_sigkill
402)
403
3e46b4ca 404trap interrupt_cleanup SIGTERM SIGINT
4c80129b
JR
405
406for fct_test in ${TESTS[@]};
407do
408 ${fct_test}
409 if [ $? -ne 0 ]; then
410 break;
411 fi
412done
413rm -rf $OUTPUT_DIR
414
415OUTPUT_DEST=/dev/null 2>&1
This page took 0.047277 seconds and 4 git commands to generate.