A test can declare it expects a specific output on stdout. In this case, we compare it to a reference file. We implement this instead of relying on a wrapper because we need the flexibility to resolve name of reference file per target.
For instance, multiarch float tests expect different ref files for each target, which is something we can't express with a test wrapper. Reviewed-by: Manos Pitsidianakis <[email protected]> Tested-by: Alex Bennée <[email protected]> Signed-off-by: Pierrick Bouvier <[email protected]> --- tests/tcg/meson.build | 12 ++++++++++-- tests/tcg/scripts/run_and_diff.sh | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100755 tests/tcg/scripts/run_and_diff.sh diff --git a/tests/tcg/meson.build b/tests/tcg/meson.build index 0311b2432e4..f5fd9bee7bc 100644 --- a/tests/tcg/meson.build +++ b/tests/tcg/meson.build @@ -6,6 +6,7 @@ if config_host.has_key('GDB') endif gdb = find_program(gdb_progs, required: false) prog_gdb_test = find_program('../guest-debug/run-test.py') +prog_run_and_diff = find_program('./scripts/run_and_diff.sh') tcg_tests = {} # tcg_tests is a dictionary with following structure: @@ -23,6 +24,7 @@ tcg_tests = {} # 'test_name': ['provide an alternative test name'], # 'cflags': ['additional cflags to compile test', ...], # 'qemu_args': ['qemu command line flags', ...], +# 'expected_output': 'file_to_compare_output', # 'gdb_test': ['gdb test args'], # 'env_var': ['VAR=value', ...], # 'wrapper': [program_to_launch_test, 'args'...], @@ -86,8 +88,9 @@ foreach target, plan: tcg_tests foreach src, setup: t # return a clear error if user misspell a setup entry foreach key, _ : setup - allowed = ['exe_name', 'env_var', 'cflags', 'gdb_test', 'plugin_test', - 'qemu_args', 'test_name', 'wrapper'] + allowed = ['exe_name', 'env_var', 'expected_output', 'cflags', + 'gdb_test', 'plugin_test', 'qemu_args', 'test_name', + 'wrapper'] if key not in allowed error('unknown tcg setup entry \'' + key + '\' for test ' + src + ' (possible: [' + ', '.join(allowed) + '])') @@ -201,6 +204,11 @@ foreach target, plan: tcg_tests ] endif + if 'expected_output' in setup + expected = files(folder / setup['expected_output']) + cmd = [prog_run_and_diff, expected, cmd] + endif + if 'wrapper' in setup cmd = [setup['wrapper'], cmd] endif diff --git a/tests/tcg/scripts/run_and_diff.sh b/tests/tcg/scripts/run_and_diff.sh new file mode 100755 index 00000000000..3e51cdc9663 --- /dev/null +++ b/tests/tcg/scripts/run_and_diff.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: GPL-2.0-or-later + +set -euo pipefail + +if [ $# -lt 2 ]; then + echo "run_and_diff: expected_output_file cmd [args]..." 1>&2 + exit 1 +fi +expected="$1";shift +output=$(mktemp) +trap "rm -rf $output" EXIT +set -x +"$@" |& tee $output +diff $output $expected -- 2.47.3
