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