Commit | Line | Data |
---|---|---|
ebaaaf5e JD |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2013 David Goulet <dgoulet@efficios.com> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | TEST_DESC="Streaming - Snapshot UST tracing" | |
18 | ||
19 | CURDIR=$(dirname $0)/ | |
20 | TESTDIR=$CURDIR/../../.. | |
21 | EVENT_NAME="tp:tptest" | |
22 | PID_RELAYD=0 | |
23 | SESSION_NAME="" | |
24 | CHANNEL_NAME="chan1" | |
25 | BIN_NAME="gen-nevents" | |
26 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
27 | TESTAPP_NAME="gen-ust-events" | |
28 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
29 | NR_ITER=2000000 | |
30 | NR_USEC_WAIT=100 | |
0fc2834c | 31 | APPS_PID= |
ebaaaf5e JD |
32 | |
33 | TRACE_PATH=$(mktemp -d) | |
34 | ||
847b88a9 | 35 | NUM_TESTS=49 |
ebaaaf5e JD |
36 | |
37 | source $TESTDIR/utils/utils.sh | |
38 | ||
39 | if [ ! -x "$TESTAPP_BIN" ]; then | |
40 | BAIL_OUT "No UST events binary detected." | |
41 | fi | |
42 | ||
43 | function snapshot_add_output () | |
44 | { | |
45 | local sess_name=$1 | |
46 | local trace_path=$2 | |
47 | local name=$3 | |
48 | local extra_opt="" | |
49 | ||
50 | if [ ! -z $name ]; then | |
51 | extra_opt="-n $name" | |
52 | fi | |
53 | ||
54 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $extra_opt $trace_path >/dev/null 2>&1 | |
55 | ok $? "Added snapshot output $trace_path" | |
56 | } | |
57 | ||
8c93562f | 58 | # Start trace application and return once one event has been hit. |
0fc2834c | 59 | function start_test_app() |
8c93562f | 60 | { |
5fcaccbc | 61 | local tmp_file=$(mktemp -u) |
8c93562f DG |
62 | |
63 | # Start application with a temporary file. | |
64 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file & | |
0fc2834c MD |
65 | ret=$? |
66 | APPS_PID="${APPS_PID} ${!}" | |
67 | ok $ret "Start application to trace" | |
8c93562f DG |
68 | |
69 | # Wait for the application file to appear indicating that at least one | |
70 | # tracepoint has been fired. | |
71 | while [ ! -f "$tmp_file" ]; do | |
72 | sleep 0.5 | |
73 | done | |
74 | diag "Removing test app temporary file $tmp_file" | |
75 | rm -f $tmp_file | |
76 | } | |
77 | ||
0fc2834c | 78 | function stop_test_apps() |
5dca3876 | 79 | { |
0fc2834c MD |
80 | diag "Stopping $TESTAPP_NAME" |
81 | for p in ${APPS_PID}; do | |
82 | kill ${p} | |
5402fe87 | 83 | wait ${p} 2>/dev/null |
0fc2834c | 84 | done |
c7613334 | 85 | APPS_PID= |
5dca3876 MD |
86 | } |
87 | ||
ebaaaf5e JD |
88 | # Test a snapshot using a default name for the output destination. |
89 | function test_ust_default_name_with_del() | |
90 | { | |
91 | diag "Test UST snapshot streaming with default name with delete output" | |
92 | create_lttng_session_no_output $SESSION_NAME | |
93 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 94 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
ebaaaf5e | 95 | start_lttng_tracing $SESSION_NAME |
8c93562f | 96 | |
0fc2834c | 97 | start_test_app |
8c93562f | 98 | |
ebaaaf5e JD |
99 | snapshot_add_output $SESSION_NAME "net://localhost" |
100 | lttng_snapshot_record $SESSION_NAME | |
101 | ||
102 | # Validate test | |
103 | echo $TRACE_PATH/$HOSTNAME/snapshot-1 | |
104 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
105 | if [ $? -ne 0 ]; then | |
0fc2834c | 106 | stop_test_apps |
ebaaaf5e JD |
107 | return $? |
108 | fi | |
109 | ||
110 | lttng_snapshot_del_output $SESSION_NAME 1 | |
111 | snapshot_add_output $SESSION_NAME "net://localhost" | |
112 | lttng_snapshot_record $SESSION_NAME | |
113 | ||
114 | # Validate test with the next ID since a del output was done prior. | |
115 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2* | |
116 | if [ $? -ne 0 ]; then | |
0fc2834c | 117 | stop_test_apps |
ebaaaf5e JD |
118 | return $? |
119 | fi | |
120 | ||
121 | stop_lttng_tracing $SESSION_NAME | |
122 | destroy_lttng_session $SESSION_NAME | |
123 | ||
0fc2834c | 124 | stop_test_apps |
ebaaaf5e JD |
125 | |
126 | return 0 | |
127 | } | |
128 | ||
129 | # Test a snapshot using a default name for the output destination. | |
130 | function test_ust_default_name() | |
131 | { | |
132 | diag "Test UST snapshot streaming with default name" | |
133 | create_lttng_session_no_output $SESSION_NAME | |
134 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 135 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
ebaaaf5e | 136 | start_lttng_tracing $SESSION_NAME |
8c93562f | 137 | |
0fc2834c | 138 | start_test_app |
8c93562f | 139 | |
ebaaaf5e JD |
140 | snapshot_add_output $SESSION_NAME "net://localhost" |
141 | lttng_snapshot_record $SESSION_NAME | |
142 | stop_lttng_tracing $SESSION_NAME | |
143 | destroy_lttng_session $SESSION_NAME | |
144 | # Validate test | |
145 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
146 | out=$? | |
147 | ||
0fc2834c | 148 | stop_test_apps |
ebaaaf5e JD |
149 | |
150 | return $out | |
151 | } | |
152 | ||
847b88a9 CB |
153 | function test_ust_default_name_custom_uri() |
154 | { | |
155 | diag "Test UST snapshot streaming with default name with custom URL" | |
156 | create_lttng_session_no_output $SESSION_NAME | |
157 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 158 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
847b88a9 | 159 | start_lttng_tracing $SESSION_NAME |
8c93562f | 160 | |
0fc2834c | 161 | start_test_app |
8c93562f | 162 | |
847b88a9 CB |
163 | snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343" |
164 | lttng_snapshot_record $SESSION_NAME | |
165 | stop_lttng_tracing $SESSION_NAME | |
166 | destroy_lttng_session $SESSION_NAME | |
167 | # Validate test | |
168 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
169 | out=$? | |
170 | ||
0fc2834c | 171 | stop_test_apps |
847b88a9 CB |
172 | |
173 | return $out | |
174 | } | |
175 | ||
ebaaaf5e JD |
176 | # Test a snapshot using a custom name for the output destination. |
177 | function test_ust_custom_name() | |
178 | { | |
179 | local out | |
180 | local name="asnapshotname" | |
181 | ||
182 | diag "Test UST snapshot streaming with custom name" | |
183 | create_lttng_session_no_output $SESSION_NAME | |
184 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 185 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
ebaaaf5e | 186 | start_lttng_tracing $SESSION_NAME |
8c93562f | 187 | |
0fc2834c | 188 | start_test_app |
8c93562f | 189 | |
ebaaaf5e JD |
190 | snapshot_add_output $SESSION_NAME "net://localhost" $name |
191 | lttng_snapshot_record $SESSION_NAME | |
192 | stop_lttng_tracing $SESSION_NAME | |
193 | destroy_lttng_session $SESSION_NAME | |
194 | ||
195 | if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev/null; then | |
196 | ok 0 "Custom name snapshot exists" | |
197 | # Validate test | |
198 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-* | |
199 | out=$? | |
200 | else | |
201 | fail "No custom name snapshot found" | |
202 | out=1 | |
203 | fi | |
204 | ||
0fc2834c | 205 | stop_test_apps |
ebaaaf5e JD |
206 | |
207 | return $out | |
208 | } | |
209 | ||
210 | plan_tests $NUM_TESTS | |
211 | ||
212 | print_test_banner "$TEST_DESC" | |
213 | ||
214 | if [ "$(id -u)" == "0" ]; then | |
215 | isroot=1 | |
216 | else | |
217 | isroot=0 | |
218 | fi | |
219 | ||
220 | start_lttng_relayd "-o $TRACE_PATH" | |
221 | start_lttng_sessiond | |
222 | ||
847b88a9 | 223 | tests=( test_ust_default_name_with_del test_ust_default_name test_ust_custom_name test_ust_default_name_custom_uri ) |
ebaaaf5e JD |
224 | |
225 | for fct_test in ${tests[@]}; | |
226 | do | |
227 | SESSION_NAME=$(randstring 16 0) | |
228 | ${fct_test} | |
229 | if [ $? -eq 0 ]; then | |
230 | # Only delete if successful | |
231 | rm -rf $TRACE_PATH | |
232 | else | |
233 | break | |
234 | fi | |
235 | done | |
236 | ||
237 | stop_lttng_sessiond | |
238 | stop_lttng_relayd |