Tests: remove declaration already present in utils.sh
[lttng-tools.git] / tests / regression / tools / filtering / test_valid_filter
1 #!/bin/bash
2 #
3 # Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com>
4 #
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.
8 #
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
12 # more details.
13 #
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.
17
18 TEST_DESC="Filtering - Valid filters"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../..
22 STATS_BIN="$TESTDIR/utils/babelstats.pl"
23 SESSION_NAME="valid_filter"
24 NR_ITER=100
25 NUM_GLOBAL_TESTS=2
26 NUM_UST_TESTS=330
27 NUM_KERNEL_TESTS=330
28 NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
29
30 source $TESTDIR/utils/utils.sh
31
32 function enable_lttng_event_filter()
33 {
34 domain="$1"
35 sess_name="$2"
36 event_name="$3"
37 filter="$4"
38
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
43
44 ok $? "Enable lttng event with filtering"
45 }
46
47 function run_ust
48 {
49 ./$CURDIR/$BIN_NAME $NR_ITER >/dev/null 2>&1
50 }
51
52 function run_kernel
53 {
54 # Trigger the event for 100 iterations
55 echo -n "100" > /proc/lttng-test-filter-event
56 }
57
58 function test_valid_filter
59 {
60 domain_name="$1"
61 domain="$2"
62 event_name="$3"
63 filter="$4"
64 validator="$5"
65
66 diag "Test valid $domain_name filter: $filter"
67
68 trace_path=$(mktemp -d)
69
70 # Create session
71 create_lttng_session_ok $SESSION_NAME $trace_path
72
73 # Enable filter
74 enable_lttng_event_filter $domain $SESSION_NAME "$event_name" "$filter"
75
76 # Trace apps
77 start_lttng_tracing_ok $SESSION_NAME
78 run_$domain_name
79 stop_lttng_tracing_ok $SESSION_NAME
80
81 # Destroy session
82 destroy_lttng_session_ok $SESSION_NAME
83
84 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
85
86 rm -rf $trace_path
87
88 $validator "$stats"
89
90 ok $? "Validate trace filter output"
91
92 rm -rf $trace_path
93 }
94
95 function validate_min_max
96 {
97 stats="$1"
98 field=$2
99 expected_min=$3
100 expected_max=$4
101
102 echo $stats | grep -q "$field $expected_min $expected_max"
103
104 return $?
105 }
106
107 function validator_intfield
108 {
109 stats="$1"
110 status=0
111
112 validate_min_max "$stats" "intfield" "1" "99"
113 status=$(($status|$?))
114
115 validate_min_max "$stats" "intfield2" "0x1" "0x63"
116 status=$(($status|$?))
117
118 validate_min_max "$stats" "longfield" "1" "99"
119 status=$(($status|$?))
120
121 validate_min_max "$stats" "netintfield" "1" "99"
122 status=$(($status|$?))
123
124 validate_min_max "$stats" "netintfieldhex" "0x1" "0x63"
125 status=$(($status|$?))
126
127 if [ $KERNEL_CHECK -eq 0 ]; then
128 validate_min_max "$stats" "floatfield" "2222" "2222"
129 status=$(($status|$?))
130
131 validate_min_max "$stats" "doublefield" "2" "2"
132 status=$(($status|$?))
133 fi
134
135 return $status
136 }
137
138 function validator_intfield_gt
139 {
140 stats="$1"
141 status=0
142
143 validate_min_max "$stats" "intfield" "2" "99"
144 status=$(($status|$?))
145
146 return $status
147 }
148
149 function validator_has_no_event
150 {
151 stats="$1"
152 status=0
153
154 validate_min_max "$stats" "intfield" "0" "99"
155 status=$(($status|$?))
156
157 if [ $status -eq 0 ]; then
158 return 1
159 else
160 return 0
161 fi
162 }
163
164 function validator_has_events
165 {
166 stats="$1"
167 status=0
168
169 validate_min_max "$stats" "intfield" "0" "99"
170 status=$(($status|$?))
171
172 return $status
173 }
174
175 function validator_intfield_ge
176 {
177 stats="$1"
178 status=0
179
180 validate_min_max "$stats" "intfield" "1" "99"
181 status=$(($status|$?))
182
183 return $status
184 }
185
186 function validator_intfield_lt
187 {
188 stats="$1"
189 status=0
190
191 validate_min_max "$stats" "intfield" "0" "1"
192 status=$(($status|$?))
193
194 return $status
195 }
196
197 function validator_intfield_le
198 {
199 stats="$1"
200 status=0
201
202 validate_min_max "$stats" "intfield" "0" "2"
203 status=$(($status|$?))
204
205 return $status
206 }
207
208 function validator_intfield_eq
209 {
210 stats="$1"
211 status=0
212
213 validate_min_max "$stats" "intfield" "1" "1"
214 status=$(($status|$?))
215
216 return $status
217 }
218
219 function validator_intfield_ne
220 {
221 stats="$1"
222 status=0
223
224 validate_min_max "$stats" "intfield" "0" "98"
225 status=$(($status|$?))
226
227 return $status
228 }
229
230 function validator_intfield_not
231 {
232 stats="$1"
233 status=0
234
235 validate_min_max "$stats" "intfield" "0" "0"
236 status=$(($status|$?))
237
238 return $status
239 }
240
241 function validator_intfield_gt_and_longfield_gt
242 {
243 stats="$1"
244 status=0
245
246 validate_min_max "$stats" "intfield" "43" "99"
247 status=$(($status|$?))
248 validate_min_max "$stats" "longfield" "43" "99"
249 status=$(($status|$?))
250
251 return $status
252 }
253
254 function validator_intfield_ge_and_longfield_le
255 {
256 stats="$1"
257 status=0
258
259 validate_min_max "$stats" "intfield" "42" "42"
260 status=$(($status|$?))
261 validate_min_max "$stats" "longfield" "42" "42"
262 status=$(($status|$?))
263
264 return $status
265 }
266
267 function validator_intfield_lt_or_longfield_gt
268 {
269 stats="$1"
270 status=0
271
272 validate_min_max "$stats" "intfield" "0" "99"
273 status=$(($status|$?))
274 validate_min_max "$stats" "longfield" "0" "99"
275 status=$(($status|$?))
276
277 return $status
278 }
279
280 function validator_mixed_str_or_int_and_int
281 {
282 stats="$1"
283 status=0
284
285 validate_min_max "$stats" "intfield" "34" "99"
286 status=$(($status|$?))
287
288 validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
289 status=$(($status|$?))
290
291 return $status
292 }
293
294 function validator_mixed_int_double
295 {
296 stats="$1"
297 status=0
298
299 validate_min_max "$stats" "intfield" "0" "42"
300 status=$(($status|$?))
301
302 return $status
303 }
304
305 function validator_true_statement
306 {
307 stats="$1"
308 status=0
309
310 validate_min_max "$stats" "intfield" "0" "99"
311 status=$(($status|$?))
312
313 validate_min_max "$stats" "intfield2" "0x0" "0x63"
314 status=$(($status|$?))
315
316 validate_min_max "$stats" "longfield" "0" "99"
317 status=$(($status|$?))
318
319 validate_min_max "$stats" "netintfield" "0" "99"
320 status=$(($status|$?))
321
322 validate_min_max "$stats" "netintfieldhex" "0x0" "0x63"
323 status=$(($status|$?))
324
325 if [ $KERNEL_CHECK -eq 0 ]; then
326 validate_min_max "$stats" "floatfield" "2222" "2222"
327 status=$(($status|$?))
328
329 validate_min_max "$stats" "doublefield" "2" "2"
330 status=$(($status|$?))
331 fi
332
333 validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
334 status=$(($status|$?))
335
336 validate_min_max "$stats" "stringfield2" ""\*"" ""\*""
337 status=$(($status|$?))
338
339 return $status
340 }
341
342 plan_tests $NUM_TESTS
343
344 print_test_banner "$TEST_DESC"
345
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"
351
352 start_lttng_sessiond
353
354 ### UST TESTS
355
356 BIN_NAME="gen-ust-events"
357
358 # One to one mapping between filters and validators
359
360 # Set IFS to newline to facilitate array declaration
361 OLDIFS="$IFS"
362 IFS=$'\n'
363 UST_FILTERS=("intfield" #1
364 "intfield > 1" #2
365 "intfield >= 1" #3
366 "intfield < 2" #4
367 "intfield <= 2" #5
368 "intfield == 1" #6
369 "intfield != 99" #7
370 "!intfield" #8
371 "-intfield" #9
372 "--intfield" #10
373 "+intfield" #11
374 "++intfield" #12
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
386 "intfield < 0x2" #24
387 "intfield < 02" #25
388 "stringfield2 == \"\\\*\"" #26
389 "1.0 || intfield || 1.0" #27
390 "1 < intfield" #28
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
411 "!a.f.d" #49
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
416 "\$ctx.44 == 0" #54
417 "0 == \$ctx.44" #55
418 )
419
420 UST_FILTER_COUNT=${#UST_FILTERS[@]}
421
422 if [ ! -x "$CURDIR/$BIN_NAME" ]; then
423 BAIL_OUT "No UST nevents binary detected."
424 fi
425
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
481 )
482
483 IFS="$OLDIFS"
484
485 diag "Test UST valid filters"
486
487 KERNEL_CHECK=0
488 i=0
489 while [ "$i" -lt "$UST_FILTER_COUNT" ]; do
490
491 test_valid_filter ust -u "tp:tptest" "${UST_FILTERS[$i]}" "${UST_VALIDATOR[$i]}"
492
493 if [ $? -eq 1 ]; then
494 stop_lttng_sessiond
495 exit 1
496 fi
497
498 let "i++"
499 done
500
501
502 ### KERNEL TESTS
503
504 BIN_NAME="test_valid_filt" # Current script name truncated by kernel
505
506 # One to one mapping between filters and validators
507 # Set IFS to newline to facilitate array declaration
508 OLDIFS="$IFS"
509 IFS=$'\n'
510 KERNEL_FILTERS=("intfield" #1
511 "intfield > 1" #2
512 "intfield >= 1" #3
513 "intfield < 2" #4
514 "intfield <= 2" #5
515 "intfield == 1" #6
516 "intfield != 99" #7
517 "!intfield" #8
518 "-intfield" #9
519 "--intfield" #10
520 "+intfield" #11
521 "++intfield" #12
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
533 "intfield < 0x2" #24
534 "intfield < 02" #25
535 "stringfield2 == \"\\\*\"" #26
536 "1.0 || intfield || 1.0" #27
537 "1 < intfield" #28
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
558 "!a.f.d" #49
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
563 "\$ctx.44 == 0" #54
564 "0 == \$ctx.44" #55
565 )
566
567 KERNEL_FILTER_COUNT=${#KERNEL_FILTERS[@]}
568
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
624 )
625
626 IFS=$OLDIFS
627
628 if [ "$(id -u)" == "0" ]; then
629 isroot=1
630 else
631 isroot=0
632 fi
633
634 skip $isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS ||
635 {
636 diag "Test kernel valid filters"
637
638 KERNEL_CHECK=1
639 modprobe lttng-test
640 i=0
641 while [ "$i" -lt "$KERNEL_FILTER_COUNT" ]; do
642
643 test_valid_filter kernel -k "lttng_test_filter_event" \
644 "${KERNEL_FILTERS[$i]}" "${KERNEL_VALIDATOR[$i]}"
645
646 if [ $? -eq 1 ]; then
647 stop_lttng_sessiond
648 exit 1
649 fi
650
651 let "i++"
652 done
653 rmmod lttng-test
654 }
655
656 stop_lttng_sessiond
This page took 0.043899 seconds and 4 git commands to generate.