tests: clean up test_trimmer
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 7 Jun 2019 18:28:53 +0000 (14:28 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 7 Jun 2019 23:04:37 +0000 (19:04 -0400)
This patch changes test_trimmer to reduce duplication of the
boilerplate.  I intend to add some test cases to this test in a
following patch, so this change allows me to understand better what the
test does currently and will help adding test cases.

Note that there are pairs of tests that are pretty much redundant, such
as:

- "Read a trace with the trimmer enabled (GMT relative timestamps)"
- "Ran successfully with --begin and --end (GMT relative timestamps)"

So I have only kept the second test of such pairs.

Change-Id: I075df21ed9c03495ab516d3870ccf7b63276d3ce
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1407
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
tests/cli/test_trimmer.in

index 249fffa60aeab01dddffa4f3c4b8ec97e44fa38b..6918cdad10c33b32cee8c2482a8c29b2f8ab2dbc 100644 (file)
 
 TRACE_PATH="${BT_CTF_TRACES}/succeed/wk-heartbeat-u/"
 
-NUM_TESTS=44
+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 a trace with the trimmer enabled (GMT relative timestamps)"
-
-"${BT_BIN}" --clock-gmt --begin 17:48:17.587029529 "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin (GMT relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 18
-ok $? "Received ${cnt}/18 events (GMT relative timestamps)"
-
-"${BT_BIN}" --clock-gmt --end 17:48:17.588680018 "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --end (GMT relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 9
-ok $? "Received ${cnt}/9 events (GMT relative timestamps)"
-
-"${BT_BIN}" --clock-gmt --begin 17:48:17.587029529 --end 17:48:17.588680018 \
-       "${TRACE_PATH}" 2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin and --end (GMT relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 7
-ok $? "Received ${cnt}/7 events (GMT relative timestamps)"
-
-"${BT_BIN}" --clock-gmt --begin 18:48:17.587029529 "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin out of range (GMT relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 0
-ok $? "No events when begin is out of range (GMT relative timestamps)"
-
-"${BT_BIN}" --clock-gmt --end 16:48:17.588680018 "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --end out of range (GMT relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 0
-ok $? "No events when end is out of range (GMT relative timestamps)"
-
-
-"${BT_BIN}" --clock-gmt --begin "2012-10-29 17:48:17.587029529" --end "2012-10-29 17:48:17.588680018" \
-       "${TRACE_PATH}" >/dev/null 2>&1
-ok $? "Read a trace with the trimmer enabled (GMT absolute timestamps)"
-
-"${BT_BIN}" --clock-gmt --begin "2012-10-29 17:48:17.587029529" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin (GMT absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 18
-ok $? "Received ${cnt}/18 events (GMT absolute timestamps)"
-
-"${BT_BIN}" --clock-gmt --end "2012-10-29 17:48:17.588680018" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --end (GMT absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 9
-ok $? "Received ${cnt}/9 events (GMT absolute timestamps)"
-
-"${BT_BIN}" --clock-gmt --begin "2012-10-29 17:48:17.587029529" --end "2012-10-29 17:48:17.588680018" \
-       "${TRACE_PATH}" 2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin and --end (GMT absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 7
-ok $? "Received ${cnt}/7 events (GMT absolute timestamps)"
-
-"${BT_BIN}" --clock-gmt --begin "2012-10-29 18:48:17.587029529" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin out of range (GMT absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 0
-ok $? "No events when begin is out of range (GMT absolute timestamps)"
-
-"${BT_BIN}" --clock-gmt --end "2012-10-29 16:48:17.588680018" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --end out of range (GMT absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 0
-ok $? "No events when end is out of range (GMT absolute timestamps)"
-
+# 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}")
+       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
 
-"${BT_BIN}" --begin "12:48:17.587029529" --end "12:48:17.588680018" \
-       "${TRACE_PATH}" >/dev/null 2>&1
-ok $? "Read a trace with the trimmer enabled (EST relative timestamps)"
-
-"${BT_BIN}" --begin "12:48:17.587029529" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin (EST relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 18
-ok $? "Received ${cnt}/18 events (EST relative timestamps)"
-
-"${BT_BIN}" --end "12:48:17.588680018" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --end (EST relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 9
-ok $? "Received ${cnt}/9 events (EST relative timestamps)"
-
-"${BT_BIN}" --begin "12:48:17.587029529" --end "12:48:17.588680018" \
-       "${TRACE_PATH}" 2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin and --end (EST relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 7
-ok $? "Received ${cnt}/7 events (EST relative timestamps)"
-
-"${BT_BIN}" --begin "13:48:17.587029529" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin out of range (EST relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 0
-ok $? "No events when begin is out of range (EST relative timestamps)"
-
-"${BT_BIN}" --end "11:48:17.588680018" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --end out of range (EST relative timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 0
-ok $? "No events when end is out of range (EST relative timestamps)"
-
-
-"${BT_BIN}" --begin "2012-10-29 12:48:17.587029529" --end "2012-10-29 12:48:17.588680018" \
-       "${TRACE_PATH}" >/dev/null 2>&1
-ok $? "Read a trace with the trimmer enabled (EST absolute timestamps)"
-
-"${BT_BIN}" --begin "2012-10-29 12:48:17.587029529" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin (EST absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 18
-ok $? "Received ${cnt}/18 events (EST absolute timestamps)"
-
-"${BT_BIN}" --end "2012-10-29 12:48:17.588680018" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --end (EST absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 9
-ok $? "Received ${cnt}/9 events (EST absolute timestamps)"
-
-"${BT_BIN}" --begin "2012-10-29 12:48:17.587029529" --end "2012-10-29 12:48:17.588680018" \
-       "${TRACE_PATH}" 2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin and --end (EST absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 7
-ok $? "Received ${cnt}/7 events (EST absolute timestamps)"
-
-"${BT_BIN}" --begin "2012-10-29 13:48:17.587029529" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --begin out of range (EST absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 0
-ok $? "No events when begin is out of range (EST absolute timestamps)"
-
-"${BT_BIN}" --end "2012-10-29 11:48:17.588680018" "${TRACE_PATH}" \
-       2>/dev/null >"${tmp_out}"
-ok $? "Ran successfully with --end out of range (EST absolute timestamps)"
-cnt=$(wc -l < "${tmp_out}")
-test $cnt == 0
-ok $? "No events when end is out of range (EST absolute timestamps)"
+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}"
This page took 0.027702 seconds and 4 git commands to generate.