1#!/usr/bin/env python3
2#
3# Functional test that boots a PReP/40p machine and checks its serial console.
4#
5# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
6#
7# This work is licensed under the terms of the GNU GPL, version 2 or
8# later. See the COPYING file in the top-level directory.
9
10import os
11
12from unittest import skipUnless
13from qemu_test import QemuSystemTest, Asset
14from qemu_test import wait_for_console_pattern
15
16
17class IbmPrep40pMachine(QemuSystemTest):
18
19    timeout = 60
20
21    ASSET_BIOS = Asset(
22        ('http://ftpmirror.your.org/pub/misc/'
23         'ftp.software.ibm.com/rs6000/firmware/'
24         '7020-40p/P12H0456.IMG'),
25        'd957f79c73f760d1455d2286fcd901ed6d06167320eb73511b478a939be25b3f')
26    ASSET_NETBSD40 = Asset(
27        ('https://archive.netbsd.org/pub/NetBSD-archive/'
28         'NetBSD-4.0/prep/installation/floppy/generic_com0.fs'),
29        'f86236e9d01b3f0dd0f5d3b8d5bbd40c68e78b4db560a108358f5ad58e636619')
30    ASSET_NETBSD71 = Asset(
31        ('https://archive.netbsd.org/pub/NetBSD-archive/'
32         'NetBSD-7.1.2/iso/NetBSD-7.1.2-prep.iso'),
33        'cc7cb290b06aaa839362deb7bd9f417ac5015557db24088508330f76c3f825ec')
34
35    # 12H0455 PPS Firmware Licensed Materials
36    # Property of IBM (C) Copyright IBM Corp. 1994.
37    # All rights reserved.
38    # U.S. Government Users Restricted Rights - Use, duplication or disclosure
39    # restricted by GSA ADP Schedule Contract with IBM Corp.
40    @skipUnless(os.getenv('QEMU_TEST_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
41    def test_factory_firmware_and_netbsd(self):
42        self.set_machine('40p')
43        self.require_accelerator("tcg")
44        bios_path = self.ASSET_BIOS.fetch()
45        drive_path = self.ASSET_NETBSD40.fetch()
46
47        self.vm.set_console()
48        self.vm.add_args('-bios', bios_path,
49                         '-drive',
50                         f"file={drive_path},format=raw,if=floppy,read-only=true")
51        self.vm.launch()
52        os_banner = 'NetBSD 4.0 (GENERIC) #0: Sun Dec 16 00:49:40 PST 2007'
53        wait_for_console_pattern(self, os_banner)
54        wait_for_console_pattern(self, 'Model: IBM PPS Model 6015')
55
56    def test_openbios_192m(self):
57        self.set_machine('40p')
58        self.require_accelerator("tcg")
59        self.vm.set_console()
60        self.vm.add_args('-m', '192') # test fw_cfg
61
62        self.vm.launch()
63        wait_for_console_pattern(self, '>> OpenBIOS')
64        wait_for_console_pattern(self, '>> Memory: 192M')
65        wait_for_console_pattern(self, '>> CPU type PowerPC,604')
66
67    def test_openbios_and_netbsd(self):
68        self.set_machine('40p')
69        self.require_accelerator("tcg")
70        drive_path = self.ASSET_NETBSD71.fetch()
71        self.vm.set_console()
72        self.vm.add_args('-cdrom', drive_path,
73                         '-boot', 'd')
74
75        self.vm.launch()
76        wait_for_console_pattern(self, 'NetBSD/prep BOOT, Revision 1.9')
77
78if __name__ == '__main__':
79    QemuSystemTest.main()
80