Gen-ust-events: use options instead of arguments
[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
c02a94c4 34NUM_TESTS=77
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.
a4c30524 51 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
4c80129b
JR
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
c02a94c4
MD
109 start_lttng_tracing_ok $session_name
110
4c80129b
JR
111 diag "Shm: clean state"
112 file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
113 test $file_count -eq "0"
114 ok $? "No file created on set-up"
115
116 # Look for per-pid folder structure
117 # Start first test app
118 diag "Shm: check folder creation and structure"
119
120 start_test_app
121 first_app_pid=$APPS_PID
122 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
123
124 file_count=$(echo "$shm_session_path"| wc -l)
125 test $file_count -eq "1"
126 ok $? "Path $shm_session_path created on application creation"
127
128 first_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1)
129 ok $? "Pid path exists: $first_pid_path"
130
131 file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l)
132 test $file_count -eq "1"
133 ok $? "Expect 1 pid registration folder got $file_count"
134
135 # Check for buffer and metadata presence in ust/pid/appfolder
136 file_count=$(find $first_pid_path/ -mindepth 1 -maxdepth 1 | wc -l)
137 test $file_count -ne "0"
138 ok $? "Expect > 0 buffer and metadata files got $file_count"
139
140 # Start second application pid
141 diag "Shm: check basic creation of second ust application"
142
143 start_test_app
144 second_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1)
145 ok $? "Pid path exist found $second_pid_path"
146
147 file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l)
148 test $file_count -eq "2"
149 ok $? "Expect 2 pid registration folder got $file_count"
150
151 # Stop first test application and check for cleanup
152 stop_test_app "$first_app_pid"
153 verify_path_dont_exists "$first_pid_path"
154 ok $? "First pid cleanup"
155
156 # Stop all applications and check for full cleanup
157 stop_test_apps
158 verify_path_dont_exists "$shm_session_path"
159 ok $? "Full cleanup"
160
161 # Tear down
162 destroy_lttng_session_ok $session_name
163 stop_lttng_sessiond
164 rm -rf $shm_path
165}
166
167function test_shm_path_per_uid()
168{
169 diag "Shm: ust per-uid test"
170 local session_name=shm_path_per_uid
171 local channel_name=channel_per_uid
172 local shm_path=$(mktemp -d)
173
174 # Build up
175 start_lttng_sessiond
176 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
177 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
178
c02a94c4
MD
179 start_lttng_tracing_ok $session_name
180
4c80129b
JR
181 diag "Shm: test clean state"
182 file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
183 test $file_count -eq "0"
184 ok $? "No files created on set-up"
185
186 # Look for per-pid folder structure
187 # Start first test app
188 diag "Shm: check folder creation and structure"
189
190 start_test_app
191 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
192 file_count=$(echo "$shm_session_path"| wc -l)
193 test $file_count -eq "1"
194 ok $? "Path $shm_session_path created on application creation"
195
196 uid_path=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1)
197 ok $? "uid path exist found $uid_path"
198
199 file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l)
200 test $file_count -eq "1"
201 ok $? "Expect 1 uid registration folder got $file_count"
202
203 # Stop all applications and check for uid presence
204 stop_test_apps
205 file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l)
206 test $file_count -eq "1"
207 ok $? "Expect 1 uid registration folder got $file_count"
208
209 # Test full cleanup
210 destroy_lttng_session_ok $session_name
211 verify_path_dont_exists "$shm_session_path"
212 ok $? "Full cleanup"
213
214 stop_lttng_sessiond
215 rm -rf $shm_path
216}
217
218function test_lttng_crash()
219{
220 diag "Lttng-crash: basic recuperation"
221 local session_name=crash_test
222 local channel_name=channel_crash
223 local shm_path=$(mktemp -d)
93c4b583 224 local shm_path_symlink=$(mktemp -d)
4c80129b
JR
225 local event_name="tp:tptest"
226
227 # Create a session in snapshot mode to deactivate any use of consumerd
228 start_lttng_sessiond
229 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
230 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
231 enable_ust_lttng_event_ok $session_name $event_name $channel_name
232 start_lttng_tracing_ok $session_name
233
234 # Generate 10 events
a4c30524 235 $TESTAPP_BIN -i 10 -w 0
7fe98a98 236 stop_lttng_tracing_ok
4c80129b
JR
237
238 crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l)
239 test $crash_recup_count -eq "10"
240 ok $? "Expect 10 recup event from buffers got $crash_recup_count"
241
93c4b583
JR
242 # Test with symlink
243 cp -rs $shm_path/. $shm_path_symlink
244 crash_recup_count=$($LTTNG_CRASH $shm_path_symlink | wc -l)
245 test $crash_recup_count -eq "10"
246 ok $? "Expect 10 recup event from symlink buffers got $crash_recup_count"
247
4c80129b
JR
248 # Tear down
249 destroy_lttng_session_ok $session_name
250 stop_lttng_sessiond
251 rm -rf $shm_path
93c4b583 252 rm -rf $shm_path_symlink
4c80129b
JR
253}
254
255function test_lttng_crash_extraction()
256{
257 diag "Lttng-crash: extraction to path"
258 local session_name=crash_test
259 local channel_name=channel_crash
260 local shm_path=$(mktemp -d)
261 local extraction_dir_path=$(mktemp -d)
262 local extraction_path=$extraction_dir_path/extract
263 local event_name="tp:tptest"
264
265 # Create a session in snapshot mode to deactivate any use of consumerd
266 start_lttng_sessiond
267 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
268 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
269 enable_ust_lttng_event_ok $session_name $event_name $channel_name
270
271 start_lttng_tracing_ok $session_name
272 # Generate 10 events
a4c30524 273 $TESTAPP_BIN -i 10 -w 0
7fe98a98 274 stop_lttng_tracing_ok
4c80129b
JR
275
276 $LTTNG_CRASH -x $extraction_path $shm_path
277 ok $? "Extraction of crashed buffers to path"
278
279 # Test extracted trace
280 trace_match_only $event_name 10 $extraction_path
281
282 # Tear down
283 destroy_lttng_session_ok $session_name
284 stop_lttng_sessiond
285 rm -rf $shm_path
286 rm -rf $extraction_dir_path
287}
288
289function test_shm_path_per_pid_sigint()
290{
291 diag "Shm: ust per-pid test sigint"
292 local session_name=shm_path_per_pid
293 local channel_name=channel_per_pid
294 local shm_path=$(mktemp -d)
295 local num_files=0
296
297 # Build up
298 start_lttng_sessiond
299 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
300 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
301
c02a94c4
MD
302 start_lttng_tracing_ok $session_name
303
4c80129b
JR
304 start_test_app
305 start_test_app
306 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
307
308 # Stop sessiond with sigint
309 stop_lttng_sessiond SIGINT
310
311 # Looking for a full cleanup
312 verify_path_dont_exists "$shm_session_path"
313 ok $? "Full cleanup on sigint"
314
315 # Tear down
316 stop_test_apps
317 rm -rf $shm_path
318}
319
320function test_shm_path_per_uid_sigint()
321{
322 diag "Shm: ust per-uid test sigint"
323 local session_name=shm_path_per_uid_sigint
324 local channel_name=channel_per_uid_sigint
325 local shm_path=$(mktemp -d)
326 local ret=0
327
328 # Build up
329 start_lttng_sessiond
330 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
331 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
332
c02a94c4
MD
333 start_lttng_tracing_ok $session_name
334
4c80129b
JR
335 start_test_app
336 start_test_app
337 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
338
339 # Test full cleanup on SIGINT
340 stop_lttng_sessiond SIGINT
341
342 # Looking for a full cleanup
343 verify_path_dont_exists "$shm_session_path"
344 ok $? "Full cleanup on sigint"
345
346 # Tear down
347 stop_test_apps
348 rm -rf $shm_path
349}
350
351function test_lttng_crash_extraction_sigkill()
352{
353 diag "Lttng-crash: extraction with sigkill"
354 local session_name=crash_test
355 local channel_name=channel_crash
356 local shm_path=$(mktemp -d)
357 local extraction_dir_path=$(mktemp -d)
358 local extraction_path=$extraction_dir_path/extract
359 local event_name="tp:tptest"
360 local ret=0
361
362 start_lttng_sessiond
363 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
364 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
365 enable_ust_lttng_event_ok $session_name $event_name $channel_name
366 start_lttng_tracing_ok $session_name
367
368 # Generate 10 events
a4c30524 369 $TESTAPP_BIN -i 10 -w 0
4c80129b 370
8490897a
MD
371 sigstop_lttng_sessiond
372 sigstop_lttng_consumerd
373
4c80129b
JR
374 # Kill the consumers then sessiond with sigkill
375 stop_lttng_consumerd SIGKILL
376 stop_lttng_sessiond SIGKILL
377
378 $LTTNG_CRASH -x $extraction_path $shm_path
379 ret=$?
380 ok $ret "Extraction of crashed buffers to path $extraction_path"
381
382 # Test extracted trace
383 trace_match_only $event_name 10 $extraction_path
384
385 # Tear down
386 stop_test_apps
387 rm -rf $shm_path
388 rm -rf $extraction_dir_path
389}
390
3e46b4ca
JG
391function interrupt_cleanup()
392{
393 diag "*** Cleaning-up test ***"
394 stop_test_apps
395 stop_lttng_sessiond
396 exit 1
397}
398
4c80129b
JR
399TESTS=(
400 test_shm_path_per_uid
401 test_shm_path_per_pid
4c80129b
JR
402 test_shm_path_per_pid_sigint
403 test_shm_path_per_uid_sigint
93c4b583
JR
404 test_lttng_crash
405 test_lttng_crash_extraction
4c80129b
JR
406 test_lttng_crash_extraction_sigkill
407)
408
3e46b4ca 409trap interrupt_cleanup SIGTERM SIGINT
4c80129b
JR
410
411for fct_test in ${TESTS[@]};
412do
413 ${fct_test}
414 if [ $? -ne 0 ]; then
415 break;
416 fi
417done
418rm -rf $OUTPUT_DIR
419
420OUTPUT_DEST=/dev/null 2>&1
This page took 0.08351 seconds and 5 git commands to generate.