Filter: Update shifting tests
[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
0358f3d8
MD
27NUM_UST_TESTS=1098
28NUM_KERNEL_TESTS=1032
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
MD
721 true_statement
722 "1<<1==2" # C99 operator priority: comparator before bitwise
723
724 has_no_event
725 "!(1<<1==2)" # C99 operator priority: comparator before bitwise
726
727 true_statement
728 "(1 << 32) == 4294967296"
729
730 true_statement
731 "(1 << 63) == 9223372036854775808"
732
bff988fa 733 true_statement
cea52dd8 734 "(arrfield1[2] & 1) == 1"
bff988fa
MD
735
736 true_statement
cea52dd8 737 "(arrfield1[2] | 0x111000) == 0x111003"
bff988fa
MD
738
739 true_statement
740 "(arrfield1[0] | arrfield1[1] | arrfield1[2]) == 0x3"
741
742 true_statement
cea52dd8 743 "(seqfield4[2] & 1) == 1"
bff988fa
MD
744
745 true_statement
cea52dd8 746 "(seqfield4[2] | 0x111000) == 0x111003"
bff988fa 747
ec7fe110
PP
748 true_statement
749 "intfield < 0xDEADBEEF"
750
751 intfield_lt
752 "intfield < 0x2"
753
754 intfield_lt
755 "intfield < 02"
756
757 true_statement
758 "stringfield2 == \"\\\*\""
759
760 true_statement
761 "1.0 || intfield || 1.0"
762
763 intfield_gt
764 "1 < intfield"
765
766 has_no_event
767 "\$ctx.vtid == 0"
768
769 has_events
770 "\$ctx.vtid != 0"
771
772 has_no_event
773 "0 == \$ctx.vtid"
774
775 has_events
776 "0 != \$ctx.vtid"
777
778 has_no_event
779 "\$ctx.vpid == 0"
780
781 has_events
782 "\$ctx.vpid != 0"
783
784 has_no_event
785 "0 == \$ctx.vpid"
786
787 has_events
788 "0 != \$ctx.vpid"
789
790 has_no_event
791 "\$ctx.procname != \"$BIN_NAME\""
792
793 has_events
794 "\$ctx.procname == \"$BIN_NAME\""
795
796 has_no_event
797 "\"$BIN_NAME\" != \$ctx.procname"
798
799 has_events
800 "\"$BIN_NAME\" == \$ctx.procname"
801
802 has_no_event
803 "\$ctx.procname != \"$BIN_NAME*\""
804
805 has_events
806 "\$ctx.procname == \"$BIN_NAME*\""
807
808 has_no_event
809 "\"$BIN_NAME*\" != \$ctx.procname"
810
811 has_events
812 "\"$BIN_NAME*\" == \$ctx.procname"
813
814 has_no_event
815 "\$ctx.procname != \"*\""
816
817 has_events
818 "\$ctx.procname == \"*\""
819
820 has_no_event
821 "\"*\" != \$ctx.procname"
822
823 has_events
824 "\"*\" == \$ctx.procname"
825
826 has_no_event
827 "!a.f.d"
828
829 has_no_event
830 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"
831
832 has_no_event
833 "\$ctx.vtid.blah == 0"
834
835 has_no_event
836 "asdf.asdfsd.sadf < 4"
837
838 has_no_event
839 "0 == \$ctx.vtid.blah"
840
ec7fe110 841 END
9fec62f7
CB
842)
843
ec7fe110
PP
844UST_STR_FILTERS=(
845 str_has_events
846 'str == "hypothecary"'
847
848 str_has_events
849 '"hypothecary" == str'
850
851 str_has_events
852 'str != "hypothecary"'
853
854 str_has_events
855 '"hypothecary" != str'
856
857 str_has_events
858 'str == "*cary"'
859
860 str_has_events
861 '"*cary" == str'
862
863 str_has_events
864 'str != "*cary"'
865
866 str_has_events
867 '"*cary" != str'
868
869 str_has_events
870 'str == "hypo*"'
871
872 str_has_events
873 '"hypo*" == str'
874
875 str_has_events
876 'str != "hypo*"'
877
878 str_has_events
879 '"hypo*" != str'
880
881 str_has_events
882 'str == "*the*"'
883
884 str_has_events
885 '"*the*" == str'
886
887 str_has_events
888 'str != "*the*"'
889
890 str_has_events
891 '"*the*" != str'
892
893 str_has_events
894 'str == "**"'
895
896 str_has_events
897 '"**" == str'
898
899 str_has_no_event
900 'str != "**"'
901
902 str_has_no_event
903 '"**" != str'
904
905 str_has_events
906 'str == "sc*"'
907
908 str_has_events
909 '"sc*" == str'
910
911 str_has_events
912 'str != "sc*"'
913
914 str_has_events
915 '"sc*" != str'
916
917 str_has_events
918 'str == "de*al"'
919
920 str_has_events
921 '"de*al" == 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 == "*po*siz*"'
931
932 str_has_events
933 '"*po*siz*" == 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_no_event
954 'str == "*po*\**siz*"'
955
956 str_has_no_event
957 '"*po*\**siz*" == str'
958
959 str_has_no_event
960 'str == "*zulu*"'
961
962 str_has_no_event
963 '"*zulu*" == str'
964
965 str_has_no_event
966 'str == "8*"'
967
968 str_has_no_event
969 '"8*" == 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 == "de\*al"'
979
980 str_has_no_event
981 '"de\*al" == str'
982
983 str_has_events
984 '"salut*" == "salut vous"'
985
986 str_has_events
987 '"salut*" == "salut vous*"'
988
989 str_has_events
990 '"salut vous*" == "salut*"'
991
992 ${KIRK_KRAUSS_TESTS[@]}
993
994 END
995)
f6788fc4
MD
996
997if [ ! -x "$CURDIR/$BIN_NAME" ]; then
998 BAIL_OUT "No UST nevents binary detected."
999fi
1000
80744d94
JR
1001IFS="$OLDIFS"
1002
f6788fc4 1003diag "Test UST valid filters"
9fec62f7 1004
f6788fc4
MD
1005KERNEL_CHECK=0
1006i=0
ec7fe110
PP
1007while true; do
1008 validator="${UST_FILTERS[$i]}"
1009
1010 if [ "$validator" = END ]; then
1011 break
1012 fi
9fec62f7 1013
ec7fe110
PP
1014 filter="${UST_FILTERS[$(( i + 1 ))]}"
1015 test_valid_filter ust -u "tp:tptest" "$filter" "validator_$validator"
9fec62f7
CB
1016
1017 if [ $? -eq 1 ]; then
1018 stop_lttng_sessiond
1019 exit 1
1020 fi
1021
ec7fe110 1022 i=$(( i + 2 ))
9fec62f7
CB
1023done
1024
ec7fe110
PP
1025i=0
1026while true; do
1027 validator="${UST_STR_FILTERS[$i]}"
1028
1029 if [ "$validator" = END ]; then
1030 break
1031 fi
1032
1033 filter="${UST_STR_FILTERS[$(( i + 1 ))]}"
1034 test_valid_filter ust_str -u "tp:the_string" "$filter" "validator_$validator"
1035
1036 if [ $? -eq 1 ]; then
1037 stop_lttng_sessiond
1038 exit 1
1039 fi
1040
1041 i=$(( i + 2 ))
1042done
f6788fc4
MD
1043
1044### KERNEL TESTS
1045
1046BIN_NAME="test_valid_filt" # Current script name truncated by kernel
1047
1048# One to one mapping between filters and validators
80744d94
JR
1049# Set IFS to newline to facilitate array declaration
1050OLDIFS="$IFS"
1051IFS=$'\n'
ec7fe110
PP
1052KERNEL_FILTERS=(
1053 intfield
1054 "intfield"
1055
1056 intfield_gt
1057 "intfield > 1"
1058
1059 intfield_ge
1060 "intfield >= 1"
1061
1062 intfield_lt
1063 "intfield < 2"
1064
1065 intfield_le
1066 "intfield <= 2"
1067
1068 intfield_eq
1069 "intfield == 1"
1070
1071 intfield_ne
1072 "intfield != 99"
1073
1074 intfield_not
1075 "!intfield"
1076
1077 intfield
1078 "-intfield"
1079
1080 intfield
1081 "--intfield"
1082
1083 intfield
1084 "+intfield"
1085
1086 intfield
1087 "++intfield"
1088
1089 intfield_gt_and_longfield_gt
1090 "intfield > 1 && longfield > 42"
1091
1092 intfield_ge_and_longfield_le
1093 "intfield >= 42 && longfield <= 42"
1094
1095 intfield_lt_or_longfield_gt
1096 "intfield < 1 || longfield > 98"
1097
1098 mixed_str_or_int_and_int
1099 "(stringfield == \"test\" || intfield != 10) && intfield > 33"
1100
1101 has_no_event
1102 "intfield < 42.4242424242"
1103
1104 true_statement
1105 "\"test\" == \"test\""
1106
1107 true_statement
1108 "stringfield == \"test\""
1109
1110 true_statement
1111 "stringfield == \"t*\""
1112
1113 true_statement
1114 "stringfield == \"*\""
1115
1116 intfield
1117 $issue_356_filter
1118
bff988fa
MD
1119 true_statement
1120 "1&1"
1121
1122 true_statement
1123 "0|1"
1124
1125 true_statement
1126 "0^1"
1127
1128 true_statement
1129 "seqfield4[1]==2"
1130
1131 true_statement
1132 "arrfield1[1]==2"
1133
1134 true_statement
1135 "arrfield1[1]==2"
1136
1137 true_statement
1138 "arrfield3[1]==2"
1139
1140 true_statement
1141 "seqfield3[1]==2"
1142
1143 true_statement
1144 "1 | (1 | (1 | 1))"
1145
1146 true_statement
1147 "1 >= (1 >= (1 >= 1))"
1148
1149 true_statement
cea52dd8 1150 "(0x101 & 0x100) == 0x100"
bff988fa
MD
1151
1152 true_statement
cea52dd8 1153 "(0x101 | 0x10100) == 0x10101"
bff988fa
MD
1154
1155 true_statement
cea52dd8 1156 "(0xF00F0F ^ 0xFF0F00) == 0x0F000F"
bff988fa 1157
116d3c01
MD
1158 true_statement
1159 "(1 << 1) == 2"
1160
1161 true_statement
1162 "(4 >> 1) == 2"
1163
1164 true_statement
1165 "(1 << 8) == 256"
1166
1167 true_statement
1168 "(262144 >> 16) == 4"
1169
1170 true_statement
1171 "(~0 & 0xffff) == 0xffff"
1172
1173 true_statement
1174 "(~0 & 0xffffffff) == 0xffffffff"
1175
1176 true_statement
1177 "(~0 & 0xffffffffffffffff) == 0xffffffffffffffff"
1178
1179 true_statement
1180 "-1==~0"
1181
0358f3d8
MD
1182 true_statement # unsigned bitwise ops
1183 "~0>>4==0x0fffffffffffffff"
1184
1185 has_no_event
1186 "1<<-1"
1187
1188 has_no_event
1189 "1<<10000"
1190
1191 true_statement # comparator is signed, shift is unsigned
1192 "(1<<63) < 0"
1193
116d3c01
MD
1194 true_statement
1195 "1<<1==2" # C99 operator priority: comparator before bitwise
1196
1197 has_no_event
1198 "!(1<<1==2)" # C99 operator priority: comparator before bitwise
1199
1200 true_statement
1201 "(1 << 32) == 4294967296"
1202
1203 true_statement
1204 "(1 << 63) == 9223372036854775808"
1205
bff988fa 1206 true_statement
cea52dd8 1207 "(arrfield1[2] & 1) == 1"
bff988fa
MD
1208
1209 true_statement
cea52dd8 1210 "(arrfield1[2] | 0x111000) == 0x111003"
bff988fa
MD
1211
1212 true_statement
1213 "(arrfield1[0] | arrfield1[1] | arrfield1[2]) == 0x3"
1214
1215 true_statement
cea52dd8 1216 "(seqfield4[2] & 1) == 1"
bff988fa
MD
1217
1218 true_statement
cea52dd8 1219 "(seqfield4[2] | 0x111000) == 0x111003"
bff988fa 1220
ec7fe110
PP
1221 true_statement
1222 "intfield < 0xDEADBEEF"
1223
1224 intfield_lt
1225 "intfield < 0x2"
1226
1227 intfield_lt
1228 "intfield < 02"
f6788fc4 1229
ec7fe110
PP
1230 true_statement
1231 "stringfield2 == \"\\\*\""
1232
1233 has_no_event
1234 "1.0 || intfield || 1.0"
1235
1236 intfield_gt
1237 "1 < intfield"
1238
1239 has_no_event
1240 "\$ctx.vtid == 0"
1241
1242 has_events
1243 "\$ctx.vtid != 0"
1244
1245 has_no_event
1246 "0 == \$ctx.vtid"
1247
1248 has_events
1249 "0 != \$ctx.vtid"
1250
1251 has_no_event
1252 "\$ctx.vpid == 0"
1253
1254 has_events
1255 "\$ctx.vpid != 0"
1256
1257 has_no_event
1258 "0 == \$ctx.vpid"
1259
1260 has_events
1261 "0 != \$ctx.vpid"
1262
1263 has_no_event
1264 "\$ctx.procname != \"$BIN_NAME\""
1265
1266 has_events
1267 "\$ctx.procname == \"$BIN_NAME\""
1268
1269 has_no_event
1270 "\"$BIN_NAME\" != \$ctx.procname"
1271
1272 has_events
1273 "\"$BIN_NAME\" == \$ctx.procname"
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 != \"*\""
1289
1290 has_events
1291 "\$ctx.procname == \"*\""
1292
1293 has_no_event
1294 "\"*\" != \$ctx.procname"
1295
1296 has_events
1297 "\"*\" == \$ctx.procname"
1298
1299 has_no_event
1300 "!a.f.d"
1301
1302 has_no_event
1303 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"
1304
1305 has_no_event
1306 "\$ctx.vtid.blah == 0"
1307
1308 has_no_event
1309 "asdf.asdfsd.sadf < 4"
1310
1311 has_no_event
1312 "0 == \$ctx.vtid.blah"
1313
ec7fe110
PP
1314 stringfield_has_events
1315 'stringfield == "test"'
1316
1317 stringfield_has_events
1318 '"test" == stringfield'
1319
1320 has_no_event
1321 'stringfield != "test"'
1322
1323 has_no_event
1324 '"test" != stringfield'
1325
1326 stringfield_has_events
1327 'stringfield == "*st"'
1328
1329 stringfield_has_events
1330 '"*st" == stringfield'
1331
1332 has_no_event
1333 'stringfield != "*st"'
1334
1335 has_no_event
1336 '"*st" != stringfield'
1337
1338 stringfield_has_events
1339 'stringfield == "te*"'
1340
1341 stringfield_has_events
1342 '"te*" == stringfield'
1343
1344 has_no_event
1345 'stringfield != "te*"'
1346
1347 has_no_event
1348 '"te*" != stringfield'
1349
1350 stringfield_has_events
1351 'stringfield == "te*t"'
1352
1353 stringfield_has_events
1354 '"te*t" == stringfield'
1355
1356 has_no_event
1357 'stringfield != "te*t"'
1358
1359 has_no_event
1360 '"te*t" != stringfield'
1361
1362 stringfield_has_events
1363 'stringfield == "tes*t"'
1364
1365 stringfield_has_events
1366 '"tes*t" == stringfield'
1367
1368 has_no_event
1369 'stringfield != "tes*t"'
1370
1371 has_no_event
1372 '"tes*t" != stringfield'
1373
1374 stringfield_has_events
1375 'stringfield == "*test"'
1376
1377 stringfield_has_events
1378 '"*test" == stringfield'
1379
1380 has_no_event
1381 'stringfield != "*test"'
1382
1383 has_no_event
1384 '"*test" != 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 == "*"'
1400
1401 stringfield_has_events
1402 '"*" == stringfield'
1403
1404 has_no_event
1405 'stringfield != "*"'
1406
1407 has_no_event
1408 '"*" != stringfield'
1409
1410 has_no_event
1411 'stringfield == "test*2"'
1412
1413 has_no_event
1414 'stringfield == "2*test"'
1415
1416 has_no_event
1417 'stringfield == "te\*st"'
1418
1419 has_no_event
1420 'stringfield == "te*ts"'
1421
1422 has_no_event
1423 'stringfield == "*\*test"'
1424
1425 has_no_event
1426 'stringfield == "test\*"'
1427
1428 ${KIRK_KRAUSS_TESTS[@]}
1429
1430 END
f6788fc4
MD
1431)
1432
80744d94
JR
1433IFS=$OLDIFS
1434
f6788fc4
MD
1435if [ "$(id -u)" == "0" ]; then
1436 isroot=1
1437else
1438 isroot=0
1439fi
1440
1441skip $isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS ||
1442{
1443 diag "Test kernel valid filters"
1444
1445 KERNEL_CHECK=1
1446 modprobe lttng-test
ec7fe110 1447
f6788fc4 1448 i=0
ec7fe110
PP
1449 while true; do
1450 validator="${KERNEL_FILTERS[$i]}"
1451
1452 if [ "$validator" = END ]; then
1453 break
1454 fi
f6788fc4 1455
ec7fe110
PP
1456 filter="${KERNEL_FILTERS[$(( i + 1 ))]}"
1457 test_valid_filter kernel -k "lttng_test_filter_event" "$filter" "validator_$validator"
f6788fc4
MD
1458
1459 if [ $? -eq 1 ]; then
1460 stop_lttng_sessiond
1461 exit 1
1462 fi
1463
ec7fe110 1464 i=$(( i + 2 ))
f6788fc4 1465 done
ec7fe110 1466
f6788fc4
MD
1467 rmmod lttng-test
1468}
1469
9fec62f7 1470stop_lttng_sessiond
This page took 0.107505 seconds and 5 git commands to generate.