Fix: bytecode test should be in UST_FILTERS, not UST_STR_FILTERS
[lttng-tools.git] / tests / regression / tools / filtering / test_valid_filter
CommitLineData
9fec62f7
CB
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
9fec62f7 4#
9d16b343 5# SPDX-License-Identifier: GPL-2.0-only
9fec62f7 6#
9fec62f7
CB
7
8TEST_DESC="Filtering - Valid filters"
9
10CURDIR=$(dirname $0)/
9ac429ef 11TESTDIR=$CURDIR/../../..
9d806fbf 12STATS_BIN="$TESTDIR/utils/babelstats.pl"
9fec62f7 13SESSION_NAME="valid_filter"
9fec62f7 14NR_ITER=100
f6788fc4 15NUM_GLOBAL_TESTS=2
c99adc64
MD
16NUM_UST_TESTS=1122
17NUM_KERNEL_TESTS=1056
f6788fc4 18NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
9fec62f7 19
9ac429ef 20source $TESTDIR/utils/utils.sh
9fec62f7 21
f6788fc4 22function enable_lttng_event_filter()
9fec62f7 23{
f6788fc4
MD
24 domain="$1"
25 sess_name="$2"
26 event_name="$3"
27 filter="$4"
9fec62f7 28
f6788fc4
MD
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
9fec62f7 33
03276eea 34 ok $? "Enable lttng event with filtering"
9fec62f7
CB
35}
36
f6788fc4 37function run_ust
9fec62f7 38{
d7ee608c 39 ./$CURDIR/$BIN_NAME $NR_ITER >/dev/null 2>&1
9fec62f7
CB
40}
41
ec7fe110
PP
42function 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
f6788fc4
MD
84function run_kernel
85{
86 # Trigger the event for 100 iterations
87 echo -n "100" > /proc/lttng-test-filter-event
88}
89
9fec62f7
CB
90function test_valid_filter
91{
f6788fc4
MD
92 domain_name="$1"
93 domain="$2"
94 event_name="$3"
95 filter="$4"
96 validator="$5"
9fec62f7 97
f6788fc4 98 diag "Test valid $domain_name filter: $filter"
9fec62f7
CB
99
100 trace_path=$(mktemp -d)
101
102 # Create session
bf6ae429 103 create_lttng_session_ok $SESSION_NAME $trace_path
9fec62f7
CB
104
105 # Enable filter
80744d94 106 enable_lttng_event_filter $domain $SESSION_NAME "$event_name" "$filter"
9fec62f7
CB
107
108 # Trace apps
e563bbdb 109 start_lttng_tracing_ok $SESSION_NAME
f6788fc4 110 run_$domain_name
96340a01 111 stop_lttng_tracing_ok $SESSION_NAME
9fec62f7
CB
112
113 # Destroy session
67b4c664 114 destroy_lttng_session_ok $SESSION_NAME
9fec62f7 115
f6788fc4 116 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
9fec62f7 117
3bae2c9a
DG
118 rm -rf $trace_path
119
9fec62f7
CB
120 $validator "$stats"
121
03276eea
CB
122 ok $? "Validate trace filter output"
123
124 rm -rf $trace_path
9fec62f7
CB
125}
126
127function 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
139function 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
f6788fc4
MD
159 if [ $KERNEL_CHECK -eq 0 ]; then
160 validate_min_max "$stats" "floatfield" "2222" "2222"
161 status=$(($status|$?))
9fec62f7 162
f6788fc4
MD
163 validate_min_max "$stats" "doublefield" "2" "2"
164 status=$(($status|$?))
165 fi
9fec62f7
CB
166
167 return $status
168}
169
170function 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
6d5d85c7
MD
181function 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
ec7fe110
PP
196function validator_str_has_no_event
197{
198 validator_has_no_event "$1"
199}
200
6d5d85c7
MD
201function 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
ec7fe110
PP
212function 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
223function 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
9fec62f7
CB
234function 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
245function 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
256function 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
267function 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
278function 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
289function 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
300function 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
313function 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
326function 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
339function 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
353function 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
364function 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
f6788fc4
MD
384 if [ $KERNEL_CHECK -eq 0 ]; then
385 validate_min_max "$stats" "floatfield" "2222" "2222"
386 status=$(($status|$?))
9fec62f7 387
f6788fc4
MD
388 validate_min_max "$stats" "doublefield" "2" "2"
389 status=$(($status|$?))
390 fi
9fec62f7
CB
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
03276eea
CB
401plan_tests $NUM_TESTS
402
e3bef725
CB
403print_test_banner "$TEST_DESC"
404
9fec62f7
CB
405issue_356_filter="intfield > 0 && intfield > 1 && "
406issue_356_filter+="intfield > 2 && intfield > 3 && "
407issue_356_filter+="intfield > 4 && intfield > 5 && "
408issue_356_filter+="intfield > 6 && intfield > 7 && "
409issue_356_filter+="intfield > 8 || intfield > 0"
410
f6788fc4
MD
411start_lttng_sessiond
412
413### UST TESTS
414
415BIN_NAME="gen-ust-events"
416
ec7fe110
PP
417KIRK_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)
9fec62f7 562
80744d94
JR
563# Set IFS to newline to facilitate array declaration
564OLDIFS="$IFS"
565IFS=$'\n'
ec7fe110
PP
566UST_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
bff988fa
MD
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
cea52dd8 666 "(0x101 & 0x100) == 0x100"
bff988fa
MD
667
668 true_statement
cea52dd8 669 "(0x101 | 0x10100) == 0x10101"
bff988fa
MD
670
671 true_statement
cea52dd8 672 "(0xF00F0F ^ 0xFF0F00) == 0x0F000F"
bff988fa 673
116d3c01
MD
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
0358f3d8
MD
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
116d3c01 710 true_statement
831b702b 711 "(1<<2!=4)==0" # operator priority: shift before equality
116d3c01 712
831b702b
MD
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
116d3c01
MD
721
722 true_statement
723 "(1 << 32) == 4294967296"
724
725 true_statement
726 "(1 << 63) == 9223372036854775808"
727
bff988fa 728 true_statement
cea52dd8 729 "(arrfield1[2] & 1) == 1"
bff988fa
MD
730
731 true_statement
cea52dd8 732 "(arrfield1[2] | 0x111000) == 0x111003"
bff988fa
MD
733
734 true_statement
735 "(arrfield1[0] | arrfield1[1] | arrfield1[2]) == 0x3"
736
737 true_statement
cea52dd8 738 "(seqfield4[2] & 1) == 1"
bff988fa
MD
739
740 true_statement
cea52dd8 741 "(seqfield4[2] | 0x111000) == 0x111003"
bff988fa 742
ec7fe110
PP
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
39ac0a0e
MD
836 # check that bytecode linker refuses to link against a
837 # non-string array.
838 has_no_event
839 'arrfield1 != "dontmatch"'
840
841 # check that bytecode linker refuses to link against a
842 # non-string sequence.
843 has_no_event
844 'seqfield1 != "dontmatch"'
845
ec7fe110 846 END
9fec62f7
CB
847)
848
ec7fe110
PP
849UST_STR_FILTERS=(
850 str_has_events
851 'str == "hypothecary"'
852
853 str_has_events
854 '"hypothecary" == str'
855
856 str_has_events
857 'str != "hypothecary"'
858
859 str_has_events
860 '"hypothecary" != str'
861
862 str_has_events
863 'str == "*cary"'
864
865 str_has_events
866 '"*cary" == str'
867
868 str_has_events
869 'str != "*cary"'
870
871 str_has_events
872 '"*cary" != str'
873
874 str_has_events
875 'str == "hypo*"'
876
877 str_has_events
878 '"hypo*" == str'
879
880 str_has_events
881 'str != "hypo*"'
882
883 str_has_events
884 '"hypo*" != str'
885
886 str_has_events
887 'str == "*the*"'
888
889 str_has_events
890 '"*the*" == str'
891
892 str_has_events
893 'str != "*the*"'
894
895 str_has_events
896 '"*the*" != str'
897
898 str_has_events
899 'str == "**"'
900
901 str_has_events
902 '"**" == str'
903
904 str_has_no_event
905 'str != "**"'
906
907 str_has_no_event
908 '"**" != str'
909
910 str_has_events
911 'str == "sc*"'
912
913 str_has_events
914 '"sc*" == str'
915
916 str_has_events
917 'str != "sc*"'
918
919 str_has_events
920 '"sc*" != str'
921
922 str_has_events
923 'str == "de*al"'
924
925 str_has_events
926 '"de*al" == str'
927
928 str_has_events
929 'str != "de*al"'
930
931 str_has_events
932 '"de*al" != str'
933
934 str_has_events
935 'str == "*po*siz*"'
936
937 str_has_events
938 '"*po*siz*" == str'
939
940 str_has_events
941 'str != "*po*siz*"'
942
943 str_has_events
944 '"*po*siz*" != str'
945
946 str_has_events
947 'str == "*po***siz*"'
948
949 str_has_events
950 '"*po***siz*" == str'
951
952 str_has_events
953 'str != "*po***siz*"'
954
955 str_has_events
956 '"*po***siz*" != str'
957
958 str_has_no_event
959 'str == "*po*\**siz*"'
960
961 str_has_no_event
962 '"*po*\**siz*" == str'
963
964 str_has_no_event
965 'str == "*zulu*"'
966
967 str_has_no_event
968 '"*zulu*" == str'
969
970 str_has_no_event
971 'str == "8*"'
972
973 str_has_no_event
974 '"8*" == str'
975
976 str_has_no_event
977 'str == "*8"'
978
979 str_has_no_event
980 '"*8" == str'
981
982 str_has_no_event
983 'str == "de\*al"'
984
985 str_has_no_event
986 '"de\*al" == str'
987
988 str_has_events
989 '"salut*" == "salut vous"'
990
991 str_has_events
992 '"salut*" == "salut vous*"'
993
994 str_has_events
995 '"salut vous*" == "salut*"'
996
997 ${KIRK_KRAUSS_TESTS[@]}
998
999 END
1000)
f6788fc4
MD
1001
1002if [ ! -x "$CURDIR/$BIN_NAME" ]; then
1003 BAIL_OUT "No UST nevents binary detected."
1004fi
1005
80744d94
JR
1006IFS="$OLDIFS"
1007
f6788fc4 1008diag "Test UST valid filters"
9fec62f7 1009
f6788fc4
MD
1010KERNEL_CHECK=0
1011i=0
ec7fe110
PP
1012while true; do
1013 validator="${UST_FILTERS[$i]}"
1014
1015 if [ "$validator" = END ]; then
1016 break
1017 fi
9fec62f7 1018
ec7fe110
PP
1019 filter="${UST_FILTERS[$(( i + 1 ))]}"
1020 test_valid_filter ust -u "tp:tptest" "$filter" "validator_$validator"
9fec62f7
CB
1021
1022 if [ $? -eq 1 ]; then
1023 stop_lttng_sessiond
1024 exit 1
1025 fi
1026
ec7fe110 1027 i=$(( i + 2 ))
9fec62f7
CB
1028done
1029
ec7fe110
PP
1030i=0
1031while 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 ))
1047done
f6788fc4
MD
1048
1049### KERNEL TESTS
1050
1051BIN_NAME="test_valid_filt" # Current script name truncated by kernel
1052
1053# One to one mapping between filters and validators
80744d94
JR
1054# Set IFS to newline to facilitate array declaration
1055OLDIFS="$IFS"
1056IFS=$'\n'
ec7fe110
PP
1057KERNEL_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
bff988fa
MD
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
cea52dd8 1155 "(0x101 & 0x100) == 0x100"
bff988fa
MD
1156
1157 true_statement
cea52dd8 1158 "(0x101 | 0x10100) == 0x10101"
bff988fa
MD
1159
1160 true_statement
cea52dd8 1161 "(0xF00F0F ^ 0xFF0F00) == 0x0F000F"
bff988fa 1162
116d3c01
MD
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
0358f3d8
MD
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
116d3c01 1199 true_statement
831b702b 1200 "(1<<2!=4)==0" # operator priority: shift before equality
116d3c01 1201
831b702b
MD
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
116d3c01
MD
1210
1211 true_statement
1212 "(1 << 32) == 4294967296"
1213
1214 true_statement
1215 "(1 << 63) == 9223372036854775808"
1216
bff988fa 1217 true_statement
cea52dd8 1218 "(arrfield1[2] & 1) == 1"
bff988fa
MD
1219
1220 true_statement
cea52dd8 1221 "(arrfield1[2] | 0x111000) == 0x111003"
bff988fa
MD
1222
1223 true_statement
1224 "(arrfield1[0] | arrfield1[1] | arrfield1[2]) == 0x3"
1225
1226 true_statement
cea52dd8 1227 "(seqfield4[2] & 1) == 1"
bff988fa
MD
1228
1229 true_statement
cea52dd8 1230 "(seqfield4[2] | 0x111000) == 0x111003"
bff988fa 1231
ec7fe110
PP
1232 true_statement
1233 "intfield < 0xDEADBEEF"
1234
1235 intfield_lt
1236 "intfield < 0x2"
1237
1238 intfield_lt
1239 "intfield < 02"
f6788fc4 1240
ec7fe110
PP
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
ec7fe110
PP
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
c99adc64
MD
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
ec7fe110
PP
1449 ${KIRK_KRAUSS_TESTS[@]}
1450
1451 END
f6788fc4
MD
1452)
1453
80744d94
JR
1454IFS=$OLDIFS
1455
f6788fc4
MD
1456if [ "$(id -u)" == "0" ]; then
1457 isroot=1
1458else
1459 isroot=0
1460fi
1461
1462skip $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
ec7fe110 1468
f6788fc4 1469 i=0
ec7fe110
PP
1470 while true; do
1471 validator="${KERNEL_FILTERS[$i]}"
1472
1473 if [ "$validator" = END ]; then
1474 break
1475 fi
f6788fc4 1476
ec7fe110
PP
1477 filter="${KERNEL_FILTERS[$(( i + 1 ))]}"
1478 test_valid_filter kernel -k "lttng_test_filter_event" "$filter" "validator_$validator"
f6788fc4
MD
1479
1480 if [ $? -eq 1 ]; then
1481 stop_lttng_sessiond
1482 exit 1
1483 fi
1484
ec7fe110 1485 i=$(( i + 2 ))
f6788fc4 1486 done
ec7fe110 1487
d0e263e7 1488 modprobe --remove lttng-test
f6788fc4
MD
1489}
1490
9fec62f7 1491stop_lttng_sessiond
This page took 0.173111 seconds and 4 git commands to generate.