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 res = self.vm.cmd('human-monitor-command', 36 command_line='screendump %s' % screenshot_path) 37 if 'unknown command' in res: 38 self.skipTest('screendump not available') 39 40 @skipIfMissingImports("PIL") 41 def test_bootrom_framebuffer_size(self): 42 self.set_machine('next-cube') 43 screenshot_path = self.scratch_file("dump.ppm") 44 self.check_bootrom_framebuffer(screenshot_path) 45 46 from PIL import Image 47 width, height = Image.open(screenshot_path).size 48 self.assertEqual(width, 1120) 49 self.assertEqual(height, 832) 50 51 @skipIfMissingCommands('tesseract') 52 def test_bootrom_framebuffer_ocr_with_tesseract(self): 53 self.set_machine('next-cube') 54 screenshot_path = self.scratch_file("dump.ppm") 55 self.check_bootrom_framebuffer(screenshot_path) 56 lines = tesseract_ocr(screenshot_path) 57 text = '\n'.join(lines) 58 self.assertIn('Testing the FPU', text) 59 self.assertIn('System test failed. Error code', text) 60 self.assertIn('Boot command', text) 61 self.assertIn('Next>', text) 62 63if __name__ == '__main__': 64 QemuSystemTest.main() 65