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 JD |
21 | |
22 | TRACE_PATH=$(mktemp -d) | |
23 | ||
b61ccd96 | 24 | NUM_TESTS=75 |
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 | { |
5fcaccbc | 50 | local tmp_file=$(mktemp -u) |
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 | |
b178f53e | 92 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* |
ebaaaf5e | 93 | if [ $? -ne 0 ]; then |
0fc2834c | 94 | stop_test_apps |
ebaaaf5e JD |
95 | return $? |
96 | fi | |
97 | ||
31580dc7 | 98 | lttng_snapshot_del_output_ok $SESSION_NAME 1 |
ebaaaf5e JD |
99 | snapshot_add_output $SESSION_NAME "net://localhost" |
100 | lttng_snapshot_record $SESSION_NAME | |
101 | ||
102 | # Validate test with the next ID since a del output was done prior. | |
b178f53e | 103 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-2* |
ebaaaf5e | 104 | if [ $? -ne 0 ]; then |
0fc2834c | 105 | stop_test_apps |
ebaaaf5e JD |
106 | return $? |
107 | fi | |
108 | ||
96340a01 | 109 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 110 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e | 111 | |
0fc2834c | 112 | stop_test_apps |
ebaaaf5e JD |
113 | |
114 | return 0 | |
115 | } | |
116 | ||
117 | # Test a snapshot using a default name for the output destination. | |
118 | function test_ust_default_name() | |
119 | { | |
120 | diag "Test UST snapshot streaming with default name" | |
121 | create_lttng_session_no_output $SESSION_NAME | |
122 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 123 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 124 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 125 | |
0fc2834c | 126 | start_test_app |
8c93562f | 127 | |
ebaaaf5e JD |
128 | snapshot_add_output $SESSION_NAME "net://localhost" |
129 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 130 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 131 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e | 132 | # Validate test |
b178f53e | 133 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* |
ebaaaf5e JD |
134 | out=$? |
135 | ||
0fc2834c | 136 | stop_test_apps |
ebaaaf5e JD |
137 | |
138 | return $out | |
139 | } | |
140 | ||
847b88a9 CB |
141 | function test_ust_default_name_custom_uri() |
142 | { | |
143 | diag "Test UST snapshot streaming with default name with custom URL" | |
144 | create_lttng_session_no_output $SESSION_NAME | |
145 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 146 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 147 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 148 | |
0fc2834c | 149 | start_test_app |
8c93562f | 150 | |
847b88a9 CB |
151 | snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343" |
152 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 153 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 154 | destroy_lttng_session_ok $SESSION_NAME |
847b88a9 | 155 | # Validate test |
b178f53e | 156 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* |
847b88a9 CB |
157 | out=$? |
158 | ||
0fc2834c | 159 | stop_test_apps |
847b88a9 CB |
160 | |
161 | return $out | |
162 | } | |
163 | ||
ebaaaf5e JD |
164 | # Test a snapshot using a custom name for the output destination. |
165 | function test_ust_custom_name() | |
166 | { | |
167 | local out | |
168 | local name="asnapshotname" | |
169 | ||
170 | diag "Test UST snapshot streaming with custom name" | |
171 | create_lttng_session_no_output $SESSION_NAME | |
172 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 173 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 174 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 175 | |
0fc2834c | 176 | start_test_app |
8c93562f | 177 | |
ebaaaf5e JD |
178 | snapshot_add_output $SESSION_NAME "net://localhost" $name |
179 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 180 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 181 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e | 182 | |
b178f53e | 183 | if ls $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name* &> /dev/null; then |
ebaaaf5e JD |
184 | ok 0 "Custom name snapshot exists" |
185 | # Validate test | |
b178f53e | 186 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/$name-* |
ebaaaf5e JD |
187 | out=$? |
188 | else | |
189 | fail "No custom name snapshot found" | |
190 | out=1 | |
191 | fi | |
192 | ||
0fc2834c | 193 | stop_test_apps |
ebaaaf5e JD |
194 | |
195 | return $out | |
196 | } | |
197 | ||
b61ccd96 JR |
198 | function test_ust_n_snapshot() |
199 | { | |
200 | diag "Test ust snapshot streaming multiple consecutive snapshot" | |
201 | create_lttng_session_no_output $SESSION_NAME | |
202 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
203 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
204 | snapshot_add_output $SESSION_NAME "net://localhost" $name | |
205 | start_test_app | |
206 | for i in {1..5}; | |
207 | do | |
208 | start_lttng_tracing_ok $SESSION_NAME | |
209 | lttng_snapshot_record $SESSION_NAME | |
210 | stop_lttng_tracing_ok $SESSION_NAME | |
b178f53e | 211 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*/snapshot-1* |
b61ccd96 JR |
212 | if [ $? -ne 0 ]; then |
213 | return 1 | |
214 | fi | |
215 | set -u | |
216 | rm -rf $TRACE_PATH/$HOSTNAME | |
217 | set +u | |
218 | done | |
219 | ||
220 | destroy_lttng_session_ok $SESSION_NAME | |
221 | stop_test_apps | |
222 | return 0 | |
223 | } | |
224 | ||
ebaaaf5e JD |
225 | plan_tests $NUM_TESTS |
226 | ||
227 | print_test_banner "$TEST_DESC" | |
228 | ||
229 | if [ "$(id -u)" == "0" ]; then | |
230 | isroot=1 | |
231 | else | |
232 | isroot=0 | |
233 | fi | |
234 | ||
235 | start_lttng_relayd "-o $TRACE_PATH" | |
236 | start_lttng_sessiond | |
237 | ||
b61ccd96 JR |
238 | tests=( test_ust_default_name_with_del |
239 | test_ust_default_name | |
240 | test_ust_custom_name | |
241 | test_ust_default_name_custom_uri | |
242 | test_ust_n_snapshot | |
243 | ) | |
ebaaaf5e JD |
244 | |
245 | for fct_test in ${tests[@]}; | |
246 | do | |
247 | SESSION_NAME=$(randstring 16 0) | |
248 | ${fct_test} | |
249 | if [ $? -eq 0 ]; then | |
250 | # Only delete if successful | |
251 | rm -rf $TRACE_PATH | |
252 | else | |
253 | break | |
254 | fi | |
255 | done | |
256 | ||
257 | stop_lttng_sessiond | |
258 | stop_lttng_relayd |