xref: /openbmc/qemu/tests/functional/generic/test_vmstate.py (revision 687a9b83833cda591a04f997a5260f85bd0c5e44)
1#!/usr/bin/env python3
2#
3# SPDX-License-Identifier: GPL-2.0-or-later
4#
5'''This test runs the vmstate-static-checker script with the current QEMU'''
6
7import subprocess
8
9from qemu_test import QemuSystemTest, skipFlakyTest
10
11
12@skipFlakyTest("vmstate-static-checker can produce false positives")
13class VmStateTest(QemuSystemTest):
14    '''
15    This test helps to check whether there are problems between old
16    reference data and the current QEMU
17    '''
18
19    def test_vmstate_7_2(self):
20        '''Check reference data from QEMU v7.2'''
21
22        target_machine = {
23            'aarch64': 'virt-7.2',
24            'm68k': 'virt-7.2',
25            'ppc64': 'pseries-7.2',
26            's390x': 's390-ccw-virtio-7.2',
27            'x86_64': 'pc-q35-7.2',
28        }
29        self.set_machine(target_machine[self.arch])
30
31        # Run QEMU to get the current vmstate json file:
32        dst_json = self.scratch_file('dest.json')
33        self.log.info('Dumping vmstate from %s', self.qemu_bin)
34        cp = subprocess.run([self.qemu_bin, '-nodefaults',
35                             '-M', target_machine[self.arch],
36                             '-dump-vmstate', dst_json],
37                            stdout=subprocess.PIPE,
38                            stderr=subprocess.STDOUT,
39                            text=True, check=True)
40        if cp.stdout:
41            self.log.info('QEMU output: %s', cp.stdout)
42
43        # Check whether the old vmstate json file is still compatible:
44        src_json = self.data_file('..', 'data', 'vmstate-static-checker',
45                                  self.arch,
46                                  target_machine[self.arch] + '.json')
47        self.log.info('Comparing vmstate with %s', src_json)
48        checkerscript = self.data_file('..', '..', 'scripts',
49                                       'vmstate-static-checker.py')
50        cp = subprocess.run([checkerscript, '-s', src_json, '-d', dst_json],
51                            stdout=subprocess.PIPE,
52                            stderr=subprocess.STDOUT,
53                            text=True, check=False)
54        if cp.returncode != 0:
55            self.fail('Running vmstate-static-checker failed:\n' + cp.stdout +
56                      '\nThis either means that there is a migration bug '
57                      'that needs to be fixed, or\nvmstate-static-checker.py '
58                      'needs to be improved (e.g. extend the changed_names\n'
59                      'in case a field has been renamed), or drop the '
60                      'problematic field from\n' + src_json +
61                      '\nin case the script cannot be fixed easily.')
62        if cp.stdout:
63            self.log.warning('vmstate-static-checker output: %s', cp.stdout)
64
65
66if __name__ == '__main__':
67    QemuSystemTest.main()
68