xref: /qemu/tests/functional/test_mips_malta.py (revision 42a87f0ce7aaf1923a610cabe4d65f7b1ce9a327)
179cb4a14SPhilippe Mathieu-Daudé#!/usr/bin/env python3
279cb4a14SPhilippe Mathieu-Daudé#
3c8b2deb9SThomas Huth# Functional tests for the big-endian 32-bit MIPS Malta board
479cb4a14SPhilippe Mathieu-Daudé#
579cb4a14SPhilippe Mathieu-Daudé# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
679cb4a14SPhilippe Mathieu-Daudé#
779cb4a14SPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-or-later
879cb4a14SPhilippe Mathieu-Daudé
9*42a87f0cSThomas Huthimport os
10*42a87f0cSThomas Huth
11*42a87f0cSThomas Huthfrom qemu_test import LinuxKernelTest, Asset, wait_for_console_pattern
1279cb4a14SPhilippe Mathieu-Daudéfrom qemu_test import exec_command_and_wait_for_pattern
1379cb4a14SPhilippe Mathieu-Daudé
1479cb4a14SPhilippe Mathieu-Daudé
15*42a87f0cSThomas Huthdef mips_run_common_commands(test, prompt='#'):
16*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
17*42a87f0cSThomas Huth        'uname -m',
18*42a87f0cSThomas Huth        'mips')
19*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
20*42a87f0cSThomas Huth        'grep XT-PIC /proc/interrupts',
21*42a87f0cSThomas Huth        'timer')
22*42a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
23*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
24*42a87f0cSThomas Huth        'grep XT-PIC /proc/interrupts',
25*42a87f0cSThomas Huth        'serial')
26*42a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
27*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
28*42a87f0cSThomas Huth        'grep XT-PIC /proc/interrupts',
29*42a87f0cSThomas Huth        'ata_piix')
30*42a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
31*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
32*42a87f0cSThomas Huth        'grep XT-PIC /proc/interrupts',
33*42a87f0cSThomas Huth        'rtc')
34*42a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
35*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
36*42a87f0cSThomas Huth        'cat /proc/devices',
37*42a87f0cSThomas Huth        'input')
38*42a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
39*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
40*42a87f0cSThomas Huth        'cat /proc/devices',
41*42a87f0cSThomas Huth        'fb')
42*42a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
43*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
44*42a87f0cSThomas Huth        'cat /proc/ioports',
45*42a87f0cSThomas Huth        ' : serial')
46*42a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
47*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
48*42a87f0cSThomas Huth        'cat /proc/ioports',
49*42a87f0cSThomas Huth        ' : ata_piix')
50*42a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
51*42a87f0cSThomas Huth
52*42a87f0cSThomas Huthdef mips_check_wheezy(test, kernel_path, image_path, kernel_command_line,
53*42a87f0cSThomas Huth                      dl_file, hsum, nic='pcnet', cpuinfo='MIPS 24Kc'):
54*42a87f0cSThomas Huth    test.require_netdev('user')
55*42a87f0cSThomas Huth    test.require_device(nic)
56*42a87f0cSThomas Huth    test.set_machine('malta')
57*42a87f0cSThomas Huth
58*42a87f0cSThomas Huth    port=8080
59*42a87f0cSThomas Huth    test.vm.add_args('-kernel', kernel_path,
60*42a87f0cSThomas Huth                     '-append', kernel_command_line,
61*42a87f0cSThomas Huth                     '-drive', 'file=%s,snapshot=on' % image_path,
62*42a87f0cSThomas Huth                     '-netdev', 'user,id=n1' +
63*42a87f0cSThomas Huth                                ',tftp=' + os.path.basename(kernel_path) +
64*42a87f0cSThomas Huth                                ',hostfwd=tcp:127.0.0.1:0-:%d' % port,
65*42a87f0cSThomas Huth                     '-device', f'{nic},netdev=n1',
66*42a87f0cSThomas Huth                     '-no-reboot')
67*42a87f0cSThomas Huth    test.vm.set_console()
68*42a87f0cSThomas Huth    test.vm.launch()
69*42a87f0cSThomas Huth
70*42a87f0cSThomas Huth    wait_for_console_pattern(test, 'login: ', 'Oops')
71*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'root', 'Password:')
72*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'root', ':~# ')
73*42a87f0cSThomas Huth    mips_run_common_commands(test)
74*42a87f0cSThomas Huth
75*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cd /', '# ')
76*42a87f0cSThomas Huth    test.check_http_download(dl_file, hsum, port,
77*42a87f0cSThomas Huth                             pythoncmd='python -m SimpleHTTPServer')
78*42a87f0cSThomas Huth
79*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cat /proc/cpuinfo', cpuinfo)
80*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cat /proc/devices', 'usb')
81*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cat /proc/ioports',
82*42a87f0cSThomas Huth                                      ' : piix4_smbus')
83*42a87f0cSThomas Huth    # lspci for the host bridge does not work on big endian targets:
84*42a87f0cSThomas Huth    # https://gitlab.com/qemu-project/qemu/-/issues/2826
85*42a87f0cSThomas Huth    # exec_command_and_wait_for_pattern(test, 'lspci -d 11ab:4620',
86*42a87f0cSThomas Huth    #                                   'GT-64120')
87*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
88*42a87f0cSThomas Huth                                      'cat /sys/bus/i2c/devices/i2c-0/name',
89*42a87f0cSThomas Huth                                      'SMBus PIIX4 adapter')
90*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cat /proc/mtd', 'YAMON')
91*42a87f0cSThomas Huth    # Empty 'Board Config' (64KB)
92*42a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'md5sum /dev/mtd2ro',
93*42a87f0cSThomas Huth                                      '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
94*42a87f0cSThomas Huth
95*42a87f0cSThomas Huth
9679cb4a14SPhilippe Mathieu-Daudéclass MaltaMachineConsole(LinuxKernelTest):
9779cb4a14SPhilippe Mathieu-Daudé
9879cb4a14SPhilippe Mathieu-Daudé    ASSET_KERNEL_2_63_2 = Asset(
9979cb4a14SPhilippe Mathieu-Daudé        ('http://snapshot.debian.org/archive/debian/'
10079cb4a14SPhilippe Mathieu-Daudé         '20130217T032700Z/pool/main/l/linux-2.6/'
10179cb4a14SPhilippe Mathieu-Daudé         'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb'),
10279cb4a14SPhilippe Mathieu-Daudé        '16ca524148afb0626f483163e5edf352bc1ab0e4fc7b9f9d473252762f2c7a43')
10379cb4a14SPhilippe Mathieu-Daudé
10479cb4a14SPhilippe Mathieu-Daudé    def test_mips_malta(self):
1055831ed84SDaniel P. Berrangé        kernel_path = self.archive_extract(
1065831ed84SDaniel P. Berrangé            self.ASSET_KERNEL_2_63_2,
1075831ed84SDaniel P. Berrangé            member='boot/vmlinux-2.6.32-5-4kc-malta')
10879cb4a14SPhilippe Mathieu-Daudé
10979cb4a14SPhilippe Mathieu-Daudé        self.set_machine('malta')
11079cb4a14SPhilippe Mathieu-Daudé        self.vm.set_console()
11179cb4a14SPhilippe Mathieu-Daudé        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
11279cb4a14SPhilippe Mathieu-Daudé        self.vm.add_args('-kernel', kernel_path,
11379cb4a14SPhilippe Mathieu-Daudé                         '-append', kernel_command_line)
11479cb4a14SPhilippe Mathieu-Daudé        self.vm.launch()
11579cb4a14SPhilippe Mathieu-Daudé        console_pattern = 'Kernel command line: %s' % kernel_command_line
11679cb4a14SPhilippe Mathieu-Daudé        self.wait_for_console_pattern(console_pattern)
11779cb4a14SPhilippe Mathieu-Daudé
11879cb4a14SPhilippe Mathieu-Daudé    ASSET_KERNEL_4_5_0 = Asset(
11979cb4a14SPhilippe Mathieu-Daudé        ('http://snapshot.debian.org/archive/debian/'
12079cb4a14SPhilippe Mathieu-Daudé         '20160601T041800Z/pool/main/l/linux/'
12179cb4a14SPhilippe Mathieu-Daudé         'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb'),
12279cb4a14SPhilippe Mathieu-Daudé        '526b17d5889840888b76fc2c36a0ebde182c9b1410a3a1e68203c3b160eb2027')
12379cb4a14SPhilippe Mathieu-Daudé
12479cb4a14SPhilippe Mathieu-Daudé    ASSET_INITRD = Asset(
12579cb4a14SPhilippe Mathieu-Daudé        ('https://github.com/groeck/linux-build-test/raw/'
12679cb4a14SPhilippe Mathieu-Daudé         '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
12779cb4a14SPhilippe Mathieu-Daudé         'mips/rootfs.cpio.gz'),
12879cb4a14SPhilippe Mathieu-Daudé        'dcfe3a7fe3200da3a00d176b95caaa086495eb158f2bff64afc67d7e1eb2cddc')
12979cb4a14SPhilippe Mathieu-Daudé
13079cb4a14SPhilippe Mathieu-Daudé    def test_mips_malta_cpio(self):
1317b7f98efSThomas Huth        self.require_netdev('user')
1327b7f98efSThomas Huth        self.set_machine('malta')
1337b7f98efSThomas Huth        self.require_device('pcnet')
1347b7f98efSThomas Huth
1355831ed84SDaniel P. Berrangé        kernel_path = self.archive_extract(
1365831ed84SDaniel P. Berrangé            self.ASSET_KERNEL_4_5_0,
1375831ed84SDaniel P. Berrangé            member='boot/vmlinux-4.5.0-2-4kc-malta')
13865d35a4eSDaniel P. Berrangé        initrd_path = self.uncompress(self.ASSET_INITRD)
13979cb4a14SPhilippe Mathieu-Daudé
14079cb4a14SPhilippe Mathieu-Daudé        self.vm.set_console()
14179cb4a14SPhilippe Mathieu-Daudé        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
14279cb4a14SPhilippe Mathieu-Daudé                               + 'console=ttyS0 console=tty '
14379cb4a14SPhilippe Mathieu-Daudé                               + 'rdinit=/sbin/init noreboot')
14479cb4a14SPhilippe Mathieu-Daudé        self.vm.add_args('-kernel', kernel_path,
14579cb4a14SPhilippe Mathieu-Daudé                         '-initrd', initrd_path,
14679cb4a14SPhilippe Mathieu-Daudé                         '-append', kernel_command_line,
1477b7f98efSThomas Huth                         '-netdev', 'user,id=n1,tftp=' + self.scratch_file('boot'),
1487b7f98efSThomas Huth                         '-device', 'pcnet,netdev=n1',
14979cb4a14SPhilippe Mathieu-Daudé                         '-no-reboot')
15079cb4a14SPhilippe Mathieu-Daudé        self.vm.launch()
15179cb4a14SPhilippe Mathieu-Daudé        self.wait_for_console_pattern('Boot successful.')
15279cb4a14SPhilippe Mathieu-Daudé
15379cb4a14SPhilippe Mathieu-Daudé        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
15479cb4a14SPhilippe Mathieu-Daudé                                                'BogoMIPS')
15579cb4a14SPhilippe Mathieu-Daudé        exec_command_and_wait_for_pattern(self, 'uname -a',
156*42a87f0cSThomas Huth                                                '4.5.0-2-4kc-malta #1 Debian')
157*42a87f0cSThomas Huth        mips_run_common_commands(self)
1587b7f98efSThomas Huth
1597b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self, 'ip link set eth0 up',
1607b7f98efSThomas Huth                                          'eth0: link up')
1617b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self,
1627b7f98efSThomas Huth                                          'ip addr add 10.0.2.15 dev eth0',
1637b7f98efSThomas Huth                                          '#')
1647b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self, 'route add default eth0', '#')
1657b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self,
1667b7f98efSThomas Huth                         'tftp -g -r vmlinux-4.5.0-2-4kc-malta 10.0.2.2', '#')
1677b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self,
1687b7f98efSThomas Huth                                          'md5sum vmlinux-4.5.0-2-4kc-malta',
1697b7f98efSThomas Huth                                          'a98218a7efbdefb2dfdf9ecd08c98318')
1707b7f98efSThomas Huth
17179cb4a14SPhilippe Mathieu-Daudé        exec_command_and_wait_for_pattern(self, 'reboot',
17279cb4a14SPhilippe Mathieu-Daudé                                                'reboot: Restarting system')
17379cb4a14SPhilippe Mathieu-Daudé        # Wait for VM to shut down gracefully
17479cb4a14SPhilippe Mathieu-Daudé        self.vm.wait()
17579cb4a14SPhilippe Mathieu-Daudé
176*42a87f0cSThomas Huth    ASSET_WHEEZY_KERNEL = Asset(
177*42a87f0cSThomas Huth        ('https://people.debian.org/~aurel32/qemu/mips/'
178*42a87f0cSThomas Huth         'vmlinux-3.2.0-4-4kc-malta'),
179*42a87f0cSThomas Huth        '0377fcda31299213c10b8e5babe7260ef99188b3ae1aca6f56594abb71e7f67e')
180*42a87f0cSThomas Huth
181*42a87f0cSThomas Huth    ASSET_WHEEZY_DISK = Asset(
182*42a87f0cSThomas Huth        ('https://people.debian.org/~aurel32/qemu/mips/'
183*42a87f0cSThomas Huth         'debian_wheezy_mips_standard.qcow2'),
184*42a87f0cSThomas Huth        'de03599285b8382ad309309a6c4869f6c6c42a5cfc983342bab9ec0dfa7849a2')
185*42a87f0cSThomas Huth
186*42a87f0cSThomas Huth    def test_wheezy(self):
187*42a87f0cSThomas Huth        kernel_path = self.ASSET_WHEEZY_KERNEL.fetch()
188*42a87f0cSThomas Huth        image_path = self.ASSET_WHEEZY_DISK.fetch()
189*42a87f0cSThomas Huth        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
190*42a87f0cSThomas Huth                               + 'console=ttyS0 root=/dev/sda1')
191*42a87f0cSThomas Huth        mips_check_wheezy(self,
192*42a87f0cSThomas Huth            kernel_path, image_path, kernel_command_line, nic='e1000',
193*42a87f0cSThomas Huth            dl_file='/boot/initrd.img-3.2.0-4-4kc-malta',
194*42a87f0cSThomas Huth            hsum='ff0c0369143d9bbb9a6e6bc79322a2be535619df639e84103237f406e87493dc')
195*42a87f0cSThomas Huth
19679cb4a14SPhilippe Mathieu-Daudé
19779cb4a14SPhilippe Mathieu-Daudéif __name__ == '__main__':
19879cb4a14SPhilippe Mathieu-Daudé    LinuxKernelTest.main()
199