1#!/usr/bin/env python3
2#
3# Test AmigaNG boards
4#
5# Copyright (c) 2023 BALATON Zoltan
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 subprocess
11
12from qemu_test import QemuSystemTest, Asset
13from qemu_test import wait_for_console_pattern, run_cmd
14from zipfile import ZipFile
15
16class AmigaOneMachine(QemuSystemTest):
17
18    timeout = 90
19
20    ASSET_IMAGE = Asset(
21        ('https://www.hyperion-entertainment.com/index.php/'
22         'downloads?view=download&format=raw&file=25'),
23        '8ff39330ba47d4f64de4ee8fd6809e9c010a9ef17fe51e95c3c1d53437cb481f')
24
25    def test_ppc_amigaone(self):
26        self.require_accelerator("tcg")
27        self.set_machine('amigaone')
28        tar_name = 'A1Firmware_Floppy_05-Mar-2005.zip'
29        zip_file = self.ASSET_IMAGE.fetch()
30        with ZipFile(zip_file, 'r') as zf:
31            zf.extractall(path=self.workdir)
32        bios_fh = open(self.workdir + "/u-boot-amigaone.bin", "wb")
33        subprocess.run(['tail', '-c', '524288',
34                        self.workdir + "/floppy_edition/updater.image"],
35                        stdout=bios_fh)
36
37        self.vm.set_console()
38        self.vm.add_args('-bios', self.workdir + '/u-boot-amigaone.bin')
39        self.vm.launch()
40        wait_for_console_pattern(self, 'FLASH:')
41
42if __name__ == '__main__':
43    QemuSystemTest.main()
44