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 | LTTNG_BIN="lttng" |
23 | SESSION_NAME="filter-invalid" | |
24 | EVENT_NAME="bogus" | |
25 | ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr" | |
26 | TRACE_PATH=$(mktemp -d) | |
f6788fc4 MD |
27 | NUM_GLOBAL_TESTS=2 |
28 | NUM_UST_TESTS=144 | |
29 | NUM_KERNEL_TESTS=144 | |
30 | NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS)) | |
b2a325c4 | 31 | |
9ac429ef | 32 | source $TESTDIR/utils/utils.sh |
b2a325c4 | 33 | |
f6788fc4 | 34 | function enable_lttng_event_filter |
b2a325c4 | 35 | { |
f6788fc4 MD |
36 | domain="$1" |
37 | sess_name="$2" | |
38 | event_name="$3" | |
39 | filter="$4" | |
b2a325c4 | 40 | |
f6788fc4 MD |
41 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name \ |
42 | $domain --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev/null | |
b2a325c4 CB |
43 | |
44 | # Enable must fail | |
45 | if [ $? -eq 0 ]; then | |
03276eea | 46 | fail "Enable lttng event with filtering and invalid filter" |
b2a325c4 CB |
47 | return 1 |
48 | else | |
03276eea | 49 | pass "Enable lttng event with filtering and invalid filter" |
b2a325c4 CB |
50 | return 0 |
51 | fi | |
52 | } | |
53 | ||
54 | function test_invalid_filter | |
55 | { | |
f6788fc4 MD |
56 | domain="$1" |
57 | test_invalid_filter="$2" | |
b2a325c4 | 58 | |
03276eea CB |
59 | diag "Test filter expression with invalid filter" |
60 | diag "Filter: $test_invalid_filter" | |
b2a325c4 CB |
61 | |
62 | # Create session | |
bf6ae429 | 63 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
b2a325c4 CB |
64 | |
65 | # Apply filter | |
f6788fc4 | 66 | enable_lttng_event_filter $domain $SESSION_NAME $EVENT_NAME "$test_invalid_filter" |
b2a325c4 CB |
67 | |
68 | # Destroy session | |
67b4c664 | 69 | destroy_lttng_session_ok $SESSION_NAME |
b2a325c4 CB |
70 | } |
71 | ||
72 | function test_bytecode_limit | |
73 | { | |
f6788fc4 MD |
74 | domain="$1" |
75 | ||
b2a325c4 CB |
76 | # Current bytecode limitation is 65536 bytes long. |
77 | # Generate a huge bytecode with some perl-fu | |
78 | BYTECODE_LIMIT=`perl -e 'print "intfield" . " && 1" x5460'` | |
79 | ||
03276eea | 80 | diag "Test filter bytecode limits (64KiB)" |
b2a325c4 CB |
81 | |
82 | # Create session | |
bf6ae429 | 83 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
b2a325c4 CB |
84 | |
85 | # Apply filter | |
f6788fc4 | 86 | enable_lttng_event_filter $domain $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT" |
b2a325c4 CB |
87 | |
88 | # Destroy session | |
67b4c664 | 89 | destroy_lttng_session_ok $SESSION_NAME |
b2a325c4 CB |
90 | } |
91 | ||
03276eea CB |
92 | plan_tests $NUM_TESTS |
93 | ||
e3bef725 CB |
94 | print_test_banner "$TEST_DESC" |
95 | ||
b2a325c4 CB |
96 | IFS=$'\n' |
97 | INVALID_FILTERS=( | |
98 | # Unsupported ops | |
99 | "intfield*1" | |
100 | "intfield/1" | |
101 | "intfield+1" | |
102 | "intfield-1" | |
103 | "intfield>>1" | |
104 | "intfield<<1" | |
105 | "intfield&1" | |
106 | "intfield|1" | |
107 | "intfield^1" | |
108 | "~intfield" | |
109 | "1+11111-3333+1" | |
110 | "(1+2)*(55*666)" | |
111 | "1+2*55*666" | |
112 | "asdf + 1 > 1" | |
113 | "asdfas < 2332 || asdf + 1 > 1" | |
114 | "!+-+++-------+++++++++++-----!!--!44+1" | |
115 | "aaa||(gg)+(333----1)" | |
116 | "1+1" | |
117 | # Unmatched parenthesis | |
118 | "((((((((((((((intfield)))))))))))))" | |
119 | '0 || ("abc" != "def")) && (3 < 4)' | |
120 | # Field dereference | |
121 | "a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" | |
122 | "a->" | |
123 | "a-->a" | |
124 | "a->a" | |
125 | "a.b.c->d.e.f+1" | |
126 | "!a.f.d" | |
127 | "asdf.asdfsd.sadf < 4" | |
128 | "asdfasdf->asdfasdf < 2" | |
6d5d85c7 | 129 | # String can\'t be root node |
ef049bee CB |
130 | "\"somestring\"" |
131 | # Unary op on string not allowed | |
132 | "!\"somestring\"" | |
133 | # Comparison with string type not allowed | |
134 | "\"somestring\" > 42" | |
135 | "\"somestring\" > 42.0" | |
136 | "42 > \"somestring\"" | |
137 | "42.0 > \"somestring\"" | |
138 | # Logical operator with string type not allowed | |
139 | "\"somestring\" || 1" | |
140 | "1 || \"somestring\"" | |
141 | # Nesting of binary operator not allowed | |
142 | "1 | (1 | (1 | 1))" | |
143 | "1 > (1 > (1 > 1))" | |
6d5d85c7 MD |
144 | # Exactly one chaining level under \$ctx allowed |
145 | "\$ctx.vtid.blah == 0" | |
146 | "0 == \$ctx.vtid.blah" | |
147 | "\$ctx.44 == 0" | |
148 | "0 == \$ctx.44" | |
149 | "\$ctx == 0" | |
150 | "0 == \$ctx" | |
151 | # Only \$ctx is supported for now | |
152 | "\$global.value == 0" | |
153 | "0 == \$global.value" | |
22fb211b JG |
154 | # A wildcard should only appear as the last character in a string literal |
155 | "msg == \"my_event*_blah\"" | |
b2a325c4 CB |
156 | ) |
157 | ||
158 | start_lttng_sessiond | |
f6788fc4 | 159 | diag "Test UST filters" |
b2a325c4 CB |
160 | for FILTER in ${INVALID_FILTERS[@]}; |
161 | do | |
f6788fc4 | 162 | test_invalid_filter -u "$FILTER" |
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" | |
176 | for FILTER in ${INVALID_FILTERS[@]}; | |
177 | do | |
178 | test_invalid_filter -k "$FILTER" | |
179 | done | |
180 | ||
181 | test_bytecode_limit -k | |
182 | } | |
b2a325c4 CB |
183 | |
184 | unset IFS | |
185 | stop_lttng_sessiond | |
186 | ||
187 | rm -f $ENABLE_EVENT_STDERR | |
188 | rm -rf $TRACE_PATH |