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 lttng_create_session_uri
53 # Create session with default path
54 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN create
$SESSION_NAME -U net
://localhost
>/dev
/null
2>&1
55 ok $?
"Create session with default path"
58 function validate_trace_date
63 which $BABELTRACE_BIN >/dev
/null
65 skip
0 "Babeltrace binary not found. Skipping trace validation"
68 res
=$
($BABELTRACE_BIN --clock-date $trace_path 2>/dev
/null |
head -1 |
grep $test_date)
70 pass
"Validate trace at date $test_date"
73 fail
"The trace is not at the expected date"
80 function test_kernel_local
()
82 diag
"Test kernel local with metadata regeneration"
83 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
84 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
85 lttng_enable_kernel_event
$SESSION_NAME $KERNEL_EVENT_NAME
86 start_lttng_tracing_ok
$SESSION_NAME
87 echo -n "100" > /proc
/lttng-test-filter-event
88 stop_lttng_tracing_ok
$SESSION_NAME
89 validate_trace_date
$DATE1 $TRACE_PATH
90 start_lttng_tracing_ok
$SESSION_NAME
91 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
92 metadata_regenerate_ok
$SESSION_NAME
93 stop_lttng_tracing_ok
$SESSION_NAME
94 validate_trace_date
$DATE2 $TRACE_PATH
96 # Only delete if successful
99 destroy_lttng_session_ok
$SESSION_NAME
102 function test_kernel_streaming
()
104 diag
"Test kernel streaming with metadata regeneration"
105 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
106 lttng_create_session_uri
107 lttng_enable_kernel_event
$SESSION_NAME $KERNEL_EVENT_NAME
108 start_lttng_tracing_ok
$SESSION_NAME
109 echo -n "100" > /proc
/lttng-test-filter-event
110 stop_lttng_tracing_ok
$SESSION_NAME
111 validate_trace_date
$DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
112 start_lttng_tracing_ok
$SESSION_NAME
113 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
114 metadata_regenerate_ok
$SESSION_NAME
115 stop_lttng_tracing_ok
$SESSION_NAME
117 validate_trace_date
$DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
118 if [ $?
-eq 0 ]; then
119 # Only delete if successful
124 destroy_lttng_session_ok
$SESSION_NAME
127 function test_ust_local
()
129 local file_sync_after_first
=$
(mktemp
-u)
130 local file_sync_before_last
=$
(mktemp
-u)
132 diag
"Test UST local with metadata regeneration"
133 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
134 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
135 enable_ust_lttng_event_ok
$SESSION_NAME $UST_EVENT_NAME
137 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} /dev
/null
2>&1 &
139 start_lttng_tracing_ok
$SESSION_NAME
141 touch ${file_sync_before_last}
142 # Wait for the applications started in background
145 stop_lttng_tracing_ok
$SESSION_NAME
146 validate_trace_date
$DATE1 $TRACE_PATH
148 start_lttng_tracing_ok
$SESSION_NAME
149 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
150 metadata_regenerate_ok
$SESSION_NAME
152 stop_lttng_tracing_ok
$SESSION_NAME
153 destroy_lttng_session_ok
$SESSION_NAME
154 validate_trace_date
$DATE2 $TRACE_PATH
155 if [ $?
-eq 0 ]; then
156 # Only delete if successful
159 rm -f ${file_sync_after_first}
160 rm -f ${file_sync_before_last}
163 function test_ust_streaming
()
165 local file_sync_after_first
=$
(mktemp
-u)
166 local file_sync_before_last
=$
(mktemp
-u)
168 diag
"Test UST streaming with metadata regeneration"
169 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
170 lttng_create_session_uri
171 enable_ust_lttng_event_ok
$SESSION_NAME $UST_EVENT_NAME
173 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} /dev
/null
2>&1 &
175 start_lttng_tracing_ok
$SESSION_NAME
177 touch ${file_sync_before_last}
179 # Wait for the applications started in background
181 stop_lttng_tracing_ok
$SESSION_NAME
182 validate_trace_date
$DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
184 start_lttng_tracing_ok
$SESSION_NAME
185 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
187 metadata_regenerate_ok
$SESSION_NAME
189 stop_lttng_tracing_ok
$SESSION_NAME
190 destroy_lttng_session_ok
$SESSION_NAME
192 validate_trace_date
$DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
193 if [ $?
-eq 0 ]; then
194 # Only delete if successful
197 rm -f ${file_sync_after_first}
198 rm -f ${file_sync_before_last}
201 if [ "$(id -u)" == "0" ]; then
207 if ! destructive_tests_enabled
; then
208 echo 'You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS to "will-break-my-system" as argument to run this test'
209 echo 'Moreover, please make sure that ntp is not running while executing this test'
213 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
215 start_lttng_relayd
"-o $TRACE_PATH"
220 test_kernel_streaming