port: add support for BSD mktemp
[lttng-tools.git] / tests / regression / tools / streaming / test_ust
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 -t tmp.test_streaming_ust_trace_path.XXXXXX)
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 -t "tmp.test_${FUNCNAME[0]}_sync_before_last.XXXXXX")
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 -t "tmp.test_${FUNCNAME[0]}_sync_after_first.XXXXXX")
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 bail_out_if_no_babeltrace
83
84 start_lttng_relayd "-o $TRACE_PATH"
85 start_lttng_sessiond
86
87 tests=( test_ust_before_start test_ust_after_start )
88
89 for fct_test in ${tests[@]};
90 do
91 SESSION_NAME=$(randstring 16 0)
92 ${fct_test}
93
94 # Validate test
95 validate_trace_path_ust_uid_network "$TRACE_PATH" "$SESSION_NAME"
96 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
97 if [ $? -eq 0 ]; then
98 # Only delete if successful
99 rm -rf $TRACE_PATH
100 else
101 break
102 fi
103 done
104
105 stop_lttng_sessiond
106 stop_lttng_relayd
107
108 exit $out
This page took 0.035461 seconds and 5 git commands to generate.