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
36 echo "$args" |
xargs "$BT_BIN" 2>/dev
/null
>"$temp_output_file"
38 # Compare output with expected output
39 if ! diff "$temp_output_file" "$expected_file" 2>/dev
/null
>"$temp_diff"; then
40 echo "ERROR: for '$args': actual and expected outputs differ:" >&2
42 rm -rf "$temp_output_file" "$temp_diff"
46 rm -f "$temp_output_file" "$temp_diff"
49 # Checks the difference between:
51 # 1. What the CLI outputs when given the arguments:
53 # "$1" -c sink.text.details $3
55 # 2. The file with path "$2".
57 # Parameter 3 is optional.
59 # Returns 0 if there's no difference, and 1 if there is, also printing
60 # said difference to the standard error.
61 bt_diff_details_ctf_single
() {
67 extra_details_args
="$3"
70 # Compare using the CLI with `sink.text.details`
71 bt_diff_cli
"\"$trace_dir\" -c sink.text.details $extra_details_args" "$expected_file"
74 # Calls bt_diff_details_ctf_single(), except that "$1" is the path to a
75 # program which generates the CTF trace to compare to. The program "$1"
76 # receives the path to a temporary, empty directory where to write the
77 # CTF trace as its first argument.
78 bt_diff_details_ctf_gen_single
() {
79 ctf_gen_prog_path
="$1"
84 extra_details_args
="$3"
87 temp_trace_dir
="$(mktemp -d)"
89 # Run the CTF trace generator program to get a CTF trace
90 if ! "$ctf_gen_prog_path" "$temp_trace_dir" 2>/dev
/null
; then
91 echo "ERROR: \"$ctf_gen_prog_path\" \"$temp_trace_dir\" failed" >&2
92 rm -rf "$temp_trace_dir"
96 # Compare using the CLI with `sink.text.details`
97 bt_diff_details_ctf_single
"$temp_trace_dir" "$expected_file" "$extra_details_args"
99 rm -rf "$temp_trace_dir"