Fix: add missing synchronization point for before app test case
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 20 Nov 2014 06:40:41 +0000 (07:40 +0100)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 26 Nov 2014 18:33:35 +0000 (13:33 -0500)
Fixes a race where the application could generate all its events before
trace start.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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/java-jul/test_java_jul
tests/regression/ust/java-log4j/test_java_log4j
tests/regression/ust/nprocesses/test_nprocesses
tests/regression/ust/periodical-metadata-flush/test_periodical_metadata_flush
tests/utils/testapp/gen-ust-events/gen-ust-events.c

index 55c1087d9e673ae0aae50e65eb87e10aa23faef1..ef38bd59914d2d648a1b92b17e38f4c0cd5e8bd4 100755 (executable)
@@ -58,7 +58,7 @@ function snapshot_add_output ()
 # Start trace application and return once one event has been hit.
 function start_test_app()
 {
-       local tmp_file="/tmp/lttng_test_ust.42.file"
+       local tmp_file=$(mktemp -u)
 
        # Start application with a temporary file.
        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
index 1541e6e1e745b3272e318d76f47f0f4cdf6c3b9d..cbc205828149a268bdec70121eb7486dee1e2719 100755 (executable)
@@ -49,7 +49,7 @@ NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 2)))
 
 function start_test_app()
 {
-       local tmp_file="/tmp/lttng_test_ust.42.file"
+       local tmp_file=$(mktemp -u)
 
        # Start application with a temporary file.
        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
index 480717515b49d3add63d213adee981ecfd06a053..e6a0bb846569117ee4add0fb11215cd022120653 100755 (executable)
@@ -49,40 +49,51 @@ function lttng_create_session_uri
 
 function test_ust_before_start ()
 {
+       local file_sync_after_first=$(mktemp -u)
+       local file_sync_before_last=$(mktemp -u)
+
        diag "Test UST streaming BEFORE tracing starts"
        lttng_create_session_uri
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
 
        # Run 5 times with a 1 second delay
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 &
-
-       #FIXME: racy missing synchro
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} /dev/null 2>&1 &
 
        start_lttng_tracing $SESSION_NAME
+
+       touch ${file_sync_before_last}
+
        # Wait for the applications started in background
        wait
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
+       rm -f ${file_sync_after_first}
+       rm -f ${file_sync_before_last}
 }
 
 function test_ust_after_start ()
 {
+       local file_sync_after_first=$(mktemp -u)
+
        diag "Test UST streaming AFTER tracing starts"
        lttng_create_session_uri
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
        start_lttng_tracing $SESSION_NAME
 
        # Run 5 times with a 1 second delay
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} >/dev/null 2>&1
 
-       #FIXME: racy missing synchro
+       while [ ! -f "${file_sync_after_first}" ]; do
+               sleep 0.5
+       done
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
        # Wait for the applications started in background
        wait
+       rm -f ${file_sync_after_first}
 }
 
 plan_tests $NUM_TESTS
index 1535f3627bbd25855573901e69de69bf4b2bf9ed..460b04c4e9e6f09fe657a9d05bb94a47622b5a21 100755 (executable)
@@ -57,22 +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)
 
        create_lttng_session $SESSION_NAME $TRACE_PATH
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} &
        ok $? "Application started in background."
 
-       #FIXME: racy missing synchronization
-
        start_lttng_tracing $SESSION_NAME
 
+       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 0258e890cd4bb02b4c6b9400ff98ffaf74f30dc0..c95a4a1f9f7c4acb9a51210f00db3ee531f0a255 100755 (executable)
@@ -74,22 +74,26 @@ 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
 
-       #FIXME: racy missing synchronization
-
        # 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"
        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"
@@ -97,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"
@@ -136,6 +145,8 @@ test_after_app() {
 
 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"
 
@@ -145,18 +156,21 @@ test_before_app() {
        enable_channel_per_pid $SESSION_NAME "channel0"
        enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} &
        ok $? "Start application to trace"
 
-       #FIXME: racy missing synchronization
-
        start_lttng_tracing $SESSION_NAME
 
+       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"
index d16880f277aa77ad9da5d10d8630340be3957c5a..d32d9ed4564e9901b639b0588f2f3bdf217e6f61 100755 (executable)
@@ -38,6 +38,7 @@ function run_app
        local finest_tp=$1
        local fire_second_tp=$2
 
+       #FIXME: app should have synchro.
        java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $finest_tp $fire_second_tp >/dev/null 2>&1
 }
 
@@ -89,6 +90,9 @@ function enable_jul_filter_loglevel_only()
 
 function test_jul_before_start ()
 {
+       local file_sync_after_first=$(mktemp -u)
+       local file_sync_before_last=$(mktemp -u)
+
        diag "Test JUL application BEFORE tracing starts"
        create_lttng_session $SESSION_NAME $TRACE_PATH
        enable_jul_lttng_event $SESSION_NAME $EVENT_NAME
@@ -96,16 +100,19 @@ function test_jul_before_start ()
        # Run 5 times with a 1 second delay
        run_app_background
 
-       #FIXME: racy missing synchronization
-
        start_lttng_tracing $SESSION_NAME
 
+       touch ${file_sync_before_last}
+
        # Wait for the applications started in background
        wait
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
+       rm -f ${file_sync_after_first}
+       rm -f ${file_sync_before_last}
+
        # Validate test. Expecting all events.
        trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
        if [ $? -ne 0 ]; then
index 11845a0bbf049324e18ca9b27e96c406171440b5..a0b7cdc0f9592bb6a5d567ed71e1183fead22f23 100755 (executable)
@@ -39,6 +39,7 @@ function run_app
        local debug_tp=$1
        local fire_second_tp=$2
 
+       # FIXME: test app should have synchro.
        java -cp $JAVA_CP -Djava.library.path="/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $debug_tp $fire_second_tp >/dev/null 2>&1
 }
 
@@ -90,6 +91,9 @@ function enable_log4j_filter_loglevel_only()
 
 function test_log4j_before_start ()
 {
+       local file_sync_after_first=$(mktemp -u)
+       local file_sync_before_last=$(mktemp -u)
+
        diag "Test LOG4J application BEFORE tracing starts"
        create_lttng_session $SESSION_NAME $TRACE_PATH
        enable_log4j_lttng_event $SESSION_NAME $EVENT_NAME
@@ -97,16 +101,19 @@ function test_log4j_before_start ()
        # Run 5 times with a 1 second delay
        run_app_background
 
-       #FIXME: racy missing synchronization
-
        start_lttng_tracing $SESSION_NAME
 
+       touch ${file_sync_before_last}
+
        # Wait for the applications started in background
        wait
 
        stop_lttng_tracing $SESSION_NAME
        destroy_lttng_session $SESSION_NAME
 
+       rm -f ${file_sync_after_first}
+       rm -f ${file_sync_before_last}
+
        # Validate test. Expecting all events.
        trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
        if [ $? -ne 0 ]; then
index ca0f9d416cba74e08eafecf04d598d867474fa46..8eed95fcaa911f8f437f63d26a536302f3155b1d 100755 (executable)
@@ -46,15 +46,16 @@ start_lttng_sessiond
 
 # Start tests. Each is an infinite tracing loop.
 
+file_sync_after_first=$(mktemp -u)
+file_sync_before_last=$(mktemp -u)
+
 diag "Starting $NUM_PROCESS test applications"
 for i in `seq 1 $NUM_PROCESS`
 do
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 &
+       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} >/dev/null 2>&1 &
        APPS_PID="${APPS_PID} ${!}"
 done
 
-#FIXME: racy missing synchronization
-
 diag "Waiting for applications to be registered to sessiond"
 
 reg_app_count=0
@@ -72,13 +73,15 @@ create_lttng_session $SESSION_NAME $TRACE_PATH
 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
 start_lttng_tracing $SESSION_NAME
 
+touch ${file_sync_before_last}
+
 # We don't validate whether the applications have traced here, rather
 # just that they registered to sessiond (above).
 
 stop_lttng_tracing $SESSION_NAME
 destroy_lttng_session $SESSION_NAME
 
-#FIXME/TODO: add validation after fixing racy synchroniaation
+#TODO: add trace validation.
 
 rm -rf $TRACE_PATH
 
@@ -90,4 +93,7 @@ done
 APPS_PID=
 pass "Stopped all spawned applications"
 
+rm -f ${file_sync_after_first}
+rm -f ${file_sync_before_last}
+
 stop_lttng_sessiond
index 53db813e1758e0921b02c7a45a496053be769929..7937fa27dd3a9e22e253404df6ec462768670eda 100755 (executable)
@@ -27,7 +27,7 @@ SESSION_NAME="periodical-flush"
 EVENT_NAME="tp:tptest"
 BIN_NAME="gen-nevents"
 NUM_TESTS=38
-APP_TMP_FILE="/tmp/lttng_test_ust.42.file"
+APP_TMP_FILE=$(mktemp -u)
 APPS_PID=
 
 source $TESTDIR/utils/utils.sh
index 3be0f0f1130958769e8d9298a1945fd441af6742..11327d5f4b6866d7c324b50223181897ccf8e862 100644 (file)
@@ -15,6 +15,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#define _GNU_SOURCE
 #define _LGPL_SOURCE
 #include <assert.h>
 #include <arpa/inet.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdbool.h>
+#include <signal.h>
+#include <poll.h>
+#include <errno.h>
 
 #define TRACEPOINT_DEFINE
 #include "tp.h"
 
 void create_file(const char *path)
 {
+       static bool file_created = false;
        int ret;
 
-       assert(path);
+       if (!path || file_created) {
+               return;
+       }
 
        ret = creat(path, S_IRWXU);
        if (ret < 0) {
@@ -45,6 +52,30 @@ void create_file(const char *path)
        }
 
        (void) close(ret);
+       file_created = true;
+}
+
+static
+void wait_on_file(const char *path)
+{
+       if (!path) {
+               return;
+       }
+       for (;;) {
+               int ret;
+               struct stat buf;
+
+               ret = stat(path, &buf);
+               if (ret == -1 && errno == ENOENT) {
+                       (void) poll(NULL, 0, 10);       /* 10 ms delay */
+                       continue;                       /* retry */
+               }
+               if (ret) {
+                       perror("stat");
+                       exit(EXIT_FAILURE);
+               }
+               break;  /* found */
+       }
 }
 
 int main(int argc, char **argv)
@@ -56,8 +87,8 @@ int main(int argc, char **argv)
        float flt = 2222.0;
        int nr_iter = 100;
        useconds_t nr_usec = 0;
-       char *tmp_file_path = NULL;
-       bool file_created = false;
+       char *after_first_event_file_path = NULL;
+       char *before_last_event_file_path = NULL;
 
        if (argc >= 2) {
                /*
@@ -72,22 +103,30 @@ int main(int argc, char **argv)
        }
 
        if (argc >= 4) {
-               tmp_file_path = argv[3];
+               after_first_event_file_path = argv[3];
+       }
+
+       if (argc >= 5) {
+               before_last_event_file_path = argv[4];
        }
 
        for (i = 0; nr_iter < 0 || i < nr_iter; i++) {
+               if (nr_iter >= 0 && i == nr_iter - 1) {
+                       /*
+                        * Wait on synchronization before writing last
+                        * event.
+                        */
+                       wait_on_file(before_last_event_file_path);
+               }
                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.
+                * First loop we create the file if asked to indicate
+                * that at least one tracepoint has been hit.
                 */
-               if (!file_created && tmp_file_path) {
-                       create_file(tmp_file_path);
-                       file_created = true;
-               }
+               create_file(after_first_event_file_path);
                usleep(nr_usec);
        }
 
This page took 0.046986 seconds and 4 git commands to generate.