On 6/9/2026 2:47 PM, Pierrick Bouvier wrote: > 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. > > Signed-off-by: Pierrick Bouvier <[email protected]> > --- > tests/tcg/meson.build | 9 ++++++++- > tests/tcg/scripts/run_and_diff.sh | 12 ++++++++++++ > 2 files changed, 20 insertions(+), 1 deletion(-) > create mode 100755 tests/tcg/scripts/run_and_diff.sh > > diff --git a/tests/tcg/meson.build b/tests/tcg/meson.build > index 5380a360830..3d2c0d6583b 100644 > --- a/tests/tcg/meson.build > +++ b/tests/tcg/meson.build > @@ -7,6 +7,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: > @@ -24,6 +25,7 @@ tcg_tests = {} > # 'test_name': ['provide an alternative test name'], > # 'cflags': ['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'...], > @@ -84,7 +86,7 @@ foreach target, plan: tcg_tests > foreach src, setup: t > # return a clear error if user mispell a setup entry > foreach key, _ : setup > - if key not in ['cflags', 'qemu_args', 'gdb_test', > + if key not in ['cflags', 'qemu_args', 'expected_output', 'gdb_test', > 'exe_name', 'test_name', 'env_var', 'plugin_test', > 'wrapper'] > error('unknown tcg setup entry \'' + key + '\' for test ' + src) > @@ -197,6 +199,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..d1e9243c49d > --- /dev/null > +++ b/tests/tcg/scripts/run_and_diff.sh > @@ -0,0 +1,12 @@ > +#!/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 > +set -x > +diff <("$@") $expected
Fixed this line, since it hides return code of program. Write to a temporary file, then diff.
