port: Use sig_t instead of sighandler_t
[babeltrace.git] / tests / utils / diff.sh.in
1 #!/bin/sh
2
3 # Copyright (C) 2019 - Philippe Proulx <pproulx@efficios.com>
4 #
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
8 # of the License.
9 #
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.
14 #
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.
18
19 . "@abs_top_builddir@/tests/utils/common.sh"
20
21 # Checks the difference between:
22 #
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".
26 #
27 # Returns 0 if there's no difference, and 1 if there is, also printing
28 # said difference to the standard error.
29 bt_diff_cli() {
30 args="$1"
31 expected_file="$2"
32 temp_output_file="$(mktemp)"
33 temp_diff="$(mktemp)"
34
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"
39
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
43 cat "$temp_diff" >&2
44 rm -rf "$temp_output_file" "$temp_diff"
45 return 1
46 fi
47
48 rm -f "$temp_output_file" "$temp_diff"
49 }
50
51 # Checks the difference between:
52 #
53 # 1. What the CLI outputs when given the arguments:
54 #
55 # "$1" -c sink.text.details $3
56 #
57 # 2. The file with path "$2".
58 #
59 # Parameter 3 is optional.
60 #
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() {
64 trace_dir="$1"
65 expected_file="$2"
66 extra_details_args=""
67
68 if [ $# -ge 3 ]; then
69 extra_details_args="$3"
70 fi
71
72 # Compare using the CLI with `sink.text.details`
73 bt_diff_cli "\"$trace_dir\" -c sink.text.details $extra_details_args" "$expected_file"
74 }
75
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"
82 expected_file="$2"
83 extra_details_args=""
84
85 if [ $# -ge 3 ]; then
86 extra_details_args="$3"
87 fi
88
89 temp_trace_dir="$(mktemp -d)"
90
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"
95 return 1
96 fi
97
98 # Compare using the CLI with `sink.text.details`
99 bt_diff_details_ctf_single "$temp_trace_dir" "$expected_file" "$extra_details_args"
100 ret=$?
101 rm -rf "$temp_trace_dir"
102 return $ret
103 }
This page took 0.0316 seconds and 4 git commands to generate.