tests: add and use bt_grep_ok
[babeltrace.git] / tests / plugins / src.ctf.fs / test-deterministic-ordering.sh
CommitLineData
7b69723d
SM
1#!/bin/bash
2#
0235b0db 3# SPDX-License-Identifier: GPL-2.0-only
7b69723d 4#
0235b0db 5# Copyright (C) 2019 Efficios, Inc.
7b69723d 6#
7b69723d
SM
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
29SH_TAP=1
30
75e396f6 31if [ -n "${BT_TESTS_SRCDIR:-}" ]; then
7b69723d
SM
32 UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh"
33else
34 UTILSSH="$(dirname "$0")/../../utils/utils.sh"
35fi
36
26ab3283 37# shellcheck source=../../utils/utils.sh
7b69723d
SM
38source "$UTILSSH"
39
40traces_dir="${BT_CTF_TRACES_PATH}/deterministic-ordering"
41trace_a_corrupted="${traces_dir}/a-corrupted"
42trace_b_not_corrupted="${traces_dir}/b-not-corrupted"
43trace_c_corrupted="${traces_dir}/c-corrupted"
44
a0baab4a 45if [ "$BT_TESTS_OS_TYPE" = "mingw" ]; then
7b69723d
SM
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}")
53fi
54
7132b838
PP
55stdout_file=$(mktemp -t test-deterministic-ordering-stdout.XXXXXX)
56stderr_file=$(mktemp -t test-deterministic-ordering-stderr.XXXXXX)
7b69723d
SM
57
58expect_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
db01f759
SM
69 bt_grep_ok \
70 "^ERROR: " \
71 "${stderr_file}" \
72 "${test_name}: error stack is produced"
73
74 bt_grep_ok \
75 "No event class with ID of event class ID to use in stream class" \
76 "$stderr_file" \
77 "$test_name: expected error message is present"
7b69723d
SM
78}
79
80expect_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
96plan_tests 10
97
98# Trace with corrupted packet comes first lexicographically, expect a failure.
99
100expect_failure "ab" "\"${trace_a_corrupted}\",\"${trace_b_not_corrupted}\""
101expect_failure "ba" "\"${trace_b_not_corrupted}\",\"${trace_a_corrupted}\""
102
103# Trace with non-corrupted packet comes first lexicographically, expect a success.
104
105expect_success "bc" "\"${trace_b_not_corrupted}\",\"${trace_c_corrupted}\""
106expect_success "cb" "\"${trace_c_corrupted}\",\"${trace_b_not_corrupted}\""
107
108rm -f "${stdout_file}" "${stderr_file}"
This page took 0.046885 seconds and 4 git commands to generate.