Cleanup: tests: name all temporary files to better identify leakage
[lttng-tools.git] / tests / regression / tools / crash / test_crash
index 3bf459dc2cb097ce8f5708c4a010a86ae5c14638..73e1e4f694816762aaad5a7f52dd7ab6c42bc774 100755 (executable)
@@ -1,19 +1,9 @@
 #!/bin/bash
 #
-# Copyright (C) 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+# Copyright (C) 2015 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
 #
-# This library is free software; you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation; version 2.1 of the License.
+# SPDX-License-Identifier: LGPL-2.1-only
 #
-# This library is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this library; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
 TEST_DESC="LTTng-crash & shm testing"
 
@@ -29,9 +19,11 @@ NR_USEC_WAIT=0
 NR_ITER=-1
 
 # Temp file output
-OUTPUT_DIR=$(mktemp -d)
+OUTPUT_DIR=$(mktemp -d --tmpdir tmp.test_crash_shm.XXXXXX)
+
+LAST_APP_PID=
 
-NUM_TESTS=73
+NUM_TESTS=77
 
 source $TESTDIR/utils/utils.sh
 
@@ -45,11 +37,12 @@ print_test_banner "$TEST_DESC"
 
 function start_test_app()
 {
-       local tmp_file=$(mktemp -u)
+       local tmp_file=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}.XXXXXX")
 
        # Start application with a temporary file.
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
+       $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
        ret=$?
+       LAST_APP_PID="${!}"
        APPS_PID="${APPS_PID} ${!}"
        ok $ret "Start application to trace"
 
@@ -81,6 +74,7 @@ function stop_test_app()
                diag "Stopping $p"
                kill ${p} 2>/dev/null
                wait ${p} 2>/dev/null
+               diag "Stopped $p"
        done
 }
 
@@ -99,13 +93,15 @@ function test_shm_path_per_pid()
        diag "Shm: ust per-pid test"
        local session_name=shm_path_per_pid
        local channel_name=channel_per_pid
-       local shm_path=$(mktemp -d)
+       local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm.XXXXXX")
 
        # Build up
        start_lttng_sessiond
        create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
        enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
 
+       start_lttng_tracing_ok $session_name
+
        diag "Shm: clean state"
        file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
        test $file_count -eq "0"
@@ -116,7 +112,7 @@ function test_shm_path_per_pid()
        diag "Shm: check folder creation and structure"
 
        start_test_app
-       first_app_pid=$APPS_PID
+       first_app_pid=$LAST_APP_PID
        shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
 
        file_count=$(echo "$shm_session_path"| wc -l)
@@ -139,6 +135,7 @@ function test_shm_path_per_pid()
        diag "Shm: check basic creation of second ust application"
 
        start_test_app
+       second_app_pid=$LAST_APP_PID
        second_pid_path=$(find $shm_session_path/ust/pid -mindepth 1 -maxdepth 1)
        ok $? "Pid path exist found $second_pid_path"
 
@@ -148,6 +145,7 @@ function test_shm_path_per_pid()
 
        # Stop first test application and check for cleanup
        stop_test_app "$first_app_pid"
+       APPS_PID="$second_app_pid"
        verify_path_dont_exists "$first_pid_path"
        ok $? "First pid cleanup"
 
@@ -167,13 +165,17 @@ function test_shm_path_per_uid()
        diag "Shm: ust per-uid test"
        local session_name=shm_path_per_uid
        local channel_name=channel_per_uid
-       local shm_path=$(mktemp -d)
+       set -x
+       local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
+       set +x
 
        # Build up
        start_lttng_sessiond
        create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
        enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
 
+       start_lttng_tracing_ok $session_name
+
        diag "Shm: test clean state"
        file_count=$(find $shm_path -mindepth 1 -maxdepth 1 | wc -l)
        test $file_count -eq "0"
@@ -216,8 +218,8 @@ function test_lttng_crash()
        diag "Lttng-crash: basic recuperation"
        local session_name=crash_test
        local channel_name=channel_crash
-       local shm_path=$(mktemp -d)
-       local shm_path_symlink=$(mktemp -d)
+       local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
+       local shm_path_symlink=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path_symlink.XXXXXX")
        local event_name="tp:tptest"
 
        # Create a session in snapshot mode to deactivate any use of consumerd
@@ -228,7 +230,7 @@ function test_lttng_crash()
        start_lttng_tracing_ok $session_name
 
        # Generate 10 events
-       $TESTAPP_BIN 10 0
+       $TESTAPP_BIN -i 10 -w 0
        stop_lttng_tracing_ok
 
        crash_recup_count=$($LTTNG_CRASH $shm_path | wc -l)
@@ -253,8 +255,8 @@ function test_lttng_crash_extraction()
        diag "Lttng-crash: extraction to path"
        local session_name=crash_test
        local channel_name=channel_crash
-       local shm_path=$(mktemp -d)
-       local extraction_dir_path=$(mktemp -d)
+       local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
+       local extraction_dir_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_extraction_dir_path.XXXXXX")
        local extraction_path=$extraction_dir_path/extract
        local event_name="tp:tptest"
 
@@ -266,7 +268,7 @@ function test_lttng_crash_extraction()
 
        start_lttng_tracing_ok $session_name
        # Generate 10 events
-       $TESTAPP_BIN 10 0
+       $TESTAPP_BIN -i 10 -w 0
        stop_lttng_tracing_ok
 
        $LTTNG_CRASH -x $extraction_path $shm_path
@@ -287,7 +289,7 @@ function test_shm_path_per_pid_sigint()
        diag "Shm: ust per-pid test sigint"
        local session_name=shm_path_per_pid
        local channel_name=channel_per_pid
-       local shm_path=$(mktemp -d)
+       local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
        local num_files=0
 
        # Build up
@@ -295,6 +297,8 @@ function test_shm_path_per_pid_sigint()
        create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
        enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-pid"
 
+       start_lttng_tracing_ok $session_name
+
        start_test_app
        start_test_app
        shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
@@ -316,7 +320,7 @@ function test_shm_path_per_uid_sigint()
        diag "Shm: ust per-uid test sigint"
        local session_name=shm_path_per_uid_sigint
        local channel_name=channel_per_uid_sigint
-       local shm_path=$(mktemp -d)
+       local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
        local ret=0
 
        # Build up
@@ -324,6 +328,8 @@ function test_shm_path_per_uid_sigint()
        create_lttng_session_ok $session_name $OUTPUT_DIR "--shm-path $shm_path"
        enable_ust_lttng_channel_ok $session_name $channel_name "--buffers-uid"
 
+       start_lttng_tracing_ok $session_name
+
        start_test_app
        start_test_app
        shm_session_path=$(find $shm_path -mindepth 1 -maxdepth 1)
@@ -345,8 +351,8 @@ function test_lttng_crash_extraction_sigkill()
        diag "Lttng-crash: extraction with sigkill"
        local session_name=crash_test
        local channel_name=channel_crash
-       local shm_path=$(mktemp -d)
-       local extraction_dir_path=$(mktemp -d)
+       local shm_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_shm_path.XXXXXX")
+       local extraction_dir_path=$(mktemp -d --tmpdir "tmp.${FUNCNAME[0]}_extraction_dir_path.XXXXXX")
        local extraction_path=$extraction_dir_path/extract
        local event_name="tp:tptest"
        local ret=0
@@ -358,7 +364,7 @@ function test_lttng_crash_extraction_sigkill()
        start_lttng_tracing_ok $session_name
 
        # Generate 10 events
-       $TESTAPP_BIN 10 0
+       $TESTAPP_BIN -i 10 -w 0
 
        sigstop_lttng_sessiond
        sigstop_lttng_consumerd
@@ -384,13 +390,12 @@ function interrupt_cleanup()
 {
     diag "*** Cleaning-up test ***"
     stop_test_apps
-    stop_lttng_sessiond
-    exit 1
+    full_cleanup
 }
 
 TESTS=(
-       test_shm_path_per_uid
        test_shm_path_per_pid
+       test_shm_path_per_uid
        test_shm_path_per_pid_sigint
        test_shm_path_per_uid_sigint
        test_lttng_crash
This page took 0.02591 seconds and 4 git commands to generate.