1#!/usr/bin/env python3 2# 3# Functional tests for the little-endian 64-bit MIPS Malta board 4# 5# Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org> 6# 7# This work is licensed under the terms of the GNU GPL, version 2 or later. 8# See the COPYING file in the top-level directory. 9# 10# SPDX-License-Identifier: GPL-2.0-or-later 11 12import os 13import logging 14 15from qemu_test import LinuxKernelTest, Asset 16from qemu_test import exec_command_and_wait_for_pattern 17from qemu_test import skipIfMissingImports, skipFlakyTest, skipUntrustedTest 18from qemu_test.utils import gzip_uncompress 19 20 21class MaltaMachineConsole(LinuxKernelTest): 22 23 ASSET_KERNEL_2_63_2 = Asset( 24 ('http://snapshot.debian.org/archive/debian/' 25 '20130217T032700Z/pool/main/l/linux-2.6/' 26 'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb'), 27 '35eb476f03be589824b0310358f1c447d85e645b88cbcd2ac02b97ef560f9f8d') 28 29 def test_mips64el_malta(self): 30 """ 31 This test requires the ar tool to extract "data.tar.gz" from 32 the Debian package. 33 34 The kernel can be rebuilt using this Debian kernel source [1] and 35 following the instructions on [2]. 36 37 [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/ 38 #linux-source-2.6.32_2.6.32-48 39 [2] https://kernel-team.pages.debian.net/kernel-handbook/ 40 ch-common-tasks.html#s-common-official 41 """ 42 deb_path = self.ASSET_KERNEL_2_63_2.fetch() 43 kernel_path = self.extract_from_deb(deb_path, 44 '/boot/vmlinux-2.6.32-5-5kc-malta') 45 46 self.set_machine('malta') 47 self.vm.set_console() 48 kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0' 49 self.vm.add_args('-kernel', kernel_path, 50 '-append', kernel_command_line) 51 self.vm.launch() 52 console_pattern = 'Kernel command line: %s' % kernel_command_line 53 self.wait_for_console_pattern(console_pattern) 54 55 ASSET_KERNEL_3_19_3 = Asset( 56 ('https://github.com/philmd/qemu-testing-blob/' 57 'raw/9ad2df38/mips/malta/mips64el/' 58 'vmlinux-3.19.3.mtoman.20150408'), 59 '8d3beb003bc66051ead98e7172139017fcf9ce2172576541c57e86418dfa5ab8') 60 61 ASSET_CPIO_R1 = Asset( 62 ('https://github.com/groeck/linux-build-test/' 63 'raw/8584a59e/rootfs/mipsel64/' 64 'rootfs.mipsel64r1.cpio.gz'), 65 '75ba10cd35fb44e32948eeb26974f061b703c81c4ba2fab1ebcacf1d1bec3b61') 66 67 @skipUntrustedTest() 68 def test_mips64el_malta_5KEc_cpio(self): 69 kernel_path = self.ASSET_KERNEL_3_19_3.fetch() 70 initrd_path_gz = self.ASSET_CPIO_R1.fetch() 71 initrd_path = os.path.join(self.workdir, 'rootfs.cpio') 72 gzip_uncompress(initrd_path_gz, initrd_path) 73 74 self.set_machine('malta') 75 self.vm.set_console() 76 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE 77 + 'console=ttyS0 console=tty ' 78 + 'rdinit=/sbin/init noreboot') 79 self.vm.add_args('-cpu', '5KEc', 80 '-kernel', kernel_path, 81 '-initrd', initrd_path, 82 '-append', kernel_command_line, 83 '-no-reboot') 84 self.vm.launch() 85 self.wait_for_console_pattern('Boot successful.') 86 87 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 88 'MIPS 5KE') 89 exec_command_and_wait_for_pattern(self, 'uname -a', 90 '3.19.3.mtoman.20150408') 91 exec_command_and_wait_for_pattern(self, 'reboot', 92 'reboot: Restarting system') 93 # Wait for VM to shut down gracefully 94 self.vm.wait() 95 96 97@skipIfMissingImports('numpy', 'cv2') 98class MaltaMachineFramebuffer(LinuxKernelTest): 99 100 timeout = 30 101 102 ASSET_KERNEL_4_7_0 = Asset( 103 ('https://github.com/philmd/qemu-testing-blob/raw/a5966ca4b5/' 104 'mips/malta/mips64el/vmlinux-4.7.0-rc1.I6400.gz'), 105 '1f64efc59968a3c328672e6b10213fe574bb2308d9d2ed44e75e40be59e9fbc2') 106 107 ASSET_TUXLOGO = Asset( 108 ('https://github.com/torvalds/linux/raw/v2.6.12/' 109 'drivers/video/logo/logo_linux_vga16.ppm'), 110 'b762f0d91ec018887ad1b334543c2fdf9be9fdfc87672b409211efaa3ea0ef79') 111 112 def do_test_i6400_framebuffer_logo(self, cpu_cores_count): 113 """ 114 Boot Linux kernel and check Tux logo is displayed on the framebuffer. 115 """ 116 117 import numpy as np 118 import cv2 119 120 screendump_path = os.path.join(self.workdir, 'screendump.pbm') 121 122 kernel_path_gz = self.ASSET_KERNEL_4_7_0.fetch() 123 kernel_path = self.workdir + "/vmlinux" 124 gzip_uncompress(kernel_path_gz, kernel_path) 125 126 tuxlogo_path = self.ASSET_TUXLOGO.fetch() 127 128 self.set_machine('malta') 129 self.vm.set_console() 130 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 131 'clocksource=GIC console=tty0 console=ttyS0') 132 self.vm.add_args('-kernel', kernel_path, 133 '-cpu', 'I6400', 134 '-smp', '%u' % cpu_cores_count, 135 '-vga', 'std', 136 '-append', kernel_command_line) 137 self.vm.launch() 138 framebuffer_ready = 'Console: switching to colour frame buffer device' 139 self.wait_for_console_pattern(framebuffer_ready) 140 self.vm.cmd('human-monitor-command', command_line='stop') 141 self.vm.cmd('human-monitor-command', 142 command_line='screendump %s' % screendump_path) 143 logger = logging.getLogger('framebuffer') 144 145 match_threshold = 0.95 146 screendump_bgr = cv2.imread(screendump_path, cv2.IMREAD_COLOR) 147 tuxlogo_bgr = cv2.imread(tuxlogo_path, cv2.IMREAD_COLOR) 148 result = cv2.matchTemplate(screendump_bgr, tuxlogo_bgr, 149 cv2.TM_CCOEFF_NORMED) 150 loc = np.where(result >= match_threshold) 151 tuxlogo_count = 0 152 h, w = tuxlogo_bgr.shape[:2] 153 debug_png = os.getenv('QEMU_TEST_CV2_SCREENDUMP_PNG_PATH') 154 for tuxlogo_count, pt in enumerate(zip(*loc[::-1]), start=1): 155 logger.debug('found Tux at position (x, y) = %s', pt) 156 cv2.rectangle(screendump_bgr, pt, 157 (pt[0] + w, pt[1] + h), (0, 0, 255), 2) 158 if debug_png: 159 cv2.imwrite(debug_png, screendump_bgr) 160 self.assertGreaterEqual(tuxlogo_count, cpu_cores_count) 161 162 def test_mips_malta_i6400_framebuffer_logo_1core(self): 163 self.do_test_i6400_framebuffer_logo(1) 164 165 # XXX file tracking bug 166 @skipFlakyTest(bug_url=None) 167 def test_mips_malta_i6400_framebuffer_logo_7cores(self): 168 self.do_test_i6400_framebuffer_logo(7) 169 170 @skipFlakyTest(bug_url=None) 171 def test_mips_malta_i6400_framebuffer_logo_8cores(self): 172 self.do_test_i6400_framebuffer_logo(8) 173 174 175from test_mipsel_malta import MaltaMachineYAMON 176 177if __name__ == '__main__': 178 LinuxKernelTest.main() 179