Test fix: use temp file sync. of test app
[lttng-tools.git] / tests / regression / tools / snapshots / test_ust_streaming
... / ...
CommitLineData
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
17TEST_DESC="Streaming - Snapshot UST tracing"
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21EVENT_NAME="tp:tptest"
22PID_RELAYD=0
23SESSION_NAME=""
24CHANNEL_NAME="chan1"
25BIN_NAME="gen-nevents"
26TESTAPP_PATH="$TESTDIR/utils/testapp"
27TESTAPP_NAME="gen-ust-events"
28TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
29NR_ITER=2000000
30NR_USEC_WAIT=100
31
32TRACE_PATH=$(mktemp -d)
33
34NUM_TESTS=49
35
36source $TESTDIR/utils/utils.sh
37
38if [ ! -x "$TESTAPP_BIN" ]; then
39 BAIL_OUT "No UST events binary detected."
40fi
41
42function 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
57# Start trace application and return once one event has been hit.
58function 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
75# Test a snapshot using a default name for the output destination.
76function test_ust_default_name_with_del()
77{
78 diag "Test UST snapshot streaming with default name with delete output"
79 create_lttng_session_no_output $SESSION_NAME
80 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
81 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
82 start_lttng_tracing $SESSION_NAME
83
84 start_trace_app
85
86 snapshot_add_output $SESSION_NAME "net://localhost"
87 lttng_snapshot_record $SESSION_NAME
88
89 # Validate test
90 echo $TRACE_PATH/$HOSTNAME/snapshot-1
91 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
92 if [ $? -ne 0 ]; then
93 return $?
94 fi
95
96 lttng_snapshot_del_output $SESSION_NAME 1
97 snapshot_add_output $SESSION_NAME "net://localhost"
98 lttng_snapshot_record $SESSION_NAME
99
100 # Validate test with the next ID since a del output was done prior.
101 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2*
102 if [ $? -ne 0 ]; then
103 return $?
104 fi
105
106 stop_lttng_tracing $SESSION_NAME
107 destroy_lttng_session $SESSION_NAME
108
109 diag "Killing $TESTAPP_NAME"
110 PID_APP=`pidof $TESTAPP_NAME`
111 kill $PID_APP >/dev/null 2>&1
112
113 return 0
114}
115
116# Test a snapshot using a default name for the output destination.
117function test_ust_default_name()
118{
119 diag "Test UST snapshot streaming with default name"
120 create_lttng_session_no_output $SESSION_NAME
121 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
122 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
123 start_lttng_tracing $SESSION_NAME
124
125 start_trace_app
126
127 snapshot_add_output $SESSION_NAME "net://localhost"
128 lttng_snapshot_record $SESSION_NAME
129 stop_lttng_tracing $SESSION_NAME
130 destroy_lttng_session $SESSION_NAME
131 # Validate test
132 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
133 out=$?
134
135 diag "Killing $TESTAPP_NAME"
136 PID_APP=`pidof $TESTAPP_NAME`
137 kill $PID_APP >/dev/null 2>&1
138
139 return $out
140}
141
142function test_ust_default_name_custom_uri()
143{
144 diag "Test UST snapshot streaming with default name with custom URL"
145 create_lttng_session_no_output $SESSION_NAME
146 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
147 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
148 start_lttng_tracing $SESSION_NAME
149
150 start_trace_app
151
152 snapshot_add_output $SESSION_NAME "-C tcp://localhost:5342 -D tcp://localhost:5343"
153 lttng_snapshot_record $SESSION_NAME
154 stop_lttng_tracing $SESSION_NAME
155 destroy_lttng_session $SESSION_NAME
156 # Validate test
157 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
158 out=$?
159
160 diag "Killing $TESTAPP_NAME"
161 PID_APP=`pidof $TESTAPP_NAME`
162 kill $PID_APP >/dev/null 2>&1
163
164 return $out
165}
166
167# Test a snapshot using a custom name for the output destination.
168function test_ust_custom_name()
169{
170 local out
171 local name="asnapshotname"
172
173 diag "Test UST snapshot streaming with custom name"
174 create_lttng_session_no_output $SESSION_NAME
175 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
176 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
177 start_lttng_tracing $SESSION_NAME
178
179 start_trace_app
180
181 snapshot_add_output $SESSION_NAME "net://localhost" $name
182 lttng_snapshot_record $SESSION_NAME
183 stop_lttng_tracing $SESSION_NAME
184 destroy_lttng_session $SESSION_NAME
185
186 if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev/null; then
187 ok 0 "Custom name snapshot exists"
188 # Validate test
189 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-*
190 out=$?
191 else
192 fail "No custom name snapshot found"
193 out=1
194 fi
195
196 diag "Killing $TESTAPP_NAME"
197 PID_APP=`pidof $TESTAPP_NAME`
198 kill $PID_APP >/dev/null 2>&1
199
200 return $out
201}
202
203plan_tests $NUM_TESTS
204
205print_test_banner "$TEST_DESC"
206
207if [ "$(id -u)" == "0" ]; then
208 isroot=1
209else
210 isroot=0
211fi
212
213start_lttng_relayd "-o $TRACE_PATH"
214start_lttng_sessiond
215
216tests=( test_ust_default_name_with_del test_ust_default_name test_ust_custom_name test_ust_default_name_custom_uri )
217
218for fct_test in ${tests[@]};
219do
220 SESSION_NAME=$(randstring 16 0)
221 ${fct_test}
222 if [ $? -eq 0 ]; then
223 # Only delete if successful
224 rm -rf $TRACE_PATH
225 else
226 break
227 fi
228done
229
230stop_lttng_sessiond
231stop_lttng_relayd
This page took 0.02286 seconds and 4 git commands to generate.