1#!/usr/bin/env python3
2#
3# Functional tests for the little-endian 32-bit MIPS Malta board
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 later.
8# See the COPYING file in the top-level directory.
9#
10# SPDX-License-Identifier: GPL-2.0-or-later
11
12import os
13
14from qemu_test import QemuSystemTest, LinuxKernelTest, Asset
15from qemu_test import interrupt_interactive_console_until_pattern
16from qemu_test import wait_for_console_pattern
17from qemu_test.utils import lzma_uncompress
18from zipfile import ZipFile
19
20
21class MaltaMachineConsole(LinuxKernelTest):
22
23    ASSET_KERNEL_4K = Asset(
24        ('http://mipsdistros.mips.com/LinuxDistro/nanomips/'
25         'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
26         'generic_nano32r6el_page4k.xz'),
27        '019e034094ac6cf3aa77df5e130fb023ce4dbc804b04bfcc560c6403e1ae6bdb')
28    ASSET_KERNEL_16K = Asset(
29        ('http://mipsdistros.mips.com/LinuxDistro/nanomips/'
30         'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
31         'generic_nano32r6el_page16k_up.xz'),
32        '3a54a10b3108c16a448dca9ea3db378733a27423befc2a45a5bdf990bd85e12c')
33    ASSET_KERNEL_64K = Asset(
34        ('http://mipsdistros.mips.com/LinuxDistro/nanomips/'
35         'kernels/v4.15.18-432-gb2eb9a8b07a1-20180627102142/'
36         'generic_nano32r6el_page64k_dbg.xz'),
37        'ce21ff4b07a981ecb8a39db2876616f5a2473eb2ab459c6f67465b9914b0c6b6')
38
39    def do_test_mips_malta32el_nanomips(self, kernel_path_xz):
40        kernel_path = os.path.join(self.workdir, 'kernel')
41        lzma_uncompress(kernel_path_xz, kernel_path)
42
43        self.set_machine('malta')
44        self.vm.set_console()
45        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
46                               + 'mem=256m@@0x0 '
47                               + 'console=ttyS0')
48        self.vm.add_args('-cpu', 'I7200',
49                         '-no-reboot',
50                         '-kernel', kernel_path,
51                         '-append', kernel_command_line)
52        self.vm.launch()
53        console_pattern = 'Kernel command line: %s' % kernel_command_line
54        self.wait_for_console_pattern(console_pattern)
55
56    def test_mips_malta32el_nanomips_4k(self):
57        kernel_path_xz = self.ASSET_KERNEL_4K.fetch()
58        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
59
60    def test_mips_malta32el_nanomips_16k_up(self):
61        kernel_path_xz = self.ASSET_KERNEL_16K.fetch()
62        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
63
64    def test_mips_malta32el_nanomips_64k_dbg(self):
65        kernel_path_xz = self.ASSET_KERNEL_16K.fetch()
66        self.do_test_mips_malta32el_nanomips(kernel_path_xz)
67
68
69class MaltaMachineYAMON(QemuSystemTest):
70
71    ASSET_YAMON_ROM = Asset(
72        ('https://s3-eu-west-1.amazonaws.com/downloads-mips/mips-downloads/'
73         'YAMON/yamon-bin-02.22.zip'),
74        'eef86f0eed0ef554f041dcd47b87eebea0e6f9f1184ed31f7e9e8b4a803860ab')
75
76    def test_mipsel_malta_yamon(self):
77        yamon_bin = 'yamon-02.22.bin'
78        zip_path = self.ASSET_YAMON_ROM.fetch()
79        with ZipFile(zip_path, 'r') as zf:
80            zf.extract(yamon_bin, path=self.workdir)
81        yamon_path = os.path.join(self.workdir, yamon_bin)
82
83        self.set_machine('malta')
84        self.vm.set_console()
85        self.vm.add_args('-bios', yamon_path)
86        self.vm.launch()
87
88        prompt =  'YAMON>'
89        pattern = 'YAMON ROM Monitor'
90        interrupt_interactive_console_until_pattern(self, pattern, prompt)
91        wait_for_console_pattern(self, prompt)
92        self.vm.shutdown()
93
94
95if __name__ == '__main__':
96    QemuSystemTest.main()
97