1407a6883SThomas Huth#!/usr/bin/env python3
2407a6883SThomas Huth#
3407a6883SThomas Huth# Functional test that boots a PReP/40p machine and checks its serial console.
4407a6883SThomas Huth#
5407a6883SThomas Huth# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
6407a6883SThomas Huth#
7407a6883SThomas Huth# This work is licensed under the terms of the GNU GPL, version 2 or
8407a6883SThomas Huth# later. See the COPYING file in the top-level directory.
9407a6883SThomas Huth
10407a6883SThomas Huthimport os
11407a6883SThomas Huth
12407a6883SThomas Huthfrom unittest import skipUnless
13407a6883SThomas Huthfrom qemu_test import QemuSystemTest, Asset
14407a6883SThomas Huthfrom qemu_test import wait_for_console_pattern
15407a6883SThomas Huth
16407a6883SThomas Huth
17407a6883SThomas Huthclass IbmPrep40pMachine(QemuSystemTest):
18407a6883SThomas Huth
19407a6883SThomas Huth    timeout = 60
20407a6883SThomas Huth
21407a6883SThomas Huth    ASSET_BIOS = Asset(
22407a6883SThomas Huth        ('http://ftpmirror.your.org/pub/misc/'
23407a6883SThomas Huth         'ftp.software.ibm.com/rs6000/firmware/'
24407a6883SThomas Huth         '7020-40p/P12H0456.IMG'),
25407a6883SThomas Huth        'd957f79c73f760d1455d2286fcd901ed6d06167320eb73511b478a939be25b3f')
26407a6883SThomas Huth    ASSET_NETBSD40 = Asset(
27407a6883SThomas Huth        ('https://archive.netbsd.org/pub/NetBSD-archive/'
28407a6883SThomas Huth         'NetBSD-4.0/prep/installation/floppy/generic_com0.fs'),
29407a6883SThomas Huth        'f86236e9d01b3f0dd0f5d3b8d5bbd40c68e78b4db560a108358f5ad58e636619')
30407a6883SThomas Huth    ASSET_NETBSD71 = Asset(
31407a6883SThomas Huth        ('https://archive.netbsd.org/pub/NetBSD-archive/'
32407a6883SThomas Huth         'NetBSD-7.1.2/iso/NetBSD-7.1.2-prep.iso'),
33407a6883SThomas Huth        'cc7cb290b06aaa839362deb7bd9f417ac5015557db24088508330f76c3f825ec')
34407a6883SThomas Huth
35407a6883SThomas Huth    # 12H0455 PPS Firmware Licensed Materials
36407a6883SThomas Huth    # Property of IBM (C) Copyright IBM Corp. 1994.
37407a6883SThomas Huth    # All rights reserved.
38407a6883SThomas Huth    # U.S. Government Users Restricted Rights - Use, duplication or disclosure
39407a6883SThomas Huth    # restricted by GSA ADP Schedule Contract with IBM Corp.
40407a6883SThomas Huth    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
41407a6883SThomas Huth    def test_factory_firmware_and_netbsd(self):
42407a6883SThomas Huth        self.set_machine('40p')
43407a6883SThomas Huth        self.require_accelerator("tcg")
44407a6883SThomas Huth        bios_path = self.ASSET_BIOS.fetch()
45407a6883SThomas Huth        drive_path = self.ASSET_NETBSD40.fetch()
46407a6883SThomas Huth
47407a6883SThomas Huth        self.vm.set_console()
48407a6883SThomas Huth        self.vm.add_args('-bios', bios_path,
49*dd6402b3SThomas Huth                         '-drive',
50*dd6402b3SThomas Huth                         f"file={drive_path},format=raw,if=floppy,read-only=true")
51407a6883SThomas Huth        self.vm.launch()
52407a6883SThomas Huth        os_banner = 'NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:49:40 PST 2007'
53407a6883SThomas Huth        wait_for_console_pattern(self, os_banner)
54407a6883SThomas Huth        wait_for_console_pattern(self, 'Model: IBM PPS Model 6015')
55407a6883SThomas Huth
56407a6883SThomas Huth    def test_openbios_192m(self):
57407a6883SThomas Huth        self.set_machine('40p')
58407a6883SThomas Huth        self.require_accelerator("tcg")
59407a6883SThomas Huth        self.vm.set_console()
60407a6883SThomas Huth        self.vm.add_args('-m', '192') # test fw_cfg
61407a6883SThomas Huth
62407a6883SThomas Huth        self.vm.launch()
63407a6883SThomas Huth        wait_for_console_pattern(self, '>> OpenBIOS')
64407a6883SThomas Huth        wait_for_console_pattern(self, '>> Memory: 192M')
65407a6883SThomas Huth        wait_for_console_pattern(self, '>> CPU type PowerPC,604')
66407a6883SThomas Huth
67407a6883SThomas Huth    def test_openbios_and_netbsd(self):
68407a6883SThomas Huth        self.set_machine('40p')
69407a6883SThomas Huth        self.require_accelerator("tcg")
70407a6883SThomas Huth        drive_path = self.ASSET_NETBSD71.fetch()
71407a6883SThomas Huth        self.vm.set_console()
72407a6883SThomas Huth        self.vm.add_args('-cdrom', drive_path,
73407a6883SThomas Huth                         '-boot', 'd')
74407a6883SThomas Huth
75407a6883SThomas Huth        self.vm.launch()
76407a6883SThomas Huth        wait_for_console_pattern(self, 'NetBSD/prep BOOT, Revision 1.9')
77407a6883SThomas Huth
78407a6883SThomas Huthif __name__ == '__main__':
79407a6883SThomas Huth    QemuSystemTest.main()
80