Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
[qemu/ar7.git] / tests / acceptance / machine_mips_malta.py
blob7c9a4ee4d2d6bdd39b4adeaf187e8acfd22ba8d5
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 skipUnless
15 from avocado_qemu import Test
16 from avocado_qemu import wait_for_console_pattern
17 from avocado.utils import archive
18 from avocado import skipIf
21 NUMPY_AVAILABLE = True
22 try:
23 import numpy as np
24 except ImportError:
25 NUMPY_AVAILABLE = False
27 CV2_AVAILABLE = True
28 try:
29 import cv2
30 except ImportError:
31 CV2_AVAILABLE = False
34 @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
35 @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
36 class MaltaMachineFramebuffer(Test):
38 timeout = 30
40 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
42 def do_test_i6400_framebuffer_logo(self, cpu_cores_count):
43 """
44 Boot Linux kernel and check Tux logo is displayed on the framebuffer.
45 """
46 screendump_path = os.path.join(self.workdir, 'screendump.pbm')
48 kernel_url = ('https://github.com/philmd/qemu-testing-blob/raw/'
49 'a5966ca4b5/mips/malta/mips64el/'
50 'vmlinux-4.7.0-rc1.I6400.gz')
51 kernel_hash = '096f50c377ec5072e6a366943324622c312045f6'
52 kernel_path_gz = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
53 kernel_path = self.workdir + "vmlinux"
54 archive.gzip_uncompress(kernel_path_gz, kernel_path)
56 tuxlogo_url = ('https://github.com/torvalds/linux/raw/v2.6.12/'
57 'drivers/video/logo/logo_linux_vga16.ppm')
58 tuxlogo_hash = '3991c2ddbd1ddaecda7601f8aafbcf5b02dc86af'
59 tuxlogo_path = self.fetch_asset(tuxlogo_url, asset_hash=tuxlogo_hash)
61 self.vm.set_console()
62 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE +
63 'clocksource=GIC console=tty0 console=ttyS0')
64 self.vm.add_args('-kernel', kernel_path,
65 '-cpu', 'I6400',
66 '-smp', '%u' % cpu_cores_count,
67 '-vga', 'std',
68 '-append', kernel_command_line)
69 self.vm.launch()
70 framebuffer_ready = 'Console: switching to colour frame buffer device'
71 wait_for_console_pattern(self, framebuffer_ready,
72 failure_message='Kernel panic - not syncing')
73 self.vm.command('human-monitor-command', command_line='stop')
74 self.vm.command('human-monitor-command',
75 command_line='screendump %s' % screendump_path)
76 logger = logging.getLogger('framebuffer')
78 match_threshold = 0.95
79 screendump_bgr = cv2.imread(screendump_path, cv2.IMREAD_COLOR)
80 tuxlogo_bgr = cv2.imread(tuxlogo_path, cv2.IMREAD_COLOR)
81 result = cv2.matchTemplate(screendump_bgr, tuxlogo_bgr,
82 cv2.TM_CCOEFF_NORMED)
83 loc = np.where(result >= match_threshold)
84 tuxlogo_count = 0
85 h, w = tuxlogo_bgr.shape[:2]
86 debug_png = os.getenv('AVOCADO_CV2_SCREENDUMP_PNG_PATH')
87 for tuxlogo_count, pt in enumerate(zip(*loc[::-1]), start=1):
88 logger.debug('found Tux at position (x, y) = %s', pt)
89 cv2.rectangle(screendump_bgr, pt,
90 (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
91 if debug_png:
92 cv2.imwrite(debug_png, screendump_bgr)
93 self.assertGreaterEqual(tuxlogo_count, cpu_cores_count)
95 def test_mips_malta_i6400_framebuffer_logo_1core(self):
96 """
97 :avocado: tags=arch:mips64el
98 :avocado: tags=machine:malta
99 :avocado: tags=cpu:i6400
101 self.do_test_i6400_framebuffer_logo(1)
103 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
104 def test_mips_malta_i6400_framebuffer_logo_7cores(self):
106 :avocado: tags=arch:mips64el
107 :avocado: tags=machine:malta
108 :avocado: tags=cpu:i6400
109 :avocado: tags=mips:smp
111 self.do_test_i6400_framebuffer_logo(7)
113 @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab')
114 def test_mips_malta_i6400_framebuffer_logo_8cores(self):
116 :avocado: tags=arch:mips64el
117 :avocado: tags=machine:malta
118 :avocado: tags=cpu:i6400
119 :avocado: tags=mips:smp
121 self.do_test_i6400_framebuffer_logo(8)