397c5e0233d4b60a1b15c4a38efe01ab680a237b
[babeltrace.git] / tests / plugins / src.ctf.fs / fail / test_fail
1 #!/bin/bash
2 #
3 # Copyright (C) 2019 EfficiOS Inc.
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; only version 2
8 # of the License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 # This test validates that a `src.ctf.fs` component handles gracefully invalid
20 # CTF traces and produces the expected error message.
21
22 SH_TAP=1
23
24 if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
25 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
26 else
27 UTILSSH="$(dirname "$0")/../../../utils/utils.sh"
28 fi
29
30 # shellcheck source=../../../utils/utils.sh
31 source "$UTILSSH"
32
33 fail_trace_dir="$BT_CTF_TRACES_PATH/fail"
34
35 stdout_file=$(mktemp -t test_ctf_fail_stdout.XXXXXX)
36 stderr_file=$(mktemp -t test_ctf_fail_stderr.XXXXXX)
37 data_dir="${BT_TESTS_SRCDIR}/data/plugins/src.ctf.fs/fail"
38
39 test_fail() {
40 local name="$1"
41 local expected_stdout_file="$2"
42 local expected_error_msg="$3"
43
44 bt_cli "${stdout_file}" "${stderr_file}" \
45 -c sink.text.details -p "with-trace-name=no,with-stream-name=no" "${fail_trace_dir}/${name}"
46 isnt $? 0 "Trace ${name}: babeltrace exits with an error"
47
48 bt_diff "${expected_stdout_file}" "${stdout_file}"
49 ok $? "Trace ${name}: babeltrace produces the expected stdout"
50
51 # The expected error message will likely be found in the error stream
52 # even if Babeltrace aborts (e.g. hits an assert). Check that the
53 # Babeltrace CLI finishes gracefully by checking that the error stream
54 # contains an error stack printed by the CLI.
55 grep --silent "^CAUSED BY " "${stderr_file}"
56 ok $? "Trace ${name}: babeltrace produces an error stack"
57
58 grep --silent "${expected_error_msg}" "${stderr_file}"
59 ok $? "Trace ${name}: babeltrace produces the expected error message"
60 }
61
62
63 plan_tests 8
64
65 test_fail \
66 "invalid-packet-size/trace" \
67 "/dev/null" \
68 "Failed to index CTF stream file '.*channel0_3'"
69
70 test_fail \
71 "valid-events-then-invalid-events" \
72 "${data_dir}/valid-events-then-invalid-events.expect" \
73 "No event class with ID of event class ID to use in stream class: .*stream-class-id=0, event-class-id=255"
74
75 rm -f "${stdout_file}" "${stderr_file}"
This page took 0.0311 seconds and 3 git commands to generate.