Cleanup: tests: name all temporary files to better identify leakage
[deliverable/lttng-tools.git] / tests / regression / tools / snapshots / test_ust_streaming
1 #!/bin/bash
2 #
3 # Copyright (C) - 2013 David Goulet <dgoulet@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Streaming - Snapshot UST tracing"
8
9 CURDIR=$(dirname $0)/
10 TESTDIR=$CURDIR/../../..
11 EVENT_NAME="tp:tptest"
12 SESSION_NAME=""
13 CHANNEL_NAME="chan1"
14 BIN_NAME="gen-nevents"
15 TESTAPP_PATH="$TESTDIR/utils/testapp"
16 TESTAPP_NAME="gen-ust-events"
17 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
18 NR_ITER=-1
19 NR_USEC_WAIT=100
20 APPS_PID=
21
22 TRACE_PATH=$(mktemp --tmpdir -d tmp.test_snapshots_ust_streaming_trace_path.XXXXXX)
23
24 NUM_TESTS=85
25
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 function snapshot_add_output ()
33 {
34 local sess_name=$1
35 local trace_path=$2
36 local name=$3
37 local extra_opt=""
38
39 if [ ! -z $name ]; then
40 extra_opt="-n $name"
41 fi
42
43 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $extra_opt $trace_path >/dev/null 2>&1
44 ok $? "Added snapshot output $trace_path"
45 }
46
47 # Start trace application and return once one event has been hit.
48 function start_test_app()
49 {
50 local tmp_file=$(mktemp --tmpdir -u tmp.test_${FUNCNAME[0]}_tmp_file.XXXXXX)
51
52 # Start application with a temporary file.
53 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
54 ret=$?
55 APPS_PID="${APPS_PID} ${!}"
56 ok $ret "Start application to trace"
57
58 # Wait for the application file to appear indicating that at least one
59 # tracepoint has been fired.
60 while [ ! -f "$tmp_file" ]; do
61 sleep 0.5
62 done
63 diag "Removing test app temporary file $tmp_file"
64 rm -f $tmp_file
65 }
66
67 function stop_test_apps()
68 {
69 diag "Stopping $TESTAPP_NAME"
70 for p in ${APPS_PID}; do
71 kill ${p}
72 wait ${p} 2>/dev/null
73 done
74 APPS_PID=
75 }
76
77 # Test a snapshot using a default name for the output destination.
78 function test_ust_default_name_with_del()
79 {
80 diag "Test UST snapshot streaming with default name with delete output"
81 create_lttng_session_no_output $SESSION_NAME
82 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
83 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
84 start_lttng_tracing_ok $SESSION_NAME
85
86 start_test_app
87
88 snapshot_add_output $SESSION_NAME "net://localhost"
89 lttng_snapshot_record $SESSION_NAME
90
91 # Validate test
92 validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0
93 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
94 if [ $? -ne 0 ]; then
95 stop_test_apps
96 return $?
97 fi
98
99 lttng_snapshot_del_output_ok $SESSION_NAME 1
100 snapshot_add_output $SESSION_NAME "net://localhost"
101 lttng_snapshot_record $SESSION_NAME
102
103 # Validate test with the next ID since a del output was done prior.
104 validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-2" 1
105 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2*
106 if [ $? -ne 0 ]; then
107 stop_test_apps
108 return $?
109 fi
110
111 stop_lttng_tracing_ok $SESSION_NAME
112 destroy_lttng_session_ok $SESSION_NAME
113
114 stop_test_apps
115
116 return 0
117 }
118
119 # Test a snapshot using a default name for the output destination.
120 function test_ust_default_name()
121 {
122 diag "Test UST snapshot streaming with default name"
123 create_lttng_session_no_output $SESSION_NAME
124 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
125 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
126 start_lttng_tracing_ok $SESSION_NAME
127
128 start_test_app
129
130 snapshot_add_output $SESSION_NAME "net://localhost"
131 lttng_snapshot_record $SESSION_NAME
132 stop_lttng_tracing_ok $SESSION_NAME
133 destroy_lttng_session_ok $SESSION_NAME
134 # Validate test
135 validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0
136 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
137 out=$?
138
139 stop_test_apps
140
141 return $out
142 }
143
144 function test_ust_default_name_custom_uri()
145 {
146 diag "Test UST snapshot streaming with default name with custom URL"
147 create_lttng_session_no_output $SESSION_NAME
148 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
149 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
150 start_lttng_tracing_ok $SESSION_NAME
151
152 start_test_app
153
154 snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343"
155 lttng_snapshot_record $SESSION_NAME
156 stop_lttng_tracing_ok $SESSION_NAME
157 destroy_lttng_session_ok $SESSION_NAME
158 # Validate test
159 validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0
160 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
161 out=$?
162
163 stop_test_apps
164
165 return $out
166 }
167
168 # Test a snapshot using a custom name for the output destination.
169 function test_ust_custom_name()
170 {
171 local out
172 local name="asnapshotname"
173
174 diag "Test UST snapshot streaming with custom name"
175 create_lttng_session_no_output $SESSION_NAME
176 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
177 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
178 start_lttng_tracing_ok $SESSION_NAME
179
180 start_test_app
181
182 snapshot_add_output $SESSION_NAME "net://localhost" $name
183 lttng_snapshot_record $SESSION_NAME
184 stop_lttng_tracing_ok $SESSION_NAME
185 destroy_lttng_session_ok $SESSION_NAME
186
187 if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev/null; then
188 ok 0 "Custom name snapshot exists"
189 # Validate test
190 validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "$name" 0
191 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-*
192 out=$?
193 else
194 fail "No custom name snapshot found"
195 out=1
196 fi
197
198 stop_test_apps
199
200 return $out
201 }
202
203 function test_ust_n_snapshot()
204 {
205 diag "Test ust snapshot streaming multiple consecutive snapshot"
206 create_lttng_session_no_output $SESSION_NAME
207 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
208 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
209 snapshot_add_output $SESSION_NAME "net://localhost"
210 start_test_app
211 for i in {0..4};
212 do
213 start_lttng_tracing_ok $SESSION_NAME
214 lttng_snapshot_record $SESSION_NAME
215 stop_lttng_tracing_ok $SESSION_NAME
216 validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" $i
217 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*
218 if [ $? -ne 0 ]; then
219 return 1
220 fi
221 set -u
222 rm -rf $TRACE_PATH/$HOSTNAME
223 set +u
224 done
225
226 destroy_lttng_session_ok $SESSION_NAME
227 stop_test_apps
228 return 0
229 }
230
231 plan_tests $NUM_TESTS
232
233 print_test_banner "$TEST_DESC"
234
235 if [ "$(id -u)" == "0" ]; then
236 isroot=1
237 else
238 isroot=0
239 fi
240
241 start_lttng_relayd "-o $TRACE_PATH"
242 start_lttng_sessiond
243
244 tests=( test_ust_default_name_with_del
245 test_ust_default_name
246 test_ust_custom_name
247 test_ust_default_name_custom_uri
248 test_ust_n_snapshot
249 )
250
251 for fct_test in ${tests[@]};
252 do
253 SESSION_NAME=$(randstring 16 0)
254 ${fct_test}
255 if [ $? -eq 0 ]; then
256 # Only delete if successful
257 rm -rf $TRACE_PATH
258 else
259 break
260 fi
261 done
262
263 stop_lttng_sessiond
264 stop_lttng_relayd
This page took 0.041533 seconds and 6 git commands to generate.