Filter: make bitwise and, or, xor higher prio than relational expressions
[lttng-tools.git] / tests / regression / tools / filtering / test_valid_filter
CommitLineData
9fec62f7
CB
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
18TEST_DESC="Filtering - Valid filters"
19
20CURDIR=$(dirname $0)/
9ac429ef 21TESTDIR=$CURDIR/../../..
9fec62f7 22LTTNG_BIN="lttng"
9d806fbf 23STATS_BIN="$TESTDIR/utils/babelstats.pl"
9fec62f7 24SESSION_NAME="valid_filter"
9fec62f7 25NR_ITER=100
f6788fc4 26NUM_GLOBAL_TESTS=2
831b702b
MD
27NUM_UST_TESTS=1110
28NUM_KERNEL_TESTS=1044
f6788fc4 29NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
9fec62f7 30
9ac429ef 31source $TESTDIR/utils/utils.sh
9fec62f7 32
f6788fc4 33function enable_lttng_event_filter()
9fec62f7 34{
f6788fc4
MD
35 domain="$1"
36 sess_name="$2"
37 event_name="$3"
38 filter="$4"
9fec62f7 39
f6788fc4
MD
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
9fec62f7 44
03276eea 45 ok $? "Enable lttng event with filtering"
9fec62f7
CB
46}
47
f6788fc4 48function run_ust
9fec62f7 49{
d7ee608c 50 ./$CURDIR/$BIN_NAME $NR_ITER >/dev/null 2>&1
9fec62f7
CB
51}
52
ec7fe110
PP
53function run_ust_str
54{
55 $TESTDIR/utils/testapp/gen-ust-nevents-str/gen-ust-nevents-str $NR_ITER \
56 hypothec \
57 hypotheca \
58 hypothecary \
59 hypothecate \
60 hypothecation \
61 hypothecator \
62 hypothecium \
63 hypothenar \
64 hypothenuse \
65 hypothermal \
66 hypothermia \
67 hypothermic \
68 hypotheses \
69 hypothesis \
70 hypothesise \
71 hypothesised \
72 hypothesises \
73 hypothesize \
74 hypothesizing \
75 hypothetic \
76 electrothermic \
77 endothermic \
78 exothermic \
79 geothermic \
80 apothecary \
81 hypothecary \
82 peccary \
83 scary \
84 actinomycosis \
85 adenohypophysis \
86 adiposis \
87 emesis \
88 emphasis \
89 conformal \
90 coseismal \
91 decimal \
92 dermal
93}
94
f6788fc4
MD
95function run_kernel
96{
97 # Trigger the event for 100 iterations
98 echo -n "100" > /proc/lttng-test-filter-event
99}
100
9fec62f7
CB
101function test_valid_filter
102{
f6788fc4
MD
103 domain_name="$1"
104 domain="$2"
105 event_name="$3"
106 filter="$4"
107 validator="$5"
9fec62f7 108
f6788fc4 109 diag "Test valid $domain_name filter: $filter"
9fec62f7
CB
110
111 trace_path=$(mktemp -d)
112
113 # Create session
bf6ae429 114 create_lttng_session_ok $SESSION_NAME $trace_path
9fec62f7
CB
115
116 # Enable filter
80744d94 117 enable_lttng_event_filter $domain $SESSION_NAME "$event_name" "$filter"
9fec62f7
CB
118
119 # Trace apps
e563bbdb 120 start_lttng_tracing_ok $SESSION_NAME
f6788fc4 121 run_$domain_name
96340a01 122 stop_lttng_tracing_ok $SESSION_NAME
9fec62f7
CB
123
124 # Destroy session
67b4c664 125 destroy_lttng_session_ok $SESSION_NAME
9fec62f7 126
f6788fc4 127 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
9fec62f7 128
3bae2c9a
DG
129 rm -rf $trace_path
130
9fec62f7
CB
131 $validator "$stats"
132
03276eea
CB
133 ok $? "Validate trace filter output"
134
135 rm -rf $trace_path
9fec62f7
CB
136}
137
138function validate_min_max
139{
140 stats="$1"
141 field=$2
142 expected_min=$3
143 expected_max=$4
144
145 echo $stats | grep -q "$field $expected_min $expected_max"
146
147 return $?
148}
149
150function validator_intfield
151{
152 stats="$1"
153 status=0
154
155 validate_min_max "$stats" "intfield" "1" "99"
156 status=$(($status|$?))
157
158 validate_min_max "$stats" "intfield2" "0x1" "0x63"
159 status=$(($status|$?))
160
161 validate_min_max "$stats" "longfield" "1" "99"
162 status=$(($status|$?))
163
164 validate_min_max "$stats" "netintfield" "1" "99"
165 status=$(($status|$?))
166
167 validate_min_max "$stats" "netintfieldhex" "0x1" "0x63"
168 status=$(($status|$?))
169
f6788fc4
MD
170 if [ $KERNEL_CHECK -eq 0 ]; then
171 validate_min_max "$stats" "floatfield" "2222" "2222"
172 status=$(($status|$?))
9fec62f7 173
f6788fc4
MD
174 validate_min_max "$stats" "doublefield" "2" "2"
175 status=$(($status|$?))
176 fi
9fec62f7
CB
177
178 return $status
179}
180
181function validator_intfield_gt
182{
183 stats="$1"
184 status=0
185
186 validate_min_max "$stats" "intfield" "2" "99"
187 status=$(($status|$?))
188
189 return $status
190}
191
6d5d85c7
MD
192function validator_has_no_event
193{
194 stats="$1"
195 status=0
196
197 validate_min_max "$stats" "intfield" "0" "99"
198 status=$(($status|$?))
199
200 if [ $status -eq 0 ]; then
201 return 1
202 else
203 return 0
204 fi
205}
206
ec7fe110
PP
207function validator_str_has_no_event
208{
209 validator_has_no_event "$1"
210}
211
6d5d85c7
MD
212function validator_has_events
213{
214 stats="$1"
215 status=0
216
217 validate_min_max "$stats" "intfield" "0" "99"
218 status=$(($status|$?))
219
220 return $status
221}
222
ec7fe110
PP
223function validator_str_has_events
224{
225 stats="$1"
226 status=0
227
228 echo $stats | grep -q str
229 status=$(($status|$?))
230
231 return $status
232}
233
234function validator_stringfield_has_events
235{
236 stats="$1"
237 status=0
238
239 echo $stats | grep -q stringfield
240 status=$(($status|$?))
241
242 return $status
243}
244
9fec62f7
CB
245function validator_intfield_ge
246{
247 stats="$1"
248 status=0
249
250 validate_min_max "$stats" "intfield" "1" "99"
251 status=$(($status|$?))
252
253 return $status
254}
255
256function validator_intfield_lt
257{
258 stats="$1"
259 status=0
260
261 validate_min_max "$stats" "intfield" "0" "1"
262 status=$(($status|$?))
263
264 return $status
265}
266
267function validator_intfield_le
268{
269 stats="$1"
270 status=0
271
272 validate_min_max "$stats" "intfield" "0" "2"
273 status=$(($status|$?))
274
275 return $status
276}
277
278function validator_intfield_eq
279{
280 stats="$1"
281 status=0
282
283 validate_min_max "$stats" "intfield" "1" "1"
284 status=$(($status|$?))
285
286 return $status
287}
288
289function validator_intfield_ne
290{
291 stats="$1"
292 status=0
293
294 validate_min_max "$stats" "intfield" "0" "98"
295 status=$(($status|$?))
296
297 return $status
298}
299
300function validator_intfield_not
301{
302 stats="$1"
303 status=0
304
305 validate_min_max "$stats" "intfield" "0" "0"
306 status=$(($status|$?))
307
308 return $status
309}
310
311function validator_intfield_gt_and_longfield_gt
312{
313 stats="$1"
314 status=0
315
316 validate_min_max "$stats" "intfield" "43" "99"
317 status=$(($status|$?))
318 validate_min_max "$stats" "longfield" "43" "99"
319 status=$(($status|$?))
320
321 return $status
322}
323
324function validator_intfield_ge_and_longfield_le
325{
326 stats="$1"
327 status=0
328
329 validate_min_max "$stats" "intfield" "42" "42"
330 status=$(($status|$?))
331 validate_min_max "$stats" "longfield" "42" "42"
332 status=$(($status|$?))
333
334 return $status
335}
336
337function validator_intfield_lt_or_longfield_gt
338{
339 stats="$1"
340 status=0
341
342 validate_min_max "$stats" "intfield" "0" "99"
343 status=$(($status|$?))
344 validate_min_max "$stats" "longfield" "0" "99"
345 status=$(($status|$?))
346
347 return $status
348}
349
350function validator_mixed_str_or_int_and_int
351{
352 stats="$1"
353 status=0
354
355 validate_min_max "$stats" "intfield" "34" "99"
356 status=$(($status|$?))
357
358 validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
359 status=$(($status|$?))
360
361 return $status
362}
363
364function validator_mixed_int_double
365{
366 stats="$1"
367 status=0
368
369 validate_min_max "$stats" "intfield" "0" "42"
370 status=$(($status|$?))
371
372 return $status
373}
374
375function validator_true_statement
376{
377 stats="$1"
378 status=0
379
380 validate_min_max "$stats" "intfield" "0" "99"
381 status=$(($status|$?))
382
383 validate_min_max "$stats" "intfield2" "0x0" "0x63"
384 status=$(($status|$?))
385
386 validate_min_max "$stats" "longfield" "0" "99"
387 status=$(($status|$?))
388
389 validate_min_max "$stats" "netintfield" "0" "99"
390 status=$(($status|$?))
391
392 validate_min_max "$stats" "netintfieldhex" "0x0" "0x63"
393 status=$(($status|$?))
394
f6788fc4
MD
395 if [ $KERNEL_CHECK -eq 0 ]; then
396 validate_min_max "$stats" "floatfield" "2222" "2222"
397 status=$(($status|$?))
9fec62f7 398
f6788fc4
MD
399 validate_min_max "$stats" "doublefield" "2" "2"
400 status=$(($status|$?))
401 fi
9fec62f7
CB
402
403 validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
404 status=$(($status|$?))
405
406 validate_min_max "$stats" "stringfield2" ""\*"" ""\*""
407 status=$(($status|$?))
408
409 return $status
410}
411
03276eea
CB
412plan_tests $NUM_TESTS
413
e3bef725
CB
414print_test_banner "$TEST_DESC"
415
9fec62f7
CB
416issue_356_filter="intfield > 0 && intfield > 1 && "
417issue_356_filter+="intfield > 2 && intfield > 3 && "
418issue_356_filter+="intfield > 4 && intfield > 5 && "
419issue_356_filter+="intfield > 6 && intfield > 7 && "
420issue_356_filter+="intfield > 8 || intfield > 0"
421
f6788fc4
MD
422start_lttng_sessiond
423
424### UST TESTS
425
426BIN_NAME="gen-ust-events"
427
ec7fe110
PP
428KIRK_KRAUSS_TESTS=(
429 # the tests below were written by Kirk Krauss in this article:
430 # http://www.drdobbs.com/architecture-and-design/matching-wildcards-an-empirical-way-to-t/240169123
431
432 str_has_events
433 '"abcccd" == "*ccd"'
434
435 str_has_events
436 '"mississipissippi" == "*issip*ss*"'
437
438 str_has_no_event
439 '"xxxx\*zzzzzzzzy\*f" == "xxxx*zzy*fffff"'
440
441 str_has_events
442 '"xxxx\*zzzzzzzzy\*f" == "xxx*zzy*f"'
443
444 str_has_no_event
445 '"xxxxzzzzzzzzyf" == "xxxx*zzy*fffff"'
446
447 str_has_events
448 '"xxxxzzzzzzzzyf" == "xxxx*zzy*f"'
449
450 str_has_events
451 '"xyxyxyzyxyz" == "xy*z*xyz"'
452
453 str_has_events
454 '"mississippi" == "*sip*"'
455
456 str_has_events
457 '"xyxyxyxyz" == "xy*xyz"'
458
459 str_has_events
460 '"mississippi" == "mi*sip*"'
461
462 str_has_events
463 '"ababac" == "*abac*"'
464
465 str_has_events
466 '"ababac" == "*abac*"'
467
468 str_has_events
469 '"aaazz" == "a*zz*"'
470
471 str_has_no_event
472 '"a12b12" == "*12*23"'
473
474 str_has_no_event
475 '"a12b12" == "a12b"'
476
477 str_has_events
478 '"a12b12" == "*12*12*"'
479
480 str_has_events
481 '"\*" == "*"'
482
483 str_has_events
484 '"a\*abab" == "a*b"'
485
486 str_has_events
487 '"a\*r" == "a*"'
488
489 str_has_no_event
490 '"a\*ar" == "a*aar"'
491
492 str_has_events
493 '"XYXYXYZYXYz" == "XY*Z*XYz"'
494
495 str_has_events
496 '"missisSIPpi" == "*SIP*"'
497
498 str_has_events
499 '"mississipPI" == "*issip*PI"'
500
501 str_has_events
502 '"xyxyxyxyz" == "xy*xyz"'
503
504 str_has_events
505 '"miSsissippi" == "mi*sip*"'
506
507 str_has_no_event
508 '"miSsissippi" == "mi*Sip*"'
509
510 str_has_events
511 '"abAbac" == "*Abac*"'
512
513 str_has_events
514 '"abAbac" == "*Abac*"'
515
516 str_has_events
517 '"aAazz" == "a*zz*"'
518
519 str_has_no_event
520 '"A12b12" == "*12*23"'
521
522 str_has_events
523 '"a12B12" == "*12*12*"'
524
525 str_has_events
526 '"oWn" == "*oWn*"'
527
528 str_has_events
529 '"bLah" == "bLah"'
530
531 str_has_no_event
532 '"bLah" == "bLaH"'
533
534 str_has_events
535 '"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab" == "a*a*a*a*a*a*aa*aaa*a*a*b"'
536
537 str_has_events
538 '"abababababababababababababababababababaacacacacacacacadaeafagahaiajakalaaaaaaaaaaaaaaaaaffafagaagggagaaaaaaaab" == "*a*b*ba*ca*a*aa*aaa*fa*ga*b*"'
539
540 str_has_no_event
541 '"abababababababababababababababababababaacacacacacacacadaeafagahaiajakalaaaaaaaaaaaaaaaaaffafagaagggagaaaaaaaab" == "*a*b*ba*ca*a*x*aaa*fa*ga*b*"'
542
543 str_has_no_event
544 '"abababababababababababababababababababaacacacacacacacadaeafagahaiajakalaaaaaaaaaaaaaaaaaffafagaagggagaaaaaaaab" == "*a*b*ba*ca*aaaa*fa*ga*gggg*b*"'
545
546 str_has_events
547 '"abababababababababababababababababababaacacacacacacacadaeafagahaiajakalaaaaaaaaaaaaaaaaaffafagaagggagaaaaaaaab" == "*a*b*ba*ca*aaaa*fa*ga*ggg*b*"'
548
549 str_has_events
550 '"aaabbaabbaab" == "*aabbaa*a*"'
551
552 str_has_events
553 '"a\*a\*a\*a\*a\*a\*a\*a\*a\*a\*a\*a\*a\*a\*a\*a\*a\*" == "a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*"'
554
555 str_has_events
556 '"aaaaaaaaaaaaaaaaa" == "*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*"'
557
558 str_has_no_event
559 '"aaaaaaaaaaaaaaaa" == "*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*"'
560
561 str_has_no_event
562 '"abc\*abcd\*abcde\*abcdef\*abcdefg\*abcdefgh\*abcdefghi\*abcdefghij\*abcdefghijk\*abcdefghijkl\*abcdefghijklm\*abcdefghijklmn" == "abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*"'
563
564 str_has_events
565 '"abc\*abcd\*abcde\*abcdef\*abcdefg\*abcdefgh\*abcdefghi\*abcdefghij\*abcdefghijk\*abcdefghijkl\*abcdefghijklm\*abcdefghijklmn" == "abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*"'
566
567 str_has_no_event
568 '"abc\*abcd\*abcd\*abc\*abcd" == "abc*abc*abc*abc*abc"'
569
570 str_has_events
571 '"abc\*abc\*abc\*abc\*abc\*abc\*abc\*abc\*abc\*abc\*abcd" == "abc*abc*abc*abc*abc*abc*abc*abc*abc*abc*abcd"'
572)
9fec62f7 573
80744d94
JR
574# Set IFS to newline to facilitate array declaration
575OLDIFS="$IFS"
576IFS=$'\n'
ec7fe110
PP
577UST_FILTERS=(
578 intfield
579 "intfield"
580
581 intfield_gt
582 "intfield > 1"
583
584 intfield_ge
585 "intfield >= 1"
586
587 intfield_lt
588 "intfield < 2"
589
590 intfield_le
591 "intfield <= 2"
592
593 intfield_eq
594 "intfield == 1"
595
596 intfield_ne
597 "intfield != 99"
598
599 intfield_not
600 "!intfield"
601
602 intfield
603 "-intfield"
604
605 intfield
606 "--intfield"
607
608 intfield
609 "+intfield"
610
611 intfield
612 "++intfield"
613
614 intfield_gt_and_longfield_gt
615 "intfield > 1 && longfield > 42"
616
617 intfield_ge_and_longfield_le
618 "intfield >= 42 && longfield <= 42"
619
620 intfield_lt_or_longfield_gt
621 "intfield < 1 || longfield > 98"
622
623 mixed_str_or_int_and_int
624 "(stringfield == \"test\" || intfield != 10) && intfield > 33"
625
626 mixed_int_double
627 "intfield < 42.4242424242"
628
629 # Issue #342
630 true_statement
631 "\"test\" == \"test\""
632
633 true_statement
634 "stringfield == \"test\""
635
636 true_statement
637 "stringfield == \"t*\""
638
639 true_statement
640 "stringfield == \"*\""
641
642 # Issue 356
643 intfield
644 $issue_356_filter
645
bff988fa
MD
646 true_statement
647 "1&1"
648
649 true_statement
650 "0|1"
651
652 true_statement
653 "0^1"
654
655 true_statement
656 "seqfield4[1]==2"
657
658 true_statement
659 "arrfield1[1]==2"
660
661 true_statement
662 "arrfield1[1]==2"
663
664 true_statement
665 "arrfield3[1]==2"
666
667 true_statement
668 "seqfield3[1]==2"
669
670 true_statement
671 "1 | (1 | (1 | 1))"
672
673 true_statement
674 "1 >= (1 >= (1 >= 1))"
675
676 true_statement
cea52dd8 677 "(0x101 & 0x100) == 0x100"
bff988fa
MD
678
679 true_statement
cea52dd8 680 "(0x101 | 0x10100) == 0x10101"
bff988fa
MD
681
682 true_statement
cea52dd8 683 "(0xF00F0F ^ 0xFF0F00) == 0x0F000F"
bff988fa 684
116d3c01
MD
685 true_statement
686 "(1 << 1) == 2"
687
688 true_statement
689 "(4 >> 1) == 2"
690
691 true_statement
692 "(1 << 8) == 256"
693
694 true_statement
695 "(262144 >> 16) == 4"
696
697 true_statement
698 "(~0 & 0xffff) == 0xffff"
699
700 true_statement
701 "(~0 & 0xffffffff) == 0xffffffff"
702
703 true_statement
704 "(~0 & 0xffffffffffffffff) == 0xffffffffffffffff"
705
706 true_statement
707 "-1==~0"
708
0358f3d8
MD
709 true_statement # unsigned bitwise ops
710 "~0>>4==0x0fffffffffffffff"
711
712 has_no_event
713 "1<<-1"
714
715 has_no_event
716 "1<<10000"
717
718 true_statement # comparator is signed, shift is unsigned
719 "(1<<63) < 0"
720
116d3c01 721 true_statement
831b702b 722 "(1<<2!=4)==0" # operator priority: shift before equality
116d3c01 723
831b702b
MD
724 true_statement
725 "1&3==1" # operator priority: masks before equality
726
727 true_statement
728 "(3|1==3)==1" # operator priority: masks before equality
729
730 true_statement
731 "(2^1==3)==1" # operator priority: masks before equality
116d3c01
MD
732
733 true_statement
734 "(1 << 32) == 4294967296"
735
736 true_statement
737 "(1 << 63) == 9223372036854775808"
738
bff988fa 739 true_statement
cea52dd8 740 "(arrfield1[2] & 1) == 1"
bff988fa
MD
741
742 true_statement
cea52dd8 743 "(arrfield1[2] | 0x111000) == 0x111003"
bff988fa
MD
744
745 true_statement
746 "(arrfield1[0] | arrfield1[1] | arrfield1[2]) == 0x3"
747
748 true_statement
cea52dd8 749 "(seqfield4[2] & 1) == 1"
bff988fa
MD
750
751 true_statement
cea52dd8 752 "(seqfield4[2] | 0x111000) == 0x111003"
bff988fa 753
ec7fe110
PP
754 true_statement
755 "intfield < 0xDEADBEEF"
756
757 intfield_lt
758 "intfield < 0x2"
759
760 intfield_lt
761 "intfield < 02"
762
763 true_statement
764 "stringfield2 == \"\\\*\""
765
766 true_statement
767 "1.0 || intfield || 1.0"
768
769 intfield_gt
770 "1 < intfield"
771
772 has_no_event
773 "\$ctx.vtid == 0"
774
775 has_events
776 "\$ctx.vtid != 0"
777
778 has_no_event
779 "0 == \$ctx.vtid"
780
781 has_events
782 "0 != \$ctx.vtid"
783
784 has_no_event
785 "\$ctx.vpid == 0"
786
787 has_events
788 "\$ctx.vpid != 0"
789
790 has_no_event
791 "0 == \$ctx.vpid"
792
793 has_events
794 "0 != \$ctx.vpid"
795
796 has_no_event
797 "\$ctx.procname != \"$BIN_NAME\""
798
799 has_events
800 "\$ctx.procname == \"$BIN_NAME\""
801
802 has_no_event
803 "\"$BIN_NAME\" != \$ctx.procname"
804
805 has_events
806 "\"$BIN_NAME\" == \$ctx.procname"
807
808 has_no_event
809 "\$ctx.procname != \"$BIN_NAME*\""
810
811 has_events
812 "\$ctx.procname == \"$BIN_NAME*\""
813
814 has_no_event
815 "\"$BIN_NAME*\" != \$ctx.procname"
816
817 has_events
818 "\"$BIN_NAME*\" == \$ctx.procname"
819
820 has_no_event
821 "\$ctx.procname != \"*\""
822
823 has_events
824 "\$ctx.procname == \"*\""
825
826 has_no_event
827 "\"*\" != \$ctx.procname"
828
829 has_events
830 "\"*\" == \$ctx.procname"
831
832 has_no_event
833 "!a.f.d"
834
835 has_no_event
836 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"
837
838 has_no_event
839 "\$ctx.vtid.blah == 0"
840
841 has_no_event
842 "asdf.asdfsd.sadf < 4"
843
844 has_no_event
845 "0 == \$ctx.vtid.blah"
846
ec7fe110 847 END
9fec62f7
CB
848)
849
ec7fe110
PP
850UST_STR_FILTERS=(
851 str_has_events
852 'str == "hypothecary"'
853
854 str_has_events
855 '"hypothecary" == str'
856
857 str_has_events
858 'str != "hypothecary"'
859
860 str_has_events
861 '"hypothecary" != str'
862
863 str_has_events
864 'str == "*cary"'
865
866 str_has_events
867 '"*cary" == str'
868
869 str_has_events
870 'str != "*cary"'
871
872 str_has_events
873 '"*cary" != str'
874
875 str_has_events
876 'str == "hypo*"'
877
878 str_has_events
879 '"hypo*" == str'
880
881 str_has_events
882 'str != "hypo*"'
883
884 str_has_events
885 '"hypo*" != str'
886
887 str_has_events
888 'str == "*the*"'
889
890 str_has_events
891 '"*the*" == str'
892
893 str_has_events
894 'str != "*the*"'
895
896 str_has_events
897 '"*the*" != str'
898
899 str_has_events
900 'str == "**"'
901
902 str_has_events
903 '"**" == str'
904
905 str_has_no_event
906 'str != "**"'
907
908 str_has_no_event
909 '"**" != str'
910
911 str_has_events
912 'str == "sc*"'
913
914 str_has_events
915 '"sc*" == str'
916
917 str_has_events
918 'str != "sc*"'
919
920 str_has_events
921 '"sc*" != str'
922
923 str_has_events
924 'str == "de*al"'
925
926 str_has_events
927 '"de*al" == str'
928
929 str_has_events
930 'str != "de*al"'
931
932 str_has_events
933 '"de*al" != str'
934
935 str_has_events
936 'str == "*po*siz*"'
937
938 str_has_events
939 '"*po*siz*" == str'
940
941 str_has_events
942 'str != "*po*siz*"'
943
944 str_has_events
945 '"*po*siz*" != str'
946
947 str_has_events
948 'str == "*po***siz*"'
949
950 str_has_events
951 '"*po***siz*" == str'
952
953 str_has_events
954 'str != "*po***siz*"'
955
956 str_has_events
957 '"*po***siz*" != str'
958
959 str_has_no_event
960 'str == "*po*\**siz*"'
961
962 str_has_no_event
963 '"*po*\**siz*" == str'
964
965 str_has_no_event
966 'str == "*zulu*"'
967
968 str_has_no_event
969 '"*zulu*" == str'
970
971 str_has_no_event
972 'str == "8*"'
973
974 str_has_no_event
975 '"8*" == str'
976
977 str_has_no_event
978 'str == "*8"'
979
980 str_has_no_event
981 '"*8" == str'
982
983 str_has_no_event
984 'str == "de\*al"'
985
986 str_has_no_event
987 '"de\*al" == str'
988
989 str_has_events
990 '"salut*" == "salut vous"'
991
992 str_has_events
993 '"salut*" == "salut vous*"'
994
995 str_has_events
996 '"salut vous*" == "salut*"'
997
998 ${KIRK_KRAUSS_TESTS[@]}
999
1000 END
1001)
f6788fc4
MD
1002
1003if [ ! -x "$CURDIR/$BIN_NAME" ]; then
1004 BAIL_OUT "No UST nevents binary detected."
1005fi
1006
80744d94
JR
1007IFS="$OLDIFS"
1008
f6788fc4 1009diag "Test UST valid filters"
9fec62f7 1010
f6788fc4
MD
1011KERNEL_CHECK=0
1012i=0
ec7fe110
PP
1013while true; do
1014 validator="${UST_FILTERS[$i]}"
1015
1016 if [ "$validator" = END ]; then
1017 break
1018 fi
9fec62f7 1019
ec7fe110
PP
1020 filter="${UST_FILTERS[$(( i + 1 ))]}"
1021 test_valid_filter ust -u "tp:tptest" "$filter" "validator_$validator"
9fec62f7
CB
1022
1023 if [ $? -eq 1 ]; then
1024 stop_lttng_sessiond
1025 exit 1
1026 fi
1027
ec7fe110 1028 i=$(( i + 2 ))
9fec62f7
CB
1029done
1030
ec7fe110
PP
1031i=0
1032while true; do
1033 validator="${UST_STR_FILTERS[$i]}"
1034
1035 if [ "$validator" = END ]; then
1036 break
1037 fi
1038
1039 filter="${UST_STR_FILTERS[$(( i + 1 ))]}"
1040 test_valid_filter ust_str -u "tp:the_string" "$filter" "validator_$validator"
1041
1042 if [ $? -eq 1 ]; then
1043 stop_lttng_sessiond
1044 exit 1
1045 fi
1046
1047 i=$(( i + 2 ))
1048done
f6788fc4
MD
1049
1050### KERNEL TESTS
1051
1052BIN_NAME="test_valid_filt" # Current script name truncated by kernel
1053
1054# One to one mapping between filters and validators
80744d94
JR
1055# Set IFS to newline to facilitate array declaration
1056OLDIFS="$IFS"
1057IFS=$'\n'
ec7fe110
PP
1058KERNEL_FILTERS=(
1059 intfield
1060 "intfield"
1061
1062 intfield_gt
1063 "intfield > 1"
1064
1065 intfield_ge
1066 "intfield >= 1"
1067
1068 intfield_lt
1069 "intfield < 2"
1070
1071 intfield_le
1072 "intfield <= 2"
1073
1074 intfield_eq
1075 "intfield == 1"
1076
1077 intfield_ne
1078 "intfield != 99"
1079
1080 intfield_not
1081 "!intfield"
1082
1083 intfield
1084 "-intfield"
1085
1086 intfield
1087 "--intfield"
1088
1089 intfield
1090 "+intfield"
1091
1092 intfield
1093 "++intfield"
1094
1095 intfield_gt_and_longfield_gt
1096 "intfield > 1 && longfield > 42"
1097
1098 intfield_ge_and_longfield_le
1099 "intfield >= 42 && longfield <= 42"
1100
1101 intfield_lt_or_longfield_gt
1102 "intfield < 1 || longfield > 98"
1103
1104 mixed_str_or_int_and_int
1105 "(stringfield == \"test\" || intfield != 10) && intfield > 33"
1106
1107 has_no_event
1108 "intfield < 42.4242424242"
1109
1110 true_statement
1111 "\"test\" == \"test\""
1112
1113 true_statement
1114 "stringfield == \"test\""
1115
1116 true_statement
1117 "stringfield == \"t*\""
1118
1119 true_statement
1120 "stringfield == \"*\""
1121
1122 intfield
1123 $issue_356_filter
1124
bff988fa
MD
1125 true_statement
1126 "1&1"
1127
1128 true_statement
1129 "0|1"
1130
1131 true_statement
1132 "0^1"
1133
1134 true_statement
1135 "seqfield4[1]==2"
1136
1137 true_statement
1138 "arrfield1[1]==2"
1139
1140 true_statement
1141 "arrfield1[1]==2"
1142
1143 true_statement
1144 "arrfield3[1]==2"
1145
1146 true_statement
1147 "seqfield3[1]==2"
1148
1149 true_statement
1150 "1 | (1 | (1 | 1))"
1151
1152 true_statement
1153 "1 >= (1 >= (1 >= 1))"
1154
1155 true_statement
cea52dd8 1156 "(0x101 & 0x100) == 0x100"
bff988fa
MD
1157
1158 true_statement
cea52dd8 1159 "(0x101 | 0x10100) == 0x10101"
bff988fa
MD
1160
1161 true_statement
cea52dd8 1162 "(0xF00F0F ^ 0xFF0F00) == 0x0F000F"
bff988fa 1163
116d3c01
MD
1164 true_statement
1165 "(1 << 1) == 2"
1166
1167 true_statement
1168 "(4 >> 1) == 2"
1169
1170 true_statement
1171 "(1 << 8) == 256"
1172
1173 true_statement
1174 "(262144 >> 16) == 4"
1175
1176 true_statement
1177 "(~0 & 0xffff) == 0xffff"
1178
1179 true_statement
1180 "(~0 & 0xffffffff) == 0xffffffff"
1181
1182 true_statement
1183 "(~0 & 0xffffffffffffffff) == 0xffffffffffffffff"
1184
1185 true_statement
1186 "-1==~0"
1187
0358f3d8
MD
1188 true_statement # unsigned bitwise ops
1189 "~0>>4==0x0fffffffffffffff"
1190
1191 has_no_event
1192 "1<<-1"
1193
1194 has_no_event
1195 "1<<10000"
1196
1197 true_statement # comparator is signed, shift is unsigned
1198 "(1<<63) < 0"
1199
116d3c01 1200 true_statement
831b702b 1201 "(1<<2!=4)==0" # operator priority: shift before equality
116d3c01 1202
831b702b
MD
1203 true_statement
1204 "1&3==1" # operator priority: masks before equality
1205
1206 true_statement
1207 "(3|1==3)==1" # operator priority: masks before equality
1208
1209 true_statement
1210 "(2^1==3)==1" # operator priority: masks before equality
116d3c01
MD
1211
1212 true_statement
1213 "(1 << 32) == 4294967296"
1214
1215 true_statement
1216 "(1 << 63) == 9223372036854775808"
1217
bff988fa 1218 true_statement
cea52dd8 1219 "(arrfield1[2] & 1) == 1"
bff988fa
MD
1220
1221 true_statement
cea52dd8 1222 "(arrfield1[2] | 0x111000) == 0x111003"
bff988fa
MD
1223
1224 true_statement
1225 "(arrfield1[0] | arrfield1[1] | arrfield1[2]) == 0x3"
1226
1227 true_statement
cea52dd8 1228 "(seqfield4[2] & 1) == 1"
bff988fa
MD
1229
1230 true_statement
cea52dd8 1231 "(seqfield4[2] | 0x111000) == 0x111003"
bff988fa 1232
ec7fe110
PP
1233 true_statement
1234 "intfield < 0xDEADBEEF"
1235
1236 intfield_lt
1237 "intfield < 0x2"
1238
1239 intfield_lt
1240 "intfield < 02"
f6788fc4 1241
ec7fe110
PP
1242 true_statement
1243 "stringfield2 == \"\\\*\""
1244
1245 has_no_event
1246 "1.0 || intfield || 1.0"
1247
1248 intfield_gt
1249 "1 < intfield"
1250
1251 has_no_event
1252 "\$ctx.vtid == 0"
1253
1254 has_events
1255 "\$ctx.vtid != 0"
1256
1257 has_no_event
1258 "0 == \$ctx.vtid"
1259
1260 has_events
1261 "0 != \$ctx.vtid"
1262
1263 has_no_event
1264 "\$ctx.vpid == 0"
1265
1266 has_events
1267 "\$ctx.vpid != 0"
1268
1269 has_no_event
1270 "0 == \$ctx.vpid"
1271
1272 has_events
1273 "0 != \$ctx.vpid"
1274
1275 has_no_event
1276 "\$ctx.procname != \"$BIN_NAME\""
1277
1278 has_events
1279 "\$ctx.procname == \"$BIN_NAME\""
1280
1281 has_no_event
1282 "\"$BIN_NAME\" != \$ctx.procname"
1283
1284 has_events
1285 "\"$BIN_NAME\" == \$ctx.procname"
1286
1287 has_no_event
1288 "\$ctx.procname != \"$BIN_NAME*\""
1289
1290 has_events
1291 "\$ctx.procname == \"$BIN_NAME*\""
1292
1293 has_no_event
1294 "\"$BIN_NAME*\" != \$ctx.procname"
1295
1296 has_events
1297 "\"$BIN_NAME*\" == \$ctx.procname"
1298
1299 has_no_event
1300 "\$ctx.procname != \"*\""
1301
1302 has_events
1303 "\$ctx.procname == \"*\""
1304
1305 has_no_event
1306 "\"*\" != \$ctx.procname"
1307
1308 has_events
1309 "\"*\" == \$ctx.procname"
1310
1311 has_no_event
1312 "!a.f.d"
1313
1314 has_no_event
1315 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"
1316
1317 has_no_event
1318 "\$ctx.vtid.blah == 0"
1319
1320 has_no_event
1321 "asdf.asdfsd.sadf < 4"
1322
1323 has_no_event
1324 "0 == \$ctx.vtid.blah"
1325
ec7fe110
PP
1326 stringfield_has_events
1327 'stringfield == "test"'
1328
1329 stringfield_has_events
1330 '"test" == stringfield'
1331
1332 has_no_event
1333 'stringfield != "test"'
1334
1335 has_no_event
1336 '"test" != stringfield'
1337
1338 stringfield_has_events
1339 'stringfield == "*st"'
1340
1341 stringfield_has_events
1342 '"*st" == stringfield'
1343
1344 has_no_event
1345 'stringfield != "*st"'
1346
1347 has_no_event
1348 '"*st" != stringfield'
1349
1350 stringfield_has_events
1351 'stringfield == "te*"'
1352
1353 stringfield_has_events
1354 '"te*" == stringfield'
1355
1356 has_no_event
1357 'stringfield != "te*"'
1358
1359 has_no_event
1360 '"te*" != stringfield'
1361
1362 stringfield_has_events
1363 'stringfield == "te*t"'
1364
1365 stringfield_has_events
1366 '"te*t" == stringfield'
1367
1368 has_no_event
1369 'stringfield != "te*t"'
1370
1371 has_no_event
1372 '"te*t" != stringfield'
1373
1374 stringfield_has_events
1375 'stringfield == "tes*t"'
1376
1377 stringfield_has_events
1378 '"tes*t" == stringfield'
1379
1380 has_no_event
1381 'stringfield != "tes*t"'
1382
1383 has_no_event
1384 '"tes*t" != stringfield'
1385
1386 stringfield_has_events
1387 'stringfield == "*test"'
1388
1389 stringfield_has_events
1390 '"*test" == stringfield'
1391
1392 has_no_event
1393 'stringfield != "*test"'
1394
1395 has_no_event
1396 '"*test" != stringfield'
1397
1398 stringfield_has_events
1399 'stringfield == "test*"'
1400
1401 stringfield_has_events
1402 '"test*" == stringfield'
1403
1404 has_no_event
1405 'stringfield != "test*"'
1406
1407 has_no_event
1408 '"test*" != stringfield'
1409
1410 stringfield_has_events
1411 'stringfield == "*"'
1412
1413 stringfield_has_events
1414 '"*" == stringfield'
1415
1416 has_no_event
1417 'stringfield != "*"'
1418
1419 has_no_event
1420 '"*" != stringfield'
1421
1422 has_no_event
1423 'stringfield == "test*2"'
1424
1425 has_no_event
1426 'stringfield == "2*test"'
1427
1428 has_no_event
1429 'stringfield == "te\*st"'
1430
1431 has_no_event
1432 'stringfield == "te*ts"'
1433
1434 has_no_event
1435 'stringfield == "*\*test"'
1436
1437 has_no_event
1438 'stringfield == "test\*"'
1439
1440 ${KIRK_KRAUSS_TESTS[@]}
1441
1442 END
f6788fc4
MD
1443)
1444
80744d94
JR
1445IFS=$OLDIFS
1446
f6788fc4
MD
1447if [ "$(id -u)" == "0" ]; then
1448 isroot=1
1449else
1450 isroot=0
1451fi
1452
1453skip $isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS ||
1454{
1455 diag "Test kernel valid filters"
1456
1457 KERNEL_CHECK=1
1458 modprobe lttng-test
ec7fe110 1459
f6788fc4 1460 i=0
ec7fe110
PP
1461 while true; do
1462 validator="${KERNEL_FILTERS[$i]}"
1463
1464 if [ "$validator" = END ]; then
1465 break
1466 fi
f6788fc4 1467
ec7fe110
PP
1468 filter="${KERNEL_FILTERS[$(( i + 1 ))]}"
1469 test_valid_filter kernel -k "lttng_test_filter_event" "$filter" "validator_$validator"
f6788fc4
MD
1470
1471 if [ $? -eq 1 ]; then
1472 stop_lttng_sessiond
1473 exit 1
1474 fi
1475
ec7fe110 1476 i=$(( i + 2 ))
f6788fc4 1477 done
ec7fe110 1478
f6788fc4
MD
1479 rmmod lttng-test
1480}
1481
9fec62f7 1482stop_lttng_sessiond
This page took 0.157857 seconds and 4 git commands to generate.