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