Cleanup: tests: name all temporary files to better identify leakage
[lttng-tools.git] / tests / regression / tools / exclusion / test_exclusion
index 949cd41df1459db3f3898ed1aeca49f6d2d2c178..1bfb63533761fed9c042b63ba7f87daf1f837419 100755 (executable)
@@ -1,19 +1,9 @@
 #!/bin/bash
 #
-# Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
+# Copyright (C) 2012 Christian Babeux <christian.babeux@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.
+# SPDX-License-Identifier: GPL-2.0-only
 #
-# 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.
 
 TEST_DESC="Event exclusion"
 
@@ -26,7 +16,7 @@ TESTAPP_NAME="gen-ust-nevents"
 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 NR_ITER=100
 NR_USEC_WAIT=1
-NUM_TESTS=149
+NUM_TESTS=185
 
 source $TESTDIR/utils/utils.sh
 
@@ -35,19 +25,52 @@ function enable_ust_lttng_all_event_exclusion()
        sess_name="$1"
        exclusion="$2"
 
-       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -a -s $sess_name -u -x "$exclusion"
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $sess_name -x "$exclusion" > /dev/null
 }
 
 function run_apps
 {
-        $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
+       $TESTAPP_BIN --iter $NR_ITER --wait $NR_USEC_WAIT >/dev/null 2>&1
+       ok $? "Running test application"
+}
+
+# Testing for the absence of an event when testing exclusion is tricky. An
+# event could be absent because our exclusion mechanism works but also because
+# the event was not generate in the first place. This function test the ability
+# of our test suite to generate events.
+function dry_run
+{
+       local trace_path=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
+
+       # Create session
+       create_lttng_session_ok $SESSION_NAME $trace_path
+
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $SESSION_NAME > /dev/null
+       ok $? "Enabling events without exclusion"
+
+       # Trace apps
+       start_lttng_tracing_ok $SESSION_NAME
+       run_apps
+       stop_lttng_tracing_ok $SESSION_NAME
+
+       nb_events=$(babeltrace $trace_path | wc -l)
+       if [ "$nb_events" -ne "0" ]; then
+               ok 0 "Events were found during the dry run without exclusion"
+       else
+               fail "No events were found during the dry run without exclusion"
+       fi
+
+       rm -rf $trace_path
+
+       # Destroy session
+       destroy_lttng_session_ok $SESSION_NAME
 }
 
 function test_exclusion
 {
-       exclusions="$1"
-       event_name_expected_to_be_missing="$2"
-       trace_path=$(mktemp -d)
+       local exclusions="$1"
+       local event_name_expected_to_be_missing="$2"
+       local trace_path=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
 
        # Create session
        create_lttng_session_ok $SESSION_NAME $trace_path
@@ -63,7 +86,60 @@ function test_exclusion
        # Destroy session
        destroy_lttng_session_ok $SESSION_NAME
 
-       stats=`babeltrace $trace_path | $STATS_BIN --tracepoint "$event_name_expected_to_be_missing" | grep -v index`
+       stats=`babeltrace $trace_path | $STATS_BIN --tracepoint "$event_name_expected_to_be_missing" | grep -v index 2> /dev/null`
+       if [ ! -z "$stats" ]; then
+               fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
+       else
+               ok 0 "Validate trace exclusion output"
+               rm -rf $trace_path
+       fi
+}
+
+function test_exclusion_tracing_started
+{
+       local exclusions="$1"
+       local event_name_expected_to_be_missing="$2"
+       local trace_path=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
+       local file_wait_before_first=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_first.XXXXXX")
+       local file_create_in_main=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_create_in_main.XXXXXX")
+
+       # Create session
+       create_lttng_session_ok $SESSION_NAME $trace_path
+
+       # Enable a dummy event so that the session is active after we start the
+       # session.
+       enable_ust_lttng_event_ok $SESSION_NAME "non-existent-event"
+
+       # Start the tracing
+       start_lttng_tracing_ok $SESSION_NAME
+
+       # Launch the test app and make it create a sync file once it's in the
+       # main function.
+       $TESTAPP_BIN -i 1 -w 10000 \
+               --create-in-main ${file_create_in_main} \
+               --wait-before-first-event ${file_wait_before_first} 2>&1 &
+
+       while [ ! -f "${file_create_in_main}" ]; do
+               sleep 0.5
+       done
+
+       # Enable an event with an exclusion once the tracing is active in the
+       # UST app.
+       enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
+       ok $? "Enable lttng event with event \"$exclusions\" excluded"
+
+       # Create the sync file so that the test app starts generating events.
+       touch ${file_wait_before_first}
+
+       # Wait for the testapp to finish.
+       wait
+
+       stop_lttng_tracing_ok $SESSION_NAME
+
+       # Destroy session
+       destroy_lttng_session_ok $SESSION_NAME
+
+       stats=$(babeltrace $trace_path | $STATS_BIN --tracepoint "$event_name_expected_to_be_missing" | grep -v index 2> /dev/null)
        if [ ! -z "$stats" ]; then
                fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
        else
@@ -93,10 +169,14 @@ function test_exclusion_fail
 
 plan_tests $NUM_TESTS
 
-print_test_banner $TEST_DESC
+print_test_banner "$TEST_DESC"
 
 start_lttng_sessiond
 
+diag "Enable event without exclusion"
+dry_run
+
+diag "Enable event with exclusion"
 test_exclusion 'tp:tptest2' 'tp:tptest2'
 test_exclusion 'tp:tptest3' 'tp:tptest3'
 test_exclusion 'tp:tptest*' 'tp:tptest1'
@@ -120,12 +200,14 @@ test_exclusion '*3' 'tp:tptest3'
 test_exclusion 'tp*test3,*2' 'tp:tptest2'
 test_exclusion '**tp*test3,*2' 'tp:tptest3'
 
-# Cannot use exclusions with non-globbing event name
+test_exclusion_tracing_started 'tp:tptest1' 'tp:tptest1'
+
+diag "Cannot use exclusions with non-globbing event name"
 test_exclusion_fail "allo" "lol"
 test_exclusion_fail "allo" "meow,lol"
 test_exclusion_fail "allo" "z*em"
 
-# Exclusion name excludes all possible event names
+diag "Exclusion name excludes all possible event names"
 test_exclusion_fail "allo*" "all*"
 test_exclusion_fail "allo*" "ze,all*,yes"
 
This page took 0.027 seconds and 4 git commands to generate.