| 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 - Invalid filters" |
| 19 | |
| 20 | CURDIR=$(dirname $0)/ |
| 21 | TESTDIR=$CURDIR/../../.. |
| 22 | SESSION_NAME="filter-invalid" |
| 23 | EVENT_NAME="bogus" |
| 24 | ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr" |
| 25 | TRACE_PATH=$(mktemp -d) |
| 26 | NUM_GLOBAL_TESTS=2 |
| 27 | NUM_UST_TESTS=135 |
| 28 | NUM_KERNEL_TESTS=135 |
| 29 | NUM_TESTS=$(($NUM_UST_TESTS+$NUM_KERNEL_TESTS+$NUM_GLOBAL_TESTS)) |
| 30 | |
| 31 | source $TESTDIR/utils/utils.sh |
| 32 | |
| 33 | function enable_lttng_event_filter |
| 34 | { |
| 35 | domain="$1" |
| 36 | sess_name="$2" |
| 37 | event_name="$3" |
| 38 | filter="$4" |
| 39 | |
| 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 |
| 42 | |
| 43 | # Enable must fail |
| 44 | if [ $? -eq 0 ]; then |
| 45 | fail "Enable lttng event with filtering and invalid filter" |
| 46 | return 1 |
| 47 | else |
| 48 | pass "Enable lttng event with filtering and invalid filter" |
| 49 | return 0 |
| 50 | fi |
| 51 | } |
| 52 | |
| 53 | function test_invalid_filter |
| 54 | { |
| 55 | domain="$1" |
| 56 | test_invalid_filter="$2" |
| 57 | |
| 58 | diag "Test filter expression with invalid filter" |
| 59 | diag "Filter: $test_invalid_filter" |
| 60 | |
| 61 | # Create session |
| 62 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 63 | |
| 64 | # Apply filter |
| 65 | enable_lttng_event_filter $domain $SESSION_NAME $EVENT_NAME "$test_invalid_filter" |
| 66 | |
| 67 | # Destroy session |
| 68 | destroy_lttng_session_ok $SESSION_NAME |
| 69 | } |
| 70 | |
| 71 | function test_bytecode_limit |
| 72 | { |
| 73 | domain="$1" |
| 74 | |
| 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 | |
| 79 | diag "Test filter bytecode limits (64KiB)" |
| 80 | |
| 81 | # Create session |
| 82 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 83 | |
| 84 | # Apply filter |
| 85 | enable_lttng_event_filter $domain $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT" |
| 86 | |
| 87 | # Destroy session |
| 88 | destroy_lttng_session_ok $SESSION_NAME |
| 89 | } |
| 90 | |
| 91 | plan_tests $NUM_TESTS |
| 92 | |
| 93 | print_test_banner "$TEST_DESC" |
| 94 | |
| 95 | OLDIFS="$IFS" |
| 96 | IFS=$'\n' |
| 97 | INVALID_FILTERS=( |
| 98 | # Unsupported ops |
| 99 | "intfield*1" |
| 100 | "intfield/1" |
| 101 | "intfield+1" |
| 102 | "intfield-1" |
| 103 | "1+11111-3333+1" |
| 104 | "(1+2)*(55*666)" |
| 105 | "1+2*55*666" |
| 106 | "asdf + 1 > 1" |
| 107 | "asdfas < 2332 || asdf + 1 > 1" |
| 108 | "!+-+++-------+++++++++++-----!!--!44+1" |
| 109 | "aaa||(gg)+(333----1)" |
| 110 | "1+1" |
| 111 | # Unmatched parenthesis |
| 112 | "((((((((((((((intfield)))))))))))))" |
| 113 | '0 || ("abc" != "def")) && (3 < 4)' |
| 114 | "a->" |
| 115 | "a-->a" |
| 116 | "a.b.c->d.e.f+1" |
| 117 | # String can\'t be root node |
| 118 | "\"somestring\"" |
| 119 | # Unary op on string not allowed |
| 120 | "!\"somestring\"" |
| 121 | # Comparison with string type not allowed |
| 122 | "\"somestring\" > 42" |
| 123 | "\"somestring\" > 42.0" |
| 124 | "42 > \"somestring\"" |
| 125 | "42.0 > \"somestring\"" |
| 126 | # Logical operator with string type not allowed |
| 127 | "\"somestring\" || 1" |
| 128 | "1 || \"somestring\"" |
| 129 | "\$ctx == 0" |
| 130 | "0 == \$ctx" |
| 131 | # Only \$ctx is supported for now |
| 132 | "\$global.value == 0" |
| 133 | "0 == \$global.value" |
| 134 | # Cannot compare two full star globbing patterns |
| 135 | '"hello*world" == "yes*man"' |
| 136 | '"hello*world" == "yesman*"' |
| 137 | '"helloworld*" == "yes*man"' |
| 138 | # May only use != and == operators when one of them is a full |
| 139 | # star globbing pattern |
| 140 | '"hello*world" < field' |
| 141 | '"hello*world" <= field' |
| 142 | '"hello*world" >= field' |
| 143 | '"hello*world" > field' |
| 144 | '"hello*world" || field' |
| 145 | '"hello*world" && field' |
| 146 | 'field < "hello*world"' |
| 147 | 'field <= "hello*world"' |
| 148 | 'field >= "hello*world"' |
| 149 | 'field > "hello*world"' |
| 150 | 'field && "hello*world"' |
| 151 | 'field || "hello*world"' |
| 152 | ) |
| 153 | IFS="$OLDIFS" |
| 154 | |
| 155 | start_lttng_sessiond |
| 156 | diag "Test UST filters" |
| 157 | |
| 158 | i=0 |
| 159 | while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do |
| 160 | echo "${INVALID_FILTERS[$i]}" |
| 161 | test_invalid_filter -u "${INVALID_FILTERS[$i]}" |
| 162 | let "i++" |
| 163 | done |
| 164 | |
| 165 | test_bytecode_limit -u |
| 166 | |
| 167 | if [ "$(id -u)" == "0" ]; then |
| 168 | isroot=1 |
| 169 | else |
| 170 | isroot=0 |
| 171 | fi |
| 172 | |
| 173 | skip $isroot "Root access is needed. Skipping all kernel invalid filter tests." $NUM_KERNEL_TESTS || |
| 174 | { |
| 175 | diag "Test kernel filters" |
| 176 | i=0 |
| 177 | while [ "$i" -lt "${#INVALID_FILTERS[@]}" ]; do |
| 178 | echo "${INVALID_FILTERS[$i]}" |
| 179 | test_invalid_filter -k "${INVALID_FILTERS[$i]}" |
| 180 | let "i++" |
| 181 | done |
| 182 | |
| 183 | test_bytecode_limit -k |
| 184 | } |
| 185 | stop_lttng_sessiond |
| 186 | |
| 187 | rm -f $ENABLE_EVENT_STDERR |
| 188 | rm -rf $TRACE_PATH |