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