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# SPDX-License-Identifier: GPL-2.0-or-later
8
9import os
10
11from qemu_test import LinuxKernelTest, Asset
12from qemu_test import exec_command_and_wait_for_pattern
13from qemu_test.utils import gzip_uncompress
14
15
16class MaltaMachineConsole(LinuxKernelTest):
17
18    ASSET_KERNEL_2_63_2 = Asset(
19        ('http://snapshot.debian.org/archive/debian/'
20         '20130217T032700Z/pool/main/l/linux-2.6/'
21         'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb'),
22        '16ca524148afb0626f483163e5edf352bc1ab0e4fc7b9f9d473252762f2c7a43')
23
24    def test_mips_malta(self):
25        deb_path = self.ASSET_KERNEL_2_63_2.fetch()
26        kernel_path = self.extract_from_deb(deb_path,
27                                            '/boot/vmlinux-2.6.32-5-4kc-malta')
28
29        self.set_machine('malta')
30        self.vm.set_console()
31        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
32        self.vm.add_args('-kernel', kernel_path,
33                         '-append', kernel_command_line)
34        self.vm.launch()
35        console_pattern = 'Kernel command line: %s' % kernel_command_line
36        self.wait_for_console_pattern(console_pattern)
37
38    ASSET_KERNEL_4_5_0 = Asset(
39        ('http://snapshot.debian.org/archive/debian/'
40         '20160601T041800Z/pool/main/l/linux/'
41         'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb'),
42        '526b17d5889840888b76fc2c36a0ebde182c9b1410a3a1e68203c3b160eb2027')
43
44    ASSET_INITRD = Asset(
45        ('https://github.com/groeck/linux-build-test/raw/'
46         '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
47         'mips/rootfs.cpio.gz'),
48        'dcfe3a7fe3200da3a00d176b95caaa086495eb158f2bff64afc67d7e1eb2cddc')
49
50    def test_mips_malta_cpio(self):
51        deb_path = self.ASSET_KERNEL_4_5_0.fetch()
52        kernel_path = self.extract_from_deb(deb_path,
53                                            '/boot/vmlinux-4.5.0-2-4kc-malta')
54        initrd_path_gz = self.ASSET_INITRD.fetch()
55        initrd_path = os.path.join(self.workdir, 'rootfs.cpio')
56        gzip_uncompress(initrd_path_gz, initrd_path)
57
58        self.set_machine('malta')
59        self.vm.set_console()
60        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
61                               + 'console=ttyS0 console=tty '
62                               + 'rdinit=/sbin/init noreboot')
63        self.vm.add_args('-kernel', kernel_path,
64                         '-initrd', initrd_path,
65                         '-append', kernel_command_line,
66                         '-no-reboot')
67        self.vm.launch()
68        self.wait_for_console_pattern('Boot successful.')
69
70        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
71                                                'BogoMIPS')
72        exec_command_and_wait_for_pattern(self, 'uname -a',
73                                                'Debian')
74        exec_command_and_wait_for_pattern(self, 'reboot',
75                                                'reboot: Restarting system')
76        # Wait for VM to shut down gracefully
77        self.vm.wait()
78
79
80if __name__ == '__main__':
81    LinuxKernelTest.main()
82