Tests: remove declaration already present in utils.sh
[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/../../..
9d806fbf 22STATS_BIN="$TESTDIR/utils/babelstats.pl"
9fec62f7 23SESSION_NAME="valid_filter"
9fec62f7 24NR_ITER=100
f6788fc4 25NUM_GLOBAL_TESTS=2
5da9cf86
MD
26NUM_UST_TESTS=330
27NUM_KERNEL_TESTS=330
f6788fc4 28NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
9fec62f7 29
9ac429ef 30source $TESTDIR/utils/utils.sh
9fec62f7 31
f6788fc4 32function enable_lttng_event_filter()
9fec62f7 33{
f6788fc4
MD
34 domain="$1"
35 sess_name="$2"
36 event_name="$3"
37 filter="$4"
9fec62f7 38
f6788fc4
MD
39 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name \
40 -s $sess_name $domain --filter "$filter" 2>&1 >/dev/null
41 $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context \
42 -s $sess_name $domain -t procname 2>&1 >/dev/null
9fec62f7 43
03276eea 44 ok $? "Enable lttng event with filtering"
9fec62f7
CB
45}
46
f6788fc4 47function run_ust
9fec62f7 48{
d7ee608c 49 ./$CURDIR/$BIN_NAME $NR_ITER >/dev/null 2>&1
9fec62f7
CB
50}
51
f6788fc4
MD
52function run_kernel
53{
54 # Trigger the event for 100 iterations
55 echo -n "100" > /proc/lttng-test-filter-event
56}
57
9fec62f7
CB
58function test_valid_filter
59{
f6788fc4
MD
60 domain_name="$1"
61 domain="$2"
62 event_name="$3"
63 filter="$4"
64 validator="$5"
9fec62f7 65
f6788fc4 66 diag "Test valid $domain_name filter: $filter"
9fec62f7
CB
67
68 trace_path=$(mktemp -d)
69
70 # Create session
bf6ae429 71 create_lttng_session_ok $SESSION_NAME $trace_path
9fec62f7
CB
72
73 # Enable filter
80744d94 74 enable_lttng_event_filter $domain $SESSION_NAME "$event_name" "$filter"
9fec62f7
CB
75
76 # Trace apps
e563bbdb 77 start_lttng_tracing_ok $SESSION_NAME
f6788fc4 78 run_$domain_name
96340a01 79 stop_lttng_tracing_ok $SESSION_NAME
9fec62f7
CB
80
81 # Destroy session
67b4c664 82 destroy_lttng_session_ok $SESSION_NAME
9fec62f7 83
f6788fc4 84 stats=`babeltrace $trace_path | $STATS_BIN --tracepoint $event_name`
9fec62f7 85
3bae2c9a
DG
86 rm -rf $trace_path
87
9fec62f7
CB
88 $validator "$stats"
89
03276eea
CB
90 ok $? "Validate trace filter output"
91
92 rm -rf $trace_path
9fec62f7
CB
93}
94
95function validate_min_max
96{
97 stats="$1"
98 field=$2
99 expected_min=$3
100 expected_max=$4
101
102 echo $stats | grep -q "$field $expected_min $expected_max"
103
104 return $?
105}
106
107function validator_intfield
108{
109 stats="$1"
110 status=0
111
112 validate_min_max "$stats" "intfield" "1" "99"
113 status=$(($status|$?))
114
115 validate_min_max "$stats" "intfield2" "0x1" "0x63"
116 status=$(($status|$?))
117
118 validate_min_max "$stats" "longfield" "1" "99"
119 status=$(($status|$?))
120
121 validate_min_max "$stats" "netintfield" "1" "99"
122 status=$(($status|$?))
123
124 validate_min_max "$stats" "netintfieldhex" "0x1" "0x63"
125 status=$(($status|$?))
126
f6788fc4
MD
127 if [ $KERNEL_CHECK -eq 0 ]; then
128 validate_min_max "$stats" "floatfield" "2222" "2222"
129 status=$(($status|$?))
9fec62f7 130
f6788fc4
MD
131 validate_min_max "$stats" "doublefield" "2" "2"
132 status=$(($status|$?))
133 fi
9fec62f7
CB
134
135 return $status
136}
137
138function validator_intfield_gt
139{
140 stats="$1"
141 status=0
142
143 validate_min_max "$stats" "intfield" "2" "99"
144 status=$(($status|$?))
145
146 return $status
147}
148
6d5d85c7
MD
149function validator_has_no_event
150{
151 stats="$1"
152 status=0
153
154 validate_min_max "$stats" "intfield" "0" "99"
155 status=$(($status|$?))
156
157 if [ $status -eq 0 ]; then
158 return 1
159 else
160 return 0
161 fi
162}
163
164function validator_has_events
165{
166 stats="$1"
167 status=0
168
169 validate_min_max "$stats" "intfield" "0" "99"
170 status=$(($status|$?))
171
172 return $status
173}
174
9fec62f7
CB
175function validator_intfield_ge
176{
177 stats="$1"
178 status=0
179
180 validate_min_max "$stats" "intfield" "1" "99"
181 status=$(($status|$?))
182
183 return $status
184}
185
186function validator_intfield_lt
187{
188 stats="$1"
189 status=0
190
191 validate_min_max "$stats" "intfield" "0" "1"
192 status=$(($status|$?))
193
194 return $status
195}
196
197function validator_intfield_le
198{
199 stats="$1"
200 status=0
201
202 validate_min_max "$stats" "intfield" "0" "2"
203 status=$(($status|$?))
204
205 return $status
206}
207
208function validator_intfield_eq
209{
210 stats="$1"
211 status=0
212
213 validate_min_max "$stats" "intfield" "1" "1"
214 status=$(($status|$?))
215
216 return $status
217}
218
219function validator_intfield_ne
220{
221 stats="$1"
222 status=0
223
224 validate_min_max "$stats" "intfield" "0" "98"
225 status=$(($status|$?))
226
227 return $status
228}
229
230function validator_intfield_not
231{
232 stats="$1"
233 status=0
234
235 validate_min_max "$stats" "intfield" "0" "0"
236 status=$(($status|$?))
237
238 return $status
239}
240
241function validator_intfield_gt_and_longfield_gt
242{
243 stats="$1"
244 status=0
245
246 validate_min_max "$stats" "intfield" "43" "99"
247 status=$(($status|$?))
248 validate_min_max "$stats" "longfield" "43" "99"
249 status=$(($status|$?))
250
251 return $status
252}
253
254function validator_intfield_ge_and_longfield_le
255{
256 stats="$1"
257 status=0
258
259 validate_min_max "$stats" "intfield" "42" "42"
260 status=$(($status|$?))
261 validate_min_max "$stats" "longfield" "42" "42"
262 status=$(($status|$?))
263
264 return $status
265}
266
267function validator_intfield_lt_or_longfield_gt
268{
269 stats="$1"
270 status=0
271
272 validate_min_max "$stats" "intfield" "0" "99"
273 status=$(($status|$?))
274 validate_min_max "$stats" "longfield" "0" "99"
275 status=$(($status|$?))
276
277 return $status
278}
279
280function validator_mixed_str_or_int_and_int
281{
282 stats="$1"
283 status=0
284
285 validate_min_max "$stats" "intfield" "34" "99"
286 status=$(($status|$?))
287
288 validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
289 status=$(($status|$?))
290
291 return $status
292}
293
294function validator_mixed_int_double
295{
296 stats="$1"
297 status=0
298
299 validate_min_max "$stats" "intfield" "0" "42"
300 status=$(($status|$?))
301
302 return $status
303}
304
305function validator_true_statement
306{
307 stats="$1"
308 status=0
309
310 validate_min_max "$stats" "intfield" "0" "99"
311 status=$(($status|$?))
312
313 validate_min_max "$stats" "intfield2" "0x0" "0x63"
314 status=$(($status|$?))
315
316 validate_min_max "$stats" "longfield" "0" "99"
317 status=$(($status|$?))
318
319 validate_min_max "$stats" "netintfield" "0" "99"
320 status=$(($status|$?))
321
322 validate_min_max "$stats" "netintfieldhex" "0x0" "0x63"
323 status=$(($status|$?))
324
f6788fc4
MD
325 if [ $KERNEL_CHECK -eq 0 ]; then
326 validate_min_max "$stats" "floatfield" "2222" "2222"
327 status=$(($status|$?))
9fec62f7 328
f6788fc4
MD
329 validate_min_max "$stats" "doublefield" "2" "2"
330 status=$(($status|$?))
331 fi
9fec62f7
CB
332
333 validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
334 status=$(($status|$?))
335
336 validate_min_max "$stats" "stringfield2" ""\*"" ""\*""
337 status=$(($status|$?))
338
339 return $status
340}
341
03276eea
CB
342plan_tests $NUM_TESTS
343
e3bef725
CB
344print_test_banner "$TEST_DESC"
345
9fec62f7
CB
346issue_356_filter="intfield > 0 && intfield > 1 && "
347issue_356_filter+="intfield > 2 && intfield > 3 && "
348issue_356_filter+="intfield > 4 && intfield > 5 && "
349issue_356_filter+="intfield > 6 && intfield > 7 && "
350issue_356_filter+="intfield > 8 || intfield > 0"
351
f6788fc4
MD
352start_lttng_sessiond
353
354### UST TESTS
355
356BIN_NAME="gen-ust-events"
357
9fec62f7
CB
358# One to one mapping between filters and validators
359
80744d94
JR
360# Set IFS to newline to facilitate array declaration
361OLDIFS="$IFS"
362IFS=$'\n'
f6788fc4 363UST_FILTERS=("intfield" #1
9fec62f7
CB
364 "intfield > 1" #2
365 "intfield >= 1" #3
366 "intfield < 2" #4
367 "intfield <= 2" #5
368 "intfield == 1" #6
369 "intfield != 99" #7
370 "!intfield" #8
371 "-intfield" #9
372 "--intfield" #10
373 "+intfield" #11
374 "++intfield" #12
375 "intfield > 1 && longfield > 42" #13
376 "intfield >= 42 && longfield <= 42" #14
377 "intfield < 1 || longfield > 98" #15
378 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
379 "intfield < 42.4242424242" #17
380 "\"test\" == \"test\"" #18 #Issue #342
381 "stringfield == \"test\"" #19
382 "stringfield == \"t*\"" #20
383 "stringfield == \"*\"" #21
384 $issue_356_filter #22 #Issue #356
385 "intfield < 0xDEADBEEF" #23
386 "intfield < 0x2" #24
387 "intfield < 02" #25
388 "stringfield2 == \"\\\*\"" #26
ef049bee
CB
389 "1.0 || intfield || 1.0" #27
390 "1 < intfield" #28
6d5d85c7
MD
391 "\$ctx.vtid == 0" #29
392 "\$ctx.vtid != 0" #30
393 "0 == \$ctx.vtid" #31
394 "0 != \$ctx.vtid" #32
395 "\$ctx.vpid == 0" #33
396 "\$ctx.vpid != 0" #34
397 "0 == \$ctx.vpid" #35
398 "0 != \$ctx.vpid" #36
399 "\$ctx.procname != \"$BIN_NAME\"" #37
400 "\$ctx.procname == \"$BIN_NAME\"" #38
401 "\"$BIN_NAME\" != \$ctx.procname" #39
402 "\"$BIN_NAME\" == \$ctx.procname" #40
403 "\$ctx.procname != \"$BIN_NAME*\"" #41
404 "\$ctx.procname == \"$BIN_NAME*\"" #42
405 "\"$BIN_NAME*\" != \$ctx.procname" #43
406 "\"$BIN_NAME*\" == \$ctx.procname" #44
407 "\$ctx.procname != \"*\"" #45
408 "\$ctx.procname == \"*\"" #46
409 "\"*\" != \$ctx.procname" #47
410 "\"*\" == \$ctx.procname" #48
5da9cf86
MD
411 "!a.f.d" #49
412 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" #50
413 "\$ctx.vtid.blah == 0" #51
414 "asdf.asdfsd.sadf < 4" #52
415 "0 == \$ctx.vtid.blah" #53
416 "\$ctx.44 == 0" #54
417 "0 == \$ctx.44" #55
9fec62f7
CB
418)
419
f6788fc4
MD
420UST_FILTER_COUNT=${#UST_FILTERS[@]}
421
422if [ ! -x "$CURDIR/$BIN_NAME" ]; then
423 BAIL_OUT "No UST nevents binary detected."
424fi
425
426UST_VALIDATOR=("validator_intfield" #1
9fec62f7
CB
427 "validator_intfield_gt" #2
428 "validator_intfield_ge" #3
429 "validator_intfield_lt" #4
430 "validator_intfield_le" #5
431 "validator_intfield_eq" #6
432 "validator_intfield_ne" #7
433 "validator_intfield_not" #8
434 "validator_intfield" #9
435 "validator_intfield" #10
436 "validator_intfield" #11
437 "validator_intfield" #12
438 "validator_intfield_gt_and_longfield_gt" #13
439 "validator_intfield_ge_and_longfield_le" #14
440 "validator_intfield_lt_or_longfield_gt" #15
441 "validator_mixed_str_or_int_and_int" #16
442 "validator_mixed_int_double" #17
443 "validator_true_statement" #18
444 "validator_true_statement" #19
445 "validator_true_statement" #20
446 "validator_true_statement" #21
447 "validator_intfield" #22
448 "validator_true_statement" #23
449 "validator_intfield_lt" #24
450 "validator_intfield_lt" #25
451 "validator_true_statement" #26
ef049bee
CB
452 "validator_true_statement" #27
453 "validator_intfield_gt" #28
6d5d85c7
MD
454 "validator_has_no_event" #29
455 "validator_has_events" #30
456 "validator_has_no_event" #31
457 "validator_has_events" #32
458 "validator_has_no_event" #33
459 "validator_has_events" #34
460 "validator_has_no_event" #35
461 "validator_has_events" #36
462 "validator_has_no_event" #36
463 "validator_has_events" #37
464 "validator_has_no_event" #38
465 "validator_has_events" #39
466 "validator_has_no_event" #41
467 "validator_has_events" #42
468 "validator_has_no_event" #43
469 "validator_has_events" #44
470 "validator_has_no_event" #45
471 "validator_has_events" #46
472 "validator_has_no_event" #47
473 "validator_has_events" #48
5da9cf86
MD
474 "validator_has_no_event" #49
475 "validator_has_no_event" #50
476 "validator_has_no_event" #51
477 "validator_has_no_event" #52
478 "validator_has_no_event" #53
479 "validator_has_no_event" #54
480 "validator_has_no_event" #55
9fec62f7
CB
481)
482
80744d94
JR
483IFS="$OLDIFS"
484
f6788fc4 485diag "Test UST valid filters"
9fec62f7 486
f6788fc4
MD
487KERNEL_CHECK=0
488i=0
489while [ "$i" -lt "$UST_FILTER_COUNT" ]; do
9fec62f7 490
f6788fc4 491 test_valid_filter ust -u "tp:tptest" "${UST_FILTERS[$i]}" "${UST_VALIDATOR[$i]}"
9fec62f7
CB
492
493 if [ $? -eq 1 ]; then
494 stop_lttng_sessiond
495 exit 1
496 fi
497
498 let "i++"
499done
500
f6788fc4
MD
501
502### KERNEL TESTS
503
504BIN_NAME="test_valid_filt" # Current script name truncated by kernel
505
506# One to one mapping between filters and validators
80744d94
JR
507# Set IFS to newline to facilitate array declaration
508OLDIFS="$IFS"
509IFS=$'\n'
f6788fc4
MD
510KERNEL_FILTERS=("intfield" #1
511 "intfield > 1" #2
512 "intfield >= 1" #3
513 "intfield < 2" #4
514 "intfield <= 2" #5
515 "intfield == 1" #6
516 "intfield != 99" #7
517 "!intfield" #8
518 "-intfield" #9
519 "--intfield" #10
520 "+intfield" #11
521 "++intfield" #12
522 "intfield > 1 && longfield > 42" #13
523 "intfield >= 42 && longfield <= 42" #14
524 "intfield < 1 || longfield > 98" #15
525 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
526 "intfield < 42.4242424242" #17
527 "\"test\" == \"test\"" #18 #Issue #342
528 "stringfield == \"test\"" #19
529 "stringfield == \"t*\"" #20
530 "stringfield == \"*\"" #21
531 $issue_356_filter #22 #Issue #356
532 "intfield < 0xDEADBEEF" #23
533 "intfield < 0x2" #24
534 "intfield < 02" #25
535 "stringfield2 == \"\\\*\"" #26
536 "1.0 || intfield || 1.0" #27
537 "1 < intfield" #28
538 "\$ctx.vtid == 0" #29
539 "\$ctx.vtid != 0" #30
540 "0 == \$ctx.vtid" #31
541 "0 != \$ctx.vtid" #32
542 "\$ctx.vpid == 0" #33
543 "\$ctx.vpid != 0" #34
544 "0 == \$ctx.vpid" #35
545 "0 != \$ctx.vpid" #36
546 "\$ctx.procname != \"$BIN_NAME\"" #37
547 "\$ctx.procname == \"$BIN_NAME\"" #38
548 "\"$BIN_NAME\" != \$ctx.procname" #39
549 "\"$BIN_NAME\" == \$ctx.procname" #40
550 "\$ctx.procname != \"$BIN_NAME*\"" #41
551 "\$ctx.procname == \"$BIN_NAME*\"" #42
552 "\"$BIN_NAME*\" != \$ctx.procname" #43
553 "\"$BIN_NAME*\" == \$ctx.procname" #44
554 "\$ctx.procname != \"*\"" #45
555 "\$ctx.procname == \"*\"" #46
556 "\"*\" != \$ctx.procname" #47
557 "\"*\" == \$ctx.procname" #48
5da9cf86
MD
558 "!a.f.d" #49
559 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" #50
560 "\$ctx.vtid.blah == 0" #51
561 "asdf.asdfsd.sadf < 4" #52
562 "0 == \$ctx.vtid.blah" #53
563 "\$ctx.44 == 0" #54
564 "0 == \$ctx.44" #55
f6788fc4
MD
565)
566
567KERNEL_FILTER_COUNT=${#KERNEL_FILTERS[@]}
568
569KERNEL_VALIDATOR=("validator_intfield" #1
570 "validator_intfield_gt" #2
571 "validator_intfield_ge" #3
572 "validator_intfield_lt" #4
573 "validator_intfield_le" #5
574 "validator_intfield_eq" #6
575 "validator_intfield_ne" #7
576 "validator_intfield_not" #8
577 "validator_intfield" #9
578 "validator_intfield" #10
579 "validator_intfield" #11
580 "validator_intfield" #12
581 "validator_intfield_gt_and_longfield_gt" #13
582 "validator_intfield_ge_and_longfield_le" #14
583 "validator_intfield_lt_or_longfield_gt" #15
584 "validator_mixed_str_or_int_and_int" #16
585 "validator_has_no_event" #17 #Unsupported by kernel
586 "validator_true_statement" #18
587 "validator_true_statement" #19
588 "validator_true_statement" #20
589 "validator_true_statement" #21
590 "validator_intfield" #22
591 "validator_true_statement" #23
592 "validator_intfield_lt" #24
593 "validator_intfield_lt" #25
594 "validator_true_statement" #26
595 "validator_has_no_event" #27 #Unsupported by kernel
596 "validator_intfield_gt" #28
597 "validator_has_no_event" #29
598 "validator_has_events" #30
599 "validator_has_no_event" #31
600 "validator_has_events" #32
601 "validator_has_no_event" #33
602 "validator_has_events" #34
603 "validator_has_no_event" #35
604 "validator_has_events" #36
605 "validator_has_no_event" #36
606 "validator_has_events" #37
607 "validator_has_no_event" #38
608 "validator_has_events" #39
609 "validator_has_no_event" #41
610 "validator_has_events" #42
611 "validator_has_no_event" #43
612 "validator_has_events" #44
613 "validator_has_no_event" #45
614 "validator_has_events" #46
615 "validator_has_no_event" #47
616 "validator_has_events" #48
5da9cf86
MD
617 "validator_has_no_event" #49
618 "validator_has_no_event" #50
619 "validator_has_no_event" #51
620 "validator_has_no_event" #52
621 "validator_has_no_event" #53
622 "validator_has_no_event" #54
623 "validator_has_no_event" #55
f6788fc4
MD
624)
625
80744d94
JR
626IFS=$OLDIFS
627
f6788fc4
MD
628if [ "$(id -u)" == "0" ]; then
629 isroot=1
630else
631 isroot=0
632fi
633
634skip $isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS ||
635{
636 diag "Test kernel valid filters"
637
638 KERNEL_CHECK=1
639 modprobe lttng-test
640 i=0
641 while [ "$i" -lt "$KERNEL_FILTER_COUNT" ]; do
642
643 test_valid_filter kernel -k "lttng_test_filter_event" \
644 "${KERNEL_FILTERS[$i]}" "${KERNEL_VALIDATOR[$i]}"
645
646 if [ $? -eq 1 ]; then
647 stop_lttng_sessiond
648 exit 1
649 fi
650
651 let "i++"
652 done
653 rmmod lttng-test
654}
655
9fec62f7 656stop_lttng_sessiond
This page took 0.062657 seconds and 4 git commands to generate.