tests: truncate metadata file for regenerate metadata test
[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
JD
18
19TRACE_PATH=$(mktemp -d)
20
dbbc5b0a 21NUM_TESTS=39
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{
42 local file_sync_after_first=$(mktemp -u)
43 local file_sync_before_last=$(mktemp -u)
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
66 metadata_path=$(find "$TRACE_PATH/$HOSTNAME/$SESSION_NAME"* | grep metadata)
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{
86 local file_sync_after_first=$(mktemp -u)
87 local file_sync_before_last=$(mktemp -u)
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
110 metadata_path=$(find "$TRACE_PATH"* | grep metadata)
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{
130 local file_sync_after_first=$(mktemp -u)
131 local file_sync_before_last=$(mktemp -u)
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{
164 local file_sync_after_first=$(mktemp -u)
165 local file_sync_before_last=$(mktemp -u)
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
195plan_tests $NUM_TESTS
196
197print_test_banner "$TEST_DESC"
198
199start_lttng_relayd "-o $TRACE_PATH"
200start_lttng_sessiond
201
202tests=( test_ust_streaming test_ust_local test_ust_pid test_ust_live )
203
204for fct_test in ${tests[@]};
205do
206 SESSION_NAME=$(randstring 16 0)
207 ${fct_test}
208done
209
210stop_lttng_sessiond
211stop_lttng_relayd
212
213exit $out
This page took 0.090922 seconds and 5 git commands to generate.