master
py 198 lines 7.89 KB
Raw
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é
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
12 import os
13
14 from qemu_test import LinuxKernelTest, Asset
15 from qemu_test import exec_command_and_wait_for_pattern
16 from qemu_test import skipIfMissingImports, skipFlakyTest, skipUntrustedTest
17
18 from mips.test_malta import mips_check_wheezy
19
20
21 class 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 kernel_path = self.archive_extract(
43 self.ASSET_KERNEL_2_63_2,
44 member='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 = f'Kernel command line: {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 = self.uncompress(self.ASSET_CPIO_R1)
71
72 self.set_machine('malta')
73 self.vm.set_console()
74 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE
75 + 'console=ttyS0 console=tty '
76 + 'rdinit=/sbin/init noreboot')
77 self.vm.add_args('-cpu', '5KEc',
78 '-kernel', kernel_path,
79 '-initrd', initrd_path,
80 '-append', kernel_command_line,
81 '-no-reboot')
82 self.vm.launch()
83 self.wait_for_console_pattern('Boot successful.')
84
85 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo',
86 'MIPS 5KE')
87 exec_command_and_wait_for_pattern(self, 'uname -a',
88 '3.19.3.mtoman.20150408')
89 exec_command_and_wait_for_pattern(self, 'reboot',
90 'reboot: Restarting system')
91 # Wait for VM to shut down gracefully
92 self.vm.wait()
93
94 ASSET_WHEEZY_KERNEL = Asset(
95 ('https://people.debian.org/~aurel32/qemu/mipsel/'
96 'vmlinux-3.2.0-4-5kc-malta'),
97 '5e8b725244c59745bb8b64f5d8f49f25fecfa549f3395fb6d19a3b9e5065b85b')
98
99 ASSET_WHEEZY_DISK = Asset(
100 ('https://people.debian.org/~aurel32/qemu/mipsel/'
101 'debian_wheezy_mipsel_standard.qcow2'),
102 '454f09ae39f7e6461c84727b927100d2c7813841f2a0a5dce328114887ecf914')
103
104 @skipFlakyTest("https://gitlab.com/qemu-project/qemu/-/issues/3109")
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')
117 class 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 # pylint: disable=import-outside-toplevel
137 import cv2 # pylint: disable=import-outside-toplevel
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', str(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=f'screendump {screendump_path}')
160 if 'unknown command' in res:
161 self.skipTest('screendump not available')
162
163 match_threshold = 0.95
164 screendump_bgr = cv2.imread(screendump_path, cv2.IMREAD_COLOR)
165 tuxlogo_bgr = cv2.imread(tuxlogo_path, cv2.IMREAD_COLOR)
166 result = cv2.matchTemplate(screendump_bgr, tuxlogo_bgr,
167 cv2.TM_CCOEFF_NORMED)
168 loc = np.where(result >= match_threshold)
169 tuxlogo_count = 0
170 h, w = tuxlogo_bgr.shape[:2]
171 debug_png = os.getenv('QEMU_TEST_CV2_SCREENDUMP_PNG_PATH')
172 for tuxlogo_count, pt in enumerate(zip(*loc[::-1]), start=1):
173 self.log.debug('found Tux at position (x, y) = %s', pt)
174 cv2.rectangle(screendump_bgr, pt,
175 (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
176 if debug_png:
177 cv2.imwrite(debug_png, screendump_bgr)
178 self.assertGreaterEqual(tuxlogo_count, cpu_cores_count)
179
180 def test_mips_malta_i6400_framebuffer_logo_1core(self):
181 self.do_test_i6400_framebuffer_logo(1)
182
183 # XXX file tracking bug
184 @skipFlakyTest(bug_url=None)
185 def test_mips_malta_i6400_framebuffer_logo_7cores(self):
186 self.do_test_i6400_framebuffer_logo(7)
187
188 @skipFlakyTest(bug_url=None)
189 def test_mips_malta_i6400_framebuffer_logo_8cores(self):
190 self.do_test_i6400_framebuffer_logo(8)
191
192
193 # Add the tests from the 32-bit mipsel file here, too.
194 # pylint: disable=unused-import,wrong-import-position
195 from mipsel.test_malta import MaltaMachineYAMON
196
197 if __name__ == '__main__':
198 LinuxKernelTest.main()