File: test_agent_log4j2_domain_log4j

package info (click to toggle)
ltt-control 2.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • 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 (595 lines) | stat: -rwxr-xr-x 19,615 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
#!/bin/bash
#
# SPDX-FileCopyrightText: 2014 David Goulet <dgoulet@efficios.com>
# SPDX-FileCopyrightText: 2022 EfficiOS Inc.
#
# SPDX-License-Identifier: GPL-2.0-only

TEST_DESC="Java LOG4J 2.x Agent tests with 'log4j' domain"

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

NR_ITER=6
NR_MSEC_WAIT=100

TESTAPP_NAME="JTestLTTngLog4j2"
TESTAPP_PATH="$CURDIR/$TESTAPP_NAME"

EVENT_NAME_BASE="log4j2-event"
EVENT_NAME1="$EVENT_NAME_BASE-1"
EVENT_NAME2="$EVENT_NAME_BASE-2"

JAVA_CP="$CURDIR:$CLASSPATH"

NUM_TESTS=196

# shellcheck source=../../../utils/utils.sh
source "$TESTDIR/utils/utils.sh"

function run_app
{
	local debug_tp=$1
	local fire_second_tp=$2

	if [ "$debug_tp" = "" ]; then
		debug_tp=0
	fi

	if [ "$fire_second_tp" = "" ]; then
		fire_second_tp=0
	fi

	# FIXME: test app should have synchro.
	diag "java -cp $JAVA_CP -Dlog4j2.configurationFile=\"domain-log4j.xml\" -Djava.library.path=\"$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib\" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT $debug_tp $fire_second_tp"
	java -cp "$JAVA_CP"  -Dlog4j2.configurationFile="domain-log4j.xml" -Djava.library.path="$LD_LIBRARY_PATH:/usr/local/lib:/usr/lib" $TESTAPP_NAME $NR_ITER $NR_MSEC_WAIT "$debug_tp" "$fire_second_tp" >/dev/null 2>&1
}

function run_app_background
{
	run_app "${@}" &
	tracee_pids+=("${!}")
}


# MUST set TESTDIR before calling those functions

function test_log4j2_before_start ()
{
	local file_sync_after_first
	local file_sync_before_last

	file_sync_after_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
	file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")

	diag "Test LOG4J2 application BEFORE tracing starts"
	create_lttng_session_ok "log4j2_before_start" "$TRACE_PATH"
	enable_log4j_lttng_event "log4j2_before_start" $EVENT_NAME1

	# Run 6 times with a 100ms delay
	run_app_background

	start_lttng_tracing_ok "log4j2_before_start"

	touch "${file_sync_before_last}"

	# Wait for the applications started in background
	wait "${tracee_pids[@]}"
	tracee_pids=()

	stop_lttng_tracing_ok "log4j2_before_start"
	destroy_lttng_session_ok "log4j2_before_start"

	rm -f "${file_sync_after_first}"
	rm -f "${file_sync_before_last}"

	# Validate test. Expecting all events.
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH"
}

function test_log4j2_after_start ()
{
	diag "Test LOG4J2 application AFTER tracing starts"

	create_lttng_session_ok "log4j2_after_start" "$TRACE_PATH"
	enable_log4j_lttng_event "log4j2_after_start" $EVENT_NAME1
	start_lttng_tracing_ok "log4j2_after_start"

	# Run 6 times with a 100ms delay
	run_app

	stop_lttng_tracing_ok "log4j2_after_start"
	destroy_lttng_session_ok "log4j2_after_start"

	# Validate test. Expecting all events.
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH"
}

function test_log4j2_loglevel ()
{
	diag "Test LOG4J2 application with loglevel"

	create_lttng_session_ok "log4j2_loglevel_info" "$TRACE_PATH"
	enable_log4j_lttng_event_loglevel "log4j2_loglevel_info" $EVENT_NAME1 "LOG4J_INFO"
	start_lttng_tracing_ok "log4j2_loglevel_info"

	# Run 6 times with a 1ms delay
	run_app

	stop_lttng_tracing_ok "log4j2_loglevel_info"
	destroy_lttng_session_ok "log4j2_loglevel_info"

	# Validate test. Expecting all events.
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH"

	diag "Test LOG4J2 applications with lower loglevel"

	create_lttng_session_ok "log4j2_loglevel_fatal" "$TRACE_PATH"
	enable_log4j_lttng_event_loglevel "log4j2_loglevel_fatal" $EVENT_NAME1 "LOG4J_FATAL"
	start_lttng_tracing_ok "log4j2_loglevel_fatal"

	# Run 6 times with a 1ms delay
	run_app

	stop_lttng_tracing_ok "log4j2_loglevel_fatal"
	destroy_lttng_session_ok "log4j2_loglevel_fatal"

	# Validate test. Expecting 0 events.
	trace_match_only $EVENT_NAME1 0 "$TRACE_PATH"

	diag "Test LOG4J2 applications with higher loglevel"

	create_lttng_session_ok "log4j2_loglevel_trace" "$TRACE_PATH"
	enable_log4j_lttng_event_loglevel "log4j2_loglevel_trace" $EVENT_NAME1 "LOG4J_TRACE"
	start_lttng_tracing_ok "log4j2_loglevel_trace"

	# Run 6 times with a 1ms delay
	run_app

	stop_lttng_tracing_ok "log4j2_loglevel_trace"
	destroy_lttng_session_ok "log4j2_loglevel_trace"

	# Validate test. Expecting all events.
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH"
}

function test_log4j2_loglevel_multiple ()
{
	diag "Test LOG4J2 application with multiple loglevel"

	create_lttng_session_ok "log4j2_loglevel_multiple" "$TRACE_PATH"
	enable_log4j_lttng_event_loglevel "log4j2_loglevel_multiple" $EVENT_NAME1 "LOG4J_INFO"
	enable_log4j_lttng_event_loglevel "log4j2_loglevel_multiple" $EVENT_NAME1 "LOG4J_DEBUG"
	start_lttng_tracing_ok "log4j2_loglevel_multiple"

	# Run 6 times with a 1ms delay and fire two TP.
	run_app 1

	stop_lttng_tracing_ok "log4j2_loglevel_multiple"
	destroy_lttng_session_ok "log4j2_loglevel_multiple"

	# Validate test. Expecting all events times two.
	trace_match_only $EVENT_NAME1 $((NR_ITER * 2)) "$TRACE_PATH"

	create_lttng_session_ok "log4j2_loglevel_multiple" "$TRACE_PATH"
	enable_log4j_lttng_event_loglevel "log4j2_loglevel_multiple" '*' "LOG4J_INFO"
	enable_log4j_lttng_event_loglevel "log4j2_loglevel_multiple" '*' "LOG4J_DEBUG"
	start_lttng_tracing_ok "log4j2_loglevel_multiple"

	# Run 6 times with a 1ms delay and fire two TP.
	run_app 1

	stop_lttng_tracing_ok "log4j2_loglevel_multiple"
	destroy_lttng_session_ok "log4j2_loglevel_multiple"

	# Validate test. Expecting all events times two.
	trace_match_only $EVENT_NAME1 $((NR_ITER * 2)) "$TRACE_PATH"
}

function test_log4j2_multi_session_loglevel()
{
	diag "Test LOG4J2 with multiple session"

	create_lttng_session_ok "log4j2_all_info" "$TRACE_PATH/log4j2_all_info"
	enable_log4j_lttng_event_loglevel_only "log4j2_all_info" '*' "LOG4J_INFO"
	start_lttng_tracing_ok "log4j2_all_info"

	create_lttng_session_ok "log4j2_all_debug" "$TRACE_PATH/log4j2_all_debug"
	enable_log4j_lttng_event_loglevel_only "log4j2_all_debug" '*' "LOG4J_DEBUG"
	start_lttng_tracing_ok "log4j2_all_debug"

	# Run 6 times with a 1ms delay and fire second TP.
	run_app 1 1

	stop_lttng_tracing_ok "log4j2_all_info"
	stop_lttng_tracing_ok "log4j2_all_debug"
	destroy_lttng_session_ok "log4j2_all_info"
	destroy_lttng_session_ok "log4j2_all_debug"

	# Expecting 7 events being the main event plus the second tp.
	trace_match_only $EVENT_NAME_BASE $((NR_ITER + 1)) "$TRACE_PATH/log4j2_all_info"

	# Expectin 6 events being the debug TP.
	trace_match_only $EVENT_NAME_BASE $NR_ITER "$TRACE_PATH/log4j2_all_debug"
}

function test_log4j2_multi_session_disable()
{
	diag "Test LOG4J2 with multiple session with disabled event"

	create_lttng_session_ok "log4j2_disabled_event" "$TRACE_PATH/log4j2_disabled_event"
	enable_log4j_lttng_event "log4j2_disabled_event" $EVENT_NAME1
	enable_log4j_lttng_event "log4j2_disabled_event" $EVENT_NAME2
	disable_log4j_lttng_event "log4j2_disabled_event" $EVENT_NAME1
	start_lttng_tracing_ok "log4j2_disabled_event"

	create_lttng_session_ok "log4j2_enabled_event" "$TRACE_PATH/log4j2_enabled_event"
	enable_log4j_lttng_event "log4j2_enabled_event" $EVENT_NAME2
	start_lttng_tracing_ok "log4j2_enabled_event"

	# Run 5 times with a 1ms delay and fire second TP.
	run_app 0 1

	stop_lttng_tracing_ok "log4j2_disabled_event"
	stop_lttng_tracing_ok "log4j2_enabled_event"
	destroy_lttng_session_ok "log4j2_disabled_event"
	destroy_lttng_session_ok "log4j2_enabled_event"

	# Validate test. Expecting one event of the second TP.
	trace_match_only $EVENT_NAME2 1 "$TRACE_PATH/log4j2_disabled_event"

	# Validate test. Expecting one event of the second TP.
	trace_match_only $EVENT_NAME2 1 "$TRACE_PATH/log4j2_enabled_event"
}

function test_log4j2_multi_session_disable_wildcard()
{
	diag "Test LOG4J2 with multiple session with disabled wildcard event"

	create_lttng_session_ok "log4j2_disabled_wildcard" "$TRACE_PATH/log4j2_disabled_wildcard"
	enable_log4j_lttng_event "log4j2_disabled_wildcard" '*'

	create_lttng_session_ok "log4j2_enabled_wildcard" "$TRACE_PATH/log4j2_enabled_wildcard"
	enable_log4j_lttng_event "log4j2_enabled_wildcard" '*'

	disable_log4j_lttng_event "log4j2_disabled_wildcard" '*'

	start_lttng_tracing_ok "log4j2_disabled_wildcard"
	start_lttng_tracing_ok "log4j2_enabled_wildcard"

	run_app

	stop_lttng_tracing_ok "log4j2_disabled_wildcard"
	stop_lttng_tracing_ok "log4j2_enabled_wildcard"
	destroy_lttng_session_ok "log4j2_disabled_wildcard"
	destroy_lttng_session_ok "log4j2_enabled_wildcard"

	# Validate test. Expecting NO event of the first TP.
	trace_match_only $EVENT_NAME_BASE 0 "$TRACE_PATH/log4j2_disabled_wildcard"

	# Validate test. Expecting all events of the first TP.
	trace_match_only $EVENT_NAME_BASE $NR_ITER "$TRACE_PATH/log4j2_enabled_wildcard"
}

function test_log4j2_multi_session_disable_wildcard_begin()
{
	ev_name='*-event-1'
	diag "Test LOG4J2 with multiple session with disabled wildcard (at the beginning) event"

	create_lttng_session_ok "log4j2_disabled_wildcard" "$TRACE_PATH/log4j2_disabled_wildcard"
	enable_log4j_lttng_event "log4j2_disabled_wildcard" "$ev_name"

	create_lttng_session_ok "log4j2_enabled_wildcard" "$TRACE_PATH/log4j2_enabled_wildcard"
	enable_log4j_lttng_event "log4j2_enabled_wildcard" "$ev_name"

	disable_log4j_lttng_event "log4j2_disabled_wildcard" "$ev_name"

	start_lttng_tracing_ok "log4j2_disabled_wildcard"
	start_lttng_tracing_ok "log4j2_enabled_wildcard"

	run_app 0 1

	stop_lttng_tracing_ok "log4j2_disabled_wildcard"
	stop_lttng_tracing_ok "log4j2_enabled_wildcard"
	destroy_lttng_session_ok "log4j2_disabled_wildcard"
	destroy_lttng_session_ok "log4j2_enabled_wildcard"

	# Validate test. Expecting NO event of the first TP.
	trace_match_only $EVENT_NAME1 0 "$TRACE_PATH/log4j2_disabled_wildcard"

	# Validate test. Expecting all events of the first TP.
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH/log4j2_enabled_wildcard"
}

function test_log4j2_multi_session_disable_wildcard_middle()
{
	ev_name='log*nt-1'
	diag "Test LOG4J2 with multiple session with disabled wildcard (at the middle) event"

	create_lttng_session_ok "log4j2_disabled_wildcard" "$TRACE_PATH/log4j2_disabled_wildcard"
	enable_log4j_lttng_event "log4j2_disabled_wildcard" "$ev_name"

	create_lttng_session_ok "log4j2_enabled_wildcard" "$TRACE_PATH/log4j2_enabled_wildcard"
	enable_log4j_lttng_event "log4j2_enabled_wildcard" "$ev_name"

	disable_log4j_lttng_event "log4j2_disabled_wildcard" "$ev_name"

	start_lttng_tracing_ok "log4j2_disabled_wildcard"
	start_lttng_tracing_ok "log4j2_enabled_wildcard"

	run_app 0 1

	stop_lttng_tracing_ok "log4j2_disabled_wildcard"
	stop_lttng_tracing_ok "log4j2_enabled_wildcard"
	destroy_lttng_session_ok "log4j2_disabled_wildcard"
	destroy_lttng_session_ok "log4j2_enabled_wildcard"

	# Validate test. Expecting NO event of the first TP.
	trace_match_only $EVENT_NAME1 0 "$TRACE_PATH/log4j2_disabled_wildcard"

	# Validate test. Expecting all events of the first TP.
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH/log4j2_enabled_wildcard"
}

function test_log4j2_multi_session_disable_wildcard_end()
{
	ev_name='log4j2-ev*'
	diag "Test LOG4J2 with multiple session with disabled wildcard (at the end) event"

	create_lttng_session_ok "log4j2_disabled_wildcard" "$TRACE_PATH/log4j2_disabled_wildcard"
	enable_log4j_lttng_event "log4j2_disabled_wildcard" "$ev_name"

	create_lttng_session_ok "log4j2_enabled_wildcard" "$TRACE_PATH/log4j2_enabled_wildcard"
	enable_log4j_lttng_event "log4j2_enabled_wildcard" "$ev_name"

	disable_log4j_lttng_event "log4j2_disabled_wildcard" "$ev_name"

	start_lttng_tracing_ok "log4j2_disabled_wildcard"
	start_lttng_tracing_ok "log4j2_enabled_wildcard"

	run_app 0 1

	stop_lttng_tracing_ok "log4j2_disabled_wildcard"
	stop_lttng_tracing_ok "log4j2_enabled_wildcard"
	destroy_lttng_session_ok "log4j2_disabled_wildcard"
	destroy_lttng_session_ok "log4j2_enabled_wildcard"

	# Validate test. Expecting NO event of the first TP.
	trace_match_only $EVENT_NAME_BASE 0 "$TRACE_PATH/log4j2_disabled_wildcard"

	# Validate test. Expecting all events of the first TP.
	trace_matches $EVENT_NAME_BASE $(( NR_ITER + 1 )) "$TRACE_PATH/log4j2_enabled_wildcard"

	trace_matches $EVENT_NAME2 1 "$TRACE_PATH/log4j2_enabled_wildcard"
}

function test_log4j2_disable_all()
{
	diag "Test LOG4J2 with multiple session with disabled all event"

	create_lttng_session_ok "log4j2_disable_all" "$TRACE_PATH/log4j2_disable_all"
	enable_log4j_lttng_event "log4j2_disable_all" '*'
	enable_log4j_lttng_event "log4j2_disable_all" $EVENT_NAME1
	enable_log4j_lttng_event "log4j2_disable_all" $EVENT_NAME2

	disable_log4j_lttng_event "log4j2_disable_all" -a

	start_lttng_tracing_ok "log4j2_disable_all"

	run_app 0 1

	stop_lttng_tracing_ok "log4j2_disable_all"
	destroy_lttng_session_ok "log4j2_disable_all"

	# Validate test. Expecting NO event of the first TP and second TP.
	trace_match_only $EVENT_NAME1 0 "$TRACE_PATH/log4j2_disable_all"
	trace_match_only $EVENT_NAME2 0 "$TRACE_PATH/log4j2_disable_all"
}

function test_log4j2_multi_session()
{
	diag "Test LOG4J2 with multiple session"

	create_lttng_session_ok "log4j2_multi_session_1" "$TRACE_PATH/log4j2_multi_session_1"
	enable_log4j_lttng_event "log4j2_multi_session_1" $EVENT_NAME1
	start_lttng_tracing_ok "log4j2_multi_session_1"

	create_lttng_session_ok "log4j2_multi_session_2" "$TRACE_PATH/log4j2_multi_session_2"
	enable_log4j_lttng_event "log4j2_multi_session_2" $EVENT_NAME2
	start_lttng_tracing_ok "log4j2_multi_session_2"

	# Run 5 times with a 1ms delay and fire second TP.
	run_app 0 1

	stop_lttng_tracing_ok "log4j2_multi_session_1"
	stop_lttng_tracing_ok "log4j2_multi_session_2"
	destroy_lttng_session_ok "log4j2_multi_session_1"
	destroy_lttng_session_ok "log4j2_multi_session_2"

	# Validate test. Expecting all events of first TP
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH/log4j2_multi_session_1"

	# Validate test. Expecting one event of the second TP.
	trace_match_only $EVENT_NAME2 1 "$TRACE_PATH/log4j2_multi_session_2"
}

function test_log4j2_destroy_session()
{
	diag "Test LOG4J2 two session with destroy"

	create_lttng_session_ok "log4j2_destroy_session" "$TRACE_PATH/first-sess"
	enable_log4j_lttng_event "log4j2_destroy_session" $EVENT_NAME1
	start_lttng_tracing_ok "log4j2_destroy_session"

	# Run 5 times with a 1ms delay
	run_app_background 0 1
	# Wait for the applications started in background
	wait "${tracee_pids[@]}"
	tracee_pids=()

	stop_lttng_tracing_ok "log4j2_destroy_session"
	destroy_lttng_session_ok "log4j2_destroy_session"

	# Validate test. Expecting at least one event num 1
	validate_trace $EVENT_NAME1 "$TRACE_PATH/first-sess"

	create_lttng_session_ok "log4j2_destroy_session" "$TRACE_PATH/second-sess"
	enable_log4j_lttng_event "log4j2_destroy_session" $EVENT_NAME2
	start_lttng_tracing_ok "log4j2_destroy_session"

	# Run 5 times with a 1ms delay
	run_app_background 0 1
	# Wait for the applications started in background
	wait "${tracee_pids[@]}"
	tracee_pids=()

	stop_lttng_tracing_ok "log4j2_destroy_session"
	destroy_lttng_session_ok "log4j2_destroy_session"

	# Validate test. Expecting only one event num 2
	trace_match_only $EVENT_NAME2 1 "$TRACE_PATH/second-sess"
}

function test_log4j2_filtering()
{
	diag "Test LOG4J2 filtering"

	create_lttng_session_ok "log4j2_filtering" "$TRACE_PATH/log4j2_filtering"
	# Enable all event with a filter.
	enable_log4j_lttng_event_filter "log4j2_filtering" '*' 'msg == "LOG4J2 INFO second logger fired"'
	start_lttng_tracing_ok "log4j2_filtering"

	# Run 5 times with a 1ms delay and fire second TP.
	run_app 0 1

	stop_lttng_tracing_ok "log4j2_filtering"
	destroy_lttng_session_ok "log4j2_filtering"

	# Validate test. Expecting one event of the second TP only.
	trace_match_only $EVENT_NAME2 1 "$TRACE_PATH/log4j2_filtering"

	create_lttng_session_ok "log4j2_filtering" "$TRACE_PATH/log4j2_filtering"
	# Enable first Logger but filter msg payload for the INFO one while
	# triggering the debug and second TP.
	enable_log4j_lttng_event_filter "log4j2_filtering" $EVENT_NAME1 'msg == "LOG4J2 INFO tp fired!"'
	start_lttng_tracing_ok "log4j2_filtering"

	# Run 5 times with a 1ms delay, fire debug and second TP.
	run_app 1 1

	stop_lttng_tracing_ok "log4j2_filtering"
	destroy_lttng_session_ok "log4j2_filtering"

	# Validate test. Expecting NR_ITER event of the main INFO tp.
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH/log4j2_filtering"
}

function test_log4j2_disable()
{
	diag "Test LOG4J2 disable event"

	create_lttng_session_ok "log4j2_disable" "$TRACE_PATH/log4j2_disable"
	# Enable all event with a filter.
	enable_log4j_lttng_event "log4j2_disable" $EVENT_NAME1
	enable_log4j_lttng_event "log4j2_disable" $EVENT_NAME2
	disable_log4j_lttng_event "log4j2_disable" $EVENT_NAME1
	start_lttng_tracing_ok "log4j2_disable"

	# Run 5 times with a 1ms delay and fire second TP.
	run_app 0 1

	stop_lttng_tracing_ok "log4j2_disable"
	destroy_lttng_session_ok "log4j2_disable"

	# Validate test. Expecting one event of the second TP only.
	trace_match_only $EVENT_NAME2 1 "$TRACE_PATH/log4j2_disable"
}

function test_log4j2_disable_enable()
{
	diag "Test LOG4J2 disable event followed by an enable"

	create_lttng_session_ok "log4j2_disable_enable" "$TRACE_PATH/log4j2_disable_enable"
	# Enable all event with a filter.
	enable_log4j_lttng_event "log4j2_disable_enable" $EVENT_NAME1
	disable_log4j_lttng_event "log4j2_disable_enable" $EVENT_NAME1
	enable_log4j_lttng_event "log4j2_disable_enable" $EVENT_NAME1
	start_lttng_tracing_ok "log4j2_disable_enable"

	# Run 5 times with a 1ms delay and fire second TP.
	run_app 0 1

	stop_lttng_tracing_ok "log4j2_disable_enable"
	destroy_lttng_session_ok "log4j2_disable_enable"

	# Validate test. Expecting NR_ITER event of the main INFO tp.
	trace_match_only $EVENT_NAME1 $NR_ITER "$TRACE_PATH/log4j2_disable_enable"
}

function test_log4j2_filter_loglevel()
{
	local bogus_event_name="not_a_real_event"
	local filter="int_loglevel > 700 || int_loglevel < 700"
	local all_events="."

	diag "Test LOG4J2 a filter with a loglevel"

	create_lttng_session_ok "log4j2_filter_info" "$TRACE_PATH/log4j2_filter_info"
	# Enable an event with a filter and the loglevel-only option.
	enable_log4j_lttng_event_filter_loglevel_only "log4j2_filter_info" $bogus_event_name "$filter" LOG4J_INFO
	disable_log4j_lttng_event "log4j2_filter_info" $bogus_event_name
	enable_log4j_lttng_event_filter_loglevel_only "log4j2_filter_info" $bogus_event_name "$filter" LOG4J_INFO
	start_lttng_tracing_ok "log4j2_filter_info"

	# Run 5 times with a 1ms delay and fire second TP.
	run_app 0 1

	stop_lttng_tracing_ok "log4j2_filter_info"
	destroy_lttng_session_ok "log4j2_filter_info"

	# Validate test. Expecting no events.
	trace_match_only $all_events 0 "$TRACE_PATH/log4j2_filter_info"
}

plan_tests $NUM_TESTS

print_test_banner "$TEST_DESC"

bail_out_if_no_babeltrace

test -f "$TESTAPP_PATH.class"
ok $? "Testapp '$TESTAPP_NAME' present"

start_lttng_sessiond

tests=(
	test_log4j2_multi_session_disable_wildcard
	test_log4j2_multi_session_disable_wildcard_begin
	test_log4j2_multi_session_disable_wildcard_middle
	test_log4j2_multi_session_disable_wildcard_end
	test_log4j2_multi_session_disable
	test_log4j2_disable
	test_log4j2_disable_enable
	test_log4j2_disable_all
	test_log4j2_filtering
	test_log4j2_multi_session_loglevel
	test_log4j2_destroy_session
	test_log4j2_loglevel
	test_log4j2_loglevel_multiple
	test_log4j2_before_start
	test_log4j2_after_start
	test_log4j2_multi_session
	test_log4j2_filter_loglevel
)

tracee_pids=()
for fct_test in "${tests[@]}";
do
	TRACE_PATH=$(mktemp -d -t tmp.test_java_log4j2_trace_path.XXXXXX)

	${fct_test}

	rm -rf "$TRACE_PATH"
done

stop_lttng_sessiond