| 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 - Unsupported operators" |
| 19 | |
| 20 | CURDIR=$(dirname $0)/ |
| 21 | TESTDIR=$CURDIR/../../.. |
| 22 | SESSION_NAME="filter-unsupported-ops" |
| 23 | EVENT_NAME="bogus" |
| 24 | ENABLE_EVENT_STDERR="/tmp/unsupported-ops-enable" |
| 25 | TRACE_PATH=$(mktemp -d) |
| 26 | NUM_GLOBAL_TESTS=2 |
| 27 | NUM_UST_TESTS=20 |
| 28 | NUM_KERNEL_TESTS=20 |
| 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_unsupported |
| 34 | { |
| 35 | domain="$1" |
| 36 | sess_name="$2" |
| 37 | event_name="$3" |
| 38 | filter="$4" |
| 39 | |
| 40 | enable_cmd="$TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event" |
| 41 | $enable_cmd $event_name -s $sess_name $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 unsupported operator" |
| 46 | return 1 |
| 47 | else |
| 48 | pass "Enable lttng event with filtering and unsupported operator" |
| 49 | return 0 |
| 50 | fi |
| 51 | } |
| 52 | |
| 53 | function test_unsupported_op |
| 54 | { |
| 55 | domain="$1" |
| 56 | test_op_str="$2" |
| 57 | test_op_tkn="$3" |
| 58 | |
| 59 | diag "Test filter expression with unsupported operator $test_op_str ($test_op_tkn)" |
| 60 | |
| 61 | # Create session |
| 62 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 63 | |
| 64 | # Create filter |
| 65 | if [ "$test_op_str" == "UNARY_BIN_NOT" ]; then |
| 66 | TEST_FILTER="${test_op_tkn}1" |
| 67 | else |
| 68 | TEST_FILTER="intfield $test_op_tkn 1" |
| 69 | fi |
| 70 | |
| 71 | # Apply filter |
| 72 | enable_lttng_event_filter_unsupported $domain $SESSION_NAME $EVENT_NAME "$TEST_FILTER" |
| 73 | |
| 74 | # Test stderr for unsupported operator |
| 75 | |
| 76 | grep -i -q "not[[:space:]]\+supported" $ENABLE_EVENT_STDERR |
| 77 | |
| 78 | if [ $? -eq 1 ]; then |
| 79 | fail "Unsupported operator test $test_op_str ($test_op_tkn)" |
| 80 | return 1 |
| 81 | else |
| 82 | pass "Unsupported operator test $test_op_str ($test_op_tkn)" |
| 83 | fi |
| 84 | |
| 85 | # Destroy session |
| 86 | destroy_lttng_session_ok $SESSION_NAME |
| 87 | return 0 |
| 88 | } |
| 89 | |
| 90 | plan_tests $NUM_TESTS |
| 91 | |
| 92 | print_test_banner "$TEST_DESC" |
| 93 | |
| 94 | # Unsupported operators |
| 95 | OP_STR=("MUL" "DIV" "MOD" "PLUS" "MINUS") |
| 96 | |
| 97 | OP_TKN=("*" "/" "%" "+" "-") |
| 98 | |
| 99 | OP_COUNT=${#OP_STR[@]} |
| 100 | |
| 101 | start_lttng_sessiond |
| 102 | |
| 103 | diag "Test UST unsupported filter operations" |
| 104 | |
| 105 | i=0 |
| 106 | while [ "$i" -lt "$OP_COUNT" ]; do |
| 107 | test_unsupported_op -u "${OP_STR[$i]}" "${OP_TKN[$i]}" |
| 108 | |
| 109 | if [ $? -eq 1 ]; then |
| 110 | exit 1 |
| 111 | fi |
| 112 | |
| 113 | let "i++" |
| 114 | done |
| 115 | |
| 116 | if [ "$(id -u)" == "0" ]; then |
| 117 | isroot=1 |
| 118 | else |
| 119 | isroot=0 |
| 120 | fi |
| 121 | |
| 122 | skip $isroot "Root access is needed. Skipping all kernel unsupported filter operations tests." $NUM_KERNEL_TESTS || |
| 123 | { |
| 124 | diag "Test kernel unsupported filter operations" |
| 125 | |
| 126 | i=0 |
| 127 | while [ "$i" -lt "$OP_COUNT" ]; do |
| 128 | test_unsupported_op -k "${OP_STR[$i]}" "${OP_TKN[$i]}" |
| 129 | |
| 130 | if [ $? -eq 1 ]; then |
| 131 | exit 1 |
| 132 | fi |
| 133 | |
| 134 | let "i++" |
| 135 | done |
| 136 | } |
| 137 | |
| 138 | stop_lttng_sessiond |
| 139 | |
| 140 | # Cleanup |
| 141 | rm -f $ENABLE_EVENT_STDERR |
| 142 | rm -rf $TRACE_PATH |