X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=tests%2Futils%2Futils.sh;h=7f1a4368008e977b846bf84f49bbbbc4f3e9cfb1;hb=95d759169cca3518352f539b6f87726b8cbb48e4;hp=9f5adf5aef66bb6d0c9f15dedbdba6143c2bc2f5;hpb=7747a39ff4d33f722737ff57a1a3b69cca97909a;p=babeltrace.git diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index 9f5adf5a..7f1a4368 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -153,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. @@ -228,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[@]}" @@ -297,6 +297,33 @@ bt_diff_details_ctf_gen_single() { return $ret } +# Run the grep binary configured for the tests. +bt_grep() { + "$BT_TESTS_GREP_BIN" "$@" +} + +# ok() with the test name `$3` on the result of bt_grep() matching the +# pattern `$1` within the file `$2`. +bt_grep_ok() { + local pattern=$1 + local file=$2 + local test_name=$3 + + bt_grep --silent "$pattern" "$file" + + local ret=$? + + if ! ok $ret "$test_name"; then + { + echo "Pattern \`$pattern\` doesn't match the contents of \`$file\`:" + echo '--- 8< ---' + cat "$file" + echo '--- >8 ---' + } >&2 + fi + + return $ret +} ### Functions ### @@ -309,7 +336,7 @@ check_coverage() { run_python() { local our_pythonpath="${BT_TESTS_SRCDIR}/utils/python" - if [[ $BT_TESTS_PYTHON_VERSION = 3.4 ]]; then + 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" @@ -358,7 +385,7 @@ 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 - if ${BT_TESTS_CC_BIN} --version | head -n 1 | grep -q '^gcc'; then + if ${BT_TESTS_CC_BIN} --version | head -n 1 | bt_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 @@ -409,3 +436,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}" +}