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 # Wait for the FPU test to finish, then the display is available, too: 33 while True: 34 res = self.vm.cmd('human-monitor-command', 35 command_line='info registers') 36 if ("F0 = 400e 8400000000000000" in res and 37 "F1 = 400e 83ff000000000000" in res and 38 "F2 = 400e 83ff000000000000" in res): 39 break 40 time.sleep(0.1) 41 42 res = self.vm.cmd('human-monitor-command', 43 command_line=f"screendump {screenshot_path}") 44 if 'unknown command' in res: 45 self.skipTest('screendump not available') 46 47 @skipIfMissingImports("PIL") 48 def test_bootrom_framebuffer_size(self): 49 self.set_machine('next-cube') 50 screenshot_path = self.scratch_file("dump.ppm") 51 self.check_bootrom_framebuffer(screenshot_path) 52 53 from PIL import Image 54 with Image.open(screenshot_path) as image: 55 width, height = image.size 56 self.assertEqual(width, 1120) 57 self.assertEqual(height, 832) 58 59 @skipIfMissingCommands('tesseract') 60 def test_bootrom_framebuffer_ocr_with_tesseract(self): 61 self.set_machine('next-cube') 62 screenshot_path = self.scratch_file("dump.ppm") 63 self.check_bootrom_framebuffer(screenshot_path) 64 lines = tesseract_ocr(screenshot_path) 65 text = '\n'.join(lines) 66 self.assertIn('Backplane slot', text) 67 self.assertIn('Ethernet address', text) 68 self.assertIn('Testing the FPU', text) 69 70 71if __name__ == '__main__': 72 QemuSystemTest.main() 73