| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 4 | # |
| 5 | '''Test whether the vmstate-static-checker script detects problems correctly''' |
| 6 | |
| 7 | import subprocess |
| 8 | import sys |
| 9 | |
| 10 | from qemu_test import QemuBaseTest |
| 11 | |
| 12 | |
| 13 | EXPECTED_OUTPUT='''Warning: checking incompatible machine types: "pc-i440fx-2.1", "pc-i440fx-2.2" |
| 14 | Section "fw_cfg" does not exist in dest |
| 15 | Section "fusbh200-ehci-usb" version error: 2 > 1 |
| 16 | Section "fusbh200-ehci-usb", Description "ehci-core": expected field "usbsts", got "usbsts_pending"; skipping rest |
| 17 | Section "pci-serial-4x" Description "pci-serial-multi": Entry "Fields" missing |
| 18 | Section "intel-hda-generic", Description "intel-hda", Field "pci": missing description |
| 19 | Section "cfi.pflash01": Entry "Description" missing |
| 20 | Section "megasas", Description "PCIDevice": expected field "irq_state", while dest has no further fields |
| 21 | Section "PIIX3-xen" Description "PIIX3": minimum version error: 1 < 2 |
| 22 | Section "PIIX3-xen" Description "PIIX3": Entry "Subsections" missing |
| 23 | Section "tpci200": Description "tpci200" missing, got "tpci2002" instead; skipping |
| 24 | Section "sun-fdtwo" Description "fdc": version error: 2 > 1 |
| 25 | Section "sun-fdtwo", Description "fdrive": Subsection "fdrive/media_rate" not found |
| 26 | Section "usb-kbd" Description "usb-kbd" Field "kbd.keycodes" size mismatch: 4 , 2 |
| 27 | ''' |
| 28 | |
| 29 | class BadVmStateTest(QemuBaseTest): |
| 30 | '''Test class for testing vmstat-static-checker script with bad input''' |
| 31 | |
| 32 | def test_checker(self): |
| 33 | """ |
| 34 | Test whether the checker script correctly detects the changes |
| 35 | between dump1.json and dump2.json. |
| 36 | """ |
| 37 | src_json = self.data_file('..', 'data', 'vmstate-static-checker', |
| 38 | 'dump1.json') |
| 39 | dst_json = self.data_file('..', 'data', 'vmstate-static-checker', |
| 40 | 'dump2.json') |
| 41 | checkerscript = self.data_file('..', '..', 'scripts', |
| 42 | 'vmstate-static-checker.py') |
| 43 | |
| 44 | self.log.info('Comparing %s with %s', src_json, dst_json) |
| 45 | cp = subprocess.run([sys.executable, checkerscript, |
| 46 | '-s', src_json, '-d', dst_json], |
| 47 | stdout=subprocess.PIPE, |
| 48 | stderr=subprocess.STDOUT, |
| 49 | text=True, check=False) |
| 50 | if cp.returncode != 13: |
| 51 | self.fail('Unexpected return code of vmstate-static-checker: %d' % |
| 52 | cp.returncode) |
| 53 | if cp.stdout != EXPECTED_OUTPUT: |
| 54 | self.log.info('vmstate-static-checker output:\n%s', cp.stdout) |
| 55 | self.log.info('expected output:\n%s', EXPECTED_OUTPUT) |
| 56 | self.fail('Unexpected vmstate-static-checker output!') |
| 57 | |
| 58 | |
| 59 | if __name__ == '__main__': |
| 60 | QemuBaseTest.main() |