tests: src.ctf.fs: add test for metadata with invalid syntax
[babeltrace.git] / tests / plugins / src.ctf.fs / fail / test_fail
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
13if [ "x${BT_TESTS_SRCDIR:-}" != "x" ]; then
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
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.
44 grep --silent "^CAUSED BY " "${stderr_file}"
45 ok $? "Trace ${name}: babeltrace produces an error stack"
46
29a8227a
SM
47 grep --silent "${expected_error_msg}" "${stderr_file}"
48 ok $? "Trace ${name}: babeltrace produces the expected error message"
49}
50
51
dfa664f9 52plan_tests 12
cbca1c06
SM
53
54test_fail \
55 "invalid-packet-size/trace" \
56 "/dev/null" \
57 "Failed to index CTF stream file '.*channel0_3'"
29a8227a 58
cbca1c06
SM
59test_fail \
60 "valid-events-then-invalid-events" \
61 "${data_dir}/valid-events-then-invalid-events.expect" \
62 "No event class with ID of event class ID to use in stream class: .*stream-class-id=0, event-class-id=255"
29a8227a 63
dfa664f9
SM
64test_fail \
65 "metadata-syntax-error" \
66 "/dev/null" \
67 "^ At line 3 in metadata stream: syntax error, unexpected CTF_RSBRAC: token=\"]\""
68
29a8227a 69rm -f "${stdout_file}" "${stderr_file}"
This page took 0.039828 seconds and 4 git commands to generate.