Test: lttng clear command for snapshot session
[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=69
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
149 create_lttng_session_ok $SESSION_NAME $TRACE_PATH "--snapshot"
150 enable_ust_lttng_channel_ok $SESSION_NAME $channel_name --buffers-pid
151 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name
152 start_lttng_tracing_ok $SESSION_NAME
153
154 # Generate 10 events that will sit in the buffers.
155 $TESTAPP_BIN -i 10 -w 0 \
156 --sync-before-last-event ${file_sync_before_last} \
157 --sync-before-last-event-touch ${file_sync_before_last_touch} >/dev/null 2>&1 &
158
159 # Continue only when there is only the last event remaining.
160 while [ ! -f "${file_sync_before_last_touch}" ]; do
161 sleep 0.5
162 done
163
164 # Take a first snapshot and validate that the events are present.
165 lttng_snapshot_record $SESSION_NAME
166 stop_lttng_tracing_ok $SESSION_NAME
167 validate_trace_count $EVENT_NAME $TRACE_PATH 9
168
169 # Clean the output path
170 clean_path $TRACE_PATH
171 start_lttng_tracing_ok $SESSION_NAME
172
173 lttng_clear_session_ok $SESSION_NAME
174
175 # Make sure the subsequent snapshot is empty and valid.
176 lttng_snapshot_record $SESSION_NAME
177 stop_lttng_tracing_ok $SESSION_NAME
178 validate_trace_empty $TRACE_PATH
179
180 touch ${file_sync_before_last}
181 wait
182 destroy_lttng_session_ok $SESSION_NAME
183
184 rm -f ${file_sync_before_last}
185 rm -f ${file_sync_before_last_touch}
186 }
187
188 plan_tests $NUM_TESTS
189
190 print_test_banner "$TEST_DESC"
191
192
193 tests=(
194 test_ust_streaming
195 test_ust_streaming_live
196 test_ust_local
197 test_ust_streaming_snapshot
198 test_ust_local_snapshot
199 test_ust_local_snapshot_per_pid
200 )
201
202 start_lttng_relayd "-o $TRACE_PATH"
203 start_lttng_sessiond
204
205 for fct_test in ${tests[@]};
206 do
207 SESSION_NAME=$(randstring 16 0)
208 ${fct_test}
209 clean_path $TRACE_PATH
210 done
211
212 stop_lttng_sessiond
213 stop_lttng_relayd
This page took 0.034078 seconds and 5 git commands to generate.