3 # SPDX-License-Identifier: GPL-2.0-only
5 # Copyright (C) 2019 EfficiOS Inc.
8 # This test validates that a `src.ctf.fs` component handles gracefully invalid
9 # CTF traces and produces the expected error message.
13 if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
14 UTILSSH
="$BT_TESTS_SRCDIR/utils/utils.sh"
16 UTILSSH
="$(dirname "$0")/../../../utils/utils.sh"
19 # shellcheck source=../../../utils/utils.sh
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"
26 # Parameters: <trace-name> <ctf-version>
29 local ctf_version
="$2"
31 echo "$BT_CTF_TRACES_PATH/$ctf_version/fail/$name"
34 # Parameters: <trace-name> <ctf-version> <method> <expected-stdout-file> <expected-error-msg>
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.
41 local ctf_version
="$2"
43 local expected_stdout_file
="$4"
44 local expected_error_msg
="$5"
47 trace_path
=$
(fail_trace_path
"$name" "$ctf_version")
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")\"]"
56 echo "invalid method: $method"
59 isnt $?
0 "Trace ${name}: method $method: babeltrace exits with an error"
61 bt_diff
"${expected_stdout_file}" "${stdout_file}"
62 ok $?
"Trace ${name}: method $method: babeltrace produces the expected stdout"
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.
71 "Trace ${name}: method $method: babeltrace produces an error stack"
74 "$expected_error_msg" \
76 "Trace ${name}: method $method: babeltrace produces the expected error message"
79 # Parameters: <trace-name> <ctf-version> <expected-stdout-file> <expected-error-msg>
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"
94 "invalid-packet-size/trace" \
97 "Failed to index CTF stream file '.*channel0_3'"
100 "valid-events-then-invalid-events/trace" \
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."
106 "metadata-syntax-error" \
109 "^ At line 3 in metadata stream: syntax error, unexpected CTF_RSBRAC: token=\"]\""
112 "invalid-sequence-length-field-class" \
115 "Sequence field class's length field class is not an unsigned integer field class: "
118 "invalid-variant-selector-field-class" \
121 "Variant field class's tag field class is not an enumeration field class: "
124 "incomplete-packet-header" \
127 "Insufficient data in file to fulfill request"
130 "meta-no-trace-cls-no-stream-cls" \
133 "Missing data stream class fragment in metadata stream."
136 "meta-no-trace-cls-no-stream-cls" \
139 "Missing data stream class fragment in metadata stream."
141 rm -f "${stdout_file}" "${stderr_file}"