Fix: tests: add missing wait, document missing synchro
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 19 Nov 2014 21:40:28 +0000 (22:40 +0100)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 21 Jan 2015 17:07:54 +0000 (12:07 -0500)
Move all wait ${!} that target a single process to "wait", to minimize
the chances to forget some background process in the future.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Conflicts:
tests/regression/ust/java-log4j/test_java_log4j

Conflicts:
tests/regression/tools/streaming/test_ust
tests/regression/ust/before-after/test_before_after
tests/regression/ust/buffers-pid/test_buffers_pid
tests/regression/ust/multi-session/test_multi_session

tests/regression/tools/snapshots/test_ust_streaming
tests/regression/tools/snapshots/ust_test
tests/regression/tools/streaming/test_ust
tests/regression/ust/before-after/test_before_after
tests/regression/ust/buffers-pid/test_buffers_pid
tests/regression/ust/high-throughput/test_high_throughput
tests/regression/ust/java-jul/test_java_jul
tests/regression/ust/multi-session/test_multi_session
tests/regression/ust/nprocesses/test_nprocesses
tests/regression/ust/periodical-metadata-flush/test_periodical_metadata_flush

index 52330a5c9f8362b1625cbe05f17b71a257c5edbf..ad0c56b19c36550d48ce2afe2b0e954d30341532 100755 (executable)
@@ -82,6 +82,7 @@ function stop_test_apps()
                kill ${p}
                wait ${p} 2>&1
        done
+       APPS_PID=
 }
 
 # Test a snapshot using a default name for the output destination.
index 9dd95bf2bb257569e95da06d084bbeabc736ac56..d8ab18880a0b9bc7f152533d81c1a1f36e134f1a 100755 (executable)
@@ -73,6 +73,7 @@ function stop_test_apps()
                kill ${p}
                wait ${p} 2>&1
        done
+       APPS_PID=
 }
 
 function snapshot_add_output ()
index 785a9a8353efe813dc6fd66f318386f8afa3684e..d96db9460f0c88b33259828a2e640d7da707e69f 100755 (executable)
@@ -29,7 +29,7 @@ PID_RELAYD=0
 
 TRACE_PATH=$(mktemp -d)
 
-NUM_TESTS=18
+NUM_TESTS=16
 
 source $TESTDIR/utils/utils.sh
 
@@ -63,9 +63,11 @@ function test_ust_before_start ()
        # Run 5 times with a 1 second delay
        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 &
 
-       start_lttng_tracing $SESSION_NAME
+       #FIXME: racy missing synchro
 
-       wait_apps
+       start_lttng_tracing $SESSION_NAME
+       # Wait for the applications started in background
+       wait
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
@@ -83,8 +85,13 @@ function test_ust_after_start ()
 
        wait_apps
 
+       #FIXME: racy missing synchro
+
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
+
+       # Wait for the applications started in background
+       wait
 }
 
 plan_tests $NUM_TESTS
index ed4981ba0f55d3f96cd6c5a3c559b96a0eb8f32b..460b04c4e9e6f09fe657a9d05bb94a47622b5a21 100755 (executable)
@@ -25,7 +25,7 @@ TESTAPP_NAME="gen-ust-events"
 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 SESSION_NAME="per-session"
 EVENT_NAME="tp:tptest"
-NUM_TESTS=17
+NUM_TESTS=16
 
 source $TESTDIR/utils/utils.sh
 
@@ -35,14 +35,6 @@ fi
 
 # MUST set TESTDIR before calling those functions
 
-function wait_app()
-{
-       while [ -n "$(pidof $TESTAPP_NAME)" ]; do
-               sleep 0.5
-       done
-       pass "Application $TESTAPP_NAME ended."
-}
-
 function test_before_apps()
 {
        # BEFORE application is spawned
@@ -50,13 +42,14 @@ function test_before_apps()
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
        start_lttng_tracing $SESSION_NAME
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
+       wait
        ok $? "Traced application stopped."
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
-       trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
+       trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
 
        return $?
 }
@@ -64,24 +57,27 @@ function test_before_apps()
 function test_after_apps()
 {
        local out
+       local file_sync_after_first=$(mktemp -u)
+       local file_sync_before_last=$(mktemp -u)
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Application started in background."
-
-       # BEFORE application is spawned
        create_lttng_session $SESSION_NAME $TRACE_PATH
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
+
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} &
+       ok $? "Application started in background."
+
        start_lttng_tracing $SESSION_NAME
 
-       # Since the start is done after the application is started, there is a
-       # bootstrap time needed between the session daemon and the UST tracer.
-       # Waiting for the application to end tells us when to stop everything and
-       # validate that at least one event is seen.
-       wait_app
+       touch ${file_sync_before_last}
+
+       wait
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
+       rm -f ${file_sync_after_first}
+       rm -f ${file_sync_before_last}
+
        validate_trace $EVENT_NAME $TRACE_PATH
        out=$?
 
index a788f869418ba70cb95819d5c09a9c2e440693a5..c95a4a1f9f7c4acb9a51210f00db3ee531f0a255 100755 (executable)
@@ -58,14 +58,15 @@ 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
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
-       trace_matches $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
+       trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
 
        return $?
 }
@@ -73,11 +74,13 @@ test_after_multiple_apps() {
 test_before_multiple_apps() {
        local out
        local i
+       local file_sync_after_first=$(mktemp -u)
+       local file_sync_before_last=$(mktemp -u)
 
        diag "Start multiple applications BEFORE tracing is started"
 
        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 ${file_sync_after_first}_${i} ${file_sync_before_last}_${i} >/dev/null 2>&1 &
                ok $? "Start application $i for tracing"
        done
 
@@ -87,6 +90,10 @@ test_before_multiple_apps() {
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
        start_lttng_tracing $SESSION_NAME
 
+       for i in `seq 1 5`; do
+               touch ${file_sync_before_last}_${i}
+       done
+
        diag "Waiting for applications to end"
        wait
        pass "Waiting done"
@@ -94,6 +101,11 @@ test_before_multiple_apps() {
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
+       for i in `seq 1 5`; do
+               rm -f ${file_sync_after_first}_${i}
+               rm -f ${file_sync_before_last}_${i}
+       done
+
        out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
        if [ $out -eq 0 ]; then
                fail "Trace validation"
@@ -119,37 +131,46 @@ test_after_app() {
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
        start_lttng_tracing $SESSION_NAME
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
        ok $? "Start application to trace"
+       wait
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
-       trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
+       trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
 
        return $?
 }
 
 test_before_app() {
        local out
+       local file_sync_after_first=$(mktemp -u)
+       local file_sync_before_last=$(mktemp -u)
 
        diag "Start application BEFORE tracing is started"
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Start application to trace"
 
        # BEFORE application is spawned
        create_lttng_session $SESSION_NAME $TRACE_PATH
        enable_channel_per_pid $SESSION_NAME "channel0"
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
+
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} &
+       ok $? "Start application to trace"
+
        start_lttng_tracing $SESSION_NAME
 
-       # At least hit one event
-       sleep 2
+       touch ${file_sync_before_last}
+
+       wait
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
+       rm -f ${file_sync_after_first}
+       rm -f ${file_sync_before_last}
+
        out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
        if [ $out -eq 0 ]; then
                fail "Trace validation"
@@ -161,8 +182,6 @@ test_before_app() {
                out=0
        fi
 
-       wait_apps
-
        return $out
 }
 
@@ -191,11 +210,12 @@ test_multiple_channels() {
        ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel4"
        start_lttng_tracing $SESSION_NAME
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
        ok $? "Start application to trace"
+       wait
 
        stop_lttng_tracing $SESSION_NAME
-       trace_matches $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
+       trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
        out=$?
 
        destroy_lttng_session $SESSION_NAME
index 101a2c0a62250369876d30d73856279d002d4c5d..1ee0ec10f6f1857dae35dfd909816aa0009db52e 100755 (executable)
@@ -46,7 +46,7 @@ enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
 start_lttng_tracing $SESSION_NAME
 
 for i in `seq 1 $NR_APP`; do
-       ./$CURDIR/$BIN_NAME & >/dev/null 2>&1
+       ./$CURDIR/$BIN_NAME >/dev/null 2>&1 &
 done
 
 diag "Waiting for applications to end"
index 08214c0ebb8ad25e0521ff350cf7754a335ef79f..a9dd235cce54d0ec7f4caaf7507418b180e112d1 100755 (executable)
@@ -78,6 +78,8 @@ function test_jul_before_start ()
        # Run 5 times with a 1 second delay
        run_app
 
+       #FIXME: racy missing synchronization
+
        start_lttng_tracing $SESSION_NAME
 
        # Wait for the applications started in background
index 313a7d70fa9c408d529d4fca80a2a56d5c0233d2..e1ff9b09124c93f27868b24f0302e702b400ca9c 100755 (executable)
@@ -44,11 +44,7 @@ test_multi_session() {
        ./$CURDIR/gen-nevents $NR_ITER &
        ok $? "Start application to generate $NR_ITER events"
 
-       # At least hit one event
-       while [ -n "$(pidof gen-nevents)" ]; do
-               sleep 0.1
-       done
-
+       wait
        pass "Wait for events to record"
 
        for i in `seq 0 3`; do
index 396dab0d8a026fbdb3a38f1846918c077dc9bbfc..ca0f9d416cba74e08eafecf04d598d867474fa46 100755 (executable)
@@ -53,6 +53,8 @@ do
        APPS_PID="${APPS_PID} ${!}"
 done
 
+#FIXME: racy missing synchronization
+
 diag "Waiting for applications to be registered to sessiond"
 
 reg_app_count=0
@@ -76,6 +78,8 @@ start_lttng_tracing $SESSION_NAME
 stop_lttng_tracing $SESSION_NAME
 destroy_lttng_session $SESSION_NAME
 
+#FIXME/TODO: add validation after fixing racy synchroniaation
+
 rm -rf $TRACE_PATH
 
 diag "Stopping all spawned applications"
@@ -83,6 +87,7 @@ for p in ${APPS_PID}; do
        kill ${p}
        wait ${p} 2>/dev/null
 done
+APPS_PID=
 pass "Stopped all spawned applications"
 
 stop_lttng_sessiond
index e4199652bce1a456333ca0d88cbe869a5b590f96..53db813e1758e0921b02c7a45a496053be769929 100755 (executable)
@@ -28,6 +28,7 @@ EVENT_NAME="tp:tptest"
 BIN_NAME="gen-nevents"
 NUM_TESTS=38
 APP_TMP_FILE="/tmp/lttng_test_ust.42.file"
+APPS_PID=
 
 source $TESTDIR/utils/utils.sh
 
@@ -106,7 +107,9 @@ function start_trace_app()
 {
        # Start application with a temporary file.
        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $APP_TMP_FILE &
-       ok $? "Start application to trace"
+       ret=$?
+       APPS_PID="${APPS_PID} ${!}"
+       ok $ret "Start application to trace"
 }
 
 function start_check_trace_app()
@@ -115,9 +118,20 @@ function start_check_trace_app()
        check_app_tmp_file
 }
 
+
+function wait_trace_apps()
+{
+       for p in ${APPS_PID}; do
+               wait ${p} 2>/dev/null
+       done
+       APPS_PID=
+}
+
 test_after_app_pid() {
        local out
 
+       APPS_PID=
+
        diag "Start application AFTER tracing is started"
 
        create_lttng_session $SESSION_NAME $TRACE_PATH
@@ -133,7 +147,9 @@ test_after_app_pid() {
        # Make sure the application does not generate any more data,
        # thus ensuring that we are not flushing a packet concurrently
        # with validate_trace.
-       killall -SIGSTOP -q $TESTAPP_NAME
+       for p in ${APPS_PID}; do
+               kill -s SIGSTOP ${p}
+       done
 
        # Give time to the consumer to write inflight data.
        sleep 2
@@ -141,11 +157,14 @@ test_after_app_pid() {
        validate_trace
        out=$?
 
-       killall -SIGKILL -q $TESTAPP_NAME
+       for p in ${APPS_PID}; do
+               kill -s SIGKILL ${p}
+               wait ${p} 2>/dev/null
+       done
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
-       wait
+       wait_trace_apps
 
        return $out
 }
@@ -154,6 +173,8 @@ test_before_app_pid() {
        local out
        local tmp_file="/tmp/lttng_test_ust.42.file"
 
+       APPS_PID=
+
        diag "Start application BEFORE tracing is started"
 
        start_trace_app
@@ -172,7 +193,9 @@ test_before_app_pid() {
        # Make sure the application does not generate any more data,
        # thus ensuring that we are not flushing a packet concurrently
        # with validate_trace.
-       killall -SIGSTOP -q $TESTAPP_NAME
+       for p in ${APPS_PID}; do
+               kill -s SIGSTOP ${p}
+       done
 
        # Give time to the consumer to write inflight data.
        sleep 2
@@ -180,11 +203,15 @@ test_before_app_pid() {
        validate_trace
        out=$?
 
-       killall -SIGKILL -q $TESTAPP_NAME
+       for p in ${APPS_PID}; do
+               kill -s SIGKILL ${p}
+               wait ${p} 2>/dev/null
+       done
+
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
-       wait
+       wait_trace_apps
 
        return $out
 }
@@ -192,6 +219,8 @@ test_before_app_pid() {
 test_after_app_uid() {
        local out
 
+       APPS_PID=
+
        diag "Start application AFTER tracing is started"
 
        create_lttng_session $SESSION_NAME $TRACE_PATH
@@ -207,7 +236,10 @@ test_after_app_uid() {
        # Make sure the application does not generate any more data,
        # thus ensuring that we are not flushing a packet concurrently
        # with validate_trace.
-       killall -SIGSTOP -q $TESTAPP_NAME
+       for p in ${APPS_PID}; do
+               kill -s SIGSTOP ${p}
+       done
+
 
        # Give time to the consumer to write inflight data.
        sleep 2
@@ -215,11 +247,14 @@ test_after_app_uid() {
        validate_trace
        out=$?
 
-       killall -SIGKILL -q $TESTAPP_NAME
+       for p in ${APPS_PID}; do
+               kill -s SIGKILL ${p}
+               wait ${p} 2>/dev/null
+       done
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
-       wait
+       wait_trace_apps
 
        return $out
 }
@@ -227,6 +262,8 @@ test_after_app_uid() {
 test_before_app_uid() {
        local out
 
+       APPS_PID=
+
        diag "Start application BEFORE tracing is started"
 
        # Start application before tracing
@@ -245,7 +282,9 @@ test_before_app_uid() {
        # Make sure the application does not generate any more data,
        # thus ensuring that we are not flushing a packet concurrently
        # with validate_trace.
-       killall -SIGSTOP -q $TESTAPP_NAME
+       for p in ${APPS_PID}; do
+               kill -s SIGSTOP ${p}
+       done
 
        # Give time to the consumer to write inflight data.
        sleep 2
@@ -253,11 +292,14 @@ test_before_app_uid() {
        validate_trace
        out=$?
 
-       killall -SIGKILL -q $TESTAPP_NAME
+       for p in ${APPS_PID}; do
+               kill -s SIGKILL ${p}
+               wait ${p} 2>/dev/null
+       done
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
-       wait
+       wait_trace_apps
 
        return $out
 }
This page took 0.034766 seconds and 4 git commands to generate.