Fix: consumer: 64-bit index for relayd rather than 32-bit (v2)
[lttng-tools.git] / tests / regression / ust / periodical-metadata-flush / test_periodical_metadata_flush
CommitLineData
a788a3ed
DG
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
17TEST_DESC="UST tracer - Tracing with per UID buffers and periodical flush"
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21NR_ITER=100
b688191f
CB
22NR_USEC_WAIT=100000
23TESTAPP_PATH="$TESTDIR/utils/testapp"
24TESTAPP_NAME="gen-ust-events"
25TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
a788a3ed 26SESSION_NAME="periodical-flush"
b688191f 27EVENT_NAME="tp:tptest"
a788a3ed
DG
28BIN_NAME="gen-nevents"
29NUM_TESTS=38
30
31source $TESTDIR/utils/utils.sh
32
b688191f
CB
33if [ ! -x "$TESTAPP_BIN" ]; then
34 BAIL_OUT "No UST events binary detected."
a788a3ed
DG
35fi
36
37# MUST set TESTDIR before calling those functions
38
39function 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
48function 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
57function 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
66function wait_apps
67{
68 diag "Waiting for applications to end..."
b688191f 69 while [ -n "$(pidof $TESTAPP_NAME)" ]; do
a788a3ed
DG
70 sleep 1
71 done
72}
73
74test_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
b688191f 86 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
a788a3ed
DG
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
97test_before_app_pid() {
98 local out
99
100 diag "Start application BEFORE tracing is started"
101
b688191f 102 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
a788a3ed
DG
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
134test_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
b688191f 146 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
a788a3ed
DG
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
157test_before_app_uid() {
158 local out
159
160 diag "Start application BEFORE tracing is started"
161
b688191f 162 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
a788a3ed
DG
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
195plan_tests $NUM_TESTS
196
197print_test_banner "$TEST_DESC"
198
199TESTS=(
200 "test_before_app_uid"
201 "test_after_app_uid"
202 "test_before_app_pid"
203 "test_after_app_pid"
204)
205
206TEST_COUNT=${#TESTS[@]}
207i=0
208
209start_lttng_sessiond
210
211while [ $i -lt $TEST_COUNT ]; do
212 TRACE_PATH=$(mktemp -d)
213 ${TESTS[$i]}
214 #rm -rf $TRACE_PATH
215 let "i++"
216done
217
218stop_lttng_sessiond
This page took 0.046461 seconds and 4 git commands to generate.