Fix: Racy event validation in tests
authorChristian Babeux <christian.babeux@efficios.com>
Fri, 18 Apr 2014 17:10:09 +0000 (13:10 -0400)
committerDavid Goulet <dgoulet@efficios.com>
Wed, 30 Apr 2014 16:44:53 +0000 (12:44 -0400)
This pattern is fundamentally racy:

$TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 &

[...]

while [ -n "$(pidof $TESTAPP_BIN)" ]; do
   sleep 1
done
pass "Wait for application end"

[...]

tracing_teardown

validate_trace $EXACT_EVENT_COUNT

It is possible that the check for "pidof $TESTAPP_BIN" occurs _before_
the execve() of the applications (starting the applications in background
with & is basically a clone() + execve()). The consequence is that the check
succeed, never waiting for any applications to finish and then the tracing
sessions are prematurely teared down. Thus the resulting trace contains only
some events. We then validate for a fixed number of events and thus the test
fails caused by this racy scheduling situation.

The fix is to start the applications in foreground instead of background.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: David Goulet <dgoulet@efficios.com>
tests/regression/tools/exclusion/test_exclusion
tests/regression/tools/filtering/test_valid_filter
tests/regression/tools/tracefile-limits/test_tracefile_count
tests/regression/tools/tracefile-limits/test_tracefile_size
tests/regression/ust/buffers-pid/test_buffers_pid

index d093e1e1fe24b41d2b653b0e89c3854a148220a8..c1d76700ac61f9bc12091983f4b1adc1b33efa01 100755 (executable)
@@ -28,7 +28,7 @@ TESTAPP_NAME="gen-ust-nevents"
 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 NR_ITER=100
 NR_USEC_WAIT=1
-NUM_TESTS=9
+NUM_TESTS=8
 
 source $TESTDIR/utils/utils.sh
 
@@ -44,15 +44,7 @@ function enable_ust_lttng_all_event_exclusion()
 
 function run_apps
 {
-        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 &
-}
-
-function wait_apps
-{
-       while [ -n "$(pidof $BIN_NAME)" ]; do
-               sleep 1
-       done
-       pass "Wait for application end"
+        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1
 }
 
 function test_exclusion
@@ -67,7 +59,6 @@ function test_exclusion
        # Trace apps
        start_lttng_tracing $SESSION_NAME
        run_apps
-       wait_apps
        stop_lttng_tracing $SESSION_NAME
 
        # Destroy session
index a62cc1ef289447c5c9d7635a4173fb0b8b2b13b8..4d8d2afff5c1d7b1ab69b9089e8c3b5b81324dd5 100755 (executable)
@@ -25,7 +25,7 @@ STATS_BIN="$TESTDIR/utils/babelstats.pl"
 SESSION_NAME="valid_filter"
 EVENT_NAME="tp:tptest"
 NR_ITER=100
-NUM_TESTS=338
+NUM_TESTS=290
 
 source $TESTDIR/utils/utils.sh
 
@@ -46,15 +46,7 @@ function enable_ust_lttng_event_filter()
 
 function run_apps
 {
-       ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1
-}
-
-function wait_apps
-{
-       while [ -n "$(pidof $BIN_NAME)" ]; do
-               sleep 1
-       done
-       pass "Wait for application end"
+       ./$CURDIR/$BIN_NAME $NR_ITER >/dev/null 2>&1
 }
 
 function test_valid_filter
@@ -75,7 +67,6 @@ function test_valid_filter
        # Trace apps
        start_lttng_tracing $SESSION_NAME
        run_apps
-       wait_apps
        stop_lttng_tracing $SESSION_NAME
 
        # Destroy session
index afe5435bd4e491388d7b42a5963b87389814a43a..df1cdceaf49aede055b1f56171bf626d768d288d 100755 (executable)
@@ -25,7 +25,7 @@ TESTAPP_NAME="gen-ust-events"
 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 
 STATS_BIN="$TESTDIR/utils/babelstats.pl"
-NUM_TESTS=82
+NUM_TESTS=74
 
 NUM_CPUS=`nproc`
 
@@ -35,14 +35,6 @@ if [ ! -x "$TESTAPP_BIN" ]; then
        BAIL_OUT "No UST events binary detected."
 fi
 
-function wait_apps
-{
-       while [ -n "$(pidof $TESTAPP_NAME)" ]; do
-               sleep 0.5
-       done
-       pass "Wait for applications to end"
-}
-
 function enable_lttng_channel_count_limit ()
 {
        sess_name="$1"
@@ -126,9 +118,7 @@ function test_tracefile_count_limit ()
 
        start_lttng_tracing $session_name
 
-       $TESTAPP_BIN $num_iter >/dev/null 2>&1 &
-
-       wait_apps
+       $TESTAPP_BIN $num_iter >/dev/null 2>&1
 
        stop_lttng_tracing $session_name
 
index ed58e70a2f0c4169bb4d392d895bffd8b6abd1a5..92144ebb740129ab3a8a7c3e7c8ccb5801009d30 100755 (executable)
@@ -26,7 +26,7 @@ TESTAPP_PATH="$TESTDIR/utils/testapp"
 TESTAPP_NAME="gen-ust-events"
 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 
-NUM_TESTS=47
+NUM_TESTS=42
 
 source $TESTDIR/utils/utils.sh
 
@@ -34,14 +34,6 @@ if [ ! -x "$TESTAPP_BIN" ]; then
        BAIL_OUT "No UST events binary detected."
 fi
 
-function wait_apps
-{
-       while [ -n "$(pidof $TESTAPP_NAME)" ]; do
-               sleep 0.5
-       done
-       pass "Wait for applications to end"
-}
-
 function enable_lttng_channel_size_limit ()
 {
        sess_name="$1"
@@ -118,9 +110,7 @@ function test_tracefile_size_limit ()
 
        start_lttng_tracing $session_name
 
-       $TESTAPP_BIN $NR_ITER >/dev/null 2>&1 &
-
-       wait_apps
+       $TESTAPP_BIN $NR_ITER >/dev/null 2>&1
 
        stop_lttng_tracing $session_name
 
index 2d227bf5f69fe98baf32a7ad70e59797b698de12..1cf3cb23ead5843a32541028505c51c1a3994f4e 100755 (executable)
@@ -66,10 +66,9 @@ test_after_multiple_apps() {
        start_lttng_tracing $SESSION_NAME
 
        for i in `seq 1 5`; do
-               $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1
+               $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1
                ok $? "Start application $i for tracing"
        done
-       wait_apps
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
This page took 0.031299 seconds and 4 git commands to generate.