| 1 | #!/bin/bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | # |
| 5 | # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com> |
| 6 | # Copyright (C) 2019 Francis Deslauriers <francis.deslauriers@efficios.com> |
| 7 | # |
| 8 | |
| 9 | SH_TAP=1 |
| 10 | |
| 11 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
| 12 | UTILSSH="$BT_TESTS_SRCDIR/utils/utils.sh" |
| 13 | else |
| 14 | UTILSSH="$(dirname "$0")/../../../utils/utils.sh" |
| 15 | fi |
| 16 | |
| 17 | # shellcheck source=../../../utils/utils.sh |
| 18 | source "$UTILSSH" |
| 19 | |
| 20 | this_dir_relative="plugins/src.ctf.fs/query" |
| 21 | succeed_trace_dir="$BT_CTF_TRACES_PATH/succeed" |
| 22 | expect_dir="$BT_TESTS_DATADIR/$this_dir_relative" |
| 23 | |
| 24 | test_query_metadata_info() { |
| 25 | local name="$1" |
| 26 | local ret=0 |
| 27 | local trace_path="$succeed_trace_dir/$name" |
| 28 | local expected_stdout="$expect_dir/metadata-info-$name.expect" |
| 29 | local temp_stdout_output_file |
| 30 | local temp_stderr_output_file |
| 31 | local query=("query" "src.ctf.fs" "metadata-info" "--params" "path=\"$trace_path\"") |
| 32 | |
| 33 | temp_stdout_output_file="$(mktemp -t actual_stdout.XXXXXX)" |
| 34 | temp_stderr_output_file="$(mktemp -t actual_stderr.XXXXXX)" |
| 35 | |
| 36 | bt_cli "$temp_stdout_output_file" "$temp_stderr_output_file" \ |
| 37 | "${query[@]}" |
| 38 | |
| 39 | bt_diff "$expected_stdout" "$temp_stdout_output_file" |
| 40 | ret_stdout=$? |
| 41 | |
| 42 | bt_diff /dev/null "$temp_stderr_output_file" |
| 43 | ret_stderr=$? |
| 44 | |
| 45 | if ((ret_stdout != 0 || ret_stderr != 0)); then |
| 46 | ret=1 |
| 47 | fi |
| 48 | |
| 49 | ok $ret "Trace '$name' \`metadata-info\` query gives the expected output" |
| 50 | rm -f "$temp_stdout_output_file" "$temp_stderr_output_file" |
| 51 | } |
| 52 | |
| 53 | test_non_existent_trace_dir() { |
| 54 | local empty_dir |
| 55 | local stdout_file |
| 56 | local stderr_file |
| 57 | local query |
| 58 | |
| 59 | empty_dir=$(mktemp -d) |
| 60 | stdout_file="$(mktemp -t actual_stdout.XXXXXX)" |
| 61 | stderr_file="$(mktemp -t actual_stderr.XXXXXX)" |
| 62 | query=("query" "src.ctf.fs" "metadata-info" "--params" "path=\"$empty_dir\"") |
| 63 | |
| 64 | bt_cli "$stdout_file" "$stderr_file" \ |
| 65 | "${query[@]}" |
| 66 | isnt $? 0 "non existent trace dir: babeltrace exits with an error" |
| 67 | |
| 68 | bt_diff "/dev/null" "${stdout_file}" |
| 69 | ok $? "non existent trace dir: babeltrace produces the expected stdout" |
| 70 | |
| 71 | grep --silent "^CAUSED BY " "${stderr_file}" |
| 72 | ok $? "non existent trace dir: babeltrace produces an error stack" |
| 73 | |
| 74 | grep --silent "Failed to open metadata file: No such file or directory: path=\".*metadata\"" \ |
| 75 | "${stderr_file}" |
| 76 | ok $? "non existent trace dir: babeltrace produces the expected error message" |
| 77 | |
| 78 | rm -f "${stdout_file}" "${stderr_file}" |
| 79 | } |
| 80 | |
| 81 | plan_tests 5 |
| 82 | test_query_metadata_info succeed1 |
| 83 | test_non_existent_trace_dir |