xref: /qemu/tests/functional/test_mips_malta.py (revision 107215089da92427c4c1644d84f5437b7b6e5e9c)
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é
942a87f0cSThomas Huthimport os
1042a87f0cSThomas Huth
1142a87f0cSThomas 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é
1542a87f0cSThomas Huthdef mips_run_common_commands(test, prompt='#'):
1642a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
1742a87f0cSThomas Huth        'uname -m',
1842a87f0cSThomas Huth        'mips')
1942a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
2042a87f0cSThomas Huth        'grep XT-PIC /proc/interrupts',
2142a87f0cSThomas Huth        'timer')
2242a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
2342a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
2442a87f0cSThomas Huth        'grep XT-PIC /proc/interrupts',
2542a87f0cSThomas Huth        'serial')
2642a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
2742a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
2842a87f0cSThomas Huth        'grep XT-PIC /proc/interrupts',
2942a87f0cSThomas Huth        'ata_piix')
3042a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
3142a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
3242a87f0cSThomas Huth        'grep XT-PIC /proc/interrupts',
3342a87f0cSThomas Huth        'rtc')
3442a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
3542a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
3642a87f0cSThomas Huth        'cat /proc/devices',
3742a87f0cSThomas Huth        'input')
3842a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
3942a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
4042a87f0cSThomas Huth        'cat /proc/devices',
4142a87f0cSThomas Huth        'fb')
4242a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
4342a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
4442a87f0cSThomas Huth        'cat /proc/ioports',
4542a87f0cSThomas Huth        ' : serial')
4642a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
4742a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
4842a87f0cSThomas Huth        'cat /proc/ioports',
4942a87f0cSThomas Huth        ' : ata_piix')
5042a87f0cSThomas Huth    wait_for_console_pattern(test, prompt)
5142a87f0cSThomas Huth
5242a87f0cSThomas Huthdef mips_check_wheezy(test, kernel_path, image_path, kernel_command_line,
5342a87f0cSThomas Huth                      dl_file, hsum, nic='pcnet', cpuinfo='MIPS 24Kc'):
5442a87f0cSThomas Huth    test.require_netdev('user')
5542a87f0cSThomas Huth    test.require_device(nic)
5642a87f0cSThomas Huth    test.set_machine('malta')
5742a87f0cSThomas Huth
5842a87f0cSThomas Huth    port=8080
5942a87f0cSThomas Huth    test.vm.add_args('-kernel', kernel_path,
6042a87f0cSThomas Huth                     '-append', kernel_command_line,
6142a87f0cSThomas Huth                     '-drive', 'file=%s,snapshot=on' % image_path,
6242a87f0cSThomas Huth                     '-netdev', 'user,id=n1' +
6342a87f0cSThomas Huth                                ',tftp=' + os.path.basename(kernel_path) +
6442a87f0cSThomas Huth                                ',hostfwd=tcp:127.0.0.1:0-:%d' % port,
6542a87f0cSThomas Huth                     '-device', f'{nic},netdev=n1',
6642a87f0cSThomas Huth                     '-no-reboot')
6742a87f0cSThomas Huth    test.vm.set_console()
6842a87f0cSThomas Huth    test.vm.launch()
6942a87f0cSThomas Huth
7042a87f0cSThomas Huth    wait_for_console_pattern(test, 'login: ', 'Oops')
7142a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'root', 'Password:')
7242a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'root', ':~# ')
7342a87f0cSThomas Huth    mips_run_common_commands(test)
7442a87f0cSThomas Huth
7542a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cd /', '# ')
7642a87f0cSThomas Huth    test.check_http_download(dl_file, hsum, port,
7742a87f0cSThomas Huth                             pythoncmd='python -m SimpleHTTPServer')
7842a87f0cSThomas Huth
7942a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cat /proc/cpuinfo', cpuinfo)
8042a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cat /proc/devices', 'usb')
8142a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cat /proc/ioports',
8242a87f0cSThomas Huth                                      ' : piix4_smbus')
83*644ded5cSThomas Huth    exec_command_and_wait_for_pattern(test, 'lspci -d 11ab:4620',
84*644ded5cSThomas Huth                                      'GT-64120')
8542a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test,
8642a87f0cSThomas Huth                                      'cat /sys/bus/i2c/devices/i2c-0/name',
8742a87f0cSThomas Huth                                      'SMBus PIIX4 adapter')
8842a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'cat /proc/mtd', 'YAMON')
8942a87f0cSThomas Huth    # Empty 'Board Config' (64KB)
9042a87f0cSThomas Huth    exec_command_and_wait_for_pattern(test, 'md5sum /dev/mtd2ro',
9142a87f0cSThomas Huth                                      '0dfbe8aa4c20b52e1b8bf3cb6cbdf193')
9242a87f0cSThomas Huth
9342a87f0cSThomas Huth
9479cb4a14SPhilippe Mathieu-Daudéclass MaltaMachineConsole(LinuxKernelTest):
9579cb4a14SPhilippe Mathieu-Daudé
9679cb4a14SPhilippe Mathieu-Daudé    ASSET_KERNEL_2_63_2 = Asset(
9779cb4a14SPhilippe Mathieu-Daudé        ('http://snapshot.debian.org/archive/debian/'
9879cb4a14SPhilippe Mathieu-Daudé         '20130217T032700Z/pool/main/l/linux-2.6/'
9979cb4a14SPhilippe Mathieu-Daudé         'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb'),
10079cb4a14SPhilippe Mathieu-Daudé        '16ca524148afb0626f483163e5edf352bc1ab0e4fc7b9f9d473252762f2c7a43')
10179cb4a14SPhilippe Mathieu-Daudé
10279cb4a14SPhilippe Mathieu-Daudé    def test_mips_malta(self):
1035831ed84SDaniel P. Berrangé        kernel_path = self.archive_extract(
1045831ed84SDaniel P. Berrangé            self.ASSET_KERNEL_2_63_2,
1055831ed84SDaniel P. Berrangé            member='boot/vmlinux-2.6.32-5-4kc-malta')
10679cb4a14SPhilippe Mathieu-Daudé
10779cb4a14SPhilippe Mathieu-Daudé        self.set_machine('malta')
10879cb4a14SPhilippe Mathieu-Daudé        self.vm.set_console()
10979cb4a14SPhilippe Mathieu-Daudé        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
11079cb4a14SPhilippe Mathieu-Daudé        self.vm.add_args('-kernel', kernel_path,
11179cb4a14SPhilippe Mathieu-Daudé                         '-append', kernel_command_line)
11279cb4a14SPhilippe Mathieu-Daudé        self.vm.launch()
11379cb4a14SPhilippe Mathieu-Daudé        console_pattern = 'Kernel command line: %s' % kernel_command_line
11479cb4a14SPhilippe Mathieu-Daudé        self.wait_for_console_pattern(console_pattern)
11579cb4a14SPhilippe Mathieu-Daudé
11679cb4a14SPhilippe Mathieu-Daudé    ASSET_KERNEL_4_5_0 = Asset(
11779cb4a14SPhilippe Mathieu-Daudé        ('http://snapshot.debian.org/archive/debian/'
11879cb4a14SPhilippe Mathieu-Daudé         '20160601T041800Z/pool/main/l/linux/'
11979cb4a14SPhilippe Mathieu-Daudé         'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb'),
12079cb4a14SPhilippe Mathieu-Daudé        '526b17d5889840888b76fc2c36a0ebde182c9b1410a3a1e68203c3b160eb2027')
12179cb4a14SPhilippe Mathieu-Daudé
12279cb4a14SPhilippe Mathieu-Daudé    ASSET_INITRD = Asset(
12379cb4a14SPhilippe Mathieu-Daudé        ('https://github.com/groeck/linux-build-test/raw/'
12479cb4a14SPhilippe Mathieu-Daudé         '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/'
12579cb4a14SPhilippe Mathieu-Daudé         'mips/rootfs.cpio.gz'),
12679cb4a14SPhilippe Mathieu-Daudé        'dcfe3a7fe3200da3a00d176b95caaa086495eb158f2bff64afc67d7e1eb2cddc')
12779cb4a14SPhilippe Mathieu-Daudé
12879cb4a14SPhilippe Mathieu-Daudé    def test_mips_malta_cpio(self):
1297b7f98efSThomas Huth        self.require_netdev('user')
1307b7f98efSThomas Huth        self.set_machine('malta')
1317b7f98efSThomas Huth        self.require_device('pcnet')
1327b7f98efSThomas Huth
1335831ed84SDaniel P. Berrangé        kernel_path = self.archive_extract(
1345831ed84SDaniel P. Berrangé            self.ASSET_KERNEL_4_5_0,
1355831ed84SDaniel P. Berrangé            member='boot/vmlinux-4.5.0-2-4kc-malta')
13665d35a4eSDaniel P. Berrangé        initrd_path = self.uncompress(self.ASSET_INITRD)
13779cb4a14SPhilippe Mathieu-Daudé
13879cb4a14SPhilippe Mathieu-Daudé        self.vm.set_console()
13979cb4a14SPhilippe Mathieu-Daudé        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
14079cb4a14SPhilippe Mathieu-Daudé                               + 'console=ttyS0 console=tty '
14179cb4a14SPhilippe Mathieu-Daudé                               + 'rdinit=/sbin/init noreboot')
14279cb4a14SPhilippe Mathieu-Daudé        self.vm.add_args('-kernel', kernel_path,
14379cb4a14SPhilippe Mathieu-Daudé                         '-initrd', initrd_path,
14479cb4a14SPhilippe Mathieu-Daudé                         '-append', kernel_command_line,
1457b7f98efSThomas Huth                         '-netdev', 'user,id=n1,tftp=' + self.scratch_file('boot'),
1467b7f98efSThomas Huth                         '-device', 'pcnet,netdev=n1',
14779cb4a14SPhilippe Mathieu-Daudé                         '-no-reboot')
14879cb4a14SPhilippe Mathieu-Daudé        self.vm.launch()
14979cb4a14SPhilippe Mathieu-Daudé        self.wait_for_console_pattern('Boot successful.')
15079cb4a14SPhilippe Mathieu-Daudé
15179cb4a14SPhilippe Mathieu-Daudé        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
15279cb4a14SPhilippe Mathieu-Daudé                                                'BogoMIPS')
15379cb4a14SPhilippe Mathieu-Daudé        exec_command_and_wait_for_pattern(self, 'uname -a',
15442a87f0cSThomas Huth                                                '4.5.0-2-4kc-malta #1 Debian')
15542a87f0cSThomas Huth        mips_run_common_commands(self)
1567b7f98efSThomas Huth
1577b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self, 'ip link set eth0 up',
1587b7f98efSThomas Huth                                          'eth0: link up')
1597b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self,
1607b7f98efSThomas Huth                                          'ip addr add 10.0.2.15 dev eth0',
1617b7f98efSThomas Huth                                          '#')
1627b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self, 'route add default eth0', '#')
1637b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self,
1647b7f98efSThomas Huth                         'tftp -g -r vmlinux-4.5.0-2-4kc-malta 10.0.2.2', '#')
1657b7f98efSThomas Huth        exec_command_and_wait_for_pattern(self,
1667b7f98efSThomas Huth                                          'md5sum vmlinux-4.5.0-2-4kc-malta',
1677b7f98efSThomas Huth                                          'a98218a7efbdefb2dfdf9ecd08c98318')
1687b7f98efSThomas Huth
16979cb4a14SPhilippe Mathieu-Daudé        exec_command_and_wait_for_pattern(self, 'reboot',
17079cb4a14SPhilippe Mathieu-Daudé                                                'reboot: Restarting system')
17179cb4a14SPhilippe Mathieu-Daudé        # Wait for VM to shut down gracefully
17279cb4a14SPhilippe Mathieu-Daudé        self.vm.wait()
17379cb4a14SPhilippe Mathieu-Daudé
17442a87f0cSThomas Huth    ASSET_WHEEZY_KERNEL = Asset(
17542a87f0cSThomas Huth        ('https://people.debian.org/~aurel32/qemu/mips/'
17642a87f0cSThomas Huth         'vmlinux-3.2.0-4-4kc-malta'),
17742a87f0cSThomas Huth        '0377fcda31299213c10b8e5babe7260ef99188b3ae1aca6f56594abb71e7f67e')
17842a87f0cSThomas Huth
17942a87f0cSThomas Huth    ASSET_WHEEZY_DISK = Asset(
18042a87f0cSThomas Huth        ('https://people.debian.org/~aurel32/qemu/mips/'
18142a87f0cSThomas Huth         'debian_wheezy_mips_standard.qcow2'),
18242a87f0cSThomas Huth        'de03599285b8382ad309309a6c4869f6c6c42a5cfc983342bab9ec0dfa7849a2')
18342a87f0cSThomas Huth
18442a87f0cSThomas Huth    def test_wheezy(self):
18542a87f0cSThomas Huth        kernel_path = self.ASSET_WHEEZY_KERNEL.fetch()
18642a87f0cSThomas Huth        image_path = self.ASSET_WHEEZY_DISK.fetch()
18742a87f0cSThomas Huth        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
18842a87f0cSThomas Huth                               + 'console=ttyS0 root=/dev/sda1')
18942a87f0cSThomas Huth        mips_check_wheezy(self,
19042a87f0cSThomas Huth            kernel_path, image_path, kernel_command_line, nic='e1000',
19142a87f0cSThomas Huth            dl_file='/boot/initrd.img-3.2.0-4-4kc-malta',
19242a87f0cSThomas Huth            hsum='ff0c0369143d9bbb9a6e6bc79322a2be535619df639e84103237f406e87493dc')
19342a87f0cSThomas Huth
19479cb4a14SPhilippe Mathieu-Daudé
19579cb4a14SPhilippe Mathieu-Daudéif __name__ == '__main__':
19679cb4a14SPhilippe Mathieu-Daudé    LinuxKernelTest.main()
197