| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# SPDX-FileCopyrightText: 2015 Julien Desfossez <[email protected]> |
| 4 |
# SPDX-FileCopyrightText: 2025 Michael Jeanson <[email protected]> |
| 5 |
# |
| 6 |
# SPDX-License-Identifier: LGPL-2.1-only |
| 7 |
|
| 8 |
TEST_DESC="Streaming - User space tracing" |
| 9 |
|
| 10 |
CURDIR=$(dirname "$0")/ |
| 11 |
TESTDIR=$CURDIR/../../.. |
| 12 |
|
| 13 |
NR_ITER=1 |
| 14 |
NR_USEC_WAIT=0 |
| 15 |
|
| 16 |
TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 17 |
TESTAPP_NAME="gen-ust-events" |
| 18 |
TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME" |
| 19 |
TESTAPP_TIMEOUT_SEC=10 |
| 20 |
|
| 21 |
EVENT_NAME="tp:tptest" |
| 22 |
|
| 23 |
NUM_TESTS=69 |
| 24 |
|
| 25 |
# shellcheck source-path=SCRIPTDIR/../../.. |
| 26 |
source "$TESTDIR/utils/utils.sh" |
| 27 |
|
| 28 |
if [ ! -x "$TESTAPP_BIN" ]; then |
| 29 |
BAIL_OUT "No UST events binary detected." |
| 30 |
fi |
| 31 |
|
| 32 |
# MUST set TESTDIR before calling those functions |
| 33 |
|
| 34 |
function test_ust_streaming_regenerate_metadata () |
| 35 |
{ |
| 36 |
local session_name="streaming" |
| 37 |
|
| 38 |
local ret |
| 39 |
local metadata_path |
| 40 |
local testapp_pid |
| 41 |
local trace_path |
| 42 |
local file_testapp_output |
| 43 |
local file_sync_application_in_main_touch |
| 44 |
local file_sync_before_last |
| 45 |
local file_sync_before_exit_touch |
| 46 |
|
| 47 |
diag "Test UST streaming with metadata regeneration" |
| 48 |
|
| 49 |
trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
| 50 |
file_testapp_output=$(mktemp -u -t "tmp.${FUNCNAME[0]}_testapp_output.XXXXXX") |
| 51 |
file_sync_application_in_main_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_application_in_main_touch.XXXXXX") |
| 52 |
file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") |
| 53 |
file_sync_before_exit_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_exit_touch.XXXXXX") |
| 54 |
|
| 55 |
start_lttng_relayd -o "$trace_path" |
| 56 |
|
| 57 |
create_lttng_session_uri "$session_name" net://localhost |
| 58 |
enable_ust_lttng_event_ok "$session_name" $EVENT_NAME |
| 59 |
|
| 60 |
"$TESTAPP_BIN" -i $NR_ITER -w $NR_USEC_WAIT \ |
| 61 |
--sync-application-in-main-touch "${file_sync_application_in_main_touch}" \ |
| 62 |
--sync-before-last-event "${file_sync_before_last}" \ |
| 63 |
--sync-before-exit-touch "${file_sync_before_exit_touch}" >"${file_testapp_output}" 2>&1 & |
| 64 |
testapp_pid="${!}" |
| 65 |
diag "Launched testapp '$TESTAPP_NAME' (pid: $testapp_pid) to generate $NR_ITER events" |
| 66 |
|
| 67 |
start_lttng_tracing_ok "$session_name" |
| 68 |
|
| 69 |
# Wait for the testapp to start |
| 70 |
app_alive_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_application_in_main_touch" |
| 71 |
|
| 72 |
# Tell the testapp to continue |
| 73 |
touch "${file_sync_before_last}" |
| 74 |
|
| 75 |
# Wait for the applications started in background |
| 76 |
app_exit_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_before_exit_touch" |
| 77 |
|
| 78 |
# Expect a valid trace |
| 79 |
stop_lttng_tracing_ok "$session_name" |
| 80 |
validate_trace $EVENT_NAME "$trace_path/$HOSTNAME" |
| 81 |
validate_metadata_event $EVENT_NAME 1 "$trace_path/$HOSTNAME" |
| 82 |
|
| 83 |
# Find the metadata file |
| 84 |
metadata_path=$(find "$trace_path/$HOSTNAME" -name "metadata") |
| 85 |
ret=$? |
| 86 |
ok $ret "Found metadata file" |
| 87 |
|
| 88 |
if [[ $ret = 0 ]]; then |
| 89 |
# Empty the metadata file |
| 90 |
echo -n > "$metadata_path" |
| 91 |
fi |
| 92 |
|
| 93 |
test ! -s "$metadata_path" |
| 94 |
ok $? "Metadata cleared" |
| 95 |
|
| 96 |
start_lttng_tracing_ok "$session_name" |
| 97 |
regenerate_metadata_ok "$session_name" |
| 98 |
stop_lttng_tracing_ok "$session_name" |
| 99 |
|
| 100 |
# Metadata file must have been regenerated |
| 101 |
validate_trace $EVENT_NAME "$trace_path/$HOSTNAME" |
| 102 |
validate_metadata_event $EVENT_NAME 1 "$trace_path/$HOSTNAME" |
| 103 |
destroy_lttng_session_ok "$session_name" |
| 104 |
|
| 105 |
stop_lttng_relayd |
| 106 |
|
| 107 |
rm -rf "$trace_path" |
| 108 |
rm -f "$file_testapp_output" |
| 109 |
rm -f "$file_sync_application_in_main_touch" |
| 110 |
rm -f "$file_sync_before_last" |
| 111 |
rm -f "$file_sync_before_exit_touch" |
| 112 |
} |
| 113 |
|
| 114 |
function test_ust_local_regenerate_metadata () |
| 115 |
{ |
| 116 |
local session_name="local" |
| 117 |
|
| 118 |
local ret |
| 119 |
local metadata_path |
| 120 |
local testapp_pid |
| 121 |
local trace_path |
| 122 |
local file_testapp_output |
| 123 |
local file_sync_application_in_main_touch |
| 124 |
local file_sync_before_last |
| 125 |
local file_sync_before_exit_touch |
| 126 |
|
| 127 |
diag "Test UST local with metadata regeneration" |
| 128 |
|
| 129 |
trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
| 130 |
file_testapp_output=$(mktemp -u -t "tmp.${FUNCNAME[0]}_testapp_output.XXXXXX") |
| 131 |
file_sync_application_in_main_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_application_in_main_touch.XXXXXX") |
| 132 |
file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") |
| 133 |
file_sync_before_exit_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_exit_touch.XXXXXX") |
| 134 |
|
| 135 |
create_lttng_session_ok "$session_name" "$trace_path" |
| 136 |
enable_ust_lttng_event_ok "$session_name" $EVENT_NAME |
| 137 |
|
| 138 |
"$TESTAPP_BIN" -i $NR_ITER -w $NR_USEC_WAIT \ |
| 139 |
--sync-application-in-main-touch "${file_sync_application_in_main_touch}" \ |
| 140 |
--sync-before-last-event "${file_sync_before_last}" \ |
| 141 |
--sync-before-exit-touch "${file_sync_before_exit_touch}" >"${file_testapp_output}" 2>&1 & |
| 142 |
testapp_pid="${!}" |
| 143 |
diag "Launched testapp '$TESTAPP_NAME' (pid: $testapp_pid) to generate $NR_ITER events" |
| 144 |
|
| 145 |
start_lttng_tracing_ok "$session_name" |
| 146 |
|
| 147 |
# Wait for the testapp to start |
| 148 |
app_alive_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_application_in_main_touch" |
| 149 |
|
| 150 |
# Tell the testapp to continue |
| 151 |
touch "${file_sync_before_last}" |
| 152 |
|
| 153 |
# Wait for the applications started in background |
| 154 |
app_exit_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_before_exit_touch" |
| 155 |
|
| 156 |
# Expect a valid trace |
| 157 |
stop_lttng_tracing_ok "$session_name" |
| 158 |
validate_trace $EVENT_NAME "$trace_path" |
| 159 |
validate_metadata_event $EVENT_NAME 1 "$trace_path" |
| 160 |
|
| 161 |
# Find the metadata file |
| 162 |
metadata_path=$(find "$trace_path" -name "metadata") |
| 163 |
ret=$? |
| 164 |
ok $ret "Found metadata file" |
| 165 |
|
| 166 |
if [[ $ret = 0 ]]; then |
| 167 |
# Empty the metadata file |
| 168 |
echo -n > "$metadata_path" |
| 169 |
fi |
| 170 |
|
| 171 |
test ! -s "$metadata_path" |
| 172 |
ok $? "Metadata cleared" |
| 173 |
|
| 174 |
start_lttng_tracing_ok "$session_name" |
| 175 |
regenerate_metadata_ok "$session_name" |
| 176 |
stop_lttng_tracing_ok "$session_name" |
| 177 |
|
| 178 |
# Metadata file must have been regenerated |
| 179 |
validate_trace $EVENT_NAME "$trace_path" |
| 180 |
validate_metadata_event $EVENT_NAME 1 "$trace_path" |
| 181 |
destroy_lttng_session_ok "$session_name" |
| 182 |
|
| 183 |
rm -rf "$trace_path" |
| 184 |
rm -f "$file_testapp_output" |
| 185 |
rm -f "$file_sync_application_in_main_touch" |
| 186 |
rm -f "$file_sync_before_last" |
| 187 |
rm -f "$file_sync_before_exit_touch" |
| 188 |
} |
| 189 |
|
| 190 |
function test_ust_pid_regenerate_metadata () |
| 191 |
{ |
| 192 |
local session_name="pid" |
| 193 |
|
| 194 |
local testapp_pid |
| 195 |
local trace_path |
| 196 |
local file_testapp_output |
| 197 |
local file_sync_application_in_main_touch |
| 198 |
local file_sync_before_last |
| 199 |
local file_sync_before_exit_touch |
| 200 |
|
| 201 |
diag "Test UST per-pid with metadata regeneration (expect failure)" |
| 202 |
|
| 203 |
trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
| 204 |
file_testapp_output=$(mktemp -u -t "tmp.${FUNCNAME[0]}_testapp_output.XXXXXX") |
| 205 |
file_sync_application_in_main_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_application_in_main_touch.XXXXXX") |
| 206 |
file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") |
| 207 |
file_sync_before_exit_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_exit_touch.XXXXXX") |
| 208 |
|
| 209 |
create_lttng_session_ok "$session_name" "$trace_path" |
| 210 |
enable_ust_lttng_channel_ok "$session_name" "channel0" --buffer-ownership=process |
| 211 |
enable_ust_lttng_event_ok "$session_name" $EVENT_NAME "channel0" |
| 212 |
|
| 213 |
"$TESTAPP_BIN" -i $NR_ITER -w $NR_USEC_WAIT \ |
| 214 |
--sync-application-in-main-touch "${file_sync_application_in_main_touch}" \ |
| 215 |
--sync-before-last-event "${file_sync_before_last}" \ |
| 216 |
--sync-before-exit-touch "${file_sync_before_exit_touch}" >"${file_testapp_output}" 2>&1 & |
| 217 |
testapp_pid="${!}" |
| 218 |
diag "Launched testapp '$TESTAPP_NAME' (pid: $testapp_pid) to generate $NR_ITER events" |
| 219 |
|
| 220 |
start_lttng_tracing_ok "$session_name" |
| 221 |
|
| 222 |
# Wait for the testapp to start |
| 223 |
app_alive_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_application_in_main_touch" |
| 224 |
|
| 225 |
# Tell the testapp to continue |
| 226 |
touch "${file_sync_before_last}" |
| 227 |
|
| 228 |
# Wait for the applications started in background |
| 229 |
app_exit_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_before_exit_touch" |
| 230 |
|
| 231 |
regenerate_metadata_fail "$session_name" |
| 232 |
|
| 233 |
stop_lttng_tracing_ok "$session_name" |
| 234 |
validate_trace $EVENT_NAME "$trace_path" |
| 235 |
validate_metadata_event $EVENT_NAME 1 "$trace_path" |
| 236 |
destroy_lttng_session_ok "$session_name" |
| 237 |
|
| 238 |
rm -rf "$trace_path" |
| 239 |
rm -f "$file_testapp_output" |
| 240 |
rm -f "$file_sync_application_in_main_touch" |
| 241 |
rm -f "$file_sync_before_last" |
| 242 |
rm -f "$file_sync_before_exit_touch" |
| 243 |
} |
| 244 |
|
| 245 |
function test_ust_live_regenerate_metadata () |
| 246 |
{ |
| 247 |
local session_name="live" |
| 248 |
|
| 249 |
local testapp_pid |
| 250 |
local trace_path |
| 251 |
local file_testapp_output |
| 252 |
local file_sync_application_in_main_touch |
| 253 |
local file_sync_before_last |
| 254 |
local file_sync_before_exit_touch |
| 255 |
|
| 256 |
diag "Test UST live with metadata regeneration (expect failure)" |
| 257 |
|
| 258 |
trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
| 259 |
file_testapp_output=$(mktemp -u -t "tmp.${FUNCNAME[0]}_testapp_output.XXXXXX") |
| 260 |
file_sync_application_in_main_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_application_in_main_touch.XXXXXX") |
| 261 |
file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") |
| 262 |
file_sync_before_exit_touch=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_exit_touch.XXXXXX") |
| 263 |
|
| 264 |
start_lttng_relayd -o "$trace_path" |
| 265 |
|
| 266 |
create_lttng_session_uri "$session_name" net://localhost --live |
| 267 |
enable_ust_lttng_event_ok "$session_name" $EVENT_NAME |
| 268 |
|
| 269 |
"$TESTAPP_BIN" -i $NR_ITER -w $NR_USEC_WAIT \ |
| 270 |
--sync-application-in-main-touch "${file_sync_application_in_main_touch}" \ |
| 271 |
--sync-before-last-event "${file_sync_before_last}" \ |
| 272 |
--sync-before-exit-touch "${file_sync_before_exit_touch}" >"${file_testapp_output}" 2>&1 & |
| 273 |
testapp_pid="${!}" |
| 274 |
diag "Launched testapp '$TESTAPP_NAME' (pid: $testapp_pid) to generate $NR_ITER events" |
| 275 |
|
| 276 |
start_lttng_tracing_ok "$session_name" |
| 277 |
|
| 278 |
# Wait for the testapp to start |
| 279 |
app_alive_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_application_in_main_touch" |
| 280 |
|
| 281 |
# Tell the testapp to continue |
| 282 |
touch "${file_sync_before_last}" |
| 283 |
|
| 284 |
# Wait for the applications started in background |
| 285 |
app_exit_wait_for_sync "$TESTAPP_NAME" "$testapp_pid" "$TESTAPP_TIMEOUT_SEC" "$file_testapp_output" "$file_sync_before_exit_touch" |
| 286 |
|
| 287 |
regenerate_metadata_fail "$session_name" |
| 288 |
|
| 289 |
stop_lttng_tracing_ok "$session_name" |
| 290 |
validate_trace $EVENT_NAME "$trace_path" |
| 291 |
validate_metadata_event $EVENT_NAME 1 "$trace_path" |
| 292 |
destroy_lttng_session_ok "$session_name" |
| 293 |
|
| 294 |
stop_lttng_relayd |
| 295 |
|
| 296 |
rm -rf "$trace_path" |
| 297 |
rm -f "$file_testapp_output" |
| 298 |
rm -f "$file_sync_application_in_main_touch" |
| 299 |
rm -f "$file_sync_before_last" |
| 300 |
rm -f "$file_sync_before_exit_touch" |
| 301 |
} |
| 302 |
|
| 303 |
function test_ust_local_snapshot_after_regenerate_metadata () |
| 304 |
{ |
| 305 |
local session_name="snapshot-regen" |
| 306 |
|
| 307 |
local trace_path |
| 308 |
local metadata_path |
| 309 |
local file_testapp_output |
| 310 |
|
| 311 |
trace_path=$(mktemp -d -t "tmp.${FUNCNAME[0]}_trace_path.XXXXXX") |
| 312 |
file_testapp_output=$(mktemp -u -t "tmp.${FUNCNAME[0]}_testapp_output.XXXXXX") |
| 313 |
|
| 314 |
diag "Test UST local snapshot after regenerate metadata" |
| 315 |
|
| 316 |
create_lttng_session_ok "$session_name" "$trace_path" --snapshot |
| 317 |
enable_ust_lttng_event_ok "$session_name" $EVENT_NAME |
| 318 |
start_lttng_tracing_ok "$session_name" |
| 319 |
|
| 320 |
run_testapp_ok "$file_testapp_output" "$TESTAPP_BIN" -i "$NR_ITER" -w "$NR_USEC_WAIT" |
| 321 |
|
| 322 |
regenerate_metadata_ok "$session_name" |
| 323 |
|
| 324 |
lttng_snapshot_record "$session_name" "$trace_path" |
| 325 |
|
| 326 |
stop_lttng_tracing_ok "$session_name" |
| 327 |
validate_trace $EVENT_NAME "$trace_path" |
| 328 |
validate_metadata_event $EVENT_NAME 1 "$trace_path" |
| 329 |
destroy_lttng_session_ok "$session_name" |
| 330 |
|
| 331 |
rm -rf "$trace_path" |
| 332 |
rm -f "$file_testapp_output" |
| 333 |
} |
| 334 |
|
| 335 |
plan_tests $NUM_TESTS |
| 336 |
|
| 337 |
print_test_banner "$TEST_DESC" |
| 338 |
bail_out_if_no_babeltrace |
| 339 |
|
| 340 |
start_lttng_sessiond |
| 341 |
|
| 342 |
test_ust_streaming_regenerate_metadata |
| 343 |
test_ust_local_regenerate_metadata |
| 344 |
test_ust_pid_regenerate_metadata |
| 345 |
test_ust_live_regenerate_metadata |
| 346 |
test_ust_local_snapshot_after_regenerate_metadata |
| 347 |
|
| 348 |
stop_lttng_sessiond |