]> git.proxmox.com Git - mirror_qemu.git/blame - tests/avocado/machine_m68k_nextcube.py
python/qemu: rename command() to cmd()
[mirror_qemu.git] / tests / avocado / machine_m68k_nextcube.py
CommitLineData
ca2e7e46
PMD
1# Functional test that boots a VM and run OCR on the framebuffer
2#
162127f2 3# Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
ca2e7e46
PMD
4#
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.
7
8import os
ca2e7e46 9import time
ca2e7e46 10
2283b627 11from avocado_qemu import QemuSystemTest
ca2e7e46 12from avocado import skipUnless
162127f2 13
ca822449 14from tesseract_utils import tesseract_available, tesseract_ocr
ca2e7e46
PMD
15
16PIL_AVAILABLE = True
17try:
18 from PIL import Image
19except ImportError:
20 PIL_AVAILABLE = False
21
22
2283b627 23class NextCubeMachine(QemuSystemTest):
ba21bde9
CR
24 """
25 :avocado: tags=arch:m68k
26 :avocado: tags=machine:next-cube
27 :avocado: tags=device:framebuffer
28 """
ca2e7e46
PMD
29
30 timeout = 15
31
32 def check_bootrom_framebuffer(self, screenshot_path):
33 rom_url = ('http://www.nextcomputers.org/NeXTfiles/Software/ROM_Files/'
34 '68040_Non-Turbo_Chipset/Rev_2.5_v66.BIN')
35 rom_hash = 'b3534796abae238a0111299fc406a9349f7fee24'
36 rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
37
ca2e7e46
PMD
38 self.vm.add_args('-bios', rom_path)
39 self.vm.launch()
40
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)
45
684750ab
VSO
46 self.vm.cmd('human-monitor-command',
47 command_line='screendump %s' % screenshot_path)
ca2e7e46
PMD
48
49 @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
50 def test_bootrom_framebuffer_size(self):
28bbe20c 51 screenshot_path = os.path.join(self.workdir, "dump.ppm")
ca2e7e46
PMD
52 self.check_bootrom_framebuffer(screenshot_path)
53
54 width, height = Image.open(screenshot_path).size
55 self.assertEqual(width, 1120)
56 self.assertEqual(height, 832)
57
58 @skipUnless(tesseract_available(3), 'tesseract v3 OCR tool not available')
59 def test_bootrom_framebuffer_ocr_with_tesseract_v3(self):
28bbe20c 60 screenshot_path = os.path.join(self.workdir, "dump.ppm")
ca2e7e46 61 self.check_bootrom_framebuffer(screenshot_path)
ca822449
PMD
62 lines = tesseract_ocr(screenshot_path, tesseract_version=3)
63 text = '\n'.join(lines)
ca2e7e46
PMD
64 self.assertIn('Backplane', text)
65 self.assertIn('Ethernet address', text)
66
67 # Tesseract 4 adds a new OCR engine based on LSTM neural networks. The
68 # new version is faster and more accurate than version 3. The drawback is
69 # that it is still alpha-level software.
70 @skipUnless(tesseract_available(4), 'tesseract v4 OCR tool not available')
71 def test_bootrom_framebuffer_ocr_with_tesseract_v4(self):
28bbe20c 72 screenshot_path = os.path.join(self.workdir, "dump.ppm")
ca2e7e46 73 self.check_bootrom_framebuffer(screenshot_path)
ca822449
PMD
74 lines = tesseract_ocr(screenshot_path, tesseract_version=4)
75 text = '\n'.join(lines)
ca2e7e46 76 self.assertIn('Testing the FPU, SCC', text)
20869f98 77 self.assertIn('System test failed. Error code', text)
ca2e7e46
PMD
78 self.assertIn('Boot command', text)
79 self.assertIn('Next>', text)