master
py 78 lines 2.61 KB
Raw
1 #!/usr/bin/env python3
2 #
3 # Functional tests for the IBM PPE42 processor
4 #
5 # Copyright (c) 2025, IBM Corporation
6 #
7 # SPDX-License-Identifier: GPL-2.0-or-later
8
9 import asyncio
10 from qemu_test import QemuSystemTest, Asset
11
12
13 class Ppe42Machine(QemuSystemTest):
14
15 timeout = 90
16 poll_period = 1.0
17
18 ASSET_PPE42_TEST_IMAGE = Asset(
19 ('https://github.com/milesg-github/ppe42-tests/raw/refs/heads/main/'
20 'images/ppe42-test.out'),
21 '03c1ac0fb7f6c025102a02776a93b35101dae7c14b75e4eab36a337e39042ea8')
22
23 def _test_completed(self):
24 self.log.info("Checking for test completion...")
25 try:
26 output = self.vm.cmd('human-monitor-command',
27 command_line='info registers')
28 except Exception as err:
29 self.log.debug(f"'info registers' cmd failed due to {err=},"
30 " {type(err)=}")
31 raise
32
33 self.log.info(output)
34 if "NIP fff80200" not in output:
35 self.log.info("<test not completed>")
36 return False
37
38 self.log.info("<test completed>")
39 return True
40
41 def _wait_pass_fail(self, timeout):
42 while not self._test_completed():
43 if timeout >= self.poll_period:
44 timeout = timeout - self.poll_period
45 self.log.info(f"Waiting {self.poll_period} seconds for test"
46 " to complete...")
47 e = None
48 try:
49 e = self.vm.event_wait('STOP', self.poll_period)
50
51 except asyncio.TimeoutError:
52 self.log.info("Poll period ended.")
53
54 except Exception as err:
55 self.log.debug(f"event_wait() failed due to {err=},"
56 " {type(err)=}")
57 raise
58
59 if e is not None:
60 self.log.debug(f"Execution stopped: {e}")
61 self.log.debug("Exiting due to test failure")
62 self.fail("Failure detected!")
63 else:
64 self.fail("Timed out waiting for test completion.")
65
66 def test_ppe42_instructions(self):
67 self.set_machine('ppe42_machine')
68 self.require_accelerator("tcg")
69 image_path = self.ASSET_PPE42_TEST_IMAGE.fetch()
70 self.vm.add_args('-nographic')
71 self.vm.add_args('-device', f'loader,file={image_path}')
72 self.vm.add_args('-device', 'loader,addr=0xfff80040,cpu-num=0')
73 self.vm.add_args('-action', 'panic=pause')
74 self.vm.launch()
75 self._wait_pass_fail(self.timeout)
76
77 if __name__ == '__main__':
78 QemuSystemTest.main()