Fix: Tests: race condition in test_ns_contexts_change
[lttng-tools.git] / tests / regression / ust / namespaces / test_ns_contexts_change
index 18a22e588567c0965143de2bbcc9ef0cd07ad720..8a4b62ce3a4ff2a04542ae062ee2686b325ce632 100755 (executable)
@@ -2,18 +2,7 @@
 #
 # Copyright (C) 2019 Michael Jeanson <mjeanson@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.
-#
-# 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
+# SPDX-License-Identifier: LGPL-2.1-only
 
 TEST_DESC="UST - Namespace contexts change"
 
@@ -57,9 +46,9 @@ function test_ns()
        ns_inode=$(stat -c '%i' -L "/proc/$$/ns/$ns")
        ok $? "Get current $ns namespace inode: $ns_inode" || ns_inode="invalid"
 
-       trace_path=$(mktemp -d)
-       file_sync_before_last=$(mktemp -u)
-       file_sync_after_unshare=$(mktemp -u)
+       trace_path=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
+       file_sync_before_last=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
+       file_sync_after_unshare=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_unshare.XXXXXX")
 
        start_lttng_sessiond
 
@@ -72,12 +61,10 @@ function test_ns()
        $TESTAPP_BIN -n "$ns" -i $NUM_EVENT -a "$file_sync_after_unshare" -b "$file_sync_before_last" &
        app_pid=$!
 
-       # Let the app do it's thing before entering the synchronisation loop
-       sleep 0.5
-
        while [ ! -f "$file_sync_after_unshare" ]; do
                # Break if the app failed / died
-               if [ ! -f "/proc/$app_pid" ]; then
+               if ! kill -0 "$app_pid" ; then
+                       echo "# App failed"
                        break
                fi
                echo "# Waiting for app..."
@@ -92,6 +79,9 @@ function test_ns()
 
        touch "$file_sync_before_last"
 
+       # Wait for the test app to generate all expected events and exit.
+       wait $app_pid
+
        # stop and destroy
        stop_lttng_tracing_ok "$session_name"
        destroy_lttng_session_ok "$session_name"
@@ -131,5 +121,6 @@ test_ns ipc
 test_ns mnt
 test_ns net
 #test_ns pid # pid_ns is special, can't be changed that way
+#test_ns time # time_ns is special, can't be changed that way
 #test_ns user # user_ns can only be change when the app is single threaded, this is always false for an ust instrumented app
 test_ns uts
This page took 0.024059 seconds and 4 git commands to generate.