| 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 PID buffers" |
| 8 | |
| 9 | CURDIR=$(dirnamescip-shell system . . dirname. $0)/ |
| 10 | TESTDIR=$CURDIR/../../.. |
| 11 | NR_ITER=100 |
| 12 | SESSION_NAME="buffers-pid" |
| 13 | |
| 14 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 15 | TESTAPP_NAME="gen-ust-events" |
| 16 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME" |
| 17 | EVENT_NAME="tp:tptest" |
| 18 | NUM_TESTS=59 |
| 19 | |
| 20 | source $TESTDIR/utils/utils.sh |
| 21 | |
| 22 | if [scip-shell system . . `[`. ! -x "$TESTAPP_BIN" ]; then |
| 23 | BAIL_OUT "No UST events binary detected." |
| 24 | fi |
| 25 | |
| 26 | # MUST set TESTDIR before calling those functions |
| 27 | |
| 28 | function enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid().() |
| 29 | { |
| 30 | sess_name=$1 |
| 31 | channel_name=$2 |
| 32 | |
| 33 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffer-ownership=process -u $channel_name -s $sess_name >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 34 | ok $? "Enable channel $channel_name per PID for session $sess_name" |
| 35 | } |
| 36 | |
| 37 | test_after_multiple_appsscip-shell shell shell-project 0.0.0 test_after_multiple_apps().() { |
| 38 | local out |
| 39 | local i |
| 40 | local tracee_pids=() |
| 41 | |
| 42 | diag "Start multiple applications AFTER tracing is started" |
| 43 | |
| 44 | # BEFORE application is spawned |
| 45 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 46 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel0" |
| 47 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 48 | start_lttng_tracing_ok $SESSION_NAME |
| 49 | |
| 50 | for i in `seqscip-shell system . . seq. 1 5`; do |
| 51 | $TESTAPP_BIN -i $NR_ITER >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 & |
| 52 | ok $? "Start application $i for tracing" |
| 53 | tracee_pids+=("${!}") |
| 54 | done |
| 55 | wait "${tracee_pids[@]}" |
| 56 | |
| 57 | stop_lttng_tracing_ok $SESSION_NAME |
| 58 | destroy_lttng_session_ok $SESSION_NAME |
| 59 | |
| 60 | trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH |
| 61 | |
| 62 | return $? |
| 63 | } |
| 64 | |
| 65 | test_before_multiple_appsscip-shell shell shell-project 0.0.0 test_before_multiple_apps().() { |
| 66 | local out |
| 67 | local i |
| 68 | local tracee_pids=() |
| 69 | local file_sync_after_first=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX") |
| 70 | local file_sync_before_last=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") |
| 71 | |
| 72 | diag "Start multiple applications BEFORE tracing is started" |
| 73 | |
| 74 | for i in `seqscip-shell system . . seq. 1 5`; do |
| 75 | $TESTAPP_BIN -i $NR_ITER \ |
| 76 | --sync-after-first-event ${file_sync_after_first}_${i} \ |
| 77 | --sync-before-last-event ${file_sync_before_last}_${i} >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 & |
| 78 | ok $? "Start application $i for tracing" |
| 79 | tracee_pids+=("${!}") |
| 80 | done |
| 81 | |
| 82 | # BEFORE application is spawned |
| 83 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 84 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel0" |
| 85 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 86 | start_lttng_tracing_ok $SESSION_NAME |
| 87 | |
| 88 | for i in `seqscip-shell system . . seq. 1 5`; do |
| 89 | touchscip-shell system . . touch. ${file_sync_before_last}_${i} |
| 90 | done |
| 91 | |
| 92 | diag "Waiting for applications to end" |
| 93 | wait "${tracee_pids[@]}" |
| 94 | pass "Waiting done" |
| 95 | |
| 96 | stop_lttng_tracing_ok $SESSION_NAME |
| 97 | destroy_lttng_session_ok $SESSION_NAME |
| 98 | |
| 99 | for i in `seqscip-shell system . . seq. 1 5`; do |
| 100 | rmscip-shell system . . rm. -f ${file_sync_after_first}_${i} |
| 101 | rmscip-shell system . . rm. -f ${file_sync_before_last}_${i} |
| 102 | done |
| 103 | |
| 104 | out=$("_run_babeltrace_cmd" $TRACE_PATH | grepscip-shell system . . grep. $EVENT_NAME | wcscip-shell system . . wc. -l) |
| 105 | if [scip-shell system . . `[`. $out -eq 0 ]; then |
| 106 | fail "Trace validation" |
| 107 | diag "No event(s) found. We are supposed to have at least one." |
| 108 | out=1 |
| 109 | else |
| 110 | pass "Trace validation" |
| 111 | diag "Found $out event(s). Coherent." |
| 112 | out=0 |
| 113 | fi |
| 114 | |
| 115 | return $out |
| 116 | } |
| 117 | |
| 118 | test_after_appscip-shell shell shell-project 0.0.0 test_after_app().() { |
| 119 | local out |
| 120 | |
| 121 | diag "Start application AFTER tracing is started" |
| 122 | |
| 123 | # BEFORE application is spawned |
| 124 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 125 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel0" |
| 126 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 127 | start_lttng_tracing_ok $SESSION_NAME |
| 128 | |
| 129 | $TESTAPP_BIN -i $NR_ITER & |
| 130 | ok $? "Start application to trace" |
| 131 | wait "${!}" |
| 132 | |
| 133 | stop_lttng_tracing_ok $SESSION_NAME |
| 134 | destroy_lttng_session_ok $SESSION_NAME |
| 135 | |
| 136 | trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH |
| 137 | |
| 138 | return $? |
| 139 | } |
| 140 | |
| 141 | test_before_appscip-shell shell shell-project 0.0.0 test_before_app().() { |
| 142 | local out |
| 143 | local pid |
| 144 | local file_sync_after_first=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX") |
| 145 | local file_sync_before_last=$(mktempscip-shell system . . mktemp. -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") |
| 146 | |
| 147 | diag "Start application BEFORE tracing is started" |
| 148 | |
| 149 | |
| 150 | # BEFORE application is spawned |
| 151 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 152 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel0" |
| 153 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0" |
| 154 | |
| 155 | $TESTAPP_BIN -i $NR_ITER \ |
| 156 | --sync-after-first-event ${file_sync_after_first} \ |
| 157 | --sync-before-last-event ${file_sync_before_last} & |
| 158 | ok $? "Start application to trace" |
| 159 | pid="${!}" |
| 160 | |
| 161 | start_lttng_tracing_ok $SESSION_NAME |
| 162 | |
| 163 | touchscip-shell system . . touch. ${file_sync_before_last} |
| 164 | |
| 165 | wait "${pid}" |
| 166 | |
| 167 | stop_lttng_tracing_ok $SESSION_NAME |
| 168 | destroy_lttng_session_ok $SESSION_NAME |
| 169 | |
| 170 | rmscip-shell system . . rm. -f ${file_sync_after_first} |
| 171 | rmscip-shell system . . rm. -f ${file_sync_before_last} |
| 172 | |
| 173 | out=$("_run_babeltrace_cmd" $TRACE_PATH | grepscip-shell system . . grep. $EVENT_NAME | wcscip-shell system . . wc. -l) |
| 174 | if [scip-shell system . . `[`. $out -eq 0 ]; then |
| 175 | fail "Trace validation" |
| 176 | diag "No event(s) found. We are supposed to have at least one." |
| 177 | out=1 |
| 178 | else |
| 179 | pass "Trace validation" |
| 180 | diag "Found $out event(s). Coherent." |
| 181 | out=0 |
| 182 | fi |
| 183 | |
| 184 | return $out |
| 185 | } |
| 186 | |
| 187 | test_multiple_channelsscip-shell shell shell-project 0.0.0 test_multiple_channels().() { |
| 188 | local out |
| 189 | |
| 190 | diag "Start with multiple channels" |
| 191 | |
| 192 | # BEFORE application is spawned |
| 193 | create_lttng_session_ok $SESSION_NAME $TRACE_PATH |
| 194 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel0" |
| 195 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel1" |
| 196 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel2" |
| 197 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel3" |
| 198 | enable_channel_per_pidscip-shell shell shell-project 0.0.0 enable_channel_per_pid(). $SESSION_NAME "channel4" |
| 199 | # Enable event in all channels. |
| 200 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel0 -s $SESSION_NAME -u >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 201 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel0" |
| 202 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel1 -s $SESSION_NAME -u >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 203 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel1" |
| 204 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel2 -s $SESSION_NAME -u >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 205 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel2" |
| 206 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel3 -s $SESSION_NAME -u >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 207 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel3" |
| 208 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel4 -s $SESSION_NAME -u >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 |
| 209 | ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel4" |
| 210 | start_lttng_tracing_ok $SESSION_NAME |
| 211 | |
| 212 | $TESTAPP_BIN -i $NR_ITER & |
| 213 | ok $? "Start application to trace" |
| 214 | wait "${!}" |
| 215 | |
| 216 | stop_lttng_tracing_ok $SESSION_NAME |
| 217 | trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH |
| 218 | out=$? |
| 219 | |
| 220 | destroy_lttng_session_ok $SESSION_NAME |
| 221 | |
| 222 | return $out |
| 223 | } |
| 224 | |
| 225 | # MUST set TESTDIR before calling those functions |
| 226 | plan_tests $NUM_TESTS |
| 227 | |
| 228 | print_test_banner "$TEST_DESC" |
| 229 | |
| 230 | bail_out_if_no_babeltrace |
| 231 | |
| 232 | TESTS=( |
| 233 | "test_before_app" |
| 234 | "test_after_app" |
| 235 | "test_after_multiple_apps" |
| 236 | "test_before_multiple_apps" |
| 237 | "test_multiple_channels" |
| 238 | ) |
| 239 | |
| 240 | TEST_COUNT=${#TESTS[@]} |
| 241 | i=0 |
| 242 | |
| 243 | start_lttng_sessiond |
| 244 | |
| 245 | while [scip-shell system . . `[`. $i -lt $TEST_COUNT ]; do |
| 246 | TRACE_PATH=$(mktempscip-shell system . . mktemp. -d -t tmp.test_buffers_pid_trace_path.XXXXXX) |
| 247 | ${TESTS[$i]} |
| 248 | rmscip-shell system . . rm. -rf $TRACE_PATH |
| 249 | let "i++" |
| 250 | done |
| 251 | |
| 252 | stop_lttng_sessiond |