Commit | Line | Data |
---|---|---|
b2a325c4 CB |
1 | #!/bin/bash |
2 | # | |
9d16b343 MJ |
3 | # Copyright (C) 2012 Christian Babeux <christian.babeux@efficios.com> |
4 | # | |
5 | # SPDX-License-Identifier: GPL-2.0-only | |
b2a325c4 CB |
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)/ | |
9ac429ef | 23 | TESTDIR=$CURDIR/../../.. |
b2a325c4 CB |
24 | SESSION_NAME="filter-invalid" |
25 | EVENT_NAME="bogus" | |
26 | ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr" | |
33e55711 | 27 | TRACE_PATH=$(mktemp --tmpdir -d tmp.test_filtering_invalid_filters_trace_path.XXXXXX) |
f6788fc4 | 28 | NUM_GLOBAL_TESTS=2 |
c6ec013d MD |
29 | NUM_UST_TESTS=138 |
30 | NUM_KERNEL_TESTS=138 | |
f6788fc4 | 31 | NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS)) |
b2a325c4 | 32 | |
9ac429ef | 33 | source $TESTDIR/utils/utils.sh |
b2a325c4 | 34 | |
f6788fc4 | 35 | function enable_lttng_event_filter |
b2a325c4 | 36 | { |
f6788fc4 MD |
37 | domain="$1" |
38 | sess_name="$2" | |
39 | event_name="$3" | |
40 | filter="$4" | |
b2a325c4 | 41 | |
f6788fc4 MD |
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 | |
b2a325c4 CB |
44 | |
45 | # Enable must fail | |
46 | if [ $? -eq 0 ]; then | |
03276eea | 47 | fail "Enable lttng event with filtering and invalid filter" |
b2a325c4 CB |
48 | return 1 |
49 | else | |
03276eea | 50 | pass "Enable lttng event with filtering and invalid filter" |
b2a325c4 CB |
51 | return 0 |
52 | fi | |
53 | } | |
54 | ||
55 | function test_invalid_filter | |
56 | { | |
f6788fc4 MD |
57 | domain="$1" |
58 | test_invalid_filter="$2" | |
b2a325c4 | 59 | |
03276eea CB |
60 | diag "Test filter expression with invalid filter" |
61 | diag "Filter: $test_invalid_filter" | |
b2a325c4 CB |
62 | |
63 | # Create session | |
bf6ae429 | 64 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
b2a325c4 CB |
65 | |
66 | # Apply filter | |
f6788fc4 | 67 | enable_lttng_event_filter $domain $SESSION_NAME $EVENT_NAME "$test_invalid_filter" |
b2a325c4 CB |
68 | |
69 | # Destroy session | |
67b4c664 | 70 | destroy_lttng_session_ok $SESSION_NAME |
b2a325c4 CB |
71 | } |
72 | ||
73 | function test_bytecode_limit | |
74 | { | |
f6788fc4 MD |
75 | domain="$1" |
76 | ||
b2a325c4 CB |
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 | ||
03276eea | 81 | diag "Test filter bytecode limits (64KiB)" |
b2a325c4 CB |
82 | |
83 | # Create session | |
bf6ae429 | 84 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
b2a325c4 CB |
85 | |
86 | # Apply filter | |
f6788fc4 | 87 | enable_lttng_event_filter $domain $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT" |
b2a325c4 CB |
88 | |
89 | # Destroy session | |
67b4c664 | 90 | destroy_lttng_session_ok $SESSION_NAME |
b2a325c4 CB |
91 | } |
92 | ||
03276eea CB |
93 | plan_tests $NUM_TESTS |
94 | ||
e3bef725 CB |
95 | print_test_banner "$TEST_DESC" |
96 | ||
e0bd0ea3 | 97 | OLDIFS="$IFS" |
b2a325c4 CB |
98 | IFS=$'\n' |
99 | INVALID_FILTERS=( | |
100 | # Unsupported ops | |
101 | "intfield*1" | |
102 | "intfield/1" | |
103 | "intfield+1" | |
104 | "intfield-1" | |
b2a325c4 CB |
105 | "1+11111-3333+1" |
106 | "(1+2)*(55*666)" | |
107 | "1+2*55*666" | |
108 | "asdf + 1 > 1" | |
109 | "asdfas < 2332 || asdf + 1 > 1" | |
110 | "!+-+++-------+++++++++++-----!!--!44+1" | |
111 | "aaa||(gg)+(333----1)" | |
112 | "1+1" | |
113 | # Unmatched parenthesis | |
114 | "((((((((((((((intfield)))))))))))))" | |
115 | '0 || ("abc" != "def")) && (3 < 4)' | |
b2a325c4 CB |
116 | "a->" |
117 | "a-->a" | |
b2a325c4 | 118 | "a.b.c->d.e.f+1" |
6d5d85c7 | 119 | # String can\'t be root node |
ef049bee CB |
120 | "\"somestring\"" |
121 | # Unary op on string not allowed | |
122 | "!\"somestring\"" | |
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\"" | |
6d5d85c7 MD |
131 | "\$ctx == 0" |
132 | "0 == \$ctx" | |
133 | # Only \$ctx is supported for now | |
134 | "\$global.value == 0" | |
135 | "0 == \$global.value" | |
fc717c6c PP |
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"' | |
c6ec013d MD |
154 | # Array expression must contain constant index |
155 | 'field[abc] == 1' | |
e0bd0ea3 JR |
156 | ) |
157 | IFS="$OLDIFS" | |
b2a325c4 CB |
158 | |
159 | start_lttng_sessiond | |
f6788fc4 | 160 | diag "Test UST filters" |
e0bd0ea3 JR |
161 | |
162 | i=0 | |
163 | while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do | |
164 | echo "${INVALID_FILTERS[$i]}" | |
165 | test_invalid_filter -u "${INVALID_FILTERS[$i]}" | |
166 | let "i++" | |
b2a325c4 CB |
167 | done |
168 | ||
f6788fc4 MD |
169 | test_bytecode_limit -u |
170 | ||
171 | if [ "$(id -u)" == "0" ]; then | |
172 | isroot=1 | |
173 | else | |
174 | isroot=0 | |
175 | fi | |
176 | ||
177 | skip $isroot "Root access is needed. Skipping all kernel invalid filter tests." $NUM_KERNEL_TESTS || | |
178 | { | |
179 | diag "Test kernel filters" | |
e0bd0ea3 JR |
180 | i=0 |
181 | while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do | |
182 | echo "${INVALID_FILTERS[$i]}" | |
183 | test_invalid_filter -k "${INVALID_FILTERS[$i]}" | |
184 | let "i++" | |
f6788fc4 MD |
185 | done |
186 | ||
187 | test_bytecode_limit -k | |
188 | } | |
b2a325c4 CB |
189 | stop_lttng_sessiond |
190 | ||
191 | rm -f $ENABLE_EVENT_STDERR | |
192 | rm -rf $TRACE_PATH |