Test: clear: take an additional snapshot after clear for per-pid
[lttng-tools.git] / tests / regression / tools / clear / test_ust
1 #!/bin/bash
2 #
3 # Copyright (C) - 2019 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
4 #
5 # This library is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Lesser General Public License as published by the Free
7 # Software Foundation; version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU Lesser General Public License
15 # along with this library; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18 TEST_DESC="Clear - UST tracing"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../..
22 EVENT_NAME="tp:tptest"
23 SESSION_NAME=""
24 TESTAPP_PATH="$TESTDIR/utils/testapp"
25 TESTAPP_NAME="gen-ust-events"
26 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
27
28 NUM_TESTS=74
29
30 TRACE_PATH=$(mktemp -d)
31
32 source $TESTDIR/utils/utils.sh
33
34 if [ ! -x "$TESTAPP_BIN" ]; then
35 BAIL_OUT "No UST events binary detected."
36 fi
37
38 function clean_path ()
39 {
40 local trace_path=$1
41 set -u
42 rm -rf $trace_path/*
43 set +u
44 }
45
46 function test_ust_streaming ()
47 {
48 diag "Test ust streaming clear"
49 create_lttng_session_uri $SESSION_NAME net://localhost
50 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
51 start_lttng_tracing_ok $SESSION_NAME
52 # TODO: place holder, support for streaming MUST be implemented
53 # This validate that for now we fail correctly
54 lttng_clear_session_fail $SESSION_NAME
55
56 destroy_lttng_session_ok $SESSION_NAME
57 }
58
59 function test_ust_streaming_live ()
60 {
61 diag "Test ust streaming live clear"
62 create_lttng_session_uri $SESSION_NAME net://localhost "--live"
63 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
64 start_lttng_tracing_ok $SESSION_NAME
65 # TODO: place holder, support for streaming MUST be implemented
66 # This validate that for now we fail correctly
67 lttng_clear_session_fail $SESSION_NAME
68
69 destroy_lttng_session_ok $SESSION_NAME
70 }
71
72 function test_ust_local ()
73 {
74 diag "Test ust local"
75 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
76 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
77 start_lttng_tracing_ok $SESSION_NAME
78 # TODO: place holder, support for local MUST be implemented
79 lttng_clear_session_fail $SESSION_NAME
80 # TODO: validate that the previous chunk IS no more present
81
82 destroy_lttng_session_ok $SESSION_NAME
83 }
84
85 function do_ust_snapshot ()
86 {
87 local session_name=$1
88 local trace_path=$2
89
90 enable_ust_lttng_event_ok $session_name $EVENT_NAME
91 start_lttng_tracing_ok $session_name
92
93 # Generate 10 events that will sit in the buffers.
94 $TESTAPP_BIN -i 10
95
96 # Take a first snapshot and validate that the events are present.
97 lttng_snapshot_record $session_name
98 stop_lttng_tracing_ok $session_name
99 validate_trace_count $EVENT_NAME $trace_path 10
100
101 # Clean the output path
102 clean_path $trace_path
103 start_lttng_tracing_ok $session_name
104
105 lttng_clear_session_ok $session_name
106
107 # Make sure the subsequent snapshot is empty and valid.
108 lttng_snapshot_record $session_name
109 stop_lttng_tracing_ok $session_name
110 validate_trace_empty $trace_path
111
112 # Clean the output path
113 clean_path $trace_path
114 start_lttng_tracing_ok $session_name
115
116 # Make sure that everything still works, generate events and take a
117 # snapshot.
118 $TESTAPP_BIN -i 10
119 lttng_snapshot_record $session_name
120 stop_lttng_tracing_ok $session_name
121 validate_trace_count $EVENT_NAME $trace_path 10
122 }
123
124 function test_ust_streaming_snapshot ()
125 {
126 diag "Test ust streaming snapshot clear"
127
128 create_lttng_session_uri $SESSION_NAME net://localhost "--snapshot"
129 do_ust_snapshot $SESSION_NAME $TRACE_PATH
130 destroy_lttng_session_ok $SESSION_NAME
131 }
132
133 function test_ust_local_snapshot ()
134 {
135 diag "Test ust local snapshot clear"
136
137 create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot"
138 do_ust_snapshot $SESSION_NAME $TRACE_PATH
139 destroy_lttng_session_ok $SESSION_NAME
140 }
141
142 function test_ust_local_snapshot_per_pid ()
143 {
144 diag "Test ust local snapshot clear per pid "
145 local channel_name="channel0"
146 local file_sync_before_last=$(mktemp -u)
147 local file_sync_before_last_touch=$(mktemp -u)
148 local file_sync_before_exit=$(mktemp -u)
149 local file_sync_before_exit_touch=$(mktemp -u)
150
151 create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot"
152 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-pid
153 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
154 start_lttng_tracing_ok $SESSION_NAME
155
156 # Generate 10 events that will sit in the buffers.
157 $TESTAPP_BIN -i 10 -w 0 \
158 --sync-before-last-event ${file_sync_before_last} \
159 --sync-before-last-event-touch ${file_sync_before_last_touch} \
160 --sync-before-exit ${file_sync_before_exit} \
161 --sync-before-exit-touch ${file_sync_before_exit_touch} >/dev/null 2>&1 &
162
163 # Continue only when there is only the last event remaining.
164 while [ ! -f "${file_sync_before_last_touch}" ]; do
165 sleep 0.5
166 done
167
168 # Take a first snapshot and validate that the events are present.
169 lttng_snapshot_record $SESSION_NAME
170 stop_lttng_tracing_ok $SESSION_NAME
171 validate_trace_count $EVENT_NAME $TRACE_PATH 9
172
173 # Clean the output path
174 clean_path $TRACE_PATH
175 start_lttng_tracing_ok $SESSION_NAME
176
177 lttng_clear_session_ok $SESSION_NAME
178
179 # Make sure the subsequent snapshot is empty and valid.
180 lttng_snapshot_record $SESSION_NAME
181 stop_lttng_tracing_ok $SESSION_NAME
182 validate_trace_empty $TRACE_PATH
183
184 # Validate that tracing still works and subsequent snapshots are valid.
185 # Clean the output path.
186 clean_path $TRACE_PATH
187 start_lttng_tracing_ok $SESSION_NAME
188
189 # Continue over the last event.
190 touch ${file_sync_before_last}
191
192 # Wait for the before exit sync point. This ensure that we went over the
193 # last tracepoint.
194 while [ ! -f "${file_sync_before_exit_touch}" ]; do
195 sleep 0.5
196 done
197
198 # Make sure the snapshot contains the last event.
199 lttng_snapshot_record $SESSION_NAME
200 stop_lttng_tracing_ok $SESSION_NAME
201 validate_trace_count $EVENT_NAME $TRACE_PATH 1
202
203 # Release the application.
204 touch ${file_sync_before_exit}
205 wait
206 destroy_lttng_session_ok $SESSION_NAME
207
208 rm -f ${file_sync_before_last}
209 rm -f ${file_sync_before_last_touch}
210 rm -f ${file_sync_before_exit}
211 rm -f ${file_sync_before_exit_touch}
212 }
213
214 plan_tests $NUM_TESTS
215
216 print_test_banner "$TEST_DESC"
217
218
219 tests=(
220 test_ust_streaming
221 test_ust_streaming_live
222 test_ust_local
223 test_ust_streaming_snapshot
224 test_ust_local_snapshot
225 test_ust_local_snapshot_per_pid
226 )
227
228 start_lttng_relayd "-o $TRACE_PATH"
229 start_lttng_sessiond
230
231 for fct_test in ${tests[@]};
232 do
233 SESSION_NAME=$(randstring 16 0)
234 ${fct_test}
235 clean_path $TRACE_PATH
236 done
237
238 stop_lttng_sessiond
239 stop_lttng_relayd
This page took 0.035 seconds and 5 git commands to generate.