xref: /qemu/tests/functional/test_mips_malta.py (revision 107215089da92427c4c1644d84f5437b7b6e5e9c)
1#!/usr/bin/env python3
2#
3# Functional tests for the big-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, wait_for_console_pattern
12from qemu_test import exec_command_and_wait_for_pattern
13
14
15def mips_run_common_commands(test, prompt='#'):
16    exec_command_and_wait_for_pattern(test,
17        'uname -m',
18        'mips')
19    exec_command_and_wait_for_pattern(test,
20        'grep XT-PIC /proc/interrupts',
21        'timer')
22    wait_for_console_pattern(test, prompt)
23    exec_command_and_wait_for_pattern(test,
24        'grep XT-PIC /proc/interrupts',
25        'serial')
26    wait_for_console_pattern(test, prompt)
27    exec_command_and_wait_for_pattern(test,
28        'grep XT-PIC /proc/interrupts',
29        'ata_piix')
30    wait_for_console_pattern(test, prompt)
31    exec_command_and_wait_for_pattern(test,
32        'grep XT-PIC /proc/interrupts',
33        'rtc')
34    wait_for_console_pattern(test, prompt)
35    exec_command_and_wait_for_pattern(test,
36        'cat /proc/devices',
37        'input')
38    wait_for_console_pattern(test, prompt)
39    exec_command_and_wait_for_pattern(test,
40        'cat /proc/devices',
41        'fb')
42    wait_for_console_pattern(test, prompt)
43    exec_command_and_wait_for_pattern(test,
44        'cat /proc/ioports',
45        ' : serial')
46    wait_for_console_pattern(test, prompt)
47    exec_command_and_wait_for_pattern(test,
48        'cat /proc/ioports',
49        ' : ata_piix')
50    wait_for_console_pattern(test, prompt)
51
52def mips_check_wheezy(test, kernel_path, image_path, kernel_command_line,
53                      dl_file, hsum, nic='pcnet', cpuinfo='MIPS 24Kc'):
54    test.require_netdev('user')
55    test.require_device(nic)
56    test.set_machine('malta')
57
58    port=8080
59    test.vm.add_args('-kernel', kernel_path,
60                     '-append', kernel_command_line,
61                     '-drive', 'file=%s,snapshot=on' % image_path,
62                     '-netdev', 'user,id=n1' +
63                                ',tftp=' + os.path.basename(kernel_path) +
64                                ',hostfwd=tcp:127.0.0.1:0-:%d' % port,
65                     '-device', f'{nic},netdev=n1',
66                     '-no-reboot')
67    test.vm.set_console()
68    test.vm.launch()
69
70    wait_for_console_pattern(test, 'login: ', 'Oops')
71    exec_command_and_wait_for_pattern(test, 'root', 'Password:')
72    exec_command_and_wait_for_pattern(test, 'root', ':~# ')
73    mips_run_common_commands(test)
74
75    exec_command_and_wait_for_pattern(test, 'cd /', '# ')
76    test.check_http_download(dl_file, hsum, port,
77                             pythoncmd='python -m SimpleHTTPServer')
78
79    exec_command_and_wait_for_pattern(test, 'cat /proc/cpuinfo', cpuinfo)
80    exec_command_and_wait_for_pattern(test, 'cat /proc/devices', 'usb')
81    exec_command_and_wait_for_pattern(test, 'cat /proc/ioports',
82                                      ' : piix4_smbus')
83    exec_command_and_wait_for_pattern(test, 'lspci -d 11ab:4620',
84                                      'GT-64120')
85    exec_command_and_wait_for_pattern(test,
86                                      'cat /sys/bus/i2c/devices/i2c-0/name',
87                                      'SMBus PIIX4 adapter')
88    exec_command_and_wait_for_pattern(test, 'cat /proc/mtd', 'YAMON')
89    # Empty 'Board Config' (64KB)
90    exec_command_and_wait_for_pattern(test, 'md5sum /dev/mtd2ro',
91                                      '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
92
93
94class MaltaMachineConsole(LinuxKernelTest):
95
96    ASSET_KERNEL_2_63_2 = Asset(
97        ('http://snapshot.debian.org/archive/debian/'
98         '20130217T032700Z/pool/main/l/linux-2.6/'
99         'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb'),
100        '16ca524148afb0626f483163e5edf352bc1ab0e4fc7b9f9d473252762f2c7a43')
101
102    def test_mips_malta(self):
103        kernel_path = self.archive_extract(
104            self.ASSET_KERNEL_2_63_2,
105            member='boot/vmlinux-2.6.32-5-4kc-malta')
106
107        self.set_machine('malta')
108        self.vm.set_console()
109        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
110        self.vm.add_args('-kernel', kernel_path,
111                         '-append', kernel_command_line)
112        self.vm.launch()
113        console_pattern = 'Kernel command line: %s' % kernel_command_line
114        self.wait_for_console_pattern(console_pattern)
115
116    ASSET_KERNEL_4_5_0 = Asset(
117        ('http://snapshot.debian.org/archive/debian/'
118         '20160601T041800Z/pool/main/l/linux/'
119         'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb'),
120        '526b17d5889840888b76fc2c36a0ebde182c9b1410a3a1e68203c3b160eb2027')
121
122    ASSET_INITRD = Asset(
123        ('https://github.com/groeck/linux-build-test/raw/'
124         '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
125         'mips/rootfs.cpio.gz'),
126        'dcfe3a7fe3200da3a00d176b95caaa086495eb158f2bff64afc67d7e1eb2cddc')
127
128    def test_mips_malta_cpio(self):
129        self.require_netdev('user')
130        self.set_machine('malta')
131        self.require_device('pcnet')
132
133        kernel_path = self.archive_extract(
134            self.ASSET_KERNEL_4_5_0,
135            member='boot/vmlinux-4.5.0-2-4kc-malta')
136        initrd_path = self.uncompress(self.ASSET_INITRD)
137
138        self.vm.set_console()
139        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
140                               + 'console=ttyS0 console=tty '
141                               + 'rdinit=/sbin/init noreboot')
142        self.vm.add_args('-kernel', kernel_path,
143                         '-initrd', initrd_path,
144                         '-append', kernel_command_line,
145                         '-netdev', 'user,id=n1,tftp=' + self.scratch_file('boot'),
146                         '-device', 'pcnet,netdev=n1',
147                         '-no-reboot')
148        self.vm.launch()
149        self.wait_for_console_pattern('Boot successful.')
150
151        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
152                                                'BogoMIPS')
153        exec_command_and_wait_for_pattern(self, 'uname -a',
154                                                '4.5.0-2-4kc-malta #1 Debian')
155        mips_run_common_commands(self)
156
157        exec_command_and_wait_for_pattern(self, 'ip link set eth0 up',
158                                          'eth0: link up')
159        exec_command_and_wait_for_pattern(self,
160                                          'ip addr add 10.0.2.15 dev eth0',
161                                          '#')
162        exec_command_and_wait_for_pattern(self, 'route add default eth0', '#')
163        exec_command_and_wait_for_pattern(self,
164                         'tftp -g -r vmlinux-4.5.0-2-4kc-malta 10.0.2.2', '#')
165        exec_command_and_wait_for_pattern(self,
166                                          'md5sum vmlinux-4.5.0-2-4kc-malta',
167                                          'a98218a7efbdefb2dfdf9ecd08c98318')
168
169        exec_command_and_wait_for_pattern(self, 'reboot',
170                                                'reboot: Restarting system')
171        # Wait for VM to shut down gracefully
172        self.vm.wait()
173
174    ASSET_WHEEZY_KERNEL = Asset(
175        ('https://people.debian.org/~aurel32/qemu/mips/'
176         'vmlinux-3.2.0-4-4kc-malta'),
177        '0377fcda31299213c10b8e5babe7260ef99188b3ae1aca6f56594abb71e7f67e')
178
179    ASSET_WHEEZY_DISK = Asset(
180        ('https://people.debian.org/~aurel32/qemu/mips/'
181         'debian_wheezy_mips_standard.qcow2'),
182        'de03599285b8382ad309309a6c4869f6c6c42a5cfc983342bab9ec0dfa7849a2')
183
184    def test_wheezy(self):
185        kernel_path = self.ASSET_WHEEZY_KERNEL.fetch()
186        image_path = self.ASSET_WHEEZY_DISK.fetch()
187        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
188                               + 'console=ttyS0 root=/dev/sda1')
189        mips_check_wheezy(self,
190            kernel_path, image_path, kernel_command_line, nic='e1000',
191            dl_file='/boot/initrd.img-3.2.0-4-4kc-malta',
192            hsum='ff0c0369143d9bbb9a6e6bc79322a2be535619df639e84103237f406e87493dc')
193
194
195if __name__ == '__main__':
196    LinuxKernelTest.main()
197