Tests: Clean-up test-crash on SIGTERM and SIGINT
[lttng-tools.git] / tests / regression / tools / crash / test_crash
CommitLineData
4c80129b
JR
1#!/bin/bash
2#
3# Copyright (C) - 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
4#
5# This library is free software; you can redistribute it and/or modify it under
6# the terms of the GNU Lesser General Public License as published by the Free
7# Software Foundation; version 2.1 of the License.
8#
9# This library is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12# details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this library; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18TEST_DESC="LTTng-crash & shm testing"
19
20CURDIR=$(dirname $0)/
21TESTDIR=$CURDIR/../../../
22CRASH_BIN="lttng-crash"
23
24# Test app for ust event
25TESTAPP_PATH="$TESTDIR/utils/testapp"
26TESTAPP_NAME="gen-ust-events"
27TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
28NR_USEC_WAIT=0
29NR_ITER=-1
30
31# Temp file output
32OUTPUT_DIR=$(mktemp -d)
33
93c4b583 34NUM_TESTS=71
4c80129b
JR
35
36source $TESTDIR/utils/utils.sh
37
38# Global declaration for simplification
39LTTNG_CRASH=$TESTDIR/../src/bin/lttng-crash/$CRASH_BIN
40
41# MUST set TESTDIR before calling those functions
42plan_tests $NUM_TESTS
43
44print_test_banner "$TEST_DESC"
45
46function start_test_app()
47{
48 local tmp_file=$(mktemp -u)
49
50 # Start application with a temporary file.
51 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
52 ret=$?
53 APPS_PID="${APPS_PID} ${!}"
54 ok $ret "Start application to trace"
55
56 # Wait for the application file to appear indicating that at least one
57 # tracepoint has been fired.
58 while [ ! -f "$tmp_file" ]; do
59 sleep 0.5
60 done
61 diag "Removing test app temporary file $tmp_file"
62 rm -rf $tmp_file
63}
64
65function stop_test_apps()
66{
67 diag "Stopping $TESTAPP_NAME"
68 for p in ${APPS_PID}; do
69 diag "Stopping $p"
70 kill ${p} 2>/dev/null
71 wait ${p} 2>/dev/null
72 diag "Stopped $p"
73 done
74 APPS_PID=
75}
76
77function stop_test_app()
78{
79 local pid="$1"
80 for p in ${pid}; do
81 diag "Stopping $p"
82 kill ${p} 2>/dev/null
83 wait ${p} 2>/dev/null
84 done
85}
86
87function verify_path_dont_exists()
88{
89 local path=$1
4c80129b
JR
90
91 while find $path -mindepth 1 -maxdepth 1 &>/dev/null ; do
91d98ef4 92 sleep 2
4c80129b 93 done
91d98ef4 94 return 0
4c80129b
JR
95}
96
97function test_shm_path_per_pid()
98{
99 diag "Shm: ust per-pid test"
100 local session_name=shm_path_per_pid
101 local channel_name=channel_per_pid
102 local shm_path=$(mktemp -d)
103
104 # Build up
105 start_lttng_sessiond
106 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
107 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
108
109 diag "Shm: clean state"
110 file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
111 test $file_count -eq "0"
112 ok $? "No file created on set-up"
113
114 # Look for per-pid folder structure
115 # Start first test app
116 diag "Shm: check folder creation and structure"
117
118 start_test_app
119 first_app_pid=$APPS_PID
120 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
121
122 file_count=$(echo "$shm_session_path"| wc -l)
123 test $file_count -eq "1"
124 ok $? "Path $shm_session_path created on application creation"
125
126 first_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1)
127 ok $? "Pid path exists: $first_pid_path"
128
129 file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l)
130 test $file_count -eq "1"
131 ok $? "Expect 1 pid registration folder got $file_count"
132
133 # Check for buffer and metadata presence in ust/pid/appfolder
134 file_count=$(find $first_pid_path/ -mindepth 1 -maxdepth 1 | wc -l)
135 test $file_count -ne "0"
136 ok $? "Expect > 0 buffer and metadata files got $file_count"
137
138 # Start second application pid
139 diag "Shm: check basic creation of second ust application"
140
141 start_test_app
142 second_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1)
143 ok $? "Pid path exist found $second_pid_path"
144
145 file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l)
146 test $file_count -eq "2"
147 ok $? "Expect 2 pid registration folder got $file_count"
148
149 # Stop first test application and check for cleanup
150 stop_test_app "$first_app_pid"
151 verify_path_dont_exists "$first_pid_path"
152 ok $? "First pid cleanup"
153
154 # Stop all applications and check for full cleanup
155 stop_test_apps
156 verify_path_dont_exists "$shm_session_path"
157 ok $? "Full cleanup"
158
159 # Tear down
160 destroy_lttng_session_ok $session_name
161 stop_lttng_sessiond
162 rm -rf $shm_path
163}
164
165function test_shm_path_per_uid()
166{
167 diag "Shm: ust per-uid test"
168 local session_name=shm_path_per_uid
169 local channel_name=channel_per_uid
170 local shm_path=$(mktemp -d)
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
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
231 $TESTAPP_BIN 10 0
232 stop_lttng_tracing
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
269 $TESTAPP_BIN 10 0
270 stop_lttng_tracing
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
298 start_test_app
299 start_test_app
300 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
301
302 # Stop sessiond with sigint
303 stop_lttng_sessiond SIGINT
304
305 # Looking for a full cleanup
306 verify_path_dont_exists "$shm_session_path"
307 ok $? "Full cleanup on sigint"
308
309 # Tear down
310 stop_test_apps
311 rm -rf $shm_path
312}
313
314function test_shm_path_per_uid_sigint()
315{
316 diag "Shm: ust per-uid test sigint"
317 local session_name=shm_path_per_uid_sigint
318 local channel_name=channel_per_uid_sigint
319 local shm_path=$(mktemp -d)
320 local ret=0
321
322 # Build up
323 start_lttng_sessiond
324 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
325 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
326
327 start_test_app
328 start_test_app
329 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
330
331 # Test full cleanup on SIGINT
332 stop_lttng_sessiond SIGINT
333
334 # Looking for a full cleanup
335 verify_path_dont_exists "$shm_session_path"
336 ok $? "Full cleanup on sigint"
337
338 # Tear down
339 stop_test_apps
340 rm -rf $shm_path
341}
342
343function test_lttng_crash_extraction_sigkill()
344{
345 diag "Lttng-crash: extraction with sigkill"
346 local session_name=crash_test
347 local channel_name=channel_crash
348 local shm_path=$(mktemp -d)
349 local extraction_dir_path=$(mktemp -d)
350 local extraction_path=$extraction_dir_path/extract
351 local event_name="tp:tptest"
352 local ret=0
353
354 start_lttng_sessiond
355 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
356 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
357 enable_ust_lttng_event_ok $session_name $event_name $channel_name
358 start_lttng_tracing_ok $session_name
359
360 # Generate 10 events
361 $TESTAPP_BIN 10 0
362
363 # Kill the consumers then sessiond with sigkill
364 stop_lttng_consumerd SIGKILL
365 stop_lttng_sessiond SIGKILL
366
367 $LTTNG_CRASH -x $extraction_path $shm_path
368 ret=$?
369 ok $ret "Extraction of crashed buffers to path $extraction_path"
370
371 # Test extracted trace
372 trace_match_only $event_name 10 $extraction_path
373
374 # Tear down
375 stop_test_apps
376 rm -rf $shm_path
377 rm -rf $extraction_dir_path
378}
379
3e46b4ca
JG
380function interrupt_cleanup()
381{
382 diag "*** Cleaning-up test ***"
383 stop_test_apps
384 stop_lttng_sessiond
385 exit 1
386}
387
4c80129b
JR
388TESTS=(
389 test_shm_path_per_uid
390 test_shm_path_per_pid
4c80129b
JR
391 test_shm_path_per_pid_sigint
392 test_shm_path_per_uid_sigint
93c4b583
JR
393 test_lttng_crash
394 test_lttng_crash_extraction
4c80129b
JR
395 test_lttng_crash_extraction_sigkill
396)
397
3e46b4ca 398trap interrupt_cleanup SIGTERM SIGINT
4c80129b
JR
399
400for fct_test in ${TESTS[@]};
401do
402 ${fct_test}
403 if [ $? -ne 0 ]; then
404 break;
405 fi
406done
407rm -rf $OUTPUT_DIR
408
409OUTPUT_DEST=/dev/null 2>&1
This page took 0.038928 seconds and 4 git commands to generate.