Tests: fix racy UST snapshot post mortem test
authorDavid Goulet <dgoulet@efficios.com>
Mon, 25 Nov 2013 17:56:03 +0000 (12:56 -0500)
committerDavid Goulet <dgoulet@efficios.com>
Mon, 25 Nov 2013 18:16:23 +0000 (13:16 -0500)
Fixes #666

Signed-off-by: David Goulet <dgoulet@efficios.com>
tests/regression/tools/snapshots/test_ust
tests/utils/testapp/gen-ust-events/gen-ust-events.c

index bd2521c48bd3089cd8b58e7426735b697a1038d6..bdc6f74d63192aa426935c346f0ca4f196984450 100755 (executable)
@@ -30,7 +30,7 @@ NR_USEC_WAIT=100
 
 TRACE_PATH=$(mktemp -d)
 
-NUM_TESTS=2075
+NUM_TESTS=2076
 
 source $TESTDIR/utils/utils.sh
 
@@ -38,6 +38,30 @@ if [ ! -x "$TESTAPP_BIN" ]; then
        BAIL_OUT "No UST events binary detected."
 fi
 
+function start_test_app()
+{
+       local tmp_file="/tmp/lttng_test_ust.42.file"
+
+       # Start application with a temporary file.
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
+       ok $? "Start application to trace"
+
+       # Wait for the application file to appear indicating that at least one
+       # tracepoint has been fired.
+       while [ ! -f "$tmp_file" ]; do
+               sleep 0.5
+       done
+       diag "Removing test app temporary file $tmp_file"
+       rm -f $tmp_file
+}
+
+function kill_test_app()
+{
+       diag "Killing $TESTAPP_NAME"
+       PID_APP=`pidof $TESTAPP_NAME`
+       kill $PID_APP >/dev/null 2>&1
+}
+
 function snapshot_add_output ()
 {
        local sess_name=$1
@@ -123,8 +147,10 @@ function test_ust_local_snapshot ()
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
        start_lttng_tracing $SESSION_NAME
        lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Start application to trace"
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+
        lttng_snapshot_record $SESSION_NAME
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
@@ -137,9 +163,8 @@ function test_ust_local_snapshot ()
        else
                break
        fi
-       diag "Killing $TESTAPP_NAME"
-       PID_APP=`pidof $TESTAPP_NAME`
-       kill $PID_APP >/dev/null 2>&1
+
+       kill_test_app
 }
 
 function test_ust_local_snapshot_max_size ()
@@ -160,8 +185,8 @@ function test_ust_local_snapshot_max_size ()
 
        snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Start application to trace"
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
 
        lttng_snapshot_record $SESSION_NAME
 
@@ -187,9 +212,7 @@ function test_ust_local_snapshot_max_size ()
                rm -rf $TRACE_PATH
        fi
 
-       diag "Killing $TESTAPP_NAME"
-       PID_APP=`pidof $TESTAPP_NAME`
-       kill $PID_APP >/dev/null 2>&1
+       kill_test_app
 }
 
 function test_ust_local_snapshot_large_metadata ()
@@ -238,8 +261,10 @@ function test_ust_per_uid_local_snapshot ()
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
        start_lttng_tracing $SESSION_NAME
        lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Start application to trace"
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+
        lttng_snapshot_record $SESSION_NAME
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
@@ -252,9 +277,8 @@ function test_ust_per_uid_local_snapshot ()
        else
                break
        fi
-       diag "Killing $TESTAPP_NAME"
-       PID_APP=`pidof $TESTAPP_NAME`
-       kill $PID_APP >/dev/null 2>&1
+
+       kill_test_app
 }
 
 function test_ust_per_uid_local_snapshot_post_mortem ()
@@ -265,11 +289,11 @@ function test_ust_per_uid_local_snapshot_post_mortem ()
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
        start_lttng_tracing $SESSION_NAME
        lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
-       ok $? "Start application to trace"
-       diag "Killing $TESTAPP_NAME"
-       PID_APP=`pidof $TESTAPP_NAME`
-       kill $PID_APP >/dev/null 2>&1
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+       kill_test_app
+
        lttng_snapshot_record $SESSION_NAME
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
@@ -294,7 +318,10 @@ function test_ust_1000_local_snapshots ()
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
        start_lttng_tracing $SESSION_NAME
        lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
+
+       # Returns once the application has at least fired ONE tracepoint.
+       start_test_app
+
        for i in $(seq 1 $NB_SNAP); do
                diag "Snapshot $i/$NB_SNAP"
                rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
@@ -310,9 +337,8 @@ function test_ust_1000_local_snapshots ()
        done
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
-       diag "Killing $TESTAPP_NAME"
-       PID_APP=`pidof $TESTAPP_NAME`
-       kill $PID_APP >/dev/null 2>&1
+
+       kill_test_app
 }
 
 plan_tests $NUM_TESTS
index edf40eee42a1c3dcbf224adb2f08e0720a6040d4..5f1e5bdd4e1dec155399fbb38c418ef82f54752d 100644 (file)
@@ -15,7 +15,9 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <assert.h>
 #include <arpa/inet.h>
+#include <fcntl.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #define TRACEPOINT_DEFINE
 #include "tp.h"
 
+void create_file(const char *path)
+{
+       int ret;
+
+       assert(path);
+
+       ret = creat(path, S_IRWXU);
+       if (ret < 0) {
+               fprintf(stderr, "Failed to create file %s\n", path);
+               return;
+       }
+
+       (void) close(ret);
+}
+
 int main(int argc, char **argv)
 {
        int i, netint;
@@ -37,6 +54,7 @@ int main(int argc, char **argv)
        float flt = 2222.0;
        unsigned int nr_iter = 100;
        useconds_t nr_usec = 0;
+       char *tmp_file_path = NULL;
 
        if (argc >= 2) {
                nr_iter = atoi(argv[1]);
@@ -47,10 +65,22 @@ int main(int argc, char **argv)
                nr_usec = atoi(argv[2]);
        }
 
+       if (argc == 4) {
+               tmp_file_path = argv[3];
+       }
+
        for (i = 0; i < nr_iter; i++) {
                netint = htonl(i);
-               tracepoint(tp, tptest, i, netint, values, text, strlen(text),
-                          dbl, flt);
+               tracepoint(tp, tptest, i, netint, values, text, strlen(text), dbl,
+                               flt);
+
+               /*
+                * First loop we create the file if asked to indicate that at least one
+                * tracepoint has been hit.
+                */
+               if (i == 0 && tmp_file_path) {
+                       create_file(tmp_file_path);
+               }
                usleep(nr_usec);
        }
 
This page took 0.027198 seconds and 4 git commands to generate.