tests: add bt_cli util function
authorSimon Marchi <simon.marchi@efficios.com>
Thu, 8 Aug 2019 15:09:11 +0000 (11:09 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 12 Aug 2019 02:19:51 +0000 (22:19 -0400)
Add a function that simply runs the CLI, redirecting stdout and
stderr to the specified files.  This will allow more flexible tests than
the existing "diff" function.

Change-Id: I8319c4a74a0baa3b40afb871bfb0605ac81c3270
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1837
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
tests/utils/utils.sh

index 97de1c735fe498a8fadcf0c8d79212e7ba821c04..5691721be67969d966dcd3cfea14db79afed52c6 100644 (file)
@@ -134,6 +134,22 @@ export BT_TESTS_SED_BIN
 BT_TESTS_DATADIR="${BT_TESTS_SRCDIR}/data"
 BT_CTF_TRACES_PATH="${BT_TESTS_DATADIR}/ctf-traces"
 
+# Run the Babeltrace CLI, redirecting stdout and stderr to specified files.
+#
+#   $1: file to redirect stdout to
+#   $2: file to redirect stderr to
+#   remaining args: arguments to pass to the CLI
+#
+# Return the exit code of the CLI.
+
+bt_cli() {
+       local stdout_file="$1"
+       local stderr_file="$2"
+       shift 2
+       local args=("$@")
+
+       run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$stdout_file" 2>"$stderr_file"
+}
 
 ### Diff Functions ###
 
@@ -214,7 +230,7 @@ bt_diff_cli() {
        temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
 
        # Run the CLI to get a detailed file.
-       run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$temp_stdout_output_file" 2>"$temp_stderr_output_file"
+       bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" "${args[@]}"
 
        bt_diff "$expected_stdout_file" "$temp_stdout_output_file" "$expected_stderr_file" "$temp_stderr_output_file" "${args[@]}"
        ret=$?
@@ -252,7 +268,7 @@ bt_diff_cli_sorted() {
        temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)"
 
        # Run the CLI to get a detailed file.
-       run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$temp_stdout_output_file" 2>"$temp_stderr_output_file"
+       bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" "${args[@]}"
 
        # Sort the stdout file, use a subshell to do it in-place
        # shellcheck disable=SC2005
This page took 0.026413 seconds and 4 git commands to generate.