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