Tests: remove declaration already present in utils.sh
[lttng-tools.git] / tests / regression / tools / filtering / test_invalid_filter
CommitLineData
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
18TEST_DESC="Filtering - Invalid filters"
19
20CURDIR=$(dirname $0)/
9ac429ef 21TESTDIR=$CURDIR/../../..
b2a325c4
CB
22SESSION_NAME="filter-invalid"
23EVENT_NAME="bogus"
24ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr"
25TRACE_PATH=$(mktemp -d)
f6788fc4 26NUM_GLOBAL_TESTS=2
5da9cf86
MD
27NUM_UST_TESTS=123
28NUM_KERNEL_TESTS=123
f6788fc4 29NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
b2a325c4 30
9ac429ef 31source $TESTDIR/utils/utils.sh
b2a325c4 32
f6788fc4 33function 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
53function 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
71function 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
91plan_tests $NUM_TESTS
92
e3bef725
CB
93print_test_banner "$TEST_DESC"
94
e0bd0ea3 95OLDIFS="$IFS"
b2a325c4
CB
96IFS=$'\n'
97INVALID_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)'
b2a325c4
CB
120 "a->"
121 "a-->a"
122 "a->a"
123 "a.b.c->d.e.f+1"
b2a325c4 124 "asdfasdf->asdfasdf < 2"
6d5d85c7 125 # String can\'t be root node
ef049bee
CB
126 "\"somestring\""
127 # Unary op on string not allowed
128 "!\"somestring\""
129 # Comparison with string type not allowed
130 "\"somestring\" > 42"
131 "\"somestring\" > 42.0"
132 "42 > \"somestring\""
133 "42.0 > \"somestring\""
134 # Logical operator with string type not allowed
135 "\"somestring\" || 1"
136 "1 || \"somestring\""
137 # Nesting of binary operator not allowed
138 "1 | (1 | (1 | 1))"
139 "1 > (1 > (1 > 1))"
6d5d85c7
MD
140 "\$ctx == 0"
141 "0 == \$ctx"
142 # Only \$ctx is supported for now
143 "\$global.value == 0"
144 "0 == \$global.value"
22fb211b
JG
145 # A wildcard should only appear as the last character in a string literal
146 "msg == \"my_event*_blah\""
e0bd0ea3
JR
147)
148IFS="$OLDIFS"
b2a325c4
CB
149
150start_lttng_sessiond
f6788fc4 151diag "Test UST filters"
e0bd0ea3
JR
152
153i=0
154while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
155 echo "${INVALID_FILTERS[$i]}"
156 test_invalid_filter -u "${INVALID_FILTERS[$i]}"
157 let "i++"
b2a325c4
CB
158done
159
f6788fc4
MD
160test_bytecode_limit -u
161
162if [ "$(id -u)" == "0" ]; then
163 isroot=1
164else
165 isroot=0
166fi
167
168skip $isroot "Root access is needed. Skipping all kernel invalid filter tests." $NUM_KERNEL_TESTS ||
169{
170 diag "Test kernel filters"
e0bd0ea3
JR
171 i=0
172 while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
173 echo "${INVALID_FILTERS[$i]}"
174 test_invalid_filter -k "${INVALID_FILTERS[$i]}"
175 let "i++"
f6788fc4
MD
176 done
177
178 test_bytecode_limit -k
179}
b2a325c4
CB
180stop_lttng_sessiond
181
182rm -f $ENABLE_EVENT_STDERR
183rm -rf $TRACE_PATH
This page took 0.040499 seconds and 4 git commands to generate.