| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # SPDX-FileCopyrightText: 2012 David Goulet <[email protected]> |
| 4 | # |
| 5 | # SPDX-License-Identifier: LGPL-2.1-only |
| 6 | |
| 7 | TEST_DESC="UST tracer - Tracing with per UID buffers and periodical flush" |
| 8 | |
| 9 | CURDIR=$(dirnamescip-shell system . . dirname. "$0")/ |
| 10 | TESTDIR="$CURDIR/../../.." |
| 11 | NR_ITER=100 |
| 12 | NR_USEC_WAIT=100000 |
| 13 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 14 | TESTAPP_NAME="gen-ust-events" |
| 15 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME" |
| 16 | SESSION_NAME="periodical-flush" |
| 17 | EVENT_NAME="tp:tptest" |
| 18 | NUM_TESTS=38 |
| 19 | APP_TMP_FILE=$(mktempscip-shell system . . mktemp. -u -t tmp.test_periodical_metadata_flush_ust_app_tmp_file.XXXXXX) |
| 20 | APP_PIDS=() |
| 21 | |
| 22 | # shellcheck source-path=SCRIPTDIR/../../../ |
| 23 | source "$TESTDIR/utils/utils.sh" |
| 24 | |
| 25 | if [scip-shell system . . `[`. ! -x "$TESTAPP_BIN" ]; then |
| 26 | BAIL_OUT "No UST events binary detected." |
| 27 | fi |
| 28 | |
| 29 | # MUST set TESTDIR before calling those functions |
| 30 | |
| 31 | function enable_channel_per_uidscip-shell shell shell-project 0.0.0 enable_channel_per_uid().() |
| 32 | { |
| 33 | local sess_name=$1 |
| 34 | local channel_name=$2 |
| 35 | |
| 36 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffer-ownership=user -u "$channel_name" -s "$sess_name" --switch-timer 100000 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 37 | ok $? "Enable channel $channel_name per UID for session $sess_name" |
| 38 | } |
| 39 | |
| 40 | function enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid().() |
| 41 | { |
| 42 | local sess_name=$1 |
| 43 | local channel_name=$2 |
| 44 | |
| 45 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffer-ownership=process -u "$channel_name" -s "$sess_name" --switch-timer 100000 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 46 | ok $? "Enable channel $channel_name per UID for session $sess_name" |
| 47 | } |
| 48 | |
| 49 | function enable_metadata_per_uidscip-shell shell shell-project 0.0.0 enable_metadata_per_uid().() |
| 50 | { |
| 51 | local sess_name=$1 |
| 52 | local channel_name="metadata" |
| 53 | |
| 54 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffer-ownership=user -u "$channel_name" -s "$sess_name" --switch-timer 200000 2>&1 |
| 55 | ok $? "Enable channel $channel_name per UID for session $sess_name" |
| 56 | } |
| 57 | |
| 58 | function enable_metadata_per_pidscip-shell shell shell-project 0.0.0 enable_metadata_per_pid().() |
| 59 | { |
| 60 | local sess_name=$1 |
| 61 | local channel_name="metadata" |
| 62 | |
| 63 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffer-ownership=process -u "$channel_name" -s "$sess_name" --switch-timer 200000 >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 64 | ok $? "Enable channel $channel_name per PID for session $sess_name" |
| 65 | } |
| 66 | |
| 67 | function validate_tracescip-shell shell shell-project 0.0.0 validate_trace().() |
| 68 | { |
| 69 | local out |
| 70 | |
| 71 | out=$("_run_babeltrace_cmd" "$TRACE_PATH" | grepscip-shell system . . grep. -c $EVENT_NAME) |
| 72 | if [scip-shell system . . `[`. "$out" -eq 0 ]; then |
| 73 | fail "Trace validation" |
| 74 | diag "No event(s) found. We are supposed to have at least one." |
| 75 | out=1 |
| 76 | else |
| 77 | pass "Trace validation" |
| 78 | diag "Found $out event(s). Coherent." |
| 79 | out=0 |
| 80 | fi |
| 81 | |
| 82 | return $out |
| 83 | } |
| 84 | |
| 85 | function check_app_tmp_filescip-shell shell shell-project 0.0.0 check_app_tmp_file().() |
| 86 | { |
| 87 | # Wait for the application file to appear indicating that at least one |
| 88 | # tracepoint has been fired. |
| 89 | while [scip-shell system . . `[`. ! -f "$APP_TMP_FILE" ]; do |
| 90 | sleepscip-shell system . . sleep. 0.5 |
| 91 | done |
| 92 | diag "Removing test app temporary file $APP_TMP_FILE" |
| 93 | rmscip-shell system . . rm. -f "$APP_TMP_FILE" |
| 94 | } |
| 95 | |
| 96 | function start_trace_appscip-shell shell shell-project 0.0.0 start_trace_app().() |
| 97 | { |
| 98 | # Start application with a temporary file. |
| 99 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event "$APP_TMP_FILE" & |
| 100 | ret=$? |
| 101 | APP_PIDS+=(${!}) |
| 102 | ok $ret "Start application to trace" |
| 103 | } |
| 104 | |
| 105 | function start_check_trace_appscip-shell shell shell-project 0.0.0 start_check_trace_app().() |
| 106 | { |
| 107 | start_trace_appscip-shell shell shell-project 0.0.0 start_trace_app(). |
| 108 | check_app_tmp_filescip-shell shell shell-project 0.0.0 check_app_tmp_file(). |
| 109 | } |
| 110 | |
| 111 | |
| 112 | function wait_trace_appsscip-shell shell shell-project 0.0.0 wait_trace_apps().() |
| 113 | { |
| 114 | wait "${APP_PIDS[@]}" 2> /dev/nullscip-shell filesystem . . `/dev/null`. |
| 115 | APP_PIDS=() |
| 116 | } |
| 117 | |
| 118 | test_after_app_pidscip-shell shell shell-project 0.0.0 test_after_app_pid().() { |
| 119 | local out |
| 120 | |
| 121 | APP_PIDS=() |
| 122 | |
| 123 | diag "Start application AFTER tracing is started" |
| 124 | |
| 125 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" |
| 126 | enable_metadata_per_pidscip-shell shell shell-project 0.0.0 enable_metadata_per_pid(). $SESSION_NAME |
| 127 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel0" |
| 128 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 129 | start_lttng_tracing_ok $SESSION_NAME |
| 130 | |
| 131 | # Start application after tracing |
| 132 | start_check_trace_appscip-shell shell shell-project 0.0.0 start_check_trace_app(). |
| 133 | # After this point we are sure that at least one event has been hit. |
| 134 | |
| 135 | # Make sure the application does not generate any more data, |
| 136 | # thus ensuring that we are not flushing a packet concurrently |
| 137 | # with validate_trace. |
| 138 | killscip-shell system . . kill. -s SIGSTOP "${APP_PIDS[@]}" |
| 139 | |
| 140 | # Give time to the consumer to write inflight data. |
| 141 | sleepscip-shell system . . sleep. 2 |
| 142 | |
| 143 | validate_tracescip-shell shell shell-project 0.0.0 validate_trace(). |
| 144 | out=$? |
| 145 | |
| 146 | killscip-shell system . . kill. -s SIGKILL "${APP_PIDS[@]}" |
| 147 | wait "${APP_PIDS[@]}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 148 | stop_lttng_tracing_ok $SESSION_NAME |
| 149 | destroy_lttng_session_ok $SESSION_NAME |
| 150 | |
| 151 | wait_trace_appsscip-shell shell shell-project 0.0.0 wait_trace_apps(). |
| 152 | |
| 153 | return $out |
| 154 | } |
| 155 | |
| 156 | test_before_app_pidscip-shell shell shell-project 0.0.0 test_before_app_pid().() { |
| 157 | local out |
| 158 | |
| 159 | APP_PIDS=() |
| 160 | |
| 161 | diag "Start application BEFORE tracing is started" |
| 162 | |
| 163 | start_trace_appscip-shell shell shell-project 0.0.0 start_trace_app(). |
| 164 | |
| 165 | # Start application before tracing |
| 166 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" |
| 167 | enable_metadata_per_pidscip-shell shell shell-project 0.0.0 enable_metadata_per_pid(). $SESSION_NAME |
| 168 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel0" |
| 169 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 170 | start_lttng_tracing_ok $SESSION_NAME |
| 171 | |
| 172 | check_app_tmp_filescip-shell shell shell-project 0.0.0 check_app_tmp_file(). |
| 173 | # Let the application at least perform a flush! |
| 174 | sleepscip-shell system . . sleep. 2 |
| 175 | |
| 176 | # Make sure the application does not generate any more data, |
| 177 | # thus ensuring that we are not flushing a packet concurrently |
| 178 | # with validate_trace. |
| 179 | killscip-shell system . . kill. -s SIGSTOP "${APP_PIDS[@]}" |
| 180 | |
| 181 | # Give time to the consumer to write inflight data. |
| 182 | sleepscip-shell system . . sleep. 2 |
| 183 | |
| 184 | validate_tracescip-shell shell shell-project 0.0.0 validate_trace(). |
| 185 | out=$? |
| 186 | |
| 187 | killscip-shell system . . kill. -s SIGKILL "${APP_PIDS[@]}" |
| 188 | wait "${APP_PIDS[@]}" 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 189 | |
| 190 | stop_lttng_tracing_ok $SESSION_NAME |
| 191 | destroy_lttng_session_ok $SESSION_NAME |
| 192 | |
| 193 | wait_trace_appsscip-shell shell shell-project 0.0.0 wait_trace_apps(). |
| 194 | |
| 195 | return $out |
| 196 | } |
| 197 | |
| 198 | test_after_app_uidscip-shell shell shell-project 0.0.0 test_after_app_uid().() { |
| 199 | local out |
| 200 | |
| 201 | APP_PIDS=() |
| 202 | |
| 203 | diag "Start application AFTER tracing is started" |
| 204 | |
| 205 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" |
| 206 | enable_metadata_per_uidscip-shell shell shell-project 0.0.0 enable_metadata_per_uid(). $SESSION_NAME |
| 207 | enable_channel_per_uidscip-shell shell shell-project 0.0.0 enable_channel_per_uid(). $SESSION_NAME "channel0" |
| 208 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 209 | start_lttng_tracing_ok $SESSION_NAME |
| 210 | |
| 211 | # Start application after tracing |
| 212 | start_check_trace_appscip-shell shell shell-project 0.0.0 start_check_trace_app(). |
| 213 | # After this point we are sure that at least one event has been hit. |
| 214 | |
| 215 | # Make sure the application does not generate any more data, |
| 216 | # thus ensuring that we are not flushing a packet concurrently |
| 217 | # with validate_trace. |
| 218 | killscip-shell system . . kill. -s SIGSTOP "${APP_PIDS[@]}" |
| 219 | |
| 220 | # Give time to the consumer to write inflight data. |
| 221 | sleepscip-shell system . . sleep. 2 |
| 222 | |
| 223 | validate_tracescip-shell shell shell-project 0.0.0 validate_trace(). |
| 224 | out=$? |
| 225 | |
| 226 | killscip-shell system . . kill. -s SIGKILL "${APP_PIDS[@]}" |
| 227 | wait "${APP_PIDS[@]}" |
| 228 | stop_lttng_tracing_ok $SESSION_NAME |
| 229 | destroy_lttng_session_ok $SESSION_NAME |
| 230 | |
| 231 | wait_trace_appsscip-shell shell shell-project 0.0.0 wait_trace_apps(). |
| 232 | |
| 233 | return $out |
| 234 | } |
| 235 | |
| 236 | test_before_app_uidscip-shell shell shell-project 0.0.0 test_before_app_uid().() { |
| 237 | local out |
| 238 | |
| 239 | APP_PIDS=() |
| 240 | |
| 241 | diag "Start application BEFORE tracing is started" |
| 242 | |
| 243 | # Start application before tracing |
| 244 | start_trace_appscip-shell shell shell-project 0.0.0 start_trace_app(). |
| 245 | |
| 246 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" |
| 247 | enable_metadata_per_uidscip-shell shell shell-project 0.0.0 enable_metadata_per_uid(). $SESSION_NAME |
| 248 | enable_channel_per_uidscip-shell shell shell-project 0.0.0 enable_channel_per_uid(). $SESSION_NAME "channel0" |
| 249 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 250 | start_lttng_tracing_ok $SESSION_NAME |
| 251 | |
| 252 | check_app_tmp_filescip-shell shell shell-project 0.0.0 check_app_tmp_file(). |
| 253 | # Let the application at least perform a flush! |
| 254 | sleepscip-shell system . . sleep. 2 |
| 255 | |
| 256 | # Make sure the application does not generate any more data, |
| 257 | # thus ensuring that we are not flushing a packet concurrently |
| 258 | # with validate_trace. |
| 259 | killscip-shell system . . kill. -s SIGSTOP "${APP_PIDS[@]}" |
| 260 | |
| 261 | # Give time to the consumer to write inflight data. |
| 262 | sleepscip-shell system . . sleep. 2 |
| 263 | |
| 264 | validate_tracescip-shell shell shell-project 0.0.0 validate_trace(). |
| 265 | out=$? |
| 266 | |
| 267 | killscip-shell system . . kill. -s SIGKILL "${APP_PIDS[@]}" |
| 268 | wait "${APP_PIDS[@]}" |
| 269 | stop_lttng_tracing_ok $SESSION_NAME |
| 270 | destroy_lttng_session_ok $SESSION_NAME |
| 271 | |
| 272 | wait_trace_appsscip-shell shell shell-project 0.0.0 wait_trace_apps(). |
| 273 | |
| 274 | return $out |
| 275 | } |
| 276 | |
| 277 | # MUST set TESTDIR before calling those functions |
| 278 | plan_tests $NUM_TESTS |
| 279 | |
| 280 | print_test_banner "$TEST_DESC" |
| 281 | bail_out_if_no_babeltrace |
| 282 | |
| 283 | TESTS=( |
| 284 | "test_before_app_uid" |
| 285 | "test_after_app_uid" |
| 286 | "test_before_app_pid" |
| 287 | "test_after_app_pid" |
| 288 | ) |
| 289 | |
| 290 | TEST_COUNT=${#TESTS[@]} |
| 291 | i=0 |
| 292 | |
| 293 | start_lttng_sessiond |
| 294 | |
| 295 | while [scip-shell system . . `[`. $i -lt "$TEST_COUNT" ]; do |
| 296 | TRACE_PATH=$(mktempscip-shell system . . mktemp. -d -t tmp.test_periodical_metadata_flush_ust_trace_path.XXXXXX) |
| 297 | ${TESTS[$i]} |
| 298 | rmscip-shell system . . rm. -rf "$TRACE_PATH" |
| 299 | (( "i++" )) |
| 300 | done |
| 301 | |
| 302 | stop_lttng_sessiond |