| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
| 4 | # |
| 5 | # SPDX-License-Identifier: LGPL-2.1-only |
| 6 | |
| 7 | TEST_DESC="Streaming - User space tracing" |
| 8 | |
| 9 | CURDIR=$(dirname $0)/ |
| 10 | TESTDIR=$CURDIR/../../.. |
| 11 | NR_ITER=5 |
| 12 | NR_USEC_WAIT=1000000 |
| 13 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
| 14 | TESTAPP_NAME="gen-ust-events" |
| 15 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" |
| 16 | SESSION_NAME="stream" |
| 17 | EVENT_NAME="tp:tptest" |
| 18 | |
| 19 | TRACE_PATH=$(mktemp -d) |
| 20 | |
| 21 | NUM_TESTS=18 |
| 22 | |
| 23 | source $TESTDIR/utils/utils.sh |
| 24 | |
| 25 | if [ ! -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 test_ust_before_start () |
| 32 | { |
| 33 | local file_sync_before_last=$(mktemp -u) |
| 34 | |
| 35 | diag "Test UST streaming BEFORE tracing starts" |
| 36 | create_lttng_session_uri $SESSION_NAME net://localhost |
| 37 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 38 | |
| 39 | # Run 5 times with a 1 second delay |
| 40 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-before-last-event ${file_sync_before_last} > /dev/null 2>&1 & |
| 41 | |
| 42 | start_lttng_tracing_ok $SESSION_NAME |
| 43 | |
| 44 | touch ${file_sync_before_last} |
| 45 | |
| 46 | # Wait for the applications started in background |
| 47 | wait |
| 48 | |
| 49 | stop_lttng_tracing_ok $SESSION_NAME |
| 50 | destroy_lttng_session_ok $SESSION_NAME |
| 51 | rm -f ${file_sync_before_last} |
| 52 | } |
| 53 | |
| 54 | function test_ust_after_start () |
| 55 | { |
| 56 | local file_sync_after_first=$(mktemp -u) |
| 57 | |
| 58 | diag "Test UST streaming AFTER tracing starts" |
| 59 | create_lttng_session_uri $SESSION_NAME net://localhost |
| 60 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME |
| 61 | start_lttng_tracing_ok $SESSION_NAME |
| 62 | |
| 63 | # Run 5 times with a 1 second delay |
| 64 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \ |
| 65 | --sync-after-first-event ${file_sync_after_first} >/dev/null 2>&1 |
| 66 | |
| 67 | while [ ! -f "${file_sync_after_first}" ]; do |
| 68 | sleep 0.5 |
| 69 | done |
| 70 | |
| 71 | stop_lttng_tracing_ok $SESSION_NAME |
| 72 | destroy_lttng_session_ok $SESSION_NAME |
| 73 | |
| 74 | # Wait for the applications started in background |
| 75 | wait |
| 76 | rm -f ${file_sync_after_first} |
| 77 | } |
| 78 | |
| 79 | plan_tests $NUM_TESTS |
| 80 | |
| 81 | print_test_banner "$TEST_DESC" |
| 82 | |
| 83 | start_lttng_relayd "-o $TRACE_PATH" |
| 84 | start_lttng_sessiond |
| 85 | |
| 86 | tests=( test_ust_before_start test_ust_after_start ) |
| 87 | |
| 88 | for fct_test in ${tests[@]}; |
| 89 | do |
| 90 | SESSION_NAME=$(randstring 16 0) |
| 91 | ${fct_test} |
| 92 | |
| 93 | # Validate test |
| 94 | validate_trace_path_ust_uid_network "$TRACE_PATH" "$SESSION_NAME" |
| 95 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME* |
| 96 | if [ $? -eq 0 ]; then |
| 97 | # Only delete if successful |
| 98 | rm -rf $TRACE_PATH |
| 99 | else |
| 100 | break |
| 101 | fi |
| 102 | done |
| 103 | |
| 104 | stop_lttng_sessiond |
| 105 | stop_lttng_relayd |
| 106 | |
| 107 | exit $out |