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"
16 CURDIR
=$
(dirname "$0")/
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 bail_out_if_no_babeltrace
44 function validate_trace_date
49 res
=$
($BABELTRACE_BIN --clock-date "$trace_path" 2>/dev
/null |
head -1 |
grep $test_date)
51 pass
"Validate trace at date $test_date"
54 fail
"The trace is not at the expected date"
61 function test_kernel_local
()
63 diag
"Test kernel local with metadata regeneration"
64 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
65 create_lttng_session_ok
$SESSION_NAME "$TRACE_PATH"
66 lttng_enable_kernel_event
$SESSION_NAME $KERNEL_EVENT_NAME
67 start_lttng_tracing_ok
$SESSION_NAME
68 echo -n "100" > /proc
/lttng-test-filter-event
69 stop_lttng_tracing_ok
$SESSION_NAME
70 validate_trace_date
$DATE1 "$TRACE_PATH"
71 start_lttng_tracing_ok
$SESSION_NAME
72 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
73 regenerate_metadata_ok
$SESSION_NAME
74 stop_lttng_tracing_ok
$SESSION_NAME
75 validate_trace_date
$DATE2 "$TRACE_PATH"
77 # Only delete if successful
80 destroy_lttng_session_ok
$SESSION_NAME
83 function test_kernel_streaming
()
85 diag
"Test kernel streaming with metadata regeneration"
86 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
87 create_lttng_session_uri
$SESSION_NAME net
://localhost
88 lttng_enable_kernel_event
$SESSION_NAME $KERNEL_EVENT_NAME
89 start_lttng_tracing_ok
$SESSION_NAME
90 echo -n "100" > /proc
/lttng-test-filter-event
91 stop_lttng_tracing_ok
$SESSION_NAME
92 validate_trace_date
$DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
93 start_lttng_tracing_ok
$SESSION_NAME
94 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
95 regenerate_metadata_ok
$SESSION_NAME
96 stop_lttng_tracing_ok
$SESSION_NAME
98 validate_trace_date
$DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
100 # Only delete if successful
105 destroy_lttng_session_ok
$SESSION_NAME
108 function test_ust_local
()
110 local file_sync_after_first
111 local file_sync_before_last
113 file_sync_after_first
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
114 file_sync_before_last
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
116 diag
"Test UST local with metadata regeneration"
117 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
118 create_lttng_session_ok
$SESSION_NAME $TRACE_PATH
119 enable_ust_lttng_event_ok
$SESSION_NAME $UST_EVENT_NAME
121 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
122 --sync-after-first-event "${file_sync_after_first}" \
123 --sync-before-last-event "${file_sync_before_last}" > /dev
/null
2>&1 &
125 start_lttng_tracing_ok
$SESSION_NAME
127 touch "${file_sync_before_last}"
128 # Wait for the applications started in background
131 stop_lttng_tracing_ok
$SESSION_NAME
132 validate_trace_date
$DATE1 "$TRACE_PATH"
134 start_lttng_tracing_ok
$SESSION_NAME
135 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
136 regenerate_metadata_ok
$SESSION_NAME
138 stop_lttng_tracing_ok
$SESSION_NAME
139 destroy_lttng_session_ok
$SESSION_NAME
140 validate_trace_date
$DATE2 "$TRACE_PATH"
141 if [ $?
-eq 0 ]; then
142 # Only delete if successful
145 rm -f "${file_sync_after_first}"
146 rm -f "${file_sync_before_last}"
149 function test_ust_streaming
()
151 local file_sync_after_first
152 local file_sync_before_last
154 file_sync_after_first
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX")
155 file_sync_before_last
=$
(mktemp
--tmpdir -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX")
157 diag
"Test UST streaming with metadata regeneration"
158 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev
/null
159 create_lttng_session_uri
$SESSION_NAME net
://localhost
160 enable_ust_lttng_event_ok
$SESSION_NAME $UST_EVENT_NAME
162 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
163 --sync-after-first-event "${file_sync_after_first}" \
164 --sync-before-last-event "${file_sync_before_last}" > /dev
/null
2>&1 &
166 start_lttng_tracing_ok
$SESSION_NAME
168 touch "${file_sync_before_last}"
170 # Wait for the applications started in background
172 stop_lttng_tracing_ok
$SESSION_NAME
173 validate_trace_date
$DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
175 start_lttng_tracing_ok
$SESSION_NAME
176 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev
/null
178 regenerate_metadata_ok
$SESSION_NAME
180 stop_lttng_tracing_ok
$SESSION_NAME
181 destroy_lttng_session_ok
$SESSION_NAME
183 validate_trace_date
$DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
184 if [ $?
-eq 0 ]; then
185 # Only delete if successful
188 rm -f "${file_sync_after_first}"
189 rm -f "${file_sync_before_last}"
192 if [ "$(id -u)" == "0" ]; then
198 if ! destructive_tests_enabled
; then
199 echo 'Please make sure that ntp is not running while executing this test'
200 skip
0 "You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS environment variable to \"will-break-my-system\" to run this test" $NUM_TESTS
205 skip
$isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
207 start_lttng_relayd
"-o $TRACE_PATH"
212 test_kernel_streaming
213 modprobe
--remove lttng-test