scriptdir="$(dirname "${BASH_SOURCE[0]}")"
+# The OS on which we are running. See [1] for possible values of 'uname -s'.
+# We do a bit of translation to ease our life down the road for comparison.
+# Export it so that called executables can use it.
+# [1] https://en.wikipedia.org/wiki/Uname#Examples
+if [ "x${BT_OS_TYPE:-}" = "x" ]; then
+ BT_OS_TYPE="$(uname -s)"
+ case "$BT_OS_TYPE" in
+ MINGW*)
+ BT_OS_TYPE="mingw"
+ ;;
+ Darwin)
+ BT_OS_TYPE="darwin"
+ ;;
+ Linux)
+ BT_OS_TYPE="linux"
+ ;;
+ CYGWIN*)
+ BT_OS_TYPE="cygwin"
+ ;;
+ *)
+ BT_OS_TYPE="unsupported"
+ ;;
+ esac
+fi
+export BT_OS_TYPE
+
# Allow overriding the source and build directories
if [ "x${BT_TESTS_SRCDIR:-}" = "x" ]; then
BT_TESTS_SRCDIR="$scriptdir/.."
# the test script, define the 'SH_TAP' variable to '1' before sourcing this
# script.
if [ "x${SH_TAP:-}" = x1 ]; then
+ # shellcheck source=./tap/tap.sh
. "${BT_TESTS_SRCDIR}/utils/tap/tap.sh"
fi
# Allow overriding the babeltrace2 executables
if [ "x${BT_TESTS_BT2_BIN:-}" = "x" ]; then
BT_TESTS_BT2_BIN="$BT_TESTS_BUILDDIR/../src/cli/babeltrace2"
+ if [ "$BT_OS_TYPE" = "mingw" ]; then
+ BT_TESTS_BT2_BIN="${BT_TESTS_BT2_BIN}.exe"
+ fi
fi
export BT_TESTS_BT2_BIN
if [ "x${BT_TESTS_BT2LOG_BIN:-}" = "x" ]; then
BT_TESTS_BT2LOG_BIN="$BT_TESTS_BUILDDIR/../src/cli/babeltrace2-log"
+ if [ "$BT_OS_TYPE" = "mingw" ]; then
+ BT_TESTS_BT2LOG_BIN="${BT_TESTS_BT2LOG_BIN}.exe"
+ fi
fi
export BT_TESTS_BT2LOG_BIN
BT_TESTS_BABELTRACE_PLUGIN_PATH="${BT_PLUGINS_PATH}/ctf:${BT_PLUGINS_PATH}/utils:${BT_PLUGINS_PATH}/text"
fi
+if [ "x${BT_TESTS_PROVIDER_DIR:-}" = "x" ]; then
+ BT_TESTS_PROVIDER_DIR="${BT_TESTS_BUILDDIR}/../src/python-plugin-provider/.libs"
+fi
+
# Allow overriding the babeltrace2 executables
if [ "x${BT_TESTS_PYTHONPATH:-}" = "x" ]; then
BT_TESTS_PYTHONPATH="${BT_TESTS_BUILDDIR}/../src/bindings/python/bt2/build/build_lib"
# Checks the difference between:
#
-# 1. What the CLI outputs when given the arguments "$1" (passed to
-# `xargs`, so they can include quoted arguments).
-# 2. The file with path "$2".
+# 1. What the CLI outputs on its standard output when given the arguments
+# "$@" (excluding the first two arguments).
+# 2. The file with path "$1".
+#
+# And the difference between:
+#
+# 1. What the CLI outputs on its standard error when given the arguments
+# "$@" (excluding the first two arguments).
+# 2. The file with path "$2".
#
# Returns 0 if there's no difference, and 1 if there is, also printing
# said difference to the standard error.
bt_diff_cli() {
- local args="$1"
- local expected_file="$2"
- local temp_output_file
+ local expected_stdout_file="$1"
+ local expected_stderr_file="$2"
+ shift 2
+ local args=("$@")
+
+ local temp_stdout_output_file
+ local temp_stderr_output_file
local temp_diff
local ret=0
- temp_output_file="$(mktemp)"
+ temp_stdout_output_file="$(mktemp)"
+ temp_stderr_output_file="$(mktemp)"
temp_diff="$(mktemp)"
- # Run the CLI to get a detailed file. Strip any \r present due to
- # Windows (\n -> \r\n). "diff --string-trailing-cr" is not used since it
- # is not present on Solaris.
- echo "$args" | xargs "$BT_TESTS_BT2_BIN" 2>/dev/null | tr -d "\r" > "$temp_output_file"
+ # 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"
+
+ # Strip any \r present due to Windows (\n -> \r\n).
+ # "diff --string-trailing-cr" is not used since it is not present on
+ # Solaris.
+ "$BT_TESTS_SED_BIN" -i 's/\r//g' "$temp_stdout_output_file"
+ "$BT_TESTS_SED_BIN" -i 's/\r//g' "$temp_stderr_output_file"
- # Compare output with expected output
- if ! diff -u "$temp_output_file" "$expected_file" 2>/dev/null >"$temp_diff"; then
- echo "ERROR: for '$args': actual and expected outputs differ:" >&2
+ # Compare stdout output with expected stdout output
+ if ! diff -u "$temp_stdout_output_file" "$expected_stdout_file" 2>/dev/null >"$temp_diff"; then
+ echo "ERROR: for '${args[*]}': actual standard output and expected output differ:" >&2
cat "$temp_diff" >&2
ret=1
fi
- rm -f "$temp_output_file" "$temp_diff"
+ # Compare stderr output with expected stderr output
+ if ! diff -u "$temp_stderr_output_file" "$expected_stderr_file" 2>/dev/null >"$temp_diff"; then
+ echo "ERROR: for '${args[*]}': actual standard error and expected error differ:" >&2
+ cat "$temp_diff" >&2
+ ret=1
+ fi
+
+ rm -f "$temp_stdout_output_file" "$temp_stderr_output_file" "$temp_diff"
return $ret
}
-# Checks the difference between:
-#
-# 1. What the CLI outputs when given the arguments:
-#
-# "$1" -c sink.text.details $3
-#
-# 2. The file with path "$2".
-#
-# Parameter 3 is optional.
+# Checks the difference between the content of the file with path "$1"
+# and the output of the CLI when called on the directory path "$2" with
+# the arguments '-c sink.text.details' and the rest of the arguments to
+# this function.
#
# Returns 0 if there's no difference, and 1 if there is, also printing
# said difference to the standard error.
bt_diff_details_ctf_single() {
- local trace_dir="$1"
- local expected_file="$2"
- local extra_details_args="${3:-}"
+ local expected_stdout_file="$1"
+ local trace_dir="$2"
+ shift 2
+ local extra_details_args=("$@")
+ expected_stderr_file="/dev/null"
# Compare using the CLI with `sink.text.details`
- bt_diff_cli "\"$trace_dir\" -c sink.text.details $extra_details_args" "$expected_file"
+ bt_diff_cli "$expected_stdout_file" "$expected_stderr_file" "$trace_dir" "-c" "sink.text.details" "${extra_details_args[@]}"
}
# Calls bt_diff_details_ctf_single(), except that "$1" is the path to a
# CTF trace as its first argument.
bt_diff_details_ctf_gen_single() {
local ctf_gen_prog_path="$1"
- local expected_file="$2"
- local extra_details_args="${3:-}"
+ local expected_stdout_file="$2"
+ shift 2
+ local extra_details_args=("$@")
local temp_trace_dir
local ret
fi
# Compare using the CLI with `sink.text.details`
- bt_diff_details_ctf_single "$temp_trace_dir" "$expected_file" "$extra_details_args"
+ bt_diff_details_ctf_single "$expected_stdout_file" "$temp_trace_dir" "${extra_details_args[@]}"
ret=$?
rm -rf "$temp_trace_dir"
return $ret
local lib_search_var
local lib_search_path
- local python_provider_path="${BT_TESTS_BUILDDIR}/../src/python-plugin-provider/.libs"
local main_lib_path="${BT_TESTS_BUILDDIR}/../src/lib/.libs"
# Set the library search path so the python interpreter can load libbabeltrace2
- if [ "x${MSYSTEM:-}" != "x" ]; then
+ if [ "$BT_OS_TYPE" = "mingw" ] || [ "$BT_OS_TYPE" = "cygwin" ]; then
lib_search_var="PATH"
- lib_search_path="${python_provider_path}:${main_lib_path}:${PATH:-}"
+ lib_search_path="${main_lib_path}:${PATH:-}"
+ elif [ "$BT_OS_TYPE" = "darwin" ]; then
+ lib_search_var="DYLD_LIBRARY_PATH"
+ lib_search_path="${main_lib_path}:${DYLD_LIBRARY_PATH:-}"
else
lib_search_var="LD_LIBRARY_PATH"
- lib_search_path="${python_provider_path}:${main_lib_path}:${LD_LIBRARY_PATH:-}"
+ lib_search_path="${main_lib_path}:${LD_LIBRARY_PATH:-}"
fi
env \
BABELTRACE_PYTHON_BT2_NO_TRACEBACK=1 \
BABELTRACE_PLUGIN_PATH="${BT_TESTS_BABELTRACE_PLUGIN_PATH}" \
+ LIBBABELTRACE2_PLUGIN_PROVIDER_DIR=${BT_TESTS_PROVIDER_DIR} \
BT_CTF_TRACES_PATH="${BT_CTF_TRACES_PATH}" \
BT_PLUGINS_PATH="${BT_PLUGINS_PATH}" \
PYTHONPATH="${BT_TESTS_PYTHONPATH}:${BT_TESTS_SRCDIR}/utils/python" \
# $2 : The pattern to match python test script names (optional)
run_python_bt2_test() {
local test_dir="$1"
- local test_pattern="${2:-}" # optional
+ local test_pattern="${2:-'*'}" # optional, if none default to "*"
local ret
local test_runner_args=()
run_python_bt2 \
"${python_exec}" \
"${BT_TESTS_SRCDIR}/utils/python/testrunner.py" \
- "${test_runner_args[@]}"
+ --pattern "$test_pattern" \
+ "$test_dir" \
+
ret=$?
if test "x${BT_TESTS_COVERAGE_REPORT:-}" = "x1"; then