d0777e583f89767efdfb040650477fcd6e3608a9
[lttng-tools.git] / tests / tools / filtering / invalid-filters
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
18 TEST_DESC="Filtering - Invalid filters"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../..
22 LTTNG_BIN="lttng"
23 SESSION_NAME="filter-invalid"
24 EVENT_NAME="bogus"
25 ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr"
26 TRACE_PATH=$(mktemp -d)
27
28 source $TESTDIR/utils.sh
29
30 print_test_banner "$TEST_DESC"
31
32 function enable_ust_lttng_event_filter
33 {
34 sess_name="$1"
35 event_name="$2"
36 filter="$3"
37 echo -n "Enabling lttng event with filtering and invalid filter "
38
39 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev/null
40
41 # Enable must fail
42 if [ $? -eq 0 ]; then
43 print_fail
44 return 1
45 else
46 print_ok
47 return 0
48 fi
49 }
50
51 function test_invalid_filter
52 {
53 test_invalid_filter="$1"
54
55 echo ""
56 echo -e "=== Testing filter expression with invalid filter"
57 echo -e "Filter: $test_invalid_filter"
58
59 # Create session
60 create_lttng_session $SESSION_NAME $TRACE_PATH
61
62 # Apply filter
63 enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME "$test_invalid_filter"
64
65 # Destroy session
66 destroy_lttng_session $SESSION_NAME
67 }
68
69 function test_bytecode_limit
70 {
71 # Current bytecode limitation is 65536 bytes long.
72 # Generate a huge bytecode with some perl-fu
73 BYTECODE_LIMIT=`perl -e 'print "intfield" . " && 1" x5460'`
74
75 echo ""
76 echo -e "=== Testing filter bytecode limits (64KiB)"
77
78 # Create session
79 create_lttng_session $SESSION_NAME $TRACE_PATH
80
81 # Apply filter
82 enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT"
83
84 # Destroy session
85 destroy_lttng_session $SESSION_NAME
86 }
87
88 IFS=$'\n'
89 INVALID_FILTERS=(
90 # Unsupported ops
91 "intfield*1"
92 "intfield/1"
93 "intfield+1"
94 "intfield-1"
95 "intfield>>1"
96 "intfield<<1"
97 "intfield&1"
98 "intfield|1"
99 "intfield^1"
100 "~intfield"
101 "1+11111-3333+1"
102 "(1+2)*(55*666)"
103 "1+2*55*666"
104 "asdf + 1 > 1"
105 "asdfas < 2332 || asdf + 1 > 1"
106 "!+-+++-------+++++++++++-----!!--!44+1"
107 "aaa||(gg)+(333----1)"
108 "1+1"
109 # Unmatched parenthesis
110 "((((((((((((((intfield)))))))))))))"
111 '0 || ("abc" != "def")) && (3 < 4)'
112 # Field dereference
113 "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"
114 "a->"
115 "a-->a"
116 "a->a"
117 "a.b.c->d.e.f+1"
118 "!a.f.d"
119 "asdf.asdfsd.sadf < 4"
120 "asdfasdf->asdfasdf < 2"
121 )
122
123 start_lttng_sessiond
124 for FILTER in ${INVALID_FILTERS[@]};
125 do
126 test_invalid_filter "$FILTER"
127 done
128
129 test_bytecode_limit
130
131 unset IFS
132 stop_lttng_sessiond
133
134 rm -f $ENABLE_EVENT_STDERR
135 rm -rf $TRACE_PATH
This page took 0.031097 seconds and 3 git commands to generate.