Filter: Implement rshift, lshift, bit not operators
[lttng-tools.git] / tests / regression / tools / filtering / test_invalid_filter
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 NUM_GLOBAL_TESTS=2
28 NUM_UST_TESTS=135
29 NUM_KERNEL_TESTS=135
30 NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
31
32 source $TESTDIR/utils/utils.sh
33
34 function enable_lttng_event_filter
35 {
36 domain="$1"
37 sess_name="$2"
38 event_name="$3"
39 filter="$4"
40
41 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name \
42 $domain --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev/null
43
44 # Enable must fail
45 if [ $? -eq 0 ]; then
46 fail "Enable lttng event with filtering and invalid filter"
47 return 1
48 else
49 pass "Enable lttng event with filtering and invalid filter"
50 return 0
51 fi
52 }
53
54 function test_invalid_filter
55 {
56 domain="$1"
57 test_invalid_filter="$2"
58
59 diag "Test filter expression with invalid filter"
60 diag "Filter: $test_invalid_filter"
61
62 # Create session
63 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
64
65 # Apply filter
66 enable_lttng_event_filter $domain $SESSION_NAME $EVENT_NAME "$test_invalid_filter"
67
68 # Destroy session
69 destroy_lttng_session_ok $SESSION_NAME
70 }
71
72 function test_bytecode_limit
73 {
74 domain="$1"
75
76 # Current bytecode limitation is 65536 bytes long.
77 # Generate a huge bytecode with some perl-fu
78 BYTECODE_LIMIT=`perl -e 'print "intfield" . " && 1" x5460'`
79
80 diag "Test filter bytecode limits (64KiB)"
81
82 # Create session
83 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
84
85 # Apply filter
86 enable_lttng_event_filter $domain $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT"
87
88 # Destroy session
89 destroy_lttng_session_ok $SESSION_NAME
90 }
91
92 plan_tests $NUM_TESTS
93
94 print_test_banner "$TEST_DESC"
95
96 OLDIFS="$IFS"
97 IFS=$'\n'
98 INVALID_FILTERS=(
99 # Unsupported ops
100 "intfield*1"
101 "intfield/1"
102 "intfield+1"
103 "intfield-1"
104 "1+11111-3333+1"
105 "(1+2)*(55*666)"
106 "1+2*55*666"
107 "asdf + 1 > 1"
108 "asdfas < 2332 || asdf + 1 > 1"
109 "!+-+++-------+++++++++++-----!!--!44+1"
110 "aaa||(gg)+(333----1)"
111 "1+1"
112 # Unmatched parenthesis
113 "((((((((((((((intfield)))))))))))))"
114 '0 || ("abc" != "def")) && (3 < 4)'
115 "a->"
116 "a-->a"
117 "a.b.c->d.e.f+1"
118 # String can\'t be root node
119 "\"somestring\""
120 # Unary op on string not allowed
121 "!\"somestring\""
122 # Comparison with string type not allowed
123 "\"somestring\" > 42"
124 "\"somestring\" > 42.0"
125 "42 > \"somestring\""
126 "42.0 > \"somestring\""
127 # Logical operator with string type not allowed
128 "\"somestring\" || 1"
129 "1 || \"somestring\""
130 "\$ctx == 0"
131 "0 == \$ctx"
132 # Only \$ctx is supported for now
133 "\$global.value == 0"
134 "0 == \$global.value"
135 # Cannot compare two full star globbing patterns
136 '"hello*world" == "yes*man"'
137 '"hello*world" == "yesman*"'
138 '"helloworld*" == "yes*man"'
139 # May only use != and == operators when one of them is a full
140 # star globbing pattern
141 '"hello*world" < field'
142 '"hello*world" <= field'
143 '"hello*world" >= field'
144 '"hello*world" > field'
145 '"hello*world" || field'
146 '"hello*world" && field'
147 'field < "hello*world"'
148 'field <= "hello*world"'
149 'field >= "hello*world"'
150 'field > "hello*world"'
151 'field && "hello*world"'
152 'field || "hello*world"'
153 )
154 IFS="$OLDIFS"
155
156 start_lttng_sessiond
157 diag "Test UST filters"
158
159 i=0
160 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
161 echo "${INVALID_FILTERS[$i]}"
162 test_invalid_filter -u "${INVALID_FILTERS[$i]}"
163 let "i++"
164 done
165
166 test_bytecode_limit -u
167
168 if [ "$(id -u)" == "0" ]; then
169 isroot=1
170 else
171 isroot=0
172 fi
173
174 skip $isroot "Root access is needed. Skipping all kernel invalid filter tests." $NUM_KERNEL_TESTS ||
175 {
176 diag "Test kernel filters"
177 i=0
178 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
179 echo "${INVALID_FILTERS[$i]}"
180 test_invalid_filter -k "${INVALID_FILTERS[$i]}"
181 let "i++"
182 done
183
184 test_bytecode_limit -k
185 }
186 stop_lttng_sessiond
187
188 rm -f $ENABLE_EVENT_STDERR
189 rm -rf $TRACE_PATH
This page took 0.035877 seconds and 5 git commands to generate.