| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2019 EfficiOS Inc. |
| 6 | # |
| 7 | |
| 8 | # This test validates that a `src.ctf.fs` component handles gracefully invalid |
| 9 | # CTF traces and produces the expected error message. |
| 10 | |
| 11 | SH_TAP=1 |
| 12 | |
| 13 | if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then |
| 14 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
| 15 | else |
| 16 | UTILSSH="$(dirname "$0")/../../../utils/utils.sh" |
| 17 | fi |
| 18 | |
| 19 | # shellcheck source=../../../utils/utils.sh |
| 20 | source "$UTILSSH" |
| 21 | |
| 22 | fail_trace_dir="$BT_CTF_TRACES_PATH/fail" |
| 23 | |
| 24 | stdout_file=$(mktemp -t test_ctf_fail_stdout.XXXXXX) |
| 25 | stderr_file=$(mktemp -t test_ctf_fail_stderr.XXXXXX) |
| 26 | data_dir="${BT_TESTS_SRCDIR}/data/plugins/src.ctf.fs/fail" |
| 27 | |
| 28 | test_fail() { |
| 29 | local name="$1" |
| 30 | local expected_stdout_file="$2" |
| 31 | local expected_error_msg="$3" |
| 32 | |
| 33 | bt_cli "${stdout_file}" "${stderr_file}" \ |
| 34 | -c sink.text.details -p "with-trace-name=no,with-stream-name=no" "${fail_trace_dir}/${name}" |
| 35 | isnt $? 0 "Trace ${name}: babeltrace exits with an error" |
| 36 | |
| 37 | bt_diff "${expected_stdout_file}" "${stdout_file}" |
| 38 | ok $? "Trace ${name}: babeltrace produces the expected stdout" |
| 39 | |
| 40 | # The expected error message will likely be found in the error stream |
| 41 | # even if Babeltrace aborts (e.g. hits an assert). Check that the |
| 42 | # Babeltrace CLI finishes gracefully by checking that the error stream |
| 43 | # contains an error stack printed by the CLI. |
| 44 | grep --silent "^CAUSED BY " "${stderr_file}" |
| 45 | ok $? "Trace ${name}: babeltrace produces an error stack" |
| 46 | |
| 47 | grep --silent "${expected_error_msg}" "${stderr_file}" |
| 48 | ok $? "Trace ${name}: babeltrace produces the expected error message" |
| 49 | } |
| 50 | |
| 51 | |
| 52 | plan_tests 8 |
| 53 | |
| 54 | test_fail \ |
| 55 | "invalid-packet-size/trace" \ |
| 56 | "/dev/null" \ |
| 57 | "Failed to index CTF stream file '.*channel0_3'" |
| 58 | |
| 59 | test_fail \ |
| 60 | "valid-events-then-invalid-events" \ |
| 61 | "${data_dir}/valid-events-then-invalid-events.expect" \ |
| 62 | "No event class with ID of event class ID to use in stream class: .*stream-class-id=0, event-class-id=255" |
| 63 | |
| 64 | rm -f "${stdout_file}" "${stderr_file}" |