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
54 while [ -n "$(pidof $BIN_NAME)" ]; do
57 pass
"Wait for application end"
60 function test_valid_filter
65 diag
"Test valid filter: $1"
67 trace_path
=$
(mktemp
-d)
70 create_lttng_session
$SESSION_NAME $trace_path
73 enable_ust_lttng_event_filter
$SESSION_NAME $EVENT_NAME $filter
76 start_lttng_tracing
$SESSION_NAME
79 stop_lttng_tracing
$SESSION_NAME
82 destroy_lttng_session
$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 validate_min_max
"$stats" "floatfield" "2222" "2222"
128 status
=$
(($status|$?
))
130 validate_min_max
"$stats" "doublefield" "2" "2"
131 status
=$
(($status|$?
))
136 function validator_intfield_gt
141 validate_min_max
"$stats" "intfield" "2" "99"
142 status
=$
(($status|$?
))
147 function validator_has_no_event
152 validate_min_max
"$stats" "intfield" "0" "99"
153 status
=$
(($status|$?
))
155 if [ $status -eq 0 ]; then
162 function validator_has_events
167 validate_min_max
"$stats" "intfield" "0" "99"
168 status
=$
(($status|$?
))
173 function validator_intfield_ge
178 validate_min_max
"$stats" "intfield" "1" "99"
179 status
=$
(($status|$?
))
184 function validator_intfield_lt
189 validate_min_max
"$stats" "intfield" "0" "1"
190 status
=$
(($status|$?
))
195 function validator_intfield_le
200 validate_min_max
"$stats" "intfield" "0" "2"
201 status
=$
(($status|$?
))
206 function validator_intfield_eq
211 validate_min_max
"$stats" "intfield" "1" "1"
212 status
=$
(($status|$?
))
217 function validator_intfield_ne
222 validate_min_max
"$stats" "intfield" "0" "98"
223 status
=$
(($status|$?
))
228 function validator_intfield_not
233 validate_min_max
"$stats" "intfield" "0" "0"
234 status
=$
(($status|$?
))
239 function validator_intfield_gt_and_longfield_gt
244 validate_min_max
"$stats" "intfield" "43" "99"
245 status
=$
(($status|$?
))
246 validate_min_max
"$stats" "longfield" "43" "99"
247 status
=$
(($status|$?
))
252 function validator_intfield_ge_and_longfield_le
257 validate_min_max
"$stats" "intfield" "42" "42"
258 status
=$
(($status|$?
))
259 validate_min_max
"$stats" "longfield" "42" "42"
260 status
=$
(($status|$?
))
265 function validator_intfield_lt_or_longfield_gt
270 validate_min_max
"$stats" "intfield" "0" "99"
271 status
=$
(($status|$?
))
272 validate_min_max
"$stats" "longfield" "0" "99"
273 status
=$
(($status|$?
))
278 function validator_mixed_str_or_int_and_int
283 validate_min_max
"$stats" "intfield" "34" "99"
284 status
=$
(($status|$?
))
286 validate_min_max
"$stats" "stringfield" "\"test\"" "\"test\""
287 status
=$
(($status|$?
))
292 function validator_mixed_int_double
297 validate_min_max
"$stats" "intfield" "0" "42"
298 status
=$
(($status|$?
))
303 function validator_true_statement
308 validate_min_max
"$stats" "intfield" "0" "99"
309 status
=$
(($status|$?
))
311 validate_min_max
"$stats" "intfield2" "0x0" "0x63"
312 status
=$
(($status|$?
))
314 validate_min_max
"$stats" "longfield" "0" "99"
315 status
=$
(($status|$?
))
317 validate_min_max
"$stats" "netintfield" "0" "99"
318 status
=$
(($status|$?
))
320 validate_min_max
"$stats" "netintfieldhex" "0x0" "0x63"
321 status
=$
(($status|$?
))
323 validate_min_max
"$stats" "floatfield" "2222" "2222"
324 status
=$
(($status|$?
))
326 validate_min_max
"$stats" "doublefield" "2" "2"
327 status
=$
(($status|$?
))
329 validate_min_max
"$stats" "stringfield" "\"test\"" "\"test\""
330 status
=$
(($status|$?
))
332 validate_min_max
"$stats" "stringfield2" ""\
*"" ""\
*""
333 status
=$
(($status|$?
))
338 plan_tests
$NUM_TESTS
340 print_test_banner
"$TEST_DESC"
344 issue_356_filter
="intfield > 0 && intfield > 1 && "
345 issue_356_filter
+="intfield > 2 && intfield > 3 && "
346 issue_356_filter
+="intfield > 4 && intfield > 5 && "
347 issue_356_filter
+="intfield > 6 && intfield > 7 && "
348 issue_356_filter
+="intfield > 8 || intfield > 0"
350 # One to one mapping between filters and validators
352 FILTERS
=("intfield" #1
364 "intfield > 1 && longfield > 42" #13
365 "intfield >= 42 && longfield <= 42" #14
366 "intfield < 1 || longfield > 98" #15
367 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
368 "intfield < 42.4242424242" #17
369 "\"test\" == \"test\"" #18 #Issue #342
370 "stringfield == \"test\"" #19
371 "stringfield == \"t*\"" #20
372 "stringfield == \"*\"" #21
373 $issue_356_filter #22 #Issue #356
374 "intfield < 0xDEADBEEF" #23
377 "stringfield2 == \"\\\*\"" #26
378 "1.0 || intfield || 1.0" #27
380 "\$ctx.vtid == 0" #29
381 "\$ctx.vtid != 0" #30
382 "0 == \$ctx.vtid" #31
383 "0 != \$ctx.vtid" #32
384 "\$ctx.vpid == 0" #33
385 "\$ctx.vpid != 0" #34
386 "0 == \$ctx.vpid" #35
387 "0 != \$ctx.vpid" #36
388 "\$ctx.procname != \"$BIN_NAME\"" #37
389 "\$ctx.procname == \"$BIN_NAME\"" #38
390 "\"$BIN_NAME\" != \$ctx.procname" #39
391 "\"$BIN_NAME\" == \$ctx.procname" #40
392 "\$ctx.procname != \"$BIN_NAME*\"" #41
393 "\$ctx.procname == \"$BIN_NAME*\"" #42
394 "\"$BIN_NAME*\" != \$ctx.procname" #43
395 "\"$BIN_NAME*\" == \$ctx.procname" #44
396 "\$ctx.procname != \"*\"" #45
397 "\$ctx.procname == \"*\"" #46
398 "\"*\" != \$ctx.procname" #47
399 "\"*\" == \$ctx.procname" #48
402 VALIDATOR
=("validator_intfield" #1
403 "validator_intfield_gt" #2
404 "validator_intfield_ge" #3
405 "validator_intfield_lt" #4
406 "validator_intfield_le" #5
407 "validator_intfield_eq" #6
408 "validator_intfield_ne" #7
409 "validator_intfield_not" #8
410 "validator_intfield" #9
411 "validator_intfield" #10
412 "validator_intfield" #11
413 "validator_intfield" #12
414 "validator_intfield_gt_and_longfield_gt" #13
415 "validator_intfield_ge_and_longfield_le" #14
416 "validator_intfield_lt_or_longfield_gt" #15
417 "validator_mixed_str_or_int_and_int" #16
418 "validator_mixed_int_double" #17
419 "validator_true_statement" #18
420 "validator_true_statement" #19
421 "validator_true_statement" #20
422 "validator_true_statement" #21
423 "validator_intfield" #22
424 "validator_true_statement" #23
425 "validator_intfield_lt" #24
426 "validator_intfield_lt" #25
427 "validator_true_statement" #26
428 "validator_true_statement" #27
429 "validator_intfield_gt" #28
430 "validator_has_no_event" #29
431 "validator_has_events" #30
432 "validator_has_no_event" #31
433 "validator_has_events" #32
434 "validator_has_no_event" #33
435 "validator_has_events" #34
436 "validator_has_no_event" #35
437 "validator_has_events" #36
438 "validator_has_no_event" #36
439 "validator_has_events" #37
440 "validator_has_no_event" #38
441 "validator_has_events" #39
442 "validator_has_no_event" #41
443 "validator_has_events" #42
444 "validator_has_no_event" #43
445 "validator_has_events" #44
446 "validator_has_no_event" #45
447 "validator_has_events" #46
448 "validator_has_no_event" #47
449 "validator_has_events" #48
452 FILTER_COUNT
=${#FILTERS[@]}
457 while [ "$i" -lt "$FILTER_COUNT" ]; do
459 test_valid_filter
"${FILTERS[$i]}" "${VALIDATOR[$i]}"
461 if [ $?
-eq 1 ]; then