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