Tests: Clean trace_path after each subtest
[lttng-tools.git] / tests / regression / tools / rotation / test_ust
1 #!/bin/bash
2 #
3 # Copyright (C) - 2017 Julien Desfossez <jdesfossez@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 TEST_DESC="Rotation - User space tracing"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 NR_USEC_WAIT=0
22 TESTAPP_PATH="$TESTDIR/utils/testapp"
23 TESTAPP_NAME="gen-ust-events"
24 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
25 SESSION_NAME="stream"
26 EVENT_NAME="tp:tptest"
27
28 TRACE_PATH=$(mktemp -d)
29
30 NUM_TESTS=150
31
32 source $TESTDIR/utils/utils.sh
33 source $CURDIR/rotate_utils.sh
34
35 if [ ! -x "$TESTAPP_BIN" ]; then
36 BAIL_OUT "No UST events binary detected."
37 fi
38
39 function enable_channel_per_pid ()
40 {
41 sess_name=$1
42 channel_name=$2
43
44 enable_ust_lttng_channel_ok $sess_name $channel_name --buffers-pid
45 }
46
47 # MUST set TESTDIR before calling those functions
48
49 function rotate_ust_test ()
50 {
51 local_path=$1
52 app_path=$2
53 per_pid=$3
54
55 start_lttng_tracing_ok $SESSION_NAME
56 today=$(date +%Y%m%d)
57
58 $TESTAPP_BIN 10 $NR_USEC_WAIT /dev/null 2>&1
59 rotate_session_ok $SESSION_NAME
60
61 $TESTAPP_BIN 20 $NR_USEC_WAIT /dev/null 2>&1
62 stop_lttng_tracing_ok $SESSION_NAME
63
64 # Third chunk contains no event (rotate after stop).
65 rotate_session_ok $SESSION_NAME
66
67 destroy_lttng_session_ok $SESSION_NAME
68
69 # The tests on the chunk folder rely on the date staying the same during
70 # the duration of the test, if this fail we will now why the other checks
71 # fail afterwards. There is a short window of time where an automated test
72 # could fail because of that.
73 now=$(date +%Y%m%d)
74 test $today = $now
75 ok $? "Date did not change during the test"
76
77 validate_test_chunks "${local_path}" $today $app_path ust $per_pid
78 }
79
80 function test_ust_streaming_uid ()
81 {
82 diag "Test UST streaming with session rotation per UID"
83 create_lttng_session_uri $SESSION_NAME net://localhost
84 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
85
86 rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/uid/*/*/" 0
87 }
88
89 function test_ust_local_uid ()
90 {
91 diag "Test UST local with session rotation per UID"
92 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
93 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
94
95 rotate_ust_test "${TRACE_PATH}" "ust/uid/*/*/" 0
96 }
97
98 function test_ust_streaming_pid ()
99 {
100 diag "Test UST streaming with session rotation per PID"
101 create_lttng_session_uri $SESSION_NAME net://localhost
102 enable_channel_per_pid $SESSION_NAME "channel0"
103 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
104
105 rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/pid/*/" 1
106 }
107
108 function test_ust_local_pid ()
109 {
110 diag "Test UST local with session rotation per PID"
111 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
112 enable_channel_per_pid $SESSION_NAME "channel0"
113 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
114
115 rotate_ust_test "${TRACE_PATH}" "ust/pid/*/" 1
116 }
117
118 function test_ust_local_timer_uid ()
119 {
120 diag "Test ust local with session rotation timer per-uid"
121 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
122 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
123 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
124 start_lttng_tracing_ok $SESSION_NAME
125 # We just want the app to register, no event generated
126 $TESTAPP_BIN 0 0 /dev/null 2>&1
127
128 rotate_timer_test "${TRACE_PATH}" 0
129 }
130
131 function test_ust_streaming_timer_uid ()
132 {
133 diag "Test ust remote with session rotation timer per-uid"
134 create_lttng_session_uri $SESSION_NAME net://localhost
135 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
136 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
137 start_lttng_tracing_ok $SESSION_NAME
138 # We just want the app to register, no event generated
139 $TESTAPP_BIN 0 0 /dev/null 2>&1
140
141 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 0
142 }
143
144 function test_ust_local_timer_pid ()
145 {
146 diag "Test ust local with session rotation timer per-pid"
147 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
148 enable_channel_per_pid $SESSION_NAME "channel0"
149 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
150 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
151 start_lttng_tracing_ok $SESSION_NAME
152 # We just want the app to register, no event generated
153 $TESTAPP_BIN 0 0 /dev/null 2>&1
154
155 rotate_timer_test "${TRACE_PATH}" 1
156 }
157
158 function test_ust_streaming_timer_pid ()
159 {
160 diag "Test ust remote with session rotation timer per-pid"
161 create_lttng_session_uri $SESSION_NAME net://localhost
162 enable_channel_per_pid $SESSION_NAME "channel0"
163 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
164 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
165 start_lttng_tracing_ok $SESSION_NAME
166 # We just want the app to register, no event generated
167 $TESTAPP_BIN 0 0 /dev/null 2>&1
168
169 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 1
170 }
171
172 function test_incompatible_sessions ()
173 {
174 diag "Check incompatible session types with rotation"
175
176 diag "Live session with rotate timer"
177 # Should not be able to enable a rotation timer with a live session
178 create_lttng_session_uri $SESSION_NAME net://localhost --live
179 lttng_enable_rotation_timer_fail $SESSION_NAME 500ms
180 destroy_lttng_session_ok $SESSION_NAME
181
182 diag "Snapshot session with rotate timer"
183 # Should not be able to enable a rotation timer with a snapshot session
184 create_lttng_session_ok $SESSION_NAME $TRACE_PATH --snapshot
185 lttng_enable_rotation_timer_fail $SESSION_NAME 500ms
186 destroy_lttng_session_ok $SESSION_NAME
187
188 diag "Live session with rotate"
189 # Should not be able to rotate a live session
190 create_lttng_session_uri $SESSION_NAME net://localhost --live
191 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
192 start_lttng_tracing_ok $SESSION_NAME
193 rotate_session_fail $SESSION_NAME
194 destroy_lttng_session_ok $SESSION_NAME
195
196 diag "Snapshot session with rotate"
197 # Should not be able to rotate a snapshot session
198 create_lttng_session_ok $SESSION_NAME $TRACE_PATH --snapshot
199 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
200 start_lttng_tracing_ok $SESSION_NAME
201 rotate_session_fail $SESSION_NAME
202 destroy_lttng_session_ok $SESSION_NAME
203 }
204
205 plan_tests $NUM_TESTS
206
207 print_test_banner "$TEST_DESC"
208
209 start_lttng_relayd "-o $TRACE_PATH"
210 start_lttng_sessiond
211
212 tests=( test_ust_streaming_uid test_ust_local_uid \
213 test_ust_streaming_pid test_ust_local_pid \
214 test_ust_local_timer_uid test_ust_streaming_timer_uid \
215 test_ust_local_timer_pid test_ust_streaming_timer_pid \
216 test_incompatible_sessions )
217
218 for fct_test in ${tests[@]};
219 do
220 SESSION_NAME=$(randstring 16 0)
221 ${fct_test}
222 clean_path $TRACE_PATH
223 done
224
225 stop_lttng_sessiond
226 stop_lttng_relayd
227
228 # Remove tmp dir
229 rm -rf $TRACE_PATH
This page took 0.05798 seconds and 4 git commands to generate.