| 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 [ -n "${BT_TESTS_SRCDIR:-}" ]; 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 | stdout_file=$(mktemp -t test-ctf-fail-stdout.XXXXXX) |
| 23 | stderr_file=$(mktemp -t test-ctf-fail-stderr.XXXXXX) |
| 24 | data_dir="${BT_TESTS_SRCDIR}/data/plugins/src.ctf.fs/fail" |
| 25 | |
| 26 | # Parameters: <trace-name> <ctf-version> |
| 27 | fail_trace_path() { |
| 28 | local name="$1" |
| 29 | local ctf_version="$2" |
| 30 | |
| 31 | echo "$BT_CTF_TRACES_PATH/$ctf_version/fail/$name" |
| 32 | } |
| 33 | |
| 34 | # Parameters: <trace-name> <ctf-version> <method> <expected-stdout-file> <expected-error-msg> |
| 35 | # |
| 36 | # <method> can be either "autodisc" or "component". "autodisc" passes the trace |
| 37 | # path directly to babeltrace2, making it use the auto-discovery mechanism. |
| 38 | # "component" instantiates a `src.ctf.fs` component explicitly. |
| 39 | test_fail_method() { |
| 40 | local name="$1" |
| 41 | local ctf_version="$2" |
| 42 | local method="$3" |
| 43 | local expected_stdout_file="$4" |
| 44 | local expected_error_msg="$5" |
| 45 | local trace_path |
| 46 | |
| 47 | trace_path=$(fail_trace_path "$name" "$ctf_version") |
| 48 | |
| 49 | if [ "$method" = "autodisc" ]; then |
| 50 | bt_cli "${stdout_file}" "${stderr_file}" \ |
| 51 | -c sink.text.details -p "with-trace-name=no,with-stream-name=no" "$trace_path" |
| 52 | elif [ "$method" = "component" ]; then |
| 53 | bt_cli "${stdout_file}" "${stderr_file}" \ |
| 54 | -c sink.text.details -p "with-trace-name=no,with-stream-name=no" -c src.ctf.fs -p "inputs=[\"$(bt_maybe_cygpath_m "$trace_path")\"]" |
| 55 | else |
| 56 | echo "invalid method: $method" |
| 57 | exit 1 |
| 58 | fi |
| 59 | isnt $? 0 "Trace ${name}: method $method: babeltrace exits with an error" |
| 60 | |
| 61 | bt_diff "${expected_stdout_file}" "${stdout_file}" |
| 62 | ok $? "Trace ${name}: method $method: babeltrace produces the expected stdout" |
| 63 | |
| 64 | # The expected error message will likely be found in the error stream |
| 65 | # even if Babeltrace aborts (e.g. hits an assert). Check that the |
| 66 | # Babeltrace CLI finishes gracefully by checking that the error stream |
| 67 | # contains an error stack printed by the CLI. |
| 68 | bt_grep_ok \ |
| 69 | "^CAUSED BY " \ |
| 70 | "$stderr_file" \ |
| 71 | "Trace ${name}: method $method: babeltrace produces an error stack" |
| 72 | |
| 73 | bt_grep_ok \ |
| 74 | "$expected_error_msg" \ |
| 75 | "$stderr_file" \ |
| 76 | "Trace ${name}: method $method: babeltrace produces the expected error message" |
| 77 | } |
| 78 | |
| 79 | # Parameters: <trace-name> <ctf-version> <expected-stdout-file> <expected-error-msg> |
| 80 | test_fail() { |
| 81 | local name="$1" |
| 82 | local ctf_version="$2" |
| 83 | local expected_stdout_file="$3" |
| 84 | local expected_error_msg="$4" |
| 85 | for method in autodisc component; do |
| 86 | test_fail_method "$name" "$ctf_version" "$method" \ |
| 87 | "$expected_stdout_file" "$expected_error_msg" |
| 88 | done |
| 89 | } |
| 90 | |
| 91 | plan_tests 64 |
| 92 | |
| 93 | test_fail \ |
| 94 | "invalid-packet-size/trace" \ |
| 95 | 1 \ |
| 96 | "/dev/null" \ |
| 97 | "Failed to index CTF stream file '.*channel0_3'" |
| 98 | |
| 99 | test_fail \ |
| 100 | "valid-events-then-invalid-events/trace" \ |
| 101 | 1 \ |
| 102 | "${data_dir}/valid-events-then-invalid-events.expect" \ |
| 103 | "At 24 bits: no event record class exists with ID 255 within the data stream class with ID 0." |
| 104 | |
| 105 | test_fail \ |
| 106 | "metadata-syntax-error" \ |
| 107 | 1 \ |
| 108 | "/dev/null" \ |
| 109 | "^ At line 3 in metadata stream: syntax error, unexpected CTF_RSBRAC: token=\"]\"" |
| 110 | |
| 111 | test_fail \ |
| 112 | "invalid-sequence-length-field-class" \ |
| 113 | 1 \ |
| 114 | "/dev/null" \ |
| 115 | "Sequence field class's length field class is not an unsigned integer field class: " |
| 116 | |
| 117 | test_fail \ |
| 118 | "invalid-variant-selector-field-class" \ |
| 119 | 1 \ |
| 120 | "/dev/null" \ |
| 121 | "Variant field class's tag field class is not an enumeration field class: " |
| 122 | |
| 123 | test_fail \ |
| 124 | "incomplete-packet-header" \ |
| 125 | 1 \ |
| 126 | "/dev/null" \ |
| 127 | "Insufficient data in file to fulfill request" |
| 128 | |
| 129 | test_fail \ |
| 130 | "meta-no-trace-cls-no-stream-cls" \ |
| 131 | 2 \ |
| 132 | "/dev/null" \ |
| 133 | "Missing data stream class fragment in metadata stream." |
| 134 | |
| 135 | test_fail \ |
| 136 | "meta-no-trace-cls-no-stream-cls" \ |
| 137 | 2 \ |
| 138 | "/dev/null" \ |
| 139 | "Missing data stream class fragment in metadata stream." |
| 140 | |
| 141 | rm -f "${stdout_file}" "${stderr_file}" |