3 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
5 # SPDX-License-Identifier: GPL-2.0-only
8 # WARNING: this test changes the date of the system (and does not set it back).
9 # This test sets the date of the current machine to $DATE1, creates a trace
10 # makes sure the trace is really at that date, then restarts the trace, changes
11 # the date to $DATE2, regenerates the metadata and validates that the trace is
14 TEST_DESC
="Metadata regeneration after date change"
20 KERNEL_EVENT_NAME
="lttng_test_filter_event"
21 TRACE_PATH
=$
(mktemp
--tmpdir -d -t tmp.metadata_regen_after_data_change.XXXXXX
)
23 TESTAPP_PATH
="$TESTDIR/utils/testapp"
24 TESTAPP_NAME
="gen-ust-events"
25 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
28 UST_EVENT_NAME
="tp:tptest"
34 source $TESTDIR/utils
/utils.sh
36 # MUST set TESTDIR before calling those functions
39 print_test_banner
"$TEST_DESC"
41 function validate_trace_date
46 which $BABELTRACE_BIN >/dev
/null
48 skip
0 "Babeltrace binary not found. Skipping trace validation"
51 res
=$
($BABELTRACE_BIN --clock-date $trace_path 2>/dev
/null |
head -1 |
grep $test_date)
53 pass
"Validate trace at date $test_date"
56 fail
"The trace is not at the expected date"
63 function test_kernel_local
()
65 diag
"Test kernel local with metadata regeneration"
66 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
67 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
68 lttng_enable_kernel_event
$SESSION_NAME $KERNEL_EVENT_NAME
69 start_lttng_tracing_ok
$SESSION_NAME
70 echo -n "100" > /proc
/lttng-test-filter-event
71 stop_lttng_tracing_ok
$SESSION_NAME
72 validate_trace_date
$DATE1 $TRACE_PATH
73 start_lttng_tracing_ok
$SESSION_NAME
74 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
75 regenerate_metadata_ok
$SESSION_NAME
76 stop_lttng_tracing_ok
$SESSION_NAME
77 validate_trace_date
$DATE2 $TRACE_PATH
79 # Only delete if successful
82 destroy_lttng_session_ok
$SESSION_NAME
85 function test_kernel_streaming
()
87 diag
"Test kernel streaming with metadata regeneration"
88 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
89 create_lttng_session_uri
$SESSION_NAME net
://localhost
90 lttng_enable_kernel_event
$SESSION_NAME $KERNEL_EVENT_NAME
91 start_lttng_tracing_ok
$SESSION_NAME
92 echo -n "100" > /proc
/lttng-test-filter-event
93 stop_lttng_tracing_ok
$SESSION_NAME
94 validate_trace_date
$DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
95 start_lttng_tracing_ok
$SESSION_NAME
96 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
97 regenerate_metadata_ok
$SESSION_NAME
98 stop_lttng_tracing_ok
$SESSION_NAME
100 validate_trace_date
$DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
101 if [ $?
-eq 0 ]; then
102 # Only delete if successful
107 destroy_lttng_session_ok
$SESSION_NAME
110 function test_ust_local
()
112 local file_sync_after_first
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
113 local file_sync_before_last
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
115 diag
"Test UST local with metadata regeneration"
116 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
117 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
118 enable_ust_lttng_event_ok
$SESSION_NAME $UST_EVENT_NAME
120 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
121 --sync-after-first-event ${file_sync_after_first} \
122 --sync-before-last-event ${file_sync_before_last} > /dev
/null
2>&1 &
124 start_lttng_tracing_ok
$SESSION_NAME
126 touch ${file_sync_before_last}
127 # Wait for the applications started in background
130 stop_lttng_tracing_ok
$SESSION_NAME
131 validate_trace_date
$DATE1 $TRACE_PATH
133 start_lttng_tracing_ok
$SESSION_NAME
134 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
135 regenerate_metadata_ok
$SESSION_NAME
137 stop_lttng_tracing_ok
$SESSION_NAME
138 destroy_lttng_session_ok
$SESSION_NAME
139 validate_trace_date
$DATE2 $TRACE_PATH
140 if [ $?
-eq 0 ]; then
141 # Only delete if successful
144 rm -f ${file_sync_after_first}
145 rm -f ${file_sync_before_last}
148 function test_ust_streaming
()
150 local file_sync_after_first
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
151 local file_sync_before_last
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
153 diag
"Test UST streaming with metadata regeneration"
154 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
155 create_lttng_session_uri
$SESSION_NAME net
://localhost
156 enable_ust_lttng_event_ok
$SESSION_NAME $UST_EVENT_NAME
158 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
159 --sync-after-first-event ${file_sync_after_first} \
160 --sync-before-last-event ${file_sync_before_last} > /dev
/null
2>&1 &
162 start_lttng_tracing_ok
$SESSION_NAME
164 touch ${file_sync_before_last}
166 # Wait for the applications started in background
168 stop_lttng_tracing_ok
$SESSION_NAME
169 validate_trace_date
$DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
171 start_lttng_tracing_ok
$SESSION_NAME
172 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
174 regenerate_metadata_ok
$SESSION_NAME
176 stop_lttng_tracing_ok
$SESSION_NAME
177 destroy_lttng_session_ok
$SESSION_NAME
179 validate_trace_date
$DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
180 if [ $?
-eq 0 ]; then
181 # Only delete if successful
184 rm -f ${file_sync_after_first}
185 rm -f ${file_sync_before_last}
188 if [ "$(id -u)" == "0" ]; then
194 if ! destructive_tests_enabled
; then
195 echo 'You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS to "will-break-my-system" as argument to run this test'
196 echo 'Moreover, please make sure that ntp is not running while executing this test'
200 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
202 start_lttng_relayd
"-o $TRACE_PATH"
207 test_kernel_streaming
208 modprobe
--remove lttng-test