Tests: use babeltrace2 for all tests
[lttng-tools.git] / tests / regression / ust / buffers-pid / test_buffers_pid
index 6fab526c111c88ec3a7d5a3e43c5f20e00566de7..982ee2d58dff73a25f7c0f4a41589634b317d601 100755 (executable)
@@ -1,19 +1,9 @@
 #!/bin/bash
 #
-# Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
+# Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
 #
-# This library is free software; you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation; version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this library; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+# SPDX-License-Identifier: LGPL-2.1-only
+
 TEST_DESC="UST tracer - Tracing with per PID buffers"
 
 CURDIR=$(dirname $0)/
@@ -26,7 +16,7 @@ TESTAPP_PATH="$TESTDIR/utils/testapp"
 TESTAPP_NAME="gen-ust-events"
 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 EVENT_NAME="tp:tptest"
-NUM_TESTS=58
+NUM_TESTS=59
 
 source $TESTDIR/utils/utils.sh
 
@@ -45,14 +35,6 @@ function enable_channel_per_pid()
        ok $? "Enable channel $channel_name per PID for session $sess_name"
 }
 
-function wait_apps
-{
-       diag "Waiting for applications to end..."
-       while [ -n "$(pidof $TESTAPP_NAME)" ]; do
-               sleep 1
-       done
-}
-
 test_after_multiple_apps() {
        local out
        local i
@@ -60,20 +42,21 @@ test_after_multiple_apps() {
        diag "Start multiple applications AFTER tracing is started"
 
        # BEFORE application is spawned
-       create_lttng_session $SESSION_NAME $TRACE_PATH
+       create_lttng_session_ok $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
+       enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
+       start_lttng_tracing_ok $SESSION_NAME
 
        for i in `seq 1 5`; do
-               $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1
+               $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1 &
                ok $? "Start application $i for tracing"
        done
+       wait
 
-       stop_lttng_tracing $SESSION_NAME
-       destroy_lttng_session $SESSION_NAME
+       stop_lttng_tracing_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME
 
-       trace_matches $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
+       trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
 
        return $?
 }
@@ -81,27 +64,41 @@ test_after_multiple_apps() {
 test_before_multiple_apps() {
        local out
        local i
+       local file_sync_after_first=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
+       local file_sync_before_last=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
 
        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 -i $NR_ITER -w $NR_USEC_WAIT \
+                       --sync-after-first-event ${file_sync_after_first}_${i} \
+                       --sync-before-last-event ${file_sync_before_last}_${i} >/dev/null 2>&1 &
                ok $? "Start application $i for tracing"
        done
 
        # BEFORE application is spawned
-       create_lttng_session $SESSION_NAME $TRACE_PATH
+       create_lttng_session_ok $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
+       enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
+       start_lttng_tracing_ok $SESSION_NAME
 
-       # At least hit one event
-       sleep 2
+       for i in `seq 1 5`; do
+               touch ${file_sync_before_last}_${i}
+       done
 
-       stop_lttng_tracing $SESSION_NAME
-       destroy_lttng_session $SESSION_NAME
+       diag "Waiting for applications to end"
+       wait
+       pass "Waiting done"
 
-       out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
+       stop_lttng_tracing_ok $SESSION_NAME
+       destroy_lttng_session_ok $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_BIN" $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."
@@ -112,8 +109,6 @@ test_before_multiple_apps() {
                out=0
        fi
 
-       wait_apps
-
        return $out
 }
 
@@ -123,44 +118,54 @@ test_after_app() {
        diag "Start application AFTER tracing is started"
 
        # BEFORE application is spawned
-       create_lttng_session $SESSION_NAME $TRACE_PATH
+       create_lttng_session_ok $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
+       enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
+       start_lttng_tracing_ok $SESSION_NAME
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
+       $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
        ok $? "Start application to trace"
+       wait
 
-       stop_lttng_tracing $SESSION_NAME
-       destroy_lttng_session $SESSION_NAME
+       stop_lttng_tracing_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME
 
-       trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
+       trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
 
        return $?
 }
 
 test_before_app() {
        local out
+       local file_sync_after_first=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
+       local file_sync_before_last=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
 
        diag "Start application BEFORE tracing is started"
 
 
        # BEFORE application is spawned
-       create_lttng_session $SESSION_NAME $TRACE_PATH
+       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
        enable_channel_per_pid $SESSION_NAME "channel0"
-       enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
+       enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
+       $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
+               --sync-after-first-event ${file_sync_after_first} \
+               --sync-before-last-event ${file_sync_before_last} &
        ok $? "Start application to trace"
 
-       start_lttng_tracing $SESSION_NAME
+       start_lttng_tracing_ok $SESSION_NAME
+
+       touch ${file_sync_before_last}
 
-       wait ${!}
+       wait
 
-       stop_lttng_tracing $SESSION_NAME
-       destroy_lttng_session $SESSION_NAME
+       stop_lttng_tracing_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME
 
-       out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
+       rm -f ${file_sync_after_first}
+       rm -f ${file_sync_before_last}
+
+       out=$("$BABELTRACE_BIN" $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."
@@ -180,7 +185,7 @@ test_multiple_channels() {
        diag "Start with multiple channels"
 
        # BEFORE application is spawned
-       create_lttng_session $SESSION_NAME $TRACE_PATH
+       create_lttng_session_ok $SESSION_NAME $TRACE_PATH
        enable_channel_per_pid $SESSION_NAME "channel0"
        enable_channel_per_pid $SESSION_NAME "channel1"
        enable_channel_per_pid $SESSION_NAME "channel2"
@@ -197,16 +202,17 @@ test_multiple_channels() {
        ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel3"
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel4 -s $SESSION_NAME -u >/dev/null 2>&1
        ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel4"
-       start_lttng_tracing $SESSION_NAME
+       start_lttng_tracing_ok $SESSION_NAME
 
-       $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
+       $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
        ok $? "Start application to trace"
+       wait
 
-       stop_lttng_tracing $SESSION_NAME
-       trace_matches $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
+       stop_lttng_tracing_ok $SESSION_NAME
+       trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
        out=$?
 
-       destroy_lttng_session $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME
 
        return $out
 }
@@ -216,6 +222,8 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
+bail_out_if_no_babeltrace
+
 TESTS=(
        "test_before_app"
        "test_after_app"
@@ -230,7 +238,7 @@ i=0
 start_lttng_sessiond
 
 while [ $i -lt $TEST_COUNT ]; do
-       TRACE_PATH=$(mktemp -d)
+       TRACE_PATH=$(mktemp --tmpdir -d tmp.test_buffers_pid_trace_path.XXXXXX)
        ${TESTS[$i]}
        rm -rf $TRACE_PATH
        let "i++"
This page took 0.02763 seconds and 4 git commands to generate.