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