Fix: Sync issue when deleting a data stream
[lttng-tools.git] / tests / tools / filtering / valid-filters
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 - Valid filters"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../..
22 LTTNG_BIN="lttng"
23 BIN_NAME="gen-ust-events"
24 STATS_BIN="babelstats.pl"
25 SESSION_NAME="valid_filter"
26 EVENT_NAME="tp:tptest"
27 NR_ITER=100
28
29 source $TESTDIR/utils.sh
30
31 print_test_banner "$TEST_DESC"
32
33 if [ ! -x "$CURDIR/$BIN_NAME" ]; then
34 echo -e "No UST nevents binary detected. Passing."
35 exit 0
36 fi
37
38 function enable_ust_lttng_event_filter()
39 {
40 sess_name="$1"
41 event_name="$2"
42 filter="$3"
43 echo -n "Enabling lttng event with filtering "
44
45 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u --filter "$filter" 2>&1 >/dev/null
46
47 if [ $? -eq 0 ]; then
48 print_ok
49 return 0
50 else
51 print_fail
52 return 1
53 fi
54 }
55
56 function run_apps
57 {
58 ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1
59 }
60
61 function wait_apps
62 {
63 echo "Waiting for applications to end"
64 while [ -n "$(pidof $BIN_NAME)" ]; do
65 echo -n "."
66 sleep 1
67 done
68 echo ""
69 }
70
71 function test_valid_filter
72 {
73 filter="$1"
74 validator="$2"
75
76 echo ""
77 echo -e "=== Testing valid filter: $1"
78
79 trace_path=$(mktemp -d)
80
81 # Create session
82 create_lttng_session $SESSION_NAME $trace_path
83
84 # Enable filter
85 enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME $filter
86
87 # Trace apps
88 start_lttng_tracing $SESSION_NAME
89 run_apps
90 wait_apps
91 stop_lttng_tracing $SESSION_NAME
92
93 # Destroy session
94 destroy_lttng_session $SESSION_NAME
95
96 echo -n "Validating filter output "
97 stats=`babeltrace $trace_path | $CURDIR/$STATS_BIN --tracepoint $EVENT_NAME`
98
99 $validator "$stats"
100
101 if [ $? -eq 0 ]; then
102 print_ok
103 # rm -rf $trace_path
104 return 0
105 else
106 print_fail
107 return 1
108 fi
109 }
110
111 function validate_min_max
112 {
113 stats="$1"
114 field=$2
115 expected_min=$3
116 expected_max=$4
117
118 echo $stats | grep -q "$field $expected_min $expected_max"
119
120 return $?
121 }
122
123 function validator_intfield
124 {
125 stats="$1"
126 status=0
127
128 validate_min_max "$stats" "intfield" "1" "99"
129 status=$(($status|$?))
130
131 validate_min_max "$stats" "intfield2" "0x1" "0x63"
132 status=$(($status|$?))
133
134 validate_min_max "$stats" "longfield" "1" "99"
135 status=$(($status|$?))
136
137 validate_min_max "$stats" "netintfield" "1" "99"
138 status=$(($status|$?))
139
140 validate_min_max "$stats" "netintfieldhex" "0x1" "0x63"
141 status=$(($status|$?))
142
143 validate_min_max "$stats" "floatfield" "2222" "2222"
144 status=$(($status|$?))
145
146 validate_min_max "$stats" "doublefield" "2" "2"
147 status=$(($status|$?))
148
149 return $status
150 }
151
152 function validator_intfield_gt
153 {
154 stats="$1"
155 status=0
156
157 validate_min_max "$stats" "intfield" "2" "99"
158 status=$(($status|$?))
159
160 return $status
161 }
162
163 function validator_intfield_ge
164 {
165 stats="$1"
166 status=0
167
168 validate_min_max "$stats" "intfield" "1" "99"
169 status=$(($status|$?))
170
171 return $status
172 }
173
174 function validator_intfield_lt
175 {
176 stats="$1"
177 status=0
178
179 validate_min_max "$stats" "intfield" "0" "1"
180 status=$(($status|$?))
181
182 return $status
183 }
184
185 function validator_intfield_le
186 {
187 stats="$1"
188 status=0
189
190 validate_min_max "$stats" "intfield" "0" "2"
191 status=$(($status|$?))
192
193 return $status
194 }
195
196 function validator_intfield_eq
197 {
198 stats="$1"
199 status=0
200
201 validate_min_max "$stats" "intfield" "1" "1"
202 status=$(($status|$?))
203
204 return $status
205 }
206
207 function validator_intfield_ne
208 {
209 stats="$1"
210 status=0
211
212 validate_min_max "$stats" "intfield" "0" "98"
213 status=$(($status|$?))
214
215 return $status
216 }
217
218 function validator_intfield_not
219 {
220 stats="$1"
221 status=0
222
223 validate_min_max "$stats" "intfield" "0" "0"
224 status=$(($status|$?))
225
226 return $status
227 }
228
229 function validator_intfield_gt_and_longfield_gt
230 {
231 stats="$1"
232 status=0
233
234 validate_min_max "$stats" "intfield" "43" "99"
235 status=$(($status|$?))
236 validate_min_max "$stats" "longfield" "43" "99"
237 status=$(($status|$?))
238
239 return $status
240 }
241
242 function validator_intfield_ge_and_longfield_le
243 {
244 stats="$1"
245 status=0
246
247 validate_min_max "$stats" "intfield" "42" "42"
248 status=$(($status|$?))
249 validate_min_max "$stats" "longfield" "42" "42"
250 status=$(($status|$?))
251
252 return $status
253 }
254
255 function validator_intfield_lt_or_longfield_gt
256 {
257 stats="$1"
258 status=0
259
260 validate_min_max "$stats" "intfield" "0" "99"
261 status=$(($status|$?))
262 validate_min_max "$stats" "longfield" "0" "99"
263 status=$(($status|$?))
264
265 return $status
266 }
267
268 function validator_mixed_str_or_int_and_int
269 {
270 stats="$1"
271 status=0
272
273 validate_min_max "$stats" "intfield" "34" "99"
274 status=$(($status|$?))
275
276 validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
277 status=$(($status|$?))
278
279 return $status
280 }
281
282 function validator_mixed_int_double
283 {
284 stats="$1"
285 status=0
286
287 validate_min_max "$stats" "intfield" "0" "42"
288 status=$(($status|$?))
289
290 return $status
291 }
292
293 function validator_true_statement
294 {
295 stats="$1"
296 status=0
297
298 validate_min_max "$stats" "intfield" "0" "99"
299 status=$(($status|$?))
300
301 validate_min_max "$stats" "intfield2" "0x0" "0x63"
302 status=$(($status|$?))
303
304 validate_min_max "$stats" "longfield" "0" "99"
305 status=$(($status|$?))
306
307 validate_min_max "$stats" "netintfield" "0" "99"
308 status=$(($status|$?))
309
310 validate_min_max "$stats" "netintfieldhex" "0x0" "0x63"
311 status=$(($status|$?))
312
313 validate_min_max "$stats" "floatfield" "2222" "2222"
314 status=$(($status|$?))
315
316 validate_min_max "$stats" "doublefield" "2" "2"
317 status=$(($status|$?))
318
319 validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
320 status=$(($status|$?))
321
322 validate_min_max "$stats" "stringfield2" ""\*"" ""\*""
323 status=$(($status|$?))
324
325 return $status
326 }
327
328 IFS=$'\n'
329
330 issue_356_filter="intfield > 0 && intfield > 1 && "
331 issue_356_filter+="intfield > 2 && intfield > 3 && "
332 issue_356_filter+="intfield > 4 && intfield > 5 && "
333 issue_356_filter+="intfield > 6 && intfield > 7 && "
334 issue_356_filter+="intfield > 8 || intfield > 0"
335
336 # One to one mapping between filters and validators
337
338 FILTERS=("intfield" #1
339 "intfield > 1" #2
340 "intfield >= 1" #3
341 "intfield < 2" #4
342 "intfield <= 2" #5
343 "intfield == 1" #6
344 "intfield != 99" #7
345 "!intfield" #8
346 "-intfield" #9
347 "--intfield" #10
348 "+intfield" #11
349 "++intfield" #12
350 "intfield > 1 && longfield > 42" #13
351 "intfield >= 42 && longfield <= 42" #14
352 "intfield < 1 || longfield > 98" #15
353 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
354 "intfield < 42.4242424242" #17
355 "\"test\" == \"test\"" #18 #Issue #342
356 "stringfield == \"test\"" #19
357 "stringfield == \"t*\"" #20
358 "stringfield == \"*\"" #21
359 $issue_356_filter #22 #Issue #356
360 "intfield < 0xDEADBEEF" #23
361 "intfield < 0x2" #24
362 "intfield < 02" #25
363 "stringfield2 == \"\\\*\"" #26
364 )
365
366 VALIDATOR=("validator_intfield" #1
367 "validator_intfield_gt" #2
368 "validator_intfield_ge" #3
369 "validator_intfield_lt" #4
370 "validator_intfield_le" #5
371 "validator_intfield_eq" #6
372 "validator_intfield_ne" #7
373 "validator_intfield_not" #8
374 "validator_intfield" #9
375 "validator_intfield" #10
376 "validator_intfield" #11
377 "validator_intfield" #12
378 "validator_intfield_gt_and_longfield_gt" #13
379 "validator_intfield_ge_and_longfield_le" #14
380 "validator_intfield_lt_or_longfield_gt" #15
381 "validator_mixed_str_or_int_and_int" #16
382 "validator_mixed_int_double" #17
383 "validator_true_statement" #18
384 "validator_true_statement" #19
385 "validator_true_statement" #20
386 "validator_true_statement" #21
387 "validator_intfield" #22
388 "validator_true_statement" #23
389 "validator_intfield_lt" #24
390 "validator_intfield_lt" #25
391 "validator_true_statement" #26
392 )
393
394 FILTER_COUNT=${#FILTERS[@]}
395 i=0
396
397 start_lttng_sessiond
398
399 while [ "$i" -lt "$FILTER_COUNT" ]; do
400
401 test_valid_filter "${FILTERS[$i]}" "${VALIDATOR[$i]}"
402
403 if [ $? -eq 1 ]; then
404 stop_lttng_sessiond
405 exit 1
406 fi
407
408 let "i++"
409 done
410
411 stop_lttng_sessiond
This page took 0.058405 seconds and 4 git commands to generate.