tests: truncate metadata file for regenerate metadata test
[lttng-tools.git] / tests / regression / tools / regen-metadata / test_ust
1 #!/bin/bash
2 #
3 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Streaming - User space tracing"
8
9 CURDIR=$(dirname $0)/
10 TESTDIR=$CURDIR/../../..
11 NR_ITER=1
12 NR_USEC_WAIT=0
13 TESTAPP_PATH="$TESTDIR/utils/testapp"
14 TESTAPP_NAME="gen-ust-events"
15 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
16 SESSION_NAME="stream"
17 EVENT_NAME="tp:tptest"
18
19 TRACE_PATH=$(mktemp -d)
20
21 NUM_TESTS=39
22
23 source $TESTDIR/utils/utils.sh
24
25 if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
27 fi
28
29 function 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
40 function test_ust_streaming ()
41 {
42 local file_sync_after_first=$(mktemp -u)
43 local file_sync_before_last=$(mktemp -u)
44 local metadata_path
45
46 diag "Test UST streaming with metadata regeneration"
47 create_lttng_session_uri $SESSION_NAME net://localhost
48 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
49
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 &
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
60
61 # Expect a valid trace
62 stop_lttng_tracing_ok $SESSION_NAME
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
76 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
77 destroy_lttng_session_ok $SESSION_NAME
78
79 rm -rf "$TRACE_PATH"
80 rm -f ${file_sync_after_first}
81 rm -f ${file_sync_before_last}
82 }
83
84 function test_ust_local ()
85 {
86 local file_sync_after_first=$(mktemp -u)
87 local file_sync_before_last=$(mktemp -u)
88 local metadata_path
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
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 &
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
104
105 # Expect a valid trace
106 stop_lttng_tracing_ok $SESSION_NAME
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
120 validate_trace $EVENT_NAME $TRACE_PATH
121 destroy_lttng_session_ok $SESSION_NAME
122
123 rm -rf "$TRACE_PATH"
124 rm -f ${file_sync_after_first}
125 rm -f ${file_sync_before_last}
126 }
127
128 function 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
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 &
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
148 regenerate_metadata_fail $SESSION_NAME
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
162 function 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)"
168 create_lttng_session_uri $SESSION_NAME net://localhost --live
169 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
170
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 &
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
181 regenerate_metadata_fail $SESSION_NAME
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
195 plan_tests $NUM_TESTS
196
197 print_test_banner "$TEST_DESC"
198
199 start_lttng_relayd "-o $TRACE_PATH"
200 start_lttng_sessiond
201
202 tests=( test_ust_streaming test_ust_local test_ust_pid test_ust_live )
203
204 for fct_test in ${tests[@]};
205 do
206 SESSION_NAME=$(randstring 16 0)
207 ${fct_test}
208 done
209
210 stop_lttng_sessiond
211 stop_lttng_relayd
212
213 exit $out
This page took 0.050571 seconds and 5 git commands to generate.