Tests: Fix: Use '.logfile' instead of '.log' for test app output
[lttng-tools.git] / tests / regression / ust / periodical-metadata-flush / test_periodical_metadata_flush
CommitLineData
a788a3ed
DG
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
a788a3ed 4#
9d16b343
MJ
5# SPDX-License-Identifier: LGPL-2.1-only
6
a788a3ed
DG
7TEST_DESC="UST tracer - Tracing with per UID buffers and periodical flush"
8
c1896e2d
KS
9CURDIR=$(dirname "$0")/
10TESTDIR="$CURDIR/../../.."
a788a3ed 11NR_ITER=100
b688191f
CB
12NR_USEC_WAIT=100000
13TESTAPP_PATH="$TESTDIR/utils/testapp"
14TESTAPP_NAME="gen-ust-events"
15TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
a788a3ed 16SESSION_NAME="periodical-flush"
b688191f 17EVENT_NAME="tp:tptest"
a788a3ed 18NUM_TESTS=38
8d5a3312 19APP_TMP_FILE=$(mktemp -u -t tmp.test_periodical_metadata_flush_ust_app_tmp_file.XXXXXX)
c1896e2d 20APP_PIDS=()
a788a3ed 21
c1896e2d
KS
22# shellcheck source-path=SCRIPTDIR/../../../
23source "$TESTDIR/utils/utils.sh"
a788a3ed 24
b688191f
CB
25if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
a788a3ed
DG
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
c1896e2d 36 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" --switch-timer 100000 >/dev/null 2>&1
dd770530
DG
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
c1896e2d 45 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-pid -u "$channel_name" -s "$sess_name" --switch-timer 100000 >/dev/null 2>&1
a788a3ed
DG
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
c1896e2d 54 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-uid -u "$channel_name" -s "$sess_name" --switch-timer 200000 2>&1
a788a3ed
DG
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
c1896e2d 63 "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-channel --buffers-pid -u "$channel_name" -s "$sess_name" --switch-timer 200000 >/dev/null 2>&1
a788a3ed
DG
64 ok $? "Enable channel $channel_name per PID for session $sess_name"
65}
66
dd770530
DG
67function validate_trace()
68{
69 local out
70
7312af6f 71 out=$("_run_babeltrace_cmd" "$TRACE_PATH" | grep -c $EVENT_NAME)
c1896e2d 72 if [ "$out" -eq 0 ]; then
dd770530
DG
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
8c93562f
DG
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"
c1896e2d 93 rm -f "$APP_TMP_FILE"
8c93562f
DG
94}
95
96function start_trace_app()
97{
98 # Start application with a temporary file.
c1896e2d 99 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event "$APP_TMP_FILE" &
c7613334 100 ret=$?
c1896e2d 101 APP_PIDS+=(${!})
c7613334 102 ok $ret "Start application to trace"
8c93562f
DG
103}
104
105function start_check_trace_app()
106{
107 start_trace_app
108 check_app_tmp_file
109}
110
c7613334
MD
111
112function wait_trace_apps()
113{
c1896e2d
KS
114 wait "${APP_PIDS[@]}" 2> /dev/null
115 APP_PIDS=()
c7613334
MD
116}
117
a788a3ed
DG
118test_after_app_pid() {
119 local out
120
c1896e2d 121 APP_PIDS=()
c7613334 122
a788a3ed
DG
123 diag "Start application AFTER tracing is started"
124
c1896e2d 125 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
a788a3ed 126 enable_metadata_per_pid $SESSION_NAME
dd770530 127 enable_channel_per_pid $SESSION_NAME "channel0"
c4926bb5 128 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 129 start_lttng_tracing_ok $SESSION_NAME
a788a3ed 130
a055228d 131 # Start application after tracing
8c93562f
DG
132 start_check_trace_app
133 # After this point we are sure that at least one event has been hit.
a055228d
MD
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.
c1896e2d 138 kill -s SIGSTOP "${APP_PIDS[@]}"
8a251cb8
DG
139
140 # Give time to the consumer to write inflight data.
a055228d
MD
141 sleep 2
142
c1896e2d 143 # shellcheck disable=SC2119
dd770530
DG
144 validate_trace
145 out=$?
146
c1896e2d
KS
147 kill -s SIGKILL "${APP_PIDS[@]}"
148 wait "${APP_PIDS[@]}" 2>/dev/null
96340a01 149 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 150 destroy_lttng_session_ok $SESSION_NAME
a788a3ed 151
c7613334 152 wait_trace_apps
8a251cb8 153
dd770530 154 return $out
a788a3ed
DG
155}
156
157test_before_app_pid() {
158 local out
159
c1896e2d 160 APP_PIDS=()
c7613334 161
a788a3ed
DG
162 diag "Start application BEFORE tracing is started"
163
8c93562f 164 start_trace_app
a788a3ed 165
a055228d 166 # Start application before tracing
c1896e2d 167 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
a788a3ed 168 enable_metadata_per_pid $SESSION_NAME
dd770530 169 enable_channel_per_pid $SESSION_NAME "channel0"
c4926bb5 170 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 171 start_lttng_tracing_ok $SESSION_NAME
a788a3ed 172
8c93562f
DG
173 check_app_tmp_file
174 # Let the application at least perform a flush!
a788a3ed 175 sleep 2
a055228d
MD
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.
c1896e2d 180 kill -s SIGSTOP "${APP_PIDS[@]}"
8a251cb8
DG
181
182 # Give time to the consumer to write inflight data.
a055228d
MD
183 sleep 2
184
c1896e2d 185 # shellcheck disable=SC2119
dd770530
DG
186 validate_trace
187 out=$?
a788a3ed 188
c1896e2d
KS
189 kill -s SIGKILL "${APP_PIDS[@]}"
190 wait "${APP_PIDS[@]}" 2>/dev/null
c7613334 191
96340a01 192 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 193 destroy_lttng_session_ok $SESSION_NAME
a788a3ed 194
c7613334 195 wait_trace_apps
a788a3ed
DG
196
197 return $out
198}
199
200test_after_app_uid() {
201 local out
202
c1896e2d 203 APP_PIDS=()
c7613334 204
a788a3ed
DG
205 diag "Start application AFTER tracing is started"
206
c1896e2d 207 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
a788a3ed
DG
208 enable_metadata_per_uid $SESSION_NAME
209 enable_channel_per_uid $SESSION_NAME "channel0"
c4926bb5 210 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 211 start_lttng_tracing_ok $SESSION_NAME
a788a3ed 212
a055228d 213 # Start application after tracing
8c93562f
DG
214 start_check_trace_app
215 # After this point we are sure that at least one event has been hit.
a055228d
MD
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.
c1896e2d 220 kill -s SIGSTOP "${APP_PIDS[@]}"
8a251cb8
DG
221
222 # Give time to the consumer to write inflight data.
a055228d
MD
223 sleep 2
224
c1896e2d 225 # shellcheck disable=SC2119
dd770530
DG
226 validate_trace
227 out=$?
228
c1896e2d
KS
229 kill -s SIGKILL "${APP_PIDS[@]}"
230 wait "${APP_PIDS[@]}"
96340a01 231 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 232 destroy_lttng_session_ok $SESSION_NAME
a788a3ed 233
c7613334 234 wait_trace_apps
8a251cb8 235
dd770530 236 return $out
a788a3ed
DG
237}
238
239test_before_app_uid() {
240 local out
241
c1896e2d 242 APP_PIDS=()
c7613334 243
a788a3ed
DG
244 diag "Start application BEFORE tracing is started"
245
8a251cb8 246 # Start application before tracing
8c93562f 247 start_trace_app
a788a3ed 248
c1896e2d 249 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH"
a788a3ed
DG
250 enable_metadata_per_uid $SESSION_NAME
251 enable_channel_per_uid $SESSION_NAME "channel0"
c4926bb5 252 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 253 start_lttng_tracing_ok $SESSION_NAME
a788a3ed 254
8c93562f
DG
255 check_app_tmp_file
256 # Let the application at least perform a flush!
a788a3ed 257 sleep 2
a055228d
MD
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.
c1896e2d 262 kill -s SIGSTOP "${APP_PIDS[@]}"
8a251cb8
DG
263
264 # Give time to the consumer to write inflight data.
a055228d
MD
265 sleep 2
266
c1896e2d 267 # shellcheck disable=SC2119
dd770530
DG
268 validate_trace
269 out=$?
a788a3ed 270
c1896e2d
KS
271 kill -s SIGKILL "${APP_PIDS[@]}"
272 wait "${APP_PIDS[@]}"
96340a01 273 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 274 destroy_lttng_session_ok $SESSION_NAME
a788a3ed 275
c7613334 276 wait_trace_apps
a788a3ed
DG
277
278 return $out
279}
280
281# MUST set TESTDIR before calling those functions
282plan_tests $NUM_TESTS
283
284print_test_banner "$TEST_DESC"
c125de8f 285bail_out_if_no_babeltrace
a788a3ed
DG
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
c1896e2d 297# shellcheck disable=SC2119
a788a3ed
DG
298start_lttng_sessiond
299
c1896e2d 300while [ $i -lt "$TEST_COUNT" ]; do
8d5a3312 301 TRACE_PATH=$(mktemp -d -t tmp.test_periodical_metadata_flush_ust_trace_path.XXXXXX)
a788a3ed 302 ${TESTS[$i]}
c1896e2d
KS
303 rm -rf "$TRACE_PATH"
304 (( "i++" ))
a788a3ed
DG
305done
306
c1896e2d 307# shellcheck disable=SC2119
a788a3ed 308stop_lttng_sessiond
This page took 0.082348 seconds and 5 git commands to generate.