Commit | Line | Data |
---|---|---|
29a8227a SM |
1 | #!/bin/bash |
2 | # | |
0235b0db | 3 | # SPDX-License-Identifier: GPL-2.0-only |
29a8227a | 4 | # |
0235b0db | 5 | # Copyright (C) 2019 EfficiOS Inc. |
29a8227a | 6 | # |
29a8227a SM |
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 | ||
75e396f6 | 13 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
29a8227a SM |
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 | ||
29a8227a SM |
22 | stdout_file=$(mktemp -t test_ctf_fail_stdout.XXXXXX) |
23 | stderr_file=$(mktemp -t test_ctf_fail_stderr.XXXXXX) | |
cbca1c06 | 24 | data_dir="${BT_TESTS_SRCDIR}/data/plugins/src.ctf.fs/fail" |
29a8227a | 25 | |
24e7f4d6 SM |
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 | ||
24d6c55b SM |
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() { | |
29a8227a | 40 | local name="$1" |
24d6c55b SM |
41 | local ctf_version="$2" |
42 | local method="$3" | |
43 | local expected_stdout_file="$4" | |
44 | local expected_error_msg="$5" | |
24e7f4d6 SM |
45 | local trace_path |
46 | ||
47 | trace_path=$(fail_trace_path "$name" "$ctf_version") | |
29a8227a | 48 | |
24d6c55b SM |
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=[\"$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" | |
29a8227a | 60 | |
cbca1c06 | 61 | bt_diff "${expected_stdout_file}" "${stdout_file}" |
24d6c55b | 62 | ok $? "Trace ${name}: method $method: babeltrace produces the expected stdout" |
cbca1c06 SM |
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 | grep --silent "^CAUSED BY " "${stderr_file}" | |
24d6c55b | 69 | ok $? "Trace ${name}: method $method: babeltrace produces an error stack" |
cbca1c06 | 70 | |
29a8227a | 71 | grep --silent "${expected_error_msg}" "${stderr_file}" |
24d6c55b | 72 | ok $? "Trace ${name}: method $method: babeltrace produces the expected error message" |
29a8227a SM |
73 | } |
74 | ||
24d6c55b SM |
75 | # Parameters: <trace-name> <ctf-version> <expected-stdout-file> <expected-error-msg> |
76 | test_fail() { | |
77 | local name="$1" | |
78 | local ctf_version="$2" | |
79 | local expected_stdout_file="$3" | |
80 | local expected_error_msg="$4" | |
81 | for method in autodisc component; do | |
82 | test_fail_method "$name" "$ctf_version" "$method" \ | |
83 | "$expected_stdout_file" "$expected_error_msg" | |
84 | done | |
85 | } | |
29a8227a | 86 | |
ba3fb998 | 87 | plan_tests 40 |
cbca1c06 SM |
88 | |
89 | test_fail \ | |
90 | "invalid-packet-size/trace" \ | |
24e7f4d6 | 91 | 1 \ |
cbca1c06 SM |
92 | "/dev/null" \ |
93 | "Failed to index CTF stream file '.*channel0_3'" | |
29a8227a | 94 | |
cbca1c06 | 95 | test_fail \ |
24d6c55b | 96 | "valid-events-then-invalid-events/trace" \ |
24e7f4d6 | 97 | 1 \ |
cbca1c06 | 98 | "${data_dir}/valid-events-then-invalid-events.expect" \ |
75b1d744 | 99 | "At 24 bits: no event record class exists with ID 255 within the data stream class with ID 0." |
29a8227a | 100 | |
dfa664f9 SM |
101 | test_fail \ |
102 | "metadata-syntax-error" \ | |
24e7f4d6 | 103 | 1 \ |
dfa664f9 SM |
104 | "/dev/null" \ |
105 | "^ At line 3 in metadata stream: syntax error, unexpected CTF_RSBRAC: token=\"]\"" | |
106 | ||
ba3fb998 SM |
107 | test_fail \ |
108 | "meta-no-trace-cls-no-stream-cls" \ | |
109 | 2 \ | |
110 | "/dev/null" \ | |
111 | "Missing data stream class fragment in metadata stream." | |
112 | ||
113 | test_fail \ | |
114 | "meta-no-trace-cls-no-stream-cls" \ | |
115 | 2 \ | |
116 | "/dev/null" \ | |
117 | "Missing data stream class fragment in metadata stream." | |
118 | ||
29a8227a | 119 | rm -f "${stdout_file}" "${stderr_file}" |