Implement support for brackets in filter 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
ec7fe110
PP
27NUM_UST_TESTS=906
28NUM_KERNEL_TESTS=840
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
646 true_statement
647 "intfield < 0xDEADBEEF"
648
649 intfield_lt
650 "intfield < 0x2"
651
652 intfield_lt
653 "intfield < 02"
654
655 true_statement
656 "stringfield2 == \"\\\*\""
657
658 true_statement
659 "1.0 || intfield || 1.0"
660
661 intfield_gt
662 "1 < intfield"
663
664 has_no_event
665 "\$ctx.vtid == 0"
666
667 has_events
668 "\$ctx.vtid != 0"
669
670 has_no_event
671 "0 == \$ctx.vtid"
672
673 has_events
674 "0 != \$ctx.vtid"
675
676 has_no_event
677 "\$ctx.vpid == 0"
678
679 has_events
680 "\$ctx.vpid != 0"
681
682 has_no_event
683 "0 == \$ctx.vpid"
684
685 has_events
686 "0 != \$ctx.vpid"
687
688 has_no_event
689 "\$ctx.procname != \"$BIN_NAME\""
690
691 has_events
692 "\$ctx.procname == \"$BIN_NAME\""
693
694 has_no_event
695 "\"$BIN_NAME\" != \$ctx.procname"
696
697 has_events
698 "\"$BIN_NAME\" == \$ctx.procname"
699
700 has_no_event
701 "\$ctx.procname != \"$BIN_NAME*\""
702
703 has_events
704 "\$ctx.procname == \"$BIN_NAME*\""
705
706 has_no_event
707 "\"$BIN_NAME*\" != \$ctx.procname"
708
709 has_events
710 "\"$BIN_NAME*\" == \$ctx.procname"
711
712 has_no_event
713 "\$ctx.procname != \"*\""
714
715 has_events
716 "\$ctx.procname == \"*\""
717
718 has_no_event
719 "\"*\" != \$ctx.procname"
720
721 has_events
722 "\"*\" == \$ctx.procname"
723
724 has_no_event
725 "!a.f.d"
726
727 has_no_event
728 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"
729
730 has_no_event
731 "\$ctx.vtid.blah == 0"
732
733 has_no_event
734 "asdf.asdfsd.sadf < 4"
735
736 has_no_event
737 "0 == \$ctx.vtid.blah"
738
739 has_no_event
740 "\$ctx.44 == 0"
741
742 has_no_event
743 "0 == \$ctx.44"
744
745 END
9fec62f7
CB
746)
747
ec7fe110
PP
748UST_STR_FILTERS=(
749 str_has_events
750 'str == "hypothecary"'
751
752 str_has_events
753 '"hypothecary" == str'
754
755 str_has_events
756 'str != "hypothecary"'
757
758 str_has_events
759 '"hypothecary" != str'
760
761 str_has_events
762 'str == "*cary"'
763
764 str_has_events
765 '"*cary" == str'
766
767 str_has_events
768 'str != "*cary"'
769
770 str_has_events
771 '"*cary" != str'
772
773 str_has_events
774 'str == "hypo*"'
775
776 str_has_events
777 '"hypo*" == str'
778
779 str_has_events
780 'str != "hypo*"'
781
782 str_has_events
783 '"hypo*" != str'
784
785 str_has_events
786 'str == "*the*"'
787
788 str_has_events
789 '"*the*" == str'
790
791 str_has_events
792 'str != "*the*"'
793
794 str_has_events
795 '"*the*" != str'
796
797 str_has_events
798 'str == "**"'
799
800 str_has_events
801 '"**" == str'
802
803 str_has_no_event
804 'str != "**"'
805
806 str_has_no_event
807 '"**" != str'
808
809 str_has_events
810 'str == "sc*"'
811
812 str_has_events
813 '"sc*" == str'
814
815 str_has_events
816 'str != "sc*"'
817
818 str_has_events
819 '"sc*" != str'
820
821 str_has_events
822 'str == "de*al"'
823
824 str_has_events
825 '"de*al" == str'
826
827 str_has_events
828 'str != "de*al"'
829
830 str_has_events
831 '"de*al" != str'
832
833 str_has_events
834 'str == "*po*siz*"'
835
836 str_has_events
837 '"*po*siz*" == str'
838
839 str_has_events
840 'str != "*po*siz*"'
841
842 str_has_events
843 '"*po*siz*" != str'
844
845 str_has_events
846 'str == "*po***siz*"'
847
848 str_has_events
849 '"*po***siz*" == str'
850
851 str_has_events
852 'str != "*po***siz*"'
853
854 str_has_events
855 '"*po***siz*" != str'
856
857 str_has_no_event
858 'str == "*po*\**siz*"'
859
860 str_has_no_event
861 '"*po*\**siz*" == str'
862
863 str_has_no_event
864 'str == "*zulu*"'
865
866 str_has_no_event
867 '"*zulu*" == str'
868
869 str_has_no_event
870 'str == "8*"'
871
872 str_has_no_event
873 '"8*" == str'
874
875 str_has_no_event
876 'str == "*8"'
877
878 str_has_no_event
879 '"*8" == str'
880
881 str_has_no_event
882 'str == "de\*al"'
883
884 str_has_no_event
885 '"de\*al" == str'
886
887 str_has_events
888 '"salut*" == "salut vous"'
889
890 str_has_events
891 '"salut*" == "salut vous*"'
892
893 str_has_events
894 '"salut vous*" == "salut*"'
895
896 ${KIRK_KRAUSS_TESTS[@]}
897
898 END
899)
f6788fc4
MD
900
901if [ ! -x "$CURDIR/$BIN_NAME" ]; then
902 BAIL_OUT "No UST nevents binary detected."
903fi
904
80744d94
JR
905IFS="$OLDIFS"
906
f6788fc4 907diag "Test UST valid filters"
9fec62f7 908
f6788fc4
MD
909KERNEL_CHECK=0
910i=0
ec7fe110
PP
911while true; do
912 validator="${UST_FILTERS[$i]}"
913
914 if [ "$validator" = END ]; then
915 break
916 fi
9fec62f7 917
ec7fe110
PP
918 filter="${UST_FILTERS[$(( i + 1 ))]}"
919 test_valid_filter ust -u "tp:tptest" "$filter" "validator_$validator"
9fec62f7
CB
920
921 if [ $? -eq 1 ]; then
922 stop_lttng_sessiond
923 exit 1
924 fi
925
ec7fe110 926 i=$(( i + 2 ))
9fec62f7
CB
927done
928
ec7fe110
PP
929i=0
930while true; do
931 validator="${UST_STR_FILTERS[$i]}"
932
933 if [ "$validator" = END ]; then
934 break
935 fi
936
937 filter="${UST_STR_FILTERS[$(( i + 1 ))]}"
938 test_valid_filter ust_str -u "tp:the_string" "$filter" "validator_$validator"
939
940 if [ $? -eq 1 ]; then
941 stop_lttng_sessiond
942 exit 1
943 fi
944
945 i=$(( i + 2 ))
946done
f6788fc4
MD
947
948### KERNEL TESTS
949
950BIN_NAME="test_valid_filt" # Current script name truncated by kernel
951
952# One to one mapping between filters and validators
80744d94
JR
953# Set IFS to newline to facilitate array declaration
954OLDIFS="$IFS"
955IFS=$'\n'
ec7fe110
PP
956KERNEL_FILTERS=(
957 intfield
958 "intfield"
959
960 intfield_gt
961 "intfield > 1"
962
963 intfield_ge
964 "intfield >= 1"
965
966 intfield_lt
967 "intfield < 2"
968
969 intfield_le
970 "intfield <= 2"
971
972 intfield_eq
973 "intfield == 1"
974
975 intfield_ne
976 "intfield != 99"
977
978 intfield_not
979 "!intfield"
980
981 intfield
982 "-intfield"
983
984 intfield
985 "--intfield"
986
987 intfield
988 "+intfield"
989
990 intfield
991 "++intfield"
992
993 intfield_gt_and_longfield_gt
994 "intfield > 1 && longfield > 42"
995
996 intfield_ge_and_longfield_le
997 "intfield >= 42 && longfield <= 42"
998
999 intfield_lt_or_longfield_gt
1000 "intfield < 1 || longfield > 98"
1001
1002 mixed_str_or_int_and_int
1003 "(stringfield == \"test\" || intfield != 10) && intfield > 33"
1004
1005 has_no_event
1006 "intfield < 42.4242424242"
1007
1008 true_statement
1009 "\"test\" == \"test\""
1010
1011 true_statement
1012 "stringfield == \"test\""
1013
1014 true_statement
1015 "stringfield == \"t*\""
1016
1017 true_statement
1018 "stringfield == \"*\""
1019
1020 intfield
1021 $issue_356_filter
1022
1023 true_statement
1024 "intfield < 0xDEADBEEF"
1025
1026 intfield_lt
1027 "intfield < 0x2"
1028
1029 intfield_lt
1030 "intfield < 02"
f6788fc4 1031
ec7fe110
PP
1032 true_statement
1033 "stringfield2 == \"\\\*\""
1034
1035 has_no_event
1036 "1.0 || intfield || 1.0"
1037
1038 intfield_gt
1039 "1 < intfield"
1040
1041 has_no_event
1042 "\$ctx.vtid == 0"
1043
1044 has_events
1045 "\$ctx.vtid != 0"
1046
1047 has_no_event
1048 "0 == \$ctx.vtid"
1049
1050 has_events
1051 "0 != \$ctx.vtid"
1052
1053 has_no_event
1054 "\$ctx.vpid == 0"
1055
1056 has_events
1057 "\$ctx.vpid != 0"
1058
1059 has_no_event
1060 "0 == \$ctx.vpid"
1061
1062 has_events
1063 "0 != \$ctx.vpid"
1064
1065 has_no_event
1066 "\$ctx.procname != \"$BIN_NAME\""
1067
1068 has_events
1069 "\$ctx.procname == \"$BIN_NAME\""
1070
1071 has_no_event
1072 "\"$BIN_NAME\" != \$ctx.procname"
1073
1074 has_events
1075 "\"$BIN_NAME\" == \$ctx.procname"
1076
1077 has_no_event
1078 "\$ctx.procname != \"$BIN_NAME*\""
1079
1080 has_events
1081 "\$ctx.procname == \"$BIN_NAME*\""
1082
1083 has_no_event
1084 "\"$BIN_NAME*\" != \$ctx.procname"
1085
1086 has_events
1087 "\"$BIN_NAME*\" == \$ctx.procname"
1088
1089 has_no_event
1090 "\$ctx.procname != \"*\""
1091
1092 has_events
1093 "\$ctx.procname == \"*\""
1094
1095 has_no_event
1096 "\"*\" != \$ctx.procname"
1097
1098 has_events
1099 "\"*\" == \$ctx.procname"
1100
1101 has_no_event
1102 "!a.f.d"
1103
1104 has_no_event
1105 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"
1106
1107 has_no_event
1108 "\$ctx.vtid.blah == 0"
1109
1110 has_no_event
1111 "asdf.asdfsd.sadf < 4"
1112
1113 has_no_event
1114 "0 == \$ctx.vtid.blah"
1115
1116 has_no_event
1117 "\$ctx.44 == 0"
1118
1119 has_no_event
1120 "0 == \$ctx.44"
1121
1122 stringfield_has_events
1123 'stringfield == "test"'
1124
1125 stringfield_has_events
1126 '"test" == stringfield'
1127
1128 has_no_event
1129 'stringfield != "test"'
1130
1131 has_no_event
1132 '"test" != stringfield'
1133
1134 stringfield_has_events
1135 'stringfield == "*st"'
1136
1137 stringfield_has_events
1138 '"*st" == stringfield'
1139
1140 has_no_event
1141 'stringfield != "*st"'
1142
1143 has_no_event
1144 '"*st" != stringfield'
1145
1146 stringfield_has_events
1147 'stringfield == "te*"'
1148
1149 stringfield_has_events
1150 '"te*" == stringfield'
1151
1152 has_no_event
1153 'stringfield != "te*"'
1154
1155 has_no_event
1156 '"te*" != stringfield'
1157
1158 stringfield_has_events
1159 'stringfield == "te*t"'
1160
1161 stringfield_has_events
1162 '"te*t" == stringfield'
1163
1164 has_no_event
1165 'stringfield != "te*t"'
1166
1167 has_no_event
1168 '"te*t" != stringfield'
1169
1170 stringfield_has_events
1171 'stringfield == "tes*t"'
1172
1173 stringfield_has_events
1174 '"tes*t" == stringfield'
1175
1176 has_no_event
1177 'stringfield != "tes*t"'
1178
1179 has_no_event
1180 '"tes*t" != stringfield'
1181
1182 stringfield_has_events
1183 'stringfield == "*test"'
1184
1185 stringfield_has_events
1186 '"*test" == stringfield'
1187
1188 has_no_event
1189 'stringfield != "*test"'
1190
1191 has_no_event
1192 '"*test" != stringfield'
1193
1194 stringfield_has_events
1195 'stringfield == "test*"'
1196
1197 stringfield_has_events
1198 '"test*" == stringfield'
1199
1200 has_no_event
1201 'stringfield != "test*"'
1202
1203 has_no_event
1204 '"test*" != stringfield'
1205
1206 stringfield_has_events
1207 'stringfield == "*"'
1208
1209 stringfield_has_events
1210 '"*" == stringfield'
1211
1212 has_no_event
1213 'stringfield != "*"'
1214
1215 has_no_event
1216 '"*" != stringfield'
1217
1218 has_no_event
1219 'stringfield == "test*2"'
1220
1221 has_no_event
1222 'stringfield == "2*test"'
1223
1224 has_no_event
1225 'stringfield == "te\*st"'
1226
1227 has_no_event
1228 'stringfield == "te*ts"'
1229
1230 has_no_event
1231 'stringfield == "*\*test"'
1232
1233 has_no_event
1234 'stringfield == "test\*"'
1235
1236 ${KIRK_KRAUSS_TESTS[@]}
1237
1238 END
f6788fc4
MD
1239)
1240
80744d94
JR
1241IFS=$OLDIFS
1242
f6788fc4
MD
1243if [ "$(id -u)" == "0" ]; then
1244 isroot=1
1245else
1246 isroot=0
1247fi
1248
1249skip $isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS ||
1250{
1251 diag "Test kernel valid filters"
1252
1253 KERNEL_CHECK=1
1254 modprobe lttng-test
ec7fe110 1255
f6788fc4 1256 i=0
ec7fe110
PP
1257 while true; do
1258 validator="${KERNEL_FILTERS[$i]}"
1259
1260 if [ "$validator" = END ]; then
1261 break
1262 fi
f6788fc4 1263
ec7fe110
PP
1264 filter="${KERNEL_FILTERS[$(( i + 1 ))]}"
1265 test_valid_filter kernel -k "lttng_test_filter_event" "$filter" "validator_$validator"
f6788fc4
MD
1266
1267 if [ $? -eq 1 ]; then
1268 stop_lttng_sessiond
1269 exit 1
1270 fi
1271
ec7fe110 1272 i=$(( i + 2 ))
f6788fc4 1273 done
ec7fe110 1274
f6788fc4
MD
1275 rmmod lttng-test
1276}
1277
9fec62f7 1278stop_lttng_sessiond
This page took 0.097496 seconds and 5 git commands to generate.