xref: /qemu/tests/functional/test_m68k_nextcube.py (revision 513823e7521a09ed7ad1e32e6454bac3b2cbf52d)
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 time
11
12from qemu_test import QemuSystemTest, Asset
13from qemu_test import skipIfMissingImports, skipIfMissingCommands
14from qemu_test.tesseract import tesseract_ocr
15
16
17class NextCubeMachine(QemuSystemTest):
18
19    timeout = 15
20
21    ASSET_ROM = Asset(('https://sourceforge.net/p/previous/code/1350/tree/'
22                       'trunk/src/Rev_2.5_v66.BIN?format=raw'),
23                      '1b753890b67095b73e104c939ddf62eca9e7d0aedde5108e3893b0ed9d8000a4')
24
25    def check_bootrom_framebuffer(self, screenshot_path):
26        rom_path = self.ASSET_ROM.fetch()
27
28        self.vm.add_args('-bios', rom_path)
29        self.vm.launch()
30
31        self.log.info('VM launched, waiting for display')
32        # TODO: wait for the 'displaysurface_create 1120x832' trace-event.
33        time.sleep(2)
34
35        self.vm.cmd('human-monitor-command',
36                    command_line='screendump %s' % screenshot_path)
37
38    @skipIfMissingImports("PIL")
39    def test_bootrom_framebuffer_size(self):
40        self.set_machine('next-cube')
41        screenshot_path = self.scratch_file("dump.ppm")
42        self.check_bootrom_framebuffer(screenshot_path)
43
44        from PIL import Image
45        width, height = Image.open(screenshot_path).size
46        self.assertEqual(width, 1120)
47        self.assertEqual(height, 832)
48
49    @skipIfMissingCommands('tesseract')
50    def test_bootrom_framebuffer_ocr_with_tesseract(self):
51        self.set_machine('next-cube')
52        screenshot_path = self.scratch_file("dump.ppm")
53        self.check_bootrom_framebuffer(screenshot_path)
54        lines = tesseract_ocr(screenshot_path)
55        text = '\n'.join(lines)
56        self.assertIn('Testing the FPU', text)
57        self.assertIn('System test failed. Error code', text)
58        self.assertIn('Boot command', text)
59        self.assertIn('Next>', text)
60
61if __name__ == '__main__':
62    QemuSystemTest.main()
63