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 15import os 16import logging 17 18from qemu_test import QemuSystemTest, Asset 19from qemu_test import wait_for_console_pattern 20from qemu_test import skipIfMissingImports, skipUntrustedTest 21 22 23class IntegratorMachine(QemuSystemTest): 24 25 timeout = 90 26 27 ASSET_KERNEL = Asset( 28 ('https://github.com/zayac/qemu-arm/raw/master/' 29 'arm-test/kernel/zImage.integrator'), 30 '26e7c7e8f943de785d95bd3c74d66451604a9b6a7a3d25dceb279e7548fd8e78') 31 32 ASSET_INITRD = Asset( 33 ('https://github.com/zayac/qemu-arm/raw/master/' 34 'arm-test/kernel/arm_root.img'), 35 'e187c27fb342ad148c7f33475fbed124933e0b3f4be8c74bc4f3426a4793373a') 36 37 ASSET_TUXLOGO = Asset( 38 ('https://github.com/torvalds/linux/raw/v2.6.12/' 39 'drivers/video/logo/logo_linux_vga16.ppm'), 40 'b762f0d91ec018887ad1b334543c2fdf9be9fdfc87672b409211efaa3ea0ef79') 41 42 def boot_integratorcp(self): 43 kernel_path = self.ASSET_KERNEL.fetch() 44 initrd_path = self.ASSET_INITRD.fetch() 45 46 self.set_machine('integratorcp') 47 self.vm.set_console() 48 self.vm.add_args('-kernel', kernel_path, 49 '-initrd', initrd_path, 50 '-append', 'printk.time=0 console=ttyAMA0') 51 self.vm.launch() 52 53 @skipUntrustedTest() 54 def test_integratorcp_console(self): 55 """ 56 Boots the Linux kernel and checks that the console is operational 57 """ 58 self.boot_integratorcp() 59 wait_for_console_pattern(self, 'Log in as root') 60 61 @skipIfMissingImports("numpy", "cv2") 62 @skipUntrustedTest() 63 def test_framebuffer_tux_logo(self): 64 """ 65 Boot Linux and verify the Tux logo is displayed on the framebuffer. 66 """ 67 import numpy as np 68 import cv2 69 70 screendump_path = os.path.join(self.workdir, "screendump.pbm") 71 tuxlogo_path = self.ASSET_TUXLOGO.fetch() 72 73 self.boot_integratorcp() 74 framebuffer_ready = 'Console: switching to colour frame buffer device' 75 wait_for_console_pattern(self, framebuffer_ready) 76 self.vm.cmd('human-monitor-command', command_line='stop') 77 self.vm.cmd('human-monitor-command', 78 command_line='screendump %s' % screendump_path) 79 logger = logging.getLogger('framebuffer') 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 logger.debug('found Tux at position [x, y] = %s', pt) 91 self.assertGreaterEqual(tux_count, cpu_count) 92 93if __name__ == '__main__': 94 QemuSystemTest.main() 95