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