From: Thomas Huth <thuth@redhat.com>
We've got this nice vmstate-static-checker.py script that can help
to detect screw-ups in the migration states. Unfortunately, it's
currently only run manually, so there are regressions that nobody
notices immediately. Let's run it from a functional test automatically
so that we got at least a basic coverage in each CI run.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
MAINTAINERS | 1 +
tests/functional/meson.build | 13 ++++++-
tests/functional/test_vmstate.py | 59 ++++++++++++++++++++++++++++++++
3 files changed, 72 insertions(+), 1 deletion(-)
create mode 100755 tests/functional/test_vmstate.py
diff --git a/MAINTAINERS b/MAINTAINERS
index 55735de4e4e..e92c60f891d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3548,6 +3548,7 @@ F: migration/
F: scripts/vmstate-static-checker.py
F: tests/data/vmstate-static-checker/
F: tests/functional/test_migration.py
+F: tests/functional/test_vmstate.py
F: tests/qtest/migration/
F: tests/qtest/migration-*
F: docs/devel/migration/
diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index 52b4706cfe8..81fc26ca3d5 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -78,6 +78,7 @@ tests_generic_bsduser = [
tests_aarch64_system_quick = [
'migration',
+ 'vmstate',
]
tests_aarch64_system_thorough = [
@@ -168,6 +169,10 @@ tests_loongarch64_system_thorough = [
'loongarch64_virt',
]
+tests_m68k_system_quick = [
+ 'vmstate',
+]
+
tests_m68k_system_thorough = [
'm68k_mcf5208evb',
'm68k_nextcube',
@@ -234,6 +239,7 @@ tests_ppc_system_thorough = [
tests_ppc64_system_quick = [
'migration',
+ 'vmstate',
]
tests_ppc64_system_thorough = [
@@ -269,6 +275,10 @@ tests_rx_system_thorough = [
'rx_gdbsim',
]
+tests_s390x_system_quick = [
+ 'vmstate',
+]
+
tests_s390x_system_thorough = [
's390x_ccw_virtio',
's390x_replay',
@@ -309,8 +319,9 @@ tests_x86_64_system_quick = [
'migration',
'pc_cpu_hotplug_props',
'virtio_version',
- 'x86_cpu_model_versions',
+ 'vmstate',
'vnc',
+ 'x86_cpu_model_versions',
]
tests_x86_64_system_thorough = [
diff --git a/tests/functional/test_vmstate.py b/tests/functional/test_vmstate.py
new file mode 100755
index 00000000000..cc988987481
--- /dev/null
+++ b/tests/functional/test_vmstate.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python3
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# This test runs the vmstate-static-checker script with the current QEMU
+
+import subprocess
+
+from qemu_test import QemuSystemTest
+
+
+class VmStateTest(QemuSystemTest):
+
+ def run_vmstate_checker(self, src_json, dst_json):
+ checkerscript = self.data_file('..', '..', 'scripts',
+ 'vmstate-static-checker.py')
+ return subprocess.run([checkerscript, '-s', src_json, '-d', dst_json],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ text=True)
+
+ def test_vmstate(self):
+ target_machine = {
+ 'aarch64': 'virt-7.2',
+ 'm68k': 'virt-7.2',
+ 'ppc64': 'pseries-7.2',
+ 's390x': 's390-ccw-virtio-7.2',
+ 'x86_64': 'pc-q35-7.2',
+ }
+ self.set_machine(target_machine[self.arch])
+
+ # Run QEMU to get the current vmstate json file:
+ dst_json = self.scratch_file('dest.json')
+ self.log.info('Dumping vmstate from ' + self.qemu_bin)
+ cp = subprocess.run([self.qemu_bin, '-nodefaults',
+ '-M', target_machine[self.arch],
+ '-dump-vmstate', dst_json],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ text=True)
+ if cp.returncode != 0:
+ self.fail('Running QEMU failed:\n' + cp.stdout)
+ if cp.stdout:
+ self.log.info('QEMU output: ' + cp.stdout)
+
+ # Check whether the old vmstate json file is still compatible:
+ src_json = self.data_file('..', 'data', 'vmstate-static-checker',
+ self.arch,
+ target_machine[self.arch] + '.json')
+ self.log.info('Comparing vmstate with ' + src_json)
+ cp = self.run_vmstate_checker(src_json, dst_json)
+ if cp.returncode != 0:
+ self.fail('Running vmstate-static-checker failed:\n' + cp.stdout)
+ if cp.stdout:
+ self.log.warning('vmstate-static-checker output: ' + cp.stdout)
+
+
+if __name__ == '__main__':
+ QemuSystemTest.main()
--
2.49.0
On Thu, May 22, 2025 at 03:37:55PM +0200, Thomas Huth wrote:
[...]
> + def test_vmstate(self):
> + target_machine = {
> + 'aarch64': 'virt-7.2',
> + 'm68k': 'virt-7.2',
> + 'ppc64': 'pseries-7.2',
> + 's390x': 's390-ccw-virtio-7.2',
> + 'x86_64': 'pc-q35-7.2',
> + }
> + self.set_machine(target_machine[self.arch])
> +
> + # Run QEMU to get the current vmstate json file:
> + dst_json = self.scratch_file('dest.json')
> + self.log.info('Dumping vmstate from ' + self.qemu_bin)
> + cp = subprocess.run([self.qemu_bin, '-nodefaults',
> + '-M', target_machine[self.arch],
> + '-dump-vmstate', dst_json],
> + stdout=subprocess.PIPE,
> + stderr=subprocess.STDOUT,
> + text=True)
> + if cp.returncode != 0:
> + self.fail('Running QEMU failed:\n' + cp.stdout)
> + if cp.stdout:
> + self.log.info('QEMU output: ' + cp.stdout)
> +
> + # Check whether the old vmstate json file is still compatible:
> + src_json = self.data_file('..', 'data', 'vmstate-static-checker',
> + self.arch,
> + target_machine[self.arch] + '.json')
> + self.log.info('Comparing vmstate with ' + src_json)
> + cp = self.run_vmstate_checker(src_json, dst_json)
> + if cp.returncode != 0:
> + self.fail('Running vmstate-static-checker failed:\n' + cp.stdout)
Would false positives happen here? Would it fail "make check" and CI, even
if the change was intended?
> + if cp.stdout:
> + self.log.warning('vmstate-static-checker output: ' + cp.stdout)
> +
> +
> +if __name__ == '__main__':
> + QemuSystemTest.main()
> --
> 2.49.0
>
--
Peter Xu
On 22/05/2025 16.38, Peter Xu wrote:
> On Thu, May 22, 2025 at 03:37:55PM +0200, Thomas Huth wrote:
>
> [...]
>
>> + def test_vmstate(self):
>> + target_machine = {
>> + 'aarch64': 'virt-7.2',
>> + 'm68k': 'virt-7.2',
>> + 'ppc64': 'pseries-7.2',
>> + 's390x': 's390-ccw-virtio-7.2',
>> + 'x86_64': 'pc-q35-7.2',
>> + }
>> + self.set_machine(target_machine[self.arch])
>> +
>> + # Run QEMU to get the current vmstate json file:
>> + dst_json = self.scratch_file('dest.json')
>> + self.log.info('Dumping vmstate from ' + self.qemu_bin)
>> + cp = subprocess.run([self.qemu_bin, '-nodefaults',
>> + '-M', target_machine[self.arch],
>> + '-dump-vmstate', dst_json],
>> + stdout=subprocess.PIPE,
>> + stderr=subprocess.STDOUT,
>> + text=True)
>> + if cp.returncode != 0:
>> + self.fail('Running QEMU failed:\n' + cp.stdout)
>> + if cp.stdout:
>> + self.log.info('QEMU output: ' + cp.stdout)
>> +
>> + # Check whether the old vmstate json file is still compatible:
>> + src_json = self.data_file('..', 'data', 'vmstate-static-checker',
>> + self.arch,
>> + target_machine[self.arch] + '.json')
>> + self.log.info('Comparing vmstate with ' + src_json)
>> + cp = self.run_vmstate_checker(src_json, dst_json)
>> + if cp.returncode != 0:
>> + self.fail('Running vmstate-static-checker failed:\n' + cp.stdout)
>
> Would false positives happen here? Would it fail "make check" and CI, even
> if the change was intended?
Yes. In that case, the quick fix is to remove the problematic piece from the
7.2 json files. Or we could try to improve the vmstate-static-checker
script. At least we now notice it immediately, not only after a long delay
until someone runs the script manually again.
But yes, this can be confusing for the who runs into this problem for the
first time. I guess I should at least add some friendly words here with
instructions what has to be done?
Thomas
>> + if cp.stdout:
>> + self.log.warning('vmstate-static-checker output: ' + cp.stdout)
>> +
>> +
>> +if __name__ == '__main__':
>> + QemuSystemTest.main()
>> --
>> 2.49.0
>>
>
On Thu, May 22, 2025 at 08:08:44PM +0200, Thomas Huth wrote:
> On 22/05/2025 16.38, Peter Xu wrote:
> > On Thu, May 22, 2025 at 03:37:55PM +0200, Thomas Huth wrote:
> >
> > [...]
> >
> > > + def test_vmstate(self):
> > > + target_machine = {
> > > + 'aarch64': 'virt-7.2',
> > > + 'm68k': 'virt-7.2',
> > > + 'ppc64': 'pseries-7.2',
> > > + 's390x': 's390-ccw-virtio-7.2',
> > > + 'x86_64': 'pc-q35-7.2',
> > > + }
> > > + self.set_machine(target_machine[self.arch])
> > > +
> > > + # Run QEMU to get the current vmstate json file:
> > > + dst_json = self.scratch_file('dest.json')
> > > + self.log.info('Dumping vmstate from ' + self.qemu_bin)
> > > + cp = subprocess.run([self.qemu_bin, '-nodefaults',
> > > + '-M', target_machine[self.arch],
> > > + '-dump-vmstate', dst_json],
> > > + stdout=subprocess.PIPE,
> > > + stderr=subprocess.STDOUT,
> > > + text=True)
> > > + if cp.returncode != 0:
> > > + self.fail('Running QEMU failed:\n' + cp.stdout)
> > > + if cp.stdout:
> > > + self.log.info('QEMU output: ' + cp.stdout)
> > > +
> > > + # Check whether the old vmstate json file is still compatible:
> > > + src_json = self.data_file('..', 'data', 'vmstate-static-checker',
> > > + self.arch,
> > > + target_machine[self.arch] + '.json')
> > > + self.log.info('Comparing vmstate with ' + src_json)
> > > + cp = self.run_vmstate_checker(src_json, dst_json)
> > > + if cp.returncode != 0:
> > > + self.fail('Running vmstate-static-checker failed:\n' + cp.stdout)
> >
> > Would false positives happen here? Would it fail "make check" and CI, even
> > if the change was intended?
>
> Yes. In that case, the quick fix is to remove the problematic piece from the
> 7.2 json files. Or we could try to improve the vmstate-static-checker
> script. At least we now notice it immediately, not only after a long delay
> until someone runs the script manually again.
Yes, the thing is I worry it'll almost always be false positives (from
statistical POV.. unfortunately). Then in that case it's actually better
to be found later because otherwise it means we're adding overhead to every
developer who might cause the false positive and each of them doing this
work with no real gain.. :(
>
> But yes, this can be confusing for the who runs into this problem for the
> first time. I guess I should at least add some friendly words here with
> instructions what has to be done?
Some instructions would be helpful for sure. Though do we have easy way to
whitelist any false positives? As this test compares the dumps so there's
no diff to fix or work around.
--
Peter Xu
© 2016 - 2026 Red Hat, Inc.