3 # Copyright (C) - 2015 Julien Desfossez <jdesfossez@efficios.com>
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 # WARNING: this test changes the date of the system (and does not set it back).
19 # This test sets the date of the current machine to $DATE1, creates a trace
20 # makes sure the trace is really at that date, then restarts the trace, changes
21 # the date to $DATE2, regenerates the metadata and validates that the trace is
24 TEST_DESC
="Metadata regeneration after date change"
30 KERNEL_EVENT_NAME
="lttng_test_filter_event"
31 TRACE_PATH
=$
(mktemp
-d)
33 TESTAPP_PATH
="$TESTDIR/utils/testapp"
34 TESTAPP_NAME
="gen-ust-events"
35 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
38 UST_EVENT_NAME
="tp:tptest"
44 source $TESTDIR/utils
/utils.sh
46 # MUST set TESTDIR before calling those functions
49 print_test_banner
"$TEST_DESC"
51 function validate_trace_date
56 which $BABELTRACE_BIN >/dev
/null
58 skip
0 "Babeltrace binary not found. Skipping trace validation"
61 res
=$
($BABELTRACE_BIN --clock-date $trace_path 2>/dev
/null |
head -1 |
grep $test_date)
63 pass
"Validate trace at date $test_date"
66 fail
"The trace is not at the expected date"
73 function test_kernel_local
()
75 diag
"Test kernel local with metadata regeneration"
76 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
77 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
78 lttng_enable_kernel_event
$SESSION_NAME $KERNEL_EVENT_NAME
79 start_lttng_tracing_ok
$SESSION_NAME
80 echo -n "100" > /proc
/lttng-test-filter-event
81 stop_lttng_tracing_ok
$SESSION_NAME
82 validate_trace_date
$DATE1 $TRACE_PATH
83 start_lttng_tracing_ok
$SESSION_NAME
84 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
85 regenerate_metadata_ok
$SESSION_NAME
86 stop_lttng_tracing_ok
$SESSION_NAME
87 validate_trace_date
$DATE2 $TRACE_PATH
89 # Only delete if successful
92 destroy_lttng_session_ok
$SESSION_NAME
95 function test_kernel_streaming
()
97 diag
"Test kernel streaming with metadata regeneration"
98 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
99 create_lttng_session_uri
$SESSION_NAME net
://localhost
100 lttng_enable_kernel_event
$SESSION_NAME $KERNEL_EVENT_NAME
101 start_lttng_tracing_ok
$SESSION_NAME
102 echo -n "100" > /proc
/lttng-test-filter-event
103 stop_lttng_tracing_ok
$SESSION_NAME
104 validate_trace_date
$DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
105 start_lttng_tracing_ok
$SESSION_NAME
106 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
107 regenerate_metadata_ok
$SESSION_NAME
108 stop_lttng_tracing_ok
$SESSION_NAME
110 validate_trace_date
$DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
111 if [ $?
-eq 0 ]; then
112 # Only delete if successful
117 destroy_lttng_session_ok
$SESSION_NAME
120 function test_ust_local
()
122 local file_sync_after_first
=$
(mktemp
-u)
123 local file_sync_before_last
=$
(mktemp
-u)
125 diag
"Test UST local with metadata regeneration"
126 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
127 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
128 enable_ust_lttng_event_ok
$SESSION_NAME $UST_EVENT_NAME
130 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
131 --sync-after-first-event ${file_sync_after_first} \
132 --sync-before-last-event ${file_sync_before_last} > /dev
/null
2>&1 &
134 start_lttng_tracing_ok
$SESSION_NAME
136 touch ${file_sync_before_last}
137 # Wait for the applications started in background
140 stop_lttng_tracing_ok
$SESSION_NAME
141 validate_trace_date
$DATE1 $TRACE_PATH
143 start_lttng_tracing_ok
$SESSION_NAME
144 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
145 regenerate_metadata_ok
$SESSION_NAME
147 stop_lttng_tracing_ok
$SESSION_NAME
148 destroy_lttng_session_ok
$SESSION_NAME
149 validate_trace_date
$DATE2 $TRACE_PATH
150 if [ $?
-eq 0 ]; then
151 # Only delete if successful
154 rm -f ${file_sync_after_first}
155 rm -f ${file_sync_before_last}
158 function test_ust_streaming
()
160 local file_sync_after_first
=$
(mktemp
-u)
161 local file_sync_before_last
=$
(mktemp
-u)
163 diag
"Test UST streaming with metadata regeneration"
164 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
165 create_lttng_session_uri
$SESSION_NAME net
://localhost
166 enable_ust_lttng_event_ok
$SESSION_NAME $UST_EVENT_NAME
168 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
169 --sync-after-first-event ${file_sync_after_first} \
170 --sync-before-last-event ${file_sync_before_last} > /dev
/null
2>&1 &
172 start_lttng_tracing_ok
$SESSION_NAME
174 touch ${file_sync_before_last}
176 # Wait for the applications started in background
178 stop_lttng_tracing_ok
$SESSION_NAME
179 validate_trace_date
$DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
181 start_lttng_tracing_ok
$SESSION_NAME
182 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
184 regenerate_metadata_ok
$SESSION_NAME
186 stop_lttng_tracing_ok
$SESSION_NAME
187 destroy_lttng_session_ok
$SESSION_NAME
189 validate_trace_date
$DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
190 if [ $?
-eq 0 ]; then
191 # Only delete if successful
194 rm -f ${file_sync_after_first}
195 rm -f ${file_sync_before_last}
198 if [ "$(id -u)" == "0" ]; then
204 if ! destructive_tests_enabled
; then
205 echo 'You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS to "will-break-my-system" as argument to run this test'
206 echo 'Moreover, please make sure that ntp is not running while executing this test'
210 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
212 start_lttng_relayd
"-o $TRACE_PATH"
217 test_kernel_streaming