Skip to contentSkip to conversation

tests/functional: Add virtio-villain fault injection test

RFC PATCH Superseded Anatol Belski 2 participants 5 messages Oct 1 – Nov 1 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 tests/functional: Add virtio-villain fault injection test

Add a functional test that drives the virtio-villain harness against the QEMU under test. virtio-villain is a guest side fault injection tool that boots one short lived guest per case. Each case violates a driver rule from the virtio spec and checks that the device model handles the bad input without crashing, hanging, or corrupting state.

The harness is added as a git submodule under tests/functional/virtio-villain. The test builds the static guest init with the host compiler for a native guest, or an architecture cross compiler for a foreign guest, then runs the whole supported suite one guest per case and fails if any case reports FAIL, WEDGED, or XPASS. Cases that need host support which is absent, such as vhost-vsock or a virtiofs daemon, are skipped.

The guest kernel is fetched as a cached asset. The test lives in the generic directory and is registered in the x86_64 and aarch64 thorough suites, skipping any host that cannot provide a kernel or a compiler for the guest architecture.

---
 .gitmodules                                   |   3 +
 MAINTAINERS                                   |   6 +
 docs/devel/testing/functional.rst             |  27 +++
 tests/functional/aarch64/meson.build          |   2 +
 .../functional/generic/test_virtio_villain.py | 195 ++++++++++++++++++
 tests/functional/virtio-villain               |   1 +
 tests/functional/x86_64/meson.build           |   2 +
 7 files changed, 236 insertions(+)
 create mode 100755 tests/functional/generic/test_virtio_villain.py
 create mode 160000 tests/functional/virtio-villain
.gitmodules +3 -0
index c307216d17..3a3b85c516 100644
@@ -45,3 +45,6 @@
 [submodule "tests/lcitool/libvirt-ci"]
 	path = tests/lcitool/libvirt-ci
 	url = https://gitlab.com/libvirt/libvirt-ci.git
+[submodule "tests/functional/virtio-villain"]
+	path = tests/functional/virtio-villain
+	url = https://github.com/weltling/virtio-villain.git
MAINTAINERS +6 -0
index 1312bbd1bd..0021e8498e 100644
@@ -4647,6 +4647,12 @@ F: tests/functional/generic/test_linters.py
 F: tests/functional/pylintrc
 F: tests/functional/qemu_test/
 
+virtio-villain fault injection test
+M: Anatol Belski <[email protected]>
+S: Maintained
+F: tests/functional/generic/test_virtio_villain.py
+F: tests/functional/virtio-villain
+
 Windows Hosted Continuous Integration
 M: Yonggang Luo <[email protected]>
 S: Maintained
docs/devel/testing/functional.rst +27 -0
index 60a427d175..963542f9b8 100644
@@ -83,6 +83,33 @@ files around on disk by setting ``QEMU_TEST_KEEP_SCRATCH=1`` as an env
 variable.  Any preserved files will be deleted the next time the test is run
 without this variable set.
 
+The virtio-villain fault injection test
+---------------------------------------
+
+The ``virtio_villain`` test drives a guest side virtio fault injection
+harness against the QEMU under test. It is included as a git submodule
+under ``tests/functional/virtio-villain``. Initialize it before running
+the test::
+
+  $ git submodule update --init tests/functional/virtio-villain
+
+The harness boots one short lived guest per case. Each case violates a
+driver rule from the virtio spec and checks that the device model
+handles the bad input without crashing, hanging, or corrupting state.
+The test builds a static guest init and then runs the whole supported
+suite through the harness, failing if any case reports a failure.
+
+Building the guest init needs a static toolchain that targets the
+guest architecture. When the guest matches the host, musl-gcc or the
+host compiler is used. When it differs, a cross compiler such as
+``aarch64-linux-gnu-gcc`` is used. The test is skipped when no
+suitable kernel or compiler is available for the guest architecture.
+
+The test is part of the thorough suite for x86_64 and aarch64, so it
+runs with ``make check-functional-x86_64`` or on its own with::
+
+  $ meson test -C build --setup thorough func-x86_64-virtio_villain
+
 Logging
 -------
 
tests/functional/aarch64/meson.build +2 -0
index f0881bed16..28563655ae 100644
@@ -18,6 +18,7 @@ test_aarch64_timeouts = {
   'virt' : 360,
   'virt_gpu' : 480,
   'virt_vbsa' : 240,
+  'virtio_villain' : 900,
 }
 
 tests_aarch64_system_quick = [
@@ -55,6 +56,7 @@ tests_aarch64_system_thorough = [
   'virt_aarch64_off',
   'virt_gpu',
   'virt_vbsa',
+  'virtio_villain',
   'xen',
   'xlnx_versal',
 ]
tests/functional/generic/test_virtio_villain.py new file +195 -0

195 lines not on this page · raw message

tests/functional/virtio-villain new file +1 -0
new file mode 160000
index 0000000000..59d02ac357
@@ -0,0 +1 @@
+Subproject commit 59d02ac35766732247670ae608177a6fd7181d7f
tests/functional/x86_64/meson.build +2 -0
index 0353b2af8e..2a7c708ddb 100644
@@ -7,6 +7,7 @@ test_x86_64_timeouts = {
   'netdev_ethtool' : 180,
   'replay' : 480,
   'virtio_balloon': 120,
+  'virtio_villain' : 900,
 }
 
 tests_x86_64_system_quick = [
@@ -50,5 +51,6 @@ tests_x86_64_system_thorough = [
   'vhost_user_bridge',
   'virtio_balloon',
   'virtio_gpu',
+  'virtio_villain',
   'rebuild_vmfd',
 ]
Signature · 1 line
2.55.0
#1 lore raw
Quoted 198 lines · Anatol Belski

Add a functional test that drives the virtio-villain harness against the QEMU under test. virtio-villain is a guest side fault injection tool that boots one short lived guest per case. Each case violates a driver rule from the virtio spec and checks that the device model handles the bad input without crashing, hanging, or corrupting state.

The harness is added as a git submodule under tests/functional/virtio-villain. The test builds the static guest init with the host compiler for a native guest, or an architecture cross compiler for a foreign guest, then runs the whole supported suite one guest per case and fails if any case reports FAIL, WEDGED, or XPASS. Cases that need host support which is absent, such as vhost-vsock or a virtiofs daemon, are skipped.

The guest kernel is fetched as a cached asset. The test lives in the generic directory and is registered in the x86_64 and aarch64 thorough suites, skipping any host that cannot provide a kernel or a compiler for the guest architecture.

---
 .gitmodules                                   |   3 +
 MAINTAINERS                                   |   6 +
 docs/devel/testing/functional.rst             |  27 +++
 tests/functional/aarch64/meson.build          |   2 +
 .../functional/generic/test_virtio_villain.py | 195 ++++++++++++++++++
 tests/functional/virtio-villain               |   1 +
 tests/functional/x86_64/meson.build           |   2 +
 7 files changed, 236 insertions(+)
 create mode 100755 tests/functional/generic/test_virtio_villain.py
 create mode 160000 tests/functional/virtio-villain
tests/functional/aarch64/meson.build +2 -0
index f0881bed16..28563655ae 100644
@@ -18,6 +18,7 @@ test_aarch64_timeouts = {
   'virt' : 360,
   'virt_gpu' : 480,
   'virt_vbsa' : 240,
+  'virtio_villain' : 900,
 }
 
 tests_aarch64_system_quick = [
@@ -55,6 +56,7 @@ tests_aarch64_system_thorough = [
   'virt_aarch64_off',
   'virt_gpu',
   'virt_vbsa',
+  'virtio_villain',
   'xen',
   'xlnx_versal',
 ]
tests/functional/generic/test_virtio_villain.py new file +140 -0
new file mode 100755
index 0000000000..d4e656edc0
@@ -0,0 +1,195 @@
+#!/usr/bin/env python3
+#
+# virtio-villain functional test
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# This test drives the virtio-villain harness, a git submodule under
+# tests/functional/virtio-villain, against the QEMU under test. The
+# harness boots one short lived guest per case. Each case violates one
+# driver rule from the virtio spec and checks that the device model
+# handles it without crashing, hanging, or corrupting state.
+#
+# virtio-villain targets x86_64 and aarch64. The guest init is built
+# static with musl-gcc or the host compiler for a native guest, or with
+# an architecture cross compiler when the guest differs from the host.
+# The whole supported suite runs one guest per case and the test fails
+# if any case is FAIL, WEDGED, or XPASS. Cases needing host support that
+# is absent, such as vhost-vsock or a virtiofs daemon, are skipped by
+# --skip-unsupported.
+#
+# Run it directly with meson test -C <build> --setup thorough
+# func-<arch>-virtio_villain
+
+import ast
+import json
+import os
+import platform
+import re
+import shutil
+import subprocess
+import unittest
+from unittest import mock
+
+from qemu_test import Asset, QemuSystemTest, skipIfMissingCommands
+
+
+ASSET_KERNEL_X86_64 = Asset(
+    ('https://github.com/cloud-hypervisor/linux/releases/download/'
+     'ch-release-v6.16.9-20260508/vmlinux-x86_64'),
+    '9d3570b47d5abb069ca00edfbfcef4c68306a9c3d078a01f10082b258f1001b8')
+
+ASSET_KERNEL_AARCH64 = Asset(
+    ('https://github.com/cloud-hypervisor/linux/releases/download/'
+     'ch-release-v6.16.9-20260508/Image-arm64'),
+    '69d1b1235381ec50f1b45cf771a7dff4a9013d452833ab34682d6283e2114010')
+
+KERNELS = {
+    'x86_64': ASSET_KERNEL_X86_64,
+    'aarch64': ASSET_KERNEL_AARCH64,
+}
+
+
+def _native_compiler():
+    if shutil.which('musl-gcc'):
+        return 'musl-gcc'
+    build_root = os.environ.get('MESON_BUILD_ROOT')
+    if build_root:
+        cross = os.path.join(build_root, 'config-meson.cross')
+        try:
+            with open(cross) as f:
+                for line in f:
+                    if line.strip().startswith('c ='):
+                        val = ast.literal_eval(line.split('=', 1)[1].strip())
+                        return val[0] if isinstance(val, list) else val
+        except OSError:
+            pass
+    return 'cc'
+
+
+def _villain_compiler(arch):
+    if arch == platform.machine():
+        return _native_compiler()
+    for cc in (arch + '-linux-musl-gcc', arch + '-linux-gnu-gcc'):
+        if shutil.which(cc):
+            return cc
+    return None
+
+
+_ANSI_RE = re.compile(r'\x1b\[[0-9;?]*[ -/]*[@-~]')
+
+
+def _clean(text):
+    return _ANSI_RE.sub('', text.replace('\r', ''))
+
+
+class VirtioVillain(QemuSystemTest):
+
+    timeout = 900
+
+    @skipIfMissingCommands('make', 'strip', 'cpio', 'gzip')
+    def test_suite(self):
+        kernel = KERNELS.get(self.arch)
+        if kernel is None:
+            self.skipTest('no virtio-villain kernel for %s' % self.arch)
+        cc = _villain_compiler(self.arch)
+        if cc is None:
+            self.skipTest('no compiler to build the %s guest init'
+                          % self.arch)
+
+        villain_dir = os.path.join(os.path.dirname(__file__), '..',
+                                   'virtio-villain')
+        # The runner reads the initramfs from its own default target path.
+        subprocess.run(['make', '-C', villain_dir, 'initramfs',
+                        f'-j{os.cpu_count() or 1}',
+                        f'CC={cc}',
+                        'CFLAGS=-static -O2 -Wall -Wextra -Werror '
+                        '-Wno-unused-but-set-variable'],
+                       stdout=subprocess.DEVNULL, check=True)
+
+        report = self.scratch_file('villain-report.json')
+        runner = os.path.join(villain_dir, 'run')
+        result = subprocess.run(
+            [runner, '-m', self.qemu_bin,
+             '-k', kernel.fetch(),
+             '--skip-unsupported',
+             '-j', str(os.cpu_count() or 1),
+             '--format', 'json', '--output', report],
+            capture_output=True, text=True, check=False)
+
+        if not os.path.exists(report):
+            self.fail('virtio-villain runner produced no report:\n'
+                      + (result.stderr or result.stdout or '')[-2000:])
+
+        with open(report) as f:
+            data = json.load(f)
+        counts = data['counts']
+        self.log.info('virtio-villain: %d tests, %s', data['total'], counts)
+
+        bad = [t for t in data['tests']
+               if t['status'] in ('FAIL', 'WEDGED', 'XPASS')]
+
+        runlog = os.path.join(self.outputdir, 'villain-run.log')
+        with open(runlog, 'w') as f:
+            f.write(_clean(result.stdout or ''))
+            for t in bad:
+                f.write('\n===== %s %s (spec %s) %s =====\n'
+                        % (t['status'], t['name'], t.get('spec_section'),
+                           t.get('description')))
+                f.write(_clean(t.get('output') or ''))
+        self.log.info('virtio-villain full log: %s', runlog)

tests/functional/generic/test_virtio_villain.py line 150

Quoted 10 lines
tests/functional/generic/test_virtio_villain.py new file +10 -0
+
+        if bad:
+            detail = '\n  '.join(
+                '%s %s (spec %s) %s'
+                % (t['status'], t['name'], t.get('spec_section'),
+                   t.get('description'))
+                for t in bad)
+            self.fail('virtio-villain reported %d failing case(s):\n  %s\n'
+                      'full guest output in %s'
+                      % (len(bad), detail, runlog))

Looking at what you end up needing todo in this method, I think that my advice to try integrating with the functional test suite was a mistake.

The building of the initramfs would work better as a custom_target() rule in meson.build, where you have direct access to the native compiler names to use.

We also have some cross compiler info available, though currently that is scoped to only tests/tcg/meson.build. Making it available to the villain test would need some re-factoring. Probably best to get the native compiler integration with villain done first, and worry about cross-builds as a followup once we're happy with the native tests.

The other issue is that when running the tests, it need to pass '-j os-cpu_count()' to stop the tests being serialized, but that introduces double parallelization, because meson itself already runs other test jobs in parallel to the entire test_virtio_villain.py test program.

I should have realized the latter problem would exist when making my recommendation to use functional test harness, as we faced the same issue already with the QEMU I/O test harness. Essentially test harnesses calling test harnesses ends up creating problems.

The way we have to solve this is by exposing individual tests directly to meson, so that it has full visibility of all individual tests and can control parallel jobs directly, with minimal impact from the secondary test harness underneath.

The only parts of the functional test suite you're benefitting from are the kernel download caching, and helpers for temporary scratch file paths. That isn't compelling enough to justify the downsides.

So I'm inclined to say we should instead treat this as its own standalone test suite, and control it all from meson directly.

Put submodule at tests/virtio-villain

A file tests/virtio-villain-list.py that initializes the git submodule and enumerates the tests.

We can't rely on running 'target/init --list-tsv' since it won't be built yet, but it looks like you have a formal naming convention for files under tests/, so we can get test names from the first component of the filename.

A custom_target() that invokes the "initramfs" build process, but with 'build_by_default: false', so we don't trigger that slow build process every time.

Use run_command() to invoke the virtio-villain-list.py file and iterate over the reported test names, creating a meson test() function for each one, using a meson suite of "virtio-villain", invoking 'run' with the single test name. The test() should depend on the custom_target() so that the initramfs gets built-on-demand when the first test is run.

There's an example of how we do this metadata driven test creation in tests/qemu-iotests/meson.build

Quoted 74 lines
tests/functional/generic/test_virtio_villain.py new file +45 -0
+
+
+class VillainHelpers(unittest.TestCase):
+
+    def test_kernels_cover_both_arches(self):
+        self.assertIn('x86_64', KERNELS)
+        self.assertIn('aarch64', KERNELS)
+
+    def test_native_prefers_musl(self):
+        with mock.patch.object(shutil, 'which',
+                               side_effect=lambda c: c == 'musl-gcc'):
+            self.assertEqual(_native_compiler(), 'musl-gcc')
+
+    def test_native_falls_back_to_cc(self):
+        with mock.patch.object(shutil, 'which', return_value=None), \
+             mock.patch.dict(os.environ, {}, clear=True):
+            self.assertEqual(_native_compiler(), 'cc')
+
+    def test_native_arch_uses_native(self):
+        with mock.patch.object(platform, 'machine', return_value='x86_64'), \
+             mock.patch.object(shutil, 'which',
+                               side_effect=lambda c: c == 'musl-gcc'):
+            self.assertEqual(_villain_compiler('x86_64'), 'musl-gcc')
+
+    def test_foreign_arch_uses_cross(self):
+        def which(cmd):
+            if cmd == 'aarch64-linux-gnu-gcc':
+                return '/usr/bin/' + cmd
+            return None
+        with mock.patch.object(platform, 'machine', return_value='x86_64'), \
+             mock.patch.object(shutil, 'which', side_effect=which):
+            self.assertEqual(_villain_compiler('aarch64'),
+                             'aarch64-linux-gnu-gcc')
+
+    def test_foreign_arch_without_cross_is_none(self):
+        with mock.patch.object(platform, 'machine', return_value='x86_64'), \
+             mock.patch.object(shutil, 'which', return_value=None):
+            self.assertIsNone(_villain_compiler('aarch64'))
+
+    def test_clean_strips_cr_and_escapes(self):
+        self.assertEqual(_clean('a\r\n\x1b[32mok\x1b[0m\r'), 'a\nok')
+
+
+if __name__ == '__main__':
+    QemuSystemTest.main()
tests/functional/virtio-villain new file +1 -0
new file mode 160000
index 0000000000..59d02ac357
@@ -0,0 +1 @@
+Subproject commit 59d02ac35766732247670ae608177a6fd7181d7f
tests/functional/x86_64/meson.build +2 -0
index 0353b2af8e..2a7c708ddb 100644
@@ -7,6 +7,7 @@ test_x86_64_timeouts = {
   'netdev_ethtool' : 180,
   'replay' : 480,
   'virtio_balloon': 120,
+  'virtio_villain' : 900,
 }
 
 tests_x86_64_system_quick = [
@@ -50,5 +51,6 @@ tests_x86_64_system_thorough = [
   'vhost_user_bridge',
   'virtio_balloon',
   'virtio_gpu',
+  'virtio_villain',
   'rebuild_vmfd',
 ]
Signature · 1 line
2.55.0

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#2 lore raw

PATCH v2 1/1 tests: Add virtio-villain fault injection suite

In reply to Anatol Belski

Add a test suite that drives the virtio-villain harness against QEMU. virtio-villain is a guest side fault injection tool that boots a separate guest for each case. Each case supplies invalid virtio driver input to test how the device model handles it.

The harness is added as a git submodule under tests/virtio-villain. Case IDs are discovered from source filenames during configuration and each case is registered as a Meson test. Meson controls parallel execution and timeouts, with one case per runner invocation.

The suite builds the static guest initramfs and fetches kernels on demand for native Linux x86_64 and aarch64 hosts. Generated artifacts stay in the build directory and kernel downloads use the QEMU asset cache.

The virtio-villain and check-virtio-villain make targets build and run the suite without adding it to the default check target. Each case retains readable logs and JSON reports, with skipped cases reported separately from successful tests. Embedded helper tests and documentation are included.

---
Thanks for the review. I reworked the integration as a standalone optional Meson suite with one test per case, parallel execution and individual logs and JSON reports. virtio-villain has been adapted to accept guest artifacts from the QEMU build directory while preserving sidecar lookup and avoiding vsock CID collisions between parallel runners.

 .gitmodules                           |   3 +
 MAINTAINERS                           |   7 +
 docs/devel/testing/index.rst          |   1 +
 docs/devel/testing/virtio-villain.rst | 102 +++++++++
 scripts/mtest2make.py                 |   3 +-
 tests/Makefile.include                |   7 +
 tests/meson.build                     |  46 ++++
 tests/virtio-villain                  |   1 +
 tests/virtio-villain-build.py         |  64 ++++++
 tests/virtio-villain-list.py          |  53 +++++
 tests/virtio-villain-test.py          | 314 ++++++++++++++++++++++++++
 11 files changed, 600 insertions(+), 1 deletion(-)
 create mode 100644 docs/devel/testing/virtio-villain.rst
 create mode 160000 tests/virtio-villain
 create mode 100644 tests/virtio-villain-build.py
 create mode 100644 tests/virtio-villain-list.py
 create mode 100644 tests/virtio-villain-test.py
.gitmodules +3 -0
index c307216d17..fd3083ca4b 100644
@@ -45,3 +45,6 @@
 [submodule "tests/lcitool/libvirt-ci"]
 	path = tests/lcitool/libvirt-ci
 	url = https://gitlab.com/libvirt/libvirt-ci.git
+[submodule "tests/virtio-villain"]
+	path = tests/virtio-villain
+	url = https://github.com/weltling/virtio-villain.git
MAINTAINERS +7 -0
index 4ca1751e30..d87fc958cb 100644
@@ -4681,6 +4681,13 @@ F: tests/functional/generic/test_linters.py
 F: tests/functional/pylintrc
 F: tests/functional/qemu_test/
 
+virtio-villain fault injection test
+M: Anatol Belski <[email protected]>
+S: Maintained
+F: tests/virtio-villain
+F: tests/virtio-villain-*.py
+F: docs/devel/testing/virtio-villain.rst
+
 Windows Hosted Continuous Integration
 M: Yonggang Luo <[email protected]>
 S: Maintained
docs/devel/testing/index.rst +1 -0
index ccc2fc6cbc..875ef92128 100644
@@ -10,6 +10,7 @@ testing infrastructure.
    main
    qtest
    functional
+   virtio-villain
    acpi-bits
    ci
    fuzzing
docs/devel/testing/virtio-villain.rst new file +102 -0

102 lines not on this page · raw message

scripts/mtest2make.py +2 -1
index 383ea68b16..696c41e9f4 100644
@@ -80,7 +80,8 @@ def emit_prolog(suites, prefix):
     print(f'all-{prefix}-targets = {all_targets}')
     print(f'all-{prefix}-xml = {all_xml}')
     print(f'.PHONY: {prefix} do-meson-{prefix} {prefix}-report.junit.xml $(all-{prefix}-targets) $(all-{prefix}-xml)')
-    print(f'ninja-cmd-goals += $(foreach s, $(.{prefix}.mtest-suites), $(.{prefix}-$s.deps))')
+    print(f'ninja-cmd-goals += $(foreach s, $(.{prefix}.mtest-suites), '
+          f'$(.{prefix}-$(patsubst %-optional,%,$s).deps))')
     print(f'{prefix}-build: run-ninja')
     print(f'{prefix} $(all-{prefix}-targets): do-meson-{prefix}')
     print(f'do-meson-{prefix}: run-ninja; $(if $(MAKE.n),,+)$(MESON) test $(.{prefix}.mtestargs)')
tests/Makefile.include +7 -0
index 9f82552ab5..d5cca6a0d1 100644
@@ -16,6 +16,7 @@ check-help:
 	@echo " $(MAKE) check-tracetool               Run tracetool generator tests"
 	@echo " $(MAKE) check-block                   Run block tests (all formats/protocols)"
 	@echo " $(MAKE) check-block-DRIVER            Run block tests (only for format/protocol 'DRIVER')"
+	@echo " $(MAKE) virtio-villain                 Run the standalone virtio fault injection suite"
 ifneq ($(filter $(all-check-targets), check-softfloat),)
 	@echo " $(MAKE) check-softfloat               Run FPU emulation tests"
 	@echo " $(MAKE) check-tcg                     Run TCG tests"
@@ -55,6 +56,10 @@ check-functional:
 .PHONY: check-func check-func-quick
 check-func check-func-quick:
 
+.PHONY: virtio-villain
+virtio-villain:
+	@$(MAKE) check-virtio-villain
+
 # Consolidated targets
 
 .PHONY: check check-clean
@@ -64,6 +69,8 @@ check-build: run-ninja
 
 check-clean:
 	rm -rf $(BUILD_DIR)/tests/functional
+	rm -rf $(BUILD_DIR)/tests/virtio-villain-build
+	rm -f $(BUILD_DIR)/tests/virtio-villain-initramfs.stamp
 
 clean: check-clean
 
tests/meson.build +46 -0

52 lines not on this page · raw message

tests/virtio-villain new file +1 -0
new file mode 160000
index 0000000000..b5f73dbf24
@@ -0,0 +1 @@
+Subproject commit b5f73dbf242f78e72c6b1fdbe8d528f54cba3e90
tests/virtio-villain-build.py new file +64 -0

64 lines not on this page · raw message

tests/virtio-villain-list.py new file +53 -0

53 lines not on this page · raw message

tests/virtio-villain-test.py new file +314 -0

314 lines not on this page · raw message

Signature · 1 line
2.56.0
#3 lore raw

Re: [PATCH v2] tests: Add virtio-villain fault injection suite

Quoted 22 lines · Anatol Belski

Add a test suite that drives the virtio-villain harness against QEMU. virtio-villain is a guest side fault injection tool that boots a separate guest for each case. Each case supplies invalid virtio driver input to test how the device model handles it.

The harness is added as a git submodule under tests/virtio-villain. Case IDs are discovered from source filenames during configuration and each case is registered as a Meson test. Meson controls parallel execution and timeouts, with one case per runner invocation.

The suite builds the static guest initramfs and fetches kernels on demand for native Linux x86_64 and aarch64 hosts. Generated artifacts stay in the build directory and kernel downloads use the QEMU asset cache.

The virtio-villain and check-virtio-villain make targets build and run the suite without adding it to the default check target. Each case retains readable logs and JSON reports, with skipped cases reported separately from successful tests. Embedded helper tests and documentation are included.

snip

Quoted 11 lines
docs/devel/testing/virtio-villain.rst new file +5 -0
new file mode 100644
index 0000000000..a4a100f49d
@@ -0,0 +1,102 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+virtio-villain
+==============
+

docs/devel/testing/virtio-villain.rst line 15

Quoted 10 lines
docs/devel/testing/virtio-villain.rst new file +10 -0
+The virtio-villain suite tests how QEMU handles invalid virtio driver
+input. The harness boots a separate guest for each case to isolate
+crashes. Meson registers each case individually and controls parallel
+execution, timeouts and results.
+
+Requirements
+------------
+
+The suite supports native Linux x86_64 and aarch64 hosts with the
+matching system emulator enabled and access to ``/dev/kvm``.

What part of it requires use of /dev/kvm ? The virtio devices can be used under TCG, albeit with a much slower test suite.

If we didn't have the KVM dep, then we could run it under gitlab CI.

docs/devel/testing/virtio-villain.rst line 20

Quoted 5 lines
docs/devel/testing/virtio-villain.rst new file +5 -0
+Cross compilation is not supported.
+Building the static guest init requires make, strip, cpio, gzip and
+a compiler with static C library support. The build prefers musl-gcc
+when available and otherwise uses the native compiler recorded by
+Meson, including its compiler arguments.

What's the goal with preferring musl-gcc ?

I get the standalone virtio-villain harness may be preferring musl-gcc and that's fine, but for integration in QEMU, I would expect it to always honour the C compiler configured by meson and nothing else.

docs/devel/testing/virtio-villain.rst line 34

Quoted 6 lines
docs/devel/testing/virtio-villain.rst new file +6 -0
+Running the suite
+-----------------
+
+From the QEMU checkout, run::
+
+  make -C build-release virtio-villain

When running 'configure' from the src tree, QEMU auto-creates a 'build' directory. So our makefiles "do the right thing" whether run from the root of the buld directory or from the source directory.

The only people needing to use '-C ...somedir...' are those who want a different build directory name while using make from the source dir.

This is along winded way of saying just drop the '-C build-release' part from the docs examples, and assume our defaults.[

docs/devel/testing/virtio-villain.rst line 39

Quoted 5 lines
docs/devel/testing/virtio-villain.rst new file +5 -0
+
+Replace ``build-release`` with your build directory. Use ``make -jN``
+to control how many cases Meson runs concurrently::
+
+  make -C build-release -j16 virtio-villain

This bit can be dropped - it is not specific to this test suite and -jNN is normal stuff anyone knows when using make, so can drop that arg from all the examples.

docs/devel/testing/virtio-villain.rst line 41

Quoted 1 line
docs/devel/testing/virtio-villain.rst new file +1 -0
+The ``virtio-villain`` target invokes ``check-virtio-villain``.

I don't see a benefit to creating a 'virtio-villain' target, we can just document 'check-virtio-villain' as that fits in with our other 'check-functional', 'check-qtest', 'check-block', etc naming conventions.

docs/devel/testing/virtio-villain.rst line 54

Quoted 13 lines
docs/devel/testing/virtio-villain.rst new file +13 -0
+The target builds the guest initramfs and fetches kernels on demand.
+Neither operation runs during a normal QEMU build. Generated files
+stay under the build directory. Kernel downloads
+reuse the QEMU asset cache and verify the SHA256 checksum. Set
+``QEMU_TEST_CACHE_DIR`` to override the cache location or
+``QEMU_TEST_NO_DOWNLOAD=1`` to require cached kernels.
+
+This standalone suite is not part of the functional tests or the
+default ``make check`` selection. Its Meson suite name is
+``virtio-villain-optional``, following the QEMU optional suite convention.
+To run one case directly through Meson::
+
+  build-release/pyvenv/bin/meson test -C build-release RNG0001-basic

We prefer to point people to the 'run' script in the build dir:

$BUILD-DIR/run meson test RNG0001-basic

Quoted 37 lines
docs/devel/testing/virtio-villain.rst new file +37 -0
+Filtering cases
+---------------
+
+Meson test names combine the case ID with a description from the source
+filename, for example ``RNG0001-basic``. The suite identifies them as
+virtio-villain tests without repeating that prefix in every name.
+
+Pass Meson name filters through ``MTESTARGS`` to run one case by ID::
+
+  make -C build-release virtio-villain MTESTARGS='RNG0001-*'
+
+Use a wildcard to run a group of cases::
+
+  make -C build-release -j16 virtio-villain MTESTARGS='RNG*'
+
+Multiple filters select the union of their matches::
+
+  make -C build-release -j16 virtio-villain \
+    MTESTARGS='RNG* B0196-*'
+
+List matching cases without running them::
+
+  build-release/pyvenv/bin/meson test -C build-release \
+    --suite virtio-villain-optional --list 'RNG*'
+
+Quote wildcard filters to prevent shell expansion. These are Meson
+test name filters, not the directory filters of the villain runner.
+
+Results and logs
+----------------
+
+Each invocation runs one case with the QEMU binary from the build.
+
+PASS and REJECT pass. SKIP and XFAIL are reported as skipped.
+FAIL, WEDGED and XPASS fail. Runner errors and missing reports fail
+rather than appearing as successful tests. Unsupported devices and
+unavailable host services are skipped by the harness.

docs/devel/testing/virtio-villain.rst line 102

Quoted 10 lines
docs/devel/testing/virtio-villain.rst new file +10 -0
+
+Meson reports each case separately and writes its standard text and
+JUnit reports under ``<build>/meson-logs/``. Full readable case logs
+and JSON reports are retained under
+``<build>/tests/virtio-villain-build/logs/<case>.log`` and ``<case>.json``.
+The test output always points to its case log.
+
+The reporting helper has embedded unit tests that run without a VM::
+
+  python3 tests/virtio-villain-test.py --self-test

If I run the villain tests on current QEMU with this patch applied I get a number of failures. I assume that is expected currently ?

Summary of Failures:

 254/1964 virtio-villain-optional - qemu:B0173-xq-write-read-verify                   FAIL            2.07s   exit status 1
 398/1964 virtio-villain-optional - qemu:B0201-hotplug-remove-readd                   FAIL           17.61s   exit status 1
 671/1964 virtio-villain-optional - qemu:M0019-mmio-queue-num-max-read                FAIL            5.32s   exit status 1
1182/1964 virtio-villain-optional - qemu:P0060-packed-desc-addr-pci-bar               FAIL           30.36s   exit status 1
1207/1964 virtio-villain-optional - qemu:PCI0200-remove-during-kick                   FAIL           14.41s   exit status 1
1504/1964 virtio-villain-optional - qemu:SND0005-info-size-short                      FAIL            1.19s   exit status 1
1514/1964 virtio-villain-optional - qemu:SND0012-pcm-info-size-zero                   FAIL            1.80s   exit status 1
1523/1964 virtio-villain-optional - qemu:SND0015-pcm-info-status-short                FAIL            2.41s   exit status 1
1563/1964 virtio-villain-optional - qemu:SND0065-tx-missing-status                    FAIL            1.73s   exit status 1
1566/1964 virtio-villain-optional - qemu:SND0066-tx-status-short                      FAIL            1.81s   exit status 1
1571/1964 virtio-villain-optional - qemu:SND0076-rx-status-short                      FAIL            1.56s   exit status 1
1573/1964 virtio-villain-optional - qemu:SND0078-rx-header-only                       FAIL            1.52s   exit status 1
1593/1964 virtio-villain-optional - qemu:SND0088-tx-status-readable                   FAIL            2.05s   exit status 1
1963/1964 virtio-villain-optional - qemu:T0063-desc-addr-pci-bar                      FAIL           30.53s   exit status 1

tests/Makefile.include check-help: · line 19

Quoted 9 lines
tests/Makefile.include +1 -0
index 9f82552ab5..d5cca6a0d1 100644
@@ -16,6 +16,7 @@ check-help:
 	@echo " $(MAKE) check-tracetool               Run tracetool generator tests"
 	@echo " $(MAKE) check-block                   Run block tests (all formats/protocols)"
 	@echo " $(MAKE) check-block-DRIVER            Run block tests (only for format/protocol 'DRIVER')"
+	@echo " $(MAKE) virtio-villain                 Run the standalone virtio fault injection suite"

s/virtio-villain/check-virtio-villain/ and ^^^ minor alignment bug

tests/Makefile.include check-functional: · line 61

Quoted 10 lines
tests/Makefile.include +3 -0
 ifneq ($(filter $(all-check-targets), check-softfloat),)
 	@echo " $(MAKE) check-softfloat               Run FPU emulation tests"
 	@echo " $(MAKE) check-tcg                     Run TCG tests"
@@ -55,6 +56,10 @@ check-functional:
 .PHONY: check-func check-func-quick
 check-func check-func-quick:
 
+.PHONY: virtio-villain
+virtio-villain:
+	@$(MAKE) check-virtio-villain

IMHO this is redundant and can be dropped.

tests/meson.build line 3

Quoted 8 lines
tests/meson.build +0 -0
index 5877d2f60b..619e24c78c 100644
@@ -1,6 +1,52 @@
 subdir('bench')
 subdir('qemu-iotests')
 

A few blank lines in places below would do wonders for readability.

tests/meson.build line 10

Quoted 7 lines
tests/meson.build +7 -0
+if host_os == 'linux' and not meson.is_cross_build() and \
+   cpu in ['x86_64', 'aarch64'] and \
+   emulators.has_key('qemu-system-' + cpu)
+  villain_make = find_program('make', required: false)
+  villain_strip = find_program('strip', required: false)
+  villain_cpio = find_program('cpio', required: false)
+  villain_gzip = find_program('gzip', required: false)

<blank>

tests/meson.build line 14

Quoted 4 lines
tests/meson.build +4 -0
+  if villain_make.found() and villain_strip.found() and \
+     villain_cpio.found() and villain_gzip.found()
+    villain_list = files('virtio-villain-list.py')
+    villain_list_args = get_option('wrap_mode') == 'nodownload' ? ['--no-download'] : []

<blank>

tests/meson.build line 20

Quoted 6 lines
tests/meson.build +6 -0
+    villain_names = run_command(
+      python, villain_list, villain_list_args, check: true
+    ).stdout().strip().split()
+    villain_sources = run_command(
+      python, villain_list, villain_list_args, '--sources', check: true
+    ).stdout().strip().split('\n')

<blank>

tests/meson.build line 24

Quoted 4 lines
tests/meson.build +4 -0
+    villain_musl = find_program('musl-gcc', required: false)
+    villain_cc = villain_musl.found() ? [villain_musl.full_path()] : \
+                                      meson.get_compiler('c', native: true).cmd_array()
+    villain_build_dir = meson.current_build_dir() / 'virtio-villain-build'

<blank>

tests/meson.build line 34

Quoted 10 lines
tests/meson.build +10 -0
+    villain_initramfs = custom_target(
+      'virtio-villain-initramfs',
+      output: 'virtio-villain-initramfs.stamp',
+      command: [python, files('virtio-villain-build.py'),
+                '--source', meson.current_source_dir() / 'virtio-villain',
+                '--build', villain_build_dir, '--arch', cpu,
+                '--stamp', '@OUTPUT@', '--make', villain_make.full_path(),
+                '--'] + villain_cc,
+      depend_files: files(villain_sources + ['functional/qemu_test/asset.py']),
+      build_by_default: false)

<blank>

Quoted 8 lines
tests/meson.build +8 -0
+    foreach name : villain_names
+      test(name, python,
+           args: [files('virtio-villain-test.py'),
+                  '--build', villain_build_dir,
+                  '--source', meson.current_source_dir() / 'virtio-villain',
+                  '--qemu', emulators['qemu-system-' + cpu].full_path(),
+                  name.split('-')[0]],
+           depends: [villain_initramfs, emulators['qemu-system-' + cpu]],

tests/meson.build line 52

Quoted 10 lines
tests/meson.build +7 -0
+           suite: ['virtio-villain-optional'], timeout: 90)
+    endforeach
+  else
+    message('virtio-villain requires make, strip, cpio and gzip')
+  endif
+endif
+
 test_qapi_outputs = [
   'qapi-builtin-types.c',
   'qapi-builtin-types.h',

If we can run without a KVM dep, then it would be nice to add this into GitLab CI, by adding to the .gitlab-ci.yml.d/buildtest.yml file:

virtio-villain:
extends: .native_test_job_template
needs:
- job: build-system-fedora
artifacts: true
variables:
IMAGE: fedora
script:
- cd build
- make -j"$JOBS" check-virtio-villain
allow-failure: true

obviously it would be better not to have the 'allow-failure: true' bit. Those failures mentioned earlier would need fixing first but I assume we want to address those bugs quickly regardless.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#4 lore raw

PATCH v3 1/1 tests: Add virtio-villain fault injection suite

In reply to Anatol Belski

Add a test suite that drives the virtio-villain harness against QEMU. virtio-villain is a guest side fault injection tool that boots a separate guest for each case. Each case supplies invalid virtio driver input to test how the device model handles it.

The harness is added as a git submodule under tests/virtio-villain. Case IDs are discovered from source filenames during configuration and each case is registered as a Meson test. Meson controls parallel execution and timeouts, with one case per runner invocation.

The suite builds the static guest initramfs and fetches kernels on demand for native Linux x86_64 and aarch64 hosts. Generated artifacts stay in the build directory and kernel downloads use the QEMU asset cache. The build uses the C compiler configured by Meson. KVM is the default, while QEMU_TEST_VIRTIO_VILLAIN_ACCEL=tcg selects TCG.

The check-virtio-villain make target builds and runs the suite without adding it to the default check target. Each case retains readable logs and JSON reports, with skipped cases reported separately from successful tests. Embedded helper tests and documentation are included. GitLab CI configuration is added for a Fedora job with TCG.

---
Thanks for the review. I've adapted virtio-villain and subsequently the current patch to fulfill the review points. TCG is now supported along with KVM, as the latter can be useful for local runs.

I run the tests regularly, especially when developing new cases, and compare the results across all supported VMMs. The failures mentioned in the review are not unexpected.

I submitted a patch for some of the SND issues some time ago:
https://lore.kernel.org/qemu-devel/[email protected]/T/#u

I also filed GitLab work item #4117 based on the findings from T0063 a couple of months ago. Those issues need follow up separately from this integration patch.

 .gitlab-ci.d/buildtest.yml            |  13 +
 .gitmodules                           |   3 +
 MAINTAINERS                           |   7 +
 docs/devel/testing/index.rst          |   1 +
 docs/devel/testing/virtio-villain.rst |  98 ++++++++
 scripts/mtest2make.py                 |   3 +-
 tests/Makefile.include                |   3 +
 tests/meson.build                     |  54 ++++
 tests/virtio-villain                  |   1 +
 tests/virtio-villain-build.py         |  64 +++++
 tests/virtio-villain-list.py          |  53 ++++
 tests/virtio-villain-test.py          | 348 ++++++++++++++++++++++++++
 12 files changed, 647 insertions(+), 1 deletion(-)
 create mode 100644 docs/devel/testing/virtio-villain.rst
 create mode 160000 tests/virtio-villain
 create mode 100644 tests/virtio-villain-build.py
 create mode 100644 tests/virtio-villain-list.py
 create mode 100644 tests/virtio-villain-test.py
.gitlab-ci.d/buildtest.yml +13 -0
index b1e95395d0..19d6d4c363 100644
@@ -148,6 +148,19 @@ functional-system-fedora:
     IMAGE: fedora
     MAKE_CHECK_ARGS: check-functional
 
+virtio-villain:
+  extends: .native_test_job_template
+  needs:
+    - job: build-system-fedora
+      artifacts: true
+  variables:
+    IMAGE: fedora
+    QEMU_TEST_VIRTIO_VILLAIN_ACCEL: tcg
+  script:
+    - cd build
+    - make -j"$JOBS" check-virtio-villain
+  allow_failure: true
+
 crash-test-fedora:
   extends: .native_test_job_template
   needs:
.gitmodules +3 -0
index c307216d17..fd3083ca4b 100644
@@ -45,3 +45,6 @@
 [submodule "tests/lcitool/libvirt-ci"]
 	path = tests/lcitool/libvirt-ci
 	url = https://gitlab.com/libvirt/libvirt-ci.git
+[submodule "tests/virtio-villain"]
+	path = tests/virtio-villain
+	url = https://github.com/weltling/virtio-villain.git
MAINTAINERS +7 -0
index 70e9fed776..fa5efa27e0 100644
@@ -4698,6 +4698,13 @@ F: tests/functional/generic/test_linters.py
 F: tests/functional/pylintrc
 F: tests/functional/qemu_test/
 
+virtio-villain fault injection test
+M: Anatol Belski <[email protected]>
+S: Maintained
+F: tests/virtio-villain
+F: tests/virtio-villain-*.py
+F: docs/devel/testing/virtio-villain.rst
+
 Windows Hosted Continuous Integration
 M: Yonggang Luo <[email protected]>
 S: Maintained
docs/devel/testing/index.rst +1 -0
index ccc2fc6cbc..875ef92128 100644
@@ -10,6 +10,7 @@ testing infrastructure.
    main
    qtest
    functional
+   virtio-villain
    acpi-bits
    ci
    fuzzing
docs/devel/testing/virtio-villain.rst new file +98 -0

98 lines not on this page · raw message

scripts/mtest2make.py +2 -1
index 383ea68b16..696c41e9f4 100644
@@ -80,7 +80,8 @@ def emit_prolog(suites, prefix):
     print(f'all-{prefix}-targets = {all_targets}')
     print(f'all-{prefix}-xml = {all_xml}')
     print(f'.PHONY: {prefix} do-meson-{prefix} {prefix}-report.junit.xml $(all-{prefix}-targets) $(all-{prefix}-xml)')
-    print(f'ninja-cmd-goals += $(foreach s, $(.{prefix}.mtest-suites), $(.{prefix}-$s.deps))')
+    print(f'ninja-cmd-goals += $(foreach s, $(.{prefix}.mtest-suites), '
+          f'$(.{prefix}-$(patsubst %-optional,%,$s).deps))')
     print(f'{prefix}-build: run-ninja')
     print(f'{prefix} $(all-{prefix}-targets): do-meson-{prefix}')
     print(f'do-meson-{prefix}: run-ninja; $(if $(MAKE.n),,+)$(MESON) test $(.{prefix}.mtestargs)')
tests/Makefile.include +3 -0
index 9f82552ab5..7d13a97f69 100644
@@ -16,6 +16,7 @@ check-help:
 	@echo " $(MAKE) check-tracetool               Run tracetool generator tests"
 	@echo " $(MAKE) check-block                   Run block tests (all formats/protocols)"
 	@echo " $(MAKE) check-block-DRIVER            Run block tests (only for format/protocol 'DRIVER')"
+	@echo " $(MAKE) check-virtio-villain          Run the standalone virtio fault injection suite"
 ifneq ($(filter $(all-check-targets), check-softfloat),)
 	@echo " $(MAKE) check-softfloat               Run FPU emulation tests"
 	@echo " $(MAKE) check-tcg                     Run TCG tests"
@@ -64,6 +65,8 @@ check-build: run-ninja
 
 check-clean:
 	rm -rf $(BUILD_DIR)/tests/functional
+	rm -rf $(BUILD_DIR)/tests/virtio-villain-build
+	rm -f $(BUILD_DIR)/tests/virtio-villain-initramfs.stamp
 
 clean: check-clean
 
tests/meson.build +54 -0

60 lines not on this page · raw message

tests/virtio-villain new file +1 -0
new file mode 160000
index 0000000000..5fda8d1a78
@@ -0,0 +1 @@
+Subproject commit 5fda8d1a78f0238b3c952c454c2cf15b1bfd204e
tests/virtio-villain-build.py new file +64 -0

64 lines not on this page · raw message

tests/virtio-villain-list.py new file +53 -0

53 lines not on this page · raw message

tests/virtio-villain-test.py new file +348 -0

348 lines not on this page · raw message

Signature · 1 line
2.56.0