# run_python_bt2() to use it.
#
# TODO: Remove when `tests/bindings/python/bt2/test_plugin.py` is fixed.
# run_python_bt2() to use it.
#
# TODO: Remove when `tests/bindings/python/bt2/test_plugin.py` is fixed.
# Colon-separated list of project plugin paths, if not set
if [ -z "${BT_TESTS_BABELTRACE_PLUGIN_PATH:-}" ]; then
# Colon-separated list of project plugin paths, if not set
if [ -z "${BT_TESTS_BABELTRACE_PLUGIN_PATH:-}" ]; then
#
# This doesn't need to be exported, but it needs to remain set for
# run_python() to use it.
#
# This doesn't need to be exported, but it needs to remain set for
# run_python() to use it.
# Name of the `python3-config` command to use when testing, if not set
if [ -z "${BT_TESTS_PYTHON_CONFIG_BIN:-}" ]; then
# Name of the `python3-config` command to use when testing, if not set
if [ -z "${BT_TESTS_PYTHON_CONFIG_BIN:-}" ]; then
echo "Running: $BT_TESTS_BT2_BIN ${args[*]}" >&2
run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$stdout_file" 2>"$stderr_file"
echo "Running: $BT_TESTS_BT2_BIN ${args[*]}" >&2
run_python_bt2 "$BT_TESTS_BT2_BIN" "${args[@]}" 1>"$stdout_file" 2>"$stderr_file"
# Returns 0 if there's no difference, or 1 otherwise, also printing said
# difference to the standard error.
bt_diff_cli() {
# Returns 0 if there's no difference, or 1 otherwise, also printing said
# difference to the standard error.
bt_diff_cli() {
- local temp_stdout_output_file
- local temp_stderr_output_file
+ local -r temp_stdout_output_file="$(mktemp -t actual-stdout.XXXXXX)"
+ local -r temp_stderr_output_file="$(mktemp -t actual-stderr.XXXXXX)"
bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" "${args[@]}"
bt_diff "$expected_stdout_file" "$temp_stdout_output_file" "${args[@]}"
bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" "${args[@]}"
bt_diff "$expected_stdout_file" "$temp_stdout_output_file" "${args[@]}"
# Returns 0 if there's no difference, or 1 otherwise, also printing said
# difference to the standard error.
bt_diff_details_ctf_single() {
# Returns 0 if there's no difference, or 1 otherwise, also printing said
# difference to the standard error.
bt_diff_details_ctf_single() {
# The program `$1` receives the path to a temporary, empty directory
# where to write the CTF trace as its first argument.
bt_diff_details_ctf_gen_single() {
# The program `$1` receives the path to a temporary, empty directory
# where to write the CTF trace as its first argument.
bt_diff_details_ctf_gen_single() {
# Run the CTF trace generator program to get a CTF trace
if ! "$ctf_gen_prog_path" "$temp_trace_dir" 2>/dev/null; then
# Run the CTF trace generator program to get a CTF trace
if ! "$ctf_gen_prog_path" "$temp_trace_dir" 2>/dev/null; then
# Compare using the CLI with `sink.text.details`
bt_diff_details_ctf_single "$expected_stdout_file" "$temp_trace_dir" \
"${extra_details_args[@]+${extra_details_args[@]}}"
# Compare using the CLI with `sink.text.details`
bt_diff_details_ctf_single "$expected_stdout_file" "$temp_trace_dir" \
"${extra_details_args[@]+${extra_details_args[@]}}"
# ok() with the test name `$3` on the result of bt_grep() matching the
# pattern `$1` within the file `$2`.
bt_grep_ok() {
# ok() with the test name `$3` on the result of bt_grep() matching the
# pattern `$1` within the file `$2`.
bt_grep_ok() {
# Add a local directory containing a `typing.py` to `PYTHONPATH`
# for Python 3.4 and Python 3.5 which either don't offer the
# `typing` module at all, or offer a partial one.
# Add a local directory containing a `typing.py` to `PYTHONPATH`
# for Python 3.4 and Python 3.5 which either don't offer the
# `typing` module at all, or offer a partial one.
# Executes a command within an environment which can import the testing
# Python modules (in `tests/utils/python`) and the `bt2` Python package.
run_python_bt2() {
# Executes a command within an environment which can import the testing
# Python modules (in `tests/utils/python`) and the `bt2` Python package.
run_python_bt2() {
local -x "BABELTRACE_PLUGIN_PATH=${BT_TESTS_BABELTRACE_PLUGIN_PATH}"
local -x "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR=${BT_TESTS_PROVIDER_DIR}"
local -x "BT_TESTS_DATADIR=${BT_TESTS_DATADIR}"
local -x "BT_CTF_TRACES_PATH=${BT_CTF_TRACES_PATH}"
local -x "BABELTRACE_PLUGIN_PATH=${BT_TESTS_BABELTRACE_PLUGIN_PATH}"
local -x "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR=${BT_TESTS_PROVIDER_DIR}"
local -x "BT_TESTS_DATADIR=${BT_TESTS_DATADIR}"
local -x "BT_CTF_TRACES_PATH=${BT_CTF_TRACES_PATH}"
# override the user's value if it contains `detect_leaks=1`.
if [ "${BT_TESTS_ENABLE_ASAN:-}" = "1" ]; then
if "${BT_TESTS_CC_BIN}" --version | head -n 1 | bt_grep -q '^gcc'; then
# override the user's value if it contains `detect_leaks=1`.
if [ "${BT_TESTS_ENABLE_ASAN:-}" = "1" ]; then
if "${BT_TESTS_CC_BIN}" --version | head -n 1 | bt_grep -q '^gcc'; then