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