Tests: Fix: Use '.logfile' instead of '.log' for test app output
[lttng-tools.git] / tests / regression / tools / regen-metadata / test_ust
CommitLineData
801236b0
JD
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
801236b0 4#
9d16b343
MJ
5# SPDX-License-Identifier: LGPL-2.1-only
6
801236b0
JD
7TEST_DESC="Streaming - User space tracing"
8
9CURDIR=$(dirname $0)/
10TESTDIR=$CURDIR/../../..
11NR_ITER=1
12NR_USEC_WAIT=0
13TESTAPP_PATH="$TESTDIR/utils/testapp"
14TESTAPP_NAME="gen-ust-events"
15TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
16SESSION_NAME="stream"
17EVENT_NAME="tp:tptest"
801236b0 18
8d5a3312 19TRACE_PATH=$(mktemp -d -t tmp.test_regen_metadata_ust_trace_path.XXXXXX)
801236b0 20
dc97de74 21NUM_TESTS=47
801236b0
JD
22
23source $TESTDIR/utils/utils.sh
24
25if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
27fi
28
801236b0
JD
29function enable_channel_per_pid()
30{
31 sess_name=$1
32 channel_name=$2
33
34 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name >/dev/null 2>&1
35 ok $? "Enable channel $channel_name per PID for session $sess_name"
36}
37
38# MUST set TESTDIR before calling those functions
39
40function test_ust_streaming ()
41{
8d5a3312
MJ
42 local file_sync_after_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
43 local file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
dbbc5b0a 44 local metadata_path
801236b0
JD
45
46 diag "Test UST streaming with metadata regeneration"
f0d43d3d 47 create_lttng_session_uri $SESSION_NAME net://localhost
801236b0
JD
48 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
49
6c4a91d6
MD
50 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
51 --sync-after-first-event ${file_sync_after_first} \
52 --sync-before-last-event ${file_sync_before_last} >/dev/null 2>&1 &
801236b0
JD
53
54 start_lttng_tracing_ok $SESSION_NAME
55
56 touch ${file_sync_before_last}
57
58 # Wait for the applications started in background
59 wait
801236b0 60
dbbc5b0a 61 # Expect a valid trace
801236b0 62 stop_lttng_tracing_ok $SESSION_NAME
dbbc5b0a
JR
63 validate_trace $EVENT_NAME "$TRACE_PATH/$HOSTNAME/$SESSION_NAME"*
64
65 # Find the metadata file
fc2dd19e 66 metadata_path=$(find "$TRACE_PATH/$HOSTNAME/$SESSION_NAME"* -name "metadata")
dbbc5b0a
JR
67
68 # Empty the metadata file
69 echo -n > "$metadata_path"
70
71 start_lttng_tracing_ok $SESSION_NAME
72 regenerate_metadata_ok $SESSION_NAME
73 stop_lttng_tracing_ok $SESSION_NAME
74
75 # Metadata file must have been regenerated
801236b0 76 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
dbbc5b0a
JR
77 destroy_lttng_session_ok $SESSION_NAME
78
79 rm -rf "$TRACE_PATH"
801236b0
JD
80 rm -f ${file_sync_after_first}
81 rm -f ${file_sync_before_last}
82}
83
84function test_ust_local ()
85{
8d5a3312
MJ
86 local file_sync_after_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
87 local file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
dbbc5b0a 88 local metadata_path
801236b0
JD
89
90 diag "Test UST local with metadata regeneration"
91 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
92 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
93
6c4a91d6
MD
94 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
95 --sync-after-first-event ${file_sync_after_first} \
96 --sync-before-last-event ${file_sync_before_last} > /dev/null 2>&1 &
801236b0
JD
97
98 start_lttng_tracing_ok $SESSION_NAME
99
100 touch ${file_sync_before_last}
101
102 # Wait for the applications started in background
103 wait
801236b0 104
dbbc5b0a 105 # Expect a valid trace
801236b0 106 stop_lttng_tracing_ok $SESSION_NAME
dbbc5b0a
JR
107 validate_trace $EVENT_NAME "$TRACE_PATH"
108
109 # Find the metadata file
fc2dd19e 110 metadata_path=$(find "$TRACE_PATH"* -name "metadata")
dbbc5b0a
JR
111
112 # Empty the metadata file
113 echo -n > "$metadata_path"
114
115 start_lttng_tracing_ok $SESSION_NAME
116 regenerate_metadata_ok $SESSION_NAME
117 stop_lttng_tracing_ok $SESSION_NAME
118
119 # Metadata file must have been regenerated
801236b0 120 validate_trace $EVENT_NAME $TRACE_PATH
dbbc5b0a
JR
121 destroy_lttng_session_ok $SESSION_NAME
122
123 rm -rf "$TRACE_PATH"
801236b0
JD
124 rm -f ${file_sync_after_first}
125 rm -f ${file_sync_before_last}
126}
127
128function test_ust_pid ()
129{
8d5a3312
MJ
130 local file_sync_after_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
131 local file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
801236b0
JD
132
133 diag "Test UST per-pid with metadata regeneration (expect failure)"
134 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
135 enable_channel_per_pid $SESSION_NAME "channel0"
136 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
137
6c4a91d6
MD
138 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
139 --sync-after-first-event ${file_sync_after_first} \
140 --sync-before-last-event ${file_sync_before_last} >/dev/null 2>&1 &
801236b0
JD
141
142 start_lttng_tracing_ok $SESSION_NAME
143
144 touch ${file_sync_before_last}
145
146 # Wait for the applications started in background
147 wait
eded6438 148 regenerate_metadata_fail $SESSION_NAME
801236b0
JD
149
150 stop_lttng_tracing_ok $SESSION_NAME
151 destroy_lttng_session_ok $SESSION_NAME
152 # Validate test
153 validate_trace $EVENT_NAME $TRACE_PATH
154 if [ $? -eq 0 ]; then
155 # Only delete if successful
156 rm -rf $TRACE_PATH
157 fi
158 rm -f ${file_sync_after_first}
159 rm -f ${file_sync_before_last}
160}
161
162function test_ust_live ()
163{
8d5a3312
MJ
164 local file_sync_after_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
165 local file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
801236b0
JD
166
167 diag "Test UST live with metadata regeneration (expect failure)"
f0d43d3d 168 create_lttng_session_uri $SESSION_NAME net://localhost --live
801236b0
JD
169 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
170
6c4a91d6
MD
171 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
172 --sync-after-first-event ${file_sync_after_first} \
173 --sync-before-last-event ${file_sync_before_last} >/dev/null 2>&1 &
801236b0
JD
174
175 start_lttng_tracing_ok $SESSION_NAME
176
177 touch ${file_sync_before_last}
178
179 # Wait for the applications started in background
180 wait
eded6438 181 regenerate_metadata_fail $SESSION_NAME
801236b0
JD
182
183 stop_lttng_tracing_ok $SESSION_NAME
184 destroy_lttng_session_ok $SESSION_NAME
185 # Validate test
186 validate_trace $EVENT_NAME $TRACE_PATH
187 if [ $? -eq 0 ]; then
188 # Only delete if successful
189 rm -rf $TRACE_PATH
190 fi
191 rm -f ${file_sync_after_first}
192 rm -f ${file_sync_before_last}
193}
194
dc97de74
JR
195function test_ust_local_snapshot_after_regenerate_metadata ()
196{
197 local file_sync_before_last
198 local metadata_path
199
200 file_sync_before_last=$(mktemp -u)
201
202 diag "Test UST local snapshot after regenerate metadata"
203 create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" --snapshot
204 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
205 start_lttng_tracing_ok $SESSION_NAME
206
207 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT
208
209 regenerate_metadata_ok $SESSION_NAME
210 lttng_snapshot_record $SESSION_NAME "$TRACE_PATH"
211 stop_lttng_tracing_ok $SESSION_NAME
212
213 validate_trace $EVENT_NAME "$TRACE_PATH"
214 destroy_lttng_session_ok $SESSION_NAME
215
216 rm -rf "$TRACE_PATH"
217}
218
801236b0
JD
219plan_tests $NUM_TESTS
220
221print_test_banner "$TEST_DESC"
c125de8f 222bail_out_if_no_babeltrace
801236b0
JD
223
224start_lttng_relayd "-o $TRACE_PATH"
225start_lttng_sessiond
226
dc97de74
JR
227tests=( test_ust_streaming test_ust_local test_ust_pid test_ust_live
228 test_ust_local_snapshot_after_regenerate_metadata)
801236b0
JD
229
230for fct_test in ${tests[@]};
231do
232 SESSION_NAME=$(randstring 16 0)
233 ${fct_test}
234done
235
236stop_lttng_sessiond
237stop_lttng_relayd
238
239exit $out
This page took 0.068562 seconds and 5 git commands to generate.