| 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}/1/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 | bt_grep_ok \ |
| 70 | "^ERROR: " \ |
| 71 | "${stderr_file}" \ |
| 72 | "${test_name}: error stack is produced" |
| 73 | |
| 74 | bt_grep_ok \ |
| 75 | "At 48 bits: no event record class exists with ID 255 within the data stream class with ID 0." \ |
| 76 | "$stderr_file" \ |
| 77 | "$test_name: expected error message is present" |
| 78 | } |
| 79 | |
| 80 | expect_success() { |
| 81 | local test_name |
| 82 | local inputs |
| 83 | |
| 84 | test_name="$1" |
| 85 | inputs="$2" |
| 86 | |
| 87 | bt_cli "${stdout_file}" "${stderr_file}" \ |
| 88 | -c src.ctf.fs -p "inputs=[${inputs}]" \ |
| 89 | -c sink.text.details -p 'with-trace-name=no,with-stream-name=no,with-metadata=no,compact=yes' |
| 90 | ok "$?" "${test_name}: exit status is 0" |
| 91 | |
| 92 | bt_diff "${traces_dir}/b-c.expect" "${stdout_file}" |
| 93 | ok "$?" "${test_name}: expected output is produced" |
| 94 | } |
| 95 | |
| 96 | plan_tests 10 |
| 97 | |
| 98 | # Trace with corrupted packet comes first lexicographically, expect a failure. |
| 99 | |
| 100 | expect_failure "ab" "\"${trace_a_corrupted}\",\"${trace_b_not_corrupted}\"" |
| 101 | expect_failure "ba" "\"${trace_b_not_corrupted}\",\"${trace_a_corrupted}\"" |
| 102 | |
| 103 | # Trace with non-corrupted packet comes first lexicographically, expect a success. |
| 104 | |
| 105 | expect_success "bc" "\"${trace_b_not_corrupted}\",\"${trace_c_corrupted}\"" |
| 106 | expect_success "cb" "\"${trace_c_corrupted}\",\"${trace_b_not_corrupted}\"" |
| 107 | |
| 108 | rm -f "${stdout_file}" "${stderr_file}" |