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