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 | ||
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 -d) | |
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 | ||
512eb148 JD |
41 | function validate_trace_date |
42 | { | |
43 | local test_date=$1 | |
44 | local trace_path=$2 | |
45 | ||
46 | which $BABELTRACE_BIN >/dev/null | |
47 | if [ $? -ne 0 ]; then | |
48 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
49 | fi | |
50 | ||
51 | res=$($BABELTRACE_BIN --clock-date $trace_path 2>/dev/null | head -1 | grep $test_date) | |
52 | if [ $? -eq 0 ]; then | |
53 | pass "Validate trace at date $test_date" | |
54 | ret=0 | |
55 | else | |
56 | fail "The trace is not at the expected date" | |
57 | ret=-1 | |
58 | fi | |
59 | ||
60 | return $ret | |
61 | } | |
62 | ||
63 | function test_kernel_local () | |
64 | { | |
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 | |
eded6438 | 75 | regenerate_metadata_ok $SESSION_NAME |
512eb148 JD |
76 | stop_lttng_tracing_ok $SESSION_NAME |
77 | validate_trace_date $DATE2 $TRACE_PATH | |
78 | if [ $? -eq 0 ]; then | |
79 | # Only delete if successful | |
80 | rm -rf $TRACE_PATH | |
81 | fi | |
82 | destroy_lttng_session_ok $SESSION_NAME | |
83 | } | |
84 | ||
85 | function test_kernel_streaming () | |
86 | { | |
87 | diag "Test kernel streaming with metadata regeneration" | |
88 | date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null | |
f0d43d3d | 89 | create_lttng_session_uri $SESSION_NAME net://localhost |
512eb148 JD |
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 | |
eded6438 | 97 | regenerate_metadata_ok $SESSION_NAME |
512eb148 JD |
98 | stop_lttng_tracing_ok $SESSION_NAME |
99 | # Validate test | |
100 | validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME* | |
101 | if [ $? -eq 0 ]; then | |
102 | # Only delete if successful | |
103 | rm -rf $TRACE_PATH | |
104 | else | |
105 | break | |
106 | fi | |
107 | destroy_lttng_session_ok $SESSION_NAME | |
108 | } | |
109 | ||
110 | function test_ust_local () | |
111 | { | |
112 | local file_sync_after_first=$(mktemp -u) | |
113 | local file_sync_before_last=$(mktemp -u) | |
114 | ||
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 | |
119 | ||
6c4a91d6 MD |
120 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \ |
121 | --sync-after-first-event ${file_sync_after_first} \ | |
fa1289fc | 122 | --sync-before-last-event ${file_sync_before_last} > /dev/null 2>&1 & |
512eb148 JD |
123 | |
124 | start_lttng_tracing_ok $SESSION_NAME | |
125 | ||
126 | touch ${file_sync_before_last} | |
127 | # Wait for the applications started in background | |
128 | wait | |
129 | ||
130 | stop_lttng_tracing_ok $SESSION_NAME | |
131 | validate_trace_date $DATE1 $TRACE_PATH | |
132 | ||
133 | start_lttng_tracing_ok $SESSION_NAME | |
134 | date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null | |
eded6438 | 135 | regenerate_metadata_ok $SESSION_NAME |
512eb148 JD |
136 | |
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 | |
142 | rm -rf $TRACE_PATH | |
143 | fi | |
144 | rm -f ${file_sync_after_first} | |
145 | rm -f ${file_sync_before_last} | |
146 | } | |
147 | ||
148 | function test_ust_streaming () | |
149 | { | |
150 | local file_sync_after_first=$(mktemp -u) | |
151 | local file_sync_before_last=$(mktemp -u) | |
152 | ||
153 | diag "Test UST streaming with metadata regeneration" | |
154 | date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null | |
f0d43d3d | 155 | create_lttng_session_uri $SESSION_NAME net://localhost |
512eb148 JD |
156 | enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME |
157 | ||
6c4a91d6 MD |
158 | $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \ |
159 | --sync-after-first-event ${file_sync_after_first} \ | |
fa1289fc | 160 | --sync-before-last-event ${file_sync_before_last} > /dev/null 2>&1 & |
512eb148 JD |
161 | |
162 | start_lttng_tracing_ok $SESSION_NAME | |
163 | ||
164 | touch ${file_sync_before_last} | |
165 | ||
166 | # Wait for the applications started in background | |
167 | wait | |
168 | stop_lttng_tracing_ok $SESSION_NAME | |
169 | validate_trace_date $DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME* | |
170 | ||
171 | start_lttng_tracing_ok $SESSION_NAME | |
172 | date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null | |
173 | ||
eded6438 | 174 | regenerate_metadata_ok $SESSION_NAME |
512eb148 JD |
175 | |
176 | stop_lttng_tracing_ok $SESSION_NAME | |
177 | destroy_lttng_session_ok $SESSION_NAME | |
178 | # Validate test | |
179 | validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME* | |
180 | if [ $? -eq 0 ]; then | |
181 | # Only delete if successful | |
182 | rm -rf $TRACE_PATH | |
183 | fi | |
184 | rm -f ${file_sync_after_first} | |
185 | rm -f ${file_sync_before_last} | |
186 | } | |
187 | ||
188 | if [ "$(id -u)" == "0" ]; then | |
189 | isroot=1 | |
190 | else | |
191 | isroot=0 | |
192 | fi | |
193 | ||
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' | |
197 | exit 0 | |
198 | fi | |
199 | ||
200 | skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || | |
201 | { | |
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 | |
215 | } |