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