--- /dev/null
+#!/bin/bash
+#
+# Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
+#
+# 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.
+#
+# 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.
+#
+# 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
+
+if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
+ UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
+else
+ UTILSSH="$(dirname "$0")/../utils/utils.sh"
+fi
+
+# shellcheck source=../utils/utils.sh
+source "$UTILSSH"
+
+TRACE_PATH="${BT_CTF_TRACES_PATH}/succeed/wk-heartbeat-u/"
+
+NUM_TESTS=40
+
+plan_tests $NUM_TESTS
+
+tmp_out=$(mktemp)
+
+# Run Babeltrace with some command line arguments, verify exit status and
+# number of output events (i.e. number of output lines)
+#
+# Arguments:
+#
+# $1: expected number of events
+# $2: test description
+# remaining arguments: command-line arguments to pass to Babeltrace
+
+function expect_success()
+{
+ local expected_num_events="$1"
+ shift
+ local msg="$1"
+ shift
+
+ "${BT_TESTS_BT2_BIN}" "${TRACE_PATH}" "$@" 2>/dev/null > "${tmp_out}"
+ 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})"
+}
+
+expect_success 18 "--begin, GMT relative timestamps" \
+ --clock-gmt --begin 17:48:17.587029529
+expect_success 9 "--end, GMT relative timestamps" \
+ --clock-gmt --end 17:48:17.588680018
+expect_success 7 "--begin and --end, GMT relative timestamps" \
+ --clock-gmt --begin 17:48:17.587029529 --end 17:48:17.588680018
+expect_success 0 "--begin, out of range, GMT relative timestamps" \
+ --clock-gmt --begin 18:48:17.587029529
+expect_success 0 "--end, out of range, GMT relative timestamps" \
+ --clock-gmt --end 16:48:17.588680018
+
+expect_success 18 "--begin, GMT absolute timestamps" \
+ --clock-gmt --begin "2012-10-29 17:48:17.587029529"
+expect_success 9 "--end, GMT absolute timestamps" \
+ --clock-gmt --end "2012-10-29 17:48:17.588680018"
+expect_success 7 "--begin and --end, GMT absolute timestamps" \
+ --clock-gmt --begin "2012-10-29 17:48:17.587029529" --end "2012-10-29 17:48:17.588680018"
+expect_success 0 "--begin, out of range, GMT absolute timestamps" \
+ --clock-gmt --begin "2012-10-29 18:48:17.587029529"
+expect_success 0 "--begin, out of range, GMT absolute timestamps" \
+ --clock-gmt --end "2012-10-29 16:48:17.588680018"
+
+export TZ=EST
+
+expect_success 18 "--begin, EST relative timestamps" \
+ --begin "12:48:17.587029529"
+expect_success 9 "--end, EST relative timestamps" \
+ --end "12:48:17.588680018"
+expect_success 7 "--begin and --end, EST relative timestamps" \
+ --begin "12:48:17.587029529" --end "12:48:17.588680018"
+expect_success 0 "--begin, out of range, EST relative timestamps" \
+ --begin "13:48:17.587029529"
+expect_success 0 "--end, out of range, EST relative timestamps" \
+ --end "11:48:17.588680018"
+
+expect_success 18 "--begin, EST absolute timestamps" \
+ --begin "2012-10-29 12:48:17.587029529"
+expect_success 9 "--end, EST absolute timestamps" \
+ --end "12:48:17.588680018"
+expect_success 7 "--begin and --end, EST absolute timestamps" \
+ --begin "2012-10-29 12:48:17.587029529" --end "2012-10-29 12:48:17.588680018"
+expect_success 0 "--begin, out of range, EST absolute timestamps" \
+ --begin "2012-10-29 13:48:17.587029529"
+expect_success 0 "--end, out of range, EST absolute timestamps" \
+ --end "2012-10-29 11:48:17.588680018"
+
+rm "${tmp_out}"