block/nvme: Pair doorbell registers
[qemu/ar7.git] / tests / acceptance / machine_m68k_nextcube.py
blob32cf571f948259663941f496005449f115800a7f
1 # Functional test that boots a VM and run OCR on the framebuffer
3 # Copyright (c) Philippe Mathieu-Daudé <f4bug@amsat.org>
5 # This work is licensed under the terms of the GNU GPL, version 2 or
6 # later. See the COPYING file in the top-level directory.
8 import os
9 import re
10 import time
11 import logging
12 import distutils.spawn
14 from avocado_qemu import Test
15 from avocado import skipUnless
16 from avocado.utils import process
17 from avocado.utils.path import find_command, CmdNotFoundError
19 PIL_AVAILABLE = True
20 try:
21 from PIL import Image
22 except ImportError:
23 PIL_AVAILABLE = False
26 def tesseract_available(expected_version):
27 try:
28 find_command('tesseract')
29 except CmdNotFoundError:
30 return False
31 res = process.run('tesseract --version')
32 try:
33 version = res.stdout_text.split()[1]
34 except IndexError:
35 version = res.stderr_text.split()[1]
36 return int(version.split('.')[0]) == expected_version
38 match = re.match(r'tesseract\s(\d)', res)
39 if match is None:
40 return False
41 # now this is guaranteed to be a digit
42 return int(match.groups()[0]) == expected_version
45 class NextCubeMachine(Test):
46 """
47 :avocado: tags=arch:m68k
48 :avocado: tags=machine:next-cube
49 :avocado: tags=device:framebuffer
50 """
52 timeout = 15
54 def check_bootrom_framebuffer(self, screenshot_path):
55 rom_url = ('http://www.nextcomputers.org/NeXTfiles/Software/ROM_Files/'
56 '68040_Non-Turbo_Chipset/Rev_2.5_v66.BIN')
57 rom_hash = 'b3534796abae238a0111299fc406a9349f7fee24'
58 rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
60 self.vm.add_args('-bios', rom_path)
61 self.vm.launch()
63 self.log.info('VM launched, waiting for display')
64 # TODO: Use avocado.utils.wait.wait_for to catch the
65 # 'displaysurface_create 1120x832' trace-event.
66 time.sleep(2)
68 self.vm.command('human-monitor-command',
69 command_line='screendump %s' % screenshot_path)
71 @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
72 def test_bootrom_framebuffer_size(self):
73 screenshot_path = os.path.join(self.workdir, "dump.png")
74 self.check_bootrom_framebuffer(screenshot_path)
76 width, height = Image.open(screenshot_path).size
77 self.assertEqual(width, 1120)
78 self.assertEqual(height, 832)
80 @skipUnless(tesseract_available(3), 'tesseract v3 OCR tool not available')
81 def test_bootrom_framebuffer_ocr_with_tesseract_v3(self):
82 screenshot_path = os.path.join(self.workdir, "dump.png")
83 self.check_bootrom_framebuffer(screenshot_path)
85 console_logger = logging.getLogger('console')
86 text = process.run("tesseract %s stdout" % screenshot_path).stdout_text
87 for line in text.split('\n'):
88 if len(line):
89 console_logger.debug(line)
90 self.assertIn('Backplane', text)
91 self.assertIn('Ethernet address', text)
93 # Tesseract 4 adds a new OCR engine based on LSTM neural networks. The
94 # new version is faster and more accurate than version 3. The drawback is
95 # that it is still alpha-level software.
96 @skipUnless(tesseract_available(4), 'tesseract v4 OCR tool not available')
97 def test_bootrom_framebuffer_ocr_with_tesseract_v4(self):
98 screenshot_path = os.path.join(self.workdir, "dump.png")
99 self.check_bootrom_framebuffer(screenshot_path)
101 console_logger = logging.getLogger('console')
102 proc = process.run("tesseract --oem 1 %s stdout" % screenshot_path)
103 text = proc.stdout_text
104 for line in text.split('\n'):
105 if len(line):
106 console_logger.debug(line)
107 self.assertIn('Testing the FPU, SCC', text)
108 self.assertIn('System test failed. Error code', text)
109 self.assertIn('Boot command', text)
110 self.assertIn('Next>', text)