a8b57633f7b73b4b9198fc8568dcdd9c246b805c
[lttng-tools.git] / tests / destructive / metadata-regeneration
1 #!/bin/bash
2 #
3 # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com>
4 #
5 # SPDX-License-Identifier: GPL-2.0-only
6 #
7
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
12 # actually at $DATE2.
13
14 TEST_DESC="Metadata regeneration after date change"
15
16 CURDIR=$(dirname "$0")/
17 TESTDIR=$CURDIR/..
18 NUM_TESTS=44
19 SESSION_NAME="regen"
20 KERNEL_EVENT_NAME="lttng_test_filter_event"
21 TRACE_PATH=$(mktemp --tmpdir -d -t tmp.metadata_regen_after_data_change.XXXXXX)
22
23 TESTAPP_PATH="$TESTDIR/utils/testapp"
24 TESTAPP_NAME="gen-ust-events"
25 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26 NR_ITER=1
27 NR_USEC_WAIT=0
28 UST_EVENT_NAME="tp:tptest"
29
30 DATE1="1970-02-02"
31 DATE2="1980-02-02"
32 HOUR="05:30"
33
34 source "$TESTDIR/utils/utils.sh"
35
36 # MUST set TESTDIR before calling those functions
37 plan_tests $NUM_TESTS
38
39 print_test_banner "$TEST_DESC"
40
41 bail_out_if_no_babeltrace
42
43
44 function validate_trace_date
45 {
46 local test_date=$1
47 local trace_path=$2
48
49 res=$($BABELTRACE_BIN --clock-date "$trace_path" 2>/dev/null | head -1 | grep $test_date)
50 if [ $? -eq 0 ]; then
51 pass "Validate trace at date $test_date"
52 ret=0
53 else
54 fail "The trace is not at the expected date"
55 ret=-1
56 fi
57
58 return $ret
59 }
60
61 function test_kernel_local ()
62 {
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"
76 if [ $? -eq 0 ]; then
77 # Only delete if successful
78 rm -rf $TRACE_PATH
79 fi
80 destroy_lttng_session_ok $SESSION_NAME
81 }
82
83 function test_kernel_streaming ()
84 {
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
97 # Validate test
98 validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
99 if [ $? -eq 0 ]; then
100 # Only delete if successful
101 rm -rf $TRACE_PATH
102 else
103 return
104 fi
105 destroy_lttng_session_ok $SESSION_NAME
106 }
107
108 function test_ust_local ()
109 {
110 local file_sync_after_first
111 local file_sync_before_last
112
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")
115
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
120
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 &
124
125 start_lttng_tracing_ok $SESSION_NAME
126
127 touch "${file_sync_before_last}"
128 # Wait for the applications started in background
129 wait
130
131 stop_lttng_tracing_ok $SESSION_NAME
132 validate_trace_date $DATE1 "$TRACE_PATH"
133
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
137
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
143 rm -rf "$TRACE_PATH"
144 fi
145 rm -f "${file_sync_after_first}"
146 rm -f "${file_sync_before_last}"
147 }
148
149 function test_ust_streaming ()
150 {
151 local file_sync_after_first
152 local file_sync_before_last
153
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")
156
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
161
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 &
165
166 start_lttng_tracing_ok $SESSION_NAME
167
168 touch "${file_sync_before_last}"
169
170 # Wait for the applications started in background
171 wait
172 stop_lttng_tracing_ok $SESSION_NAME
173 validate_trace_date $DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
174
175 start_lttng_tracing_ok $SESSION_NAME
176 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
177
178 regenerate_metadata_ok $SESSION_NAME
179
180 stop_lttng_tracing_ok $SESSION_NAME
181 destroy_lttng_session_ok $SESSION_NAME
182 # Validate test
183 validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
184 if [ $? -eq 0 ]; then
185 # Only delete if successful
186 rm -rf "$TRACE_PATH"
187 fi
188 rm -f "${file_sync_after_first}"
189 rm -f "${file_sync_before_last}"
190 }
191
192 if [ "$(id -u)" == "0" ]; then
193 isroot=1
194 else
195 isroot=0
196 fi
197
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
201
202 exit 0
203 fi
204
205 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
206 {
207 start_lttng_relayd "-o $TRACE_PATH"
208 start_lttng_sessiond
209
210 modprobe lttng-test
211 test_kernel_local
212 test_kernel_streaming
213 modprobe --remove lttng-test
214
215 test_ust_local
216 test_ust_streaming
217
218 stop_lttng_sessiond
219 stop_lttng_relayd
220 }
This page took 0.034836 seconds and 4 git commands to generate.