18d8a46c1b7ea213fe8299baabdffaf3c48b1b72
[lttng-tools.git] / tests / regression / ust / periodical-metadata-flush / test_periodical_metadata_flush
1 #!/bin/bash
2 #
3 # Copyright (C) - 2012 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="UST tracer - Tracing with per UID buffers and periodical flush"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 NR_ITER=100
22 NR_USEC_WAIT=100000
23 TESTAPP_PATH="$TESTDIR/utils/testapp"
24 TESTAPP_NAME="gen-ust-events"
25 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26 SESSION_NAME="periodical-flush"
27 EVENT_NAME="tp:tptest"
28 BIN_NAME="gen-nevents"
29 NUM_TESTS=38
30
31 source $TESTDIR/utils/utils.sh
32
33 if [ ! -x "$TESTAPP_BIN" ]; then
34 BAIL_OUT "No UST events binary detected."
35 fi
36
37 # MUST set TESTDIR before calling those functions
38
39 function enable_channel_per_uid()
40 {
41 local sess_name=$1
42 local channel_name=$2
43
44 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name >/dev/null 2>&1
45 ok $? "Enable channel $channel_name per UID for session $sess_name"
46 }
47
48 function enable_metadata_per_uid()
49 {
50 local sess_name=$1
51 local channel_name="metadata"
52
53 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --switch-timer 200000 >/dev/null 2>&1
54 ok $? "Enable channel $channel_name per UID for session $sess_name"
55 }
56
57 function enable_metadata_per_pid()
58 {
59 local sess_name=$1
60 local channel_name="metadata"
61
62 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name --switch-timer 200000 >/dev/null 2>&1
63 ok $? "Enable channel $channel_name per PID for session $sess_name"
64 }
65
66 function wait_apps
67 {
68 diag "Waiting for applications to end..."
69 while [ -n "$(pidof $TESTAPP_NAME)" ]; do
70 sleep 1
71 done
72 }
73
74 test_after_app_pid() {
75 local out
76
77 diag "Start application AFTER tracing is started"
78
79 # BEFORE application is spawned
80 create_lttng_session $SESSION_NAME $TRACE_PATH
81 enable_metadata_per_pid $SESSION_NAME
82 enable_ust_lttng_channel $SESSION_NAME "channel0"
83 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
84 start_lttng_tracing $SESSION_NAME
85
86 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
87 ok $? "Start application to trace"
88
89 stop_lttng_tracing $SESSION_NAME
90 destroy_lttng_session $SESSION_NAME
91
92 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
93
94 return $?
95 }
96
97 test_before_app_pid() {
98 local out
99
100 diag "Start application BEFORE tracing is started"
101
102 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
103 ok $? "Start application to trace"
104
105 # BEFORE application is spawned
106 create_lttng_session $SESSION_NAME $TRACE_PATH
107 enable_metadata_per_pid $SESSION_NAME
108 enable_ust_lttng_channel $SESSION_NAME "channel0"
109 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
110 start_lttng_tracing $SESSION_NAME
111
112 # At least hit one event
113 sleep 2
114
115 stop_lttng_tracing $SESSION_NAME
116 destroy_lttng_session $SESSION_NAME
117
118 out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
119 if [ $out -eq 0 ]; then
120 fail "Trace validation"
121 diag "No event(s) found. We are supposed to have at least one."
122 out=1
123 else
124 pass "Trace validation"
125 diag "Found $out event(s). Coherent."
126 out=0
127 fi
128
129 wait_apps
130
131 return $out
132 }
133
134 test_after_app_uid() {
135 local out
136
137 diag "Start application AFTER tracing is started"
138
139 # BEFORE application is spawned
140 create_lttng_session $SESSION_NAME $TRACE_PATH
141 enable_metadata_per_uid $SESSION_NAME
142 enable_channel_per_uid $SESSION_NAME "channel0"
143 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
144 start_lttng_tracing $SESSION_NAME
145
146 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
147 ok $? "Start application to trace"
148
149 stop_lttng_tracing $SESSION_NAME
150 destroy_lttng_session $SESSION_NAME
151
152 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
153
154 return $?
155 }
156
157 test_before_app_uid() {
158 local out
159
160 diag "Start application BEFORE tracing is started"
161
162 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
163 ok $? "Start application to trace"
164
165 # BEFORE application is spawned
166 create_lttng_session $SESSION_NAME $TRACE_PATH
167 enable_metadata_per_uid $SESSION_NAME
168 enable_channel_per_uid $SESSION_NAME "channel0"
169 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
170 start_lttng_tracing $SESSION_NAME
171
172 # At least hit one event
173 sleep 2
174
175 stop_lttng_tracing $SESSION_NAME
176 destroy_lttng_session $SESSION_NAME
177
178 out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
179 if [ $out -eq 0 ]; then
180 fail "Trace validation"
181 diag "No event(s) found. We are supposed to have at least one."
182 out=1
183 else
184 pass "Trace validation"
185 diag "Found $out event(s). Coherent."
186 out=0
187 fi
188
189 wait_apps
190
191 return $out
192 }
193
194 # MUST set TESTDIR before calling those functions
195 plan_tests $NUM_TESTS
196
197 print_test_banner "$TEST_DESC"
198
199 TESTS=(
200 "test_before_app_uid"
201 "test_after_app_uid"
202 "test_before_app_pid"
203 "test_after_app_pid"
204 )
205
206 TEST_COUNT=${#TESTS[@]}
207 i=0
208
209 start_lttng_sessiond
210
211 while [ $i -lt $TEST_COUNT ]; do
212 TRACE_PATH=$(mktemp -d)
213 ${TESTS[$i]}
214 #rm -rf $TRACE_PATH
215 let "i++"
216 done
217
218 stop_lttng_sessiond
This page took 0.050269 seconds and 4 git commands to generate.