X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Fcli%2Ftest_trimmer;h=c40db035c370fbb26269614c9a15c075f9799952;hb=5ce9818ba4e76858b2ef12c81ba75c1306f195d3;hp=c1525024dc63a8ab65710e276154c229813c7b10;hpb=644e036445497ef69ccf946f0700da20a5bae84f;p=babeltrace.git diff --git a/tests/cli/test_trimmer b/tests/cli/test_trimmer index c1525024..c40db035 100755 --- a/tests/cli/test_trimmer +++ b/tests/cli/test_trimmer @@ -1,19 +1,9 @@ #!/bin/bash # -# Copyright (C) 2017 Julien Desfossez -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License, version 2 only, as -# published by the Free Software Foundation. +# SPDX-License-Identifier: GPL-2.0-only # -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for -# more details. +# Copyright (C) 2017 Julien Desfossez # -# You should have received a copy of the GNU General Public License along with -# this program; if not, write to the Free Software Foundation, Inc., 51 -# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. SH_TAP=1 @@ -28,11 +18,13 @@ source "$UTILSSH" TRACE_PATH="${BT_CTF_TRACES_PATH}/succeed/wk-heartbeat-u/" -NUM_TESTS=40 +NUM_TESTS=118 plan_tests $NUM_TESTS tmp_out=$(mktemp) +tmp_err=$(mktemp) + # Run Babeltrace with some command line arguments, verify exit status and # number of output events (i.e. number of output lines) @@ -46,17 +38,52 @@ tmp_out=$(mktemp) function expect_success() { local expected_num_events="$1" - shift - local msg="$1" - shift + local msg="$2" + shift 2 - "${BT_TESTS_BT2_BIN}" "${TRACE_PATH}" "$@" 2>/dev/null > "${tmp_out}" + bt_cli "${tmp_out}" /dev/null "${TRACE_PATH}" "$@" ok $? "trimmer: ${msg}: exit status" + num_events=$(wc -l < "${tmp_out}") # Use bash parameter expansion to strip spaces added by BSD 'wc' on macOs and Solaris is "${num_events// /}" "${expected_num_events}" "trimmer: ${msg}: number of events (${expected_num_events})" } +# Run Babeltrace with some command line arguments, verify that the exit status +# is not 0 and that the error message contains a given string. +# +# Arguments: +# +# $1: a string expected to be found in the error message +# $2: test description +# remaining arguments: command-line arguments to pass to Babeltrace + +function expect_failure() +{ + local expected_err_string="$1" + local msg="$2" + shift 2 + + # We check the error message logged by the trimmer plugin, set the env + # var necessary for it to log errors. + BABELTRACE_FLT_UTILS_TRIMMER_LOG_LEVEL=E bt_cli "${tmp_out}" "${tmp_err}" "${TRACE_PATH}" "$@" + isnt $? 0 "trimmer: ${msg}: exit status" + + num_events=$(wc -l < "${tmp_out}") + # Use bash parameter expansion to strip spaces added by BSD 'wc' on macOs and Solaris + is "${num_events// /}" 0 "trimmer: ${msg}: number of events (0)" + + stderr="$(cat "${tmp_err}")" + # "like" doesn't like when the passed text is empty. + if [ -n "${stderr}" ]; then + like "${stderr}" "${expected_err_string}" "trimmer: ${msg}: error message" + else + fail "trimmer: ${msg}: error message" + diag "Nothing was output on stderr". + fi + +} + expect_success 18 "--begin, GMT relative timestamps" \ --clock-gmt --begin 17:48:17.587029529 expect_success 9 "--end, GMT relative timestamps" \ @@ -79,7 +106,18 @@ expect_success 0 "--begin, out of range, GMT absolute timestamps" \ expect_success 0 "--begin, out of range, GMT absolute timestamps" \ --clock-gmt --end "2012-10-29 16:48:17.588680018" -export TZ=EST +# Note here that the POSIX notation is a bit weird. +# The libc documentation shed some light on this: +# The offset specifies the time value you must add to the local time to get a +# Coordinated Universal Time value. It has syntax like [+|-]hh[:mm[:ss]]. This +# is positive if the local time zone is west of the Prime Meridian and negative +# if it is east. The hour must be between 0 and 24, and the minute and seconds +# between 0 and 59. [1] +# +# This is why we use EST5 to simulate an effective UTC-5:00 time. +# +# [1] https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html +export TZ=EST5 expect_success 18 "--begin, EST relative timestamps" \ --begin "12:48:17.587029529" @@ -103,4 +141,69 @@ expect_success 0 "--begin, out of range, EST absolute timestamps" \ expect_success 0 "--end, out of range, EST absolute timestamps" \ --end "2012-10-29 11:48:17.588680018" -rm "${tmp_out}" +# Check various formats. +# +# We sometimes apply a clock offset to make the events of the trace span two +# different seconds or minutes. + +expect_success 13 "date time format: partial nanosecond precision" \ + --begin="2012-10-29 12:48:17.588" +expect_success 11 "date time format: second precision" \ + --clock-offset-ns=411282268 --begin="2012-10-29 12:48:18" +expect_success 11 "date time format: minute precision" \ + --clock-offset=42 --clock-offset-ns=411282268 --begin="2012-10-29 12:49" + +expect_success 11 "seconds from origin format: nanosecond precision" \ + --begin="1351532897.588717732" +expect_success 11 "seconds from origin format: partial nanosecond precision" \ + --begin="1351532897.58871773" +expect_success 11 "seconds from origin format: second precision" \ + --clock-offset-ns=411282268 --begin="1351532898" + +expect_failure "Invalid date/time format" "date time format: too many nanosecond digits" \ + --begin="2012-10-29 12:48:17.1231231231" +expect_failure "Invalid date/time format" "date time format: missing nanoseconds" \ + --begin="2012-10-29 12:48:17." +expect_failure "Invalid date/time format" "date time format: seconds with too many digit" \ + --begin="2012-10-29 12:48:123" +expect_failure "Invalid date/time format" "date time format: seconds with missing digit" \ + --begin="2012-10-29 12:48:1" +expect_failure "Invalid date/time format" "date time format: minutes with too many digit" \ + --begin="2012-10-29 12:489:17" +expect_failure "Invalid date/time format" "date time format: minutes with missing digit" \ + --begin="2012-10-29 12:4:17" +expect_failure "Invalid date/time format" "date time format: hours with too many digit" \ + --begin="2012-10-29 123:48:17" +expect_failure "Invalid date/time format" "date time format: hours with missing digit" \ + --begin="2012-10-29 2:48:17" +expect_failure "Invalid date/time format" "date time format: missing seconds" \ + --begin="2012-10-29 12:48:" +expect_failure "Invalid date/time format" "date time format: missing minutes 1" \ + --begin="2012-10-29 12:" +expect_failure "Invalid date/time format" "date time format: missing minutes 2" \ + --begin="2012-10-29 12" +expect_failure "Invalid date/time format" "date time format: missing time" \ + --begin="2012-10-29 " +expect_failure "Invalid date/time format" "date time format: day with too many digit" \ + --begin="2012-10-291" +expect_failure "Invalid date/time format" "date time format: day with missing digit" \ + --begin="2012-10-2" +expect_failure "Invalid date/time format" "date time format: month with too many digit" \ + --begin="2012-101-29" +expect_failure "Invalid date/time format" "date time format: month with missing digit" \ + --begin="2012-1-29" +expect_failure "Invalid date/time format" "date time format: year with too many digits" \ + --begin="20121-10-29" +expect_failure "Invalid date/time format" "date time format: year with missing digits" \ + --begin="12-10-29" +expect_failure "Invalid date/time format" "date time format: missing day 1" \ + --begin="2012-10-" +expect_failure "Invalid date/time format" "date time format: missing day 2" \ + --begin="2012-10" + +expect_failure "Invalid date/time format" "seconds from origin format: too many nanosecond digits" \ + --begin="1351532898.1231231231" +expect_failure "Invalid date/time format" "seconds from origin format: missing nanseconds" \ + --begin="1351532898." + +rm "${tmp_out}" "${tmp_err}"