xref: /qemu/tests/functional/test_m68k_nextcube.py (revision 9132fff802431438a2805389e74402321fb9afed)
1#!/usr/bin/env python3
2#
3# Functional test that boots a VM and run OCR on the framebuffer
4#
5# Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
6#
7# This work is licensed under the terms of the GNU GPL, version 2 or
8# later.  See the COPYING file in the top-level directory.
9
10import os
11import time
12
13from qemu_test import QemuSystemTest, Asset
14from qemu_test import skipIfMissingImports, skipIfMissingCommands
15from qemu_test.tesseract import tesseract_ocr
16
17
18class NextCubeMachine(QemuSystemTest):
19
20    timeout = 15
21
22    ASSET_ROM = Asset(('https://sourceforge.net/p/previous/code/1350/tree/'
23                       'trunk/src/Rev_2.5_v66.BIN?format=raw'),
24                      '1b753890b67095b73e104c939ddf62eca9e7d0aedde5108e3893b0ed9d8000a4')
25
26    def check_bootrom_framebuffer(self, screenshot_path):
27        rom_path = self.ASSET_ROM.fetch()
28
29        self.vm.add_args('-bios', rom_path)
30        self.vm.launch()
31
32        self.log.info('VM launched, waiting for display')
33        # TODO: wait for the 'displaysurface_create 1120x832' trace-event.
34        time.sleep(2)
35
36        self.vm.cmd('human-monitor-command',
37                    command_line='screendump %s' % screenshot_path)
38
39    @skipIfMissingImports("PIL")
40    def test_bootrom_framebuffer_size(self):
41        self.set_machine('next-cube')
42        screenshot_path = os.path.join(self.workdir, "dump.ppm")
43        self.check_bootrom_framebuffer(screenshot_path)
44
45        from PIL import Image
46        width, height = Image.open(screenshot_path).size
47        self.assertEqual(width, 1120)
48        self.assertEqual(height, 832)
49
50    @skipIfMissingCommands('tesseract')
51    def test_bootrom_framebuffer_ocr_with_tesseract(self):
52        self.set_machine('next-cube')
53        screenshot_path = os.path.join(self.workdir, "dump.ppm")
54        self.check_bootrom_framebuffer(screenshot_path)
55        lines = tesseract_ocr(screenshot_path)
56        text = '\n'.join(lines)
57        self.assertIn('Testing the FPU', text)
58        self.assertIn('System test failed. Error code', text)
59        self.assertIn('Boot command', text)
60        self.assertIn('Next>', text)
61
62if __name__ == '__main__':
63    QemuSystemTest.main()
64