Commit | Line | Data |
---|---|---|
b34bfe00 FD |
1 | #!/bin/bash |
2 | # | |
0235b0db MJ |
3 | # SPDX-License-Identifier: GPL-2.0-only |
4 | # | |
b34bfe00 FD |
5 | # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com> |
6 | # Copyright (C) 2019 Francis Deslauriers <francis.deslauriers@efficios.com> | |
7 | # | |
b34bfe00 FD |
8 | |
9 | SH_TAP=1 | |
10 | ||
75e396f6 | 11 | if [ -n "${BT_TESTS_SRCDIR:-}" ]; then |
b34bfe00 FD |
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" | |
b34bfe00 FD |
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" | |
ba9ea7f5 SM |
29 | local temp_stdout_output_file |
30 | local temp_stderr_output_file | |
b34bfe00 FD |
31 | local query=("query" "src.ctf.fs" "metadata-info" "--params" "path=\"$trace_path\"") |
32 | ||
7132b838 PP |
33 | temp_stdout_output_file="$(mktemp -t actual-stdout.XXXXXX)" |
34 | temp_stderr_output_file="$(mktemp -t actual-stderr.XXXXXX)" | |
ba9ea7f5 | 35 | |
b34bfe00 FD |
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 | ||
0ac40cd4 SM |
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) | |
7132b838 PP |
60 | stdout_file="$(mktemp -t actual-stdout.XXXXXX)" |
61 | stderr_file="$(mktemp -t actual-stderr.XXXXXX)" | |
0ac40cd4 SM |
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 | ||
454605f1 | 81 | plan_tests 7 |
b34bfe00 | 82 | test_query_metadata_info succeed1 |
0ac40cd4 | 83 | test_non_existent_trace_dir |
454605f1 MJ |
84 | test_query_metadata_info lf-metadata |
85 | test_query_metadata_info crlf-metadata |