| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2012 David Goulet <dgoulet@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="Streaming - User space tracing" |
| 18 | |
| 19 | CURDIR=$(dirname $0)/ |
| 20 | TESTDIR=$CURDIR/../../.. |
| 21 | BIN_NAME="gen-ust-events" |
| 22 | SESSION_NAME="stream" |
| 23 | EVENT_NAME="tp:tptest" |
| 24 | PID_RELAYD=0 |
| 25 | |
| 26 | TRACE_PATH=$(mktemp -d) |
| 27 | |
| 28 | source $TESTDIR/utils/utils.sh |
| 29 | |
| 30 | print_test_banner "$TEST_DESC" |
| 31 | |
| 32 | if [ ! -x "$CURDIR/$BIN_NAME" ]; then |
| 33 | echo -e "No UST nevents binary detected. Passing." |
| 34 | exit 0 |
| 35 | fi |
| 36 | |
| 37 | function lttng_create_session_uri |
| 38 | { |
| 39 | # Create session with default path |
| 40 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1 |
| 41 | } |
| 42 | |
| 43 | function wait_apps |
| 44 | { |
| 45 | echo -n "Waiting for applications to end" |
| 46 | while [ -n "$(pidof $BIN_NAME)" ]; do |
| 47 | echo -n "." |
| 48 | sleep 0.5 |
| 49 | done |
| 50 | echo "" |
| 51 | } |
| 52 | |
| 53 | # MUST set TESTDIR before calling those functions |
| 54 | |
| 55 | function test_ust_before_start () |
| 56 | { |
| 57 | echo -e "\n=== Testing UST streaming BEFORE tracing starts\n" |
| 58 | lttng_create_session_uri |
| 59 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME |
| 60 | |
| 61 | # Run 5 times with a 1 second delay |
| 62 | ./$CURDIR/$BIN_NAME 5 1000000 >/dev/null 2>&1 & |
| 63 | |
| 64 | start_lttng_tracing $SESSION_NAME |
| 65 | |
| 66 | wait_apps |
| 67 | stop_lttng_tracing $SESSION_NAME |
| 68 | destroy_lttng_session $SESSION_NAME |
| 69 | } |
| 70 | |
| 71 | function test_ust_after_start () |
| 72 | { |
| 73 | echo -e "\n=== Testing UST streaming AFTER tracing starts\n" |
| 74 | lttng_create_session_uri |
| 75 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME |
| 76 | start_lttng_tracing $SESSION_NAME |
| 77 | |
| 78 | # Run 5 times with a 1 second delay |
| 79 | ./$CURDIR/$BIN_NAME 5 1000000 >/dev/null 2>&1 & |
| 80 | |
| 81 | wait_apps |
| 82 | stop_lttng_tracing $SESSION_NAME |
| 83 | destroy_lttng_session $SESSION_NAME |
| 84 | } |
| 85 | |
| 86 | start_lttng_sessiond |
| 87 | start_lttng_relayd "-o $TRACE_PATH" |
| 88 | |
| 89 | tests=( test_ust_before_start test_ust_after_start ) |
| 90 | |
| 91 | for fct_test in ${tests[@]}; |
| 92 | do |
| 93 | SESSION_NAME=$(randstring 16 0) |
| 94 | ${fct_test} |
| 95 | |
| 96 | # Validate test |
| 97 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME* |
| 98 | if [ $? -eq 0 ]; then |
| 99 | # Only delete if successful |
| 100 | rm -rf $TRACE_PATH |
| 101 | else |
| 102 | break |
| 103 | fi |
| 104 | done |
| 105 | |
| 106 | echo "" |
| 107 | stop_lttng_sessiond |
| 108 | stop_lttng_relayd |
| 109 | |
| 110 | exit $out |