Test: lttng-crash and ust shm path
[lttng-tools.git] / tests / regression / tools / crash / test_crash
... / ...
CommitLineData
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
34NUM_TESTS=70
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
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
105function 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
173function 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
222function 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 event_name="tp:tptest"
229
230 # Create a session in snapshot mode to deactivate any use of consumerd
231 start_lttng_sessiond
232 create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path --snapshot"
233 enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
234 enable_ust_lttng_event_ok $session_name $event_name $channel_name
235 start_lttng_tracing_ok $session_name
236
237 # Generate 10 events
238 $TESTAPP_BIN 10 0
239 stop_lttng_tracing
240
241 crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l)
242 test $crash_recup_count -eq "10"
243 ok $? "Expect 10 recup event from buffers got $crash_recup_count"
244
245 # Tear down
246 destroy_lttng_session_ok $session_name
247 stop_lttng_sessiond
248 rm -rf $shm_path
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
380TESTS=(
381 test_shm_path_per_uid
382 test_shm_path_per_pid
383 test_lttng_crash
384 test_lttng_crash_extraction
385 test_shm_path_per_pid_sigint
386 test_shm_path_per_uid_sigint
387 test_lttng_crash_extraction_sigkill
388)
389
390
391for fct_test in ${TESTS[@]};
392do
393 ${fct_test}
394 if [ $? -ne 0 ]; then
395 break;
396 fi
397done
398rm -rf $OUTPUT_DIR
399
400OUTPUT_DEST=/dev/null 2>&1
This page took 0.023749 seconds and 4 git commands to generate.