.gitignore: ignore local vscode workspace settings file
[lttng-tools.git] / tests / regression / tools / tracker / test_event_tracker
index f6ed6ba8bef1f9e4725c500311ea5af75c604348..2507498bfb452aa301653650152f0adf2119d8a0 100755 (executable)
@@ -1,22 +1,11 @@
 #!/bin/bash
 #
-# Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
-# Copyright (C) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+# Copyright (C) 2013 Christian Babeux <christian.babeux@efficios.com>
+# Copyright (C) 2015-2018 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License, version 2 only, as
-# published by the Free Software Foundation.
-#
-# This program 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 General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# this program; if not, write to the Free Software Foundation, Inc., 51
-# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# SPDX-License-Identifier: GPL-2.0-only
 
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"
 
 CURDIR=$(dirname "$0")/
 TESTDIR="$CURDIR/../../.."
@@ -26,7 +15,7 @@ TESTAPP_KERNEL_NAME="gen-kernel-test-events"
 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 TESTAPP_KERNEL_BIN="$TESTAPP_PATH/$TESTAPP_KERNEL_NAME/$TESTAPP_KERNEL_NAME"
 SESSION_NAME="tracker"
-NR_ITER=100
+NR_ITER=1
 NUM_GLOBAL_TESTS=2
 NUM_UST_TESTS=283
 NUM_KERNEL_TESTS=462
@@ -41,32 +30,46 @@ SCRIPT_GROUPNAME="$(id -gn)"
 
 CHILD_PID=-1
 WAIT_PATH=
-AFTER_FIRST_PATH=
-BEFORE_LAST_PATH=
+TOUCH_BEFORE_LAST_PATH=
+SYNC_BEFORE_LAST_PATH=
 
 source $TESTDIR/utils/utils.sh
 
+# Launch the testapp and execute it up until right before the last event. It is
+# useful to do it in two seperate steps in order to test tracking and
+# untracking on an active app.
 function prepare_ust_app
 {
-       AFTER_FIRST_PATH=$(mktemp -u)
-       BEFORE_LAST_PATH=$(mktemp -u)
+       TOUCH_BEFORE_LAST_PATH=$(mktemp -u -t tmp.${FUNCNAME[0]}_touch_before_last.XXXXXX)
+       SYNC_BEFORE_LAST_PATH=$(mktemp -u -t tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX)
+
+       $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
+               --sync-before-last-event-touch "$TOUCH_BEFORE_LAST_PATH" \
+               --sync-before-last-event "$SYNC_BEFORE_LAST_PATH" &
 
-       $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b "$BEFORE_LAST_PATH" &
        CHILD_PID=$!
+
+       # Wait for the app to execute all the way to right before the last
+       # event.
+       while [ ! -f "${TOUCH_BEFORE_LAST_PATH}" ]; do
+               sleep 0.01
+       done
 }
 
+# Generate the last event.
 function trace_ust_app
 {
-       touch "$BEFORE_LAST_PATH"
-       wait
+       # Ask the test app to generate the last event.
+       touch "$SYNC_BEFORE_LAST_PATH"
+       wait "$CHILD_PID"
        ok $? "Traced application stopped."
-       rm "$BEFORE_LAST_PATH"
-       rm "$AFTER_FIRST_PATH"
+       rm "$SYNC_BEFORE_LAST_PATH"
+       rm "$TOUCH_BEFORE_LAST_PATH"
 }
 
 function prepare_kernel_app
 {
-       WAIT_PATH=$(mktemp -u)
+       WAIT_PATH=$(mktemp -u -t "tmp.${FUNCNAME[0]}_wait_path.XXXXXX")
 
        "$TESTAPP_KERNEL_BIN" "$WAIT_PATH" $NR_ITER &
        CHILD_PID=$!
@@ -75,7 +78,7 @@ function prepare_kernel_app
 function trace_kernel_app
 {
        touch "$WAIT_PATH"
-       wait
+       wait "$CHILD_PID"
        ok $? "Traced application stopped."
        rm "$WAIT_PATH"
 }
@@ -89,7 +92,9 @@ function test_event_tracker()
        local tracker="$4"
        local channel=''
 
-       trace_path=$(mktemp -d)
+       diag "${FUNCNAME[0]} $*"
+
+       trace_path=$(mktemp -d -t tmp.${FUNCNAME[0]}_trace_path.XXXXXX)
 
        create_lttng_session_ok $SESSION_NAME "$trace_path"
 
@@ -109,7 +114,7 @@ function test_event_tracker()
        trace_"$domain"_app
 
        stop_lttng_tracing_ok
-       destroy_lttng_session_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME --no-wait
 
        if [ "$expect_event" -eq 1 ]; then
                trace_matches "$EVENT_NAME" $NR_ITER "$trace_path"
@@ -128,7 +133,9 @@ function test_event_vpid_tracker()
        local wildcard="$3"
        local channel=''
 
-       trace_path=$(mktemp -d)
+       diag "${FUNCNAME[0]} $*"
+
+       trace_path=$(mktemp -d -t tmp.${FUNCNAME[0]}_trace_path.XXXXXX)
 
        create_lttng_session_ok $SESSION_NAME "$trace_path"
 
@@ -152,7 +159,7 @@ function test_event_vpid_tracker()
        trace_"$domain"_app
 
        stop_lttng_tracing_ok
-       destroy_lttng_session_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME --no-wait
 
        if [ "$expect_event" -eq 1 ]; then
                validate_trace "$EVENT_NAME" "$trace_path"
@@ -171,7 +178,9 @@ function test_event_pid_tracker()
        local wildcard="$3"
        local channel=''
 
-       trace_path=$(mktemp -d)
+       diag "${FUNCNAME[0]} $*"
+
+       trace_path=$(mktemp -d -t tmp.${FUNCNAME[0]}_trace_path.XXXXXX)
 
        create_lttng_session_ok $SESSION_NAME "$trace_path"
 
@@ -195,7 +204,7 @@ function test_event_pid_tracker()
        trace_"$domain"_app
 
        stop_lttng_tracing_ok
-       destroy_lttng_session_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME --no-wait
 
        if [ "$expect_event" -eq 1 ]; then
                validate_trace "$EVENT_NAME" "$trace_path"
@@ -214,12 +223,14 @@ function test_event_tracker_fail()
        local wildcard="$2"
        local tracker="$3"
 
-       trace_path=$(mktemp -d)
+       diag "${FUNCNAME[0]} $*"
+
+       trace_path=$(mktemp -d -t tmp.${FUNCNAME[0]}_trace_path.XXXXXX)
 
        create_lttng_session_ok $SESSION_NAME "$trace_path"
        enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard"
        lttng_track_"$domain"_fail "${tracker}"
-       destroy_lttng_session_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME --no-wait
 
        rm -rf "$trace_path"
 }
@@ -233,7 +244,9 @@ function test_event_track_untrack()
        local tracker="$4"
        local channel=''
 
-       trace_path=$(mktemp -d)
+       diag "${FUNCNAME[0]} $*"
+
+       trace_path=$(mktemp -d -t tmp.${FUNCNAME[0]}_trace_path.XXXXXX)
 
        create_lttng_session_ok $SESSION_NAME "$trace_path"
 
@@ -254,7 +267,7 @@ function test_event_track_untrack()
        trace_"$domain"_app
 
        stop_lttng_tracing_ok
-       destroy_lttng_session_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME --no-wait
 
        if [ "$expect_event" -eq 1 ]; then
                trace_matches "$EVENT_NAME" $NR_ITER "$trace_path"
@@ -273,7 +286,9 @@ function test_event_vpid_track_untrack()
        local wildcard="$3"
        local channel=''
 
-       trace_path=$(mktemp -d)
+       diag "${FUNCNAME[0]} $*"
+
+       trace_path=$(mktemp -d -t tmp.${FUNCNAME[0]}_trace_path.XXXXXX)
 
        create_lttng_session_ok $SESSION_NAME "$trace_path"
 
@@ -294,7 +309,7 @@ function test_event_vpid_track_untrack()
        trace_"$domain"_app
 
        stop_lttng_tracing_ok
-       destroy_lttng_session_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME --no-wait
 
        if [ "$expect_event" -eq 1 ]; then
                validate_trace "$EVENT_NAME" "$trace_path"
@@ -313,7 +328,9 @@ function test_event_pid_track_untrack()
        local wildcard="$3"
        local channel=''
 
-       trace_path=$(mktemp -d)
+       diag "${FUNCNAME[0]} $*"
+
+       trace_path=$(mktemp -d -t tmp.${FUNCNAME[0]}_trace_path.XXXXXX)
 
        create_lttng_session_ok $SESSION_NAME "$trace_path"
 
@@ -334,7 +351,7 @@ function test_event_pid_track_untrack()
        trace_"$domain"_app
 
        stop_lttng_tracing_ok
-       destroy_lttng_session_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME --no-wait
 
        if [ "$expect_event" -eq 1 ]; then
                validate_trace "$EVENT_NAME" "$trace_path"
@@ -347,11 +364,9 @@ function test_event_pid_track_untrack()
 
 function test_event_ust_vpid_untrack_snapshot()
 {
-       local trace_path
+       diag "${FUNCNAME[0]} $*"
 
-       trace_path=$(mktemp -d)
-
-       diag "Test_event_ust_vpid_untrack_snapshot"
+       local trace_path=$(mktemp -d -t tmp.${FUNCNAME[0]}_trace_path.XXXXXX)
 
        create_lttng_session_ok $SESSION_NAME "$trace_path" "--snapshot"
 
@@ -367,7 +382,7 @@ function test_event_ust_vpid_untrack_snapshot()
        lttng_snapshot_record $SESSION_NAME
 
        stop_lttng_tracing_ok
-       destroy_lttng_session_ok $SESSION_NAME
+       destroy_lttng_session_ok $SESSION_NAME --no-wait
 
        snapshot_count=$(find "$trace_path" -name metadata | wc -l)
        is "$snapshot_count" 0 "Number of snapshot is zero"
@@ -380,6 +395,8 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
+bail_out_if_no_babeltrace
+
 start_lttng_sessiond
 
 diag "Test UST tracker"
@@ -451,13 +468,7 @@ test_event_track_untrack ust 0 "${EVENT_NAME}" "--pid --all"       # backward compat
 test_event_tracker ust 1 "${EVENT_NAME}" "--pid --all" # backward compat
 test_event_pid_tracker ust 1 "${EVENT_NAME}"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel tracker tests." $NUM_KERNEL_TESTS ||
+check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel tracker tests." ||
 {
        diag "Test kernel tracker"
 
@@ -548,7 +559,20 @@ skip $isroot "Root access is needed. Skipping all kernel tracker tests." $NUM_KE
        test_event_tracker kernel 1 "${EVENT_NAME}" "--pid --all"
        test_event_pid_tracker kernel 1 "${EVENT_NAME}"
 
-       rmmod lttng-test
+       # When using session destroy with '--no-wait', the quick
+       # exit at the end means that the lttng-test modules is
+       # still marked as being in use and 'modprobe --remove' fails.
+       #
+       # It is possible to work around the issue by not setting
+       # '--no-wait' on the last kernel test, but it seems like
+       # an easy detail to forget about.
+       #
+       # The sleep here gives the system a small amount of time to
+       # finish wrapping up the session that had the lttng-test kernel
+       # module loaded.
+       sleep 1
+
+       modprobe --remove lttng-test
        ok $? "Unloading lttng-test module"
 }
 
This page took 0.027568 seconds and 4 git commands to generate.