Gen-ust-events: use options instead of arguments
[lttng-tools.git] / tests / destructive / metadata-regeneration
1 #!/bin/bash
2 #
3 # Copyright (C) - 2015 Julien Desfossez <jdesfossez@efficios.com>
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 # WARNING: this test changes the date of the system (and does not set it back).
19 # This test sets the date of the current machine to $DATE1, creates a trace
20 # makes sure the trace is really at that date, then restarts the trace, changes
21 # the date to $DATE2, regenerates the metadata and validates that the trace is
22 # actually at $DATE2.
23
24 TEST_DESC="Metadata regeneration after date change"
25
26 CURDIR=$(dirname $0)/
27 TESTDIR=$CURDIR/..
28 NUM_TESTS=44
29 SESSION_NAME="regen"
30 KERNEL_EVENT_NAME="lttng_test_filter_event"
31 TRACE_PATH=$(mktemp -d)
32
33 TESTAPP_PATH="$TESTDIR/utils/testapp"
34 TESTAPP_NAME="gen-ust-events"
35 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
36 NR_ITER=1
37 NR_USEC_WAIT=0
38 UST_EVENT_NAME="tp:tptest"
39
40 DATE1="1970-02-02"
41 DATE2="1980-02-02"
42 HOUR="05:30"
43
44 source $TESTDIR/utils/utils.sh
45
46 # MUST set TESTDIR before calling those functions
47 plan_tests $NUM_TESTS
48
49 print_test_banner "$TEST_DESC"
50
51 function validate_trace_date
52 {
53 local test_date=$1
54 local trace_path=$2
55
56 which $BABELTRACE_BIN >/dev/null
57 if [ $? -ne 0 ]; then
58 skip 0 "Babeltrace binary not found. Skipping trace validation"
59 fi
60
61 res=$($BABELTRACE_BIN --clock-date $trace_path 2>/dev/null | head -1 | grep $test_date)
62 if [ $? -eq 0 ]; then
63 pass "Validate trace at date $test_date"
64 ret=0
65 else
66 fail "The trace is not at the expected date"
67 ret=-1
68 fi
69
70 return $ret
71 }
72
73 function test_kernel_local ()
74 {
75 diag "Test kernel local with metadata regeneration"
76 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
77 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
78 lttng_enable_kernel_event $SESSION_NAME $KERNEL_EVENT_NAME
79 start_lttng_tracing_ok $SESSION_NAME
80 echo -n "100" > /proc/lttng-test-filter-event
81 stop_lttng_tracing_ok $SESSION_NAME
82 validate_trace_date $DATE1 $TRACE_PATH
83 start_lttng_tracing_ok $SESSION_NAME
84 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
85 regenerate_metadata_ok $SESSION_NAME
86 stop_lttng_tracing_ok $SESSION_NAME
87 validate_trace_date $DATE2 $TRACE_PATH
88 if [ $? -eq 0 ]; then
89 # Only delete if successful
90 rm -rf $TRACE_PATH
91 fi
92 destroy_lttng_session_ok $SESSION_NAME
93 }
94
95 function test_kernel_streaming ()
96 {
97 diag "Test kernel streaming with metadata regeneration"
98 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
99 create_lttng_session_uri $SESSION_NAME net://localhost
100 lttng_enable_kernel_event $SESSION_NAME $KERNEL_EVENT_NAME
101 start_lttng_tracing_ok $SESSION_NAME
102 echo -n "100" > /proc/lttng-test-filter-event
103 stop_lttng_tracing_ok $SESSION_NAME
104 validate_trace_date $DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
105 start_lttng_tracing_ok $SESSION_NAME
106 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
107 regenerate_metadata_ok $SESSION_NAME
108 stop_lttng_tracing_ok $SESSION_NAME
109 # Validate test
110 validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
111 if [ $? -eq 0 ]; then
112 # Only delete if successful
113 rm -rf $TRACE_PATH
114 else
115 break
116 fi
117 destroy_lttng_session_ok $SESSION_NAME
118 }
119
120 function test_ust_local ()
121 {
122 local file_sync_after_first=$(mktemp -u)
123 local file_sync_before_last=$(mktemp -u)
124
125 diag "Test UST local with metadata regeneration"
126 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
127 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
128 enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME
129
130 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
131 --sync-after-first-event ${file_sync_after_first} \
132 --sync-before-last-event ${file_sync_before_last} /dev/null 2>&1 &
133
134 start_lttng_tracing_ok $SESSION_NAME
135
136 touch ${file_sync_before_last}
137 # Wait for the applications started in background
138 wait
139
140 stop_lttng_tracing_ok $SESSION_NAME
141 validate_trace_date $DATE1 $TRACE_PATH
142
143 start_lttng_tracing_ok $SESSION_NAME
144 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
145 regenerate_metadata_ok $SESSION_NAME
146
147 stop_lttng_tracing_ok $SESSION_NAME
148 destroy_lttng_session_ok $SESSION_NAME
149 validate_trace_date $DATE2 $TRACE_PATH
150 if [ $? -eq 0 ]; then
151 # Only delete if successful
152 rm -rf $TRACE_PATH
153 fi
154 rm -f ${file_sync_after_first}
155 rm -f ${file_sync_before_last}
156 }
157
158 function test_ust_streaming ()
159 {
160 local file_sync_after_first=$(mktemp -u)
161 local file_sync_before_last=$(mktemp -u)
162
163 diag "Test UST streaming with metadata regeneration"
164 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
165 create_lttng_session_uri $SESSION_NAME net://localhost
166 enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME
167
168 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
169 --sync-after-first-event ${file_sync_after_first} \
170 --sync-before-last-event ${file_sync_before_last} /dev/null 2>&1 &
171
172 start_lttng_tracing_ok $SESSION_NAME
173
174 touch ${file_sync_before_last}
175
176 # Wait for the applications started in background
177 wait
178 stop_lttng_tracing_ok $SESSION_NAME
179 validate_trace_date $DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
180
181 start_lttng_tracing_ok $SESSION_NAME
182 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
183
184 regenerate_metadata_ok $SESSION_NAME
185
186 stop_lttng_tracing_ok $SESSION_NAME
187 destroy_lttng_session_ok $SESSION_NAME
188 # Validate test
189 validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
190 if [ $? -eq 0 ]; then
191 # Only delete if successful
192 rm -rf $TRACE_PATH
193 fi
194 rm -f ${file_sync_after_first}
195 rm -f ${file_sync_before_last}
196 }
197
198 if [ "$(id -u)" == "0" ]; then
199 isroot=1
200 else
201 isroot=0
202 fi
203
204 if ! destructive_tests_enabled ; then
205 echo 'You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS to "will-break-my-system" as argument to run this test'
206 echo 'Moreover, please make sure that ntp is not running while executing this test'
207 exit 0
208 fi
209
210 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
211 {
212 start_lttng_relayd "-o $TRACE_PATH"
213 start_lttng_sessiond
214
215 modprobe lttng-test
216 test_kernel_local
217 test_kernel_streaming
218 rmmod lttng-test
219
220 test_ust_local
221 test_ust_streaming
222
223 stop_lttng_sessiond
224 stop_lttng_relayd
225 }
This page took 0.05243 seconds and 5 git commands to generate.