Tests: add hidden trigger visibility test
[lttng-tools.git] / tests / regression / tools / exclusion / test_exclusion
CommitLineData
345121ec
DG
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
345121ec 4#
9d16b343 5# SPDX-License-Identifier: GPL-2.0-only
345121ec 6#
345121ec
DG
7
8TEST_DESC="Event exclusion"
9
10CURDIR=$(dirname $0)/
11TESTDIR=$CURDIR/../../..
345121ec
DG
12STATS_BIN="$TESTDIR/utils/babelstats.pl"
13SESSION_NAME="test-exclusion"
345121ec
DG
14TESTAPP_PATH="$TESTDIR/utils/testapp"
15TESTAPP_NAME="gen-ust-nevents"
16TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17NR_ITER=100
18NR_USEC_WAIT=1
e4598313 19NUM_TESTS=185
345121ec
DG
20
21source $TESTDIR/utils/utils.sh
22
23function enable_ust_lttng_all_event_exclusion()
24{
25 sess_name="$1"
26 exclusion="$2"
27
a0e115d5 28 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $sess_name -x "$exclusion" > /dev/null
345121ec
DG
29}
30
31function run_apps
32{
8db430e7 33 $TESTAPP_BIN --iter $NR_ITER --wait $NR_USEC_WAIT >/dev/null 2>&1
afa7d3f1
FD
34 ok $? "Running test application"
35}
36
37# Testing for the absence of an event when testing exclusion is tricky. An
38# event could be absent because our exclusion mechanism works but also because
39# the event was not generate in the first place. This function test the ability
40# of our test suite to generate events.
41function dry_run
42{
33e55711 43 local trace_path=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
afa7d3f1
FD
44
45 # Create session
46 create_lttng_session_ok $SESSION_NAME $trace_path
47
48 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "tp:*" -s $SESSION_NAME > /dev/null
49 ok $? "Enabling events without exclusion"
50
51 # Trace apps
52 start_lttng_tracing_ok $SESSION_NAME
53 run_apps
54 stop_lttng_tracing_ok $SESSION_NAME
55
56 nb_events=$(babeltrace $trace_path | wc -l)
57 if [ "$nb_events" -ne "0" ]; then
58 ok 0 "Events were found during the dry run without exclusion"
59 else
60 fail "No events were found during the dry run without exclusion"
61 fi
62
63 rm -rf $trace_path
64
65 # Destroy session
66 destroy_lttng_session_ok $SESSION_NAME
345121ec
DG
67}
68
69function test_exclusion
70{
33e55711
FD
71 local exclusions="$1"
72 local event_name_expected_to_be_missing="$2"
73 local trace_path=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
345121ec
DG
74
75 # Create session
bf6ae429 76 create_lttng_session_ok $SESSION_NAME $trace_path
345121ec 77
062f6132
PP
78 enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
79 ok $? "Enable lttng event with event \"$exclusions\" excluded"
345121ec
DG
80
81 # Trace apps
e563bbdb 82 start_lttng_tracing_ok $SESSION_NAME
345121ec 83 run_apps
96340a01 84 stop_lttng_tracing_ok $SESSION_NAME
345121ec
DG
85
86 # Destroy session
67b4c664 87 destroy_lttng_session_ok $SESSION_NAME
345121ec 88
afa7d3f1 89 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint "$event_name_expected_to_be_missing" | grep -v index 2> /dev/null`
345121ec 90 if [ ! -z "$stats" ]; then
062f6132 91 fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
345121ec
DG
92 else
93 ok 0 "Validate trace exclusion output"
94 rm -rf $trace_path
95 fi
96}
97
e4598313
FD
98function test_exclusion_tracing_started
99{
100 local exclusions="$1"
101 local event_name_expected_to_be_missing="$2"
33e55711
FD
102 local trace_path=$(mktemp --tmpdir -d "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
103 local file_wait_before_first=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_before_first.XXXXXX")
104 local file_create_in_main=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_sync_create_in_main.XXXXXX")
e4598313
FD
105
106 # Create session
107 create_lttng_session_ok $SESSION_NAME $trace_path
108
109 # Enable a dummy event so that the session is active after we start the
110 # session.
111 enable_ust_lttng_event_ok $SESSION_NAME "non-existent-event"
112
113 # Start the tracing
114 start_lttng_tracing_ok $SESSION_NAME
115
116 # Launch the test app and make it create a sync file once it's in the
117 # main function.
118 $TESTAPP_BIN -i 1 -w 10000 \
119 --create-in-main ${file_create_in_main} \
120 --wait-before-first-event ${file_wait_before_first} 2>&1 &
121
122 while [ ! -f "${file_create_in_main}" ]; do
123 sleep 0.5
124 done
125
126 # Enable an event with an exclusion once the tracing is active in the
127 # UST app.
128 enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
129 ok $? "Enable lttng event with event \"$exclusions\" excluded"
130
131 # Create the sync file so that the test app starts generating events.
132 touch ${file_wait_before_first}
133
134 # Wait for the testapp to finish.
135 wait
136
137 stop_lttng_tracing_ok $SESSION_NAME
138
139 # Destroy session
140 destroy_lttng_session_ok $SESSION_NAME
141
142 stats=$(babeltrace $trace_path | $STATS_BIN --tracepoint "$event_name_expected_to_be_missing" | grep -v index 2> /dev/null)
143 if [ ! -z "$stats" ]; then
144 fail "Excluded event \"$event_name_expected_to_be_missing\" was found in trace!"
145 else
146 ok 0 "Validate trace exclusion output"
147 rm -rf $trace_path
148 fi
0d0386e0
FD
149
150 rm -f $file_wait_before_first
151 rm -f $file_create_in_main
e4598313
FD
152}
153
062f6132
PP
154function test_exclusion_fail
155{
156 event_name="$1"
157 exclusions="$2"
158
159 create_lttng_session_ok $SESSION_NAME $trace_path
6efba076 160 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event -u "$event_name" -s $sess_name -x "$exclusions" >/dev/null 2>&1
062f6132
PP
161 res=$?
162 destroy_lttng_session_ok $SESSION_NAME
163
164 if [ $res -eq 0 ]; then
165 fail "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" passes"
166 return 1
167 else
168 pass "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" fails"
169 return 0
170 fi
171}
172
345121ec
DG
173plan_tests $NUM_TESTS
174
a0e115d5 175print_test_banner "$TEST_DESC"
345121ec
DG
176
177start_lttng_sessiond
178
a0e115d5 179diag "Enable event without exclusion"
afa7d3f1
FD
180dry_run
181
a0e115d5 182diag "Enable event with exclusion"
062f6132
PP
183test_exclusion 'tp:tptest2' 'tp:tptest2'
184test_exclusion 'tp:tptest3' 'tp:tptest3'
185test_exclusion 'tp:tptest*' 'tp:tptest1'
186test_exclusion 'tp:tptest*' 'tp:tptest2'
187test_exclusion 'tp:tptest*' 'tp:tptest3'
188test_exclusion 'tp:tptest*' 'tp:tptest4'
189test_exclusion 'tp:tptest*' 'tp:tptest5'
190test_exclusion 'tp*tptest*' 'tp:tptest1'
191test_exclusion 'tp*tptest*' 'tp:tptest2'
192test_exclusion 'tp*tptest*' 'tp:tptest3'
193test_exclusion 'tp*tptest*' 'tp:tptest4'
194test_exclusion 'tp*tptest*' 'tp:tptest5'
195test_exclusion '*test2' 'tp:tptest2'
196test_exclusion '*test5' 'tp:tptest5'
197test_exclusion '*p*test*' 'tp:tptest1'
198test_exclusion '*p*test*' 'tp:tptest2'
199test_exclusion '*p*test*' 'tp:tptest3'
200test_exclusion '*p***test*' 'tp:tptest4'
201test_exclusion '*p*test*' 'tp:tptest5'
202test_exclusion '*3' 'tp:tptest3'
203test_exclusion 'tp*test3,*2' 'tp:tptest2'
204test_exclusion '**tp*test3,*2' 'tp:tptest3'
205
e4598313
FD
206test_exclusion_tracing_started 'tp:tptest1' 'tp:tptest1'
207
a0e115d5 208diag "Cannot use exclusions with non-globbing event name"
062f6132
PP
209test_exclusion_fail "allo" "lol"
210test_exclusion_fail "allo" "meow,lol"
211test_exclusion_fail "allo" "z*em"
212
a0e115d5 213diag "Exclusion name excludes all possible event names"
062f6132
PP
214test_exclusion_fail "allo*" "all*"
215test_exclusion_fail "allo*" "ze,all*,yes"
345121ec
DG
216
217stop_lttng_sessiond
This page took 0.049203 seconds and 4 git commands to generate.