From 22703f66b1011d07a5afb1ae5b766784158f27bd Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Thu, 8 Aug 2019 11:09:11 -0400 Subject: [PATCH] tests: add bt_cli util function 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1837 Tested-by: jenkins Reviewed-by: Philippe Proulx --- tests/utils/utils.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 97de1c73..5691721b 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -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 -- 2.34.1