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