Clean-up: consumer.hpp: coding style indentation fix
[lttng-tools.git] / tests / regression / ust / periodical-metadata-flush / test_periodical_metadata_flush
... / ...
CommitLineData
1#!/bin/bash
2#
3# Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
4#
5# SPDX-License-Identifier: LGPL-2.1-only
6
7TEST_DESC="UST tracer - Tracing with per UID buffers and periodical flush"
8
9CURDIR=$(dirname "$0")/
10TESTDIR="$CURDIR/../../.."
11NR_ITER=100
12NR_USEC_WAIT=100000
13TESTAPP_PATH="$TESTDIR/utils/testapp"
14TESTAPP_NAME="gen-ust-events"
15TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
16SESSION_NAME="periodical-flush"
17EVENT_NAME="tp:tptest"
18NUM_TESTS=38
19APP_TMP_FILE=$(mktemp -u -t tmp.test_periodical_metadata_flush_ust_app_tmp_file.XXXXXX)
20APP_PIDS=()
21
22# shellcheck source-path=SCRIPTDIR/../../../
23source "$TESTDIR/utils/utils.sh"
24
25if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
27fi
28
29# MUST set TESTDIR before calling those functions
30
31function enable_channel_per_uid()
32{
33 local sess_name=$1
34 local channel_name=$2
35
36 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" --switch-timer 100000 >/dev/null 2>&1
37 ok $? "Enable channel $channel_name per UID for session $sess_name"
38}
39
40function enable_channel_per_pid()
41{
42 local sess_name=$1
43 local channel_name=$2
44
45 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-pid -u "$channel_name" -s "$sess_name" --switch-timer 100000 >/dev/null 2>&1
46 ok $? "Enable channel $channel_name per UID for session $sess_name"
47}
48
49function enable_metadata_per_uid()
50{
51 local sess_name=$1
52 local channel_name="metadata"
53
54 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" --switch-timer 200000 2>&1
55 ok $? "Enable channel $channel_name per UID for session $sess_name"
56}
57
58function enable_metadata_per_pid()
59{
60 local sess_name=$1
61 local channel_name="metadata"
62
63 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-pid -u "$channel_name" -s "$sess_name" --switch-timer 200000 >/dev/null 2>&1
64 ok $? "Enable channel $channel_name per PID for session $sess_name"
65}
66
67function validate_trace()
68{
69 local out
70
71 out=$("$BABELTRACE_BIN" "$TRACE_PATH" | grep -c $EVENT_NAME)
72 if [ "$out" -eq 0 ]; then
73 fail "Trace validation"
74 diag "No event(s) found. We are supposed to have at least one."
75 out=1
76 else
77 pass "Trace validation"
78 diag "Found $out event(s). Coherent."
79 out=0
80 fi
81
82 return $out
83}
84
85function check_app_tmp_file()
86{
87 # Wait for the application file to appear indicating that at least one
88 # tracepoint has been fired.
89 while [ ! -f "$APP_TMP_FILE" ]; do
90 sleep 0.5
91 done
92 diag "Removing test app temporary file $APP_TMP_FILE"
93 rm -f "$APP_TMP_FILE"
94}
95
96function start_trace_app()
97{
98 # Start application with a temporary file.
99 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event "$APP_TMP_FILE" &
100 ret=$?
101 APP_PIDS+=(${!})
102 ok $ret "Start application to trace"
103}
104
105function start_check_trace_app()
106{
107 start_trace_app
108 check_app_tmp_file
109}
110
111
112function wait_trace_apps()
113{
114 wait "${APP_PIDS[@]}" 2> /dev/null
115 APP_PIDS=()
116}
117
118test_after_app_pid() {
119 local out
120
121 APP_PIDS=()
122
123 diag "Start application AFTER tracing is started"
124
125 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
126 enable_metadata_per_pid $SESSION_NAME
127 enable_channel_per_pid $SESSION_NAME "channel0"
128 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
129 start_lttng_tracing_ok $SESSION_NAME
130
131 # Start application after tracing
132 start_check_trace_app
133 # After this point we are sure that at least one event has been hit.
134
135 # Make sure the application does not generate any more data,
136 # thus ensuring that we are not flushing a packet concurrently
137 # with validate_trace.
138 kill -s SIGSTOP "${APP_PIDS[@]}"
139
140 # Give time to the consumer to write inflight data.
141 sleep 2
142
143 # shellcheck disable=SC2119
144 validate_trace
145 out=$?
146
147 kill -s SIGKILL "${APP_PIDS[@]}"
148 wait "${APP_PIDS[@]}" 2>/dev/null
149 stop_lttng_tracing_ok $SESSION_NAME
150 destroy_lttng_session_ok $SESSION_NAME
151
152 wait_trace_apps
153
154 return $out
155}
156
157test_before_app_pid() {
158 local out
159
160 APP_PIDS=()
161
162 diag "Start application BEFORE tracing is started"
163
164 start_trace_app
165
166 # Start application before tracing
167 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
168 enable_metadata_per_pid $SESSION_NAME
169 enable_channel_per_pid $SESSION_NAME "channel0"
170 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
171 start_lttng_tracing_ok $SESSION_NAME
172
173 check_app_tmp_file
174 # Let the application at least perform a flush!
175 sleep 2
176
177 # Make sure the application does not generate any more data,
178 # thus ensuring that we are not flushing a packet concurrently
179 # with validate_trace.
180 kill -s SIGSTOP "${APP_PIDS[@]}"
181
182 # Give time to the consumer to write inflight data.
183 sleep 2
184
185 # shellcheck disable=SC2119
186 validate_trace
187 out=$?
188
189 kill -s SIGKILL "${APP_PIDS[@]}"
190 wait "${APP_PIDS[@]}" 2>/dev/null
191
192 stop_lttng_tracing_ok $SESSION_NAME
193 destroy_lttng_session_ok $SESSION_NAME
194
195 wait_trace_apps
196
197 return $out
198}
199
200test_after_app_uid() {
201 local out
202
203 APP_PIDS=()
204
205 diag "Start application AFTER tracing is started"
206
207 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
208 enable_metadata_per_uid $SESSION_NAME
209 enable_channel_per_uid $SESSION_NAME "channel0"
210 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
211 start_lttng_tracing_ok $SESSION_NAME
212
213 # Start application after tracing
214 start_check_trace_app
215 # After this point we are sure that at least one event has been hit.
216
217 # Make sure the application does not generate any more data,
218 # thus ensuring that we are not flushing a packet concurrently
219 # with validate_trace.
220 kill -s SIGSTOP "${APP_PIDS[@]}"
221
222 # Give time to the consumer to write inflight data.
223 sleep 2
224
225 # shellcheck disable=SC2119
226 validate_trace
227 out=$?
228
229 kill -s SIGKILL "${APP_PIDS[@]}"
230 wait "${APP_PIDS[@]}"
231 stop_lttng_tracing_ok $SESSION_NAME
232 destroy_lttng_session_ok $SESSION_NAME
233
234 wait_trace_apps
235
236 return $out
237}
238
239test_before_app_uid() {
240 local out
241
242 APP_PIDS=()
243
244 diag "Start application BEFORE tracing is started"
245
246 # Start application before tracing
247 start_trace_app
248
249 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
250 enable_metadata_per_uid $SESSION_NAME
251 enable_channel_per_uid $SESSION_NAME "channel0"
252 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
253 start_lttng_tracing_ok $SESSION_NAME
254
255 check_app_tmp_file
256 # Let the application at least perform a flush!
257 sleep 2
258
259 # Make sure the application does not generate any more data,
260 # thus ensuring that we are not flushing a packet concurrently
261 # with validate_trace.
262 kill -s SIGSTOP "${APP_PIDS[@]}"
263
264 # Give time to the consumer to write inflight data.
265 sleep 2
266
267 # shellcheck disable=SC2119
268 validate_trace
269 out=$?
270
271 kill -s SIGKILL "${APP_PIDS[@]}"
272 wait "${APP_PIDS[@]}"
273 stop_lttng_tracing_ok $SESSION_NAME
274 destroy_lttng_session_ok $SESSION_NAME
275
276 wait_trace_apps
277
278 return $out
279}
280
281# MUST set TESTDIR before calling those functions
282plan_tests $NUM_TESTS
283
284print_test_banner "$TEST_DESC"
285bail_out_if_no_babeltrace
286
287TESTS=(
288 "test_before_app_uid"
289 "test_after_app_uid"
290 "test_before_app_pid"
291 "test_after_app_pid"
292)
293
294TEST_COUNT=${#TESTS[@]}
295i=0
296
297# shellcheck disable=SC2119
298start_lttng_sessiond
299
300while [ $i -lt "$TEST_COUNT" ]; do
301 TRACE_PATH=$(mktemp -d -t tmp.test_periodical_metadata_flush_ust_trace_path.XXXXXX)
302 ${TESTS[$i]}
303 rm -rf "$TRACE_PATH"
304 (( "i++" ))
305done
306
307# shellcheck disable=SC2119
308stop_lttng_sessiond
This page took 0.024323 seconds and 5 git commands to generate.