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"
107 "asdfas < 2332 || asdf + 1 > 1"
108 "!+-+++-------+++++++++++-----!!--!44+1"
109 "aaa||(gg)+(333----1)"
111 # Unmatched parenthesis
112 "((((((((((((((intfield)))))))))))))"
113 '0 || ("abc" != "def")) && (3 < 4)'
117 # String can\'t be root node
119 # Unary op on string not allowed
121 # Comparison with string type not allowed
122 "\"somestring\" > 42"
123 "\"somestring\" > 42.0"
124 "42 > \"somestring\""
125 "42.0 > \"somestring\""
126 # Logical operator with string type not allowed
127 "\"somestring\" || 1"
128 "1 || \"somestring\""
131 # Only \$ctx is supported for now
132 "\$global.value == 0"
133 "0 == \$global.value"
134 # Cannot compare two full star globbing patterns
135 '"hello*world" == "yes*man"'
136 '"hello*world" == "yesman*"'
137 '"helloworld*" == "yes*man"'
138 # May only use != and == operators when one of them is a full
139 # star globbing pattern
140 '"hello*world" < field'
141 '"hello*world" <= field'
142 '"hello*world" >= field'
143 '"hello*world" > field'
144 '"hello*world" || field'
145 '"hello*world" && field'
146 'field < "hello*world"'
147 'field <= "hello*world"'
148 'field >= "hello*world"'
149 'field > "hello*world"'
150 'field && "hello*world"'
151 'field || "hello*world"'
156 diag
"Test UST filters"
159 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
160 echo "${INVALID_FILTERS[$i]}"
161 test_invalid_filter
-u "${INVALID_FILTERS[$i]}"
165 test_bytecode_limit
-u
167 if [ "$(id -u)" == "0" ]; then
173 skip
$isroot "Root access is needed. Skipping all kernel invalid filter tests." $NUM_KERNEL_TESTS ||
175 diag
"Test kernel filters"
177 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
178 echo "${INVALID_FILTERS[$i]}"
179 test_invalid_filter
-k "${INVALID_FILTERS[$i]}"
183 test_bytecode_limit
-k
187 rm -f $ENABLE_EVENT_STDERR