fuzz: add virtio-9p configurations for fuzzing
[qemu/ar7.git] / tests / acceptance / machine_m68k_nextcube.py
blob2baba5fdc269a704159044c5d222e16623d06761
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
13 from avocado_qemu import Test
14 from avocado import skipUnless
15 from avocado.utils import process
16 from avocado.utils.path import find_command, CmdNotFoundError
18 PIL_AVAILABLE = True
19 try:
20 from PIL import Image
21 except ImportError:
22 PIL_AVAILABLE = False
25 def tesseract_available(expected_version):
26 try:
27 find_command('tesseract')
28 except CmdNotFoundError:
29 return False
30 res = process.run('tesseract --version')
31 try:
32 version = res.stdout_text.split()[1]
33 except IndexError:
34 version = res.stderr_text.split()[1]
35 return int(version.split('.')[0]) == expected_version
37 match = re.match(r'tesseract\s(\d)', res)
38 if match is None:
39 return False
40 # now this is guaranteed to be a digit
41 return int(match.groups()[0]) == expected_version
44 class NextCubeMachine(Test):
45 """
46 :avocado: tags=arch:m68k
47 :avocado: tags=machine:next-cube
48 :avocado: tags=device:framebuffer
49 """
51 timeout = 15
53 def check_bootrom_framebuffer(self, screenshot_path):
54 rom_url = ('http://www.nextcomputers.org/NeXTfiles/Software/ROM_Files/'
55 '68040_Non-Turbo_Chipset/Rev_2.5_v66.BIN')
56 rom_hash = 'b3534796abae238a0111299fc406a9349f7fee24'
57 rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
59 self.vm.add_args('-bios', rom_path)
60 self.vm.launch()
62 self.log.info('VM launched, waiting for display')
63 # TODO: Use avocado.utils.wait.wait_for to catch the
64 # 'displaysurface_create 1120x832' trace-event.
65 time.sleep(2)
67 self.vm.command('human-monitor-command',
68 command_line='screendump %s' % screenshot_path)
70 @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
71 def test_bootrom_framebuffer_size(self):
72 screenshot_path = os.path.join(self.workdir, "dump.ppm")
73 self.check_bootrom_framebuffer(screenshot_path)
75 width, height = Image.open(screenshot_path).size
76 self.assertEqual(width, 1120)
77 self.assertEqual(height, 832)
79 @skipUnless(tesseract_available(3), 'tesseract v3 OCR tool not available')
80 def test_bootrom_framebuffer_ocr_with_tesseract_v3(self):
81 screenshot_path = os.path.join(self.workdir, "dump.ppm")
82 self.check_bootrom_framebuffer(screenshot_path)
84 console_logger = logging.getLogger('console')
85 text = process.run("tesseract %s stdout" % screenshot_path).stdout_text
86 for line in text.split('\n'):
87 if len(line):
88 console_logger.debug(line)
89 self.assertIn('Backplane', text)
90 self.assertIn('Ethernet address', text)
92 # Tesseract 4 adds a new OCR engine based on LSTM neural networks. The
93 # new version is faster and more accurate than version 3. The drawback is
94 # that it is still alpha-level software.
95 @skipUnless(tesseract_available(4), 'tesseract v4 OCR tool not available')
96 def test_bootrom_framebuffer_ocr_with_tesseract_v4(self):
97 screenshot_path = os.path.join(self.workdir, "dump.ppm")
98 self.check_bootrom_framebuffer(screenshot_path)
100 console_logger = logging.getLogger('console')
101 proc = process.run("tesseract --oem 1 %s stdout" % screenshot_path)
102 text = proc.stdout_text
103 for line in text.split('\n'):
104 if len(line):
105 console_logger.debug(line)
106 self.assertIn('Testing the FPU, SCC', text)
107 self.assertIn('System test failed. Error code', text)
108 self.assertIn('Boot command', text)
109 self.assertIn('Next>', text)