# 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 &
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 &
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
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=$?
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"
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"
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"
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"
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
}
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
# 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
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
}
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
# 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
# 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
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
APPS_PID=
pass "Stopped all spawned applications"
+rm -f ${file_sync_after_first}
+rm -f ${file_sync_before_last}
+
stop_lttng_sessiond
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
* 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) {
}
(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)
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) {
/*
}
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);
}