machine_m68k_nextcube.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Functional test that boots a VM and run OCR on the framebuffer
  2. #
  3. # Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
  4. #
  5. # This work is licensed under the terms of the GNU GPL, version 2 or
  6. # later. See the COPYING file in the top-level directory.
  7. import os
  8. import time
  9. from avocado_qemu import QemuSystemTest
  10. from avocado import skipUnless
  11. from tesseract_utils import tesseract_available, tesseract_ocr
  12. PIL_AVAILABLE = True
  13. try:
  14. from PIL import Image
  15. except ImportError:
  16. PIL_AVAILABLE = False
  17. class NextCubeMachine(QemuSystemTest):
  18. """
  19. :avocado: tags=arch:m68k
  20. :avocado: tags=machine:next-cube
  21. :avocado: tags=device:framebuffer
  22. """
  23. timeout = 15
  24. def check_bootrom_framebuffer(self, screenshot_path):
  25. rom_url = ('http://www.nextcomputers.org/NeXTfiles/Software/ROM_Files/'
  26. '68040_Non-Turbo_Chipset/Rev_2.5_v66.BIN')
  27. rom_hash = 'b3534796abae238a0111299fc406a9349f7fee24'
  28. rom_path = self.fetch_asset(rom_url, asset_hash=rom_hash)
  29. self.vm.add_args('-bios', rom_path)
  30. self.vm.launch()
  31. self.log.info('VM launched, waiting for display')
  32. # TODO: Use avocado.utils.wait.wait_for to catch the
  33. # 'displaysurface_create 1120x832' trace-event.
  34. time.sleep(2)
  35. self.vm.cmd('human-monitor-command',
  36. command_line='screendump %s' % screenshot_path)
  37. @skipUnless(PIL_AVAILABLE, 'Python PIL not installed')
  38. def test_bootrom_framebuffer_size(self):
  39. screenshot_path = os.path.join(self.workdir, "dump.ppm")
  40. self.check_bootrom_framebuffer(screenshot_path)
  41. width, height = Image.open(screenshot_path).size
  42. self.assertEqual(width, 1120)
  43. self.assertEqual(height, 832)
  44. @skipUnless(tesseract_available(3), 'tesseract v3 OCR tool not available')
  45. def test_bootrom_framebuffer_ocr_with_tesseract_v3(self):
  46. screenshot_path = os.path.join(self.workdir, "dump.ppm")
  47. self.check_bootrom_framebuffer(screenshot_path)
  48. lines = tesseract_ocr(screenshot_path, tesseract_version=3)
  49. text = '\n'.join(lines)
  50. self.assertIn('Backplane', text)
  51. self.assertIn('Ethernet address', text)
  52. # Tesseract 4 adds a new OCR engine based on LSTM neural networks. The
  53. # new version is faster and more accurate than version 3. The drawback is
  54. # that it is still alpha-level software.
  55. @skipUnless(tesseract_available(4), 'tesseract v4 OCR tool not available')
  56. def test_bootrom_framebuffer_ocr_with_tesseract_v4(self):
  57. screenshot_path = os.path.join(self.workdir, "dump.ppm")
  58. self.check_bootrom_framebuffer(screenshot_path)
  59. lines = tesseract_ocr(screenshot_path, tesseract_version=4)
  60. text = '\n'.join(lines)
  61. self.assertIn('Testing the FPU, SCC', text)
  62. self.assertIn('System test failed. Error code', text)
  63. self.assertIn('Boot command', text)
  64. self.assertIn('Next>', text)