Skip to contentSkip to conversation

tests/tcg: run tests with meson

PATCH Superseded Pierrick Bouvier 6 participants 75 messages Jun 9 – Jun 26 Arm/Amlogic Meson SoC support

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover tests/tcg: run tests with meson

This series is an experiment to replace TCG tests makefiles with meson, with the goal of having something more readable and maintainable in the long term. Also it closes the gap that tcg tests had with the rest of tests, by integrating them with meson directly.

It covers all existing tests for aarch64 architecture, including user/system/multiarch-user/multiarch-system. I'll carry the effort to port all other architectures once we agree on a base. We agreed with Alex to not merge anything before all arch are covered.

Series first declare the global infrastructure, then add aarch64 and multiarch tests, and finally plugin tests.

For review, I would suggest to start with aarch64 patches (end of the series) to get an idea of what they will look like, before the implementation itself. You can also compare that to existing Makefiles, they follow the same order.

It implements all requirements listed on original thread [1], except cross container support, which can be easily added on top once we agree on the base.
[1] https://lore.kernel.org/qemu-devel/[email protected]/

We also have for free:
- correct and complete dependencies for any test, including:
scripts, c.inc, headers, reference files and binaries/plugins.
- catch test declaration issues at configure time vs test time.
- proper data types for variables instead of string expansion with make.
- we could now build tests binaries by default with 'all' target.
- hopefully, better readability to your taste.

Main ideas for the current design are:
- make arch files as simple and explicit as possible. If it conflicts, always pick explicit, as long as we don't expose meson details. remove any kind of "skip, override, filter" logic.
- never expose custom_target and meson details in arch files.
- catch any spelling mistake on test or any dependency.
- keep complexity contained in tests/tcg/meson.build.

Usage:

```
make check-tcg
make check-tcg-aarch64-linux-user
make check-tcg-aarch64-softmmu

from build folder:
./pyvenv/bin/meson test --list --suite tcg
ninja clean
./pyvenv/bin/meson test aarch64-softmmu-asid2 --verbose
```

Pierrick Bouvier (27):
tests/tcg/multiarch/system/memory.c: remove unused variable tests/tcg/multiarch/plugin/check-plugin-output.sh: take test output as
input
tests/tcg/multiarch/plugin: rename check-plugin-output to
regex-compare
tests/tcg: introduce meson.build
tests/tcg/meson.build: introduce exe_name tests/tcg/meson.build: introduce test_name tests/tcg/meson.build: introduce cflags tests/tcg/meson.build: introduce qemu_args tests/tcg/meson.build: introduce env_var tests/tcg/plugins: build list of test_plugins tests/tcg/meson.build: introduce plugin_test tests/tcg/meson.build: test gdb support and introduce gdb_arch tests/tcg/meson.build: introduce gdb_test tests/tcg/meson.build: add default flag for testing compiler support tests/tcg/meson.build: introduce wrapper tests/tcg/meson.build: introduce expected_output tests/tcg/meson.build: add wrapper run_and_check_forbidden_output tests/tcg/meson.build: add wrapper run_with_input tests/tcg/meson.build: add wrapper record_replay tests/tcg/meson.build: add wrapper check_plugin_output tests/tcg/aarch64: add user tests
tests/tcg/aarch64: add system tests
tests/tcg/multiarch: declare user tests
tests/tcg/aarch64: add multiarch user tests tests/tcg/multiarch: declare system tests tests/tcg/aarch64: add multiarch system tests tests/tcg/meson.build: add generic plugin tests

 tests/meson.build                             |   2 +-
 tests/tcg/aarch64/meson.build                 | 248 ++++++++++++++++
 tests/tcg/aarch64/system/meson.build          | 100 +++++++
 tests/tcg/meson.build                         | 276 ++++++++++++++++++
 tests/tcg/multiarch/Makefile.target           |   3 +-
 tests/tcg/multiarch/meson.build               | 149 ++++++++++
 .../multiarch/plugin/check-plugin-output.sh   |  36 ---
 tests/tcg/multiarch/plugin/regex-compare.sh   |  28 ++
 tests/tcg/multiarch/sha1.ref                  |   1 +
 tests/tcg/multiarch/system/memory.c           |   3 +-
 tests/tcg/multiarch/system/meson.build        |  53 ++++
 tests/tcg/plugins/meson.build                 |  11 +-
 tests/tcg/scripts/check_plugin_output.sh      |  19 ++
 tests/tcg/scripts/record_replay.sh            |  16 +
 .../scripts/run_and_check_forbidden_output.sh |  19 ++
 tests/tcg/scripts/run_and_diff.sh             |  12 +
 tests/tcg/scripts/run_with_input.sh           |  12 +
 17 files changed, 943 insertions(+), 45 deletions(-)
 create mode 100644 tests/tcg/aarch64/meson.build
 create mode 100644 tests/tcg/aarch64/system/meson.build
 create mode 100644 tests/tcg/meson.build
 create mode 100644 tests/tcg/multiarch/meson.build
 delete mode 100755 tests/tcg/multiarch/plugin/check-plugin-output.sh
 create mode 100755 tests/tcg/multiarch/plugin/regex-compare.sh
 create mode 100644 tests/tcg/multiarch/sha1.ref
 create mode 100644 tests/tcg/multiarch/system/meson.build
 create mode 100755 tests/tcg/scripts/check_plugin_output.sh
 create mode 100755 tests/tcg/scripts/record_replay.sh
 create mode 100755 tests/tcg/scripts/run_and_check_forbidden_output.sh
 create mode 100755 tests/tcg/scripts/run_and_diff.sh
 create mode 100755 tests/tcg/scripts/run_with_input.sh
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/27 tests/tcg/multiarch/system/memory.c: remove unused variable

Caught this since by compiling this file with -Wall, -Werror.

../tests/tcg/aarch64/system/../../multiarch/system/memory.c: In function ‘init_test_data_s8’:
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:97:18: error: unused variable ‘bottom’ [-Werror=unused-variable]

   97 |     uint8_t top, bottom, *ptr = &test_data[0];
      |                  ^~~~~~

../tests/tcg/aarch64/system/../../multiarch/system/memory.c:97:13: error: unused variable ‘top’ [-Werror=unused-variable]
97 | uint8_t top, bottom, *ptr = &test_data[0];
| ^~~
../tests/tcg/aarch64/system/../../multiarch/system/memory.c: In function ‘read_test_data_s8’:
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:384:14: error: unused variable ‘ok’ [-Werror=unused-variable]

  384 |         bool ok;
      |
---
 tests/tcg/multiarch/system/memory.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
tests/tcg/multiarch/system/memory.c +1 -2
index 7508f6b916d..adc7ac60c1f 100644
@@ -94,7 +94,7 @@ static inline uint8_t get_byte(int index, bool neg)
 
 static void init_test_data_s8(bool neg_first)
 {
-    uint8_t top, bottom, *ptr = &test_data[0];
+    uint8_t *ptr = &test_data[0];
     int i;
 
     ml_printf("Filling test area with s8 pairs (%s):",
@@ -381,7 +381,6 @@ static bool read_test_data_s8(int offset, bool neg_first)
 
     for (i = 0; i < max; i++) {
         int16_t first, second;
-        bool ok;
         first = *ptr++;
         second = *ptr++;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 1/27
#2 lore raw

Re: [PATCH 01/27] tests/tcg/multiarch/system/memory.c: remove unused variable

Quoted 14 lines · Pierrick Bouvier

Caught this since by compiling this file with -Wall, -Werror.

../tests/tcg/aarch64/system/../../multiarch/system/memory.c: In function ‘init_test_data_s8’:
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:97:18: error: unused variable ‘bottom’ [-Werror=unused-variable]

    97 |     uint8_t top, bottom, *ptr = &test_data[0];
       |                  ^~~~~~
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:97:13: error: unused variable ‘top’ [-Werror=unused-variable]
    97 |     uint8_t top, bottom, *ptr = &test_data[0];
       |             ^~~
../tests/tcg/aarch64/system/../../multiarch/system/memory.c: In function ‘read_test_data_s8’:
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:384:14: error: unused variable ‘ok’ [-Werror=unused-variable]
   384 |         bool ok;
       |
Quoted 1 line

r~

Reviewed-by on v1 1/27
#3 lore raw

Re: [PATCH 01/27] tests/tcg/multiarch/system/memory.c: remove unused variable

In reply to Pierrick Bouvier
Quoted 11 lines · Pierrick Bouvier

Caught this since by compiling this file with -Wall, -Werror.

../tests/tcg/aarch64/system/../../multiarch/system/memory.c: In function ‘init_test_data_s8’:
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:97:18: error: unused variable ‘bottom’ [-Werror=unused-variable]

   97 |     uint8_t top, bottom, *ptr = &test_data[0];
      |                  ^~~~~~

../tests/tcg/aarch64/system/../../multiarch/system/memory.c:97:13: error: unused variable ‘top’ [-Werror=unused-variable]
97 | uint8_t top, bottom, *ptr = &test_data[0];
| ^~~
../tests/tcg/aarch64/system/../../multiarch/system/memory.c: In function ‘read_test_data_s8’:
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:384:14: error: unused variable ‘ok’ [-Werror=unused-variable]

Quoted 4 lines
  384 |         bool ok;
      |
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
Reviewed-by on v1 1/27
#4 lore raw

Re: [PATCH 01/27] tests/tcg/multiarch/system/memory.c: remove unused variable

In reply to Pierrick Bouvier
Quoted 14 lines · Pierrick Bouvier

Caught this since by compiling this file with -Wall, -Werror.

../tests/tcg/aarch64/system/../../multiarch/system/memory.c: In function ‘init_test_data_s8’:
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:97:18: error: unused variable ‘bottom’ [-Werror=unused-variable]

    97 |     uint8_t top, bottom, *ptr = &test_data[0];
       |                  ^~~~~~
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:97:13: error: unused variable ‘top’ [-Werror=unused-variable]
    97 |     uint8_t top, bottom, *ptr = &test_data[0];
       |             ^~~
../tests/tcg/aarch64/system/../../multiarch/system/memory.c: In function ‘read_test_data_s8’:
../tests/tcg/aarch64/system/../../multiarch/system/memory.c:384:14: error: unused variable ‘ok’ [-Werror=unused-variable]
   384 |         bool ok;
       |
Quoted 4 lines
---
  tests/tcg/multiarch/system/memory.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
#5 lore raw

PATCH 2/27 tests/tcg/multiarch/plugin/check-plugin-output.sh: take test output as input

In reply to Pierrick Bouvier

Instead of executing test, just read it's output from a file. This allows to standardize how to call check plugins scripts.

---
 tests/tcg/multiarch/Makefile.target           |  3 +--
 .../multiarch/plugin/check-plugin-output.sh   | 22 ++++++-------------
 2 files changed, 8 insertions(+), 17 deletions(-)
tests/tcg/multiarch/Makefile.target +1 -2
index 508149d57bd..f46983cc76e 100644
@@ -211,8 +211,7 @@ run-plugin-test-plugin-mem-access-with-libmem.so: \
 	PLUGIN_ARGS=$(COMMA)print-accesses=true
 run-plugin-test-plugin-mem-access-with-libmem.so: \
 	CHECK_PLUGIN_OUTPUT_COMMAND= \
-	$(SRC_PATH)/tests/tcg/multiarch/plugin/check-plugin-output.sh \
-	$(QEMU) $<
+	$(SRC_PATH)/tests/tcg/multiarch/plugin/check-plugin-output.sh [email protected]
 run-plugin-test-plugin-syscall-filter-with-libsyscall.so:
 run-plugin-test-plugin-set-pc-with-libsetpc.so:
 
tests/tcg/multiarch/plugin/check-plugin-output.sh +7 -15
index 80607f04b5d..338c9ced23e 100755
@@ -1,8 +1,7 @@
 #!/usr/bin/env bash
 
-# This script runs a given executable using qemu, and compare its standard
-# output with an expected plugin output.
-# Each line of output is searched (as a regexp) in the expected plugin output.
+# This script checks that plugin_output contains line from test_output.
+# Each line of output is searched (as a regexp) in plugin_output.
 
 set -euo pipefail
 
@@ -19,18 +18,11 @@ check()
     grep "$pattern" "$file" > /dev/null || die "\"$pattern\" not found in $file"
 }
 
-[ $# -eq 3 ] || die "usage: qemu_bin exe plugin_out_file"
+[ $# -eq 2 ] || die "usage: test_output plugin_out"
 
-qemu_bin=$1; shift
-exe=$1;shift
-plugin_out=$1; shift
+test_output=$1;shift
+plugin_output=$1;shift
 
-expected()
-{
-    $qemu_bin $exe ||
-        die "running $exe failed"
-}
-
-expected | while read line; do
-    check "$plugin_out" "$line"
+cat $test_output | while read line; do
+    check "$plugin_output" "$line"
 done
Signature · 1 line
2.43.0
Reviewed-by on v1 2/27
#6 lore raw

Re: [PATCH 02/27] tests/tcg/multiarch/plugin/check-plugin-output.sh: take test output as input

Quoted 8 lines · Pierrick Bouvier

Instead of executing test, just read it's output from a file. This allows to standardize how to call check plugins scripts.

---
  tests/tcg/multiarch/Makefile.target           |  3 +--
  .../multiarch/plugin/check-plugin-output.sh   | 22 ++++++-------------
  2 files changed, 8 insertions(+), 17 deletions(-)

Could use "done < $test_output" instead of cat, but

r~

Reviewed-by on v1 2/27
#7 lore raw

Re: [PATCH 02/27] tests/tcg/multiarch/plugin/check-plugin-output.sh: take test output as input

In reply to Pierrick Bouvier
Quoted 4 lines · Pierrick Bouvier

Instead of executing test, just read it's output from a file. This allows to standardize how to call check plugins scripts.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#8 lore raw

PATCH 3/27 tests/tcg/multiarch/plugin: rename check-plugin-output to regex-compare

In reply to Pierrick Bouvier

We'll reuse this name later in the series, so change existing script.

---
 tests/tcg/multiarch/Makefile.target                             | 2 +-
 .../plugin/{check-plugin-output.sh => regex-compare.sh}         | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename tests/tcg/multiarch/plugin/{check-plugin-output.sh => regex-compare.sh} (100%)
tests/tcg/multiarch/Makefile.target +1 -1
index f46983cc76e..6907c2830aa 100644
@@ -211,7 +211,7 @@ run-plugin-test-plugin-mem-access-with-libmem.so: \
 	PLUGIN_ARGS=$(COMMA)print-accesses=true
 run-plugin-test-plugin-mem-access-with-libmem.so: \
 	CHECK_PLUGIN_OUTPUT_COMMAND= \
-	$(SRC_PATH)/tests/tcg/multiarch/plugin/check-plugin-output.sh [email protected]
+	$(SRC_PATH)/tests/tcg/multiarch/plugin/regex-compare.sh [email protected]
 run-plugin-test-plugin-syscall-filter-with-libsyscall.so:
 run-plugin-test-plugin-set-pc-with-libsetpc.so:
 
tests/tcg/multiarch/plugin/regex-compare.sh renamed from tests/tcg/multiarch/plugin/check-plugin-output.sh +0 -0
similarity index 100%
rename from tests/tcg/multiarch/plugin/check-plugin-output.sh
rename to tests/tcg/multiarch/plugin/regex-compare.sh
Signature · 1 line
2.43.0
Reviewed-by on v1 3/27
#9 lore raw

Re: [PATCH 03/27] tests/tcg/multiarch/plugin: rename check-plugin-output to regex-compare

Quoted 8 lines · Pierrick Bouvier

We'll reuse this name later in the series, so change existing script.

---
  tests/tcg/multiarch/Makefile.target                             | 2 +-
  .../plugin/{check-plugin-output.sh => regex-compare.sh}         | 0
  2 files changed, 1 insertion(+), 1 deletion(-)

rename tests/tcg/multiarch/plugin/{check-plugin-output.sh => regex-compare.sh} (100%)

r~

#11 lore raw

PATCH 4/27 tests/tcg: introduce meson.build

In reply to Pierrick Bouvier

Every target declare its tests, and add them in global tcg_tests dictionary, indexed by target name. See comment for full description.

We make sure that if a user repeats a test several time it won't result in duplicated executables or tests. In next commits, we'll introduce what's needed to deal with that.

A test is compiled from a single source file (and later, a single set of compile flags). We make sure dependencies are correctly handled by generating a depfile.

---
 tests/meson.build     |  2 +-
 tests/tcg/meson.build | 94 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/meson.build
tests/meson.build +1 -1
index 9ba04bbedd3..5877d2f60b1 100644
@@ -74,7 +74,7 @@ subdir('decode')
 
 if 'CONFIG_TCG' in config_all_accel
   subdir('fp')
-  subdir('tcg/plugins')
+  subdir('tcg')
 endif
 
 subdir('audio')
tests/tcg/meson.build new file +94 -0

94 lines not on this page · raw message

Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH 04/27] tests/tcg: introduce meson.build

Quoted 80 lines · Pierrick Bouvier

Every target declare its tests, and add them in global tcg_tests dictionary, indexed by target name. See comment for full description.

We make sure that if a user repeats a test several time it won't result in duplicated executables or tests. In next commits, we'll introduce what's needed to deal with that.

A test is compiled from a single source file (and later, a single set of compile flags). We make sure dependencies are correctly handled by generating a depfile.

---
 tests/meson.build     |  2 +-
 tests/tcg/meson.build | 94 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/meson.build
tests/meson.build +1 -1
index 9ba04bbedd3..5877d2f60b1 100644
@@ -74,7 +74,7 @@ subdir('decode')
 
 if 'CONFIG_TCG' in config_all_accel
   subdir('fp')
-  subdir('tcg/plugins')
+  subdir('tcg')
 endif
 
 subdir('audio')
tests/tcg/meson.build new file +43 -0
new file mode 100644
index 00000000000..72d1a9f8986
@@ -0,0 +1,94 @@
+env = find_program('env')
+
+tcg_tests = {}
+# tcg_tests is a dictionary with following structure:
+#
+# {
+#   'name_of_target': {
+#     'cc': cross_compiler,
+#     'folder': 'folder_for_test_src_files',
+#     'qemu': emulators['qemu-...'],
+#     'tests': [
+#       {
+#         'src_file': {
+#         }
+#       },
+#       ...
+#     ]
+#   }
+# }
+#
+# Every test executable, is built only once.
+# Tests for a given src use the same executable by default, and their definition
+# is guaranteed to be unique also.
+# Default name is derived from src.
+
+# plugins come first, as we need to build the list
+subdir('plugins')
+
+# Finally, we can create all test executables and test targets
+foreach target, plan: tcg_tests
+  # Detect duplicated executables/tests, and report an error to force user to
+  # choose how to deal with it.
+  built_tests = {}
+  added_tests = {}
+
+  # return a clear error if user mispell a target entry
+  foreach key, _ : plan
+    if key not in ['cc', 'folder', 'qemu', 'tests']
+      error('unknown tcg test plan entry \'' + key + '\' for target ' + target)
+    endif
+  endforeach
+
+  cc = plan['cc']

tests/tcg/meson.build line 53

Quoted 10 lines
tests/tcg/meson.build new file +10 -0
+  folder = plan['folder']
+  qemu = plan['qemu']
+  tests = plan['tests']
+
+  foreach t : tests
+    foreach src, setup: t
+      # meson '/' operator drops left operand if right is an absolute path
+      src = folder / src
+      file = files(src)
+      test = fs.name(file)

dead variable, removed.

Quoted 41 lines
tests/tcg/meson.build new file +41 -0
+      exe_name = fs.stem(src)
+
+      exe_name = target + '-' + exe_name
+      test_name = exe_name
+
+      if test_name in added_tests
+        error('test ' + test_name + ' was already added: ' +
+              'specify a different \'test_name\'')
+      endif
+
+      # build executable if needed
+      if exe_name not in built_tests
+        exe = custom_target(exe_name,
+                            input: file,
+                            command: [cc, '@INPUT@',
+                                      '-o', '@OUTPUT@', '-static',
+                                      '-MMD', '-MF', '@DEPFILE@',
+                                      '-Wall', '-Werror',
+                                      '-O0', '-g', '-fno-strict-aliasing',
+                                      ],
+                            depfile: exe_name + '.d',
+                            output: exe_name + '.test',
+                            build_by_default: false)
+        built_tests += {exe_name: exe}
+      endif
+
+      depends = []
+
+      exe = built_tests[exe_name]
+      cmd = [qemu, exe]
+
+      # some tests expect QEMU env var to be set
+      cmd = ['QEMU=' + qemu.full_path(), cmd]
+
+      test(test_name, env, args: cmd,
+           depends: depends,
+           suite: ['tcg', 'tcg-' + target])
+      added_tests += {test_name: true}
+    endforeach
+  endforeach
+endforeach
Reviewed-by on v1 4/27
#13 lore raw

Re: [PATCH 04/27] tests/tcg: introduce meson.build

In reply to Pierrick Bouvier
Quoted 20 lines · Pierrick Bouvier

Every target declare its tests, and add them in global tcg_tests dictionary, indexed by target name. See comment for full description.

We make sure that if a user repeats a test several time it won't result in duplicated executables or tests. In next commits, we'll introduce what's needed to deal with that.

A test is compiled from a single source file (and later, a single set of compile flags). We make sure dependencies are correctly handled by generating a depfile.

---
 tests/meson.build     |  2 +-
 tests/tcg/meson.build | 94 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/meson.build
tests/meson.build +0 -0
index 9ba04bbedd3..5877d2f60b1 100644

<snip>

Quoted 6 lines
tests/meson.build +6 -0
+
+      # build executable if needed
+      if exe_name not in built_tests
+        exe = custom_target(exe_name,
+                            input: file,
+                            command: [cc, '@INPUT@',

tests/meson.build

Quoted 10 lines
tests/meson.build +10 -0
+                                      '-o', '@OUTPUT@', '-static',
+                                      '-MMD', '-MF', '@DEPFILE@',
+                                      '-Wall', '-Werror',
+                                      '-O0', '-g', '-fno-strict-aliasing',
+                                      ],
+                            depfile: exe_name + '.d',
+                            output: exe_name + '.test',
+                            build_by_default: false)
+        built_tests += {exe_name: exe}
+      endif

I noticed:

ninja -v tests/tcg/aarch64-linux-user-sve-str.test
[1/1] /usr/lib/ccache/aarch64-linux-gnu-gcc ../../tests/tcg/aarch64/sve-str.c -o tests/tcg/aarch64-linux-user-sve-str.test -static -MMD -MF tests/tcg/aarch64-linux-user-sve-str.d -Wall -Werror -O0 -g -fno-strict-aliasing -march=armv8.1-a+sve -O1

and as the compiler parses the command line left to right it does the right thing, but perhaps a comment here to point out additional flags can be added.

Otherwise with your other fixes:

Quoted 16 lines
tests/meson.build +16 -0
+
+      depends = []
+
+      exe = built_tests[exe_name]
+      cmd = [qemu, exe]
+
+      # some tests expect QEMU env var to be set
+      cmd = ['QEMU=' + qemu.full_path(), cmd]
+
+      test(test_name, env, args: cmd,
+           depends: depends,
+           suite: ['tcg', 'tcg-' + target])
+      added_tests += {test_name: true}
+    endforeach
+  endforeach
+endforeach
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#14 lore raw

Re: [PATCH 04/27] tests/tcg: introduce meson.build

Quoted 40 lines · Alex Bennée
Quoted 20 lines · Pierrick Bouvier

Every target declare its tests, and add them in global tcg_tests dictionary, indexed by target name. See comment for full description.

We make sure that if a user repeats a test several time it won't result in duplicated executables or tests. In next commits, we'll introduce what's needed to deal with that.

A test is compiled from a single source file (and later, a single set of compile flags). We make sure dependencies are correctly handled by generating a depfile.

---
 tests/meson.build     |  2 +-
 tests/tcg/meson.build | 94 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 tests/tcg/meson.build
tests/meson.build +0 -0
index 9ba04bbedd3..5877d2f60b1 100644

<snip>

Quoted 6 lines
tests/meson.build +6 -0
+
+      # build executable if needed
+      if exe_name not in built_tests
+        exe = custom_target(exe_name,
+                            input: file,
+                            command: [cc, '@INPUT@',

tests/meson.build

Quoted 10 lines
tests/meson.build +10 -0
+                                      '-o', '@OUTPUT@', '-static',
+                                      '-MMD', '-MF', '@DEPFILE@',
+                                      '-Wall', '-Werror',
+                                      '-O0', '-g', '-fno-strict-aliasing',
+                                      ],
+                            depfile: exe_name + '.d',
+                            output: exe_name + '.test',
+                            build_by_default: false)
+        built_tests += {exe_name: exe}
+      endif
Quoted 9 lines

I noticed:

ninja -v tests/tcg/aarch64-linux-user-sve-str.test
[1/1] /usr/lib/ccache/aarch64-linux-gnu-gcc ../../tests/tcg/aarch64/sve-str.c -o tests/tcg/aarch64-linux-user-sve-str.test -static -MMD -MF tests/tcg/aarch64-linux-user-sve-str.d -Wall -Werror -O0 -g -fno-strict-aliasing -march=armv8.1-a+sve -O1

and as the compiler parses the command line left to right it does the right thing, but perhaps a comment here to point out additional flags can be added.

This should be more clear after reading patch 7 which adds cflags at the end of command line, as expected.

Quoted 22 lines

Otherwise with your other fixes:

Quoted 16 lines
tests/meson.build +16 -0
+
+      depends = []
+
+      exe = built_tests[exe_name]
+      cmd = [qemu, exe]
+
+      # some tests expect QEMU env var to be set
+      cmd = ['QEMU=' + qemu.full_path(), cmd]
+
+      test(test_name, env, args: cmd,
+           depends: depends,
+           suite: ['tcg', 'tcg-' + target])
+      added_tests += {test_name: true}
+    endforeach
+  endforeach
+endforeach
#15 lore raw

PATCH 5/27 tests/tcg/meson.build: introduce exe_name

In reply to Pierrick Bouvier

We add possibility to duplicate a test executable for a given source file. This is needed when different cflags need to be used (like vectorized vs non-vectorized for instance, like sve tests in aarch64).

---
 tests/tcg/meson.build | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tests/tcg/meson.build +15 -2
index 72d1a9f8986..2c6d85c586a 100644
@@ -11,6 +11,7 @@ tcg_tests = {}
 #     'tests': [
 #       {
 #         'src_file': {
+#           'exe_name': ['provide an alternative binary name'],
 #         }
 #       },
 #       ...
@@ -18,10 +19,10 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, is built only once.
+# Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their definition
 # is guaranteed to be unique also.
-# Default name is derived from src.
+# Default name is derived from src if 'exe_name' is omitted.
 
 # plugins come first, as we need to build the list
 subdir('plugins')
@@ -47,11 +48,23 @@ foreach target, plan: tcg_tests
 
   foreach t : tests
     foreach src, setup: t
+      # return a clear error if user mispell a setup entry
+      foreach key, _ : setup
+        if key not in [
+                       'exe_name',
+                       ]
+          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
+        endif
+      endforeach
+
       # meson '/' operator drops left operand if right is an absolute path
       src = folder / src
       file = files(src)
       test = fs.name(file)
       exe_name = fs.stem(src)
+      if 'exe_name' in setup
+        exe_name = setup['exe_name']
+      endif
 
       exe_name = target + '-' + exe_name
       test_name = exe_name
Signature · 1 line
2.43.0
Reviewed-by on v1 5/27
#16 lore raw

Re: [PATCH 05/27] tests/tcg/meson.build: introduce exe_name

Quoted 35 lines · Pierrick Bouvier

We add possibility to duplicate a test executable for a given source file. This is needed when different cflags need to be used (like vectorized vs non-vectorized for instance, like sve tests in aarch64).

---
tests/tcg/meson.build | 17 +++++++++++++++--

1 file changed, 15 insertions(+), 2 deletions(-)
tests/tcg/meson.build +3 -2
index 72d1a9f8986..2c6d85c586a 100644
@@ -11,6 +11,7 @@ tcg_tests = {}
 #     'tests': [
 #       {
 #         'src_file': {
+#           'exe_name': ['provide an alternative binary name'],
 #         }
 #       },
 #       ...
@@ -18,10 +19,10 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, is built only once.
+# Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their definition
 # is guaranteed to be unique also.
-# Default name is derived from src.
+# Default name is derived from src if 'exe_name' is omitted.
 
 # plugins come first, as we need to build the list
 subdir('plugins')

tests/tcg/meson.build foreach target, plan: tcg_tests · line 51

Quoted 4 lines
tests/tcg/meson.build +1 -0
@@ -47,11 +48,23 @@ foreach target, plan: tcg_tests
 
  foreach t : tests
    foreach src, setup: t
+      # return a clear error if user mispell a setup entry

Minor typo:

If user misspells*

Quoted 22 lines
tests/tcg/meson.build +11 -0
+      foreach key, _ : setup
+        if key not in [
+                       'exe_name',
+                       ]
+          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
+        endif
+      endforeach
+
      # meson '/' operator drops left operand if right is an absolute path
      src = folder / src
      file = files(src)
      test = fs.name(file)
      exe_name = fs.stem(src)
+      if 'exe_name' in setup
+        exe_name = setup['exe_name']
+      endif
 
      exe_name = target + '-' + exe_name
      test_name = exe_name
Signature · 1 line
2.43.0
#17 lore raw

Re: [PATCH 05/27] tests/tcg/meson.build: introduce exe_name

Quoted 39 lines · Manos Pitsidianakis
Quoted 37 lines · Pierrick Bouvier

We add possibility to duplicate a test executable for a given source file. This is needed when different cflags need to be used (like vectorized vs non-vectorized for instance, like sve tests in aarch64).

---
tests/tcg/meson.build | 17 +++++++++++++++--

1 file changed, 15 insertions(+), 2 deletions(-)
tests/tcg/meson.build +2 -1
index 72d1a9f8986..2c6d85c586a 100644
@@ -11,6 +11,7 @@ tcg_tests = {}
 #     'tests': [
 #       {
 #         'src_file': {
+#           'exe_name': ['provide an alternative binary name'],
 #         }
 #       },
 #       ...
@@ -18,10 +19,10 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, is built only once.
+# Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their

definition

# is guaranteed to be unique also.
tests/tcg/meson.build +1 -1
-# Default name is derived from src.
+# Default name is derived from src if 'exe_name' is omitted.
# plugins come first, as we need to build the list
subdir('plugins')
tests/tcg/meson.build +0 -0
@@ -47,11 +48,23 @@ foreach target, plan: tcg_tests
 
Quoted 8 lines
Quoted 3 lines

  foreach t : tests
    foreach src, setup: t
+      # return a clear error if user mispell a setup entry

Minor typo:

 If user misspells*

Thanks for the english fix, I'll check other places also.

Quoted 26 lines
Quoted 24 lines

+      foreach key, _ : setup
+        if key not in [
+                       'exe_name',
+                       ]
+          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
+        endif
+      endforeach
+

      # meson '/' operator drops left operand if right is an absolute
path
      src = folder / src
      file = files(src)
      test = fs.name(file)
      exe_name = fs.stem(src)
+      if 'exe_name' in setup
+        exe_name = setup['exe_name']
+      endif

      exe_name = target + '-' + exe_name
      test_name = exe_name
--
2.43.0

Reviewed-by on v1 5/27
#18 lore raw

Re: [PATCH 05/27] tests/tcg/meson.build: introduce exe_name

In reply to Pierrick Bouvier
Quoted 46 lines · Pierrick Bouvier

We add possibility to duplicate a test executable for a given source file. This is needed when different cflags need to be used (like vectorized vs non-vectorized for instance, like sve tests in aarch64).

---
 tests/tcg/meson.build | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tests/tcg/meson.build +11 -2
index 72d1a9f8986..2c6d85c586a 100644
@@ -11,6 +11,7 @@ tcg_tests = {}
 #     'tests': [
 #       {
 #         'src_file': {
+#           'exe_name': ['provide an alternative binary name'],
 #         }
 #       },
 #       ...
@@ -18,10 +19,10 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, is built only once.
+# Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their definition
 # is guaranteed to be unique also.
-# Default name is derived from src.
+# Default name is derived from src if 'exe_name' is omitted.
 
 # plugins come first, as we need to build the list
 subdir('plugins')
@@ -47,11 +48,23 @@ foreach target, plan: tcg_tests
 
   foreach t : tests
     foreach src, setup: t
+      # return a clear error if user mispell a setup entry
+      foreach key, _ : setup
+        if key not in [
+                       'exe_name',
+                       ]
+          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
+        endif
+      endforeach

tests/tcg/meson.build foreach target, plan: tcg_tests · line 68

Quoted 10 lines
tests/tcg/meson.build +4 -0
+
       # meson '/' operator drops left operand if right is an absolute path
       src = folder / src
       file = files(src)
       test = fs.name(file)
       exe_name = fs.stem(src)
+      if 'exe_name' in setup
+        exe_name = setup['exe_name']
+      endif
 

Would it be better to put exe_name = fs.stem(src) in an else leg?

Anyway:

Quoted 2 lines
tests/tcg/meson.build +0 -0
       exe_name = target + '-' + exe_name
       test_name = exe_name
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#19 lore raw

Re: [PATCH 05/27] tests/tcg/meson.build: introduce exe_name

Quoted 52 lines · Alex Bennée
Quoted 50 lines · Pierrick Bouvier

We add possibility to duplicate a test executable for a given source file. This is needed when different cflags need to be used (like vectorized vs non-vectorized for instance, like sve tests in aarch64).

---
 tests/tcg/meson.build | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tests/tcg/meson.build +12 -2
index 72d1a9f8986..2c6d85c586a 100644
@@ -11,6 +11,7 @@ tcg_tests = {}
 #     'tests': [
 #       {
 #         'src_file': {
+#           'exe_name': ['provide an alternative binary name'],
 #         }
 #       },
 #       ...
@@ -18,10 +19,10 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, is built only once.
+# Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their definition
 # is guaranteed to be unique also.
-# Default name is derived from src.
+# Default name is derived from src if 'exe_name' is omitted.
 
 # plugins come first, as we need to build the list
 subdir('plugins')
@@ -47,11 +48,23 @@ foreach target, plan: tcg_tests
 
   foreach t : tests
     foreach src, setup: t
+      # return a clear error if user mispell a setup entry
+      foreach key, _ : setup
+        if key not in [
+                       'exe_name',
+                       ]
+          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
+        endif
+      endforeach
+
       # meson '/' operator drops left operand if right is an absolute path
       src = folder / src
       file = files(src)
Quoted 9 lines

tests/tcg/meson.build foreach target, plan: tcg_tests · line 68

Quoted 6 lines
tests/tcg/meson.build +3 -0
       test = fs.name(file)
       exe_name = fs.stem(src)
+      if 'exe_name' in setup
+        exe_name = setup['exe_name']
+      endif
 

Would it be better to put exe_name = fs.stem(src) in an else leg?

The rest of the file follow the pattern
var = default
if (different)
var = other

So better to stick with one pattern for consistency. It absolutely does not matter for "performance".

Quoted 8 lines

Anyway:

Quoted 2 lines
tests/tcg/meson.build +0 -0
       exe_name = target + '-' + exe_name
       test_name = exe_name
#20 lore raw

Re: [PATCH 05/27] tests/tcg/meson.build: introduce exe_name

Quoted 63 lines · Pierrick Bouvier
Quoted 52 lines · Alex Bennée
Quoted 50 lines · Pierrick Bouvier

We add possibility to duplicate a test executable for a given source file. This is needed when different cflags need to be used (like vectorized vs non-vectorized for instance, like sve tests in aarch64).

---
 tests/tcg/meson.build | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tests/tcg/meson.build +12 -2
index 72d1a9f8986..2c6d85c586a 100644
@@ -11,6 +11,7 @@ tcg_tests = {}
 #     'tests': [
 #       {
 #         'src_file': {
+#           'exe_name': ['provide an alternative binary name'],
 #         }
 #       },
 #       ...
@@ -18,10 +19,10 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, is built only once.
+# Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their definition
 # is guaranteed to be unique also.
-# Default name is derived from src.
+# Default name is derived from src if 'exe_name' is omitted.
 
 # plugins come first, as we need to build the list
 subdir('plugins')
@@ -47,11 +48,23 @@ foreach target, plan: tcg_tests
 
   foreach t : tests
     foreach src, setup: t
+      # return a clear error if user mispell a setup entry
+      foreach key, _ : setup
+        if key not in [
+                       'exe_name',
+                       ]
+          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
+        endif
+      endforeach
+
       # meson '/' operator drops left operand if right is an absolute path
       src = folder / src
       file = files(src)
Quoted 9 lines

tests/tcg/meson.build foreach target, plan: tcg_tests · line 68

Quoted 6 lines
tests/tcg/meson.build +3 -0
       test = fs.name(file)
       exe_name = fs.stem(src)
+      if 'exe_name' in setup
+        exe_name = setup['exe_name']
+      endif
 

Would it be better to put exe_name = fs.stem(src) in an else leg?

Quoted 6 lines

The rest of the file follow the pattern
var = default
if (different)
var = other

So better to stick with one pattern for consistency.

Sure - but the other meson files seem to follow the other pattern, e.g.:

if cpu not in supported_cpus
host_arch = 'unknown'
else
host_arch = cpu
endif

Quoted 10 lines

It absolutely does not matter for "performance".

Quoted 8 lines

Anyway:

Quoted 2 lines
tests/tcg/meson.build +0 -0
       exe_name = target + '-' + exe_name
       test_name = exe_name
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#21 lore raw

PATCH 6/27 tests/tcg/meson.build: introduce test_name

In reply to Pierrick Bouvier

We add possibility to duplicate a test for a given src. This allows to declare several tests that still share the same executable, thus saving space and compile time.

A side note to mention that meson perfectly supports declaring several tests with the same name. However, we prevent that to force dev to clarify what is the intent of each individual test.

---
 tests/tcg/meson.build | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
tests/tcg/meson.build +10 -4
index 2c6d85c586a..bb0184732fd 100644
@@ -12,6 +12,7 @@ tcg_tests = {}
 #       {
 #         'src_file': {
 #           'exe_name': ['provide an alternative binary name'],
+#           'test_name': ['provide an alternative test name'],
 #         }
 #       },
 #       ...
@@ -21,8 +22,8 @@ tcg_tests = {}
 #
 # Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their definition
-# is guaranteed to be unique also.
-# Default name is derived from src if 'exe_name' is omitted.
+# is guaranteed to be unique also. They can be duplicated by setting 'test_name'.
+# Default name is derived from src if 'exe_name' and 'test_name' are omitted.
 
 # plugins come first, as we need to build the list
 subdir('plugins')
@@ -51,7 +52,7 @@ foreach target, plan: tcg_tests
       # return a clear error if user mispell a setup entry
       foreach key, _ : setup
         if key not in [
-                       'exe_name',
+                       'exe_name', 'test_name',
                        ]
           error('unknown tcg setup entry \'' + key + '\' for test ' + src)
         endif
@@ -66,8 +67,13 @@ foreach target, plan: tcg_tests
         exe_name = setup['exe_name']
       endif
 
-      exe_name = target + '-' + exe_name
       test_name = exe_name
+      if 'test_name' in setup
+        test_name = setup['test_name']
+      endif
+
+      exe_name = target + '-' + exe_name
+      test_name = target + '-' + test_name
 
       if test_name in added_tests
         error('test ' + test_name + ' was already added: ' +
Signature · 1 line
2.43.0
Reviewed-by on v1 6/27
#22 lore raw

Re: [PATCH 06/27] tests/tcg/meson.build: introduce test_name

Quoted 26 lines · Pierrick Bouvier

We add possibility to duplicate a test for a given src. This allows to declare several tests that still share the same executable, thus saving space and compile time.

A side note to mention that meson perfectly supports declaring several tests with the same name. However, we prevent that to force dev to clarify what is the intent of each individual test.

---
tests/tcg/meson.build | 14 ++++++++++----

1 file changed, 10 insertions(+), 4 deletions(-)
tests/tcg/meson.build +1 -0
index 2c6d85c586a..bb0184732fd 100644
@@ -12,6 +12,7 @@ tcg_tests = {}
 #       {
 #         'src_file': {
 #           'exe_name': ['provide an alternative binary name'],
+#           'test_name': ['provide an alternative test name'],
 #         }
 #       },
 #       ...

tests/tcg/meson.build tcg_tests = {} · line 25

Quoted 6 lines
tests/tcg/meson.build +1 -2
@@ -21,8 +22,8 @@ tcg_tests = {}
 #
 # Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their definition
-# is guaranteed to be unique also.
-# Default name is derived from src if 'exe_name' is omitted.
+# is guaranteed to be unique also. They can be duplicated by setting 'test_name'.

While it's clear in the patch description, it might be a good idea to explain that "duplication" means using the same executable here, for clarity, if you respin this series.

tests/tcg/meson.build foreach target, plan: tcg_tests · line 57

Quoted 12 lines
tests/tcg/meson.build +2 -1
+# Default name is derived from src if 'exe_name' and 'test_name' are omitted.
 
 # plugins come first, as we need to build the list
 subdir('plugins')
@@ -51,7 +52,7 @@ foreach target, plan: tcg_tests
      # return a clear error if user mispell a setup entry
      foreach key, _ : setup
        if key not in [
-                       'exe_name',
+                       'exe_name', 'test_name',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)

Unrelated to this patch, but you could refactor the ['exe_name', 'test_name'] etc key set outside and print the list of valid keys in the error message as well for UX.

Quoted 19 lines
tests/tcg/meson.build +6 -1
        endif
@@ -66,8 +67,13 @@ foreach target, plan: tcg_tests
        exe_name = setup['exe_name']
      endif
 
-      exe_name = target + '-' + exe_name
      test_name = exe_name
+      if 'test_name' in setup
+        test_name = setup['test_name']
+      endif
+
+      exe_name = target + '-' + exe_name
+      test_name = target + '-' + test_name
 
      if test_name in added_tests
        error('test ' + test_name + ' was already added: ' +
Signature · 1 line
2.43.0

LGTM (feel free to ignore the comments)

#23 lore raw

Re: [PATCH 06/27] tests/tcg/meson.build: introduce test_name

Quoted 32 lines · Manos Pitsidianakis
Quoted 30 lines · Pierrick Bouvier

We add possibility to duplicate a test for a given src. This allows to declare several tests that still share the same executable, thus saving space and compile time.

A side note to mention that meson perfectly supports declaring several tests with the same name. However, we prevent that to force dev to clarify what is the intent of each individual test.

---
tests/tcg/meson.build | 14 ++++++++++----

1 file changed, 10 insertions(+), 4 deletions(-)
tests/tcg/meson.build +1 -0
index 2c6d85c586a..bb0184732fd 100644
@@ -12,6 +12,7 @@ tcg_tests = {}
 #       {
 #         'src_file': {
 #           'exe_name': ['provide an alternative binary name'],
+#           'test_name': ['provide an alternative test name'],
 #         }
 #       },
 #       ...
@@ -21,8 +22,8 @@ tcg_tests = {}
 #
 # Every test executable, identified by 'exe_name' is built only once.
 # Tests for a given src use the same executable by default, and their

definition

Quoted 9 lines
Quoted 4 lines
tests/tcg/meson.build +1 -2
-# is guaranteed to be unique also.
-# Default name is derived from src if 'exe_name' is omitted.
+# is guaranteed to be unique also. They can be duplicated by setting

'test_name'.

While it's clear in the patch description, it might be a good idea to explain that "duplication" means using the same executable here, for clarity, if you respin this series.

Sure, I can add this.

Quoted 20 lines
Quoted 7 lines

+# Default name is derived from src if 'exe_name' and 'test_name' are omitted.

# plugins come first, as we need to build the list
subdir('plugins')
tests/tcg/meson.build +0 -0
@@ -51,7 +52,7 @@ foreach target, plan: tcg_tests
       # return a clear error if user mispell a setup entry
Quoted 7 lines

      foreach key, _ : setup
        if key not in [
-                       'exe_name',
+                       'exe_name', 'test_name',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)

Unrelated to this patch, but you could refactor the ['exe_name', 'test_name'] etc key set outside and print the list of valid keys in the error message as well for UX.

Good idea.

Quoted 24 lines
Quoted 14 lines

        endif

tests/tcg/meson.build +0 -0
@@ -66,8 +67,13 @@ foreach target, plan: tcg_tests

        exe_name = setup['exe_name']
      endif

-      exe_name = target + '-' + exe_name
      test_name = exe_name
+      if 'test_name' in setup
+        test_name = setup['test_name']
+      endif
+
+      exe_name = target + '-' + exe_name
+      test_name = target + '-' + test_name

Quoted 5 lines

      if test_name in added_tests
        error('test ' + test_name + ' was already added: ' + --
2.43.0

LGTM (feel free to ignore the comments)

#24 lore raw

Re: [PATCH 06/27] tests/tcg/meson.build: introduce test_name

In reply to Manos Pitsidianakis
Quoted 29 lines · Manos Pitsidianakis
Quoted 28 lines · Pierrick Bouvier

We add possibility to duplicate a test for a given src. This allows to declare several tests that still share the same executable, thus saving space and compile time.

A side note to mention that meson perfectly supports declaring several tests with the same name. However, we prevent that to force dev to clarify what is the intent of each individual test.

---
tests/tcg/meson.build | 14 ++++++++++----

1 file changed, 10 insertions(+), 4 deletions(-)
tests/tcg/meson.build +1 -0
index 2c6d85c586a..bb0184732fd 100644
@@ -12,6 +12,7 @@ tcg_tests = {}
 #       {
 #         'src_file': {
 #           'exe_name': ['provide an alternative binary name'],
+#           'test_name': ['provide an alternative test name'],
 #         }
 #       },
 #       ...
@@ -21,8 +22,8 @@ tcg_tests = {}
 #
 # Every test executable, identified by 'exe_name' is built only once.
Quoted 8 lines

tests/tcg/meson.build tcg_tests = {} · line 25

Quoted 4 lines
tests/tcg/meson.build +1 -2
 # Tests for a given src use the same executable by default, and their definition
-# is guaranteed to be unique also.
-# Default name is derived from src if 'exe_name' is omitted.
+# is guaranteed to be unique also. They can be duplicated by setting 'test_name'.

While it's clear in the patch description, it might be a good idea to explain that "duplication" means using the same executable here, for clarity, if you respin this series.

additional versions of the test can be added by setting 'test_name'?

Quoted 39 lines

tests/tcg/meson.build foreach target, plan: tcg_tests · line 57

Quoted 12 lines
tests/tcg/meson.build +2 -1
+# Default name is derived from src if 'exe_name' and 'test_name' are omitted.
 # plugins come first, as we need to build the list
 subdir('plugins')
@@ -51,7 +52,7 @@ foreach target, plan: tcg_tests
      # return a clear error if user mispell a setup entry
      foreach key, _ : setup
        if key not in [
-                       'exe_name',
+                       'exe_name', 'test_name',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)

Unrelated to this patch, but you could refactor the ['exe_name', 'test_name'] etc key set outside and print the list of valid keys in the error message as well for UX.

Quoted 6 lines
tests/tcg/meson.build +0 -1
        endif
@@ -66,8 +67,13 @@ foreach target, plan: tcg_tests
        exe_name = setup['exe_name']
      endif
-      exe_name = target + '-' + exe_name
      test_name = exe_name

tests/tcg/meson.build foreach target, plan: tcg_tests · line 78

Quoted 10 lines
tests/tcg/meson.build +6 -1
+      if 'test_name' in setup
+        test_name = setup['test_name']
+      endif
+
+      exe_name = target + '-' + exe_name
+      test_name = target + '-' + test_name
      if test_name in added_tests
        error('test ' + test_name + ' was already added: ' +
-- 2.43.0
 

LGTM (feel free to ignore the comments)

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#25 lore raw

PATCH 7/27 tests/tcg/meson.build: introduce cflags

In reply to Pierrick Bouvier

We add possibility to declare cflags for a given test. Since we want to preserve the uniqueness of test binaries, we prevent repeating those cflags later, for an existing binary.

This ensures one executable == one set of cflags, and if dev needs duplication, they can use a custom 'exe_name' to override this.

---
 tests/tcg/meson.build | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
tests/tcg/meson.build +14 -3
index bb0184732fd..ad56fdf4ab5 100644
@@ -13,6 +13,7 @@ tcg_tests = {}
 #         'src_file': {
 #           'exe_name': ['provide an alternative binary name'],
 #           'test_name': ['provide an alternative test name'],
+#           'cflags': ['cflags to compile test', ...],
 #         }
 #       },
 #       ...
@@ -20,7 +21,8 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, identified by 'exe_name' is built only once.
+# Every test executable, identified by 'exe_name' is built only once, and we
+# ensure cflags are specified only once, on first declaration.
 # Tests for a given src use the same executable by default, and their definition
 # is guaranteed to be unique also. They can be duplicated by setting 'test_name'.
 # Default name is derived from src if 'exe_name' and 'test_name' are omitted.
@@ -51,7 +53,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 [
+        if key not in ['cflags',
                        'exe_name', 'test_name',
                        ]
           error('unknown tcg setup entry \'' + key + '\' for test ' + src)
@@ -80,6 +82,15 @@ foreach target, plan: tcg_tests
               'specify a different \'test_name\'')
       endif
 
+      cflags = []
+      if 'cflags' in setup
+        if exe_name in built_tests
+          error('test ' + exe_name + ' was already built with cflags: ' +
+                'remove cflags or set \'exe_name\' (if cflags are different)')
+        endif
+        cflags = setup['cflags']
+      endif
+
       # build executable if needed
       if exe_name not in built_tests
         exe = custom_target(exe_name,
@@ -89,7 +100,7 @@ foreach target, plan: tcg_tests
                                       '-MMD', '-MF', '@DEPFILE@',
                                       '-Wall', '-Werror',
                                       '-O0', '-g', '-fno-strict-aliasing',
-                                      ],
+                                      cflags],
                             depfile: exe_name + '.d',
                             output: exe_name + '.test',
                             build_by_default: false)
Signature · 1 line
2.43.0
Reviewed-by on v1 7/27
#26 lore raw

Re: [PATCH 07/27] tests/tcg/meson.build: introduce cflags

Quoted 9 lines · Pierrick Bouvier

We add possibility to declare cflags for a given test. Since we want to preserve the uniqueness of test binaries, we prevent repeating those cflags later, for an existing binary.

This ensures one executable == one set of cflags, and if dev needs duplication, they can use a custom 'exe_name' to override this.

---

Quoted 62 lines

tests/tcg/meson.build | 17 ++++++++++++++---

1 file changed, 14 insertions(+), 3 deletions(-)
tests/tcg/meson.build +14 -3
index bb0184732fd..ad56fdf4ab5 100644
@@ -13,6 +13,7 @@ tcg_tests = {}
 #         'src_file': {
 #           'exe_name': ['provide an alternative binary name'],
 #           'test_name': ['provide an alternative test name'],
+#           'cflags': ['cflags to compile test', ...],
 #         }
 #       },
 #       ...
@@ -20,7 +21,8 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, identified by 'exe_name' is built only once.
+# Every test executable, identified by 'exe_name' is built only once, and we
+# ensure cflags are specified only once, on first declaration.
 # Tests for a given src use the same executable by default, and their definition
 # is guaranteed to be unique also. They can be duplicated by setting 'test_name'.
 # Default name is derived from src if 'exe_name' and 'test_name' are omitted.
@@ -51,7 +53,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 [
+        if key not in ['cflags',
                       'exe_name', 'test_name',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
@@ -80,6 +82,15 @@ foreach target, plan: tcg_tests
              'specify a different \'test_name\'')
      endif
 
+      cflags = []
+      if 'cflags' in setup
+        if exe_name in built_tests
+          error('test ' + exe_name + ' was already built with cflags: ' +
+                'remove cflags or set \'exe_name\' (if cflags are different)')
+        endif
+        cflags = setup['cflags']
+      endif
+
      # build executable if needed
      if exe_name not in built_tests
        exe = custom_target(exe_name,
@@ -89,7 +100,7 @@ foreach target, plan: tcg_tests
                                      '-MMD', '-MF', '@DEPFILE@',
                                      '-Wall', '-Werror',
                                      '-O0', '-g', '-fno-strict-aliasing',
-                                      ],
+                                      cflags],
                            depfile: exe_name + '.d',
                            output: exe_name + '.test',
                            build_by_default: false)
Signature · 1 line
2.43.0
#27 lore raw

Re: [PATCH 07/27] tests/tcg/meson.build: introduce cflags

In reply to Pierrick Bouvier
Quoted 17 lines · Pierrick Bouvier

We add possibility to declare cflags for a given test. Since we want to preserve the uniqueness of test binaries, we prevent repeating those cflags later, for an existing binary.

This ensures one executable == one set of cflags, and if dev needs duplication, they can use a custom 'exe_name' to override this.

---
 tests/tcg/meson.build | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
tests/tcg/meson.build +0 -0
index bb0184732fd..ad56fdf4ab5 100644

tests/tcg/meson.build tcg_tests = {} · line 16

Quoted 4 lines
tests/tcg/meson.build +1 -0
@@ -13,6 +13,7 @@ tcg_tests = {}
 #         'src_file': {
 #           'exe_name': ['provide an alternative binary name'],
 #           'test_name': ['provide an alternative test name'],
+#           'cflags': ['cflags to compile test', ...],

additional cflags to compile test?

Quoted 47 lines
tests/tcg/meson.build +13 -3
 #         }
 #       },
 #       ...
@@ -20,7 +21,8 @@ tcg_tests = {}
 #   }
 # }
 #
-# Every test executable, identified by 'exe_name' is built only once.
+# Every test executable, identified by 'exe_name' is built only once, and we
+# ensure cflags are specified only once, on first declaration.
 # Tests for a given src use the same executable by default, and their definition
 # is guaranteed to be unique also. They can be duplicated by setting 'test_name'.
 # Default name is derived from src if 'exe_name' and 'test_name' are omitted.
@@ -51,7 +53,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 [
+        if key not in ['cflags',
                        'exe_name', 'test_name',
                        ]
           error('unknown tcg setup entry \'' + key + '\' for test ' + src)
@@ -80,6 +82,15 @@ foreach target, plan: tcg_tests
               'specify a different \'test_name\'')
       endif
 
+      cflags = []
+      if 'cflags' in setup
+        if exe_name in built_tests
+          error('test ' + exe_name + ' was already built with cflags: ' +
+                'remove cflags or set \'exe_name\' (if cflags are different)')
+        endif
+        cflags = setup['cflags']
+      endif
+
       # build executable if needed
       if exe_name not in built_tests
         exe = custom_target(exe_name,
@@ -89,7 +100,7 @@ foreach target, plan: tcg_tests
                                       '-MMD', '-MF', '@DEPFILE@',
                                       '-Wall', '-Werror',
                                       '-O0', '-g', '-fno-strict-aliasing',
-                                      ],
+                                      cflags],
                             depfile: exe_name + '.d',
                             output: exe_name + '.test',
                             build_by_default: false)
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#28 lore raw

PATCH 8/27 tests/tcg/meson.build: introduce qemu_args

In reply to Pierrick Bouvier

We add possibility to use custom arguments when calling qemu for a test.

---
 tests/tcg/meson.build | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tests/tcg/meson.build +7 -2
index ad56fdf4ab5..28a7e529c7e 100644
@@ -14,6 +14,7 @@ tcg_tests = {}
 #           'exe_name': ['provide an alternative binary name'],
 #           'test_name': ['provide an alternative test name'],
 #           'cflags': ['cflags to compile test', ...],
+#           'qemu_args': ['qemu command line flags', ...],
 #         }
 #       },
 #       ...
@@ -53,7 +54,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',
+        if key not in ['cflags', 'qemu_args',
                        'exe_name', 'test_name',
                        ]
           error('unknown tcg setup entry \'' + key + '\' for test ' + src)
@@ -108,9 +109,13 @@ foreach target, plan: tcg_tests
       endif
 
       depends = []
+      qemu_args = []
+      if 'qemu_args' in setup
+        qemu_args = setup['qemu_args']
+      endif
 
       exe = built_tests[exe_name]
-      cmd = [qemu, exe]
+      cmd = [qemu, qemu_args, exe]
 
       # some tests expect QEMU env var to be set
       cmd = ['QEMU=' + qemu.full_path(), cmd]
Signature · 1 line
2.43.0
Reviewed-by on v1 8/27
#29 lore raw

Re: [PATCH 08/27] tests/tcg/meson.build: introduce qemu_args

Quoted 4 lines · Pierrick Bouvier

We add possibility to use custom arguments when calling qemu for a test.

---

Quoted 42 lines

tests/tcg/meson.build | 9 +++++++--

1 file changed, 7 insertions(+), 2 deletions(-)
tests/tcg/meson.build +7 -2
index ad56fdf4ab5..28a7e529c7e 100644
@@ -14,6 +14,7 @@ tcg_tests = {}
 #           'exe_name': ['provide an alternative binary name'],
 #           'test_name': ['provide an alternative test name'],
 #           'cflags': ['cflags to compile test', ...],
+#           'qemu_args': ['qemu command line flags', ...],
 #         }
 #       },
 #       ...
@@ -53,7 +54,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',
+        if key not in ['cflags', 'qemu_args',
                       'exe_name', 'test_name',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
@@ -108,9 +109,13 @@ foreach target, plan: tcg_tests
      endif
 
      depends = []
+      qemu_args = []
+      if 'qemu_args' in setup
+        qemu_args = setup['qemu_args']
+      endif
 
      exe = built_tests[exe_name]
-      cmd = [qemu, exe]
+      cmd = [qemu, qemu_args, exe]
 
      # some tests expect QEMU env var to be set
      cmd = ['QEMU=' + qemu.full_path(), cmd]
Signature · 1 line
2.43.0
#31 lore raw

PATCH 9/27 tests/tcg/meson.build: introduce env_var

In reply to Pierrick Bouvier

We add possibility to set an environment variable when running a test. An example of a test requiring this is tests/tcg/multiarch/linux/linux-sigrtminmax.c.

---
 tests/tcg/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tests/tcg/meson.build +6 -1
index 28a7e529c7e..b6a375e9eee 100644
@@ -15,6 +15,7 @@ tcg_tests = {}
 #           'test_name': ['provide an alternative test name'],
 #           'cflags': ['cflags to compile test', ...],
 #           'qemu_args': ['qemu command line flags', ...],
+#           'env_var': ['VAR=value', ...],
 #         }
 #       },
 #       ...
@@ -55,7 +56,7 @@ foreach target, plan: tcg_tests
       # return a clear error if user mispell a setup entry
       foreach key, _ : setup
         if key not in ['cflags', 'qemu_args',
-                       'exe_name', 'test_name',
+                       'exe_name', 'test_name', 'env_var',
                        ]
           error('unknown tcg setup entry \'' + key + '\' for test ' + src)
         endif
@@ -120,6 +121,10 @@ foreach target, plan: tcg_tests
       # some tests expect QEMU env var to be set
       cmd = ['QEMU=' + qemu.full_path(), cmd]
 
+      if 'env_var' in setup
+        cmd = [setup['env_var'], cmd]
+      endif
+
       test(test_name, env, args: cmd,
            depends: depends,
            suite: ['tcg', 'tcg-' + target])
Signature · 1 line
2.43.0
Reviewed-by on v1 9/27
#32 lore raw

Re: [PATCH 09/27] tests/tcg/meson.build: introduce env_var

Quoted 6 lines · Pierrick Bouvier

We add possibility to set an environment variable when running a test. An example of a test requiring this is tests/tcg/multiarch/linux/linux-sigrtminmax.c.

---

Quoted 38 lines

tests/tcg/meson.build | 7 ++++++-

1 file changed, 6 insertions(+), 1 deletion(-)
tests/tcg/meson.build +6 -1
index 28a7e529c7e..b6a375e9eee 100644
@@ -15,6 +15,7 @@ tcg_tests = {}
 #           'test_name': ['provide an alternative test name'],
 #           'cflags': ['cflags to compile test', ...],
 #           'qemu_args': ['qemu command line flags', ...],
+#           'env_var': ['VAR=value', ...],
 #         }
 #       },
 #       ...
@@ -55,7 +56,7 @@ foreach target, plan: tcg_tests
      # return a clear error if user mispell a setup entry
      foreach key, _ : setup
        if key not in ['cflags', 'qemu_args',
-                       'exe_name', 'test_name',
+                       'exe_name', 'test_name', 'env_var',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
        endif
@@ -120,6 +121,10 @@ foreach target, plan: tcg_tests
      # some tests expect QEMU env var to be set
      cmd = ['QEMU=' + qemu.full_path(), cmd]
 
+      if 'env_var' in setup
+        cmd = [setup['env_var'], cmd]
+      endif
+
      test(test_name, env, args: cmd,
           depends: depends,
           suite: ['tcg', 'tcg-' + target])
Signature · 1 line
2.43.0
#33 lore raw

PATCH 10/27 tests/tcg/plugins: build list of test_plugins

In reply to Pierrick Bouvier

We previously had list of test_plugins sources, but not the target themselves. Create this list, so tests can then reference a plugin by its name from there.

---
 tests/tcg/meson.build         |  1 +
 tests/tcg/plugins/meson.build | 11 +++++++----
 2 files changed, 8 insertions(+), 4 deletions(-)
tests/tcg/meson.build +1 -0
index b6a375e9eee..5cd80f3c030 100644
@@ -30,6 +30,7 @@ tcg_tests = {}
 # Default name is derived from src if 'exe_name' and 'test_name' are omitted.
 
 # plugins come first, as we need to build the list
+test_plugins = {}
 subdir('plugins')
 
 # Finally, we can create all test executables and test targets
tests/tcg/plugins/meson.build +7 -4
index d7f8f0ae0ad..2abc317d1e7 100644
@@ -1,4 +1,4 @@
-test_plugins = [
+test_plugins_src = [
 'bb.c',
 'discons.c',
 'empty.c',
@@ -14,9 +14,12 @@ test_plugins = [
 
 t = []
 if get_option('plugins')
-  foreach i : test_plugins
-    t += shared_module(fs.stem(i), files(i),
-                       dependencies: plugins_deps)
+  foreach i : test_plugins_src
+    name = fs.stem(i)
+    plugin = shared_module(name, files(i),
+                           dependencies: plugins_deps)
+    t += plugin
+    test_plugins += {name: plugin}
   endforeach
 endif
 if t.length() > 0
Signature · 1 line
2.43.0
Reviewed-by on v1 10/27
#34 lore raw

Re: [PATCH 10/27] tests/tcg/plugins: build list of test_plugins

Quoted 6 lines · Pierrick Bouvier

We previously had list of test_plugins sources, but not the target themselves. Create this list, so tests can then reference a plugin by its name from there.

---

Quoted 45 lines

tests/tcg/meson.build | 1 +
tests/tcg/plugins/meson.build | 11 +++++++----

2 files changed, 8 insertions(+), 4 deletions(-)
tests/tcg/meson.build +1 -0
index b6a375e9eee..5cd80f3c030 100644
@@ -30,6 +30,7 @@ tcg_tests = {}
 # Default name is derived from src if 'exe_name' and 'test_name' are omitted.
 
 # plugins come first, as we need to build the list
+test_plugins = {}
 subdir('plugins')
 
 # Finally, we can create all test executables and test targets
tests/tcg/plugins/meson.build +1 -1
index d7f8f0ae0ad..2abc317d1e7 100644
@@ -1,4 +1,4 @@
-test_plugins = [
+test_plugins_src = [
 'bb.c',
 'discons.c',
 'empty.c',
@@ -14,9 +14,12 @@ test_plugins = [
 

t = []
if get_option('plugins')

tests/tcg/plugins/meson.build +6 -3
-  foreach i : test_plugins
-    t += shared_module(fs.stem(i), files(i),
-                       dependencies: plugins_deps)
+  foreach i : test_plugins_src
+    name = fs.stem(i)
+    plugin = shared_module(name, files(i),
+                           dependencies: plugins_deps)
+    t += plugin
+    test_plugins += {name: plugin}
  endforeach

endif
if t.length() > 0

Signature · 1 line
2.43.0
#35 lore raw

PATCH 11/27 tests/tcg/meson.build: introduce plugin_test

In reply to Pierrick Bouvier

We add possibility to declare a test that is based on a plugin.

---
 tests/tcg/meson.build | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
tests/tcg/meson.build +39 -1
index 5cd80f3c030..a47f1ada779 100644
@@ -16,6 +16,10 @@ tcg_tests = {}
 #           'cflags': ['cflags to compile test', ...],
 #           'qemu_args': ['qemu command line flags', ...],
 #           'env_var': ['VAR=value', ...],
+#           'plugin_test': {
+#             'plugin': 'plugin_name',
+#             'args': ['plugin_args', ...],
+#           },
 #         }
 #       },
 #       ...
@@ -57,12 +61,25 @@ foreach target, plan: tcg_tests
       # return a clear error if user mispell a setup entry
       foreach key, _ : setup
         if key not in ['cflags', 'qemu_args',
-                       'exe_name', 'test_name', 'env_var',
+                       'exe_name', 'test_name', 'env_var', 'plugin_test',
                        ]
           error('unknown tcg setup entry \'' + key + '\' for test ' + src)
         endif
       endforeach
 
+      # return a clear error if user mispell a plugin entry
+      if 'plugin_test' in setup
+        foreach key, _ : setup['plugin_test']
+          if key not in ['plugin', 'args']
+            error('unknown tcg plugin entry \'' + key + '\' for test ' + src)
+          endif
+        endforeach
+      endif
+
+      if 'plugin_test' in setup and not get_option('plugins')
+        continue
+      endif
+
       # meson '/' operator drops left operand if right is an absolute path
       src = folder / src
       file = files(src)
@@ -76,6 +93,12 @@ foreach target, plan: tcg_tests
       if 'test_name' in setup
         test_name = setup['test_name']
       endif
+      if 'plugin_test' in setup
+        # remove lib prefix
+        plugin = test_plugins[setup['plugin_test']['plugin']]
+        plugin_name = fs.stem(plugin).substring(3)
+        test_name = 'plugin-' + plugin_name + '-with-' + test_name
+      endif
 
       exe_name = target + '-' + exe_name
       test_name = target + '-' + test_name
@@ -116,6 +139,21 @@ foreach target, plan: tcg_tests
         qemu_args = setup['qemu_args']
       endif
 
+      if 'plugin_test' in setup
+        plugin_setup = setup['plugin_test']
+        plugin = test_plugins[plugin_setup['plugin']]
+        plugin_args = []
+        if 'args' in plugin_setup
+          # add empty arg to generate an additional comma
+          plugin_args = ['', plugin_setup['args']]
+        endif
+        plugin_args = ','.join(plugin_args)
+
+        # since we turn plugin into a string, add dependency explicitly
+        depends += plugin
+        qemu_args = ['-plugin', plugin.full_path() + plugin_args, qemu_args]
+      endif
+
       exe = built_tests[exe_name]
       cmd = [qemu, qemu_args, exe]
 
Signature · 1 line
2.43.0
Reviewed-by on v1 11/27
#36 lore raw

Re: [PATCH 11/27] tests/tcg/meson.build: introduce plugin_test

Quoted 24 lines · Pierrick Bouvier

We add possibility to declare a test that is based on a plugin.

---
tests/tcg/meson.build | 40 +++++++++++++++++++++++++++++++++++++++-

1 file changed, 39 insertions(+), 1 deletion(-)
tests/tcg/meson.build +4 -0
index 5cd80f3c030..a47f1ada779 100644
@@ -16,6 +16,10 @@ tcg_tests = {}
 #           'cflags': ['cflags to compile test', ...],
 #           'qemu_args': ['qemu command line flags', ...],
 #           'env_var': ['VAR=value', ...],
+#           'plugin_test': {
+#             'plugin': 'plugin_name',
+#             'args': ['plugin_args', ...],
+#           },
 #         }
 #       },
 #       ...
@@ -57,12 +61,25 @@ foreach target, plan: tcg_tests
      # return a clear error if user mispell a setup entry

tests/tcg/meson.build foreach target, plan: tcg_tests · line 70

Quoted 10 lines
tests/tcg/meson.build +2 -1
      foreach key, _ : setup
        if key not in ['cflags', 'qemu_args',
-                       'exe_name', 'test_name', 'env_var',
+                       'exe_name', 'test_name', 'env_var', 'plugin_test',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
        endif
      endforeach
 
+      # return a clear error if user mispell a plugin entry

misspells :D haha

Quoted 16 lines
tests/tcg/meson.build +12 -0
+      if 'plugin_test' in setup
+        foreach key, _ : setup['plugin_test']
+          if key not in ['plugin', 'args']
+            error('unknown tcg plugin entry \'' + key + '\' for test ' + src)
+          endif
+        endforeach
+      endif
+
+      if 'plugin_test' in setup and not get_option('plugins')
+        continue
+      endif
+
      # meson '/' operator drops left operand if right is an absolute path
      src = folder / src
      file = files(src)

tests/tcg/meson.build foreach target, plan: tcg_tests · line 99

Quoted 7 lines
tests/tcg/meson.build +4 -0
@@ -76,6 +93,12 @@ foreach target, plan: tcg_tests
      if 'test_name' in setup
        test_name = setup['test_name']
      endif
+      if 'plugin_test' in setup
+        # remove lib prefix
+        plugin = test_plugins[setup['plugin_test']['plugin']]
+        plugin_name = fs.stem(plugin).substring(3)

Why skip the first 3 chars? Maybe add a comment like you do elsewhere for unclear lines (suggestion).

Regardless of my comments:

Quoted 30 lines
tests/tcg/meson.build +17 -0
+        test_name = 'plugin-' + plugin_name + '-with-' + test_name
+      endif
 
      exe_name = target + '-' + exe_name
      test_name = target + '-' + test_name
@@ -116,6 +139,21 @@ foreach target, plan: tcg_tests
        qemu_args = setup['qemu_args']
      endif
 
+      if 'plugin_test' in setup
+        plugin_setup = setup['plugin_test']
+        plugin = test_plugins[plugin_setup['plugin']]
+        plugin_args = []
+        if 'args' in plugin_setup
+          # add empty arg to generate an additional comma
+          plugin_args = ['', plugin_setup['args']]
+        endif
+        plugin_args = ','.join(plugin_args)
+
+        # since we turn plugin into a string, add dependency explicitly
+        depends += plugin
+        qemu_args = ['-plugin', plugin.full_path() + plugin_args, qemu_args]
+      endif
+
      exe = built_tests[exe_name]
      cmd = [qemu, qemu_args, exe]
 
Signature · 1 line
2.43.0
#37 lore raw

Re: [PATCH 11/27] tests/tcg/meson.build: introduce plugin_test

Quoted 61 lines · Manos Pitsidianakis
Quoted 35 lines · Pierrick Bouvier

We add possibility to declare a test that is based on a plugin.

---
tests/tcg/meson.build | 40 +++++++++++++++++++++++++++++++++++++++-

1 file changed, 39 insertions(+), 1 deletion(-)
tests/tcg/meson.build +4 -0
index 5cd80f3c030..a47f1ada779 100644
@@ -16,6 +16,10 @@ tcg_tests = {}
 #           'cflags': ['cflags to compile test', ...],
 #           'qemu_args': ['qemu command line flags', ...],
 #           'env_var': ['VAR=value', ...],
+#           'plugin_test': {
+#             'plugin': 'plugin_name',
+#             'args': ['plugin_args', ...],
+#           },
 #         }
 #       },
 #       ...
@@ -57,12 +61,25 @@ foreach target, plan: tcg_tests
       # return a clear error if user mispell a setup entry

      foreach key, _ : setup
        if key not in ['cflags', 'qemu_args',
-                       'exe_name', 'test_name', 'env_var', +                       'exe_name', 'test_name', 'env_var', 'plugin_test',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
        endif
      endforeach

Quoted 1 line

+      # return a clear error if user mispell a plugin entry

misspells :D haha

Quoted 20 lines

+      if 'plugin_test' in setup
+        foreach key, _ : setup['plugin_test']
+          if key not in ['plugin', 'args']
+            error('unknown tcg plugin entry \'' + key + '\' for test ' + src)
+          endif
+        endforeach
+      endif

tests/tcg/meson.build +5 -0
+
+      if 'plugin_test' in setup and not get_option('plugins')
+        continue
+      endif
+
      # meson '/' operator drops left operand if right is an absolute
path
      src = folder / src
      file = files(src)
tests/tcg/meson.build +0 -0
@@ -76,6 +93,12 @@ foreach target, plan: tcg_tests

      if 'test_name' in setup
        test_name = setup['test_name']

Quoted 9 lines
Quoted 5 lines

      endif
+      if 'plugin_test' in setup
+        # remove lib prefix
+        plugin = test_plugins[setup['plugin_test']['plugin']] +        plugin_name = fs.stem(plugin).substring(3)

Why skip the first 3 chars? Maybe add a comment like you do elsewhere for unclear lines (suggestion).

The comment says it "remove 'lib' prefix", but I should move it just on next line.

Quoted 35 lines

Regardless of my comments:

Quoted 31 lines

+        test_name = 'plugin-' + plugin_name + '-with-' + test_name +      endif

      exe_name = target + '-' + exe_name
      test_name = target + '-' + test_name

tests/tcg/meson.build +0 -0
@@ -116,6 +139,21 @@ foreach target, plan: tcg_tests

        qemu_args = setup['qemu_args']
      endif

+      if 'plugin_test' in setup
+        plugin_setup = setup['plugin_test']
+        plugin = test_plugins[plugin_setup['plugin']]
+        plugin_args = []
+        if 'args' in plugin_setup
+          # add empty arg to generate an additional comma
+          plugin_args = ['', plugin_setup['args']]
+        endif
+        plugin_args = ','.join(plugin_args)
+
+        # since we turn plugin into a string, add dependency explicitly +        depends += plugin
+        qemu_args = ['-plugin', plugin.full_path() + plugin_args, qemu_args]
+      endif
+
      exe = built_tests[exe_name]
      cmd = [qemu, qemu_args, exe]

--
2.43.0

#38 lore raw

PATCH 12/27 tests/tcg/meson.build: test gdb support and introduce gdb_arch

In reply to Pierrick Bouvier

A given target can now declare which gdb architecture it requires. Also, we add the code to check gdb capabilities, and version. Tests can use gdb_version.version_compare('>=X.Y') to test this.

---
 tests/tcg/meson.build | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
tests/tcg/meson.build +21 -1
index a47f1ada779..1496cba460c 100644
@@ -1,5 +1,11 @@
 env = find_program('env')
 
+gdb_progs = ['gdb-multiarch', 'gdb']
+if config_host.has_key('GDB')
+  gdb_progs = [config_host['GDB'], gdb_progs]
+endif
+gdb = find_program(gdb_progs, required: false)
+
 tcg_tests = {}
 # tcg_tests is a dictionary with following structure:
 #
@@ -7,6 +13,7 @@ tcg_tests = {}
 #   'name_of_target': {
 #     'cc': cross_compiler,
 #     'folder': 'folder_for_test_src_files',
+#     'gdb_arch': 'gdb architecture requirement',
 #     'qemu': emulators['qemu-...'],
 #     'tests': [
 #       {
@@ -33,6 +40,18 @@ tcg_tests = {}
 # is guaranteed to be unique also. They can be duplicated by setting 'test_name'.
 # Default name is derived from src if 'exe_name' and 'test_name' are omitted.
 
+gdb_arch_supported = {}
+gdb_version = '0'
+if gdb.found()
+  gdb_version = gdb.version()
+  gdb_arch = run_command(python, files('../../scripts/probe-gdb-support.py'),
+                           gdb,
+                           check: true)
+  foreach arch: gdb_arch.stdout().split()
+    gdb_arch_supported += {arch: true}
+  endforeach
+endif
+
 # plugins come first, as we need to build the list
 test_plugins = {}
 subdir('plugins')
@@ -46,13 +65,14 @@ foreach target, plan: tcg_tests
 
   # return a clear error if user mispell a target entry
   foreach key, _ : plan
-    if key not in ['cc', 'folder', 'qemu', 'tests']
+    if key not in ['cc', 'folder', 'gdb_arch', 'qemu', 'tests']
       error('unknown tcg test plan entry \'' + key + '\' for target ' + target)
     endif
   endforeach
 
   cc = plan['cc']
   folder = plan['folder']
+  gdb_arch = plan['gdb_arch']
   qemu = plan['qemu']
   tests = plan['tests']
 
Signature · 1 line
2.43.0
Reviewed-by on v1 12/27
#39 lore raw

Re: [PATCH 12/27] tests/tcg/meson.build: test gdb support and introduce gdb_arch

Quoted 6 lines · Pierrick Bouvier

A given target can now declare which gdb architecture it requires. Also, we add the code to check gdb capabilities, and version. Tests can use gdb_version.version_compare('>=X.Y') to test this.

---

Quoted 65 lines

tests/tcg/meson.build | 22 +++++++++++++++++++++-

1 file changed, 21 insertions(+), 1 deletion(-)
tests/tcg/meson.build +21 -1
index a47f1ada779..1496cba460c 100644
@@ -1,5 +1,11 @@
 env = find_program('env')
 
+gdb_progs = ['gdb-multiarch', 'gdb']
+if config_host.has_key('GDB')
+  gdb_progs = [config_host['GDB'], gdb_progs]
+endif
+gdb = find_program(gdb_progs, required: false)
+
 tcg_tests = {}
 # tcg_tests is a dictionary with following structure:
 #
@@ -7,6 +13,7 @@ tcg_tests = {}
 #   'name_of_target': {
 #     'cc': cross_compiler,
 #     'folder': 'folder_for_test_src_files',
+#     'gdb_arch': 'gdb architecture requirement',
 #     'qemu': emulators['qemu-...'],
 #     'tests': [
 #       {
@@ -33,6 +40,18 @@ tcg_tests = {}
 # is guaranteed to be unique also. They can be duplicated by setting 'test_name'.
 # Default name is derived from src if 'exe_name' and 'test_name' are omitted.
 
+gdb_arch_supported = {}
+gdb_version = '0'
+if gdb.found()
+  gdb_version = gdb.version()
+  gdb_arch = run_command(python, files('../../scripts/probe-gdb-support.py'),
+                           gdb,
+                           check: true)
+  foreach arch: gdb_arch.stdout().split()
+    gdb_arch_supported += {arch: true}
+  endforeach
+endif
+
 # plugins come first, as we need to build the list
 test_plugins = {}
 subdir('plugins')
@@ -46,13 +65,14 @@ foreach target, plan: tcg_tests
 
  # return a clear error if user mispell a target entry
  foreach key, _ : plan
-    if key not in ['cc', 'folder', 'qemu', 'tests']
+    if key not in ['cc', 'folder', 'gdb_arch', 'qemu', 'tests']
      error('unknown tcg test plan entry \'' + key + '\' for target ' + target)
    endif
  endforeach
 
  cc = plan['cc']
  folder = plan['folder']
+  gdb_arch = plan['gdb_arch']
  qemu = plan['qemu']
  tests = plan['tests']
 
Signature · 1 line
2.43.0
#40 lore raw

PATCH 13/27 tests/tcg/meson.build: introduce gdb_test

In reply to Pierrick Bouvier

We can now declare a test requiring gdb interaction, based on tests/guest-debug/run-test.py.

---
 tests/tcg/meson.build | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
tests/tcg/meson.build +20 -2
index 1496cba460c..d0080eb0f9f 100644
@@ -5,6 +5,7 @@ if config_host.has_key('GDB')
   gdb_progs = [config_host['GDB'], gdb_progs]
 endif
 gdb = find_program(gdb_progs, required: false)
+prog_gdb_test = find_program('../guest-debug/run-test.py')
 
 tcg_tests = {}
 # tcg_tests is a dictionary with following structure:
@@ -22,6 +23,7 @@ tcg_tests = {}
 #           'test_name': ['provide an alternative test name'],
 #           'cflags': ['cflags to compile test', ...],
 #           'qemu_args': ['qemu command line flags', ...],
+#           'gdb_test': ['gdb test args'],
 #           'env_var': ['VAR=value', ...],
 #           'plugin_test': {
 #             'plugin': 'plugin_name',
@@ -80,7 +82,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',
+        if key not in ['cflags', 'qemu_args', 'gdb_test',
                        'exe_name', 'test_name', 'env_var', 'plugin_test',
                        ]
           error('unknown tcg setup entry \'' + key + '\' for test ' + src)
@@ -96,6 +98,10 @@ foreach target, plan: tcg_tests
         endforeach
       endif
 
+      if 'gdb_test' in setup and gdb_arch not in gdb_arch_supported
+        continue
+      endif
+
       if 'plugin_test' in setup and not get_option('plugins')
         continue
       endif
@@ -113,7 +119,9 @@ foreach target, plan: tcg_tests
       if 'test_name' in setup
         test_name = setup['test_name']
       endif
-      if 'plugin_test' in setup
+      if 'gdb_test' in setup
+        test_name = 'gdb-' + test_name
+      elif 'plugin_test' in setup
         # remove lib prefix
         plugin = test_plugins[setup['plugin_test']['plugin']]
         plugin_name = fs.stem(plugin).substring(3)
@@ -177,6 +185,16 @@ foreach target, plan: tcg_tests
       exe = built_tests[exe_name]
       cmd = [qemu, qemu_args, exe]
 
+      if 'gdb_test' in setup
+        cmd = [prog_gdb_test,
+               '--gdb', gdb,
+               '--qemu', qemu,
+               '--qargs', ' '.join(qemu_args),
+               '--bin', exe,
+               setup['gdb_test'],
+              ]
+      endif
+
       # some tests expect QEMU env var to be set
       cmd = ['QEMU=' + qemu.full_path(), cmd]
 
Signature · 1 line
2.43.0
Reviewed-by on v1 13/27
#41 lore raw

Re: [PATCH 13/27] tests/tcg/meson.build: introduce gdb_test

Quoted 5 lines · Pierrick Bouvier

We can now declare a test requiring gdb interaction, based on tests/guest-debug/run-test.py.

---

Quoted 74 lines

tests/tcg/meson.build | 22 ++++++++++++++++++++--

1 file changed, 20 insertions(+), 2 deletions(-)
tests/tcg/meson.build +0 -0
index 1496cba460c..d0080eb0f9f 100644
@@ -5,6 +5,7 @@ if config_host.has_key('GDB')
  gdb_progs = [config_host['GDB'], gdb_progs]

endif
gdb = find_program(gdb_progs, required: false) +prog_gdb_test = find_program('../guest-debug/run-test.py')

tcg_tests = {}

# tcg_tests is a dictionary with following structure:
tests/tcg/meson.build +19 -2
@@ -22,6 +23,7 @@ tcg_tests = {}
 #           'test_name': ['provide an alternative test name'],
 #           'cflags': ['cflags to compile test', ...],
 #           'qemu_args': ['qemu command line flags', ...],
+#           'gdb_test': ['gdb test args'],
 #           'env_var': ['VAR=value', ...],
 #           'plugin_test': {
 #             'plugin': 'plugin_name',
@@ -80,7 +82,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',
+        if key not in ['cflags', 'qemu_args', 'gdb_test',
                       'exe_name', 'test_name', 'env_var', 'plugin_test',
                       ]
          error('unknown tcg setup entry \'' + key + '\' for test ' + src)
@@ -96,6 +98,10 @@ foreach target, plan: tcg_tests
        endforeach
      endif
 
+      if 'gdb_test' in setup and gdb_arch not in gdb_arch_supported
+        continue
+      endif
+
      if 'plugin_test' in setup and not get_option('plugins')
        continue
      endif
@@ -113,7 +119,9 @@ foreach target, plan: tcg_tests
      if 'test_name' in setup
        test_name = setup['test_name']
      endif
-      if 'plugin_test' in setup
+      if 'gdb_test' in setup
+        test_name = 'gdb-' + test_name
+      elif 'plugin_test' in setup
        # remove lib prefix
        plugin = test_plugins[setup['plugin_test']['plugin']]
        plugin_name = fs.stem(plugin).substring(3)
@@ -177,6 +185,16 @@ foreach target, plan: tcg_tests
      exe = built_tests[exe_name]
      cmd = [qemu, qemu_args, exe]
 
+      if 'gdb_test' in setup
+        cmd = [prog_gdb_test,
+               '--gdb', gdb,
+               '--qemu', qemu,
+               '--qargs', ' '.join(qemu_args),
+               '--bin', exe,
+               setup['gdb_test'],
+              ]
+      endif
+
      # some tests expect QEMU env var to be set
      cmd = ['QEMU=' + qemu.full_path(), cmd]
 
Signature · 1 line
2.43.0
#42 lore raw

PATCH 14/27 tests/tcg/meson.build: add default flag for testing compiler support

In reply to Pierrick Bouvier

This global variable can be used as cflags when checking if a compiler supports specific flags.

---
 tests/tcg/meson.build | 1 +
 1 file changed, 1 insertion(+)
tests/tcg/meson.build +1 -0
index d0080eb0f9f..aca59933d71 100644
@@ -1,3 +1,4 @@
+cc_check_args = ['-xc', '/dev/null', '-o', '/dev/null', '-c']
 env = find_program('env')
 
 gdb_progs = ['gdb-multiarch', 'gdb']
Signature · 1 line
2.43.0
#44 lore raw

PATCH 15/27 tests/tcg/meson.build: introduce wrapper

In reply to Pierrick Bouvier

We add possibility to wrap a test command through a given script. This can be used to provide any kind of ad-hoc check for specific tests.

---
 tests/tcg/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tests/tcg/meson.build +6 -1
index aca59933d71..5380a360830 100644
@@ -26,6 +26,7 @@ tcg_tests = {}
 #           'qemu_args': ['qemu command line flags', ...],
 #           'gdb_test': ['gdb test args'],
 #           'env_var': ['VAR=value', ...],
+#           'wrapper': [program_to_launch_test, 'args'...],
 #           'plugin_test': {
 #             'plugin': 'plugin_name',
 #             'args': ['plugin_args', ...],
@@ -85,7 +86,7 @@ foreach target, plan: tcg_tests
       foreach key, _ : setup
         if key not in ['cflags', 'qemu_args', 'gdb_test',
                        'exe_name', 'test_name', 'env_var', 'plugin_test',
-                       ]
+                       'wrapper']
           error('unknown tcg setup entry \'' + key + '\' for test ' + src)
         endif
       endforeach
@@ -196,6 +197,10 @@ foreach target, plan: tcg_tests
               ]
       endif
 
+      if 'wrapper' in setup
+        cmd = [setup['wrapper'], cmd]
+      endif
+
       # some tests expect QEMU env var to be set
       cmd = ['QEMU=' + qemu.full_path(), cmd]
 
Signature · 1 line
2.43.0
Reviewed-by on v1 15/27
#45 lore raw

Re: [PATCH 15/27] tests/tcg/meson.build: introduce wrapper

Quoted 7 lines · Pierrick Bouvier

We add possibility to wrap a test command through a given script. This can be used to provide any kind of ad-hoc check for specific tests.

---
  tests/tcg/meson.build | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
#46 lore raw

PATCH 16/27 tests/tcg/meson.build: introduce expected_output

In reply to Pierrick Bouvier

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.

---
 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
tests/tcg/meson.build +8 -1
index 5380a360830..3d2c0d6583b 100644
@@ -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
tests/tcg/scripts/run_and_diff.sh new file +12 -0
new file mode 100755
index 00000000000..d1e9243c49d
@@ -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
Signature · 1 line
2.43.0
#47 lore raw

Re: [PATCH 16/27] tests/tcg/meson.build: introduce expected_output

Quoted 64 lines · Pierrick Bouvier

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.

---
 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
tests/tcg/meson.build +8 -1
index 5380a360830..3d2c0d6583b 100644
@@ -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
tests/tcg/scripts/run_and_diff.sh new file +2 -0
new file mode 100755
index 00000000000..d1e9243c49d
@@ -0,0 +1,12 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-2.0-or-later

tests/tcg/scripts/run_and_diff.sh line 12

Quoted 10 lines
tests/tcg/scripts/run_and_diff.sh new file +10 -0
+
+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.

#48 lore raw

Re: [PATCH 16/27] tests/tcg/meson.build: introduce expected_output

Quoted 70 lines · Pierrick Bouvier
Quoted 69 lines · Pierrick Bouvier

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.

---
 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
tests/tcg/meson.build +8 -1
index 5380a360830..3d2c0d6583b 100644
@@ -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
tests/tcg/scripts/run_and_diff.sh new file +7 -0
new file mode 100755
index 00000000000..d1e9243c49d
@@ -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
Quoted 8 lines

tests/tcg/scripts/run_and_diff.sh line 12

Quoted 5 lines
tests/tcg/scripts/run_and_diff.sh new file +5 -0
+    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.

Also, consider if using #!/bin/sh is possible, since it's universally portable.

#49 lore raw

Re: [PATCH 16/27] tests/tcg/meson.build: introduce expected_output

Quoted 85 lines · Manos Pitsidianakis
Quoted 74 lines · Pierrick Bouvier
Quoted 73 lines · Pierrick Bouvier

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.

---
 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

tests/tcg/meson.build +0 -0
index 5380a360830..3d2c0d6583b 100644
@@ -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:
tests/tcg/meson.build +1 -0
@@ -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)
tests/tcg/meson.build +0 -0
@@ -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

tests/tcg/scripts/ renamed from tests/tcg/scripts/run_and_diff.sh +0 -0

run_and_diff.sh
new file mode 100755
index 00000000000..d1e9243c49d

tests/tcg/scripts/run_and_diff.sh new file +7 -0
@@ -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
Quoted 8 lines

tests/tcg/scripts/run_and_diff.sh line 12

Quoted 5 lines
tests/tcg/scripts/run_and_diff.sh new file +5 -0
+    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.

Quoted 3 lines

Also, consider if using #!/bin/sh is possible, since it's universally portable.

Probably will move this to python instead. sh does not have equivalent for set -euo pipefail.

#50 lore raw

PATCH 17/27 tests/tcg/meson.build: add wrapper run_and_check_forbidden_output

In reply to Pierrick Bouvier

One of our test requires to make sure output does not contain a specific string. An example is system multiarch test run-gdbstub-untimely-packet.

---
 tests/tcg/meson.build                         |  3 +++
 .../scripts/run_and_check_forbidden_output.sh | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100755 tests/tcg/scripts/run_and_check_forbidden_output.sh
tests/tcg/meson.build +3 -0
index 3d2c0d6583b..f379449e582 100644
@@ -8,6 +8,9 @@ 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')
+prog_run_and_check_forbidden_output = find_program(
+  './scripts/run_and_check_forbidden_output.sh'
+)
 
 tcg_tests = {}
 # tcg_tests is a dictionary with following structure:
tests/tcg/scripts/run_and_check_forbidden_output.sh new file +19 -0
new file mode 100755
index 00000000000..4486ca8ef83
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set -euo pipefail
+
+if [ $# -lt 2 ]; then
+    echo "run_and_check_forbidden_output: 'forbidden string' cmd [args]..." 1>&2
+    exit 1
+fi
+forbidden="$1";shift
+output=$("$@" 2>&1)
+set -x
+if ! echo "$output" | grep -Fi "$forbidden"
+then
+    echo "output does not contain forbidden string: $forbidden"
+    exit 0
+fi
+echo "found forbidden string: $forbidden" 1>&2
+exit 1
Signature · 1 line
2.43.0
#51 lore raw

PATCH 18/27 tests/tcg/meson.build: add wrapper run_with_input

In reply to Pierrick Bouvier

Semihosting console tests require console interaction, and were flagged as manual because of this. This wrapper automates interaction, by sending a specific string on stdin.

---
 tests/tcg/meson.build               |  1 +
 tests/tcg/scripts/run_with_input.sh | 12 ++++++++++++
 2 files changed, 13 insertions(+)
 create mode 100755 tests/tcg/scripts/run_with_input.sh
tests/tcg/meson.build +1 -0
index f379449e582..7201a7809e1 100644
@@ -8,6 +8,7 @@ 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')
+prog_run_with_input = find_program('./scripts/run_with_input.sh')
 prog_run_and_check_forbidden_output = find_program(
   './scripts/run_and_check_forbidden_output.sh'
 )
tests/tcg/scripts/run_with_input.sh new file +12 -0
new file mode 100755
index 00000000000..3d280547c3a
@@ -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_with_input: input_string cmd [args]..." 1>&2
+    exit 1
+fi
+input="$1";shift
+set -x
+echo "$input" | "$@"
Signature · 1 line
2.43.0
#52 lore raw

Re: [PATCH 18/27] tests/tcg/meson.build: add wrapper run_with_input

Quoted 6 lines · Pierrick Bouvier

Semihosting console tests require console interaction, and were flagged as manual because of this. This wrapper automates interaction, by sending a specific string on stdin.

---

Fyi there is also expect(1) https://packages.debian.org/trixie/expect but is kind of arcane.

Quoted 38 lines

tests/tcg/meson.build | 1 +
tests/tcg/scripts/run_with_input.sh | 12 ++++++++++++

2 files changed, 13 insertions(+)

create mode 100755 tests/tcg/scripts/run_with_input.sh

tests/tcg/meson.build +1 -0
index f379449e582..7201a7809e1 100644
@@ -8,6 +8,7 @@ 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')
+prog_run_with_input = find_program('./scripts/run_with_input.sh')

prog_run_and_check_forbidden_output = find_program(
'./scripts/run_and_check_forbidden_output.sh'
)

tests/tcg/scripts/run_with_input.sh new file +12 -0
new file mode 100755
index 00000000000..3d280547c3a
@@ -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_with_input: input_string cmd [args]..." 1>&2
+    exit 1
+fi
+input="$1";shift
+set -x
+echo "$input" | "$@"
Signature · 1 line
2.43.0
#53 lore raw

Re: [PATCH 18/27] tests/tcg/meson.build: add wrapper run_with_input

Quoted 6 lines · Manos Pitsidianakis
Quoted 4 lines · Pierrick Bouvier

Semihosting console tests require console interaction, and were flagged as manual because of this. This wrapper automates interaction, by sending a specific string on stdin.

Quoted 6 lines
Quoted 2 lines

---

Fyi there is also expect(1) https://packages.debian.org/trixie/expect
but is kind of arcane.

An an additional dependency that may or may not be available also. Also, this kind of interaction is more for functional test. The goal here was just to automate a single test.

#54 lore raw

PATCH 19/27 tests/tcg/meson.build: add wrapper record_replay

In reply to Pierrick Bouvier

Runs a record and replay test, and make sure the output produced by both runs is the same.

---
 tests/tcg/meson.build              |  1 +
 tests/tcg/scripts/record_replay.sh | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100755 tests/tcg/scripts/record_replay.sh
tests/tcg/meson.build +1 -0
index 7201a7809e1..f0efd46ee3e 100644
@@ -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_record_replay = find_program('./scripts/record_replay.sh')
 prog_run_and_diff = find_program('./scripts/run_and_diff.sh')
 prog_run_with_input = find_program('./scripts/run_with_input.sh')
 prog_run_and_check_forbidden_output = find_program(
tests/tcg/scripts/record_replay.sh new file +16 -0
new file mode 100755
index 00000000000..57775a2d4c1
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set -euo pipefail
+
+if [ $# -lt 2 ]; then
+    echo "record_replay: qemu_bin [args]..." 1>&2
+    exit 1
+fi
+qemu="$1";shift
+tmp=$(mktemp -d)
+trap "rm -rf $tmp" EXIT
+set -x
+$qemu -icount shift=5,rr=record,rrfile=$tmp/rr.bin "$@" |& tee $tmp/record
+$qemu -icount shift=5,rr=replay,rrfile=$tmp/rr.bin "$@" |& tee $tmp/replay
+diff $tmp/record $tmp/replay
Signature · 1 line
2.43.0
#55 lore raw

PATCH 20/27 tests/tcg/meson.build: add wrapper check_plugin_output

In reply to Pierrick Bouvier

This wrapper runs a qemu command, record command output and plugin output, and forward both to a check script.
We use this pattern in several plugin tests (for instance, with validate-memory-counts.py).

---
 tests/tcg/meson.build                    |  1 +
 tests/tcg/scripts/check_plugin_output.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100755 tests/tcg/scripts/check_plugin_output.sh
tests/tcg/meson.build +1 -0
index f0efd46ee3e..6e46c121fda 100644
@@ -6,6 +6,7 @@ if config_host.has_key('GDB')
   gdb_progs = [config_host['GDB'], gdb_progs]
 endif
 gdb = find_program(gdb_progs, required: false)
+prog_check_plugin_output = find_program('./scripts/check_plugin_output.sh')
 prog_gdb_test = find_program('../guest-debug/run-test.py')
 prog_record_replay = find_program('./scripts/record_replay.sh')
 prog_run_and_diff = find_program('./scripts/run_and_diff.sh')
tests/tcg/scripts/check_plugin_output.sh new file +19 -0
new file mode 100755
index 00000000000..4d12e23ad60
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set -euo pipefail
+
+if [ $# -lt 3 ]; then
+    echo "check_plugin_output: check_cmd qemu_bin [args]..." 1>&2
+    exit 1
+fi
+check_cmd="$1"; shift
+qemu="$1"; shift
+tmp=$(mktemp -d)
+trap "rm -rf $tmp" EXIT
+
+set -x
+
+$qemu -d plugin -D $tmp/plugin "$@" |& tee $tmp/output
+cat $tmp/plugin
+$check_cmd $tmp/output $tmp/plugin
Signature · 1 line
2.43.0
#56 lore raw

Re: [PATCH 20/27] tests/tcg/meson.build: add wrapper check_plugin_output

Quoted 40 lines · Pierrick Bouvier

This wrapper runs a qemu command, record command output and plugin output, and forward both to a check script.
We use this pattern in several plugin tests (for instance, with validate-memory-counts.py).

---
tests/tcg/meson.build | 1 +
tests/tcg/scripts/check_plugin_output.sh | 19 +++++++++++++++++++

2 files changed, 20 insertions(+)

create mode 100755 tests/tcg/scripts/check_plugin_output.sh

tests/tcg/meson.build +0 -0
index f0efd46ee3e..6e46c121fda 100644
@@ -6,6 +6,7 @@ if config_host.has_key('GDB')
  gdb_progs = [config_host['GDB'], gdb_progs]

endif
gdb = find_program(gdb_progs, required: false) +prog_check_plugin_output = find_program('./scripts/check_plugin_output.sh') prog_gdb_test = find_program('../guest-debug/run-test.py') prog_record_replay = find_program('./scripts/record_replay.sh') prog_run_and_diff = find_program('./scripts/run_and_diff.sh')

tests/tcg/scripts/check_plugin_output.sh new file +9 -0
new file mode 100755
index 00000000000..4d12e23ad60
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set -euo pipefail
+
+if [ $# -lt 3 ]; then
+    echo "check_plugin_output: check_cmd qemu_bin [args]..." 1>&2
+    exit 1
+fi

tests/tcg/scripts/check_plugin_output.sh line 19

Quoted 10 lines
tests/tcg/scripts/check_plugin_output.sh new file +10 -0
+check_cmd="$1"; shift
+qemu="$1"; shift
+tmp=$(mktemp -d)
+trap "rm -rf $tmp" EXIT
+
+set -x
+
+$qemu -d plugin -D $tmp/plugin "$@" |& tee $tmp/output
+cat $tmp/plugin
+$check_cmd $tmp/output $tmp/plugin

Could we write a single python script for all the shell script wrappers and use a different kind of wrapper depending on its command line flags/subcommand we invoke it with?

Maybe this could be better? WDYT?

#57 lore raw

Re: [PATCH 20/27] tests/tcg/meson.build: add wrapper check_plugin_output

Quoted 51 lines · Manos Pitsidianakis
Quoted 49 lines · Pierrick Bouvier

This wrapper runs a qemu command, record command output and plugin output, and forward both to a check script.
We use this pattern in several plugin tests (for instance, with validate-memory-counts.py).

---
tests/tcg/meson.build                    |  1 + tests/tcg/scripts/check_plugin_output.sh | 19 +++++++++++++++++++

2 files changed, 20 insertions(+)

create mode 100755 tests/tcg/scripts/check_plugin_output.sh

tests/tcg/meson.build +0 -0
index f0efd46ee3e..6e46c121fda 100644
@@ -6,6 +6,7 @@ if config_host.has_key('GDB')

  gdb_progs = [config_host['GDB'], gdb_progs]
endif
gdb = find_program(gdb_progs, required: false) +prog_check_plugin_output = find_program('./scripts/ check_plugin_output.sh')
prog_gdb_test = find_program('../guest-debug/run-test.py') prog_record_replay = find_program('./scripts/record_replay.sh') prog_run_and_diff = find_program('./scripts/run_and_diff.sh')

tests/tcg/ renamed from tests/tcg/scripts/check_plugin_output.sh +0 -0

scripts/check_plugin_output.sh
new file mode 100755
index 00000000000..4d12e23ad60

tests/tcg/scripts/check_plugin_output.sh new file +17 -0
@@ -0,0 +1,19 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+set -euo pipefail
+
+if [ $# -lt 3 ]; then
+    echo "check_plugin_output: check_cmd qemu_bin [args]..." 1>&2
+    exit 1
+fi
+check_cmd="$1"; shift
+qemu="$1"; shift
+tmp=$(mktemp -d)
+trap "rm -rf $tmp" EXIT
+
+set -x
+
+$qemu -d plugin -D $tmp/plugin "$@" |& tee $tmp/output
Quoted 8 lines
Quoted 3 lines
tests/tcg/scripts/check_plugin_output.sh new file +2 -0
+cat $tmp/plugin
+$check_cmd $tmp/output $tmp/plugin

--

Could we write a single python script for all the shell script wrappers and use a different kind of wrapper depending on its command line flags/ subcommand we invoke it with?
Maybe this could be better? WDYT?

We could do that for sure. Better or not? Not sure, but I don't have strong opinion.
I just picked bash because it's more concise than python for this. Before putting too much effort into the wrapper part, I'll wait to see if the rest is working for maintainers.

Regards,
Pierrick

#58 lore raw

PATCH 21/27 tests/tcg/aarch64: add user tests

In reply to Pierrick Bouvier

We are finally ready to add tests. Let's start with aarch64 user first.

---
 tests/tcg/aarch64/meson.build | 213 ++++++++++++++++++++++++++++++++++
 tests/tcg/meson.build         |   3 +
 2 files changed, 216 insertions(+)
 create mode 100644 tests/tcg/aarch64/meson.build
tests/tcg/aarch64/meson.build new file +213 -0
new file mode 100644
index 00000000000..9c42b129551
@@ -0,0 +1,213 @@
+cc = find_program('aarch64-linux-gnu-gcc', required : false)
+
+if not cc.found()
+  subdir_done()
+endif
+
+feat_cflags = {
+  'aes': '-march=armv8-a+aes',
+  'sve': '-march=armv8.1-a+sve',
+  'sve2': '-march=armv8.1-a+sve2',
+  'v8.2': '-march=armv8.2-a',
+  'v8.3': '-march=armv8.3-a',
+  'v8.5': '-march=armv8.5-a',
+  'bti':  '-mbranch-protection=standard',
+  'mte':  '-march=armv8.5-a+memtag',
+  'sme':  '-Wa,-march=armv9-a+sme',
+}
+cc_has_feat = {}
+
+foreach feat, flags : feat_cflags
+  cmd = run_command([cc, cc_check_args, flags], check: false)
+  avail = cmd.returncode() == 0
+  cc_has_feat += {feat: avail}
+  if not avail
+    warning('aarch64 tcg tests for feature \'' + feat + '\' ' +
+            'disabled: unsupported by cross-compiler')
+  endif
+endforeach
+
+gdb_feat_version = {
+  'sme-tiles': '14.1',
+  'mte': '15.1',
+  'mte-baremetal': '16.0',
+}
+gdb_has_feat = {}
+
+foreach feat, min_ver : gdb_feat_version
+  avail = gdb_version.version_compare('>=' + min_ver)
+  gdb_has_feat += {feat: avail}
+  if not avail
+    warning('aarch64 gdb tests for feature \'' + feat + '\' ' +
+            'disabled: unsupported by gdb')
+  endif
+endforeach
+
+if 'qemu-aarch64' not in emulators
+  subdir_done()
+endif
+
+tests = []
+
+# Base architecture tests
+tests += {
+  '../arm/fcvt.c': {'cflags': '-lm', 'expected_output': 'fcvt.ref'},
+  'pcalign-a64.c': {},
+  'lse2-fault.c': {},
+  'test-2248.c': {},
+  'test-2150.c': {},
+}
+
+if cc_has_feat['v8.2']
+  tests += {'dcpop.c': {'cflags': feat_cflags['v8.2']}}
+endif
+
+if cc_has_feat['v8.5']
+  tests += {'dcpodp.c': {'cflags': feat_cflags['v8.5']}}
+endif
+
+# Pauth Tests
+if cc_has_feat['v8.3']
+  f = feat_cflags['v8.3']
+  cpu_max = ['-cpu', 'max']
+  cpu_neoverse = ['-cpu', 'neoverse-v1']
+  tests += {
+    'test-2375.c': {'cflags': f},
+    'pauth-1.c': {'cflags': f, 'qemu_args': cpu_max},
+    'pauth-2.c': {'cflags': f, 'qemu_args': cpu_max},
+    # Choose a cpu with FEAT_Pauth but without FEAT_FPAC for pauth-[45].
+    'pauth-4.c': {'cflags': f, 'qemu_args': cpu_neoverse},
+    'pauth-5.c': {'cflags': f, 'qemu_args': cpu_neoverse},
+  }
+endif
+
+# BTI Tests
+# bti-1 tests the elf notes, so we require special compiler support.
+if cc_has_feat['bti']
+  f = [feat_cflags['bti'], '-fno-stack-protector', '-nostdlib']
+  tests += {
+    'bti-1.c': {'cflags': f},
+    'bti-3.c': {'cflags': f},
+  }
+endif
+# bti-2 tests PROT_BTI, so no special compiler support required.
+tests += {'bti-2.c': {}}
+
+# MTE Tests
+if cc_has_feat['mte']
+  f = feat_cflags['mte']
+  tests += {
+    'mte-1.c': {'cflags': f},
+    'mte-2.c': {'cflags': f},
+    'mte-3.c': {'cflags': f},
+    'mte-4.c': {'cflags': f},
+    'mte-5.c': {'cflags': f},
+    'mte-6.c': {'cflags': f},
+    'mte-7.c': {'cflags': f},
+    'mte-8.c': {'cflags': f},
+  }
+endif
+
+# SME Tests
+if cc_has_feat['sme']
+  f = feat_cflags['sme']
+  tests += {
+    'sme-outprod1.c': {'cflags': f},
+    'sme-smopa-1.c': {'cflags': f},
+    'sme-smopa-2.c': {'cflags': f},
+    'sme-fmopa-1.c': {'cflags': f},
+    'sme-fmopa-2.c': {'cflags': f},
+    'sme-fmopa-3.c': {'cflags': f},
+  }
+endif
+
+# GCS Tests
+tests += {
+  'gcsstr.c': {},
+  'gcspushm.c': {},
+  'gcsss.c': {},
+}
+
+# System Registers Tests
+tests += {'sysregs.c': {}}
+
+# Crypto Tests
+tests += {'test-aes.c': {'cflags': feat_cflags['aes']}}
+
+# SVE Tests
+if cc_has_feat['sve']
+  f = feat_cflags['sve']
+  tests += {
+    'sve-ioctls.c': {'cflags': f},
+    'sve-str.c': {'cflags': [f, '-O1']},
+  }
+endif
+
+# SVE2 Tests
+if cc_has_feat['sve2']
+  tests += {'test-826.c': {'cflags': feat_cflags['sve2']}}
+endif
+
+# GDB Tests
+if cc_has_feat['sve']
+  f = feat_cflags['sve']
+  tests += {
+    'sysregs.c': {
+      'exe_name': 'sysregs-sve',
+      'cflags': f,
+      'gdb_test': ['--test', files('gdbstub/test-sve.py')],
+    },
+    'sve-ioctls.c': {
+      'gdb_test': ['--test', files('gdbstub/test-sve-ioctl.py')],
+    },
+  }
+endif
+
+if cc_has_feat['sme']
+  f = feat_cflags['sme']
+  sysregs_sme = 'sysregs-sme'
+  tests += {
+    'sysregs.c': {
+      'exe_name': sysregs_sme,
+      'cflags': f,
+      'gdb_test': ['--test', files('gdbstub/test-sme.py'), '--',
+                   'test_sme', '--gdb_basic_za_test'],
+    }
+  }
+  if gdb_has_feat['sme-tiles']
+    tests += {
+      'sysregs.c': {
+        'test_name': 'sysregs-sme-tile-slice',
+        'exe_name': sysregs_sme,
+        'gdb_test': ['--test', files('gdbstub/test-sme.py'), '--',
+                     'test_sme', '--gdb_tile_slice_test'],
+      }
+    }
+  endif
+  tests += {
+    'sysregs.c': {
+      'test_name': 'sysregs-sme2',
+      'exe_name': sysregs_sme,
+      'gdb_test': ['--test', files('gdbstub/test-sme2.py')],
+    }
+  }
+endif
+
+if cc_has_feat['mte'] and gdb_has_feat['mte']
+  f = feat_cflags['mte']
+  tests += {
+    'mte-8.c': {
+      'gdb_test': ['--test', files('gdbstub/test-mte.py'), '--', '--mode=user'],
+    }
+  }
+endif
+
+tcg_tests += {
+  'aarch64-linux-user': {
+    'cc': cc,
+    'folder': 'aarch64',
+    'gdb_arch': 'aarch64',
+    'qemu': emulators['qemu-aarch64'],
+    'tests': tests,
+  }
+}
tests/tcg/meson.build +3 -0
index 6e46c121fda..8633c58459b 100644
@@ -68,6 +68,9 @@ endif
 test_plugins = {}
 subdir('plugins')
 
+# Now let's go through all architectures
+subdir('aarch64')
+
 # Finally, we can create all test executables and test targets
 foreach target, plan: tcg_tests
   # Detect duplicated executables/tests, and report an error to force user to
Signature · 1 line
2.43.0
#59 lore raw

Re: [PATCH 21/27] tests/tcg/aarch64: add user tests

tests/tcg/aarch64/meson.build line 5

Quoted 7 lines · Pierrick Bouvier

+++ b/tests/tcg/aarch64/meson.build

tests/tcg/aarch64/meson.build new file +5 -0
@@ -0,0 +1,213 @@
+cc = find_program('aarch64-linux-gnu-gcc', required : false)
+
+if not cc.found()
+  subdir_done()
+endif

The primary thing we lose here is the ability to use containers for the cross-compile.

We detect cross-compilers in configure. We currently write them to build/tests/tcg/${target}/config-target.mak. It's not very meson to parse a file like that, but I imagine we could use scripts or meson variables somehow.

r~

#60 lore raw

Re: [PATCH 21/27] tests/tcg/aarch64: add user tests

Quoted 12 lines · Richard Henderson

tests/tcg/aarch64/meson.build line 5

Quoted 7 lines · Pierrick Bouvier

+++ b/tests/tcg/aarch64/meson.build

tests/tcg/aarch64/meson.build new file +5 -0
@@ -0,0 +1,213 @@
+cc = find_program('aarch64-linux-gnu-gcc', required : false)
+
+if not cc.found()
+  subdir_done()
+endif

The primary thing we lose here is the ability to use containers for the cross-compile.

It's definitely on the requirements list, but as listed in the cover letter, out of the scope for current series.

Quoted 5 lines

We detect cross-compilers in configure.  We currently write them to build/tests/tcg/${target}/config-target.mak.  It's not very meson to parse a file like that, but I imagine we could use scripts or meson variables somehow.

We can rewrite this mechanic in meson directly, similar to what we do for gdb in this series. find_program from a list of known names, else fallback to our cross containers which have a known and fixed setup.

The "build_container_and_run_compiler" logic will be in an external script, appearing as a cross compiler itself, so meson role will be limited to find a given program and test some flags.

Quoted 2 lines

r~

#61 lore raw

Re: [PATCH 21/27] tests/tcg/aarch64: add user tests

In reply to Richard Henderson
Quoted 11 lines · Richard Henderson

tests/tcg/aarch64/meson.build line 5

Quoted 7 lines · Pierrick Bouvier

+++ b/tests/tcg/aarch64/meson.build

tests/tcg/aarch64/meson.build new file +5 -0
@@ -0,0 +1,213 @@
+cc = find_program('aarch64-linux-gnu-gcc', required : false)
+
+if not cc.found()
+  subdir_done()
+endif

The primary thing we lose here is the ability to use containers for the cross-compile.

Quoted 1 line

We detect cross-compilers in configure.  We currently write them to build/tests/tcg/${target}/config-target.mak.  It's not very meson to parse a file like that, but I imagine we could use scripts or meson variables somehow.

That's not a problem, we can write them in [binaries] and find_program() will pick it up automatically. I'm a bit more worried about having to reinvent cross compilation altogether, I'll reply elsewhere.

Paolo

#62 lore raw

PATCH 22/27 tests/tcg/aarch64: add system tests

In reply to Pierrick Bouvier

Let's continue with system tests. Take note of how we don't generate intermediate (common) objects, but instead provide a single build command for every test, embedding all dependencies.

Besides reducing boilerplate, this makes sure we track correctly all the dependencies for a given test. Compilation time difference is invisible.

---
 tests/tcg/aarch64/meson.build        |  2 +
 tests/tcg/aarch64/system/meson.build | 69 ++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)
 create mode 100644 tests/tcg/aarch64/system/meson.build
tests/tcg/aarch64/meson.build +2 -0
index 9c42b129551..e6cf5309649 100644
@@ -43,6 +43,8 @@ foreach feat, min_ver : gdb_feat_version
   endif
 endforeach
 
+subdir('system')
+
 if 'qemu-aarch64' not in emulators
   subdir_done()
 endif
tests/tcg/aarch64/system/meson.build new file +69 -0

69 lines not on this page · raw message

Signature · 1 line
2.43.0
#63 lore raw

PATCH 23/27 tests/tcg/multiarch: declare user tests

In reply to Pierrick Bouvier

At this point, those tests are just declared and not used yet.

---
 tests/tcg/meson.build           |   7 ++
 tests/tcg/multiarch/meson.build | 147 ++++++++++++++++++++++++++++++++
 tests/tcg/multiarch/sha1.ref    |   1 +
 3 files changed, 155 insertions(+)
 create mode 100644 tests/tcg/multiarch/meson.build
 create mode 100644 tests/tcg/multiarch/sha1.ref
tests/tcg/meson.build +7 -0
index 8633c58459b..9ec33739884 100644
@@ -67,12 +67,19 @@ endif
 # plugins come first, as we need to build the list
 test_plugins = {}
 subdir('plugins')
+# multiarch comes second, so it can be referenced by other arch after
+subdir('multiarch')
 
 # Now let's go through all architectures
 subdir('aarch64')
 
 # Finally, we can create all test executables and test targets
 foreach target, plan: tcg_tests
+  if target.startswith('multiarch-')
+    # those tests are included by architecture files if needed
+    continue
+  endif
+
   # Detect duplicated executables/tests, and report an error to force user to
   # choose how to deal with it.
   built_tests = {}
tests/tcg/multiarch/meson.build new file +147 -0

147 lines not on this page · raw message

tests/tcg/multiarch/sha1.ref new file +1 -0
new file mode 100644
index 00000000000..4a8a114634f
@@ -0,0 +1 @@
+SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
Signature · 1 line
2.43.0
#64 lore raw

PATCH 24/27 tests/tcg/aarch64: add multiarch user tests

In reply to Pierrick Bouvier

We can now add multiarch tests. We also take care of semihosting tests here, by including them explicitly, instead of relying on any kind of "per-target" config.

---
 tests/tcg/aarch64/meson.build | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
tests/tcg/aarch64/meson.build +33 -0
index e6cf5309649..53085278155 100644
@@ -51,6 +51,9 @@ endif
 
 tests = []
 
+# Multi arch tests
+tests += tcg_tests['multiarch-linux-user']['tests']
+
 # Base architecture tests
 tests += {
   '../arm/fcvt.c': {'cflags': '-lm', 'expected_output': 'fcvt.ref'},
@@ -136,11 +139,29 @@ tests += {'sysregs.c': {}}
 # Crypto Tests
 tests += {'test-aes.c': {'cflags': feat_cflags['aes']}}
 
+# Vector SHA1
+# Work around compiler false-positive warning, as we do for the 'sha1' test
+tests += {'../multiarch/sha1.c': {
+            'exe_name': 'sha1-vector',
+            'cflags': ['-O3', '-Wno-stringop-overread'],
+            'expected_output': '../multiarch/sha1.ref',
+         }}
+
+# Vector versions of sha512 (-O3 triggers vectorisation)
+tests += {'../multiarch/sha512.c': {
+            'exe_name': 'sha512-vector',
+            'cflags': ['-O3'],
+         }}
+
 # SVE Tests
 if cc_has_feat['sve']
   f = feat_cflags['sve']
   tests += {
     'sve-ioctls.c': {'cflags': f},
+    '../multiarch/sha512.c': {
+       'exe_name': 'sha512-sve',
+       'cflags': f,
+    },
     'sve-str.c': {'cflags': [f, '-O1']},
   }
 endif
@@ -204,6 +225,18 @@ if cc_has_feat['mte'] and gdb_has_feat['mte']
   }
 endif
 
+# Semihosting tests
+# Add -I path for semicall.h
+semihosting_cflags = ['-I', meson.current_source_dir()]
+
+tests += {
+  '../multiarch/arm-compat-semi/semiconsole.c': {
+    'cflags': semihosting_cflags,
+    'wrapper': [prog_run_with_input, 'X'],
+  },
+  '../multiarch/arm-compat-semi/semihosting.c': {'cflags': semihosting_cflags},
+}
+
 tcg_tests += {
   'aarch64-linux-user': {
     'cc': cc,
Signature · 1 line
2.43.0
#65 lore raw

PATCH 25/27 tests/tcg/multiarch: declare system tests

In reply to Pierrick Bouvier

We now declare all multiarch system tests.

---
 tests/tcg/multiarch/meson.build        |  2 +
 tests/tcg/multiarch/system/meson.build | 53 ++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 tests/tcg/multiarch/system/meson.build
tests/tcg/multiarch/meson.build +2 -0
index 99af41b3fcc..508fdb585b7 100644
@@ -1,3 +1,5 @@
+subdir('system')
+
 tests = []
 
 float_helpers = files('libs/float_helpers.c')[0]
tests/tcg/multiarch/system/meson.build new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.43.0
#66 lore raw

PATCH 26/27 tests/tcg/aarch64: add multiarch system tests

In reply to Pierrick Bouvier

We can now add multiarch system tests. Because of our policy to not repeat cflags, we must make sure we only add those once per executable.

---
 tests/tcg/aarch64/system/meson.build | 31 ++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
tests/tcg/aarch64/system/meson.build +31 -0
index a1edf1b8442..2a613cca52d 100644
@@ -17,6 +17,32 @@ qemu_base_args = ['-display', 'none',
                   '-kernel']
 qemu_def_args = ['-M', 'virt', '-cpu', 'max', qemu_base_args]
 
+# Multi arch tests - add cflags only once per src
+multi_src = []
+foreach t: tcg_tests['multiarch-softmmu']['tests']
+  foreach src, setup: t
+    new_cflags = cflags
+    if fs.stem(src) == 'memory'
+      new_cflags += '-DCHECK_UNALIGNED=1'
+    endif
+    if src not in multi_src
+      setup += {'cflags': [new_cflags]}
+      multi_src += src
+    endif
+    tests += {src: setup + {'qemu_args': qemu_def_args}}
+  endforeach
+endforeach
+
+if cc_has_feat['sve']
+  tests += {
+    '../../multiarch/system/memory.c': {
+      'exe_name': 'memory-sve',
+      'cflags': [cflags, feat_cflags['sve'], '-DCHECK_UNALIGNED=1', '-O3'],
+      'qemu_args': qemu_def_args,
+    },
+  }
+endif
+
 tests += {
   'asid2.c': {'cflags': cflags, 'qemu_args': qemu_def_args},
   'feat-xs.c': {'cflags': cflags, 'qemu_args': qemu_def_args},
@@ -30,6 +56,11 @@ tests += {
                   qemu_def_args],
     'wrapper': [prog_run_with_input, 'X']
   },
+  '../../multiarch/system/memory.c': {
+    'test_name': 'memory-record-replay',
+    'qemu_args': qemu_def_args,
+    'wrapper': [prog_record_replay],
+  },
   'vtimer.c': {
     'cflags': cflags,
     'qemu_args': ['-M', 'virt,virtualization=on,gic-version=2',
Signature · 1 line
2.43.0
#67 lore raw

PATCH 27/27 tests/tcg/meson.build: add generic plugin tests

In reply to Pierrick Bouvier

We finally run every multiarch test (user & system) with every plugin we have. We can implement another strategy easily, the point here is just to show how we can do this without impacting test definitions files.

---
 tests/tcg/meson.build | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tests/tcg/meson.build +36 -0
index 9ec33739884..e88c018fb6e 100644
@@ -70,6 +70,42 @@ subdir('plugins')
 # multiarch comes second, so it can be referenced by other arch after
 subdir('multiarch')
 
+# Generic Plugin tests - add plugin for every user/system multiarch test
+plugin_tests_exclude = ['patch']
+foreach target: ['multiarch-linux-user', 'multiarch-softmmu']
+  plugin_tests = []
+  tests = tcg_tests[target]['tests']
+
+  foreach plugin_name, _: test_plugins
+    if plugin_name in plugin_tests_exclude
+      continue
+    endif
+
+    foreach t: tests
+      foreach src, setup: t
+        if 'plugin_test' in setup or 'gdb_test' in setup
+          continue
+        endif
+
+        # copy existing setup and remove existing cflags
+        new_setup = {}
+        foreach key, val: setup
+          if key == 'cflags'
+            continue
+          endif
+          new_setup += {key: val}
+        endforeach
+
+        new_setup += {'plugin_test': {'plugin': plugin_name}}
+        plugin_tests += {src: new_setup}
+      endforeach
+    endforeach
+  endforeach
+
+  # replace list of tests with old and new ones
+  tcg_tests += {target: {'tests': tests + plugin_tests}}
+endforeach
+
 # Now let's go through all architectures
 subdir('aarch64')
 
Signature · 1 line
2.43.0
#68 lore raw
In reply to Pierrick Bouvier

For reference:

Quoted 6 lines · Pierrick Bouvier

It implements all requirements listed on original thread [1], except cross container support, which can be easily added on top once we agree on the base.
[1] https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 1 line

- support building tests with containers

to be implemented in future version, but nothing blocking.

Quoted 3 lines
Quoted 3 lines

- handle all existing tests
- per-arch *-user and *-softmmu
- including post test validation checks (conditional-diff-out,

validate-memory-counts.py, etc...)

Done by adding the 'wrapper' concept.

Quoted 1 line
Quoted 1 line

- per-target overrides (some targets are broken for some tests)

Each target includes what it wants, so it's free to skip/customize any test.

Quoted 1 line
Quoted 1 line

- custom QEMU_OPTS for some tests

Done by adding 'qemu_args'.

Quoted 1 line
Quoted 1 line

- including sub-arch tests (e.g. x86_64 includes i386, mips64el

includes mips64 etc...)

Each target includes what it wants, including sub-arch if needed.

Quoted 3 lines
Quoted 3 lines

- multiarch tests for all *-user targets
- multiarch tests for all *-softmmu targets with boot.S
- gdbstub tests

Done by adding 'gdb_test'.

Quoted 1 line
Quoted 1 line

- don't forget gdb feature probing for arch and arch features

(e.g. GDB_HAS_SME_TILES)

Done by comparing gdb version as needed from meson.

Quoted 1 line
Quoted 1 line

- record/replay tests

Done by adding a record_replay wrapper.

Quoted 1 line
Quoted 1 line

- tcg plugin tests

Done by adding 'plugin_test'.

Quoted 1 line
Quoted 1 line

- modulate plugins over tests to avoid combinatorial explosion

Not implemented at the moment, but we can use any heuristic to limit the PxT expansion.

Quoted 3 lines
Quoted 3 lines

- filter some plugins from general testing (e.g. patch)
- filter some plugins based on mode (e.g. syscall)
- specific plugins with specific tests (e.g. patch, memory)

Each plugin test is explicit, so we are free to implement any policy.

Quoted 1 line
Quoted 1 line

- support build variations

Done by adding 'cflags' and ensuring we can't create an accidental duplication.

Quoted 1 line
Quoted 1 line

- compiler feature probing to gate tests

Done directly in meson by testing compiler.

Quoted 1 line
Quoted 1 line

- custom cflags for some tests

Done by adding 'cflags'.

Quoted 1 line
Quoted 1 line

- alternate cflag builds for some tests (e.g.

sha512-[vector|sse|mvx|...])

Done by specifying a different 'cflags', and an alternate executable name with 'exe_name'. We ensure duplication is explicit.

Quoted 1 line
Quoted 1 line

- build scripts (e.g. test-mmx.py)

Not needed in aarch64 at the moment. For this use case, we'll generate a header using a custom target, which will be a dependency of final test.

Regards,
Pierrick

#69 lore raw
In reply to Pierrick Bouvier
Quoted 21 lines · Pierrick Bouvier

This series is an experiment to replace TCG tests makefiles with meson, with the goal of having something more readable and maintainable in the long term. Also it closes the gap that tcg tests had with the rest of tests, by integrating them with meson directly.

It covers all existing tests for aarch64 architecture, including user/system/multiarch-user/multiarch-system. I'll carry the effort to port all other architectures once we agree on a base. We agreed with Alex to not merge anything before all arch are covered.

Series first declare the global infrastructure, then add aarch64 and multiarch tests, and finally plugin tests.

For review, I would suggest to start with aarch64 patches (end of the series) to get an idea of what they will look like, before the implementation itself. You can also compare that to existing Makefiles, they follow the same order.

It implements all requirements listed on original thread [1], except cross container support, which can be easily added on top once we agree on the base.
[1] https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 7 lines

We also have for free:
- correct and complete dependencies for any test, including:
scripts, c.inc, headers, reference files and binaries/plugins.
- catch test declaration issues at configure time vs test time.
- proper data types for variables instead of string expansion with make.
- we could now build tests binaries by default with 'all' target.
- hopefully, better readability to your taste.

Yes there is absolutely a readability improvement! At most, one could say that it's not a very high bar. :)

Having to reinvent cross compilation (cc_has_feat, custom_targets for compilation) is not great and the only part I'm not super convinced about; I wonder what it would be like to make TCG tests their own standalone meson projects. While the Makefiles are awful I do like being able to do "make -C tests/tcg/x86_64-softmmu", and in that respect this would be a half step backwards (and a big step forwards in many other respects, mind).

I can help with the integration of the individual test suites into tests/tcg/Makefile.include.

Paolo

Quoted 84 lines

Main ideas for the current design are:
- make arch files as simple and explicit as possible. If it conflicts, always pick explicit, as long as we don't expose meson details. remove any kind of "skip, override, filter" logic.
- never expose custom_target and meson details in arch files.
- catch any spelling mistake on test or any dependency.
- keep complexity contained in tests/tcg/meson.build.

Usage:

```
make check-tcg
make check-tcg-aarch64-linux-user
make check-tcg-aarch64-softmmu

from build folder:
./pyvenv/bin/meson test --list --suite tcg
ninja clean
./pyvenv/bin/meson test aarch64-softmmu-asid2 --verbose
```

Pierrick Bouvier (27):
tests/tcg/multiarch/system/memory.c: remove unused variable tests/tcg/multiarch/plugin/check-plugin-output.sh: take test output as
input
tests/tcg/multiarch/plugin: rename check-plugin-output to
regex-compare
tests/tcg: introduce meson.build
tests/tcg/meson.build: introduce exe_name tests/tcg/meson.build: introduce test_name tests/tcg/meson.build: introduce cflags tests/tcg/meson.build: introduce qemu_args tests/tcg/meson.build: introduce env_var tests/tcg/plugins: build list of test_plugins tests/tcg/meson.build: introduce plugin_test tests/tcg/meson.build: test gdb support and introduce gdb_arch tests/tcg/meson.build: introduce gdb_test tests/tcg/meson.build: add default flag for testing compiler support tests/tcg/meson.build: introduce wrapper tests/tcg/meson.build: introduce expected_output tests/tcg/meson.build: add wrapper run_and_check_forbidden_output tests/tcg/meson.build: add wrapper run_with_input tests/tcg/meson.build: add wrapper record_replay tests/tcg/meson.build: add wrapper check_plugin_output tests/tcg/aarch64: add user tests
tests/tcg/aarch64: add system tests
tests/tcg/multiarch: declare user tests
tests/tcg/aarch64: add multiarch user tests tests/tcg/multiarch: declare system tests tests/tcg/aarch64: add multiarch system tests tests/tcg/meson.build: add generic plugin tests

  tests/meson.build                             |   2 +-
  tests/tcg/aarch64/meson.build                 | 248 ++++++++++++++++
  tests/tcg/aarch64/system/meson.build          | 100 +++++++
  tests/tcg/meson.build                         | 276 ++++++++++++++++++
  tests/tcg/multiarch/Makefile.target           |   3 +-
  tests/tcg/multiarch/meson.build               | 149 ++++++++++
  .../multiarch/plugin/check-plugin-output.sh   |  36 ---
  tests/tcg/multiarch/plugin/regex-compare.sh   |  28 ++
  tests/tcg/multiarch/sha1.ref                  |   1 +
  tests/tcg/multiarch/system/memory.c           |   3 +-
  tests/tcg/multiarch/system/meson.build        |  53 ++++
  tests/tcg/plugins/meson.build                 |  11 +-
  tests/tcg/scripts/check_plugin_output.sh      |  19 ++
  tests/tcg/scripts/record_replay.sh            |  16 +
  .../scripts/run_and_check_forbidden_output.sh |  19 ++
  tests/tcg/scripts/run_and_diff.sh             |  12 +
  tests/tcg/scripts/run_with_input.sh           |  12 +
  17 files changed, 943 insertions(+), 45 deletions(-)

create mode 100644 tests/tcg/aarch64/meson.build
create mode 100644 tests/tcg/aarch64/system/meson.build create mode 100644 tests/tcg/meson.build
create mode 100644 tests/tcg/multiarch/meson.build
delete mode 100755 tests/tcg/multiarch/plugin/check-plugin-output.sh create mode 100755 tests/tcg/multiarch/plugin/regex-compare.sh create mode 100644 tests/tcg/multiarch/sha1.ref
create mode 100644 tests/tcg/multiarch/system/meson.build create mode 100755 tests/tcg/scripts/check_plugin_output.sh create mode 100755 tests/tcg/scripts/record_replay.sh create mode 100755 tests/tcg/scripts/run_and_check_forbidden_output.sh create mode 100755 tests/tcg/scripts/run_and_diff.sh create mode 100755 tests/tcg/scripts/run_with_input.sh

#70 lore raw
Quoted 13 lines · Paolo Bonzini
Quoted 7 lines · Pierrick Bouvier

We also have for free:
- correct and complete dependencies for any test, including:
   scripts, c.inc, headers, reference files and binaries/plugins.
- catch test declaration issues at configure time vs test time.
- proper data types for variables instead of string expansion with make.
- we could now build tests binaries by default with 'all' target.
- hopefully, better readability to your taste.

Yes there is absolutely a readability improvement!  At most, one could say that it's not a very high bar. :)

Quoted 8 lines

Having to reinvent cross compilation (cc_has_feat, custom_targets for compilation) is not great and the only part I'm not super convinced about; I wonder what it would be like to make TCG tests their own standalone meson projects.  While the Makefiles are awful I do like being able to do "make -C tests/tcg/x86_64-softmmu", and in that respect this would be a half step backwards (and a big step forwards in many other respects, mind).

Your idea is to have one project per target, and use meson cross compile support for this?

make check-tcg-aarch64-softmu is supported out of the box with this series, without having to write a single line of Makefile. You can still do what you like: see cover letter usage, to run a suite or a single test.

I don't see rewriting the cc_feat part in meson directly as a problem to be honest. Not all architectures needs to check specific feat (only aarch64, arm, i386, ppc64 and s390x).

Also, calling:
supported = run_command[cc, check_cflags, flags].returncode() == 0
vs
cc.get_supported_arguments(flags)
is not really much more complex IMHO, and not a huge reinvention.

Also, the custom target is hidden inside tcg/tests/meson.build and not exposed to arch files. Even if we had multiple projects, I would stick to not exposing test() and executable() in arch files.

Quoted 3 lines

I can help with the integration of the individual test suites into tests/tcg/Makefile.include.

I would expect this file to disappear completely, and to rely on make check-tcg-arch-* targets at top level instead. Would that work for you?

Quoted 2 lines

Paolo

Regards,
Pierrick

#71 lore raw
Quoted 2 lines · Pierrick Bouvier

Your idea is to have one project per target, and use meson cross compile support for this?

Yes, that was the idea.

Quoted 13 lines

make check-tcg-aarch64-softmu is supported out of the box with this series, without having to write a single line of Makefile. You can still do what you like: see cover letter usage, to run a suite or a single test. I don't see rewriting the cc_feat part in meson directly as a problem to be honest. Not all architectures needs to check specific feat (only aarch64, arm, i386, ppc64 and s390x).

Also, calling:
supported = run_command[cc, check_cflags, flags].returncode() == 0
vs
cc.get_supported_arguments(flags)
is not really much more complex IMHO, and not a huge reinvention.

Quoted 3 lines

Also, the custom target is hidden inside tcg/tests/meson.build and not exposed to arch files. Even if we had multiple projects, I would stick to not exposing test() and executable() in arch files.

Fair enough.

Quoted 2 lines

I would expect this file to disappear completely, and to rely on make check-tcg-arch-* targets at top level instead. Would that work for you?

Yeah, you're right that at this point TCG tests are the last stragglers in that file. That tilts the balance for me, it does make sense to do this with custom_target() until Meson grows support for something like multi-machine projects. Just please add an alias_target 'build-tcg-tests-...' for compatibility with tests/Makefile.include.

Paolo

#72 lore raw
Quoted 26 lines · Paolo Bonzini
Quoted 2 lines · Pierrick Bouvier

Your idea is to have one project per target, and use meson cross compile support for this?

Yes, that was the idea.

Quoted 13 lines

make check-tcg-aarch64-softmu is supported out of the box with this series, without having to write a single line of Makefile. You can still do what you like: see cover letter usage, to run a suite or a single test. I don't see rewriting the cc_feat part in meson directly as a problem to be honest. Not all architectures needs to check specific feat (only aarch64, arm, i386, ppc64 and s390x).

Also, calling:
supported = run_command[cc, check_cflags, flags].returncode() == 0
vs
cc.get_supported_arguments(flags)
is not really much more complex IMHO, and not a huge reinvention.

Quoted 3 lines

Also, the custom target is hidden inside tcg/tests/meson.build and not exposed to arch files. Even if we had multiple projects, I would stick to not exposing test() and executable() in arch files.

Fair enough.

Quoted 9 lines
Quoted 2 lines

I would expect this file to disappear completely, and to rely on make check-tcg-arch-* targets at top level instead. Would that work for you?

Yeah, you're right that at this point TCG tests are the last stragglers in that file. That tilts the balance for me, it does make sense to do this with custom_target() until Meson grows support for something like multi-machine projects. Just please add an alias_target 'build-tcg-tests-...' for compatibility with tests/Makefile.include.

Sure, that's a good idea.
I was wondering as well if we should build those tests by default (as part of 'all' target). We should do this only if cross compiler is not using any container, to avoid triggering a confusing container build. Any opinion?

Quoted 2 lines

Paolo

#73 lore raw
Quoted 5 lines · Pierrick Bouvier

Sure, that's a good idea.
I was wondering as well if we should build those tests by default (as part of 'all' target). We should do this only if cross compiler is not using any container, to avoid triggering a confusing container build. Any opinion?

Definitely not if using docker/podman... but if not go for it - nobody will notice, they are really small.

Paolo

#74 lore raw
In reply to Pierrick Bouvier
Quoted 104 lines · Pierrick Bouvier

This series is an experiment to replace TCG tests makefiles with meson, with the goal of having something more readable and maintainable in the long term. Also it closes the gap that tcg tests had with the rest of tests, by integrating them with meson directly.

It covers all existing tests for aarch64 architecture, including user/system/multiarch-user/multiarch-system. I'll carry the effort to port all other architectures once we agree on a base. We agreed with Alex to not merge anything before all arch are covered.

Series first declare the global infrastructure, then add aarch64 and multiarch tests, and finally plugin tests.

For review, I would suggest to start with aarch64 patches (end of the series) to get an idea of what they will look like, before the implementation itself. You can also compare that to existing Makefiles, they follow the same order.

It implements all requirements listed on original thread [1], except cross container support, which can be easily added on top once we agree on the base.
[1] https://lore.kernel.org/qemu-devel/[email protected]/

We also have for free:
- correct and complete dependencies for any test, including:
scripts, c.inc, headers, reference files and binaries/plugins.
- catch test declaration issues at configure time vs test time.
- proper data types for variables instead of string expansion with make.
- we could now build tests binaries by default with 'all' target.
- hopefully, better readability to your taste.

Main ideas for the current design are:
- make arch files as simple and explicit as possible. If it conflicts, always pick explicit, as long as we don't expose meson details. remove any kind of "skip, override, filter" logic.
- never expose custom_target and meson details in arch files.
- catch any spelling mistake on test or any dependency.
- keep complexity contained in tests/tcg/meson.build.

Usage:

```
make check-tcg
make check-tcg-aarch64-linux-user
make check-tcg-aarch64-softmmu

from build folder:
./pyvenv/bin/meson test --list --suite tcg
ninja clean
./pyvenv/bin/meson test aarch64-softmmu-asid2 --verbose
```

Pierrick Bouvier (27):
tests/tcg/multiarch/system/memory.c: remove unused variable tests/tcg/multiarch/plugin/check-plugin-output.sh: take test output as
input
tests/tcg/multiarch/plugin: rename check-plugin-output to
regex-compare
tests/tcg: introduce meson.build
tests/tcg/meson.build: introduce exe_name tests/tcg/meson.build: introduce test_name tests/tcg/meson.build: introduce cflags tests/tcg/meson.build: introduce qemu_args tests/tcg/meson.build: introduce env_var tests/tcg/plugins: build list of test_plugins tests/tcg/meson.build: introduce plugin_test tests/tcg/meson.build: test gdb support and introduce gdb_arch tests/tcg/meson.build: introduce gdb_test tests/tcg/meson.build: add default flag for testing compiler support tests/tcg/meson.build: introduce wrapper tests/tcg/meson.build: introduce expected_output tests/tcg/meson.build: add wrapper run_and_check_forbidden_output tests/tcg/meson.build: add wrapper run_with_input tests/tcg/meson.build: add wrapper record_replay tests/tcg/meson.build: add wrapper check_plugin_output tests/tcg/aarch64: add user tests
tests/tcg/aarch64: add system tests
tests/tcg/multiarch: declare user tests
tests/tcg/aarch64: add multiarch user tests tests/tcg/multiarch: declare system tests tests/tcg/aarch64: add multiarch system tests tests/tcg/meson.build: add generic plugin tests

 tests/meson.build                             |   2 +-
 tests/tcg/aarch64/meson.build                 | 248 ++++++++++++++++
 tests/tcg/aarch64/system/meson.build          | 100 +++++++
 tests/tcg/meson.build                         | 276 ++++++++++++++++++
 tests/tcg/multiarch/Makefile.target           |   3 +-
 tests/tcg/multiarch/meson.build               | 149 ++++++++++
 .../multiarch/plugin/check-plugin-output.sh   |  36 ---
 tests/tcg/multiarch/plugin/regex-compare.sh   |  28 ++
 tests/tcg/multiarch/sha1.ref                  |   1 +
 tests/tcg/multiarch/system/memory.c           |   3 +-
 tests/tcg/multiarch/system/meson.build        |  53 ++++
 tests/tcg/plugins/meson.build                 |  11 +-
 tests/tcg/scripts/check_plugin_output.sh      |  19 ++
 tests/tcg/scripts/record_replay.sh            |  16 +
 .../scripts/run_and_check_forbidden_output.sh |  19 ++
 tests/tcg/scripts/run_and_diff.sh             |  12 +
 tests/tcg/scripts/run_with_input.sh           |  12 +
 17 files changed, 943 insertions(+), 45 deletions(-)
 create mode 100644 tests/tcg/aarch64/meson.build
 create mode 100644 tests/tcg/aarch64/system/meson.build
 create mode 100644 tests/tcg/meson.build
 create mode 100644 tests/tcg/multiarch/meson.build
 delete mode 100755 tests/tcg/multiarch/plugin/check-plugin-output.sh
Quoted 9 lines
 create mode 100755 tests/tcg/multiarch/plugin/regex-compare.sh
 create mode 100644 tests/tcg/multiarch/sha1.ref
 create mode 100644 tests/tcg/multiarch/system/meson.build
 create mode 100755 tests/tcg/scripts/check_plugin_output.sh
 create mode 100755 tests/tcg/scripts/record_replay.sh
 create mode 100755 tests/tcg/scripts/run_and_check_forbidden_output.sh
 create mode 100755 tests/tcg/scripts/run_and_diff.sh
 create mode 100755 tests/tcg/scripts/run_with_input.sh

v2 sent, with container support:
https://lore.kernel.org/qemu-devel/[email protected]/T/#t

Regards,
Pierrick