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 | |
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 DG |
57 | # Start trace application and return once one event has been hit. |
58 | function start_trace_app() | |
59 | { | |
60 | local tmp_file="/tmp/lttng_test_ust.42.file" | |
61 | ||
62 | # Start application with a temporary file. | |
63 | $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file & | |
64 | ok $? "Start application to trace" | |
65 | ||
66 | # Wait for the application file to appear indicating that at least one | |
67 | # tracepoint has been fired. | |
68 | while [ ! -f "$tmp_file" ]; do | |
69 | sleep 0.5 | |
70 | done | |
71 | diag "Removing test app temporary file $tmp_file" | |
72 | rm -f $tmp_file | |
73 | } | |
74 | ||
5dca3876 MD |
75 | function stop_trace_app() |
76 | { | |
77 | diag "Killing $TESTAPP_NAME" | |
78 | PID_APP=`pidof $TESTAPP_NAME` | |
79 | kill $PID_APP >/dev/null 2>&1 | |
80 | diag "Waiting on $TESTAPP_NAME" | |
81 | wait | |
82 | } | |
83 | ||
ebaaaf5e JD |
84 | # Test a snapshot using a default name for the output destination. |
85 | function test_ust_default_name_with_del() | |
86 | { | |
87 | diag "Test UST snapshot streaming with default name with delete output" | |
88 | create_lttng_session_no_output $SESSION_NAME | |
89 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
90 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
91 | start_lttng_tracing $SESSION_NAME | |
8c93562f DG |
92 | |
93 | start_trace_app | |
94 | ||
ebaaaf5e JD |
95 | snapshot_add_output $SESSION_NAME "net://localhost" |
96 | lttng_snapshot_record $SESSION_NAME | |
97 | ||
98 | # Validate test | |
99 | echo $TRACE_PATH/$HOSTNAME/snapshot-1 | |
100 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
101 | if [ $? -ne 0 ]; then | |
5dca3876 | 102 | stop_trace_app |
ebaaaf5e JD |
103 | return $? |
104 | fi | |
105 | ||
106 | lttng_snapshot_del_output $SESSION_NAME 1 | |
107 | snapshot_add_output $SESSION_NAME "net://localhost" | |
108 | lttng_snapshot_record $SESSION_NAME | |
109 | ||
110 | # Validate test with the next ID since a del output was done prior. | |
111 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2* | |
112 | if [ $? -ne 0 ]; then | |
5dca3876 | 113 | stop_trace_app |
ebaaaf5e JD |
114 | return $? |
115 | fi | |
116 | ||
117 | stop_lttng_tracing $SESSION_NAME | |
118 | destroy_lttng_session $SESSION_NAME | |
119 | ||
5dca3876 | 120 | stop_trace_app |
ebaaaf5e JD |
121 | |
122 | return 0 | |
123 | } | |
124 | ||
125 | # Test a snapshot using a default name for the output destination. | |
126 | function test_ust_default_name() | |
127 | { | |
128 | diag "Test UST snapshot streaming with default name" | |
129 | create_lttng_session_no_output $SESSION_NAME | |
130 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
131 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
132 | start_lttng_tracing $SESSION_NAME | |
8c93562f DG |
133 | |
134 | start_trace_app | |
135 | ||
ebaaaf5e JD |
136 | snapshot_add_output $SESSION_NAME "net://localhost" |
137 | lttng_snapshot_record $SESSION_NAME | |
138 | stop_lttng_tracing $SESSION_NAME | |
139 | destroy_lttng_session $SESSION_NAME | |
140 | # Validate test | |
141 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
142 | out=$? | |
143 | ||
5dca3876 | 144 | stop_trace_app |
ebaaaf5e JD |
145 | |
146 | return $out | |
147 | } | |
148 | ||
847b88a9 CB |
149 | function test_ust_default_name_custom_uri() |
150 | { | |
151 | diag "Test UST snapshot streaming with default name with custom URL" | |
152 | create_lttng_session_no_output $SESSION_NAME | |
153 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
154 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
155 | start_lttng_tracing $SESSION_NAME | |
8c93562f DG |
156 | |
157 | start_trace_app | |
158 | ||
847b88a9 CB |
159 | snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343" |
160 | lttng_snapshot_record $SESSION_NAME | |
161 | stop_lttng_tracing $SESSION_NAME | |
162 | destroy_lttng_session $SESSION_NAME | |
163 | # Validate test | |
164 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1* | |
165 | out=$? | |
166 | ||
5dca3876 | 167 | stop_trace_app |
847b88a9 CB |
168 | |
169 | return $out | |
170 | } | |
171 | ||
ebaaaf5e JD |
172 | # Test a snapshot using a custom name for the output destination. |
173 | function test_ust_custom_name() | |
174 | { | |
175 | local out | |
176 | local name="asnapshotname" | |
177 | ||
178 | diag "Test UST snapshot streaming with custom name" | |
179 | create_lttng_session_no_output $SESSION_NAME | |
180 | enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME | |
181 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
182 | start_lttng_tracing $SESSION_NAME | |
8c93562f DG |
183 | |
184 | start_trace_app | |
185 | ||
ebaaaf5e JD |
186 | snapshot_add_output $SESSION_NAME "net://localhost" $name |
187 | lttng_snapshot_record $SESSION_NAME | |
188 | stop_lttng_tracing $SESSION_NAME | |
189 | destroy_lttng_session $SESSION_NAME | |
190 | ||
191 | if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev/null; then | |
192 | ok 0 "Custom name snapshot exists" | |
193 | # Validate test | |
194 | validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-* | |
195 | out=$? | |
196 | else | |
197 | fail "No custom name snapshot found" | |
198 | out=1 | |
199 | fi | |
200 | ||
5dca3876 | 201 | stop_trace_app |
ebaaaf5e JD |
202 | |
203 | return $out | |
204 | } | |
205 | ||
206 | plan_tests $NUM_TESTS | |
207 | ||
208 | print_test_banner "$TEST_DESC" | |
209 | ||
210 | if [ "$(id -u)" == "0" ]; then | |
211 | isroot=1 | |
212 | else | |
213 | isroot=0 | |
214 | fi | |
215 | ||
216 | start_lttng_relayd "-o $TRACE_PATH" | |
217 | start_lttng_sessiond | |
218 | ||
847b88a9 | 219 | tests=( test_ust_default_name_with_del test_ust_default_name test_ust_custom_name test_ust_default_name_custom_uri ) |
ebaaaf5e JD |
220 | |
221 | for fct_test in ${tests[@]}; | |
222 | do | |
223 | SESSION_NAME=$(randstring 16 0) | |
224 | ${fct_test} | |
225 | if [ $? -eq 0 ]; then | |
226 | # Only delete if successful | |
227 | rm -rf $TRACE_PATH | |
228 | else | |
229 | break | |
230 | fi | |
231 | done | |
232 | ||
233 | stop_lttng_sessiond | |
234 | stop_lttng_relayd |