Commit | Line | Data |
---|---|---|
ebaaaf5e JD |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2013 David Goulet <dgoulet@efficios.com> | |
4 | # | |
9d16b343 MJ |
5 | # SPDX-License-Identifier: LGPL-2.1-only |
6 | ||
ebaaaf5e JD |
7 | TEST_DESC="Streaming - Snapshot UST tracing" |
8 | ||
9 | CURDIR=$(dirname $0)/ | |
10 | TESTDIR=$CURDIR/../../.. | |
11 | EVENT_NAME="tp:tptest" | |
ebaaaf5e JD |
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" | |
18c9d47c | 18 | NR_ITER=-1 |
ebaaaf5e | 19 | NR_USEC_WAIT=100 |
0fc2834c | 20 | APPS_PID= |
ebaaaf5e | 21 | |
8d5a3312 | 22 | TRACE_PATH=$(mktemp -d -t tmp.test_snapshots_ust_streaming_trace_path.XXXXXX) |
ebaaaf5e | 23 | |
bd666153 | 24 | NUM_TESTS=85 |
ebaaaf5e JD |
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 | ||
8c93562f | 47 | # Start trace application and return once one event has been hit. |
0fc2834c | 48 | function start_test_app() |
8c93562f | 49 | { |
8d5a3312 | 50 | local tmp_file=$(mktemp -u -t tmp.test_${FUNCNAME[0]}_tmp_file.XXXXXX) |
8c93562f DG |
51 | |
52 | # Start application with a temporary file. | |
6c4a91d6 | 53 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file & |
0fc2834c MD |
54 | ret=$? |
55 | APPS_PID="${APPS_PID} ${!}" | |
56 | ok $ret "Start application to trace" | |
8c93562f DG |
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 | ||
0fc2834c | 67 | function stop_test_apps() |
5dca3876 | 68 | { |
0fc2834c MD |
69 | diag "Stopping $TESTAPP_NAME" |
70 | for p in ${APPS_PID}; do | |
71 | kill ${p} | |
5402fe87 | 72 | wait ${p} 2>/dev/null |
0fc2834c | 73 | done |
c7613334 | 74 | APPS_PID= |
5dca3876 MD |
75 | } |
76 | ||
ebaaaf5e JD |
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 | |
c4926bb5 | 83 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 84 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 85 | |
0fc2834c | 86 | start_test_app |
8c93562f | 87 | |
ebaaaf5e JD |
88 | snapshot_add_output $SESSION_NAME "net://localhost" |
89 | lttng_snapshot_record $SESSION_NAME | |
90 | ||
91 | # Validate test | |
bd666153 | 92 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 |
b178f53e | 93 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* |
ebaaaf5e | 94 | if [ $? -ne 0 ]; then |
0fc2834c | 95 | stop_test_apps |
ebaaaf5e JD |
96 | return $? |
97 | fi | |
98 | ||
31580dc7 | 99 | lttng_snapshot_del_output_ok $SESSION_NAME 1 |
ebaaaf5e JD |
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. | |
bd666153 | 104 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-2" 1 |
b178f53e | 105 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2* |
ebaaaf5e | 106 | if [ $? -ne 0 ]; then |
0fc2834c | 107 | stop_test_apps |
ebaaaf5e JD |
108 | return $? |
109 | fi | |
110 | ||
96340a01 | 111 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 112 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e | 113 | |
0fc2834c | 114 | stop_test_apps |
ebaaaf5e JD |
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 | |
c4926bb5 | 125 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 126 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 127 | |
0fc2834c | 128 | start_test_app |
8c93562f | 129 | |
ebaaaf5e JD |
130 | snapshot_add_output $SESSION_NAME "net://localhost" |
131 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 132 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 133 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e | 134 | # Validate test |
bd666153 | 135 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 |
b178f53e | 136 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* |
ebaaaf5e JD |
137 | out=$? |
138 | ||
0fc2834c | 139 | stop_test_apps |
ebaaaf5e JD |
140 | |
141 | return $out | |
142 | } | |
143 | ||
847b88a9 CB |
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 | |
c4926bb5 | 149 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 150 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 151 | |
0fc2834c | 152 | start_test_app |
8c93562f | 153 | |
847b88a9 CB |
154 | snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343" |
155 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 156 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 157 | destroy_lttng_session_ok $SESSION_NAME |
847b88a9 | 158 | # Validate test |
bd666153 | 159 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 |
b178f53e | 160 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* |
847b88a9 CB |
161 | out=$? |
162 | ||
0fc2834c | 163 | stop_test_apps |
847b88a9 CB |
164 | |
165 | return $out | |
166 | } | |
167 | ||
ebaaaf5e JD |
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 | |
c4926bb5 | 177 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 178 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 179 | |
0fc2834c | 180 | start_test_app |
8c93562f | 181 | |
ebaaaf5e JD |
182 | snapshot_add_output $SESSION_NAME "net://localhost" $name |
183 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 184 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 185 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e | 186 | |
b178f53e | 187 | if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev/null; then |
ebaaaf5e JD |
188 | ok 0 "Custom name snapshot exists" |
189 | # Validate test | |
bd666153 | 190 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "$name" 0 |
b178f53e | 191 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-* |
ebaaaf5e JD |
192 | out=$? |
193 | else | |
194 | fail "No custom name snapshot found" | |
195 | out=1 | |
196 | fi | |
197 | ||
0fc2834c | 198 | stop_test_apps |
ebaaaf5e JD |
199 | |
200 | return $out | |
201 | } | |
202 | ||
b61ccd96 JR |
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 | |
bd666153 | 209 | snapshot_add_output $SESSION_NAME "net://localhost" |
b61ccd96 | 210 | start_test_app |
bd666153 | 211 | for i in {0..4}; |
b61ccd96 JR |
212 | do |
213 | start_lttng_tracing_ok $SESSION_NAME | |
214 | lttng_snapshot_record $SESSION_NAME | |
215 | stop_lttng_tracing_ok $SESSION_NAME | |
bd666153 | 216 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" $i |
b178f53e | 217 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* |
b61ccd96 JR |
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 | ||
ebaaaf5e JD |
231 | plan_tests $NUM_TESTS |
232 | ||
233 | print_test_banner "$TEST_DESC" | |
234 | ||
c125de8f FD |
235 | bail_out_if_no_babeltrace |
236 | ||
ebaaaf5e JD |
237 | if [ "$(id -u)" == "0" ]; then |
238 | isroot=1 | |
239 | else | |
240 | isroot=0 | |
241 | fi | |
242 | ||
243 | start_lttng_relayd "-o $TRACE_PATH" | |
244 | start_lttng_sessiond | |
245 | ||
b61ccd96 JR |
246 | tests=( test_ust_default_name_with_del |
247 | test_ust_default_name | |
248 | test_ust_custom_name | |
249 | test_ust_default_name_custom_uri | |
250 | test_ust_n_snapshot | |
251 | ) | |
ebaaaf5e JD |
252 | |
253 | for fct_test in ${tests[@]}; | |
254 | do | |
255 | SESSION_NAME=$(randstring 16 0) | |
256 | ${fct_test} | |
257 | if [ $? -eq 0 ]; then | |
258 | # Only delete if successful | |
259 | rm -rf $TRACE_PATH | |
260 | else | |
261 | break | |
262 | fi | |
263 | done | |
264 | ||
265 | stop_lttng_sessiond | |
266 | stop_lttng_relayd |