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.
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
26 def tesseract_available(expected_version
):
28 find_command('tesseract')
29 except CmdNotFoundError
:
31 res
= process
.run('tesseract --version')
33 version
= res
.stdout_text
.split()[1]
35 version
= res
.stderr_text
.split()[1]
36 return int(version
.split('.')[0]) == expected_version
38 match
= re
.match(r
'tesseract\s(\d)', res
)
41 # now this is guaranteed to be a digit
42 return int(match
.groups()[0]) == expected_version
45 class NextCubeMachine(Test
):
49 def check_bootrom_framebuffer(self
, screenshot_path
):
50 rom_url
= ('http://www.nextcomputers.org/NeXTfiles/Software/ROM_Files/'
51 '68040_Non-Turbo_Chipset/Rev_2.5_v66.BIN')
52 rom_hash
= 'b3534796abae238a0111299fc406a9349f7fee24'
53 rom_path
= self
.fetch_asset(rom_url
, asset_hash
=rom_hash
)
55 self
.vm
.set_machine('next-cube')
56 self
.vm
.add_args('-bios', rom_path
)
59 self
.log
.info('VM launched, waiting for display')
60 # TODO: Use avocado.utils.wait.wait_for to catch the
61 # 'displaysurface_create 1120x832' trace-event.
64 self
.vm
.command('human-monitor-command',
65 command_line
='screendump %s' % screenshot_path
)
67 @skipUnless(PIL_AVAILABLE
, 'Python PIL not installed')
68 def test_bootrom_framebuffer_size(self
):
70 :avocado: tags=arch:m68k
71 :avocado: tags=machine:next_cube
72 :avocado: tags=device:framebuffer
74 screenshot_path
= os
.path
.join(self
.workdir
, "dump.png")
75 self
.check_bootrom_framebuffer(screenshot_path
)
77 width
, height
= Image
.open(screenshot_path
).size
78 self
.assertEqual(width
, 1120)
79 self
.assertEqual(height
, 832)
81 @skipUnless(tesseract_available(3), 'tesseract v3 OCR tool not available')
82 def test_bootrom_framebuffer_ocr_with_tesseract_v3(self
):
84 :avocado: tags=arch:m68k
85 :avocado: tags=machine:next_cube
86 :avocado: tags=device:framebuffer
88 screenshot_path
= os
.path
.join(self
.workdir
, "dump.png")
89 self
.check_bootrom_framebuffer(screenshot_path
)
91 console_logger
= logging
.getLogger('console')
92 text
= process
.run("tesseract %s stdout" % screenshot_path
).stdout_text
93 for line
in text
.split('\n'):
95 console_logger
.debug(line
)
96 self
.assertIn('Backplane', text
)
97 self
.assertIn('Ethernet address', text
)
99 # Tesseract 4 adds a new OCR engine based on LSTM neural networks. The
100 # new version is faster and more accurate than version 3. The drawback is
101 # that it is still alpha-level software.
102 @skipUnless(tesseract_available(4), 'tesseract v4 OCR tool not available')
103 def test_bootrom_framebuffer_ocr_with_tesseract_v4(self
):
105 :avocado: tags=arch:m68k
106 :avocado: tags=machine:next_cube
107 :avocado: tags=device:framebuffer
109 screenshot_path
= os
.path
.join(self
.workdir
, "dump.png")
110 self
.check_bootrom_framebuffer(screenshot_path
)
112 console_logger
= logging
.getLogger('console')
113 proc
= process
.run("tesseract --oem 1 %s stdout" % screenshot_path
)
114 text
= proc
.stdout_text
115 for line
in text
.split('\n'):
117 console_logger
.debug(line
)
118 self
.assertIn('Testing the FPU, SCC', text
)
119 self
.assertIn('System test failed. Error code 51', text
)
120 self
.assertIn('Boot command', text
)
121 self
.assertIn('Next>', text
)