From 4986e6a68873ff8ec774489964c79aead7d39a49 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 28 Nov 2013 14:48:59 -0500 Subject: [PATCH] Tests: fix racy tests and misleading output messages Signed-off-by: David Goulet --- .../ust/before-after/test_before_after | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/tests/regression/ust/before-after/test_before_after b/tests/regression/ust/before-after/test_before_after index 6d45bb5e7..ed4981ba0 100755 --- a/tests/regression/ust/before-after/test_before_after +++ b/tests/regression/ust/before-after/test_before_after @@ -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) -- 2.34.1