lttng-crash: support symlink
[lttng-tools.git] / tests / regression / tools / crash / test_crash
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
18 TEST_DESC="LTTng-crash & shm testing"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../../
22 CRASH_BIN="lttng-crash"
23
24 # Test app for ust event
25 TESTAPP_PATH="$TESTDIR/utils/testapp"
26 TESTAPP_NAME="gen-ust-events"
27 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
28 NR_USEC_WAIT=0
29 NR_ITER=-1
30
31 # Temp file output
32 OUTPUT_DIR=$(mktemp -d)
33
34 NUM_TESTS=71
35
36 source $TESTDIR/utils/utils.sh
37
38 # Global declaration for simplification
39 LTTNG_CRASH=$TESTDIR/../src/bin/lttng-crash/$CRASH_BIN
40
41 # MUST set TESTDIR before calling those functions
42 plan_tests $NUM_TESTS
43
44 print_test_banner "$TEST_DESC"
45
46 function 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
65 function 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
77 function 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
87 function verify_path_dont_exists()
88 {
89 local path=$1
90 local timeout_try_limit=100
91 local timeout_try_count=0
92 local timeout_flag=0
93
94 while find $path -mindepth 1 -maxdepth 1 &>/dev/null ; do
95 if [[ $timeout_try_count -gt $timeout_try_limit ]]; then
96 timeout_flag=1
97 break
98 fi
99 timeout_try_count=$((timeout_try_count+1))
100 sleep 0.1
101 done
102 return $timeout_flag
103 }
104
105 function test_shm_path_per_pid()
106 {
107 diag "Shm: ust per-pid test"
108 local session_name=shm_path_per_pid
109 local channel_name=channel_per_pid
110 local shm_path=$(mktemp -d)
111
112 # Build up
113 start_lttng_sessiond
114 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
115 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
116
117 diag "Shm: clean state"
118 file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
119 test $file_count -eq "0"
120 ok $? "No file created on set-up"
121
122 # Look for per-pid folder structure
123 # Start first test app
124 diag "Shm: check folder creation and structure"
125
126 start_test_app
127 first_app_pid=$APPS_PID
128 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
129
130 file_count=$(echo "$shm_session_path"| wc -l)
131 test $file_count -eq "1"
132 ok $? "Path $shm_session_path created on application creation"
133
134 first_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1)
135 ok $? "Pid path exists: $first_pid_path"
136
137 file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l)
138 test $file_count -eq "1"
139 ok $? "Expect 1 pid registration folder got $file_count"
140
141 # Check for buffer and metadata presence in ust/pid/appfolder
142 file_count=$(find $first_pid_path/ -mindepth 1 -maxdepth 1 | wc -l)
143 test $file_count -ne "0"
144 ok $? "Expect > 0 buffer and metadata files got $file_count"
145
146 # Start second application pid
147 diag "Shm: check basic creation of second ust application"
148
149 start_test_app
150 second_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1)
151 ok $? "Pid path exist found $second_pid_path"
152
153 file_count=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1 | wc -l)
154 test $file_count -eq "2"
155 ok $? "Expect 2 pid registration folder got $file_count"
156
157 # Stop first test application and check for cleanup
158 stop_test_app "$first_app_pid"
159 verify_path_dont_exists "$first_pid_path"
160 ok $? "First pid cleanup"
161
162 # Stop all applications and check for full cleanup
163 stop_test_apps
164 verify_path_dont_exists "$shm_session_path"
165 ok $? "Full cleanup"
166
167 # Tear down
168 destroy_lttng_session_ok $session_name
169 stop_lttng_sessiond
170 rm -rf $shm_path
171 }
172
173 function test_shm_path_per_uid()
174 {
175 diag "Shm: ust per-uid test"
176 local session_name=shm_path_per_uid
177 local channel_name=channel_per_uid
178 local shm_path=$(mktemp -d)
179
180 # Build up
181 start_lttng_sessiond
182 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
183 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
184
185 diag "Shm: test clean state"
186 file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
187 test $file_count -eq "0"
188 ok $? "No files created on set-up"
189
190 # Look for per-pid folder structure
191 # Start first test app
192 diag "Shm: check folder creation and structure"
193
194 start_test_app
195 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
196 file_count=$(echo "$shm_session_path"| wc -l)
197 test $file_count -eq "1"
198 ok $? "Path $shm_session_path created on application creation"
199
200 uid_path=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1)
201 ok $? "uid path exist found $uid_path"
202
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 # Stop all applications and check for uid presence
208 stop_test_apps
209 file_count=$(find $shm_session_path/ust/uid -mindepth 1 -maxdepth 1 | wc -l)
210 test $file_count -eq "1"
211 ok $? "Expect 1 uid registration folder got $file_count"
212
213 # Test full cleanup
214 destroy_lttng_session_ok $session_name
215 verify_path_dont_exists "$shm_session_path"
216 ok $? "Full cleanup"
217
218 stop_lttng_sessiond
219 rm -rf $shm_path
220 }
221
222 function test_lttng_crash()
223 {
224 diag "Lttng-crash: basic recuperation"
225 local session_name=crash_test
226 local channel_name=channel_crash
227 local shm_path=$(mktemp -d)
228 local shm_path_symlink=$(mktemp -d)
229 local event_name="tp:tptest"
230
231 # Create a session in snapshot mode to deactivate any use of consumerd
232 start_lttng_sessiond
233 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
234 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
235 enable_ust_lttng_event_ok $session_name $event_name $channel_name
236 start_lttng_tracing_ok $session_name
237
238 # Generate 10 events
239 $TESTAPP_BIN 10 0
240 stop_lttng_tracing
241
242 crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l)
243 test $crash_recup_count -eq "10"
244 ok $? "Expect 10 recup event from buffers got $crash_recup_count"
245
246 # Test with symlink
247 cp -rs $shm_path/. $shm_path_symlink
248 crash_recup_count=$($LTTNG_CRASH $shm_path_symlink | wc -l)
249 test $crash_recup_count -eq "10"
250 ok $? "Expect 10 recup event from symlink buffers got $crash_recup_count"
251
252 # Tear down
253 destroy_lttng_session_ok $session_name
254 stop_lttng_sessiond
255 rm -rf $shm_path
256 rm -rf $shm_path_symlink
257 }
258
259 function test_lttng_crash_extraction()
260 {
261 diag "Lttng-crash: extraction to path"
262 local session_name=crash_test
263 local channel_name=channel_crash
264 local shm_path=$(mktemp -d)
265 local extraction_dir_path=$(mktemp -d)
266 local extraction_path=$extraction_dir_path/extract
267 local event_name="tp:tptest"
268
269 # Create a session in snapshot mode to deactivate any use of consumerd
270 start_lttng_sessiond
271 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
272 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
273 enable_ust_lttng_event_ok $session_name $event_name $channel_name
274
275 start_lttng_tracing_ok $session_name
276 # Generate 10 events
277 $TESTAPP_BIN 10 0
278 stop_lttng_tracing
279
280 $LTTNG_CRASH -x $extraction_path $shm_path
281 ok $? "Extraction of crashed buffers to path"
282
283 # Test extracted trace
284 trace_match_only $event_name 10 $extraction_path
285
286 # Tear down
287 destroy_lttng_session_ok $session_name
288 stop_lttng_sessiond
289 rm -rf $shm_path
290 rm -rf $extraction_dir_path
291 }
292
293 function test_shm_path_per_pid_sigint()
294 {
295 diag "Shm: ust per-pid test sigint"
296 local session_name=shm_path_per_pid
297 local channel_name=channel_per_pid
298 local shm_path=$(mktemp -d)
299 local num_files=0
300
301 # Build up
302 start_lttng_sessiond
303 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
304 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
305
306 start_test_app
307 start_test_app
308 shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
309
310 # Stop sessiond with sigint
311 stop_lttng_sessiond SIGINT
312
313 # Looking for a full cleanup
314 verify_path_dont_exists "$shm_session_path"
315 ok $? "Full cleanup on sigint"
316
317 # Tear down
318 stop_test_apps
319 rm -rf $shm_path
320 }
321
322 function test_shm_path_per_uid_sigint()
323 {
324 diag "Shm: ust per-uid test sigint"
325 local session_name=shm_path_per_uid_sigint
326 local channel_name=channel_per_uid_sigint
327 local shm_path=$(mktemp -d)
328 local ret=0
329
330 # Build up
331 start_lttng_sessiond
332 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
333 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
334
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
351 function 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
369 $TESTAPP_BIN 10 0
370
371 # Kill the consumers then sessiond with sigkill
372 stop_lttng_consumerd SIGKILL
373 stop_lttng_sessiond SIGKILL
374
375 $LTTNG_CRASH -x $extraction_path $shm_path
376 ret=$?
377 ok $ret "Extraction of crashed buffers to path $extraction_path"
378
379 # Test extracted trace
380 trace_match_only $event_name 10 $extraction_path
381
382 # Tear down
383 stop_test_apps
384 rm -rf $shm_path
385 rm -rf $extraction_dir_path
386 }
387
388 TESTS=(
389 test_shm_path_per_uid
390 test_shm_path_per_pid
391 test_shm_path_per_pid_sigint
392 test_shm_path_per_uid_sigint
393 test_lttng_crash
394 test_lttng_crash_extraction
395 test_lttng_crash_extraction_sigkill
396 )
397
398
399 for fct_test in ${TESTS[@]};
400 do
401 ${fct_test}
402 if [ $? -ne 0 ]; then
403 break;
404 fi
405 done
406 rm -rf $OUTPUT_DIR
407
408 OUTPUT_DEST=/dev/null 2>&1
This page took 0.061913 seconds and 5 git commands to generate.