X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Futils%2Futils.sh;h=e2b730923685828301a158ecbba35a19e3fc1402;hb=faf5c654855a7a42093e43c4c739bb69dd2375d3;hp=6107a610453e3dff10cfe3138cb556a2ebee113d;hpb=75e396f6b20bdf52c76a3c7312e7fb815ac1e5e9;p=babeltrace.git diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 6107a610..e2b73092 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -111,6 +111,8 @@ if [ -z "${BT_TESTS_PYTHON_BIN:-}" ]; then fi export BT_TESTS_PYTHON_BIN +BT_TESTS_PYTHON_VERSION=$($BT_TESTS_PYTHON_BIN -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))') + if [ -z "${BT_TESTS_PYTHON_CONFIG_BIN:-}" ]; then BT_TESTS_PYTHON_CONFIG_BIN="python3-config" fi @@ -151,7 +153,7 @@ fi # Remove CR characters in file "$1". bt_remove_cr() { - "$BT_TESTS_SED_BIN" -i 's/\r//g' "$1" + "$BT_TESTS_SED_BIN" -i'' -e 's/\r//g' "$1" } # Run the Babeltrace CLI, redirecting stdout and stderr to specified files. @@ -226,8 +228,8 @@ bt_diff_cli() { local ret_stdout local ret_stderr - temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)" - temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)" + temp_stdout_output_file="$(mktemp -t actual-stdout.XXXXXX)" + temp_stderr_output_file="$(mktemp -t actual-stderr.XXXXXX)" # Run the CLI to get a detailed file. bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" "${args[@]}" @@ -302,38 +304,50 @@ check_coverage() { coverage run "$@" } +# Execute a shell command in the appropriate environment to access the Python +# test utility modules in `tests/utils/python`. +run_python() { + local our_pythonpath="${BT_TESTS_SRCDIR}/utils/python" + + if [[ $BT_TESTS_PYTHON_VERSION =~ 3.[45] ]]; then + # Add a local directory containing a `typing.py` to `PYTHONPATH` for + # Python 3.4 which doesn't offer the `typing` module. + our_pythonpath="$our_pythonpath:${BT_TESTS_SRCDIR}/utils/python/typing" + fi + + PYTHONPATH="${our_pythonpath}${PYTHONPATH:+:}${PYTHONPATH:-}" "$@" +} + # Execute a shell command in the appropriate environment to have access to the # bt2 Python bindings. run_python_bt2() { - local env_args local lib_asan - - env_args=( - "BABELTRACE_PYTHON_BT2_NO_TRACEBACK=1" \ - "BABELTRACE_PLUGIN_PATH=${BT_TESTS_BABELTRACE_PLUGIN_PATH}" \ - "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR=${BT_TESTS_PROVIDER_DIR}" \ - "BT_TESTS_DATADIR=${BT_TESTS_DATADIR}" \ - "BT_CTF_TRACES_PATH=${BT_CTF_TRACES_PATH}" \ - "BT_PLUGINS_PATH=${BT_PLUGINS_PATH}" \ - "PYTHONPATH=${BT_TESTS_PYTHONPATH}:${BT_TESTS_SRCDIR}/utils/python" - ) + local -x "BABELTRACE_PYTHON_BT2_NO_TRACEBACK=1" + 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 "BT_PLUGINS_PATH=${BT_PLUGINS_PATH}" + local -x "PYTHONPATH=${BT_TESTS_PYTHONPATH}${PYTHONPATH:+:}${PYTHONPATH:-}" local main_lib_path="${BT_TESTS_BUILDDIR}/../src/lib/.libs" # Set the library search path so the python interpreter can load libbabeltrace2 if [ "$BT_TESTS_OS_TYPE" = "mingw" ] || [ "$BT_TESTS_OS_TYPE" = "cygwin" ]; then - env_args+=("PATH=${main_lib_path}:${PATH:-}") + local -x PATH="${main_lib_path}${PATH:+:}${PATH:-}" elif [ "$BT_TESTS_OS_TYPE" = "darwin" ]; then - env_args+=("DYLD_LIBRARY_PATH=${main_lib_path}:${DYLD_LIBRARY_PATH:-}") + local -x DYLD_LIBRARY_PATH="${main_lib_path}${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH:-}" else - env_args+=("LD_LIBRARY_PATH=${main_lib_path}:${LD_LIBRARY_PATH:-}") + local -x LD_LIBRARY_PATH="${main_lib_path}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH:-}" fi # On Windows, an embedded Python interpreter needs a way to locate the path - # to it's internal modules, set the prefix from python-config to the + # to its internal modules, set the prefix from python-config to the # PYTHONHOME variable. if [ "$BT_TESTS_OS_TYPE" = "mingw" ]; then - env_args+=("PYTHONHOME=$($BT_TESTS_PYTHON_CONFIG_BIN --prefix)") + local -x PYTHONHOME + + PYTHONHOME=$($BT_TESTS_PYTHON_CONFIG_BIN --prefix) fi # If AddressSanitizer is used, we must preload libasan.so so that @@ -344,13 +358,15 @@ run_python_bt2() { # existing ASAN_OPTIONS, such that we override the user's value if it # contains detect_leaks=1. if [ "${BT_TESTS_ENABLE_ASAN:-}" = "1" ]; then - lib_asan=$(${BT_TESTS_CC_BIN} -print-file-name=libasan.so) + if ${BT_TESTS_CC_BIN} --version | head -n 1 | grep -q '^gcc'; then + lib_asan="$(${BT_TESTS_CC_BIN} -print-file-name=libasan.so)" + local -x LD_PRELOAD="${lib_asan}${LD_PRELOAD:+:}${LD_PRELOAD:-}" + fi - env_args+=("LD_PRELOAD=${lib_asan}:${LD_PRELOAD:-}") - env_args+=("ASAN_OPTIONS=${ASAN_OPTIONS:-},detect_leaks=0") + local -x "ASAN_OPTIONS=${ASAN_OPTIONS:-}${ASAN_OPTIONS:+,}detect_leaks=0" fi - env "${env_args[@]}" "$@" + run_python "$@" } # Set the environment and run python tests in the directory. @@ -393,3 +409,16 @@ run_python_bt2_test() { return $ret } + +# Generate a CTF trace using `mctf.py`. +# +# $1: Input filename +# $2: Base directory path for output files +gen_mctf_trace() { + local input_file="$1" + local base_dir="$2" + + diag "Running: ${BT_TESTS_PYTHON_BIN} ${BT_TESTS_SRCDIR}/utils/python/mctf.py --base-dir ${base_dir} ${input_file}" + run_python "${BT_TESTS_PYTHON_BIN}" "${BT_TESTS_SRCDIR}/utils/python/mctf.py" \ + --base-dir "${base_dir}" "${input_file}" +}