8eddc8247bb696ccc5977a8ef5d41af23b4f7adf
[lttng-tools.git] / tests / regression / ust / overlap / test_overlap
1 #!/bin/bash
2 #
3 # Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="UST - Wildcard overlap"
8
9 CURDIR=$(dirname $0)/
10 TESTDIR=$CURDIR/../../..
11 SESSION_NAME="wildcard-overlap"
12
13 DEMO_EVENT1="ust_tests_demo:starting"
14 DEMO_EVENT1_2="ust_tests_demo:done"
15 DEMO_EVENT2="ust_tests_demo2:loop"
16 DEMO_EVENT3="ust_tests_demo3:done"
17
18 NUM_DEMO1_EVENT=1
19 NUM_DEMO1_2_EVENT=1
20 NUM_DEMO2_EVENT=5
21 NUM_DEMO3_EVENT=1
22
23 NUM_TESTS=259
24
25 source $TESTDIR/utils/utils.sh
26
27 # MUST set TESTDIR before calling those functions
28
29 run_demo_app()
30 {
31 cd $CURDIR/demo
32
33 # Start test
34 diag "Running application"
35 ./demo-trace >/dev/null 2>&1
36 ok $? "Application done"
37
38 cd -
39 }
40
41 # Ease our life a bit ;)
42 trace_match_demo1_events()
43 {
44 trace_matches "$DEMO_EVENT1" $NUM_DEMO1_EVENT $TRACE_PATH
45 trace_matches "$DEMO_EVENT1_2" $NUM_DEMO1_EVENT $TRACE_PATH
46 }
47
48 # Ease our life a bit ;)
49 trace_match_all_demo_events()
50 {
51 trace_match_demo1_events
52 trace_matches "$DEMO_EVENT2" $NUM_DEMO2_EVENT $TRACE_PATH
53 trace_matches "$DEMO_EVENT3" $NUM_DEMO3_EVENT $TRACE_PATH
54 }
55
56 # Ease our life a bit ;)
57 trace_match_no_demo_events()
58 {
59 trace_matches "$DEMO_EVENT1" 0 $TRACE_PATH
60 trace_matches "$DEMO_EVENT1_2" 0 $TRACE_PATH
61 trace_matches "$DEMO_EVENT2" 0 $TRACE_PATH
62 trace_matches "$DEMO_EVENT3" 0 $TRACE_PATH
63 }
64
65 # Expect all "demo" events, no duplicate.
66 test_enable_simple_wildcard()
67 {
68 local event_wild1="us*"
69 local event_wild2="ust*"
70
71 diag "Simple wildcard overlap"
72
73 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild1"
74 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild2"
75
76 start_lttng_tracing_ok $SESSION_NAME
77
78 run_demo_app
79
80 stop_lttng_tracing_ok $SESSION_NAME
81
82 trace_match_all_demo_events
83
84 return $?
85 }
86
87 # Expect all "demo" events, no duplicate.
88 test_enable_wildcard_filter()
89 {
90 local event_wild1="us*"
91 local event_wild2="ust*"
92
93 diag "Wildcard overlap with filter"
94
95 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1"
96 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0"
97
98 start_lttng_tracing_ok $SESSION_NAME
99
100 run_demo_app
101
102 stop_lttng_tracing_ok $SESSION_NAME
103
104 trace_match_all_demo_events
105 return $?
106 }
107
108 # Expect all "demo" events, no duplicate.
109 test_enable_wildcard_filter_2()
110 {
111 local event_wild1="us*"
112 local event_wild2="ust*"
113
114 diag "Wildcard overlap with filter 2"
115
116 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0"
117 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1"
118
119 start_lttng_tracing_ok $SESSION_NAME
120
121 run_demo_app
122
123 stop_lttng_tracing_ok $SESSION_NAME
124
125 trace_match_all_demo_events
126 return $?
127 }
128
129 # Expect all "demo" events, no duplicate.
130 test_enable_wildcard_filter_3()
131 {
132 local event_wild1="us*"
133 local event_wild2="ust*"
134
135 diag "Wildcard overlap with filter 3"
136
137 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1"
138 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1"
139
140 start_lttng_tracing_ok $SESSION_NAME
141
142 run_demo_app
143
144 stop_lttng_tracing_ok $SESSION_NAME
145
146 trace_match_all_demo_events
147 return $?
148 }
149
150 # Expected: No events.
151 test_enable_wildcard_filter_4()
152 {
153 local event_wild1="us*"
154 local event_wild2="ust*"
155
156 diag "Wildcard overlap with filter 4"
157
158 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0"
159 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0"
160
161 start_lttng_tracing_ok $SESSION_NAME
162
163 run_demo_app
164
165 stop_lttng_tracing_ok $SESSION_NAME
166
167 trace_match_no_demo_events
168 return $?
169 }
170
171 # Expect all "demo" events, no duplicate.
172 test_enable_wildcard_filter_5()
173 {
174 local event_wild1="us*"
175 local event_wild2="$DEMO_EVENT1"
176
177 diag "Wildcard overlap with filter 5"
178
179 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1"
180 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0"
181
182 start_lttng_tracing_ok $SESSION_NAME
183
184 run_demo_app
185
186 stop_lttng_tracing_ok $SESSION_NAME
187
188 trace_match_all_demo_events
189 return $?
190 }
191
192 # Expect all $DEMO_EVENT1 events, no duplicate.
193 test_enable_wildcard_filter_6()
194 {
195 local event_wild1="us*"
196 local event_wild2="$DEMO_EVENT1"
197
198 diag "Wildcard overlap with filter 6"
199
200 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0"
201 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1"
202
203 start_lttng_tracing_ok $SESSION_NAME
204
205 run_demo_app
206
207 stop_lttng_tracing_ok $SESSION_NAME
208
209 trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH
210 trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH
211 trace_matches $DEMO_EVENT2 0 $TRACE_PATH
212 trace_matches $DEMO_EVENT3 0 $TRACE_PATH
213 return $?
214 }
215
216 # Expect all events, no duplicate.
217 test_enable_wildcard_filter_7()
218 {
219 local event_wild1="us*"
220 local event_wild2="$DEMO_EVENT1"
221
222 diag "Wildcard overlap with filter 7"
223
224 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1"
225 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1"
226
227 start_lttng_tracing_ok $SESSION_NAME
228
229 run_demo_app
230
231 stop_lttng_tracing_ok $SESSION_NAME
232
233 trace_match_all_demo_events
234 return $?
235 }
236
237 # Expected: No events.
238 test_enable_wildcard_filter_8()
239 {
240 local event_wild1="us*"
241 local event_wild2="$DEMO_EVENT1"
242
243 diag "Wildcard overlap with filter 8"
244
245 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0"
246 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0"
247
248 start_lttng_tracing_ok $SESSION_NAME
249
250 run_demo_app
251
252 stop_lttng_tracing_ok $SESSION_NAME
253
254 trace_match_no_demo_events
255 return $?
256 }
257
258 # Expect all events.
259 test_enable_same_wildcard_filter()
260 {
261 local event_wild1="ust*"
262 local event_wild2="ust*"
263
264 diag "Same wildcard overlap with filter"
265
266 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1"
267 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1"
268
269 start_lttng_tracing_ok $SESSION_NAME
270
271 run_demo_app
272
273 stop_lttng_tracing_ok $SESSION_NAME
274
275 trace_match_all_demo_events
276 return $?
277 }
278
279 # Expect all events.
280 test_enable_same_wildcard_filter_2()
281 {
282 local event_wild1="ust*"
283 local event_wild2="ust*"
284
285 diag "Same wildcard overlap with filter 2"
286
287 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1"
288
289 # Enabling the same events with same filters should fail. This one is expected to fail.
290 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_wild2" -s $SESSION_NAME -u --filter "1==1" >/dev/null 2>&1
291 if [ $? -ne 0 ]; then
292 pass "Enable event $event_name with filtering for session $sess_name twice failure detected"
293 else
294 fail "Enable event $event_name with filtering for session $sess_name twice failure NOT detected"
295 fi
296
297 start_lttng_tracing_ok $SESSION_NAME
298
299 run_demo_app
300
301 stop_lttng_tracing_ok $SESSION_NAME
302
303 trace_match_all_demo_events
304 return $?
305 }
306
307 # Expect all events.
308 test_enable_same_wildcard_filter_3()
309 {
310 local event_wild1="ust*"
311 local event_wild2="ust*"
312
313 diag "Same wildcard overlap with filter 3"
314
315 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1"
316 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0"
317
318 start_lttng_tracing_ok $SESSION_NAME
319
320 run_demo_app
321
322 stop_lttng_tracing_ok $SESSION_NAME
323
324 trace_match_all_demo_events
325 return $?
326 }
327
328 # Expected: No events.
329 test_enable_same_wildcard_filter_4()
330 {
331 local event_wild1="ust*"
332 local event_wild2="ust*"
333
334 diag "Same wildcard overlap with filter 4"
335
336 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==0&&1==0"
337 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==0"
338
339 start_lttng_tracing_ok $SESSION_NAME
340
341 run_demo_app
342
343 stop_lttng_tracing_ok $SESSION_NAME
344
345 trace_match_no_demo_events
346 return $?
347 }
348
349 # Expected: Only $DEMO_EVENT1
350 test_enable_same_event_filter()
351 {
352 local event_wild1="$DEMO_EVENT1"
353 local event_wild2="$DEMO_EVENT1"
354
355 diag "Enable same event with filter."
356
357 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1"
358 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1"
359
360 start_lttng_tracing_ok $SESSION_NAME
361
362 run_demo_app
363
364 stop_lttng_tracing_ok $SESSION_NAME
365
366 trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH
367 trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH
368 trace_matches $DEMO_EVENT2 0 $TRACE_PATH
369 trace_matches $DEMO_EVENT3 0 $TRACE_PATH
370 return $?
371 }
372
373 # Expected: No events.
374 test_disable_same_wildcard_filter()
375 {
376 local event_wild1="ust*"
377 local event_wild2="ust*"
378
379 diag "Disable same wildcard with filter."
380
381 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild1" "1==1&&1==1"
382 enable_ust_lttng_event_filter $SESSION_NAME "$event_wild2" "1==1"
383
384 disable_ust_lttng_event $SESSION_NAME "ust*"
385
386 start_lttng_tracing_ok $SESSION_NAME
387
388 run_demo_app
389
390 stop_lttng_tracing_ok $SESSION_NAME
391
392 trace_match_no_demo_events
393 return $?
394 }
395
396 # Expect no events
397 test_enable_bad_wildcard()
398 {
399 # Invalid event
400 local event_wild1="ust_tests_demo"
401 local event_wild2="ust_tests_demo2"
402 local event_wild3="ust_tests_demo3"
403
404 diag "Enable bad wildcard"
405
406 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild1"
407 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild2"
408 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild3"
409
410 start_lttng_tracing_ok $SESSION_NAME
411
412 run_demo_app
413
414 stop_lttng_tracing_ok $SESSION_NAME
415
416 trace_match_no_demo_events
417 return $?
418 }
419
420 # Expect all "demo" events, no duplicate.
421 test_enable_simple_wildcard_2()
422 {
423 local event_wild1="us*"
424 local event_wild2="$DEMO_EVENT1"
425
426 diag "Simple wildcard 2"
427
428 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild1"
429 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild2"
430
431 start_lttng_tracing_ok $SESSION_NAME
432
433 run_demo_app
434
435 stop_lttng_tracing_ok $SESSION_NAME
436
437 trace_match_all_demo_events
438 return $?
439 }
440
441 # Expected: all CRIT events, + all warning events.
442 test_enable_loglevel_overlap()
443 {
444 local event_wild1="us*"
445 local event_wild2="ust*"
446
447 diag "Enable loglevel overlap"
448
449 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING"
450 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_CRIT"
451
452 start_lttng_tracing_ok $SESSION_NAME
453
454 run_demo_app
455
456 stop_lttng_tracing_ok $SESSION_NAME
457
458 trace_match_all_demo_events
459 return $?
460 }
461
462 # Expected: all CRIT events, + all warning events.
463 test_enable_loglevel_only_overlap()
464 {
465 local event_wild1="us*"
466 local event_wild2="ust*"
467
468 diag "Enable loglevel only overlap"
469
470 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING"
471 enable_ust_lttng_event_loglevel_only $SESSION_NAME "$event_wild2" "TRACE_CRIT"
472
473 start_lttng_tracing_ok $SESSION_NAME
474
475 run_demo_app
476
477 stop_lttng_tracing_ok $SESSION_NAME
478
479 trace_match_all_demo_events
480 return $?
481 }
482
483 # Expected: all events
484 test_enable_loglevel_overlap_2()
485 {
486 local event_wild1="us*"
487 local event_wild2="$DEMO_EVENT2"
488
489 diag "Enable loglevel overlap 2"
490
491 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_WARNING"
492 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_CRIT"
493
494 start_lttng_tracing_ok $SESSION_NAME
495
496 run_demo_app
497
498 stop_lttng_tracing_ok $SESSION_NAME
499
500 trace_match_all_demo_events
501 return $?
502 }
503
504 # Expected only ust_tests_demo* events.
505 test_enable_same_wildcard_loglevels()
506 {
507 local event_wild1="ust*"
508 local event_wild2="ust*"
509
510 diag "Enable same wildcard with different loglevels"
511
512 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_CRIT"
513 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_WARNING"
514
515 start_lttng_tracing_ok $SESSION_NAME
516
517 run_demo_app
518
519 stop_lttng_tracing_ok $SESSION_NAME
520
521 trace_match_all_demo_events
522 return $?
523 }
524
525 # Expected only ust_tests_demo:starting events.
526 test_enable_same_event_loglevels()
527 {
528 local event_wild1="$DEMO_EVENT1"
529 local event_wild2="$DEMO_EVENT1"
530
531 diag "Enable same event with different loglevels"
532
533 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild1" "TRACE_CRIT"
534 enable_ust_lttng_event_loglevel $SESSION_NAME "$event_wild2" "TRACE_WARNING"
535
536 start_lttng_tracing_ok $SESSION_NAME
537
538 run_demo_app
539
540 stop_lttng_tracing_ok $SESSION_NAME
541
542 trace_matches $DEMO_EVENT1 $NUM_DEMO1_EVENT $TRACE_PATH
543 trace_matches $DEMO_EVENT1_2 0 $TRACE_PATH
544 trace_matches $DEMO_EVENT2 0 $TRACE_PATH
545 trace_matches $DEMO_EVENT3 0 $TRACE_PATH
546 return $?
547 }
548
549 # Expect 0 event
550 test_disable_simple_wildcard()
551 {
552 local event_wild1="us*"
553 local event_wild2="$DEMO_EVENT1"
554
555 diag "Disable simple wildcard"
556
557 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild1"
558 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild2"
559
560 disable_ust_lttng_event $SESSION_NAME "$event_wild1"
561 disable_ust_lttng_event $SESSION_NAME "$event_wild2"
562
563 start_lttng_tracing_ok $SESSION_NAME
564
565 run_demo_app
566
567 stop_lttng_tracing_ok $SESSION_NAME
568
569 # No events are expected.
570 trace_match_no_demo_events
571 return $?
572 }
573
574 # Expect only "ust_tests_demo" events.
575 test_disable_wildcard_overlap()
576 {
577 local event_wild1="us*"
578 local event_wild2="$DEMO_EVENT1"
579
580 diag "Disable wildcard overlap"
581
582 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild1"
583 enable_ust_lttng_event_ok $SESSION_NAME "$event_wild2"
584
585 disable_ust_lttng_event $SESSION_NAME "$event_wild1"
586
587 start_lttng_tracing_ok $SESSION_NAME
588
589 run_demo_app
590
591 stop_lttng_tracing_ok $SESSION_NAME
592
593 # Expect only "ust_tests_demo" events.
594 trace_matches "$DEMO_EVENT1" $NUM_DEMO1_EVENT $TRACE_PATH
595 trace_matches "$DEMO_EVENT1_2" 0 $TRACE_PATH
596 trace_matches "$DEMO_EVENT2" 0 $TRACE_PATH
597 trace_matches "$DEMO_EVENT3" 0 $TRACE_PATH
598 return $?
599 }
600
601 plan_tests $NUM_TESTS
602
603 print_test_banner "$TEST_DESC"
604
605 bail_out_if_no_babeltrace
606
607 if [ -x "$CURDIR/demo/demo" ]; then
608 foundbin=1
609 else
610 foundbin=0
611 fi
612
613 skip $foundbin "No UST nevents binary detected. Skipping all tests." $NUM_TESTS && exit 0
614
615 TESTS=(
616 "test_enable_wildcard_filter"
617 "test_enable_wildcard_filter_2"
618 "test_enable_wildcard_filter_3"
619 "test_enable_wildcard_filter_4"
620 "test_enable_wildcard_filter_5"
621 "test_enable_wildcard_filter_6"
622 "test_enable_wildcard_filter_7"
623 "test_enable_wildcard_filter_8"
624 "test_enable_same_wildcard_filter"
625 "test_enable_same_wildcard_filter_2"
626 "test_enable_same_wildcard_filter_3"
627 "test_enable_same_wildcard_filter_4"
628 "test_enable_same_event_filter"
629 "test_enable_loglevel_only_overlap"
630 "test_enable_same_event_loglevels"
631 "test_enable_same_wildcard_loglevels"
632 "test_enable_bad_wildcard"
633 "test_enable_loglevel_overlap_2"
634 "test_enable_simple_wildcard"
635 "test_enable_simple_wildcard_2"
636 "test_enable_loglevel_overlap"
637 "test_disable_simple_wildcard"
638 "test_disable_wildcard_overlap"
639 )
640
641 TEST_COUNT=${#TESTS[@]}
642 i=0
643
644 start_lttng_sessiond
645
646 while [ "$i" -lt "$TEST_COUNT" ]; do
647
648 TRACE_PATH=$(mktemp -d -t tmp.test_overlap.XXXXXX)
649
650 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
651
652 # Execute test
653 ${TESTS[$i]}
654
655 destroy_lttng_session_ok $SESSION_NAME
656
657 rm -rf $TRACE_PATH
658
659 let "i++"
660 done
661
662 stop_lttng_sessiond
This page took 0.046919 seconds and 4 git commands to generate.