3 # Copyright (C) 2019 - Philippe Proulx <pproulx@efficios.com>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; only version 2
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 .
"@abs_top_builddir@/tests/utils/common.sh"
21 # Checks the difference between:
23 # 1. What the CLI outputs when given the arguments "$1" (passed to
24 # `xargs`, so they can include quoted arguments).
25 # 2. The file with path "$2".
27 # Returns 0 if there's no difference, and 1 if there is, also printing
28 # said difference to the standard error.
32 temp_output_file
="$(mktemp)"
35 # Run the CLI to get a detailed file. Strip any \r present due to
36 # Windows (\n -> \r\n). "diff --string-trailing-cr" is not used since it
37 # is not present on Solaris.
38 echo "$args" |
xargs "$BT_BIN" 2>/dev
/null |
tr -d "\r" > "$temp_output_file"
40 # Compare output with expected output
41 if ! diff "$temp_output_file" "$expected_file" 2>/dev
/null
>"$temp_diff"; then
42 echo "ERROR: for '$args': actual and expected outputs differ:" >&2
44 rm -rf "$temp_output_file" "$temp_diff"
48 rm -f "$temp_output_file" "$temp_diff"
51 # Checks the difference between:
53 # 1. What the CLI outputs when given the arguments:
55 # "$1" -c sink.text.details $3
57 # 2. The file with path "$2".
59 # Parameter 3 is optional.
61 # Returns 0 if there's no difference, and 1 if there is, also printing
62 # said difference to the standard error.
63 bt_diff_details_ctf_single
() {
69 extra_details_args
="$3"
72 # Compare using the CLI with `sink.text.details`
73 bt_diff_cli
"\"$trace_dir\" -c sink.text.details $extra_details_args" "$expected_file"
76 # Calls bt_diff_details_ctf_single(), except that "$1" is the path to a
77 # program which generates the CTF trace to compare to. The program "$1"
78 # receives the path to a temporary, empty directory where to write the
79 # CTF trace as its first argument.
80 bt_diff_details_ctf_gen_single
() {
81 ctf_gen_prog_path
="$1"
86 extra_details_args
="$3"
89 temp_trace_dir
="$(mktemp -d)"
91 # Run the CTF trace generator program to get a CTF trace
92 if ! "$ctf_gen_prog_path" "$temp_trace_dir" 2>/dev
/null
; then
93 echo "ERROR: \"$ctf_gen_prog_path\" \"$temp_trace_dir\" failed" >&2
94 rm -rf "$temp_trace_dir"
98 # Compare using the CLI with `sink.text.details`
99 bt_diff_details_ctf_single
"$temp_trace_dir" "$expected_file" "$extra_details_args"
101 rm -rf "$temp_trace_dir"