src.ctf.lttng-live: remove some goto error-handling
[babeltrace.git] / tests / plugins / src.ctf.fs / test_deterministic_ordering
1 #!/bin/bash
2 #
3 # SPDX-License-Identifier: GPL-2.0-only
4 #
5 # Copyright (C) 2019 Efficios, Inc.
6 #
7
8 # Test the deterministic behavior of the src.ctf.fs component versus the
9 # ordering of the given input paths.
10 #
11 # In presence of multiple copies of the same packet, we want it to pick the
12 # copy of the packet to read in a deterministic fashion.
13 #
14 # This test is written assuming the specific implementation of the src.ctf.fs
15 # component class, which sorts its input paths lexicographically.
16 #
17 # There are three traces (a-corrupted, b-not-corrupted and c-corrupted) with the
18 # same UUID and the same packet, except that this packet is corrupted in
19 # a-corrupted and c-corrupted. In these cases, there is an event with an
20 # invalid id. When reading these corrupted packets, we expect babeltrace to
21 # emit an error.
22 #
23 # When reading a-corrupted and b-not-corrupted together, the copy of the packet
24 # from a-corrupted is read, and babeltrace exits with an error.
25 #
26 # When reading b-not-corrupted and c-corrupted together, the copy of the packet
27 # from b-not-corrupted is read, and babeltrace executes successfully.
28
29 SH_TAP=1
30
31 if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
32 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
33 else
34 UTILSSH="$(dirname "$0")/../../utils/utils.sh"
35 fi
36
37 # shellcheck source=../../utils/utils.sh
38 source "$UTILSSH"
39
40 traces_dir="${BT_CTF_TRACES_PATH}/deterministic-ordering"
41 trace_a_corrupted="${traces_dir}/a-corrupted"
42 trace_b_not_corrupted="${traces_dir}/b-not-corrupted"
43 trace_c_corrupted="${traces_dir}/c-corrupted"
44
45 if [ "$BT_TESTS_OS_TYPE" = "mingw" ]; then
46 # The MSYS2 shell makes a mess trying to convert the Unix-like paths
47 # to Windows-like paths, so just disable the automatic conversion and
48 # do it by hand.
49 export MSYS2_ARG_CONV_EXCL="*"
50 trace_a_corrupted=$(cygpath -m "${trace_a_corrupted}")
51 trace_b_not_corrupted=$(cygpath -m "${trace_b_not_corrupted}")
52 trace_c_corrupted=$(cygpath -m "${trace_c_corrupted}")
53 fi
54
55 stdout_file=$(mktemp -t test_deterministic_ordering_stdout.XXXXXX)
56 stderr_file=$(mktemp -t test_deterministic_ordering_stderr.XXXXXX)
57
58 expect_failure() {
59 local test_name
60 local inputs
61
62 test_name="$1"
63 inputs="$2"
64
65 bt_cli "${stdout_file}" "${stderr_file}" \
66 -c src.ctf.fs -p "inputs=[${inputs}]"
67 isnt 0 "$?" "${test_name}: exit status is not 0"
68
69 grep --silent "^ERROR: " "${stderr_file}"
70 ok "$?" "${test_name}: error stack is produced"
71
72 grep --silent "No event class with ID of event class ID to use in stream class" "${stderr_file}"
73 ok "$?" "${test_name}: expected error message is present"
74 }
75
76 expect_success() {
77 local test_name
78 local inputs
79
80 test_name="$1"
81 inputs="$2"
82
83 bt_cli "${stdout_file}" "${stderr_file}" \
84 -c src.ctf.fs -p "inputs=[${inputs}]" \
85 -c sink.text.details -p 'with-trace-name=no,with-stream-name=no,with-metadata=no,compact=yes'
86 ok "$?" "${test_name}: exit status is 0"
87
88 bt_diff "${traces_dir}/b-c.expect" "${stdout_file}"
89 ok "$?" "${test_name}: expected output is produced"
90 }
91
92 plan_tests 10
93
94 # Trace with corrupted packet comes first lexicographically, expect a failure.
95
96 expect_failure "ab" "\"${trace_a_corrupted}\",\"${trace_b_not_corrupted}\""
97 expect_failure "ba" "\"${trace_b_not_corrupted}\",\"${trace_a_corrupted}\""
98
99 # Trace with non-corrupted packet comes first lexicographically, expect a success.
100
101 expect_success "bc" "\"${trace_b_not_corrupted}\",\"${trace_c_corrupted}\""
102 expect_success "cb" "\"${trace_c_corrupted}\",\"${trace_b_not_corrupted}\""
103
104 rm -f "${stdout_file}" "${stderr_file}"
This page took 0.031395 seconds and 4 git commands to generate.