pm_smbus: rename variable to avoid shadowing
[qemu/kevin.git] / tests / avocado / machine_mips_malta.py
blob3620266589f71ab1b232c319bdcc6eef10ff6160
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 skip
15 from avocado import skipIf
16 from avocado import skipUnless
17 from avocado.utils import archive
18 from avocado_qemu import QemuSystemTest
19 from avocado_qemu import exec_command_and_wait_for_pattern
20 from avocado_qemu import interrupt_interactive_console_until_pattern
21 from avocado_qemu import wait_for_console_pattern
24 NUMPY_AVAILABLE = True
25 try:
26 import numpy as np
27 except ImportError:
28 NUMPY_AVAILABLE = False
30 CV2_AVAILABLE = True
31 try:
32 import cv2
33 except ImportError:
34 CV2_AVAILABLE = False
37 @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
38 @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
39 class MaltaMachineFramebuffer(QemuSystemTest):
41 timeout = 30
43 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
45 def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
46 """
47 Boot Linux kernel and check Tux logo is displayed on the framebuffer.
48 """
49 screendump_path = os.path.join(self.workdir, 'screendump.pbm')
51 kernel_url = ('https://github.com/philmd/qemu-testing-blob/raw/'
52 'a5966ca4b5/mips/malta/mips64el/'
53 'vmlinux-4.7.0-rc1.I6400.gz')
54 kernel_hash = '096f50c377ec5072e6a366943324622c312045f6'
55 kernel_path_gz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
56 kernel_path = self.workdir + "vmlinux"
57 archive.gzip_uncompress(kernel_path_gz, kernel_path)
59 tuxlogo_url = ('https://github.com/torvalds/linux/raw/v2.6.12/'
60 'drivers/video/logo/logo_linux_vga16.ppm')
61 tuxlogo_hash = '3991c2ddbd1ddaecda7601f8aafbcf5b02dc86af'
62 tuxlogo_path = self.fetch_asset(tuxlogo_url, asset_hash=tuxlogo_hash)
64 self.vm.set_console()
65 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
66 'clocksource=GIC console=tty0 console=ttyS0')
67 self.vm.add_args('-kernel', kernel_path,
68 '-smp', '%u' % cpu_cores_count,
69 '-vga', 'std',
70 '-append', kernel_command_line)
71 self.vm.launch()
72 framebuffer_ready = 'Console: switching to colour frame buffer device'
73 wait_for_console_pattern(self, framebuffer_ready,
74 failure_message='Kernel panic - not syncing')
75 self.vm.command('human-monitor-command', command_line='stop')
76 self.vm.command('human-monitor-command',
77 command_line='screendump %s' % screendump_path)
78 logger = logging.getLogger('framebuffer')
80 match_threshold = 0.95
81 screendump_bgr = cv2.imread(screendump_path, cv2.IMREAD_COLOR)
82 tuxlogo_bgr = cv2.imread(tuxlogo_path, cv2.IMREAD_COLOR)
83 result = cv2.matchTemplate(screendump_bgr, tuxlogo_bgr,
84 cv2.TM_CCOEFF_NORMED)
85 loc = np.where(result >= match_threshold)
86 tuxlogo_count = 0
87 h, w = tuxlogo_bgr.shape[:2]
88 debug_png = os.getenv('AVOCADO_CV2_SCREENDUMP_PNG_PATH')
89 for tuxlogo_count, pt in enumerate(zip(*loc[::-1]), start=1):
90 logger.debug('found Tux at position (x, y) = %s', pt)
91 cv2.rectangle(screendump_bgr, pt,
92 (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
93 if debug_png:
94 cv2.imwrite(debug_png, screendump_bgr)
95 self.assertGreaterEqual(tuxlogo_count, cpu_cores_count)
97 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884')
98 def test_mips_malta_i6400_framebuffer_logo_1core(self):
99 """
100 :avocado: tags=arch:mips64el
101 :avocado: tags=machine:malta
102 :avocado: tags=cpu:I6400
104 self.do_test_i6400_framebuffer_logo(1)
106 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884')
107 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
108 def test_mips_malta_i6400_framebuffer_logo_7cores(self):
110 :avocado: tags=arch:mips64el
111 :avocado: tags=machine:malta
112 :avocado: tags=cpu:I6400
113 :avocado: tags=mips:smp
115 self.do_test_i6400_framebuffer_logo(7)
117 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884')
118 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
119 def test_mips_malta_i6400_framebuffer_logo_8cores(self):
121 :avocado: tags=arch:mips64el
122 :avocado: tags=machine:malta
123 :avocado: tags=cpu:I6400
124 :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)
141 self.vm.launch()
143 prompt = 'YAMON>'
144 pattern = 'YAMON ROM Monitor'
145 interrupt_interactive_console_until_pattern(self, pattern, prompt)
146 wait_for_console_pattern(self, prompt)
147 self.vm.shutdown()
149 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884')
150 def test_mipsel_malta_yamon(self):
152 :avocado: tags=arch:mipsel
153 :avocado: tags=machine:malta
154 :avocado: tags=endian:little
156 self.do_test_yamon()
158 @skip('https://gitlab.com/qemu-project/qemu/-/issues/1884')
159 def test_mips64el_malta_yamon(self):
161 :avocado: tags=arch:mips64el
162 :avocado: tags=machine:malta
163 :avocado: tags=endian:little
165 self.do_test_yamon()