| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2017 Julien Desfossez <jdesfossez@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 | TEST_DESC="Rotation - User space tracing" |
| 18 | |
| 19 | CURDIR=$(dirname $0)/ |
| 20 | TESTDIR=$CURDIR/../../.. |
| 21 | NR_ITER=1 |
| 22 | NR_USEC_WAIT=0 |
| 23 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 24 | TESTAPP_NAME="gen-ust-events" |
| 25 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" |
| 26 | SESSION_NAME="stream" |
| 27 | EVENT_NAME="tp:tptest" |
| 28 | PID_RELAYD=0 |
| 29 | |
| 30 | TRACE_PATH=$(mktemp -d) |
| 31 | |
| 32 | NUM_TESTS=146 |
| 33 | |
| 34 | source $TESTDIR/utils/utils.sh |
| 35 | source $CURDIR/rotate_utils.sh |
| 36 | |
| 37 | if [ ! -x "$TESTAPP_BIN" ]; then |
| 38 | BAIL_OUT "No UST events binary detected." |
| 39 | fi |
| 40 | |
| 41 | function enable_channel_per_pid() |
| 42 | { |
| 43 | sess_name=$1 |
| 44 | channel_name=$2 |
| 45 | |
| 46 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name >/dev/null 2>&1 |
| 47 | ok $? "Enable channel $channel_name per PID for session $sess_name" |
| 48 | } |
| 49 | |
| 50 | function lttng_create_session_uri |
| 51 | { |
| 52 | # Create session with default path |
| 53 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1 |
| 54 | |
| 55 | ok $? "Create session $SESSION_NAME" |
| 56 | } |
| 57 | |
| 58 | # MUST set TESTDIR before calling those functions |
| 59 | |
| 60 | function rotate_ust_test () |
| 61 | { |
| 62 | local_path=$1 |
| 63 | app_path=$2 |
| 64 | per_pid=$3 |
| 65 | |
| 66 | start_lttng_tracing_ok $SESSION_NAME |
| 67 | today=$(date +%Y%m%d) |
| 68 | |
| 69 | $TESTAPP_BIN 10 $NR_USEC_WAIT /dev/null 2>&1 |
| 70 | rotate_session_ok $SESSION_NAME |
| 71 | |
| 72 | $TESTAPP_BIN 20 $NR_USEC_WAIT /dev/null 2>&1 |
| 73 | stop_lttng_tracing_ok $SESSION_NAME |
| 74 | |
| 75 | # Third chunk contains no event (rotate after stop). |
| 76 | rotate_session_ok $SESSION_NAME |
| 77 | |
| 78 | destroy_lttng_session_ok $SESSION_NAME |
| 79 | |
| 80 | # The tests on the chunk folder rely on the date staying the same during |
| 81 | # the duration of the test, if this fail we will now why the other checks |
| 82 | # fail afterwards. There is a short window of time where an automated test |
| 83 | # could fail because of that. |
| 84 | now=$(date +%Y%m%d) |
| 85 | test $today = $now |
| 86 | ok $? "Date did not change during the test" |
| 87 | |
| 88 | validate_test_chunks "${local_path}" $today $app_path ust $per_pid |
| 89 | } |
| 90 | |
| 91 | function test_ust_streaming_uid () |
| 92 | { |
| 93 | diag "Test UST streaming with session rotation per UID" |
| 94 | lttng_create_session_uri |
| 95 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 96 | |
| 97 | rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/uid/*/*/" 0 |
| 98 | clean_path $TRACE_PATH |
| 99 | } |
| 100 | |
| 101 | function test_ust_local_uid () |
| 102 | { |
| 103 | diag "Test UST local with session rotation per UID" |
| 104 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 105 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 106 | |
| 107 | rotate_ust_test "${TRACE_PATH}" "ust/uid/*/*/" 0 |
| 108 | clean_path $TRACE_PATH |
| 109 | } |
| 110 | |
| 111 | function test_ust_streaming_pid () |
| 112 | { |
| 113 | diag "Test UST streaming with session rotation per PID" |
| 114 | lttng_create_session_uri |
| 115 | enable_channel_per_pid $SESSION_NAME "channel0" |
| 116 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 117 | |
| 118 | rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/pid/*/" 1 |
| 119 | clean_path $TRACE_PATH |
| 120 | } |
| 121 | |
| 122 | function test_ust_local_pid () |
| 123 | { |
| 124 | diag "Test UST local with session rotation per PID" |
| 125 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 126 | enable_channel_per_pid $SESSION_NAME "channel0" |
| 127 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 128 | |
| 129 | rotate_ust_test "${TRACE_PATH}" "ust/pid/*/" 1 |
| 130 | clean_path $TRACE_PATH |
| 131 | } |
| 132 | |
| 133 | function test_ust_local_timer_uid () |
| 134 | { |
| 135 | diag "Test ust local with session rotation timer per-uid" |
| 136 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 137 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 138 | lttng_enable_rotation_timer_ok $SESSION_NAME 500ms |
| 139 | start_lttng_tracing_ok $SESSION_NAME |
| 140 | # We just want the app to register, no event generated |
| 141 | $TESTAPP_BIN 0 0 /dev/null 2>&1 |
| 142 | |
| 143 | rotate_timer_test "${TRACE_PATH}" 0 |
| 144 | clean_path $TRACE_PATH |
| 145 | } |
| 146 | |
| 147 | function test_ust_streaming_timer_uid () |
| 148 | { |
| 149 | diag "Test ust remote with session rotation timer per-uid" |
| 150 | lttng_create_session_uri |
| 151 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 152 | lttng_enable_rotation_timer_ok $SESSION_NAME 500ms |
| 153 | start_lttng_tracing_ok $SESSION_NAME |
| 154 | # We just want the app to register, no event generated |
| 155 | $TESTAPP_BIN 0 0 /dev/null 2>&1 |
| 156 | |
| 157 | rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 0 |
| 158 | clean_path $TRACE_PATH |
| 159 | } |
| 160 | |
| 161 | function test_ust_local_timer_pid () |
| 162 | { |
| 163 | diag "Test ust local with session rotation timer per-pid" |
| 164 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 165 | enable_channel_per_pid $SESSION_NAME "channel0" |
| 166 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 167 | lttng_enable_rotation_timer_ok $SESSION_NAME 500ms |
| 168 | start_lttng_tracing_ok $SESSION_NAME |
| 169 | # We just want the app to register, no event generated |
| 170 | $TESTAPP_BIN 0 0 /dev/null 2>&1 |
| 171 | |
| 172 | rotate_timer_test "${TRACE_PATH}" 1 |
| 173 | clean_path $TRACE_PATH |
| 174 | } |
| 175 | |
| 176 | function test_ust_streaming_timer_pid () |
| 177 | { |
| 178 | diag "Test ust remote with session rotation timer per-pid" |
| 179 | lttng_create_session_uri |
| 180 | enable_channel_per_pid $SESSION_NAME "channel0" |
| 181 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 182 | lttng_enable_rotation_timer_ok $SESSION_NAME 500ms |
| 183 | start_lttng_tracing_ok $SESSION_NAME |
| 184 | # We just want the app to register, no event generated |
| 185 | $TESTAPP_BIN 0 0 /dev/null 2>&1 |
| 186 | |
| 187 | rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 1 |
| 188 | clean_path $TRACE_PATH |
| 189 | } |
| 190 | |
| 191 | function test_incompatible_sessions () |
| 192 | { |
| 193 | diag "Check incompatible session types with rotation" |
| 194 | |
| 195 | diag "Live session with rotate timer" |
| 196 | # Should not be able to enable a rotation timer with a live session |
| 197 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live >/dev/null 2>&1 |
| 198 | lttng_enable_rotation_timer_fail $SESSION_NAME 500ms |
| 199 | destroy_lttng_session_ok $SESSION_NAME |
| 200 | |
| 201 | diag "Snapshot session with rotate timer" |
| 202 | # Should not be able to enable a rotation timer with a snapshot session |
| 203 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --snapshot >/dev/null 2>&1 |
| 204 | lttng_enable_rotation_timer_fail $SESSION_NAME 500ms |
| 205 | destroy_lttng_session_ok $SESSION_NAME |
| 206 | |
| 207 | diag "Live session with rotate" |
| 208 | # Should not be able to rotate a live session |
| 209 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live >/dev/null 2>&1 |
| 210 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 211 | start_lttng_tracing_ok $SESSION_NAME |
| 212 | rotate_session_fail $SESSION_NAME |
| 213 | destroy_lttng_session_ok $SESSION_NAME |
| 214 | |
| 215 | diag "Snapshot session with rotate" |
| 216 | # Should not be able to rotate a snapshot session |
| 217 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --snapshot >/dev/null 2>&1 |
| 218 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 219 | start_lttng_tracing_ok $SESSION_NAME |
| 220 | rotate_session_fail $SESSION_NAME |
| 221 | destroy_lttng_session_ok $SESSION_NAME |
| 222 | |
| 223 | } |
| 224 | |
| 225 | plan_tests $NUM_TESTS |
| 226 | |
| 227 | print_test_banner "$TEST_DESC" |
| 228 | |
| 229 | start_lttng_relayd "-o $TRACE_PATH" |
| 230 | start_lttng_sessiond |
| 231 | |
| 232 | tests=( test_ust_streaming_uid test_ust_local_uid \ |
| 233 | test_ust_streaming_pid test_ust_local_pid \ |
| 234 | test_ust_local_timer_uid test_ust_streaming_timer_uid \ |
| 235 | test_ust_local_timer_pid test_ust_streaming_timer_pid \ |
| 236 | test_incompatible_sessions ) |
| 237 | |
| 238 | for fct_test in ${tests[@]}; |
| 239 | do |
| 240 | SESSION_NAME=$(randstring 16 0) |
| 241 | ${fct_test} |
| 242 | done |
| 243 | |
| 244 | stop_lttng_sessiond |
| 245 | stop_lttng_relayd |
| 246 | |
| 247 | # Remove tmp dir |
| 248 | rm -rf $TRACE_PATH |