+ # If AddressSanitizer is used, we must preload `libasan.so` so that
+ # libasan doesn't complain about not being the first loaded library.
+ #
+ # Python and sed (executed as part of the Libtool wrapper) produce
+ # some leaks, so we must unfortunately disable leak detection.
+ #
+ # Append it to existing `ASAN_OPTIONS` variable, such that we
+ # 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
+ local -r lib_asan=$("$BT_TESTS_CC_BIN" -print-file-name=libasan.so)
+ local -x LD_PRELOAD=$lib_asan${LD_PRELOAD:+:}${LD_PRELOAD:-}
+ fi
+
+ local -x ASAN_OPTIONS=${ASAN_OPTIONS:-}${ASAN_OPTIONS:+,}detect_leaks=0
+ fi
+
+ bt_run_in_py_utils_env "$@"
+}
+
+# Runs the Python tests matching the pattern `$2` (optional, `*` if
+# missing) in the directory `$1` using `testrunner.py`.
+#
+# This function uses bt_run_in_py_env(), therefore such tests can import
+# the testing Python modules (in `tests/utils/python`) and the `bt2`
+# Python package.
+bt_run_py_test() {
+ local -r test_dir=$1
+ local -r test_pattern=${2:-*}
+ local python_exec
+
+ if [[ ${BT_TESTS_COVERAGE:-} == 1 ]]; then
+ python_exec=_bt_tests_check_coverage