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