Merge tag 'pull-riscv-to-apply-20240806-2' of https://github.com/alistair23/qemu...
[qemu/kevin.git] / tests / avocado / machine_m68k_nextcube.py
blob1f3c883910d15b0edbd4a21482627b865ae4880e
1 # Functional test that boots a VM and run OCR on the framebuffer
3 # Copyright (c) 2019 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 time
11 from avocado_qemu import QemuSystemTest
12 from avocado import skipUnless
14 from tesseract_utils import tesseract_available, tesseract_ocr
16 PIL_AVAILABLE = True
17 try:
18 from PIL import Image
19 except ImportError:
20 PIL_AVAILABLE = False
23 class NextCubeMachine(QemuSystemTest):
24 """
25 :avocado: tags=arch:m68k
26 :avocado: tags=machine:next-cube
27 :avocado: tags=device:framebuffer
28 """
30 timeout = 15
32 def check_bootrom_framebuffer(self, screenshot_path):
33 rom_url = ('https://sourceforge.net/p/previous/code/1350/tree/'
34 'trunk/src/Rev_2.5_v66.BIN?format=raw')
35 rom_hash = 'b3534796abae238a0111299fc406a9349f7fee24'
36 rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
38 self.vm.add_args('-bios', rom_path)
39 self.vm.launch()
41 self.log.info('VM launched, waiting for display')
42 # TODO: Use avocado.utils.wait.wait_for to catch the
43 # 'displaysurface_create 1120x832' trace-event.
44 time.sleep(2)
46 self.vm.cmd('human-monitor-command',
47 command_line='screendump %s' % screenshot_path)
49 @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
50 def test_bootrom_framebuffer_size(self):
51 screenshot_path = os.path.join(self.workdir, "dump.ppm")
52 self.check_bootrom_framebuffer(screenshot_path)
54 width, height = Image.open(screenshot_path).size
55 self.assertEqual(width, 1120)
56 self.assertEqual(height, 832)
58 # Tesseract 4 adds a new OCR engine based on LSTM neural networks. The
59 # new version is faster and more accurate than version 3. The drawback is
60 # that it is still alpha-level software.
61 @skipUnless(tesseract_available(4), 'tesseract OCR tool not available')
62 def test_bootrom_framebuffer_ocr_with_tesseract(self):
63 screenshot_path = os.path.join(self.workdir, "dump.ppm")
64 self.check_bootrom_framebuffer(screenshot_path)
65 lines = tesseract_ocr(screenshot_path, tesseract_version=4)
66 text = '\n'.join(lines)
67 self.assertIn('Testing the FPU', text)
68 self.assertIn('System test failed. Error code', text)
69 self.assertIn('Boot command', text)
70 self.assertIn('Next>', text)