tests: specify the timezone offset
[babeltrace.git] / tests / cli / test_trimmer
CommitLineData
e5a54f3f
JD
1#!/bin/bash
2#
644e0364 3# Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
e5a54f3f
JD
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
644e0364
MJ
18SH_TAP=1
19
20if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
21 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
22else
23 UTILSSH="$(dirname "$0")/../utils/utils.sh"
24fi
25
26# shellcheck source=../utils/utils.sh
27source "$UTILSSH"
e5a54f3f 28
bbff0ab4 29TRACE_PATH="${BT_CTF_TRACES_PATH}/succeed/wk-heartbeat-u/"
e5a54f3f 30
d4d7ffc9 31NUM_TESTS=118
e5a54f3f
JD
32
33plan_tests $NUM_TESTS
34
35tmp_out=$(mktemp)
d4d7ffc9
SM
36tmp_err=$(mktemp)
37
e5a54f3f 38
93fb46c6
SM
39# Run Babeltrace with some command line arguments, verify exit status and
40# number of output events (i.e. number of output lines)
41#
42# Arguments:
43#
44# $1: expected number of events
45# $2: test description
46# remaining arguments: command-line arguments to pass to Babeltrace
47
48function expect_success()
49{
50 local expected_num_events="$1"
d4d7ffc9
SM
51 local msg="$2"
52 shift 2
93fb46c6 53
644e0364 54 "${BT_TESTS_BT2_BIN}" "${TRACE_PATH}" "$@" 2>/dev/null > "${tmp_out}"
93fb46c6 55 ok $? "trimmer: ${msg}: exit status"
d4d7ffc9 56
93fb46c6 57 num_events=$(wc -l < "${tmp_out}")
891c35e4
MJ
58 # Use bash parameter expansion to strip spaces added by BSD 'wc' on macOs and Solaris
59 is "${num_events// /}" "${expected_num_events}" "trimmer: ${msg}: number of events (${expected_num_events})"
93fb46c6
SM
60}
61
d4d7ffc9
SM
62# Run Babeltrace with some command line arguments, verify that the exit status
63# is not 0 and that the error message contains a given string.
64#
65# Arguments:
66#
67# $1: a string expected to be found in the error message
68# $2: test description
69# remaining arguments: command-line arguments to pass to Babeltrace
70
71function expect_failure()
72{
73 local expected_err_string="$1"
74 local msg="$2"
75 shift 2
76
77 # We check the error message logged by the trimmer plugin, set the env
78 # var necessary for it to log errors.
79 BABELTRACE_FLT_UTILS_TRIMMER_LOG_LEVEL=E "${BT_TESTS_BT2_BIN}" "${TRACE_PATH}" "$@" 2> "${tmp_err}" > "${tmp_out}"
80 isnt $? 0 "trimmer: ${msg}: exit status"
81
82 num_events=$(wc -l < "${tmp_out}")
bfb5625d
JR
83 # Use bash parameter expansion to strip spaces added by BSD 'wc' on macOs and Solaris
84 is "${num_events// /}" 0 "trimmer: ${msg}: number of events (0)"
d4d7ffc9
SM
85
86 stderr="$(cat "${tmp_err}")"
87 # "like" doesn't like when the passed text is empty.
88 if [ -n "${stderr}" ]; then
89 like "${stderr}" "${expected_err_string}" "trimmer: ${msg}: error message"
90 else
91 fail "trimmer: ${msg}: error message"
92 diag "Nothing was output on stderr".
93 fi
94
95}
96
93fb46c6
SM
97expect_success 18 "--begin, GMT relative timestamps" \
98 --clock-gmt --begin 17:48:17.587029529
99expect_success 9 "--end, GMT relative timestamps" \
100 --clock-gmt --end 17:48:17.588680018
101expect_success 7 "--begin and --end, GMT relative timestamps" \
102 --clock-gmt --begin 17:48:17.587029529 --end 17:48:17.588680018
103expect_success 0 "--begin, out of range, GMT relative timestamps" \
104 --clock-gmt --begin 18:48:17.587029529
105expect_success 0 "--end, out of range, GMT relative timestamps" \
106 --clock-gmt --end 16:48:17.588680018
107
108expect_success 18 "--begin, GMT absolute timestamps" \
109 --clock-gmt --begin "2012-10-29 17:48:17.587029529"
110expect_success 9 "--end, GMT absolute timestamps" \
111 --clock-gmt --end "2012-10-29 17:48:17.588680018"
112expect_success 7 "--begin and --end, GMT absolute timestamps" \
113 --clock-gmt --begin "2012-10-29 17:48:17.587029529" --end "2012-10-29 17:48:17.588680018"
114expect_success 0 "--begin, out of range, GMT absolute timestamps" \
115 --clock-gmt --begin "2012-10-29 18:48:17.587029529"
116expect_success 0 "--begin, out of range, GMT absolute timestamps" \
117 --clock-gmt --end "2012-10-29 16:48:17.588680018"
95abf2a0 118
2f137223
JR
119# Note here that the POSIX notation is a bit weird.
120# The libc documentation shed some light on this:
121# The offset specifies the time value you must add to the local time to get a
122# Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This
123# is positive if the local time zone is west of the Prime Meridian and negative
124# if it is east. The hour must be between 0 and 24, and the minute and seconds
125# between 0 and 59. [1]
126#
127# This is why we use EST5 to simulate an effective UTC-5:00 time.
128#
129# [1] https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html
130export TZ=EST5
95abf2a0 131
93fb46c6
SM
132expect_success 18 "--begin, EST relative timestamps" \
133 --begin "12:48:17.587029529"
134expect_success 9 "--end, EST relative timestamps" \
135 --end "12:48:17.588680018"
136expect_success 7 "--begin and --end, EST relative timestamps" \
137 --begin "12:48:17.587029529" --end "12:48:17.588680018"
138expect_success 0 "--begin, out of range, EST relative timestamps" \
139 --begin "13:48:17.587029529"
140expect_success 0 "--end, out of range, EST relative timestamps" \
141 --end "11:48:17.588680018"
142
143expect_success 18 "--begin, EST absolute timestamps" \
144 --begin "2012-10-29 12:48:17.587029529"
145expect_success 9 "--end, EST absolute timestamps" \
146 --end "12:48:17.588680018"
147expect_success 7 "--begin and --end, EST absolute timestamps" \
148 --begin "2012-10-29 12:48:17.587029529" --end "2012-10-29 12:48:17.588680018"
149expect_success 0 "--begin, out of range, EST absolute timestamps" \
150 --begin "2012-10-29 13:48:17.587029529"
151expect_success 0 "--end, out of range, EST absolute timestamps" \
152 --end "2012-10-29 11:48:17.588680018"
e5a54f3f 153
d4d7ffc9
SM
154# Check various formats.
155#
156# We sometimes apply a clock offset to make the events of the trace span two
157# different seconds or minutes.
158
159expect_success 13 "date time format: partial nanosecond precision" \
160 --begin="2012-10-29 12:48:17.588"
161expect_success 11 "date time format: second precision" \
162 --clock-offset-ns=411282268 --begin="2012-10-29 12:48:18"
163expect_success 11 "date time format: minute precision" \
164 --clock-offset=42 --clock-offset-ns=411282268 --begin="2012-10-29 12:49"
165
166expect_success 11 "seconds from origin format: nanosecond precision" \
167 --begin="1351532897.588717732"
168expect_success 11 "seconds from origin format: partial nanosecond precision" \
169 --begin="1351532897.58871773"
170expect_success 11 "seconds from origin format: second precision" \
171 --clock-offset-ns=411282268 --begin="1351532898"
172
173expect_failure "Invalid date/time format" "date time format: too many nanosecond digits" \
174 --begin="2012-10-29 12:48:17.1231231231"
175expect_failure "Invalid date/time format" "date time format: missing nanoseconds" \
176 --begin="2012-10-29 12:48:17."
177expect_failure "Invalid date/time format" "date time format: seconds with too many digit" \
178 --begin="2012-10-29 12:48:123"
179expect_failure "Invalid date/time format" "date time format: seconds with missing digit" \
180 --begin="2012-10-29 12:48:1"
181expect_failure "Invalid date/time format" "date time format: minutes with too many digit" \
182 --begin="2012-10-29 12:489:17"
183expect_failure "Invalid date/time format" "date time format: minutes with missing digit" \
184 --begin="2012-10-29 12:4:17"
185expect_failure "Invalid date/time format" "date time format: hours with too many digit" \
186 --begin="2012-10-29 123:48:17"
187expect_failure "Invalid date/time format" "date time format: hours with missing digit" \
188 --begin="2012-10-29 2:48:17"
189expect_failure "Invalid date/time format" "date time format: missing seconds" \
190 --begin="2012-10-29 12:48:"
191expect_failure "Invalid date/time format" "date time format: missing minutes 1" \
192 --begin="2012-10-29 12:"
193expect_failure "Invalid date/time format" "date time format: missing minutes 2" \
194 --begin="2012-10-29 12"
195expect_failure "Invalid date/time format" "date time format: missing time" \
196 --begin="2012-10-29 "
197expect_failure "Invalid date/time format" "date time format: day with too many digit" \
198 --begin="2012-10-291"
199expect_failure "Invalid date/time format" "date time format: day with missing digit" \
200 --begin="2012-10-2"
201expect_failure "Invalid date/time format" "date time format: month with too many digit" \
202 --begin="2012-101-29"
203expect_failure "Invalid date/time format" "date time format: month with missing digit" \
204 --begin="2012-1-29"
205expect_failure "Invalid date/time format" "date time format: year with too many digits" \
206 --begin="20121-10-29"
207expect_failure "Invalid date/time format" "date time format: year with missing digits" \
208 --begin="12-10-29"
209expect_failure "Invalid date/time format" "date time format: missing day 1" \
210 --begin="2012-10-"
211expect_failure "Invalid date/time format" "date time format: missing day 2" \
212 --begin="2012-10"
213
214expect_failure "Invalid date/time format" "seconds from origin format: too many nanosecond digits" \
215 --begin="1351532898.1231231231"
216expect_failure "Invalid date/time format" "seconds from origin format: missing nanseconds" \
217 --begin="1351532898."
218
219rm "${tmp_out}" "${tmp_err}"
This page took 0.045471 seconds and 4 git commands to generate.