| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2013 Christian Babeux <christian.babeux@efficios.com> |
| 4 | # |
| 5 | # This library is free software; you can redistribute it and/or modify it under |
| 6 | # the terms of the GNU Lesser General Public License as published by the Free |
| 7 | # Software Foundation; version 2.1 of the License. |
| 8 | # |
| 9 | # This library is distributed in the hope that it will be useful, but WITHOUT |
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
| 12 | # details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU Lesser General Public License |
| 15 | # along with this library; if not, write to the Free Software Foundation, Inc., |
| 16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | |
| 18 | TEST_DESC="Tracefile size limits" |
| 19 | |
| 20 | CURDIR=$(dirname $0)/ |
| 21 | TESTDIR=$CURDIR/../../.. |
| 22 | |
| 23 | NR_ITER=1000 |
| 24 | |
| 25 | PAGE_SIZE=$(getconf PAGE_SIZE) |
| 26 | |
| 27 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 28 | TESTAPP_NAME="gen-ust-events" |
| 29 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" |
| 30 | |
| 31 | NUM_TESTS=66 |
| 32 | |
| 33 | source $TESTDIR/utils/utils.sh |
| 34 | |
| 35 | if [ ! -x "$TESTAPP_BIN" ]; then |
| 36 | BAIL_OUT "No UST events binary detected." |
| 37 | fi |
| 38 | |
| 39 | function enable_lttng_channel_size_limit () |
| 40 | { |
| 41 | sess_name="$1" |
| 42 | channel_name="$2" |
| 43 | tracefile_size_limit="$3" |
| 44 | |
| 45 | test_name="Enable channel $channel_name " |
| 46 | test_name+="for session $sess_name: " |
| 47 | test_name+="$tracefile_size_limit bytes tracefile limit" |
| 48 | |
| 49 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel \ |
| 50 | -u $channel_name -s $sess_name --buffers-pid \ |
| 51 | --subbuf-size=$PAGE_SIZE \ |
| 52 | -C $tracefile_size_limit >/dev/null 2>&1 |
| 53 | |
| 54 | ok $? "$test_name" |
| 55 | } |
| 56 | |
| 57 | function enable_ust_lttng_event_per_channel () |
| 58 | { |
| 59 | sess_name="$1" |
| 60 | event_name="$2" |
| 61 | channel_name="$3" |
| 62 | |
| 63 | test_name="Enable event $event_name " |
| 64 | test_name+="for session $sess_name " |
| 65 | test_name+="in channel $channel_name" |
| 66 | |
| 67 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" \ |
| 68 | -s $sess_name -u -c $channel_name >/dev/null 2>&1 |
| 69 | |
| 70 | ok $? "$test_name" |
| 71 | } |
| 72 | |
| 73 | function check_file_size () |
| 74 | { |
| 75 | path="$1" |
| 76 | file_pattern="$2" |
| 77 | expected_max_size="$3" |
| 78 | |
| 79 | find $path -name "$file_pattern" -exec stat -c '%n %s' {} \; \ |
| 80 | | while read file_info; |
| 81 | do |
| 82 | name=$(echo $file_info | cut -f1 -d ' ') |
| 83 | size=$(echo $file_info | cut -f2 -d ' ') |
| 84 | |
| 85 | if [ "$size" -gt "$expected_max_size" ]; then |
| 86 | diag_msg="file: $name size: $size" |
| 87 | diag_msg+="expected maximum size: $expected_max_size" |
| 88 | diag "$diag_msg" |
| 89 | exit 1 |
| 90 | fi |
| 91 | done |
| 92 | |
| 93 | ok $? "File size validation" |
| 94 | } |
| 95 | |
| 96 | function test_tracefile_size_limit () |
| 97 | { |
| 98 | size_limit="$1" |
| 99 | trace_path=$(mktemp -d) |
| 100 | session_name=$(randstring 16 0) |
| 101 | channel_name="channel" |
| 102 | event_name="tp:tptest" |
| 103 | |
| 104 | diag "Test tracefile size limit : $size_limit bytes" |
| 105 | |
| 106 | create_lttng_session_ok $session_name $trace_path |
| 107 | |
| 108 | enable_lttng_channel_size_limit \ |
| 109 | $session_name $channel_name $size_limit |
| 110 | |
| 111 | enable_ust_lttng_event_per_channel \ |
| 112 | $session_name $event_name $channel_name |
| 113 | |
| 114 | start_lttng_tracing_ok $session_name |
| 115 | |
| 116 | $TESTAPP_BIN $NR_ITER >/dev/null 2>&1 |
| 117 | |
| 118 | stop_lttng_tracing_ok $session_name |
| 119 | |
| 120 | destroy_lttng_session_ok $session_name |
| 121 | |
| 122 | # Validate file size, each one shall be no larger than the |
| 123 | # specified size limit |
| 124 | |
| 125 | check_file_size $trace_path "${channel_name}_*" $size_limit |
| 126 | |
| 127 | # Validate tracing data, we should at least have some events |
| 128 | |
| 129 | validate_trace $event_name $trace_path |
| 130 | |
| 131 | rm -rf $trace_path |
| 132 | } |
| 133 | |
| 134 | function test_tracefile_size_limit_pagesize () |
| 135 | { |
| 136 | # Set a size limit lower than the page_size |
| 137 | size_limit="$(($PAGE_SIZE-2))" |
| 138 | trace_path=$(mktemp -d) |
| 139 | session_name=$(randstring 16 0) |
| 140 | channel_name="channel" |
| 141 | event_name="tp:tptest" |
| 142 | |
| 143 | diag "Test tracefile size limit lower than PAGE_SIZE : $size_limit bytes" |
| 144 | |
| 145 | create_lttng_session_ok $session_name $trace_path |
| 146 | |
| 147 | enable_lttng_channel_size_limit \ |
| 148 | $session_name $channel_name $size_limit |
| 149 | |
| 150 | enable_ust_lttng_event_per_channel \ |
| 151 | $session_name $event_name $channel_name |
| 152 | |
| 153 | start_lttng_tracing_ok $session_name |
| 154 | |
| 155 | $TESTAPP_BIN $NR_ITER >/dev/null 2>&1 |
| 156 | |
| 157 | stop_lttng_tracing_ok $session_name |
| 158 | |
| 159 | destroy_lttng_session_ok $session_name |
| 160 | |
| 161 | # Validate file size, expect file size to be equal to the page size |
| 162 | |
| 163 | check_file_size $trace_path "${channel_name}_*" $PAGE_SIZE |
| 164 | |
| 165 | # Validate tracing data, we should at least have some events |
| 166 | |
| 167 | validate_trace $event_name $trace_path |
| 168 | |
| 169 | rm -rf $trace_path |
| 170 | } |
| 171 | |
| 172 | plan_tests $NUM_TESTS |
| 173 | |
| 174 | print_test_banner "$TEST_DESC" |
| 175 | |
| 176 | start_lttng_sessiond |
| 177 | |
| 178 | # Test with multiples of PAGE_SIZE |
| 179 | LIMITS=("$(($PAGE_SIZE))" |
| 180 | "$(($PAGE_SIZE*2))" |
| 181 | "$(($PAGE_SIZE*4))" |
| 182 | "$(($PAGE_SIZE*8))" |
| 183 | "$(($PAGE_SIZE*16))" |
| 184 | "$(($PAGE_SIZE*32))") |
| 185 | |
| 186 | for limit in ${LIMITS[@]}; |
| 187 | do |
| 188 | test_tracefile_size_limit $limit |
| 189 | done |
| 190 | |
| 191 | # Test with a value that is not a multiple of PAGE_SIZE |
| 192 | test_tracefile_size_limit "$(($PAGE_SIZE+1024))" |
| 193 | |
| 194 | # Test that a value lower than the PAGE_SIZE is rounded to it |
| 195 | test_tracefile_size_limit_pagesize |
| 196 | |
| 197 | stop_lttng_sessiond |