1 # Functional tests for the MIPS Malta board
3 # Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
5 # This work is licensed under the terms of the GNU GPL, version 2 or later.
6 # See the COPYING file in the top-level directory.
8 # SPDX-License-Identifier: GPL-2.0-or-later
14 from avocado
import skipUnless
15 from avocado
import skipUnless
16 from avocado
.utils
import archive
17 from avocado_qemu
import QemuSystemTest
18 from avocado_qemu
import exec_command_and_wait_for_pattern
19 from avocado_qemu
import interrupt_interactive_console_until_pattern
20 from avocado_qemu
import wait_for_console_pattern
23 NUMPY_AVAILABLE
= True
27 NUMPY_AVAILABLE
= False
36 @skipUnless(NUMPY_AVAILABLE
, 'Python NumPy not installed')
37 @skipUnless(CV2_AVAILABLE
, 'Python OpenCV not installed')
38 class MaltaMachineFramebuffer(QemuSystemTest
):
42 KERNEL_COMMON_COMMAND_LINE
= 'printk.time=0 '
44 def do_test_i6400_framebuffer_logo(self
, cpu_cores_count
):
46 Boot Linux kernel and check Tux logo is displayed on the framebuffer.
48 screendump_path
= os
.path
.join(self
.workdir
, 'screendump.pbm')
50 kernel_url
= ('https://github.com/philmd/qemu-testing-blob/raw/'
51 'a5966ca4b5/mips/malta/mips64el/'
52 'vmlinux-4.7.0-rc1.I6400.gz')
53 kernel_hash
= '096f50c377ec5072e6a366943324622c312045f6'
54 kernel_path_gz
= self
.fetch_asset(kernel_url
, asset_hash
=kernel_hash
)
55 kernel_path
= self
.workdir
+ "vmlinux"
56 archive
.gzip_uncompress(kernel_path_gz
, kernel_path
)
58 tuxlogo_url
= ('https://github.com/torvalds/linux/raw/v2.6.12/'
59 'drivers/video/logo/logo_linux_vga16.ppm')
60 tuxlogo_hash
= '3991c2ddbd1ddaecda7601f8aafbcf5b02dc86af'
61 tuxlogo_path
= self
.fetch_asset(tuxlogo_url
, asset_hash
=tuxlogo_hash
)
64 kernel_command_line
= (self
.KERNEL_COMMON_COMMAND_LINE
+
65 'clocksource=GIC console=tty0 console=ttyS0')
66 self
.vm
.add_args('-kernel', kernel_path
,
67 '-smp', '%u' % cpu_cores_count
,
69 '-append', kernel_command_line
)
71 framebuffer_ready
= 'Console: switching to colour frame buffer device'
72 wait_for_console_pattern(self
, framebuffer_ready
,
73 failure_message
='Kernel panic - not syncing')
74 self
.vm
.cmd('human-monitor-command', command_line
='stop')
75 self
.vm
.cmd('human-monitor-command',
76 command_line
='screendump %s' % screendump_path
)
77 logger
= logging
.getLogger('framebuffer')
79 match_threshold
= 0.95
80 screendump_bgr
= cv2
.imread(screendump_path
, cv2
.IMREAD_COLOR
)
81 tuxlogo_bgr
= cv2
.imread(tuxlogo_path
, cv2
.IMREAD_COLOR
)
82 result
= cv2
.matchTemplate(screendump_bgr
, tuxlogo_bgr
,
84 loc
= np
.where(result
>= match_threshold
)
86 h
, w
= tuxlogo_bgr
.shape
[:2]
87 debug_png
= os
.getenv('AVOCADO_CV2_SCREENDUMP_PNG_PATH')
88 for tuxlogo_count
, pt
in enumerate(zip(*loc
[::-1]), start
=1):
89 logger
.debug('found Tux at position (x, y) = %s', pt
)
90 cv2
.rectangle(screendump_bgr
, pt
,
91 (pt
[0] + w
, pt
[1] + h
), (0, 0, 255), 2)
93 cv2
.imwrite(debug_png
, screendump_bgr
)
94 self
.assertGreaterEqual(tuxlogo_count
, cpu_cores_count
)
96 def test_mips_malta_i6400_framebuffer_logo_1core(self
):
98 :avocado: tags=arch:mips64el
99 :avocado: tags=machine:malta
100 :avocado: tags=cpu:I6400
102 self
.do_test_i6400_framebuffer_logo(1)
104 @skipUnless(os
.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
106 def test_mips_malta_i6400_framebuffer_logo_7cores(self
):
108 :avocado: tags=arch:mips64el
109 :avocado: tags=machine:malta
110 :avocado: tags=cpu:I6400
111 :avocado: tags=mips:smp
114 self
.do_test_i6400_framebuffer_logo(7)
116 @skipUnless(os
.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
118 def test_mips_malta_i6400_framebuffer_logo_8cores(self
):
120 :avocado: tags=arch:mips64el
121 :avocado: tags=machine:malta
122 :avocado: tags=cpu:I6400
123 :avocado: tags=mips:smp
126 self
.do_test_i6400_framebuffer_logo(8)
128 class MaltaMachine(QemuSystemTest
):
130 def do_test_yamon(self
):
131 rom_url
= ('http://www.imgtec.com/tools/mips-tools/downloads/'
132 'yamon/yamon-bin-02.22.zip')
133 rom_hash
= '8da7ecddbc5312704b8b324341ee238189bde480'
134 zip_path
= self
.fetch_asset(rom_url
, asset_hash
=rom_hash
)
136 archive
.extract(zip_path
, self
.workdir
)
137 yamon_path
= os
.path
.join(self
.workdir
, 'yamon-02.22.bin')
139 self
.vm
.set_console()
140 self
.vm
.add_args('-bios', yamon_path
)
144 pattern
= 'YAMON ROM Monitor'
145 interrupt_interactive_console_until_pattern(self
, pattern
, prompt
)
146 wait_for_console_pattern(self
, prompt
)
149 def test_mipsel_malta_yamon(self
):
151 :avocado: tags=arch:mipsel
152 :avocado: tags=machine:malta
153 :avocado: tags=endian:little
157 def test_mips64el_malta_yamon(self
):
159 :avocado: tags=arch:mips64el
160 :avocado: tags=machine:malta
161 :avocado: tags=endian:little