machine_arm_integratorcp.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # Functional test that boots a Linux kernel and checks the console
  2. #
  3. # Copyright (c) 2020 Red Hat, Inc.
  4. #
  5. # Author:
  6. # Thomas Huth <thuth@redhat.com>
  7. #
  8. # This work is licensed under the terms of the GNU GPL, version 2 or
  9. # later. See the COPYING file in the top-level directory.
  10. import os
  11. import logging
  12. from avocado import skipUnless
  13. from avocado_qemu import QemuSystemTest
  14. from avocado_qemu import wait_for_console_pattern
  15. NUMPY_AVAILABLE = True
  16. try:
  17. import numpy as np
  18. except ImportError:
  19. NUMPY_AVAILABLE = False
  20. CV2_AVAILABLE = True
  21. try:
  22. import cv2
  23. except ImportError:
  24. CV2_AVAILABLE = False
  25. class IntegratorMachine(QemuSystemTest):
  26. timeout = 90
  27. def boot_integratorcp(self):
  28. kernel_url = ('https://github.com/zayac/qemu-arm/raw/master/'
  29. 'arm-test/kernel/zImage.integrator')
  30. kernel_hash = '0d7adba893c503267c946a3cbdc63b4b54f25468'
  31. kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
  32. initrd_url = ('https://github.com/zayac/qemu-arm/raw/master/'
  33. 'arm-test/kernel/arm_root.img')
  34. initrd_hash = 'b51e4154285bf784e017a37586428332d8c7bd8b'
  35. initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash)
  36. self.vm.set_console()
  37. self.vm.add_args('-kernel', kernel_path,
  38. '-initrd', initrd_path,
  39. '-append', 'printk.time=0 console=ttyAMA0')
  40. self.vm.launch()
  41. @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
  42. def test_integratorcp_console(self):
  43. """
  44. Boots the Linux kernel and checks that the console is operational
  45. :avocado: tags=arch:arm
  46. :avocado: tags=machine:integratorcp
  47. :avocado: tags=device:pl011
  48. """
  49. self.boot_integratorcp()
  50. wait_for_console_pattern(self, 'Log in as root')
  51. @skipUnless(NUMPY_AVAILABLE, 'Python NumPy not installed')
  52. @skipUnless(CV2_AVAILABLE, 'Python OpenCV not installed')
  53. @skipUnless(os.getenv('AVOCADO_ALLOW_UNTRUSTED_CODE'), 'untrusted code')
  54. def test_framebuffer_tux_logo(self):
  55. """
  56. Boot Linux and verify the Tux logo is displayed on the framebuffer.
  57. :avocado: tags=arch:arm
  58. :avocado: tags=machine:integratorcp
  59. :avocado: tags=device:pl110
  60. :avocado: tags=device:framebuffer
  61. """
  62. screendump_path = os.path.join(self.workdir, "screendump.pbm")
  63. tuxlogo_url = ('https://github.com/torvalds/linux/raw/v2.6.12/'
  64. 'drivers/video/logo/logo_linux_vga16.ppm')
  65. tuxlogo_hash = '3991c2ddbd1ddaecda7601f8aafbcf5b02dc86af'
  66. tuxlogo_path = self.fetch_asset(tuxlogo_url, asset_hash=tuxlogo_hash)
  67. self.boot_integratorcp()
  68. framebuffer_ready = 'Console: switching to colour frame buffer device'
  69. wait_for_console_pattern(self, framebuffer_ready)
  70. self.vm.cmd('human-monitor-command', command_line='stop')
  71. self.vm.cmd('human-monitor-command',
  72. command_line='screendump %s' % screendump_path)
  73. logger = logging.getLogger('framebuffer')
  74. cpu_count = 1
  75. match_threshold = 0.92
  76. screendump_bgr = cv2.imread(screendump_path)
  77. screendump_gray = cv2.cvtColor(screendump_bgr, cv2.COLOR_BGR2GRAY)
  78. result = cv2.matchTemplate(screendump_gray, cv2.imread(tuxlogo_path, 0),
  79. cv2.TM_CCOEFF_NORMED)
  80. loc = np.where(result >= match_threshold)
  81. tux_count = 0
  82. for tux_count, pt in enumerate(zip(*loc[::-1]), start=1):
  83. logger.debug('found Tux at position [x, y] = %s', pt)
  84. self.assertGreaterEqual(tux_count, cpu_count)