Fix: Tests: missing stream redirect causes test failure
[lttng-tools.git] / tests / destructive / metadata-regeneration
CommitLineData
512eb148
JD
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
24TEST_DESC="Metadata regeneration after date change"
25
26CURDIR=$(dirname $0)/
27TESTDIR=$CURDIR/..
28NUM_TESTS=44
29SESSION_NAME="regen"
30KERNEL_EVENT_NAME="lttng_test_filter_event"
31TRACE_PATH=$(mktemp -d)
32
33TESTAPP_PATH="$TESTDIR/utils/testapp"
34TESTAPP_NAME="gen-ust-events"
35TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
36NR_ITER=1
37NR_USEC_WAIT=0
38UST_EVENT_NAME="tp:tptest"
39
40DATE1="1970-02-02"
41DATE2="1980-02-02"
42HOUR="05:30"
43
44source $TESTDIR/utils/utils.sh
45
46# MUST set TESTDIR before calling those functions
47plan_tests $NUM_TESTS
48
49print_test_banner "$TEST_DESC"
50
512eb148
JD
51function 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
73function 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
eded6438 85 regenerate_metadata_ok $SESSION_NAME
512eb148
JD
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
95function test_kernel_streaming ()
96{
97 diag "Test kernel streaming with metadata regeneration"
98 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
f0d43d3d 99 create_lttng_session_uri $SESSION_NAME net://localhost
512eb148
JD
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
eded6438 107 regenerate_metadata_ok $SESSION_NAME
512eb148
JD
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
120function 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
6c4a91d6
MD
130 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
131 --sync-after-first-event ${file_sync_after_first} \
fa1289fc 132 --sync-before-last-event ${file_sync_before_last} > /dev/null 2>&1 &
512eb148
JD
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
eded6438 145 regenerate_metadata_ok $SESSION_NAME
512eb148
JD
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
158function 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
f0d43d3d 165 create_lttng_session_uri $SESSION_NAME net://localhost
512eb148
JD
166 enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME
167
6c4a91d6
MD
168 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT \
169 --sync-after-first-event ${file_sync_after_first} \
fa1289fc 170 --sync-before-last-event ${file_sync_before_last} > /dev/null 2>&1 &
512eb148
JD
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
eded6438 184 regenerate_metadata_ok $SESSION_NAME
512eb148
JD
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
198if [ "$(id -u)" == "0" ]; then
199 isroot=1
200else
201 isroot=0
202fi
203
204if ! 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
208fi
209
210skip $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.05784 seconds and 4 git commands to generate.