File: test_exclusion

package info (click to toggle)
ltt-control 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,860 kB
  • sloc: cpp: 192,012; sh: 28,777; ansic: 10,960; python: 7,108; makefile: 3,520; java: 109; xml: 46
file content (228 lines) | stat: -rwxr-xr-x 6,743 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
#
# SPDX-FileCopyrightText: 2012 Christian Babeux <christian.babeux@efficios.com>
#
# SPDX-License-Identifier: GPL-2.0-only
#

TEST_DESC="Event exclusion"

CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/../../..
BT2_PLUGINS_DIR="${TESTDIR}/utils/bt2_plugins"

SESSION_NAME="test-exclusion"
TESTAPP_PATH="$TESTDIR/utils/testapp"
TESTAPP_NAME="gen-ust-nevents"
TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
NR_ITER=100
NR_USEC_WAIT=1
NUM_TESTS=185

source $TESTDIR/utils/utils.sh

function enable_ust_lttng_all_event_exclusion()
{
	sess_name="$1"
	exclusion="$2"

	_run_lttng_cmd "$(lttng_client_log_file)" "$(lttng_client_err_file)" \
		enable-event --userspace "tp:*" --session "$sess_name" \
		--exclude "$exclusion"
}

function run_apps
{
	$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 -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")

	# Create session
	create_lttng_session_ok $SESSION_NAME $trace_path

	_run_lttng_cmd "$(lttng_client_log_file)" "$(lttng_client_err_file)" \
		enable-event --userspace "tp:*" --session "$SESSION_NAME"
	ok $? "Enabling events without exclusion"

	# Trace apps
	start_lttng_tracing_ok $SESSION_NAME
	run_apps
	stop_lttng_tracing_ok $SESSION_NAME

	nb_events=$("_run_babeltrace_cmd" $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
{
	local exclusions="$1"
	local event_name_expected_to_be_missing="$2"
	local trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")

	# Create session
	create_lttng_session_ok $SESSION_NAME $trace_path

	enable_ust_lttng_all_event_exclusion $SESSION_NAME "$exclusions"
	ok $? "Enable lttng event with event \"$exclusions\" excluded"

	# Trace apps
	start_lttng_tracing_ok $SESSION_NAME
	run_apps
	stop_lttng_tracing_ok $SESSION_NAME

	# Destroy session
	destroy_lttng_session_ok $SESSION_NAME

	stats=$("_run_babeltrace_cmd" --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)
	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 -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX")
	local file_wait_before_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_first.XXXXXX")
	local file_create_in_main=$(mktemp -u -t "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 &
	tracee_pids+=("${!}")

	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 "${tracee_pids[@]}"
	tracee_pids=()

	stop_lttng_tracing_ok $SESSION_NAME

	# Destroy session
	destroy_lttng_session_ok $SESSION_NAME

	stats=$("_run_babeltrace_cmd" --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)
	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

	rm -f $file_wait_before_first
	rm -f $file_create_in_main
}

function test_exclusion_fail
{
	event_name="$1"
	exclusions="$2"

	create_lttng_session_ok $SESSION_NAME $trace_path
	_run_lttng_cmd "$(lttng_client_log_file)" "$(lttng_client_err_file)" \
		enable-event --userspace "$event_name" --session "$sess_name" \
		--exclude "$exclusions"
	res=$?
	destroy_lttng_session_ok $SESSION_NAME

	if [ $res -eq 0 ]; then
		fail "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" passes"
		return 1
	else
		pass "Enable LTTng event \"$event_name\" with exclusion \"$exclusions\" fails"
		return 0
	fi
}

plan_tests $NUM_TESTS

print_test_banner "$TEST_DESC"

bail_out_if_no_babeltrace

start_lttng_sessiond
tracee_pids=()

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'
test_exclusion 'tp:tptest*' 'tp:tptest2'
test_exclusion 'tp:tptest*' 'tp:tptest3'
test_exclusion 'tp:tptest*' 'tp:tptest4'
test_exclusion 'tp:tptest*' 'tp:tptest5'
test_exclusion 'tp*tptest*' 'tp:tptest1'
test_exclusion 'tp*tptest*' 'tp:tptest2'
test_exclusion 'tp*tptest*' 'tp:tptest3'
test_exclusion 'tp*tptest*' 'tp:tptest4'
test_exclusion 'tp*tptest*' 'tp:tptest5'
test_exclusion '*test2' 'tp:tptest2'
test_exclusion '*test5' 'tp:tptest5'
test_exclusion '*p*test*' 'tp:tptest1'
test_exclusion '*p*test*' 'tp:tptest2'
test_exclusion '*p*test*' 'tp:tptest3'
test_exclusion '*p***test*' 'tp:tptest4'
test_exclusion '*p*test*' 'tp:tptest5'
test_exclusion '*3' 'tp:tptest3'
test_exclusion 'tp*test3,*2' 'tp:tptest2'
test_exclusion '**tp*test3,*2' 'tp:tptest3'

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"

diag "Exclusion name excludes all possible event names"
test_exclusion_fail "allo*" "all*"
test_exclusion_fail "allo*" "ze,all*,yes"

stop_lttng_sessiond