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