3 # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License, version 2 only, as
9 # published by the Free Software Foundation.
11 # This program is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 # You should have received a copy of the GNU General Public License along with
17 # this program; if not, write to the Free Software Foundation, Inc., 51
18 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 TEST_DESC
="Filtering - Invalid filters"
23 TESTDIR
=$CURDIR/..
/..
/..
24 SESSION_NAME
="filter-invalid"
26 ENABLE_EVENT_STDERR
="/tmp/invalid-filters-stderr"
27 TRACE_PATH
=$
(mktemp
-d)
31 NUM_TESTS
=$
(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
33 source $TESTDIR/utils
/utils.sh
35 function enable_lttng_event_filter
42 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-event
$event_name -s $sess_name \
43 $domain --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev
/null
47 fail
"Enable lttng event with filtering and invalid filter"
50 pass
"Enable lttng event with filtering and invalid filter"
55 function test_invalid_filter
58 test_invalid_filter
="$2"
60 diag
"Test filter expression with invalid filter"
61 diag
"Filter: $test_invalid_filter"
64 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
67 enable_lttng_event_filter
$domain $SESSION_NAME $EVENT_NAME "$test_invalid_filter"
70 destroy_lttng_session_ok
$SESSION_NAME
73 function test_bytecode_limit
77 # Current bytecode limitation is 65536 bytes long.
78 # Generate a huge bytecode with some perl-fu
79 BYTECODE_LIMIT
=`perl -e 'print "intfield" . " && 1" x5460'`
81 diag
"Test filter bytecode limits (64KiB)"
84 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
87 enable_lttng_event_filter
$domain $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT"
90 destroy_lttng_session_ok
$SESSION_NAME
95 print_test_banner
"$TEST_DESC"
109 "asdfas < 2332 || asdf + 1 > 1"
110 "!+-+++-------+++++++++++-----!!--!44+1"
111 "aaa||(gg)+(333----1)"
113 # Unmatched parenthesis
114 "((((((((((((((intfield)))))))))))))"
115 '0 || ("abc" != "def")) && (3 < 4)'
119 # String can\'t be root node
121 # Unary op on string not allowed
123 # Comparison with string type not allowed
124 "\"somestring\" > 42"
125 "\"somestring\" > 42.0"
126 "42 > \"somestring\""
127 "42.0 > \"somestring\""
128 # Logical operator with string type not allowed
129 "\"somestring\" || 1"
130 "1 || \"somestring\""
133 # Only \$ctx is supported for now
134 "\$global.value == 0"
135 "0 == \$global.value"
136 # Cannot compare two full star globbing patterns
137 '"hello*world" == "yes*man"'
138 '"hello*world" == "yesman*"'
139 '"helloworld*" == "yes*man"'
140 # May only use != and == operators when one of them is a full
141 # star globbing pattern
142 '"hello*world" < field'
143 '"hello*world" <= field'
144 '"hello*world" >= field'
145 '"hello*world" > field'
146 '"hello*world" || field'
147 '"hello*world" && field'
148 'field < "hello*world"'
149 'field <= "hello*world"'
150 'field >= "hello*world"'
151 'field > "hello*world"'
152 'field && "hello*world"'
153 'field || "hello*world"'
158 diag
"Test UST filters"
161 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
162 echo "${INVALID_FILTERS[$i]}"
163 test_invalid_filter
-u "${INVALID_FILTERS[$i]}"
167 test_bytecode_limit
-u
169 if [ "$(id -u)" == "0" ]; then
175 skip
$isroot "Root access is needed. Skipping all kernel invalid filter tests." $NUM_KERNEL_TESTS ||
177 diag
"Test kernel filters"
179 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
180 echo "${INVALID_FILTERS[$i]}"
181 test_invalid_filter
-k "${INVALID_FILTERS[$i]}"
185 test_bytecode_limit
-k
189 rm -f $ENABLE_EVENT_STDERR