Commit | Line | Data |
---|---|---|
512eb148 JD |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2015 Julien Desfossez <jdesfossez@efficios.com> |
512eb148 | 4 | # |
9d16b343 | 5 | # SPDX-License-Identifier: GPL-2.0-only |
512eb148 | 6 | # |
512eb148 JD |
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 | ||
a24ac4d1 | 16 | CURDIR=$(dirname "$0")/ |
512eb148 JD |
17 | TESTDIR=$CURDIR/.. |
18 | NUM_TESTS=44 | |
19 | SESSION_NAME="regen" | |
20 | KERNEL_EVENT_NAME="lttng_test_filter_event" | |
8d5a3312 | 21 | TRACE_PATH=$(mktemp -d -t tmp.metadata_regen_after_data_change.XXXXXX) |
512eb148 JD |
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 | ||
a24ac4d1 | 34 | source "$TESTDIR/utils/utils.sh" |
512eb148 JD |
35 | |
36 | # MUST set TESTDIR before calling those functions | |
37 | plan_tests $NUM_TESTS | |
38 | ||
39 | print_test_banner "$TEST_DESC" | |
40 | ||
c125de8f FD |
41 | bail_out_if_no_babeltrace |
42 | ||
43 | ||
512eb148 JD |
44 | function validate_trace_date |
45 | { | |
46 | local test_date=$1 | |
47 | local trace_path=$2 | |
48 | ||
a24ac4d1 | 49 | res=$($BABELTRACE_BIN --clock-date "$trace_path" 2>/dev/null | head -1 | grep $test_date) |
512eb148 JD |
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 | |
a24ac4d1 | 65 | create_lttng_session_ok $SESSION_NAME "$TRACE_PATH" |
512eb148 JD |
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 | |
a24ac4d1 | 70 | validate_trace_date $DATE1 "$TRACE_PATH" |
512eb148 JD |
71 | start_lttng_tracing_ok $SESSION_NAME |
72 | date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null | |
eded6438 | 73 | regenerate_metadata_ok $SESSION_NAME |
512eb148 | 74 | stop_lttng_tracing_ok $SESSION_NAME |
a24ac4d1 | 75 | validate_trace_date $DATE2 "$TRACE_PATH" |
512eb148 JD |
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 | |
f0d43d3d | 87 | create_lttng_session_uri $SESSION_NAME net://localhost |
512eb148 JD |
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 | |
eded6438 | 95 | regenerate_metadata_ok $SESSION_NAME |
512eb148 JD |
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 | |
a24ac4d1 | 103 | return |
512eb148 JD |
104 | fi |
105 | destroy_lttng_session_ok $SESSION_NAME | |
106 | } | |
107 | ||
108 | function test_ust_local () | |
109 | { | |
a24ac4d1 JR |
110 | local file_sync_after_first |
111 | local file_sync_before_last | |
112 | ||
8d5a3312 MJ |
113 | file_sync_after_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX") |
114 | file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") | |
512eb148 JD |
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 | ||
6c4a91d6 | 121 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \ |
a24ac4d1 JR |
122 | --sync-after-first-event "${file_sync_after_first}" \ |
123 | --sync-before-last-event "${file_sync_before_last}" > /dev/null 2>&1 & | |
512eb148 JD |
124 | |
125 | start_lttng_tracing_ok $SESSION_NAME | |
126 | ||
a24ac4d1 | 127 | touch "${file_sync_before_last}" |
512eb148 JD |
128 | # Wait for the applications started in background |
129 | wait | |
130 | ||
131 | stop_lttng_tracing_ok $SESSION_NAME | |
a24ac4d1 | 132 | validate_trace_date $DATE1 "$TRACE_PATH" |
512eb148 JD |
133 | |
134 | start_lttng_tracing_ok $SESSION_NAME | |
135 | date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null | |
eded6438 | 136 | regenerate_metadata_ok $SESSION_NAME |
512eb148 JD |
137 | |
138 | stop_lttng_tracing_ok $SESSION_NAME | |
139 | destroy_lttng_session_ok $SESSION_NAME | |
a24ac4d1 | 140 | validate_trace_date $DATE2 "$TRACE_PATH" |
512eb148 JD |
141 | if [ $? -eq 0 ]; then |
142 | # Only delete if successful | |
a24ac4d1 | 143 | rm -rf "$TRACE_PATH" |
512eb148 | 144 | fi |
a24ac4d1 JR |
145 | rm -f "${file_sync_after_first}" |
146 | rm -f "${file_sync_before_last}" | |
512eb148 JD |
147 | } |
148 | ||
149 | function test_ust_streaming () | |
150 | { | |
a24ac4d1 JR |
151 | local file_sync_after_first |
152 | local file_sync_before_last | |
153 | ||
8d5a3312 MJ |
154 | file_sync_after_first=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_after_first.XXXXXX") |
155 | file_sync_before_last=$(mktemp -u -t "tmp.${FUNCNAME[0]}_sync_before_last.XXXXXX") | |
512eb148 JD |
156 | |
157 | diag "Test UST streaming with metadata regeneration" | |
158 | date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null | |
f0d43d3d | 159 | create_lttng_session_uri $SESSION_NAME net://localhost |
512eb148 JD |
160 | enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME |
161 | ||
6c4a91d6 | 162 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \ |
a24ac4d1 JR |
163 | --sync-after-first-event "${file_sync_after_first}" \ |
164 | --sync-before-last-event "${file_sync_before_last}" > /dev/null 2>&1 & | |
512eb148 JD |
165 | |
166 | start_lttng_tracing_ok $SESSION_NAME | |
167 | ||
a24ac4d1 | 168 | touch "${file_sync_before_last}" |
512eb148 JD |
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 | ||
eded6438 | 178 | regenerate_metadata_ok $SESSION_NAME |
512eb148 JD |
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 | |
a24ac4d1 | 186 | rm -rf "$TRACE_PATH" |
512eb148 | 187 | fi |
a24ac4d1 JR |
188 | rm -f "${file_sync_after_first}" |
189 | rm -f "${file_sync_before_last}" | |
512eb148 JD |
190 | } |
191 | ||
512eb148 | 192 | if ! destructive_tests_enabled ; then |
a24ac4d1 JR |
193 | echo 'Please make sure that ntp is not running while executing this test' |
194 | skip 0 "You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS environment variable to \"will-break-my-system\" to run this test" $NUM_TESTS | |
195 | ||
512eb148 JD |
196 | exit 0 |
197 | fi | |
198 | ||
3a174400 | 199 | check_skip_kernel_test $NUM_TESTS "Skipping all tests." || |
512eb148 | 200 | { |
a99a847c | 201 | original_date=$(date) |
512eb148 JD |
202 | start_lttng_relayd "-o $TRACE_PATH" |
203 | start_lttng_sessiond | |
204 | ||
205 | modprobe lttng-test | |
206 | test_kernel_local | |
207 | test_kernel_streaming | |
d0e263e7 | 208 | modprobe --remove lttng-test |
512eb148 JD |
209 | |
210 | test_ust_local | |
211 | test_ust_streaming | |
212 | ||
213 | stop_lttng_sessiond | |
214 | stop_lttng_relayd | |
a99a847c JG |
215 | |
216 | # This set of test sets the date in the past which causes | |
217 | # `make` to panic when it sees files created in the "future" | |
218 | # while running the "check" target. Obviously this doesn't set | |
219 | # the correct date, but at least its close enough to allow the | |
220 | # test suite to continue. | |
221 | date --set "$original_date" | |
512eb148 | 222 | } |