[lttng-dev] [PATCH lttng-tools] Fix: use tmpdir for intermediate sync files

Jonathan Rajotte jonathan.rajotte-julien at efficios.com
Thu Oct 12 15:19:58 UTC 2017


Perform cleanup when necessary.

Use rm -f to prevent interactive mode when files or folders to be deleted
have permission issues (e.g root owned but running test under user).

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 .../tools/notification/test_notification_multi_app | 111 +++++++++++----------
 1 file changed, 56 insertions(+), 55 deletions(-)

diff --git a/tests/regression/tools/notification/test_notification_multi_app b/tests/regression/tools/notification/test_notification_multi_app
index d7f6319f..53d51685 100755
--- a/tests/regression/tools/notification/test_notification_multi_app
+++ b/tests/regression/tools/notification/test_notification_multi_app
@@ -40,7 +40,7 @@ DIR=$(readlink -f $TESTDIR)
 
 PAGE_SIZE=$(getconf PAGE_SIZE)
 
-NUM_TESTS=62
+NUM_TESTS=60
 
 source $TESTDIR/utils/utils.sh
 
@@ -73,10 +73,11 @@ function start_client {
 
 function wait_for_message ()
 {
-	local file_pattern=$1
-	local message=$2
+	local tmpdir=$1
+	local file_pattern=$2
+	local message=$3
 
-	for file in $CURDIR/${file_pattern}*; do
+	for file in ${tmpdir}/${file_pattern}*; do
 		while(true); do
 			# Check for "error" message
 			grep -q "error:" ${file}
@@ -103,9 +104,10 @@ function wait_for_message ()
 
 function print_errors ()
 {
-	local file_pattern=$1
+	local tmpdir=$1
+	local file_pattern=$2
 
-	for file in $CURDIR/${file_pattern}*; do
+	for file in ${tmpdir}/${file_pattern}*; do
 		# Check for "error" message
 		error_message=$(grep "error:" ${file})
 		if [[ "${error_message}x" != "x" ]]; then
@@ -143,15 +145,13 @@ function test_multi_app ()
 	local low_output_file_pattern="low_app_output_file_"
 	local high_output_file_pattern="high_app_output_file_"
 
-	local testpoint_base_path=$(readlink -f "$CURDIR/lttng.t_p_n_multi_app")
+	local tmpdir=$(mktemp -d)
+	local testpoint_base_path=$(readlink -f "$tmpdir/lttng.t_p_n_multi_app")
 	local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX")
 
 	local nr_notification_expected=5
 	local nr_client_app=50
-
-	# Cleanup
-	rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null
-	rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null
+	local consumerd_pipe=()
 
 	# Setup
 	LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
@@ -175,19 +175,19 @@ function test_multi_app ()
 
 	# Fetch consumerd testpoint pipe information
 	# This is needed since the testpoint create a pipe with the consumer type suffixed
-	for f in "$testpoint_base_path"*; do
+	for f in "$testpoint_pipe_path"*; do
 		consumerd_pipe+=("$f")
 	done
 
 	for (( i = 0; i < $nr_client_app; i++ )); do
-		low_app_output_file=$CURDIR/${low_output_file_pattern}${i}
-		high_app_output_file=$CURDIR/${high_output_file_pattern}${i}
+		low_app_output_file=${tmpdir}/${low_output_file_pattern}${i}
+		high_app_output_file=${tmpdir}/${high_output_file_pattern}${i}
 		start_client $low_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST LOW RATIO 0.0 $nr_notification_expected
 		start_client $high_app_output_file $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO 0.420 $nr_notification_expected
 	done
 
-	wait_for_message "${low_output_file_pattern}" "sync: ready"
-	wait_for_message "${high_output_file_pattern}" "sync: ready"
+	wait_for_message "${tmpdir}" "${low_output_file_pattern}" "sync: ready"
+	wait_for_message "${tmpdir}" "${high_output_file_pattern}" "sync: ready"
 
 	# Test notification reception
 	for (( i = 0; i < $nr_notification_expected; i++ )); do
@@ -198,7 +198,7 @@ function test_multi_app ()
 			stop_consumerd "${pipe}"
 		done
 
-		wait_for_message "${high_output_file_pattern}" "notification: high $i"
+		wait_for_message "${tmpdir}" "${high_output_file_pattern}" "notification: high $i"
 
 		# Resume consumerd
 		for pipe in "${consumerd_pipe[@]}"; do
@@ -208,7 +208,7 @@ function test_multi_app ()
 		stop_lttng_tracing $SESSION_NAME
 
 		# Check for notifications reception
-		wait_for_message "${low_output_file_pattern}" "notification: low $i"
+		wait_for_message "${tmpdir}" "${low_output_file_pattern}" "notification: low $i"
 		ret=$?
 		ok $ret "Notifications $i received"
 		if [[ $ret -ne "0" ]]; then
@@ -217,30 +217,34 @@ function test_multi_app ()
 		fi
 	done
 
-	wait_for_message "${low_output_file_pattern}" "exit: 0"
-	ret=$?
-	ok $ret "Application for low notification terminated normally"
-	if [[ $ret -eq "0" ]]; then
-		rm ${CURDIR}/${low_output_file_pattern}* 2> /dev/null
+	wait_for_message "${tmpdir}" "${low_output_file_pattern}" "exit: 0"
+	ret_low=$?
+	ok $ret_low "Application for low notification terminated normally"
+	if [[ $ret_low -eq "0" ]]; then
+		rm -rf ${tmpdir}/${low_output_file_pattern}* 2> /dev/null
 	else
 		# Keep the file
-		print_errors "${low_output_file_pattern}"
+		print_errors "${tmpdir}" "${low_output_file_pattern}"
 	fi
 
-	wait_for_message "${high_output_file_pattern}" "exit: 0"
-	ret=$?
-	ok $ret "Application for high notification terminated normally"
-	if [[ $ret -eq "0" ]]; then
-		rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null
+	wait_for_message "${tmpdir}" "${high_output_file_pattern}" "exit: 0"
+	ret_high=$?
+	ok $ret_high "Application for high notification terminated normally"
+	if [[ $ret_high -eq "0" ]]; then
+		rm -rf ${tmpdir}/${high_output_file_pattern}* 2> /dev/null
 	else
 		# Keep the file
-		print_errors "${high_output_file_pattern}"
+		print_errors "${tmpdir}" "${high_output_file_pattern}"
 	fi
 
+	stop_lttng_sessiond
 	kill -9 $app_pid
 	wait $app_pid 2> /dev/null
 
-	stop_lttng_sessiond
+	if [[ $ret_low -eq "0" && $ret_high -eq "0" ]]; then
+		rm -rf ${tmpdir}
+	fi
+	return 0
 }
 
 function test_on_register_evaluation ()
@@ -248,11 +252,10 @@ function test_on_register_evaluation ()
 	local app_pids=()
 	local high_output_file_pattern="high_app_output_file_on_register_evaluation"
 
-	local testpoint_base_path=$(readlink -f "$CURDIR/lttng.t_p_n_register_evaluation")
+	local tmpdir=$(mktemp -d)
+	local testpoint_base_path=$(readlink -f "${tmpdir}/lttng.t_p_n_register_evaluation")
 	local testpoint_pipe_path=$(mktemp -u "${testpoint_base_path}.XXXXXX")
-
-	# Cleanup
-	rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null
+	local consumerd_pipe=()
 
 	# Setup
 	LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
@@ -276,15 +279,15 @@ function test_on_register_evaluation ()
 
 	# Fetch consumerd testpoint pipe information
 	# This is needed since the testpoint create a pipe with the consumer type suffixed
-	for f in "$testpoint_base_path"*; do
+	for f in "$testpoint_pipe_path"*; do
 		consumerd_pipe+=("$f")
 	done
 
 	high_app_output_file=${high_output_file_pattern}.first_receiver
-	high_app_output_path=$CURDIR/${high_app_output_file}
+	high_app_output_path=${tmpdir}/${high_app_output_file}
 	start_client $high_app_output_path $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO 0.420 1
 
-	wait_for_message "${high_app_output_file}" "sync: ready"
+	wait_for_message "${tmpdir}" "${high_app_output_file}" "sync: ready"
 
 	# Stop consumerd consumption to force high notification
 	start_lttng_tracing_ok $SESSION_NAME
@@ -293,35 +296,36 @@ function test_on_register_evaluation ()
 		stop_consumerd "${pipe}"
 	done
 
-	wait_for_message "${high_app_output_file}" "notification: high 0"
+	wait_for_message "${tmpdir}" "${high_app_output_file}" "notification: high 0"
 
 	# Start a second receiver, the receiver should receive a high
 	# notification on subscription
 	high_app_output_file=${high_output_file_pattern}.second_receiver
-	high_app_output_path=$CURDIR/${high_app_output_file}
+	high_app_output_path=${tmpdir}/${high_app_output_file}
 	start_client $high_app_output_path $SESSION_NAME $UST_CHANNEL_NAME LTTNG_DOMAIN_UST HIGH RATIO 0.420 1
-	wait_for_message "${high_app_output_file}" "sync: ready"
-	wait_for_message "${high_app_output_file}" "notification: high 0"
+	wait_for_message "${tmpdir}" "${high_app_output_file}" "sync: ready"
+	wait_for_message "${tmpdir}" "${high_app_output_file}" "notification: high 0"
 
 	# Resume consumerd
 	for pipe in "${consumerd_pipe[@]}"; do
 		resume_consumerd "${pipe}"
 	done
 
-	wait_for_message "${high_output_file_pattern}" "exit: 0"
-	ret=$?
-	ok $ret "Application for high notification terminated normally"
-	if [[ $ret -eq "0" ]]; then
-		rm ${CURDIR}/${high_output_file_pattern}* 2> /dev/null
-	else
-		# Keep the file
-		print_errors "${high_output_file_pattern}"
-	fi
+	wait_for_message "${tmpdir}" "${high_output_file_pattern}" "exit: 0"
+	ret_high=$?
+	ok $ret_high "Application for high notification terminated normally"
 
 	stop_lttng_sessiond
-
 	kill -9 $app_pid
 	wait $app_pid 2> /dev/null
+
+	if [[ $ret_high -eq "0" ]]; then
+		rm -rf ${tmpdir} 2> /dev/null
+	else
+		# Keep the file
+		print_errors "${tmpdir}" "${high_output_file_pattern}"
+	fi
+	return 0
 }
 
 
@@ -335,9 +339,6 @@ do
 	TRACE_PATH=$(mktemp -d)
 
 	${fct_test}
-	if [ $? -ne 0 ]; then
-		break;
-	fi
 
 	# Only delete if successful
 	rm -rf $TRACE_PATH
-- 
2.11.0



More information about the lttng-dev mailing list