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 # lspci for the host bridge does not work on big endian targets: 84 # https://gitlab.com/qemu-project/qemu/-/issues/2826 85 # exec_command_and_wait_for_pattern(test, 'lspci -d 11ab:4620', 86 # 'GT-64120') 87 exec_command_and_wait_for_pattern(test, 88 'cat /sys/bus/i2c/devices/i2c-0/name', 89 'SMBus PIIX4 adapter') 90 exec_command_and_wait_for_pattern(test, 'cat /proc/mtd', 'YAMON') 91 # Empty 'Board Config' (64KB) 92 exec_command_and_wait_for_pattern(test, 'md5sum /dev/mtd2ro', 93 '0dfbe8aa4c20b52e1b8bf3cb6cbdf193') 94 95 96class MaltaMachineConsole(LinuxKernelTest): 97 98 ASSET_KERNEL_2_63_2 = Asset( 99 ('http://snapshot.debian.org/archive/debian/' 100 '20130217T032700Z/pool/main/l/linux-2.6/' 101 'linux-image-2.6.32-5-4kc-malta_2.6.32-48_mips.deb'), 102 '16ca524148afb0626f483163e5edf352bc1ab0e4fc7b9f9d473252762f2c7a43') 103 104 def test_mips_malta(self): 105 kernel_path = self.archive_extract( 106 self.ASSET_KERNEL_2_63_2, 107 member='boot/vmlinux-2.6.32-5-4kc-malta') 108 109 self.set_machine('malta') 110 self.vm.set_console() 111 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 112 self.vm.add_args('-kernel', kernel_path, 113 '-append', kernel_command_line) 114 self.vm.launch() 115 console_pattern = 'Kernel command line: %s' % kernel_command_line 116 self.wait_for_console_pattern(console_pattern) 117 118 ASSET_KERNEL_4_5_0 = Asset( 119 ('http://snapshot.debian.org/archive/debian/' 120 '20160601T041800Z/pool/main/l/linux/' 121 'linux-image-4.5.0-2-4kc-malta_4.5.5-1_mips.deb'), 122 '526b17d5889840888b76fc2c36a0ebde182c9b1410a3a1e68203c3b160eb2027') 123 124 ASSET_INITRD = Asset( 125 ('https://github.com/groeck/linux-build-test/raw/' 126 '8584a59ed9e5eb5ee7ca91f6d74bbb06619205b8/rootfs/' 127 'mips/rootfs.cpio.gz'), 128 'dcfe3a7fe3200da3a00d176b95caaa086495eb158f2bff64afc67d7e1eb2cddc') 129 130 def test_mips_malta_cpio(self): 131 self.require_netdev('user') 132 self.set_machine('malta') 133 self.require_device('pcnet') 134 135 kernel_path = self.archive_extract( 136 self.ASSET_KERNEL_4_5_0, 137 member='boot/vmlinux-4.5.0-2-4kc-malta') 138 initrd_path = self.uncompress(self.ASSET_INITRD) 139 140 self.vm.set_console() 141 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 142 + 'console=ttyS0 console=tty ' 143 + 'rdinit=/sbin/init noreboot') 144 self.vm.add_args('-kernel', kernel_path, 145 '-initrd', initrd_path, 146 '-append', kernel_command_line, 147 '-netdev', 'user,id=n1,tftp=' + self.scratch_file('boot'), 148 '-device', 'pcnet,netdev=n1', 149 '-no-reboot') 150 self.vm.launch() 151 self.wait_for_console_pattern('Boot successful.') 152 153 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 154 'BogoMIPS') 155 exec_command_and_wait_for_pattern(self, 'uname -a', 156 '4.5.0-2-4kc-malta #1 Debian') 157 mips_run_common_commands(self) 158 159 exec_command_and_wait_for_pattern(self, 'ip link set eth0 up', 160 'eth0: link up') 161 exec_command_and_wait_for_pattern(self, 162 'ip addr add 10.0.2.15 dev eth0', 163 '#') 164 exec_command_and_wait_for_pattern(self, 'route add default eth0', '#') 165 exec_command_and_wait_for_pattern(self, 166 'tftp -g -r vmlinux-4.5.0-2-4kc-malta 10.0.2.2', '#') 167 exec_command_and_wait_for_pattern(self, 168 'md5sum vmlinux-4.5.0-2-4kc-malta', 169 'a98218a7efbdefb2dfdf9ecd08c98318') 170 171 exec_command_and_wait_for_pattern(self, 'reboot', 172 'reboot: Restarting system') 173 # Wait for VM to shut down gracefully 174 self.vm.wait() 175 176 ASSET_WHEEZY_KERNEL = Asset( 177 ('https://people.debian.org/~aurel32/qemu/mips/' 178 'vmlinux-3.2.0-4-4kc-malta'), 179 '0377fcda31299213c10b8e5babe7260ef99188b3ae1aca6f56594abb71e7f67e') 180 181 ASSET_WHEEZY_DISK = Asset( 182 ('https://people.debian.org/~aurel32/qemu/mips/' 183 'debian_wheezy_mips_standard.qcow2'), 184 'de03599285b8382ad309309a6c4869f6c6c42a5cfc983342bab9ec0dfa7849a2') 185 186 def test_wheezy(self): 187 kernel_path = self.ASSET_WHEEZY_KERNEL.fetch() 188 image_path = self.ASSET_WHEEZY_DISK.fetch() 189 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 190 + 'console=ttyS0 root=/dev/sda1') 191 mips_check_wheezy(self, 192 kernel_path, image_path, kernel_command_line, nic='e1000', 193 dl_file='/boot/initrd.img-3.2.0-4-4kc-malta', 194 hsum='ff0c0369143d9bbb9a6e6bc79322a2be535619df639e84103237f406e87493dc') 195 196 197if __name__ == '__main__': 198 LinuxKernelTest.main() 199