| 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Functional test that boots a Linux kernel and checks the console |
| 4 | # |
| 5 | # Copyright (c) 2020 Red Hat, Inc. |
| 6 | # |
| 7 | # Author: |
| 8 | # Thomas Huth <thuth@redhat.com> |
| 9 | # |
| 10 | # This work is licensed under the terms of the GNU GPL, version 2 or |
| 11 | # later. See the COPYING file in the top-level directory. |
| 12 | # |
| 13 | # SPDX-License-Identifier: GPL-2.0-or-later |
| 14 | |
| 15 | import logging |
| 16 | |
| 17 | from qemu_test import QemuSystemTest, Asset |
| 18 | from qemu_test import wait_for_console_pattern |
| 19 | from qemu_test import skipIfMissingImports, skipUntrustedTest |
| 20 | |
| 21 | |
| 22 | class IntegratorMachine(QemuSystemTest): |
| 23 | |
| 24 | timeout = 90 |
| 25 | |
| 26 | ASSET_KERNEL = Asset( |
| 27 | ('https://github.com/zayac/qemu-arm/raw/master/' |
| 28 | 'arm-test/kernel/zImage.integrator'), |
| 29 | '26e7c7e8f943de785d95bd3c74d66451604a9b6a7a3d25dceb279e7548fd8e78') |
| 30 | |
| 31 | ASSET_INITRD = Asset( |
| 32 | ('https://github.com/zayac/qemu-arm/raw/master/' |
| 33 | 'arm-test/kernel/arm_root.img'), |
| 34 | 'e187c27fb342ad148c7f33475fbed124933e0b3f4be8c74bc4f3426a4793373a') |
| 35 | |
| 36 | ASSET_TUXLOGO = Asset( |
| 37 | ('https://github.com/torvalds/linux/raw/v2.6.12/' |
| 38 | 'drivers/video/logo/logo_linux_vga16.ppm'), |
| 39 | 'b762f0d91ec018887ad1b334543c2fdf9be9fdfc87672b409211efaa3ea0ef79') |
| 40 | |
| 41 | def boot_integratorcp(self): |
| 42 | kernel_path = self.ASSET_KERNEL.fetch() |
| 43 | initrd_path = self.ASSET_INITRD.fetch() |
| 44 | |
| 45 | self.set_machine('integratorcp') |
| 46 | self.vm.set_console() |
| 47 | self.vm.add_args('-kernel', kernel_path, |
| 48 | '-initrd', initrd_path, |
| 49 | '-append', 'printk.time=0 console=ttyAMA0') |
| 50 | self.vm.launch() |
| 51 | |
| 52 | @skipUntrustedTest() |
| 53 | def test_integratorcp_console(self): |
| 54 | """ |
| 55 | Boots the Linux kernel and checks that the console is operational |
| 56 | """ |
| 57 | self.boot_integratorcp() |
| 58 | wait_for_console_pattern(self, 'Log in as root') |
| 59 | |
| 60 | @skipIfMissingImports("numpy", "cv2") |
| 61 | @skipUntrustedTest() |
| 62 | def test_framebuffer_tux_logo(self): |
| 63 | """ |
| 64 | Boot Linux and verify the Tux logo is displayed on the framebuffer. |
| 65 | """ |
| 66 | import numpy as np |
| 67 | import cv2 |
| 68 | |
| 69 | screendump_path = self.scratch_file("screendump.pbm") |
| 70 | tuxlogo_path = self.ASSET_TUXLOGO.fetch() |
| 71 | |
| 72 | self.boot_integratorcp() |
| 73 | framebuffer_ready = 'Console: switching to colour frame buffer device' |
| 74 | wait_for_console_pattern(self, framebuffer_ready) |
| 75 | self.vm.cmd('human-monitor-command', command_line='stop') |
| 76 | res = self.vm.cmd('human-monitor-command', |
| 77 | command_line='screendump %s' % screendump_path) |
| 78 | if 'unknown command' in res: |
| 79 | self.skipTest('screendump not available') |
| 80 | |
| 81 | cpu_count = 1 |
| 82 | match_threshold = 0.92 |
| 83 | screendump_bgr = cv2.imread(screendump_path) |
| 84 | screendump_gray = cv2.cvtColor(screendump_bgr, cv2.COLOR_BGR2GRAY) |
| 85 | result = cv2.matchTemplate(screendump_gray, cv2.imread(tuxlogo_path, 0), |
| 86 | cv2.TM_CCOEFF_NORMED) |
| 87 | loc = np.where(result >= match_threshold) |
| 88 | tux_count = 0 |
| 89 | for tux_count, pt in enumerate(zip(*loc[::-1]), start=1): |
| 90 | self.log.debug('found Tux at position [x, y] = %s', pt) |
| 91 | self.assertGreaterEqual(tux_count, cpu_count) |
| 92 | |
| 93 | if __name__ == '__main__': |
| 94 | QemuSystemTest.main() |