File: test_notification_multi_app

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 (438 lines) | stat: -rwxr-xr-x 11,527 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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#!/bin/bash
#
# SPDX-FileCopyrightText: 2017 Jonathan Rajotte <jonathan.rajotte-julien@efficiso.com>>
#
# SPDX-License-Identifier: LGPL-2.1-only

TEST_DESC="Notification"

CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/../../../

TESTPOINT=$(readlink -f ${CURDIR}/.libs/libpause_consumer.so)

TESTAPP_PATH="$TESTDIR/utils/testapp"
TESTAPP_NAME="gen-ust-events"
TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
TESTAPP_STATE_FILE="$(mktemp -u -t tmp.test_notification_multi_app_state_file.XXXXXX)"

NR_ITER=1000
NR_USEC_WAIT=5

SESSION_NAME="my_session"
CHANNEL_NAME="my_channel"


DIR=$(readlink -f $TESTDIR)

PAGE_SIZE=$(getconf PAGE_SIZE)

NUM_TEST_UST=50
NUM_TEST_KERNEL=50
NUM_TESTS=$(($NUM_TEST_UST + $NUM_TEST_KERNEL))

source $TESTDIR/utils/utils.sh
source $CURDIR/util_event_generator.sh

consumerd_pipe=()
file_sync_after_first_event=$(mktemp -u -t tmp.test_notification_multi_app_sync_after_first.XXXXXX)

# MUST set TESTDIR before calling those functions
plan_tests $NUM_TESTS

print_test_banner "$TEST_DESC"

app_pids=()

function start_client {
	local pid=-1
	local output_file=$1
	local session_name=$2
	local channel_name=$3
	local domain_type=$4
	local buffer_usage_type=$5
	local buffer_usage_threshold_type=$6
	local buffer_usage_threshold_value=$7
	local nr_expected_notification=$8
	local use_action_list=$9

	${CURDIR}/base_client ${session_name} ${channel_name} ${domain_type} ${buffer_usage_type} ${buffer_usage_threshold_type} ${buffer_usage_threshold_value} ${nr_expected_notification} ${use_action_list} > ${output_file} &
	pid=$!

	app_pids+=("$pid")
}

function wait_for_message ()
{
	local directory=$1
	local file_pattern=$2
	local message=$3

	for file in $directory/${file_pattern}*; do
		while(true); do
			# Check for "error" message
			grep -q "error:" ${file}
			app_error=$?
			if [ $app_error -eq "0" ] ; then
				# An error occurred
				fail "Waiting message: error logged see file content: ${message}, ${file}"
				return 1
			fi

			grep -q "${message}" ${file}
			if [[ "$?" -ne "0" ]]; then
				# Lookup failed restart loop
				diag "Lookup failed sleep and retry grep for: ${message}, ${file}"
				sleep 0.25
				continue
			fi
			break
		done
	done
	pass "Message received: ${message}"
	return 0
}

function print_errors ()
{
	local directory=$1
	local file_pattern=$2

	for file in $directory/${file_pattern}*; do
		# Check for "error" message
		error_message=$(grep "error:" ${file})
		if [[ "${error_message}x" != "x" ]]; then
			diag "Errors for application ${file}:"
			diag "${error_message}"
		fi
	done
}

function comm_consumerd ()
{
	local message=$1
	local pipe=$2
	echo -ne "${message}" > "${pipe}"
}

function stop_consumerd ()
{
	local pipe=$1
	comm_consumerd "1" "$pipe"
}

function resume_consumerd ()
{
	local pipe=$1
	comm_consumerd "\0" "$pipe"
}

function test_multi_app ()
{
	local domain_type=$1
	local event_generator_pid=$2

	local app_pids=()
	local low_output_file_pattern="low_app_output_file_"
	local high_output_file_pattern="high_app_output_file_"
	local output_dir=$(mktemp -d -t "tmp.test_${FUNCNAME[0]}_output_dir.XXXXXX")

	local testpoint_base_path=$(readlink -f "$output_dir/lttng.t_p_n_multi_app")
	local testpoint_pipe_path=$(TMPDIR="$output_dir" mktemp -u -t "lttng.t_p_n_multi_app.XXXXXX")

	local nr_notification_expected=5
	local nr_client_app=50
	local domain_string=""
	local event_name=""

	case $domain_type in
		ust)
			domain_string=LTTNG_DOMAIN_UST
			event_name="tp:tptest"
			;;
		kernel)
			domain_string=LTTNG_DOMAIN_KERNEL
			event_name="lttng_test_filter_event"
			;;
		*)
			fail "Invalid domain type"
			exit 1
			;;
	esac

	# Setup
	LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
	start_lttng_sessiond

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH
	enable_${domain_type}_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
	enable_${domain_type}_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME

	# Fetch consumerd testpoint pipe information
	# This is needed since the testpoint create a pipe with the consumer type suffixed
	consumerd_pipe=()
	for f in "$testpoint_pipe_path"*; do
		consumerd_pipe+=("$f")
	done

	for (( i = 0; i < $nr_client_app; i++ )); do
		low_app_output_file=$output_dir/${low_output_file_pattern}${i}
		high_app_output_file=$output_dir/${high_output_file_pattern}${i}
		start_client $low_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string LOW RATIO 0.0 $nr_notification_expected $(( $i % 2))
		start_client $high_app_output_file $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 $nr_notification_expected $(( $i % 2))
	done

	wait_for_message $output_dir "${low_output_file_pattern}" "sync: ready"
	wait_for_message $output_dir "${high_output_file_pattern}" "sync: ready"

	# Test notification reception
	for (( i = 0; i < $nr_notification_expected; i++ )); do

		# Stop consumerd consumption to force high notification
		start_lttng_tracing_ok $SESSION_NAME
		for pipe in "${consumerd_pipe[@]}"; do
			stop_consumerd "${pipe}"
		done

		wait_for_message $output_dir "${high_output_file_pattern}" "notification: high $i"

		# Put application in suspend mode to prevent double low
		# notification and synchronize on state file.
		kill -s SIGUSR1 $event_generator_pid
		while [ ! -f "${TESTAPP_STATE_FILE}" ]; do
			sleep 0.5
		done

		# Resume consumerd
		for pipe in "${consumerd_pipe[@]}"; do
			resume_consumerd "${pipe}"
		done
		# Stop tracing forcing full buffer consumption
		stop_lttng_tracing_ok $SESSION_NAME

		# Check for notifications reception
		wait_for_message $output_dir "${low_output_file_pattern}" "notification: low $i"
		ret=$?
		ok $ret "Notifications $i received"
		if [[ $ret -ne "0" ]]; then
			# Error occurred bail out
			break;
		fi

		# Put application in active mode and synchronize on state file.
		kill -s SIGUSR1 $event_generator_pid
		while [ -f "${TESTAPP_STATE_FILE}" ]; do
			sleep 0.5
		done
	done

	wait_for_message $output_dir "${low_output_file_pattern}" "exit: 0"
	ret=$?
	ok $ret "Application for low notification terminated normally"
	if [[ $ret -ne "0" ]]; then
		print_errors $output_dir "${low_output_file_pattern}"
	fi

	wait_for_message $output_dir "${high_output_file_pattern}" "exit: 0"
	ret=$?
	ok $ret "Application for high notification terminated normally"
	if [[ $ret -ne "0" ]]; then
		print_errors $output_dir "${high_output_file_pattern}"
	fi


	destroy_lttng_session_ok $SESSION_NAME
	stop_lttng_sessiond

	for pipe in "${consumerd_pipe[@]}"; do
		rm -rf "${pipe}"
	done

	rm -rf $output_dir
}

function test_multi_app_ust ()
{
	diag "Multi client app UST notification"
	ust_event_generator "$TESTAPP_BIN" "$TESTAPP_STATE_FILE" &
	local generator_pid=$!

	test_multi_app ust $generator_pid

	kill -s SIGUSR2 $generator_pid 2> /dev/null
	wait $generator_pid 2> /dev/null
	rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null
}

function test_multi_app_kernel ()
{
	diag "Multi client app kernel notification"
	modprobe lttng-test

	kernel_event_generator generate_filter_events $TESTAPP_STATE_FILE &
	local generator_pid=$!

	test_multi_app kernel $generator_pid


	kill -s SIGUSR2 $generator_pid 2> /dev/null
	wait $generator_pid 2> /dev/null
	rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null

	modprobe --remove lttng-test
}

function test_on_register_evaluation_ust ()
{
	diag "On register notification UST"

	# Start app in infinite loop
	ust_event_generator "$TESTAPP_BIN" "$TESTAPP_STATE_FILE" &
	local generator_pid=$!

	test_on_register_evaluation ust $generator_pid

	kill -s SIGUSR2 $generator_pid 2> /dev/null
	wait $generator_pid 2> /dev/null
	rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null

}

function test_on_register_evaluation_kernel()
{
	diag "On register notification kernel"

	modprobe lttng-test

	kernel_event_generator generate_filter_events $TESTAPP_STATE_FILE &
	local generator_pid=$!

	test_on_register_evaluation kernel $generator_pid


	kill -s SIGUSR2 $generator_pid 2> /dev/null
	wait $generator_pid 2> /dev/null
	rm -rf ${TESTAPP_STATE_FILE} 2> /dev/null

	modprobe --remove lttng-test
}

function test_on_register_evaluation ()
{
	local domain_type=$1
	local event_generator_pid=$2

	local app_pids=()
	local high_output_file_pattern="high_app_output_file_on_register_evaluation"

	local output_dir=$(mktemp -d -t "tmp.test_${FUNCNAME[0]}_output_dir.XXXXXX")
	local testpoint_base_path=$(readlink -f "$output_dir/lttng.t_p_n_register_evaluation")
	local testpoint_pipe_path=$(TMPDIR="$output_dir" mktemp -u -t "lttng.t_p_n_register_evaluation.XXXXXX")
	local domain_string=""
	local event_name=""

	case $domain_type in
		ust)
			domain_string=LTTNG_DOMAIN_UST
			event_name="tp:tptest"
			;;
		kernel)
			domain_string=LTTNG_DOMAIN_KERNEL
			event_name="lttng_test_filter_event"
			;;
		*)
			fail "Invalid domain type"
			exit 1
			;;
	esac

	# Setup
	LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 CONSUMER_PAUSE_PIPE_PATH=${testpoint_pipe_path} LD_PRELOAD=${TESTPOINT}"
	start_lttng_sessiond

	create_lttng_session_ok $SESSION_NAME $TRACE_PATH
	enable_${domain_type}_lttng_channel_ok $SESSION_NAME $CHANNEL_NAME --subbuf-size=$PAGE_SIZE
	enable_${domain_type}_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME

	# Fetch consumerd testpoint pipe information
	# This is needed since the testpoint create a pipe with the consumer type suffixed
	consumerd_pipe=()
	for f in "$testpoint_pipe_path"*; do
		consumerd_pipe+=("$f")
	done

	high_app_output_file=${high_output_file_pattern}.first_receiver
	high_app_output_path=$output_dir/${high_app_output_file}
	start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1 0

	wait_for_message $output_dir "${high_app_output_file}" "sync: ready"

	# Stop consumerd consumption to force high notification
	start_lttng_tracing_ok $SESSION_NAME

	for pipe in "${consumerd_pipe[@]}"; do
		stop_consumerd "${pipe}"
	done

	wait_for_message $output_dir "${high_app_output_file}" "notification: high 0"

	# Start a second receiver, the receiver should receive a high
	# notification on subscription
	high_app_output_file=${high_output_file_pattern}.second_receiver
	high_app_output_path=$output_dir/${high_app_output_file}
	start_client $high_app_output_path $SESSION_NAME $CHANNEL_NAME $domain_string HIGH RATIO 0.420 1 0
	wait_for_message $output_dir "${high_app_output_file}" "sync: ready"
	wait_for_message $output_dir "${high_app_output_file}" "notification: high 0"

	# Resume consumerd
	for pipe in "${consumerd_pipe[@]}"; do
		resume_consumerd "${pipe}"
	done

	wait_for_message $output_dir "${high_output_file_pattern}" "exit: 0"
	ret=$?
	ok $ret "Application for high notification terminated normally"
	if [[ $ret -ne "0" ]]; then
		# Keep the file
		print_errors "${high_output_file_pattern}"
	fi


	destroy_lttng_session_ok $SESSION_NAME
	stop_lttng_sessiond

	kill -s SIGUSR2 $generator_pid 2> /dev/null
	wait $generator_pid 2> /dev/null

	for pipe in "${consumerd_pipe[@]}"; do
		rm -rf "${pipe}"
	done

	rm -rf "$output_dir"
}

TESTS=(
	test_multi_app_ust
	test_on_register_evaluation_ust
)

check_skip_kernel_test "$NUM_TEST_KERNEL" "Skipping kernel multi-app notification tests." || {
	validate_lttng_modules_present
	TESTS+=(
		test_multi_app_kernel
		test_on_register_evaluation_kernel
	)
}

for fct_test in ${TESTS[@]};
do
	TRACE_PATH=$(mktemp -d -t tmp.test_notification_multi_app_trace_path.XXXXXX)

	${fct_test}
	if [ $? -ne 0 ]; then
		break;
	fi

	# Only delete if successful
	rm -rf $TRACE_PATH
done