3 # Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com>
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.
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
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.
18 TEST_DESC
="Filtering - Invalid filters"
21 TESTDIR
=$CURDIR/..
/..
/..
22 SESSION_NAME
="filter-invalid"
24 ENABLE_EVENT_STDERR
="/tmp/invalid-filters-stderr"
25 TRACE_PATH
=$
(mktemp
-d)
29 NUM_TESTS
=$
(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
31 source $TESTDIR/utils
/utils.sh
33 function enable_lttng_event_filter
40 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$event_name -s $sess_name \
41 $domain --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev
/null
45 fail
"Enable lttng event with filtering and invalid filter"
48 pass
"Enable lttng event with filtering and invalid filter"
53 function test_invalid_filter
56 test_invalid_filter
="$2"
58 diag
"Test filter expression with invalid filter"
59 diag
"Filter: $test_invalid_filter"
62 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
65 enable_lttng_event_filter
$domain $SESSION_NAME $EVENT_NAME "$test_invalid_filter"
68 destroy_lttng_session_ok
$SESSION_NAME
71 function test_bytecode_limit
75 # Current bytecode limitation is 65536 bytes long.
76 # Generate a huge bytecode with some perl-fu
77 BYTECODE_LIMIT
=`perl -e 'print "intfield" . " && 1" x5460'`
79 diag
"Test filter bytecode limits (64KiB)"
82 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
85 enable_lttng_event_filter
$domain $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT"
88 destroy_lttng_session_ok
$SESSION_NAME
93 print_test_banner
"$TEST_DESC"
113 "asdfas
< 2332 || asdf
+ 1 > 1"
114 "!+-+++-------+++++++++++-----!!--!44+1"
115 "aaa||
(gg
)+(333----1)"
117 # Unmatched parenthesis
118 "((((((((((((((intfield
)))))))))))))"
119 '0 || ("abc
" != "def
")) && (3 < 4)'
124 "asdfasdf-
>asdfasdf
< 2"
125 # String can\'t be root node
127 # Unary op on string not allowed
129 # Comparison with string type not allowed
130 "\"somestring
\" > 42"
131 "\"somestring
\" > 42.0"
132 "42 > \"somestring
\""
133 "42.0 > \"somestring
\""
134 # Logical operator with string type not allowed
135 "\"somestring
\" ||
1"
136 "1 ||
\"somestring
\""
137 # Nesting of binary operator not allowed
142 # Only \$ctx is supported for now
143 "\
$global.value
== 0"
144 "0 == \
$global.value
"
145 # Cannot compare two full star globbing patterns
146 '"hello
*world
" == "yes*man
"'
147 '"hello
*world
" == "yesman
*"'
148 '"helloworld
*" == "yes*man
"'
149 # May only use != and == operators when one of them is a full
150 # star globbing pattern
151 '"hello
*world
" < field'
152 '"hello
*world
" <= field'
153 '"hello
*world
" >= field'
154 '"hello
*world
" > field'
155 '"hello
*world
" || field'
156 '"hello
*world
" && field'
157 'field < "hello
*world
"'
158 'field <= "hello
*world
"'
159 'field >= "hello
*world
"'
160 'field > "hello
*world
"'
161 'field && "hello
*world
"'
162 'field || "hello
*world
"'
167 diag "Test UST filters
"
170 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
171 echo "${INVALID_FILTERS[$i]}"
172 test_invalid_filter -u "${INVALID_FILTERS[$i]}"
176 test_bytecode_limit -u
178 if [ "$
(id
-u)" == "0" ]; then
184 skip $isroot "Root access is needed. Skipping all kernel invalid filter tests.
" $NUM_KERNEL_TESTS ||
186 diag "Test kernel filters
"
188 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
189 echo "${INVALID_FILTERS[$i]}"
190 test_invalid_filter -k "${INVALID_FILTERS[$i]}"
194 test_bytecode_limit -k
198 rm -f $ENABLE_EVENT_STDERR