Merge tag 'qemu-macppc-20230206' of https://github.com/mcayland/qemu into staging
[qemu.git] / tests / avocado / machine_mips_malta.py
blob92233451c59677c9d40c34a102a6234908d22202
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
10 import os
11 import gzip
12 import logging
14 from avocado import skipIf
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
24 try:
25 import numpy as np
26 except ImportError:
27 NUMPY_AVAILABLE = False
29 CV2_AVAILABLE = True
30 try:
31 import cv2
32 except ImportError:
33 CV2_AVAILABLE = False
36 @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
37 @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
38 class MaltaMachineFramebuffer(QemuSystemTest):
40 timeout = 30
42 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
44 def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
45 """
46 Boot Linux kernel and check Tux logo is displayed on the framebuffer.
47 """
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)
63 self.vm.set_console()
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,
68 '-vga', 'std',
69 '-append', kernel_command_line)
70 self.vm.launch()
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.command('human-monitor-command', command_line='stop')
75 self.vm.command('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,
83 cv2.TM_CCOEFF_NORMED)
84 loc = np.where(result >= match_threshold)
85 tuxlogo_count = 0
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)
92 if debug_png:
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):
97 """
98 :avocado: tags=arch:mips64el
99 :avocado: tags=machine:malta
100 :avocado: tags=cpu:I6400
102 self.do_test_i6400_framebuffer_logo(1)
104 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
105 def test_mips_malta_i6400_framebuffer_logo_7cores(self):
107 :avocado: tags=arch:mips64el
108 :avocado: tags=machine:malta
109 :avocado: tags=cpu:I6400
110 :avocado: tags=mips:smp
112 self.do_test_i6400_framebuffer_logo(7)
114 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
115 def test_mips_malta_i6400_framebuffer_logo_8cores(self):
117 :avocado: tags=arch:mips64el
118 :avocado: tags=machine:malta
119 :avocado: tags=cpu:I6400
120 :avocado: tags=mips:smp
122 self.do_test_i6400_framebuffer_logo(8)
124 class MaltaMachine(QemuSystemTest):
126 def do_test_yamon(self):
127 rom_url = ('http://www.imgtec.com/tools/mips-tools/downloads/'
128 'yamon/yamon-bin-02.22.zip')
129 rom_hash = '8da7ecddbc5312704b8b324341ee238189bde480'
130 zip_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
132 archive.extract(zip_path, self.workdir)
133 yamon_path = os.path.join(self.workdir, 'yamon-02.22.bin')
135 self.vm.set_console()
136 self.vm.add_args('-bios', yamon_path)
137 self.vm.launch()
139 prompt = 'YAMON>'
140 pattern = 'YAMON ROM Monitor'
141 interrupt_interactive_console_until_pattern(self, pattern, prompt)
142 wait_for_console_pattern(self, prompt)
143 self.vm.shutdown()
145 def test_mipsel_malta_yamon(self):
147 :avocado: tags=arch:mipsel
148 :avocado: tags=machine:malta
149 :avocado: tags=endian:little
151 self.do_test_yamon()
153 def test_mips64el_malta_yamon(self):
155 :avocado: tags=arch:mips64el
156 :avocado: tags=machine:malta
157 :avocado: tags=endian:little
159 self.do_test_yamon()