#!/bin/sh # Copyright (C) 2019 - Philippe Proulx # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; only version 2 # of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. . "@abs_top_builddir@/tests/utils/common.sh" # Checks the difference between: # # 1. What the CLI outputs when given the arguments "$1" (passed to # `xargs`, so they can include quoted arguments). # 2. The file with path "$2". # # Returns 0 if there's no difference, and 1 if there is, also printing # said difference to the standard error. bt_diff_cli() { args="$1" expected_file="$2" temp_output_file="$(mktemp)" temp_diff="$(mktemp)" # Run the CLI to get a detailed file. Strip any \r present due to # Windows (\n -> \r\n). "diff --string-trailing-cr" is not used since it # is not present on Solaris. echo "$args" | xargs "$BT_BIN" 2>/dev/null | tr -d "\r" > "$temp_output_file" # Compare output with expected output if ! diff "$temp_output_file" "$expected_file" 2>/dev/null >"$temp_diff"; then echo "ERROR: for '$args': actual and expected outputs differ:" >&2 cat "$temp_diff" >&2 rm -rf "$temp_output_file" "$temp_diff" return 1 fi rm -f "$temp_output_file" "$temp_diff" } # Checks the difference between: # # 1. What the CLI outputs when given the arguments: # # "$1" -c sink.text.details $3 # # 2. The file with path "$2". # # Parameter 3 is optional. # # Returns 0 if there's no difference, and 1 if there is, also printing # said difference to the standard error. bt_diff_details_ctf_single() { trace_dir="$1" expected_file="$2" extra_details_args="" if [ $# -ge 3 ]; then extra_details_args="$3" fi # Compare using the CLI with `sink.text.details` bt_diff_cli "\"$trace_dir\" -c sink.text.details $extra_details_args" "$expected_file" } # Calls bt_diff_details_ctf_single(), except that "$1" is the path to a # program which generates the CTF trace to compare to. The program "$1" # receives the path to a temporary, empty directory where to write the # CTF trace as its first argument. bt_diff_details_ctf_gen_single() { ctf_gen_prog_path="$1" expected_file="$2" extra_details_args="" if [ $# -ge 3 ]; then extra_details_args="$3" fi temp_trace_dir="$(mktemp -d)" # Run the CTF trace generator program to get a CTF trace if ! "$ctf_gen_prog_path" "$temp_trace_dir" 2>/dev/null; then echo "ERROR: \"$ctf_gen_prog_path\" \"$temp_trace_dir\" failed" >&2 rm -rf "$temp_trace_dir" return 1 fi # Compare using the CLI with `sink.text.details` bt_diff_details_ctf_single "$temp_trace_dir" "$expected_file" "$extra_details_args" ret=$? rm -rf "$temp_trace_dir" return $ret }