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" | |
ebaaaf5e JD |
22 | SESSION_NAME="" |
23 | CHANNEL_NAME="chan1" | |
24 | BIN_NAME="gen-nevents" | |
25 | TESTAPP_PATH="$TESTDIR/utils/testapp" | |
26 | TESTAPP_NAME="gen-ust-events" | |
27 | TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME" | |
28 | NR_ITER=2000000 | |
29 | NR_USEC_WAIT=100 | |
0fc2834c | 30 | APPS_PID= |
ebaaaf5e JD |
31 | |
32 | TRACE_PATH=$(mktemp -d) | |
33 | ||
847b88a9 | 34 | NUM_TESTS=49 |
ebaaaf5e JD |
35 | |
36 | source $TESTDIR/utils/utils.sh | |
37 | ||
38 | if [ ! -x "$TESTAPP_BIN" ]; then | |
39 | BAIL_OUT "No UST events binary detected." | |
40 | fi | |
41 | ||
42 | function snapshot_add_output () | |
43 | { | |
44 | local sess_name=$1 | |
45 | local trace_path=$2 | |
46 | local name=$3 | |
47 | local extra_opt="" | |
48 | ||
49 | if [ ! -z $name ]; then | |
50 | extra_opt="-n $name" | |
51 | fi | |
52 | ||
53 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $extra_opt $trace_path >/dev/null 2>&1 | |
54 | ok $? "Added snapshot output $trace_path" | |
55 | } | |
56 | ||
8c93562f | 57 | # Start trace application and return once one event has been hit. |
0fc2834c | 58 | function start_test_app() |
8c93562f | 59 | { |
5fcaccbc | 60 | local tmp_file=$(mktemp -u) |
8c93562f DG |
61 | |
62 | # Start application with a temporary file. | |
63 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file & | |
0fc2834c MD |
64 | ret=$? |
65 | APPS_PID="${APPS_PID} ${!}" | |
66 | ok $ret "Start application to trace" | |
8c93562f DG |
67 | |
68 | # Wait for the application file to appear indicating that at least one | |
69 | # tracepoint has been fired. | |
70 | while [ ! -f "$tmp_file" ]; do | |
71 | sleep 0.5 | |
72 | done | |
73 | diag "Removing test app temporary file $tmp_file" | |
74 | rm -f $tmp_file | |
75 | } | |
76 | ||
0fc2834c | 77 | function stop_test_apps() |
5dca3876 | 78 | { |
0fc2834c MD |
79 | diag "Stopping $TESTAPP_NAME" |
80 | for p in ${APPS_PID}; do | |
81 | kill ${p} | |
5402fe87 | 82 | wait ${p} 2>/dev/null |
0fc2834c | 83 | done |
c7613334 | 84 | APPS_PID= |
5dca3876 MD |
85 | } |
86 | ||
ebaaaf5e JD |
87 | # Test a snapshot using a default name for the output destination. |
88 | function test_ust_default_name_with_del() | |
89 | { | |
90 | diag "Test UST snapshot streaming with default name with delete output" | |
91 | create_lttng_session_no_output $SESSION_NAME | |
92 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 93 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 94 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 95 | |
0fc2834c | 96 | start_test_app |
8c93562f | 97 | |
ebaaaf5e JD |
98 | snapshot_add_output $SESSION_NAME "net://localhost" |
99 | lttng_snapshot_record $SESSION_NAME | |
100 | ||
101 | # Validate test | |
102 | echo $TRACE_PATH/$HOSTNAME/snapshot-1 | |
103 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
104 | if [ $? -ne 0 ]; then | |
0fc2834c | 105 | stop_test_apps |
ebaaaf5e JD |
106 | return $? |
107 | fi | |
108 | ||
31580dc7 | 109 | lttng_snapshot_del_output_ok $SESSION_NAME 1 |
ebaaaf5e JD |
110 | snapshot_add_output $SESSION_NAME "net://localhost" |
111 | lttng_snapshot_record $SESSION_NAME | |
112 | ||
113 | # Validate test with the next ID since a del output was done prior. | |
114 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2* | |
115 | if [ $? -ne 0 ]; then | |
0fc2834c | 116 | stop_test_apps |
ebaaaf5e JD |
117 | return $? |
118 | fi | |
119 | ||
96340a01 | 120 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 121 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e | 122 | |
0fc2834c | 123 | stop_test_apps |
ebaaaf5e JD |
124 | |
125 | return 0 | |
126 | } | |
127 | ||
128 | # Test a snapshot using a default name for the output destination. | |
129 | function test_ust_default_name() | |
130 | { | |
131 | diag "Test UST snapshot streaming with default name" | |
132 | create_lttng_session_no_output $SESSION_NAME | |
133 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 134 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 135 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 136 | |
0fc2834c | 137 | start_test_app |
8c93562f | 138 | |
ebaaaf5e JD |
139 | snapshot_add_output $SESSION_NAME "net://localhost" |
140 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 141 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 142 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e JD |
143 | # Validate test |
144 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
145 | out=$? | |
146 | ||
0fc2834c | 147 | stop_test_apps |
ebaaaf5e JD |
148 | |
149 | return $out | |
150 | } | |
151 | ||
847b88a9 CB |
152 | function test_ust_default_name_custom_uri() |
153 | { | |
154 | diag "Test UST snapshot streaming with default name with custom URL" | |
155 | create_lttng_session_no_output $SESSION_NAME | |
156 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 157 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 158 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 159 | |
0fc2834c | 160 | start_test_app |
8c93562f | 161 | |
847b88a9 CB |
162 | snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343" |
163 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 164 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 165 | destroy_lttng_session_ok $SESSION_NAME |
847b88a9 CB |
166 | # Validate test |
167 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
168 | out=$? | |
169 | ||
0fc2834c | 170 | stop_test_apps |
847b88a9 CB |
171 | |
172 | return $out | |
173 | } | |
174 | ||
ebaaaf5e JD |
175 | # Test a snapshot using a custom name for the output destination. |
176 | function test_ust_custom_name() | |
177 | { | |
178 | local out | |
179 | local name="asnapshotname" | |
180 | ||
181 | diag "Test UST snapshot streaming with custom name" | |
182 | create_lttng_session_no_output $SESSION_NAME | |
183 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
c4926bb5 | 184 | enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME |
e563bbdb | 185 | start_lttng_tracing_ok $SESSION_NAME |
8c93562f | 186 | |
0fc2834c | 187 | start_test_app |
8c93562f | 188 | |
ebaaaf5e JD |
189 | snapshot_add_output $SESSION_NAME "net://localhost" $name |
190 | lttng_snapshot_record $SESSION_NAME | |
96340a01 | 191 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 192 | destroy_lttng_session_ok $SESSION_NAME |
ebaaaf5e JD |
193 | |
194 | if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev/null; then | |
195 | ok 0 "Custom name snapshot exists" | |
196 | # Validate test | |
197 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-* | |
198 | out=$? | |
199 | else | |
200 | fail "No custom name snapshot found" | |
201 | out=1 | |
202 | fi | |
203 | ||
0fc2834c | 204 | stop_test_apps |
ebaaaf5e JD |
205 | |
206 | return $out | |
207 | } | |
208 | ||
209 | plan_tests $NUM_TESTS | |
210 | ||
211 | print_test_banner "$TEST_DESC" | |
212 | ||
213 | if [ "$(id -u)" == "0" ]; then | |
214 | isroot=1 | |
215 | else | |
216 | isroot=0 | |
217 | fi | |
218 | ||
219 | start_lttng_relayd "-o $TRACE_PATH" | |
220 | start_lttng_sessiond | |
221 | ||
847b88a9 | 222 | tests=( test_ust_default_name_with_del test_ust_default_name test_ust_custom_name test_ust_default_name_custom_uri ) |
ebaaaf5e JD |
223 | |
224 | for fct_test in ${tests[@]}; | |
225 | do | |
226 | SESSION_NAME=$(randstring 16 0) | |
227 | ${fct_test} | |
228 | if [ $? -eq 0 ]; then | |
229 | # Only delete if successful | |
230 | rm -rf $TRACE_PATH | |
231 | else | |
232 | break | |
233 | fi | |
234 | done | |
235 | ||
236 | stop_lttng_sessiond | |
237 | stop_lttng_relayd |