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 | ||
c1896e2d KS |
9 | CURDIR=$(dirname "$0")/ |
10 | TESTDIR="$CURDIR/../../.." | |
ebaaaf5e | 11 | EVENT_NAME="tp:tptest" |
ebaaaf5e JD |
12 | SESSION_NAME="" |
13 | CHANNEL_NAME="chan1" | |
ebaaaf5e JD |
14 | TESTAPP_PATH="$TESTDIR/utils/testapp" |
15 | TESTAPP_NAME="gen-ust-events" | |
16 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
18c9d47c | 17 | NR_ITER=-1 |
ebaaaf5e | 18 | NR_USEC_WAIT=100 |
c1896e2d | 19 | APP_PIDS=() |
ebaaaf5e | 20 | |
8d5a3312 | 21 | TRACE_PATH=$(mktemp -d -t tmp.test_snapshots_ust_streaming_trace_path.XXXXXX) |
ebaaaf5e | 22 | |
bd666153 | 23 | NUM_TESTS=85 |
ebaaaf5e | 24 | |
c1896e2d KS |
25 | # shellcheck source-path=SCRIPTDIR/../../../ |
26 | source "$TESTDIR/utils/utils.sh" | |
ebaaaf5e JD |
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 | |
c1896e2d KS |
37 | local options=() |
38 | local args=() | |
ebaaaf5e | 39 | |
c1896e2d KS |
40 | if [ -n "$sess_name" ] ; then |
41 | options+=(-s "$sess_name") | |
ebaaaf5e JD |
42 | fi |
43 | ||
c1896e2d KS |
44 | if [ -n "$name" ]; then |
45 | options+=(-n "$name") | |
46 | fi | |
47 | ||
48 | # Checking for any other optional arguments that should be passed to the lttng command | |
49 | args=("$@") | |
50 | if [ -n "${args[*]:3}" ] ; then | |
51 | options+=("${args[@]:3}") | |
52 | fi | |
53 | ||
54 | # The trace_path is a positional argument and must always come last if it is defined | |
55 | if [ -n "$trace_path" ] ; then | |
56 | options+=("$trace_path") | |
57 | fi | |
58 | ||
59 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" snapshot add-output "${options[@]}" >/dev/null 2>&1 | |
ebaaaf5e JD |
60 | ok $? "Added snapshot output $trace_path" |
61 | } | |
62 | ||
8c93562f | 63 | # Start trace application and return once one event has been hit. |
0fc2834c | 64 | function start_test_app() |
8c93562f | 65 | { |
c1896e2d KS |
66 | local tmp_file |
67 | tmp_file=$(mktemp -u -t tmp.test_"${FUNCNAME[0]}"_tmp_file.XXXXXX) | |
8c93562f DG |
68 | |
69 | # Start application with a temporary file. | |
c1896e2d | 70 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event "$tmp_file" & |
0fc2834c | 71 | ret=$? |
c1896e2d | 72 | APP_PIDS+=(${!}) |
0fc2834c | 73 | ok $ret "Start application to trace" |
8c93562f DG |
74 | |
75 | # Wait for the application file to appear indicating that at least one | |
76 | # tracepoint has been fired. | |
77 | while [ ! -f "$tmp_file" ]; do | |
78 | sleep 0.5 | |
79 | done | |
80 | diag "Removing test app temporary file $tmp_file" | |
c1896e2d | 81 | rm -f "$tmp_file" |
8c93562f DG |
82 | } |
83 | ||
0fc2834c | 84 | function stop_test_apps() |
5dca3876 | 85 | { |
0fc2834c | 86 | diag "Stopping $TESTAPP_NAME" |
c1896e2d KS |
87 | kill "${APP_PIDS[@]}" |
88 | wait "${APP_PIDS[@]}" 2>/dev/null | |
89 | APP_PIDS=() | |
5dca3876 MD |
90 | } |
91 | ||
ebaaaf5e JD |
92 | # Test a snapshot using a default name for the output destination. |
93 | function test_ust_default_name_with_del() | |
94 | { | |
95 | diag "Test UST snapshot streaming with default name with delete output" | |
c1896e2d KS |
96 | create_lttng_session_no_output "$SESSION_NAME" |
97 | enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME | |
98 | enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME | |
99 | start_lttng_tracing_ok "$SESSION_NAME" | |
8c93562f | 100 | |
0fc2834c | 101 | start_test_app |
8c93562f | 102 | |
c1896e2d KS |
103 | snapshot_add_output "$SESSION_NAME" "net://localhost" |
104 | lttng_snapshot_record "$SESSION_NAME" | |
ebaaaf5e JD |
105 | |
106 | # Validate test | |
bd666153 | 107 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 |
c1896e2d | 108 | if ! validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*" ; then |
0fc2834c | 109 | stop_test_apps |
ebaaaf5e JD |
110 | return $? |
111 | fi | |
112 | ||
c1896e2d KS |
113 | lttng_snapshot_del_output_ok "$SESSION_NAME" 1 |
114 | snapshot_add_output "$SESSION_NAME" "net://localhost" | |
115 | lttng_snapshot_record "$SESSION_NAME" | |
ebaaaf5e JD |
116 | |
117 | # Validate test with the next ID since a del output was done prior. | |
bd666153 | 118 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-2" 1 |
c1896e2d | 119 | if ! validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2*" ; then |
0fc2834c | 120 | stop_test_apps |
ebaaaf5e JD |
121 | return $? |
122 | fi | |
123 | ||
c1896e2d KS |
124 | stop_lttng_tracing_ok "$SESSION_NAME" |
125 | destroy_lttng_session_ok "$SESSION_NAME" | |
ebaaaf5e | 126 | |
0fc2834c | 127 | stop_test_apps |
ebaaaf5e JD |
128 | |
129 | return 0 | |
130 | } | |
131 | ||
132 | # Test a snapshot using a default name for the output destination. | |
133 | function test_ust_default_name() | |
134 | { | |
135 | diag "Test UST snapshot streaming with default name" | |
c1896e2d KS |
136 | create_lttng_session_no_output "$SESSION_NAME" |
137 | enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME | |
138 | enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME | |
139 | start_lttng_tracing_ok "$SESSION_NAME" | |
8c93562f | 140 | |
0fc2834c | 141 | start_test_app |
8c93562f | 142 | |
c1896e2d KS |
143 | snapshot_add_output "$SESSION_NAME" "net://localhost" |
144 | lttng_snapshot_record "$SESSION_NAME" | |
145 | stop_lttng_tracing_ok "$SESSION_NAME" | |
146 | destroy_lttng_session_ok "$SESSION_NAME" | |
ebaaaf5e | 147 | # Validate test |
bd666153 | 148 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 |
c1896e2d | 149 | validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*" |
ebaaaf5e JD |
150 | out=$? |
151 | ||
0fc2834c | 152 | stop_test_apps |
ebaaaf5e JD |
153 | |
154 | return $out | |
155 | } | |
156 | ||
847b88a9 CB |
157 | function test_ust_default_name_custom_uri() |
158 | { | |
159 | diag "Test UST snapshot streaming with default name with custom URL" | |
c1896e2d KS |
160 | create_lttng_session_no_output "$SESSION_NAME" |
161 | enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME | |
162 | enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME | |
163 | start_lttng_tracing_ok "$SESSION_NAME" | |
8c93562f | 164 | |
0fc2834c | 165 | start_test_app |
8c93562f | 166 | |
c1896e2d KS |
167 | snapshot_add_output "$SESSION_NAME" '' '' -C tcp://localhost:5342 -D tcp://localhost:5343 |
168 | lttng_snapshot_record "$SESSION_NAME" | |
169 | stop_lttng_tracing_ok "$SESSION_NAME" | |
170 | destroy_lttng_session_ok "$SESSION_NAME" | |
847b88a9 | 171 | # Validate test |
bd666153 | 172 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" 0 |
c1896e2d | 173 | validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*" |
847b88a9 CB |
174 | out=$? |
175 | ||
0fc2834c | 176 | stop_test_apps |
847b88a9 CB |
177 | |
178 | return $out | |
179 | } | |
180 | ||
ebaaaf5e JD |
181 | # Test a snapshot using a custom name for the output destination. |
182 | function test_ust_custom_name() | |
183 | { | |
184 | local out | |
185 | local name="asnapshotname" | |
186 | ||
187 | diag "Test UST snapshot streaming with custom name" | |
c1896e2d KS |
188 | create_lttng_session_no_output "$SESSION_NAME" |
189 | enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME | |
190 | enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME | |
191 | start_lttng_tracing_ok "$SESSION_NAME" | |
8c93562f | 192 | |
0fc2834c | 193 | start_test_app |
8c93562f | 194 | |
c1896e2d KS |
195 | snapshot_add_output "$SESSION_NAME" "net://localhost" $name |
196 | lttng_snapshot_record "$SESSION_NAME" | |
197 | stop_lttng_tracing_ok "$SESSION_NAME" | |
198 | destroy_lttng_session_ok "$SESSION_NAME" | |
ebaaaf5e | 199 | |
c1896e2d | 200 | if ls "$TRACE_PATH/$HOSTNAME/$SESSION_NAME"*/"$name"* &> /dev/null; then |
ebaaaf5e JD |
201 | ok 0 "Custom name snapshot exists" |
202 | # Validate test | |
bd666153 | 203 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "$name" 0 |
c1896e2d | 204 | validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-*" |
ebaaaf5e JD |
205 | out=$? |
206 | else | |
207 | fail "No custom name snapshot found" | |
208 | out=1 | |
209 | fi | |
210 | ||
0fc2834c | 211 | stop_test_apps |
ebaaaf5e JD |
212 | |
213 | return $out | |
214 | } | |
215 | ||
b61ccd96 JR |
216 | function test_ust_n_snapshot() |
217 | { | |
218 | diag "Test ust snapshot streaming multiple consecutive snapshot" | |
c1896e2d KS |
219 | create_lttng_session_no_output "$SESSION_NAME" |
220 | enable_lttng_mmap_overwrite_ust_channel "$SESSION_NAME" $CHANNEL_NAME | |
221 | enable_ust_lttng_event_ok "$SESSION_NAME" $EVENT_NAME $CHANNEL_NAME | |
222 | snapshot_add_output "$SESSION_NAME" "net://localhost" | |
b61ccd96 | 223 | start_test_app |
bd666153 | 224 | for i in {0..4}; |
b61ccd96 | 225 | do |
c1896e2d KS |
226 | start_lttng_tracing_ok "$SESSION_NAME" |
227 | lttng_snapshot_record "$SESSION_NAME" | |
228 | stop_lttng_tracing_ok "$SESSION_NAME" | |
229 | validate_trace_path_ust_uid_snapshot_network "$TRACE_PATH" "$SESSION_NAME" "snapshot-1" "$i" | |
230 | if ! validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1*" ; then | |
b61ccd96 JR |
231 | return 1 |
232 | fi | |
233 | set -u | |
c1896e2d | 234 | rm -rf "${TRACE_PATH:?}/${HOSTNAME}" |
b61ccd96 JR |
235 | set +u |
236 | done | |
237 | ||
c1896e2d | 238 | destroy_lttng_session_ok "$SESSION_NAME" |
b61ccd96 JR |
239 | stop_test_apps |
240 | return 0 | |
241 | } | |
242 | ||
ebaaaf5e JD |
243 | plan_tests $NUM_TESTS |
244 | ||
245 | print_test_banner "$TEST_DESC" | |
246 | ||
c125de8f FD |
247 | bail_out_if_no_babeltrace |
248 | ||
ebaaaf5e | 249 | start_lttng_relayd "-o $TRACE_PATH" |
c1896e2d | 250 | # shellcheck disable=SC2119 |
ebaaaf5e JD |
251 | start_lttng_sessiond |
252 | ||
b61ccd96 JR |
253 | tests=( test_ust_default_name_with_del |
254 | test_ust_default_name | |
255 | test_ust_custom_name | |
256 | test_ust_default_name_custom_uri | |
257 | test_ust_n_snapshot | |
258 | ) | |
ebaaaf5e | 259 | |
c1896e2d | 260 | for fct_test in "${tests[@]}"; |
ebaaaf5e JD |
261 | do |
262 | SESSION_NAME=$(randstring 16 0) | |
c1896e2d | 263 | if ${fct_test} ; then |
ebaaaf5e | 264 | # Only delete if successful |
c1896e2d | 265 | rm -rf "$TRACE_PATH" |
ebaaaf5e JD |
266 | else |
267 | break | |
268 | fi | |
269 | done | |
270 | ||
c1896e2d | 271 | # shellcheck disable=SC2119 |
ebaaaf5e | 272 | stop_lttng_sessiond |
c1896e2d | 273 | # shellcheck disable=SC2119 |
ebaaaf5e | 274 | stop_lttng_relayd |