Fix: test cases now rely on explicit workloads
[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
51function lttng_create_session_uri
52{
53 # Create session with default path
54 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1
55 ok $? "Create session with default path"
56}
57
58function validate_trace_date
59{
60 local test_date=$1
61 local trace_path=$2
62
63 which $BABELTRACE_BIN >/dev/null
64 if [ $? -ne 0 ]; then
65 skip 0 "Babeltrace binary not found. Skipping trace validation"
66 fi
67
68 res=$($BABELTRACE_BIN --clock-date $trace_path 2>/dev/null | head -1 | grep $test_date)
69 if [ $? -eq 0 ]; then
70 pass "Validate trace at date $test_date"
71 ret=0
72 else
73 fail "The trace is not at the expected date"
74 ret=-1
75 fi
76
77 return $ret
78}
79
80function test_kernel_local ()
81{
82 diag "Test kernel local with metadata regeneration"
83 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
84 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
85 lttng_enable_kernel_event $SESSION_NAME $KERNEL_EVENT_NAME
86 start_lttng_tracing_ok $SESSION_NAME
87 echo -n "100" > /proc/lttng-test-filter-event
88 stop_lttng_tracing_ok $SESSION_NAME
89 validate_trace_date $DATE1 $TRACE_PATH
90 start_lttng_tracing_ok $SESSION_NAME
91 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
92 metadata_regenerate_ok $SESSION_NAME
93 stop_lttng_tracing_ok $SESSION_NAME
94 validate_trace_date $DATE2 $TRACE_PATH
95 if [ $? -eq 0 ]; then
96 # Only delete if successful
97 rm -rf $TRACE_PATH
98 fi
99 destroy_lttng_session_ok $SESSION_NAME
100}
101
102function test_kernel_streaming ()
103{
104 diag "Test kernel streaming with metadata regeneration"
105 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
106 lttng_create_session_uri
107 lttng_enable_kernel_event $SESSION_NAME $KERNEL_EVENT_NAME
108 start_lttng_tracing_ok $SESSION_NAME
109 echo -n "100" > /proc/lttng-test-filter-event
110 stop_lttng_tracing_ok $SESSION_NAME
111 validate_trace_date $DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
112 start_lttng_tracing_ok $SESSION_NAME
113 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
114 metadata_regenerate_ok $SESSION_NAME
115 stop_lttng_tracing_ok $SESSION_NAME
116 # Validate test
117 validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
118 if [ $? -eq 0 ]; then
119 # Only delete if successful
120 rm -rf $TRACE_PATH
121 else
122 break
123 fi
124 destroy_lttng_session_ok $SESSION_NAME
125}
126
127function test_ust_local ()
128{
129 local file_sync_after_first=$(mktemp -u)
130 local file_sync_before_last=$(mktemp -u)
131
132 diag "Test UST local with metadata regeneration"
133 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
134 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
135 enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME
136
137 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} /dev/null 2>&1 &
138
139 start_lttng_tracing_ok $SESSION_NAME
140
141 touch ${file_sync_before_last}
142 # Wait for the applications started in background
143 wait
144
145 stop_lttng_tracing_ok $SESSION_NAME
146 validate_trace_date $DATE1 $TRACE_PATH
147
148 start_lttng_tracing_ok $SESSION_NAME
149 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
150 metadata_regenerate_ok $SESSION_NAME
151
152 stop_lttng_tracing_ok $SESSION_NAME
153 destroy_lttng_session_ok $SESSION_NAME
154 validate_trace_date $DATE2 $TRACE_PATH
155 if [ $? -eq 0 ]; then
156 # Only delete if successful
157 rm -rf $TRACE_PATH
158 fi
159 rm -f ${file_sync_after_first}
160 rm -f ${file_sync_before_last}
161}
162
163function test_ust_streaming ()
164{
165 local file_sync_after_first=$(mktemp -u)
166 local file_sync_before_last=$(mktemp -u)
167
168 diag "Test UST streaming with metadata regeneration"
169 date "+%Y-%m-%d %H:%M" -s "$DATE1 $HOUR" >/dev/null
170 lttng_create_session_uri
171 enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME
172
173 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} /dev/null 2>&1 &
174
175 start_lttng_tracing_ok $SESSION_NAME
176
177 touch ${file_sync_before_last}
178
179 # Wait for the applications started in background
180 wait
181 stop_lttng_tracing_ok $SESSION_NAME
182 validate_trace_date $DATE1 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
183
184 start_lttng_tracing_ok $SESSION_NAME
185 date "+%Y-%m-%d %H:%M" -s "$DATE2 $HOUR" >/dev/null
186
187 metadata_regenerate_ok $SESSION_NAME
188
189 stop_lttng_tracing_ok $SESSION_NAME
190 destroy_lttng_session_ok $SESSION_NAME
191 # Validate test
192 validate_trace_date $DATE2 $TRACE_PATH/$HOSTNAME/$SESSION_NAME*
193 if [ $? -eq 0 ]; then
194 # Only delete if successful
195 rm -rf $TRACE_PATH
196 fi
197 rm -f ${file_sync_after_first}
198 rm -f ${file_sync_before_last}
199}
200
201if [ "$(id -u)" == "0" ]; then
202 isroot=1
203else
204 isroot=0
205fi
206
207if ! destructive_tests_enabled ; then
208 echo 'You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS to "will-break-my-system" as argument to run this test'
209 echo 'Moreover, please make sure that ntp is not running while executing this test'
210 exit 0
211fi
212
213skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
214{
215 start_lttng_relayd "-o $TRACE_PATH"
216 start_lttng_sessiond
217
218 modprobe lttng-test
219 test_kernel_local
220 test_kernel_streaming
221 rmmod lttng-test
222
223 test_ust_local
224 test_ust_streaming
225
226 stop_lttng_sessiond
227 stop_lttng_relayd
228}
This page took 0.064776 seconds and 4 git commands to generate.