fix: test_trimmer on macOs and Solaris
[babeltrace.git] / tests / cli / test_trimmer.in
index 9303cdf76049ac00ffa9e9ea50e42a7e025cb90b..8c853aeaa0a7a12f5f089aec45d355a54eabb227 100644 (file)
 # this program; if not, write to the Free Software Foundation, Inc., 51
 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
-. "@abs_top_srcdir@/tests/utils/common.sh"
+. "@abs_top_builddir@/tests/utils/common.sh"
 
 TRACE_PATH="${BT_CTF_TRACES}/succeed/wk-heartbeat-u/"
 
-NUM_TESTS=10
+NUM_TESTS=40
 
 plan_tests $NUM_TESTS
 
 tmp_out=$(mktemp)
 
-"${BT_BIN}" --clock-gmt --begin 17:48:17.587029529 --end 17:48:17.588680018 \
-       "${TRACE_PATH}" >/dev/null 2>&1
-ok $? "Read the trace with the trimmer enabled"
+# 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_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})"
+}
 
-"${BT_BIN}" --clock-gmt --begin 17:48:17.587029529 "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Running with --begin"
-cnt=$(wc -l < "${tmp_out}")
-test "$cnt" == 18
-ok $? "Expected number of events after trimming begin and end"
+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
 
-"${BT_BIN}" --clock-gmt --end 17:48:17.588680018 "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Running with --end"
-cnt=$(wc -l < "${tmp_out}")
-test "$cnt" == 9
-ok $? "Expected number of events after trimming end"
+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"
 
-"${BT_BIN}" --clock-gmt --begin 17:48:17.587029529 --end 17:48:17.588680018 \
-       "${TRACE_PATH}" 2>/dev/null >"${tmp_out}"
-ok $? "Running with --begin and --end"
-cnt=$(wc -l < "${tmp_out}")
-test "$cnt" == 7
-ok $? "Expected number of events after trimming begin and end"
+export TZ=EST
 
-"${BT_BIN}" --clock-gmt --begin 18:48:17.587029529 "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Running with --begin out of range"
-cnt=$(wc -l < "${tmp_out}")
-test "$cnt" == 0
-ok $? "No event output when begin is after the end of the trace"
+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"
 
-"${BT_BIN}" --clock-gmt --end 16:48:17.588680018 "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-cnt=$(wc -l < "${tmp_out}")
-test "$cnt" == 0
-ok $? "No event output when end is before the beginning of the trace"
+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}"
This page took 0.024734 seconds and 4 git commands to generate.