xref: /qemu/tests/functional/test_mips64el_malta.py (revision 92fbc2ffc92f387c2ccb00b38ac800ca924c079a)
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
18
19from test_mips_malta import mips_check_wheezy
20
21
22class MaltaMachineConsole(LinuxKernelTest):
23
24    ASSET_KERNEL_2_63_2 = Asset(
25        ('http://snapshot.debian.org/archive/debian/'
26         '20130217T032700Z/pool/main/l/linux-2.6/'
27         'linux-image-2.6.32-5-5kc-malta_2.6.32-48_mipsel.deb'),
28        '35eb476f03be589824b0310358f1c447d85e645b88cbcd2ac02b97ef560f9f8d')
29
30    def test_mips64el_malta(self):
31        """
32        This test requires the ar tool to extract "data.tar.gz" from
33        the Debian package.
34
35        The kernel can be rebuilt using this Debian kernel source [1] and
36        following the instructions on [2].
37
38        [1] http://snapshot.debian.org/package/linux-2.6/2.6.32-48/
39            #linux-source-2.6.32_2.6.32-48
40        [2] https://kernel-team.pages.debian.net/kernel-handbook/
41            ch-common-tasks.html#s-common-official
42        """
43        kernel_path = self.archive_extract(
44            self.ASSET_KERNEL_2_63_2,
45            member='boot/vmlinux-2.6.32-5-5kc-malta')
46
47        self.set_machine('malta')
48        self.vm.set_console()
49        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'console=ttyS0'
50        self.vm.add_args('-kernel', kernel_path,
51                         '-append', kernel_command_line)
52        self.vm.launch()
53        console_pattern = 'Kernel command line: %s' % kernel_command_line
54        self.wait_for_console_pattern(console_pattern)
55
56    ASSET_KERNEL_3_19_3 = Asset(
57        ('https://github.com/philmd/qemu-testing-blob/'
58         'raw/9ad2df38/mips/malta/mips64el/'
59         'vmlinux-3.19.3.mtoman.20150408'),
60        '8d3beb003bc66051ead98e7172139017fcf9ce2172576541c57e86418dfa5ab8')
61
62    ASSET_CPIO_R1 = Asset(
63        ('https://github.com/groeck/linux-build-test/'
64         'raw/8584a59e/rootfs/mipsel64/'
65         'rootfs.mipsel64r1.cpio.gz'),
66        '75ba10cd35fb44e32948eeb26974f061b703c81c4ba2fab1ebcacf1d1bec3b61')
67
68    @skipUntrustedTest()
69    def test_mips64el_malta_5KEc_cpio(self):
70        kernel_path = self.ASSET_KERNEL_3_19_3.fetch()
71        initrd_path = self.uncompress(self.ASSET_CPIO_R1)
72
73        self.set_machine('malta')
74        self.vm.set_console()
75        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
76                               + 'console=ttyS0 console=tty '
77                               + 'rdinit=/sbin/init noreboot')
78        self.vm.add_args('-cpu', '5KEc',
79                         '-kernel', kernel_path,
80                         '-initrd', initrd_path,
81                         '-append', kernel_command_line,
82                         '-no-reboot')
83        self.vm.launch()
84        self.wait_for_console_pattern('Boot successful.')
85
86        exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
87                                                'MIPS 5KE')
88        exec_command_and_wait_for_pattern(self, 'uname -a',
89                                                '3.19.3.mtoman.20150408')
90        exec_command_and_wait_for_pattern(self, 'reboot',
91                                                'reboot: Restarting system')
92        # Wait for VM to shut down gracefully
93        self.vm.wait()
94
95    ASSET_WHEEZY_KERNEL = Asset(
96        ('https://people.debian.org/~aurel32/qemu/mipsel/'
97         'vmlinux-3.2.0-4-5kc-malta'),
98        '5e8b725244c59745bb8b64f5d8f49f25fecfa549f3395fb6d19a3b9e5065b85b')
99
100    ASSET_WHEEZY_DISK = Asset(
101        ('https://people.debian.org/~aurel32/qemu/mipsel/'
102         'debian_wheezy_mipsel_standard.qcow2'),
103        '454f09ae39f7e6461c84727b927100d2c7813841f2a0a5dce328114887ecf914')
104
105    def test_wheezy(self):
106        kernel_path = self.ASSET_WHEEZY_KERNEL.fetch()
107        image_path = self.ASSET_WHEEZY_DISK.fetch()
108        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
109                               + 'console=ttyS0 root=/dev/sda1')
110        mips_check_wheezy(self,
111            kernel_path, image_path, kernel_command_line, cpuinfo='MIPS 20Kc',
112            dl_file='/boot/initrd.img-3.2.0-4-5kc-malta',
113            hsum='7579f8b56c1187c7c04d0dc3c0c56c7a6314c5ddd3a9bf8803ecc7cf8a3be9f8')
114
115
116@skipIfMissingImports('numpy', 'cv2')
117class MaltaMachineFramebuffer(LinuxKernelTest):
118
119    timeout = 30
120
121    ASSET_KERNEL_4_7_0 = Asset(
122        ('https://github.com/philmd/qemu-testing-blob/raw/a5966ca4b5/'
123         'mips/malta/mips64el/vmlinux-4.7.0-rc1.I6400.gz'),
124        '1f64efc59968a3c328672e6b10213fe574bb2308d9d2ed44e75e40be59e9fbc2')
125
126    ASSET_TUXLOGO = Asset(
127        ('https://github.com/torvalds/linux/raw/v2.6.12/'
128         'drivers/video/logo/logo_linux_vga16.ppm'),
129        'b762f0d91ec018887ad1b334543c2fdf9be9fdfc87672b409211efaa3ea0ef79')
130
131    def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
132        """
133        Boot Linux kernel and check Tux logo is displayed on the framebuffer.
134        """
135
136        import numpy as np
137        import cv2
138
139        screendump_path = self.scratch_file('screendump.pbm')
140
141        kernel_path = self.uncompress(self.ASSET_KERNEL_4_7_0)
142
143        tuxlogo_path = self.ASSET_TUXLOGO.fetch()
144
145        self.set_machine('malta')
146        self.vm.set_console()
147        kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
148                               'clocksource=GIC console=tty0 console=ttyS0')
149        self.vm.add_args('-kernel', kernel_path,
150                         '-cpu', 'I6400',
151                         '-smp', '%u' % cpu_cores_count,
152                         '-vga', 'std',
153                         '-append', kernel_command_line)
154        self.vm.launch()
155        framebuffer_ready = 'Console: switching to colour frame buffer device'
156        self.wait_for_console_pattern(framebuffer_ready)
157        self.vm.cmd('human-monitor-command', command_line='stop')
158        res = self.vm.cmd('human-monitor-command',
159                          command_line='screendump %s' % screendump_path)
160        if 'unknown command' in res:
161            self.skipTest('screendump not available')
162        logger = logging.getLogger('framebuffer')
163
164        match_threshold = 0.95
165        screendump_bgr = cv2.imread(screendump_path, cv2.IMREAD_COLOR)
166        tuxlogo_bgr = cv2.imread(tuxlogo_path, cv2.IMREAD_COLOR)
167        result = cv2.matchTemplate(screendump_bgr, tuxlogo_bgr,
168                                   cv2.TM_CCOEFF_NORMED)
169        loc = np.where(result >= match_threshold)
170        tuxlogo_count = 0
171        h, w = tuxlogo_bgr.shape[:2]
172        debug_png = os.getenv('QEMU_TEST_CV2_SCREENDUMP_PNG_PATH')
173        for tuxlogo_count, pt in enumerate(zip(*loc[::-1]), start=1):
174            logger.debug('found Tux at position (x, y) = %s', pt)
175            cv2.rectangle(screendump_bgr, pt,
176                          (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
177        if debug_png:
178            cv2.imwrite(debug_png, screendump_bgr)
179        self.assertGreaterEqual(tuxlogo_count, cpu_cores_count)
180
181    def test_mips_malta_i6400_framebuffer_logo_1core(self):
182        self.do_test_i6400_framebuffer_logo(1)
183
184    # XXX file tracking bug
185    @skipFlakyTest(bug_url=None)
186    def test_mips_malta_i6400_framebuffer_logo_7cores(self):
187        self.do_test_i6400_framebuffer_logo(7)
188
189    @skipFlakyTest(bug_url=None)
190    def test_mips_malta_i6400_framebuffer_logo_8cores(self):
191        self.do_test_i6400_framebuffer_logo(8)
192
193
194from test_mipsel_malta import MaltaMachineYAMON
195
196if __name__ == '__main__':
197    LinuxKernelTest.main()
198