tests: add declarations for functions in gen-syscall-events-callstack.c
[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 $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} /dev/null 2>&1 &
131
132 start_lttng_tracing_ok $SESSION_NAME
133
134 touch ${file_sync_before_last}
135 # Wait for the applications started in background
136 wait
137
138 stop_lttng_tracing_ok $SESSION_NAME
139 validate_trace_date $DATE1 $TRACE_PATH
140
141 start_lttng_tracing_ok $SESSION_NAME
142 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
143 regenerate_metadata_ok $SESSION_NAME
144
145 stop_lttng_tracing_ok $SESSION_NAME
146 destroy_lttng_session_ok $SESSION_NAME
147 validate_trace_date $DATE2 $TRACE_PATH
148 if [ $? -eq 0 ]; then
149 # Only delete if successful
150 rm -rf $TRACE_PATH
151 fi
152 rm -f ${file_sync_after_first}
153 rm -f ${file_sync_before_last}
154 }
155
156 function test_ust_streaming ()
157 {
158 local file_sync_after_first=$(mktemp -u)
159 local file_sync_before_last=$(mktemp -u)
160
161 diag "Test UST streaming with metadata regeneration"
162 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
163 create_lttng_session_uri $SESSION_NAME net://localhost
164 enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME
165
166 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} /dev/null 2>&1 &
167
168 start_lttng_tracing_ok $SESSION_NAME
169
170 touch ${file_sync_before_last}
171
172 # Wait for the applications started in background
173 wait
174 stop_lttng_tracing_ok $SESSION_NAME
175 validate_trace_date $DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
176
177 start_lttng_tracing_ok $SESSION_NAME
178 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
179
180 regenerate_metadata_ok $SESSION_NAME
181
182 stop_lttng_tracing_ok $SESSION_NAME
183 destroy_lttng_session_ok $SESSION_NAME
184 # Validate test
185 validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
186 if [ $? -eq 0 ]; then
187 # Only delete if successful
188 rm -rf $TRACE_PATH
189 fi
190 rm -f ${file_sync_after_first}
191 rm -f ${file_sync_before_last}
192 }
193
194 if [ "$(id -u)" == "0" ]; then
195 isroot=1
196 else
197 isroot=0
198 fi
199
200 if ! destructive_tests_enabled ; then
201 echo 'You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS to "will-break-my-system" as argument to run this test'
202 echo 'Moreover, please make sure that ntp is not running while executing this test'
203 exit 0
204 fi
205
206 skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
207 {
208 start_lttng_relayd "-o $TRACE_PATH"
209 start_lttng_sessiond
210
211 modprobe lttng-test
212 test_kernel_local
213 test_kernel_streaming
214 rmmod lttng-test
215
216 test_ust_local
217 test_ust_streaming
218
219 stop_lttng_sessiond
220 stop_lttng_relayd
221 }
This page took 0.034662 seconds and 5 git commands to generate.