Filter: index array, sequences, implement bitwise binary operators
[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
22LTTNG_BIN="lttng"
23SESSION_NAME="filter-invalid"
24EVENT_NAME="bogus"
25ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr"
26TRACE_PATH=$(mktemp -d)
f6788fc4 27NUM_GLOBAL_TESTS=2
bff988fa
MD
28NUM_UST_TESTS=144
29NUM_KERNEL_TESTS=144
f6788fc4 30NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS))
b2a325c4 31
9ac429ef 32source $TESTDIR/utils/utils.sh
b2a325c4 33
f6788fc4 34function 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
54function 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
72function 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
92plan_tests $NUM_TESTS
93
e3bef725
CB
94print_test_banner "$TEST_DESC"
95
e0bd0ea3 96OLDIFS="$IFS"
b2a325c4
CB
97IFS=$'\n'
98INVALID_FILTERS=(
99 # Unsupported ops
100 "intfield*1"
101 "intfield/1"
102 "intfield+1"
103 "intfield-1"
104 "intfield>>1"
105 "intfield<<1"
b2a325c4
CB
106 "~intfield"
107 "1+11111-3333+1"
108 "(1+2)*(55*666)"
109 "1+2*55*666"
110 "asdf + 1 > 1"
111 "asdfas < 2332 || asdf + 1 > 1"
112 "!+-+++-------+++++++++++-----!!--!44+1"
113 "aaa||(gg)+(333----1)"
114 "1+1"
115 # Unmatched parenthesis
116 "((((((((((((((intfield)))))))))))))"
117 '0 || ("abc" != "def")) && (3 < 4)'
b2a325c4
CB
118 "a->"
119 "a-->a"
b2a325c4 120 "a.b.c->d.e.f+1"
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\""
6d5d85c7
MD
133 "\$ctx == 0"
134 "0 == \$ctx"
135 # Only \$ctx is supported for now
136 "\$global.value == 0"
137 "0 == \$global.value"
fc717c6c
PP
138 # Cannot compare two full star globbing patterns
139 '"hello*world" == "yes*man"'
140 '"hello*world" == "yesman*"'
141 '"helloworld*" == "yes*man"'
142 # May only use != and == operators when one of them is a full
143 # star globbing pattern
144 '"hello*world" < field'
145 '"hello*world" <= field'
146 '"hello*world" >= field'
147 '"hello*world" > field'
148 '"hello*world" || field'
149 '"hello*world" && field'
150 'field < "hello*world"'
151 'field <= "hello*world"'
152 'field >= "hello*world"'
153 'field > "hello*world"'
154 'field && "hello*world"'
155 'field || "hello*world"'
e0bd0ea3
JR
156)
157IFS="$OLDIFS"
b2a325c4
CB
158
159start_lttng_sessiond
f6788fc4 160diag "Test UST filters"
e0bd0ea3
JR
161
162i=0
163while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do
164 echo "${INVALID_FILTERS[$i]}"
165 test_invalid_filter -u "${INVALID_FILTERS[$i]}"
166 let "i++"
b2a325c4
CB
167done
168
f6788fc4
MD
169test_bytecode_limit -u
170
171if [ "$(id -u)" == "0" ]; then
172 isroot=1
173else
174 isroot=0
175fi
176
177skip $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
189stop_lttng_sessiond
190
191rm -f $ENABLE_EVENT_STDERR
192rm -rf $TRACE_PATH
This page took 0.056567 seconds and 5 git commands to generate.