| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2019 Philippe Proulx <pproulx@efficios.com> |
| 6 | # |
| 7 | |
| 8 | # This test validates that a `src.ctf.fs` component successfully reads |
| 9 | # specific CTF traces and creates the expected messages. |
| 10 | # |
| 11 | # Such CTF traces to open either exist (in `tests/ctf-traces/succeed`) |
| 12 | # or are generated by this test using local trace generators. |
| 13 | |
| 14 | SH_TAP=1 |
| 15 | |
| 16 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
| 17 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
| 18 | else |
| 19 | UTILSSH="$(dirname "$0")/../../../utils/utils.sh" |
| 20 | fi |
| 21 | |
| 22 | # shellcheck source=../../../utils/utils.sh |
| 23 | source "$UTILSSH" |
| 24 | |
| 25 | this_dir_relative="plugins/sink.ctf.fs/succeed" |
| 26 | this_dir_build="$BT_TESTS_BUILDDIR/$this_dir_relative" |
| 27 | expect_dir="$BT_TESTS_DATADIR/$this_dir_relative" |
| 28 | succeed_traces="$BT_CTF_TRACES_PATH/succeed" |
| 29 | |
| 30 | test_ctf_single() { |
| 31 | local name="$1" |
| 32 | local in_trace_dir="$2" |
| 33 | local temp_out_trace_dir |
| 34 | |
| 35 | temp_out_trace_dir="$(mktemp -d)" |
| 36 | |
| 37 | diag "Converting trace '$name' to CTF through 'sink.ctf.fs'" |
| 38 | "$BT_TESTS_BT2_BIN" >/dev/null "$in_trace_dir" -o ctf -w "$temp_out_trace_dir" |
| 39 | ret=$? |
| 40 | ok $ret "'sink.ctf.fs' component succeeds with input trace '$name'" |
| 41 | converted_test_name="Converted trace '$name' gives the expected output" |
| 42 | |
| 43 | if [ $ret -eq 0 ]; then |
| 44 | bt_diff_details_ctf_single "$expect_dir/trace-$name.expect" \ |
| 45 | "$temp_out_trace_dir" \ |
| 46 | '-p' 'with-uuid=no,with-trace-name=no,with-stream-name=no' |
| 47 | ok $? "$converted_test_name" |
| 48 | else |
| 49 | fail "$converted_test_name" |
| 50 | fi |
| 51 | |
| 52 | rm -rf "$temp_out_trace_dir" |
| 53 | } |
| 54 | |
| 55 | test_ctf_existing_single() { |
| 56 | local name="$1" |
| 57 | local trace_dir="$succeed_traces/$name" |
| 58 | |
| 59 | test_ctf_single "$name" "$trace_dir" |
| 60 | } |
| 61 | |
| 62 | test_ctf_gen_single() { |
| 63 | local name="$1" |
| 64 | local temp_gen_trace_dir |
| 65 | |
| 66 | temp_gen_trace_dir="$(mktemp -d)" |
| 67 | |
| 68 | diag "Generating trace '$name'" |
| 69 | |
| 70 | if ! "$this_dir_build/gen-trace-$name" "$temp_gen_trace_dir"; then |
| 71 | # this is not part of the test itself; it must not fail |
| 72 | echo "ERROR: \"$this_dir_build/gen-trace-$name" "$temp_gen_trace_dir\" failed" >&2 |
| 73 | rm -rf "$temp_gen_trace_dir" |
| 74 | exit 1 |
| 75 | fi |
| 76 | |
| 77 | test_ctf_single "$name" "$temp_gen_trace_dir" |
| 78 | rm -rf "$temp_gen_trace_dir" |
| 79 | } |
| 80 | |
| 81 | plan_tests 14 |
| 82 | |
| 83 | test_ctf_gen_single float |
| 84 | test_ctf_gen_single double |
| 85 | test_ctf_existing_single meta-variant-no-underscore |
| 86 | test_ctf_existing_single meta-variant-one-underscore |
| 87 | test_ctf_existing_single meta-variant-reserved-keywords |
| 88 | test_ctf_existing_single meta-variant-same-with-underscore |
| 89 | test_ctf_existing_single meta-variant-two-underscores |