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 BIN_NAME
="gen-ust-events"
24 STATS_BIN
="$TESTDIR/utils/babelstats.pl"
25 SESSION_NAME
="valid_filter"
26 EVENT_NAME
="tp:tptest"
30 source $TESTDIR/utils
/utils.sh
32 if [ ! -x "$CURDIR/$BIN_NAME" ]; then
33 BAIL_OUT
"No UST nevents binary detected."
36 function enable_ust_lttng_event_filter
()
42 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$event_name -s $sess_name -u --filter "$filter" 2>&1 >/dev
/null
44 ok $?
"Enable lttng event with filtering"
49 .
/$CURDIR/$BIN_NAME $NR_ITER >/dev
/null
2>&1
52 function test_valid_filter
57 diag
"Test valid filter: $1"
59 trace_path
=$
(mktemp
-d)
62 create_lttng_session_ok
$SESSION_NAME $trace_path
65 enable_ust_lttng_event_filter
$SESSION_NAME $EVENT_NAME $filter
68 start_lttng_tracing_ok
$SESSION_NAME
70 stop_lttng_tracing
$SESSION_NAME
73 destroy_lttng_session
$SESSION_NAME
75 stats
=`babeltrace $trace_path | $STATS_BIN --tracepoint $EVENT_NAME`
81 ok $?
"Validate trace filter output"
86 function validate_min_max
93 echo $stats |
grep -q "$field $expected_min $expected_max"
98 function validator_intfield
103 validate_min_max
"$stats" "intfield" "1" "99"
104 status
=$
(($status|$?
))
106 validate_min_max
"$stats" "intfield2" "0x1" "0x63"
107 status
=$
(($status|$?
))
109 validate_min_max
"$stats" "longfield" "1" "99"
110 status
=$
(($status|$?
))
112 validate_min_max
"$stats" "netintfield" "1" "99"
113 status
=$
(($status|$?
))
115 validate_min_max
"$stats" "netintfieldhex" "0x1" "0x63"
116 status
=$
(($status|$?
))
118 validate_min_max
"$stats" "floatfield" "2222" "2222"
119 status
=$
(($status|$?
))
121 validate_min_max
"$stats" "doublefield" "2" "2"
122 status
=$
(($status|$?
))
127 function validator_intfield_gt
132 validate_min_max
"$stats" "intfield" "2" "99"
133 status
=$
(($status|$?
))
138 function validator_has_no_event
143 validate_min_max
"$stats" "intfield" "0" "99"
144 status
=$
(($status|$?
))
146 if [ $status -eq 0 ]; then
153 function validator_has_events
158 validate_min_max
"$stats" "intfield" "0" "99"
159 status
=$
(($status|$?
))
164 function validator_intfield_ge
169 validate_min_max
"$stats" "intfield" "1" "99"
170 status
=$
(($status|$?
))
175 function validator_intfield_lt
180 validate_min_max
"$stats" "intfield" "0" "1"
181 status
=$
(($status|$?
))
186 function validator_intfield_le
191 validate_min_max
"$stats" "intfield" "0" "2"
192 status
=$
(($status|$?
))
197 function validator_intfield_eq
202 validate_min_max
"$stats" "intfield" "1" "1"
203 status
=$
(($status|$?
))
208 function validator_intfield_ne
213 validate_min_max
"$stats" "intfield" "0" "98"
214 status
=$
(($status|$?
))
219 function validator_intfield_not
224 validate_min_max
"$stats" "intfield" "0" "0"
225 status
=$
(($status|$?
))
230 function validator_intfield_gt_and_longfield_gt
235 validate_min_max
"$stats" "intfield" "43" "99"
236 status
=$
(($status|$?
))
237 validate_min_max
"$stats" "longfield" "43" "99"
238 status
=$
(($status|$?
))
243 function validator_intfield_ge_and_longfield_le
248 validate_min_max
"$stats" "intfield" "42" "42"
249 status
=$
(($status|$?
))
250 validate_min_max
"$stats" "longfield" "42" "42"
251 status
=$
(($status|$?
))
256 function validator_intfield_lt_or_longfield_gt
261 validate_min_max
"$stats" "intfield" "0" "99"
262 status
=$
(($status|$?
))
263 validate_min_max
"$stats" "longfield" "0" "99"
264 status
=$
(($status|$?
))
269 function validator_mixed_str_or_int_and_int
274 validate_min_max
"$stats" "intfield" "34" "99"
275 status
=$
(($status|$?
))
277 validate_min_max
"$stats" "stringfield" "\"test\"" "\"test\""
278 status
=$
(($status|$?
))
283 function validator_mixed_int_double
288 validate_min_max
"$stats" "intfield" "0" "42"
289 status
=$
(($status|$?
))
294 function validator_true_statement
299 validate_min_max
"$stats" "intfield" "0" "99"
300 status
=$
(($status|$?
))
302 validate_min_max
"$stats" "intfield2" "0x0" "0x63"
303 status
=$
(($status|$?
))
305 validate_min_max
"$stats" "longfield" "0" "99"
306 status
=$
(($status|$?
))
308 validate_min_max
"$stats" "netintfield" "0" "99"
309 status
=$
(($status|$?
))
311 validate_min_max
"$stats" "netintfieldhex" "0x0" "0x63"
312 status
=$
(($status|$?
))
314 validate_min_max
"$stats" "floatfield" "2222" "2222"
315 status
=$
(($status|$?
))
317 validate_min_max
"$stats" "doublefield" "2" "2"
318 status
=$
(($status|$?
))
320 validate_min_max
"$stats" "stringfield" "\"test\"" "\"test\""
321 status
=$
(($status|$?
))
323 validate_min_max
"$stats" "stringfield2" ""\
*"" ""\
*""
324 status
=$
(($status|$?
))
329 plan_tests
$NUM_TESTS
331 print_test_banner
"$TEST_DESC"
335 issue_356_filter
="intfield > 0 && intfield > 1 && "
336 issue_356_filter
+="intfield > 2 && intfield > 3 && "
337 issue_356_filter
+="intfield > 4 && intfield > 5 && "
338 issue_356_filter
+="intfield > 6 && intfield > 7 && "
339 issue_356_filter
+="intfield > 8 || intfield > 0"
341 # One to one mapping between filters and validators
343 FILTERS
=("intfield" #1
355 "intfield > 1 && longfield > 42" #13
356 "intfield >= 42 && longfield <= 42" #14
357 "intfield < 1 || longfield > 98" #15
358 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
359 "intfield < 42.4242424242" #17
360 "\"test\" == \"test\"" #18 #Issue #342
361 "stringfield == \"test\"" #19
362 "stringfield == \"t*\"" #20
363 "stringfield == \"*\"" #21
364 $issue_356_filter #22 #Issue #356
365 "intfield < 0xDEADBEEF" #23
368 "stringfield2 == \"\\\*\"" #26
369 "1.0 || intfield || 1.0" #27
371 "\$ctx.vtid == 0" #29
372 "\$ctx.vtid != 0" #30
373 "0 == \$ctx.vtid" #31
374 "0 != \$ctx.vtid" #32
375 "\$ctx.vpid == 0" #33
376 "\$ctx.vpid != 0" #34
377 "0 == \$ctx.vpid" #35
378 "0 != \$ctx.vpid" #36
379 "\$ctx.procname != \"$BIN_NAME\"" #37
380 "\$ctx.procname == \"$BIN_NAME\"" #38
381 "\"$BIN_NAME\" != \$ctx.procname" #39
382 "\"$BIN_NAME\" == \$ctx.procname" #40
383 "\$ctx.procname != \"$BIN_NAME*\"" #41
384 "\$ctx.procname == \"$BIN_NAME*\"" #42
385 "\"$BIN_NAME*\" != \$ctx.procname" #43
386 "\"$BIN_NAME*\" == \$ctx.procname" #44
387 "\$ctx.procname != \"*\"" #45
388 "\$ctx.procname == \"*\"" #46
389 "\"*\" != \$ctx.procname" #47
390 "\"*\" == \$ctx.procname" #48
393 VALIDATOR
=("validator_intfield" #1
394 "validator_intfield_gt" #2
395 "validator_intfield_ge" #3
396 "validator_intfield_lt" #4
397 "validator_intfield_le" #5
398 "validator_intfield_eq" #6
399 "validator_intfield_ne" #7
400 "validator_intfield_not" #8
401 "validator_intfield" #9
402 "validator_intfield" #10
403 "validator_intfield" #11
404 "validator_intfield" #12
405 "validator_intfield_gt_and_longfield_gt" #13
406 "validator_intfield_ge_and_longfield_le" #14
407 "validator_intfield_lt_or_longfield_gt" #15
408 "validator_mixed_str_or_int_and_int" #16
409 "validator_mixed_int_double" #17
410 "validator_true_statement" #18
411 "validator_true_statement" #19
412 "validator_true_statement" #20
413 "validator_true_statement" #21
414 "validator_intfield" #22
415 "validator_true_statement" #23
416 "validator_intfield_lt" #24
417 "validator_intfield_lt" #25
418 "validator_true_statement" #26
419 "validator_true_statement" #27
420 "validator_intfield_gt" #28
421 "validator_has_no_event" #29
422 "validator_has_events" #30
423 "validator_has_no_event" #31
424 "validator_has_events" #32
425 "validator_has_no_event" #33
426 "validator_has_events" #34
427 "validator_has_no_event" #35
428 "validator_has_events" #36
429 "validator_has_no_event" #36
430 "validator_has_events" #37
431 "validator_has_no_event" #38
432 "validator_has_events" #39
433 "validator_has_no_event" #41
434 "validator_has_events" #42
435 "validator_has_no_event" #43
436 "validator_has_events" #44
437 "validator_has_no_event" #45
438 "validator_has_events" #46
439 "validator_has_no_event" #47
440 "validator_has_events" #48
443 FILTER_COUNT
=${#FILTERS[@]}
448 while [ "$i" -lt "$FILTER_COUNT" ]; do
450 test_valid_filter
"${FILTERS[$i]}" "${VALIDATOR[$i]}"
452 if [ $?
-eq 1 ]; then