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/..
/..
/..
23 STATS_BIN
="$TESTDIR/utils/babelstats.pl"
24 SESSION_NAME
="valid_filter"
29 NUM_TESTS
=$
(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
31 source $TESTDIR/utils
/utils.sh
33 function enable_lttng_event_filter
()
40 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$event_name \
41 -s $sess_name $domain --filter "$filter" 2>&1 >/dev
/null
42 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN add-context \
43 -s $sess_name $domain -t procname
2>&1 >/dev
/null
45 ok $?
"Enable lttng event with filtering"
50 .
/$CURDIR/$BIN_NAME $NR_ITER >/dev
/null
2>&1
55 # Trigger the event for 100 iterations
56 echo -n "100" > /proc
/lttng-test-filter-event
59 function test_valid_filter
67 diag
"Test valid $domain_name filter: $filter"
69 trace_path
=$
(mktemp
-d)
72 create_lttng_session_ok
$SESSION_NAME $trace_path
75 enable_lttng_event_filter
$domain $SESSION_NAME $event_name $filter
78 start_lttng_tracing_ok
$SESSION_NAME
80 stop_lttng_tracing_ok
$SESSION_NAME
83 destroy_lttng_session_ok
$SESSION_NAME
85 stats
=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
91 ok $?
"Validate trace filter output"
96 function validate_min_max
103 echo $stats |
grep -q "$field $expected_min $expected_max"
108 function validator_intfield
113 validate_min_max
"$stats" "intfield" "1" "99"
114 status
=$
(($status|$?
))
116 validate_min_max
"$stats" "intfield2" "0x1" "0x63"
117 status
=$
(($status|$?
))
119 validate_min_max
"$stats" "longfield" "1" "99"
120 status
=$
(($status|$?
))
122 validate_min_max
"$stats" "netintfield" "1" "99"
123 status
=$
(($status|$?
))
125 validate_min_max
"$stats" "netintfieldhex" "0x1" "0x63"
126 status
=$
(($status|$?
))
128 if [ $KERNEL_CHECK -eq 0 ]; then
129 validate_min_max
"$stats" "floatfield" "2222" "2222"
130 status
=$
(($status|$?
))
132 validate_min_max
"$stats" "doublefield" "2" "2"
133 status
=$
(($status|$?
))
139 function validator_intfield_gt
144 validate_min_max
"$stats" "intfield" "2" "99"
145 status
=$
(($status|$?
))
150 function validator_has_no_event
155 validate_min_max
"$stats" "intfield" "0" "99"
156 status
=$
(($status|$?
))
158 if [ $status -eq 0 ]; then
165 function validator_has_events
170 validate_min_max
"$stats" "intfield" "0" "99"
171 status
=$
(($status|$?
))
176 function validator_intfield_ge
181 validate_min_max
"$stats" "intfield" "1" "99"
182 status
=$
(($status|$?
))
187 function validator_intfield_lt
192 validate_min_max
"$stats" "intfield" "0" "1"
193 status
=$
(($status|$?
))
198 function validator_intfield_le
203 validate_min_max
"$stats" "intfield" "0" "2"
204 status
=$
(($status|$?
))
209 function validator_intfield_eq
214 validate_min_max
"$stats" "intfield" "1" "1"
215 status
=$
(($status|$?
))
220 function validator_intfield_ne
225 validate_min_max
"$stats" "intfield" "0" "98"
226 status
=$
(($status|$?
))
231 function validator_intfield_not
236 validate_min_max
"$stats" "intfield" "0" "0"
237 status
=$
(($status|$?
))
242 function validator_intfield_gt_and_longfield_gt
247 validate_min_max
"$stats" "intfield" "43" "99"
248 status
=$
(($status|$?
))
249 validate_min_max
"$stats" "longfield" "43" "99"
250 status
=$
(($status|$?
))
255 function validator_intfield_ge_and_longfield_le
260 validate_min_max
"$stats" "intfield" "42" "42"
261 status
=$
(($status|$?
))
262 validate_min_max
"$stats" "longfield" "42" "42"
263 status
=$
(($status|$?
))
268 function validator_intfield_lt_or_longfield_gt
273 validate_min_max
"$stats" "intfield" "0" "99"
274 status
=$
(($status|$?
))
275 validate_min_max
"$stats" "longfield" "0" "99"
276 status
=$
(($status|$?
))
281 function validator_mixed_str_or_int_and_int
286 validate_min_max
"$stats" "intfield" "34" "99"
287 status
=$
(($status|$?
))
289 validate_min_max
"$stats" "stringfield" "\"test\"" "\"test\""
290 status
=$
(($status|$?
))
295 function validator_mixed_int_double
300 validate_min_max
"$stats" "intfield" "0" "42"
301 status
=$
(($status|$?
))
306 function validator_true_statement
311 validate_min_max
"$stats" "intfield" "0" "99"
312 status
=$
(($status|$?
))
314 validate_min_max
"$stats" "intfield2" "0x0" "0x63"
315 status
=$
(($status|$?
))
317 validate_min_max
"$stats" "longfield" "0" "99"
318 status
=$
(($status|$?
))
320 validate_min_max
"$stats" "netintfield" "0" "99"
321 status
=$
(($status|$?
))
323 validate_min_max
"$stats" "netintfieldhex" "0x0" "0x63"
324 status
=$
(($status|$?
))
326 if [ $KERNEL_CHECK -eq 0 ]; then
327 validate_min_max
"$stats" "floatfield" "2222" "2222"
328 status
=$
(($status|$?
))
330 validate_min_max
"$stats" "doublefield" "2" "2"
331 status
=$
(($status|$?
))
334 validate_min_max
"$stats" "stringfield" "\"test\"" "\"test\""
335 status
=$
(($status|$?
))
337 validate_min_max
"$stats" "stringfield2" ""\
*"" ""\
*""
338 status
=$
(($status|$?
))
343 plan_tests
$NUM_TESTS
345 print_test_banner
"$TEST_DESC"
349 issue_356_filter
="intfield > 0 && intfield > 1 && "
350 issue_356_filter
+="intfield > 2 && intfield > 3 && "
351 issue_356_filter
+="intfield > 4 && intfield > 5 && "
352 issue_356_filter
+="intfield > 6 && intfield > 7 && "
353 issue_356_filter
+="intfield > 8 || intfield > 0"
359 BIN_NAME
="gen-ust-events"
361 # One to one mapping between filters and validators
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
483 diag
"Test UST valid filters"
487 while [ "$i" -lt "$UST_FILTER_COUNT" ]; do
489 test_valid_filter ust
-u "tp:tptest" "${UST_FILTERS[$i]}" "${UST_VALIDATOR[$i]}"
491 if [ $?
-eq 1 ]; then
502 BIN_NAME
="test_valid_filt" # Current script name truncated by kernel
504 # One to one mapping between filters and validators
506 KERNEL_FILTERS
=("intfield" #1
518 "intfield > 1 && longfield > 42" #13
519 "intfield >= 42 && longfield <= 42" #14
520 "intfield < 1 || longfield > 98" #15
521 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
522 "intfield < 42.4242424242" #17
523 "\"test\" == \"test\"" #18 #Issue #342
524 "stringfield == \"test\"" #19
525 "stringfield == \"t*\"" #20
526 "stringfield == \"*\"" #21
527 $issue_356_filter #22 #Issue #356
528 "intfield < 0xDEADBEEF" #23
531 "stringfield2 == \"\\\*\"" #26
532 "1.0 || intfield || 1.0" #27
534 "\$ctx.vtid == 0" #29
535 "\$ctx.vtid != 0" #30
536 "0 == \$ctx.vtid" #31
537 "0 != \$ctx.vtid" #32
538 "\$ctx.vpid == 0" #33
539 "\$ctx.vpid != 0" #34
540 "0 == \$ctx.vpid" #35
541 "0 != \$ctx.vpid" #36
542 "\$ctx.procname != \"$BIN_NAME\"" #37
543 "\$ctx.procname == \"$BIN_NAME\"" #38
544 "\"$BIN_NAME\" != \$ctx.procname" #39
545 "\"$BIN_NAME\" == \$ctx.procname" #40
546 "\$ctx.procname != \"$BIN_NAME*\"" #41
547 "\$ctx.procname == \"$BIN_NAME*\"" #42
548 "\"$BIN_NAME*\" != \$ctx.procname" #43
549 "\"$BIN_NAME*\" == \$ctx.procname" #44
550 "\$ctx.procname != \"*\"" #45
551 "\$ctx.procname == \"*\"" #46
552 "\"*\" != \$ctx.procname" #47
553 "\"*\" == \$ctx.procname" #48
555 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" #50
556 "\$ctx.vtid.blah == 0" #51
557 "asdf.asdfsd.sadf < 4" #52
558 "0 == \$ctx.vtid.blah" #53
563 KERNEL_FILTER_COUNT
=${#KERNEL_FILTERS[@]}
565 KERNEL_VALIDATOR
=("validator_intfield" #1
566 "validator_intfield_gt" #2
567 "validator_intfield_ge" #3
568 "validator_intfield_lt" #4
569 "validator_intfield_le" #5
570 "validator_intfield_eq" #6
571 "validator_intfield_ne" #7
572 "validator_intfield_not" #8
573 "validator_intfield" #9
574 "validator_intfield" #10
575 "validator_intfield" #11
576 "validator_intfield" #12
577 "validator_intfield_gt_and_longfield_gt" #13
578 "validator_intfield_ge_and_longfield_le" #14
579 "validator_intfield_lt_or_longfield_gt" #15
580 "validator_mixed_str_or_int_and_int" #16
581 "validator_has_no_event" #17 #Unsupported by kernel
582 "validator_true_statement" #18
583 "validator_true_statement" #19
584 "validator_true_statement" #20
585 "validator_true_statement" #21
586 "validator_intfield" #22
587 "validator_true_statement" #23
588 "validator_intfield_lt" #24
589 "validator_intfield_lt" #25
590 "validator_true_statement" #26
591 "validator_has_no_event" #27 #Unsupported by kernel
592 "validator_intfield_gt" #28
593 "validator_has_no_event" #29
594 "validator_has_events" #30
595 "validator_has_no_event" #31
596 "validator_has_events" #32
597 "validator_has_no_event" #33
598 "validator_has_events" #34
599 "validator_has_no_event" #35
600 "validator_has_events" #36
601 "validator_has_no_event" #36
602 "validator_has_events" #37
603 "validator_has_no_event" #38
604 "validator_has_events" #39
605 "validator_has_no_event" #41
606 "validator_has_events" #42
607 "validator_has_no_event" #43
608 "validator_has_events" #44
609 "validator_has_no_event" #45
610 "validator_has_events" #46
611 "validator_has_no_event" #47
612 "validator_has_events" #48
613 "validator_has_no_event" #49
614 "validator_has_no_event" #50
615 "validator_has_no_event" #51
616 "validator_has_no_event" #52
617 "validator_has_no_event" #53
618 "validator_has_no_event" #54
619 "validator_has_no_event" #55
622 if [ "$(id -u)" == "0" ]; then
628 skip
$isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS ||
630 diag
"Test kernel valid filters"
635 while [ "$i" -lt "$KERNEL_FILTER_COUNT" ]; do
637 test_valid_filter kernel
-k "lttng_test_filter_event" \
638 "${KERNEL_FILTERS[$i]}" "${KERNEL_VALIDATOR[$i]}"
640 if [ $?
-eq 1 ]; then