tests: add and use bt_grep_ok
[babeltrace.git] / tests / plugins / src.ctf.fs / fail / test-fail.sh
CommitLineData
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
11SH_TAP=1
12
75e396f6 13if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
29a8227a
SM
14 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
15else
16 UTILSSH="$(dirname "$0")/../../../utils/utils.sh"
17fi
18
19# shellcheck source=../../../utils/utils.sh
20source "$UTILSSH"
21
22fail_trace_dir="$BT_CTF_TRACES_PATH/fail"
23
7132b838
PP
24stdout_file=$(mktemp -t test-ctf-fail-stdout.XXXXXX)
25stderr_file=$(mktemp -t test-ctf-fail-stderr.XXXXXX)
cbca1c06 26data_dir="${BT_TESTS_SRCDIR}/data/plugins/src.ctf.fs/fail"
29a8227a
SM
27
28test_fail() {
29 local name="$1"
cbca1c06
SM
30 local expected_stdout_file="$2"
31 local expected_error_msg="$3"
29a8227a
SM
32
33 bt_cli "${stdout_file}" "${stderr_file}" \
cbca1c06 34 -c sink.text.details -p "with-trace-name=no,with-stream-name=no" "${fail_trace_dir}/${name}"
29a8227a
SM
35 isnt $? 0 "Trace ${name}: babeltrace exits with an error"
36
cbca1c06
SM
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.
db01f759
SM
44 bt_grep_ok \
45 "^CAUSED BY " \
46 "$stderr_file" \
47 "Trace $name: babeltrace produces an error stack"
48
49 bt_grep_ok \
50 "$expected_error_msg" \
51 "$stderr_file" \
52 "Trace $name: babeltrace produces the expected error message"
29a8227a
SM
53}
54
55
ab003dc0 56plan_tests 20
cbca1c06
SM
57
58test_fail \
59 "invalid-packet-size/trace" \
60 "/dev/null" \
61 "Failed to index CTF stream file '.*channel0_3'"
29a8227a 62
cbca1c06
SM
63test_fail \
64 "valid-events-then-invalid-events" \
65 "${data_dir}/valid-events-then-invalid-events.expect" \
66 "No event class with ID of event class ID to use in stream class: .*stream-class-id=0, event-class-id=255"
29a8227a 67
dfa664f9
SM
68test_fail \
69 "metadata-syntax-error" \
70 "/dev/null" \
71 "^ At line 3 in metadata stream: syntax error, unexpected CTF_RSBRAC: token=\"]\""
72
ab003dc0
SM
73test_fail \
74 "invalid-sequence-length-field-class" \
75 "/dev/null" \
76 "Sequence field class's length field class is not an unsigned integer field class: "
77
78test_fail \
79 "invalid-variant-selector-field-class" \
80 "/dev/null" \
81 "Variant field class's tag field class is not an enumeration field class: "
82
29a8227a 83rm -f "${stdout_file}" "${stderr_file}"
This page took 0.052563 seconds and 4 git commands to generate.