Tests: use "kill -0" for app existence check in NS tests
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 15 Oct 2019 20:50:46 +0000 (16:50 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 23 Oct 2019 22:47:09 +0000 (18:47 -0400)
Removing the sleep 0.5 we hit a race where the "-f /proc/$pid_app"
test returns false immediately. Using "kill -0" protects us against
such races. From kill (2):

If sig is 0, then no signal is sent, but existence and permission
checks are still performed; this can be used to check for the
existence of a process ID or process group ID that the caller is
permitted to signal.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/kernel/test_ns_contexts_change
tests/regression/ust/namespaces/test_ns_contexts_change

index 905f6cf2bb01bd1efe349534493fe004ed6386d9..08150244d3111d19bcc5e12e1489e558a88cf190 100755 (executable)
@@ -119,13 +119,11 @@ function test_ns()
 
                touch "$file_sync_wait_before_unshare"
 
-               # Let the app do it's thing before entering the synchronisation loop
-               sleep 0.5
-
                while [ ! -f "$file_sync_signal_after_unshare" ]; do
                        # Break if the app failed / died
-                       if [ ! -f "/proc/$app_pid" ]; then
+                       if ! kill -0 "$app_pid" ; then
                                break
+                               echo "# App failed"
                        fi
                        echo "# Waiting for app..."
                        sleep 0.5
index 18a22e588567c0965143de2bbcc9ef0cd07ad720..0e03d53932dbd3aaaacbf7fcbcd60beeb6e907af 100755 (executable)
@@ -72,12 +72,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..."
This page took 0.027481 seconds and 5 git commands to generate.