Tests: fix racy tests and misleading output messages
authorDavid Goulet <dgoulet@efficios.com>
Thu, 28 Nov 2013 19:48:59 +0000 (14:48 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Thu, 28 Nov 2013 19:52:40 +0000 (14:52 -0500)
Signed-off-by: David Goulet <dgoulet@efficios.com>
tests/regression/ust/before-after/test_before_after

index 6d45bb5e7f2bfee9c933e93a27e22dd16122915f..ed4981ba0f55d3f96cd6c5a3c559b96a0eb8f32b 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=16
+NUM_TESTS=17
 
 source $TESTDIR/utils/utils.sh
 
@@ -35,14 +35,23 @@ fi
 
 # MUST set TESTDIR before calling those functions
 
-test_before_apps() {
+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
        create_lttng_session $SESSION_NAME $TRACE_PATH
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
        start_lttng_tracing $SESSION_NAME
 
        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
-       ok $? "Start application to trace"
+       ok $? "Traced application stopped."
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
@@ -52,33 +61,29 @@ test_before_apps() {
        return $?
 }
 
-test_after_apps() {
+function test_after_apps()
+{
        local out
 
        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Start application to trace"
+       ok $? "Application started in background."
 
        # BEFORE application is spawned
        create_lttng_session $SESSION_NAME $TRACE_PATH
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
        start_lttng_tracing $SESSION_NAME
 
-       # At least hit one event
-       sleep 2
+       # 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
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
-       out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
-       if [ $out -eq 0 ]; then
-               fail "Trace validation"
-               diag "No event(s) found. We are supposed to have at least one."
-               out=1
-       else
-               pass "Trace validation"
-               diag "Found $out event(s). Coherent."
-               out=0
-       fi
+       validate_trace $EVENT_NAME $TRACE_PATH
+       out=$?
 
        return $out
 }
@@ -90,7 +95,7 @@ print_test_banner "$TEST_DESC"
 
 start_lttng_sessiond
 
-diag "Start application BEFORE tracing was started"
+diag "Start tracing BEFORE application is started"
 
 TRACE_PATH=$(mktemp -d)
 
@@ -103,7 +108,7 @@ fi
 
 rm -rf $TRACE_PATH
 
-diag "Start application AFTER tracing was started"
+diag "Start tracing AFTER application is started"
 
 TRACE_PATH=$(mktemp -d)
 
This page took 0.026835 seconds and 4 git commands to generate.