3 # Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 TEST_DESC
="Filtering - Valid filters"
21 TESTDIR
=$CURDIR/..
/..
/..
22 STATS_BIN
="$TESTDIR/utils/babelstats.pl"
23 SESSION_NAME
="valid_filter"
28 NUM_TESTS
=$
(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
30 source $TESTDIR/utils
/utils.sh
32 function enable_lttng_event_filter
()
39 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$event_name \
40 -s $sess_name $domain --filter "$filter" 2>&1 >/dev
/null
41 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context \
42 -s $sess_name $domain -t procname
2>&1 >/dev
/null
44 ok $?
"Enable lttng event with filtering"
49 .
/$CURDIR/$BIN_NAME $NR_ITER >/dev
/null
2>&1
54 # Trigger the event for 100 iterations
55 echo -n "100" > /proc
/lttng-test-filter-event
58 function test_valid_filter
66 diag
"Test valid $domain_name filter: $filter"
68 trace_path
=$
(mktemp
-d)
71 create_lttng_session_ok
$SESSION_NAME $trace_path
74 enable_lttng_event_filter
$domain $SESSION_NAME "$event_name" "$filter"
77 start_lttng_tracing_ok
$SESSION_NAME
79 stop_lttng_tracing_ok
$SESSION_NAME
82 destroy_lttng_session_ok
$SESSION_NAME
84 stats
=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
90 ok $?
"Validate trace filter output"
95 function validate_min_max
102 echo $stats |
grep -q "$field $expected_min $expected_max"
107 function validator_intfield
112 validate_min_max
"$stats" "intfield" "1" "99"
113 status
=$
(($status|$?
))
115 validate_min_max
"$stats" "intfield2" "0x1" "0x63"
116 status
=$
(($status|$?
))
118 validate_min_max
"$stats" "longfield" "1" "99"
119 status
=$
(($status|$?
))
121 validate_min_max
"$stats" "netintfield" "1" "99"
122 status
=$
(($status|$?
))
124 validate_min_max
"$stats" "netintfieldhex" "0x1" "0x63"
125 status
=$
(($status|$?
))
127 if [ $KERNEL_CHECK -eq 0 ]; then
128 validate_min_max
"$stats" "floatfield" "2222" "2222"
129 status
=$
(($status|$?
))
131 validate_min_max
"$stats" "doublefield" "2" "2"
132 status
=$
(($status|$?
))
138 function validator_intfield_gt
143 validate_min_max
"$stats" "intfield" "2" "99"
144 status
=$
(($status|$?
))
149 function validator_has_no_event
154 validate_min_max
"$stats" "intfield" "0" "99"
155 status
=$
(($status|$?
))
157 if [ $status -eq 0 ]; then
164 function validator_has_events
169 validate_min_max
"$stats" "intfield" "0" "99"
170 status
=$
(($status|$?
))
175 function validator_intfield_ge
180 validate_min_max
"$stats" "intfield" "1" "99"
181 status
=$
(($status|$?
))
186 function validator_intfield_lt
191 validate_min_max
"$stats" "intfield" "0" "1"
192 status
=$
(($status|$?
))
197 function validator_intfield_le
202 validate_min_max
"$stats" "intfield" "0" "2"
203 status
=$
(($status|$?
))
208 function validator_intfield_eq
213 validate_min_max
"$stats" "intfield" "1" "1"
214 status
=$
(($status|$?
))
219 function validator_intfield_ne
224 validate_min_max
"$stats" "intfield" "0" "98"
225 status
=$
(($status|$?
))
230 function validator_intfield_not
235 validate_min_max
"$stats" "intfield" "0" "0"
236 status
=$
(($status|$?
))
241 function validator_intfield_gt_and_longfield_gt
246 validate_min_max
"$stats" "intfield" "43" "99"
247 status
=$
(($status|$?
))
248 validate_min_max
"$stats" "longfield" "43" "99"
249 status
=$
(($status|$?
))
254 function validator_intfield_ge_and_longfield_le
259 validate_min_max
"$stats" "intfield" "42" "42"
260 status
=$
(($status|$?
))
261 validate_min_max
"$stats" "longfield" "42" "42"
262 status
=$
(($status|$?
))
267 function validator_intfield_lt_or_longfield_gt
272 validate_min_max
"$stats" "intfield" "0" "99"
273 status
=$
(($status|$?
))
274 validate_min_max
"$stats" "longfield" "0" "99"
275 status
=$
(($status|$?
))
280 function validator_mixed_str_or_int_and_int
285 validate_min_max
"$stats" "intfield" "34" "99"
286 status
=$
(($status|$?
))
288 validate_min_max
"$stats" "stringfield" "\"test\"" "\"test\""
289 status
=$
(($status|$?
))
294 function validator_mixed_int_double
299 validate_min_max
"$stats" "intfield" "0" "42"
300 status
=$
(($status|$?
))
305 function validator_true_statement
310 validate_min_max
"$stats" "intfield" "0" "99"
311 status
=$
(($status|$?
))
313 validate_min_max
"$stats" "intfield2" "0x0" "0x63"
314 status
=$
(($status|$?
))
316 validate_min_max
"$stats" "longfield" "0" "99"
317 status
=$
(($status|$?
))
319 validate_min_max
"$stats" "netintfield" "0" "99"
320 status
=$
(($status|$?
))
322 validate_min_max
"$stats" "netintfieldhex" "0x0" "0x63"
323 status
=$
(($status|$?
))
325 if [ $KERNEL_CHECK -eq 0 ]; then
326 validate_min_max
"$stats" "floatfield" "2222" "2222"
327 status
=$
(($status|$?
))
329 validate_min_max
"$stats" "doublefield" "2" "2"
330 status
=$
(($status|$?
))
333 validate_min_max
"$stats" "stringfield" "\"test\"" "\"test\""
334 status
=$
(($status|$?
))
336 validate_min_max
"$stats" "stringfield2" ""\
*"" ""\
*""
337 status
=$
(($status|$?
))
342 plan_tests
$NUM_TESTS
344 print_test_banner
"$TEST_DESC"
346 issue_356_filter
="intfield > 0 && intfield > 1 && "
347 issue_356_filter
+="intfield > 2 && intfield > 3 && "
348 issue_356_filter
+="intfield > 4 && intfield > 5 && "
349 issue_356_filter
+="intfield > 6 && intfield > 7 && "
350 issue_356_filter
+="intfield > 8 || intfield > 0"
356 BIN_NAME
="gen-ust-events"
358 # One to one mapping between filters and validators
360 # Set IFS to newline to facilitate array declaration
363 UST_FILTERS
=("intfield" #1
375 "intfield > 1 && longfield > 42" #13
376 "intfield >= 42 && longfield <= 42" #14
377 "intfield < 1 || longfield > 98" #15
378 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
379 "intfield < 42.4242424242" #17
380 "\"test\" == \"test\"" #18 #Issue #342
381 "stringfield == \"test\"" #19
382 "stringfield == \"t*\"" #20
383 "stringfield == \"*\"" #21
384 $issue_356_filter #22 #Issue #356
385 "intfield < 0xDEADBEEF" #23
388 "stringfield2 == \"\\\*\"" #26
389 "1.0 || intfield || 1.0" #27
391 "\$ctx.vtid == 0" #29
392 "\$ctx.vtid != 0" #30
393 "0 == \$ctx.vtid" #31
394 "0 != \$ctx.vtid" #32
395 "\$ctx.vpid == 0" #33
396 "\$ctx.vpid != 0" #34
397 "0 == \$ctx.vpid" #35
398 "0 != \$ctx.vpid" #36
399 "\$ctx.procname != \"$BIN_NAME\"" #37
400 "\$ctx.procname == \"$BIN_NAME\"" #38
401 "\"$BIN_NAME\" != \$ctx.procname" #39
402 "\"$BIN_NAME\" == \$ctx.procname" #40
403 "\$ctx.procname != \"$BIN_NAME*\"" #41
404 "\$ctx.procname == \"$BIN_NAME*\"" #42
405 "\"$BIN_NAME*\" != \$ctx.procname" #43
406 "\"$BIN_NAME*\" == \$ctx.procname" #44
407 "\$ctx.procname != \"*\"" #45
408 "\$ctx.procname == \"*\"" #46
409 "\"*\" != \$ctx.procname" #47
410 "\"*\" == \$ctx.procname" #48
412 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" #50
413 "\$ctx.vtid.blah == 0" #51
414 "asdf.asdfsd.sadf < 4" #52
415 "0 == \$ctx.vtid.blah" #53
420 UST_FILTER_COUNT
=${#UST_FILTERS[@]}
422 if [ ! -x "$CURDIR/$BIN_NAME" ]; then
423 BAIL_OUT
"No UST nevents binary detected."
426 UST_VALIDATOR
=("validator_intfield" #1
427 "validator_intfield_gt" #2
428 "validator_intfield_ge" #3
429 "validator_intfield_lt" #4
430 "validator_intfield_le" #5
431 "validator_intfield_eq" #6
432 "validator_intfield_ne" #7
433 "validator_intfield_not" #8
434 "validator_intfield" #9
435 "validator_intfield" #10
436 "validator_intfield" #11
437 "validator_intfield" #12
438 "validator_intfield_gt_and_longfield_gt" #13
439 "validator_intfield_ge_and_longfield_le" #14
440 "validator_intfield_lt_or_longfield_gt" #15
441 "validator_mixed_str_or_int_and_int" #16
442 "validator_mixed_int_double" #17
443 "validator_true_statement" #18
444 "validator_true_statement" #19
445 "validator_true_statement" #20
446 "validator_true_statement" #21
447 "validator_intfield" #22
448 "validator_true_statement" #23
449 "validator_intfield_lt" #24
450 "validator_intfield_lt" #25
451 "validator_true_statement" #26
452 "validator_true_statement" #27
453 "validator_intfield_gt" #28
454 "validator_has_no_event" #29
455 "validator_has_events" #30
456 "validator_has_no_event" #31
457 "validator_has_events" #32
458 "validator_has_no_event" #33
459 "validator_has_events" #34
460 "validator_has_no_event" #35
461 "validator_has_events" #36
462 "validator_has_no_event" #36
463 "validator_has_events" #37
464 "validator_has_no_event" #38
465 "validator_has_events" #39
466 "validator_has_no_event" #41
467 "validator_has_events" #42
468 "validator_has_no_event" #43
469 "validator_has_events" #44
470 "validator_has_no_event" #45
471 "validator_has_events" #46
472 "validator_has_no_event" #47
473 "validator_has_events" #48
474 "validator_has_no_event" #49
475 "validator_has_no_event" #50
476 "validator_has_no_event" #51
477 "validator_has_no_event" #52
478 "validator_has_no_event" #53
479 "validator_has_no_event" #54
480 "validator_has_no_event" #55
485 diag
"Test UST valid filters"
489 while [ "$i" -lt "$UST_FILTER_COUNT" ]; do
491 test_valid_filter ust
-u "tp:tptest" "${UST_FILTERS[$i]}" "${UST_VALIDATOR[$i]}"
493 if [ $?
-eq 1 ]; then
504 BIN_NAME
="test_valid_filt" # Current script name truncated by kernel
506 # One to one mapping between filters and validators
507 # Set IFS to newline to facilitate array declaration
510 KERNEL_FILTERS
=("intfield" #1
522 "intfield > 1 && longfield > 42" #13
523 "intfield >= 42 && longfield <= 42" #14
524 "intfield < 1 || longfield > 98" #15
525 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
526 "intfield < 42.4242424242" #17
527 "\"test\" == \"test\"" #18 #Issue #342
528 "stringfield == \"test\"" #19
529 "stringfield == \"t*\"" #20
530 "stringfield == \"*\"" #21
531 $issue_356_filter #22 #Issue #356
532 "intfield < 0xDEADBEEF" #23
535 "stringfield2 == \"\\\*\"" #26
536 "1.0 || intfield || 1.0" #27
538 "\$ctx.vtid == 0" #29
539 "\$ctx.vtid != 0" #30
540 "0 == \$ctx.vtid" #31
541 "0 != \$ctx.vtid" #32
542 "\$ctx.vpid == 0" #33
543 "\$ctx.vpid != 0" #34
544 "0 == \$ctx.vpid" #35
545 "0 != \$ctx.vpid" #36
546 "\$ctx.procname != \"$BIN_NAME\"" #37
547 "\$ctx.procname == \"$BIN_NAME\"" #38
548 "\"$BIN_NAME\" != \$ctx.procname" #39
549 "\"$BIN_NAME\" == \$ctx.procname" #40
550 "\$ctx.procname != \"$BIN_NAME*\"" #41
551 "\$ctx.procname == \"$BIN_NAME*\"" #42
552 "\"$BIN_NAME*\" != \$ctx.procname" #43
553 "\"$BIN_NAME*\" == \$ctx.procname" #44
554 "\$ctx.procname != \"*\"" #45
555 "\$ctx.procname == \"*\"" #46
556 "\"*\" != \$ctx.procname" #47
557 "\"*\" == \$ctx.procname" #48
559 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" #50
560 "\$ctx.vtid.blah == 0" #51
561 "asdf.asdfsd.sadf < 4" #52
562 "0 == \$ctx.vtid.blah" #53
567 KERNEL_FILTER_COUNT
=${#KERNEL_FILTERS[@]}
569 KERNEL_VALIDATOR
=("validator_intfield" #1
570 "validator_intfield_gt" #2
571 "validator_intfield_ge" #3
572 "validator_intfield_lt" #4
573 "validator_intfield_le" #5
574 "validator_intfield_eq" #6
575 "validator_intfield_ne" #7
576 "validator_intfield_not" #8
577 "validator_intfield" #9
578 "validator_intfield" #10
579 "validator_intfield" #11
580 "validator_intfield" #12
581 "validator_intfield_gt_and_longfield_gt" #13
582 "validator_intfield_ge_and_longfield_le" #14
583 "validator_intfield_lt_or_longfield_gt" #15
584 "validator_mixed_str_or_int_and_int" #16
585 "validator_has_no_event" #17 #Unsupported by kernel
586 "validator_true_statement" #18
587 "validator_true_statement" #19
588 "validator_true_statement" #20
589 "validator_true_statement" #21
590 "validator_intfield" #22
591 "validator_true_statement" #23
592 "validator_intfield_lt" #24
593 "validator_intfield_lt" #25
594 "validator_true_statement" #26
595 "validator_has_no_event" #27 #Unsupported by kernel
596 "validator_intfield_gt" #28
597 "validator_has_no_event" #29
598 "validator_has_events" #30
599 "validator_has_no_event" #31
600 "validator_has_events" #32
601 "validator_has_no_event" #33
602 "validator_has_events" #34
603 "validator_has_no_event" #35
604 "validator_has_events" #36
605 "validator_has_no_event" #36
606 "validator_has_events" #37
607 "validator_has_no_event" #38
608 "validator_has_events" #39
609 "validator_has_no_event" #41
610 "validator_has_events" #42
611 "validator_has_no_event" #43
612 "validator_has_events" #44
613 "validator_has_no_event" #45
614 "validator_has_events" #46
615 "validator_has_no_event" #47
616 "validator_has_events" #48
617 "validator_has_no_event" #49
618 "validator_has_no_event" #50
619 "validator_has_no_event" #51
620 "validator_has_no_event" #52
621 "validator_has_no_event" #53
622 "validator_has_no_event" #54
623 "validator_has_no_event" #55
628 if [ "$(id -u)" == "0" ]; then
634 skip
$isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS ||
636 diag
"Test kernel valid filters"
641 while [ "$i" -lt "$KERNEL_FILTER_COUNT" ]; do
643 test_valid_filter kernel
-k "lttng_test_filter_event" \
644 "${KERNEL_FILTERS[$i]}" "${KERNEL_VALIDATOR[$i]}"
646 if [ $?
-eq 1 ]; then