1*d5674412SThomas Huth#!/usr/bin/env python3
2*d5674412SThomas Huth#
3*d5674412SThomas Huth# Functional test that boots a Linux kernel and checks the console
4*d5674412SThomas Huth#
5*d5674412SThomas Huth# Copyright (c) 2018 Red Hat, Inc.
6*d5674412SThomas Huth#
7*d5674412SThomas Huth# Author:
8*d5674412SThomas Huth#  Cleber Rosa <crosa@redhat.com>
9*d5674412SThomas Huth#
10*d5674412SThomas Huth# This work is licensed under the terms of the GNU GPL, version 2 or
11*d5674412SThomas Huth# later.  See the COPYING file in the top-level directory.
12*d5674412SThomas Huth
13*d5674412SThomas Huthimport os
14*d5674412SThomas Huth
15*d5674412SThomas Huthfrom unittest import skipUnless
16*d5674412SThomas Huthfrom qemu_test import QemuSystemTest, Asset
17*d5674412SThomas Huthfrom qemu_test import exec_command_and_wait_for_pattern
18*d5674412SThomas Huthfrom qemu_test import wait_for_console_pattern
19*d5674412SThomas Huthfrom qemu_test.utils import gzip_uncompress
20*d5674412SThomas Huth
21*d5674412SThomas Huth
22*d5674412SThomas Huthclass RxGdbSimMachine(QemuSystemTest):
23*d5674412SThomas Huth
24*d5674412SThomas Huth    timeout = 30
25*d5674412SThomas Huth    KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 '
26*d5674412SThomas Huth
27*d5674412SThomas Huth    ASSET_UBOOT = Asset(
28*d5674412SThomas Huth        'https://acc.dl.osdn.jp/users/23/23888/u-boot.bin.gz',
29*d5674412SThomas Huth        '7146567d669e91dbac166384b29aeba1715beb844c8551e904b86831bfd9d046')
30*d5674412SThomas Huth    ASSET_DTB = Asset(
31*d5674412SThomas Huth        'https://acc.dl.osdn.jp/users/23/23887/rx-virt.dtb',
32*d5674412SThomas Huth        'aa278d9c1907a4501741d7ee57e7f65c02dd1b3e0323b33c6d4247f1b32cf29a')
33*d5674412SThomas Huth    ASSET_KERNEL = Asset(
34*d5674412SThomas Huth        'http://acc.dl.osdn.jp/users/23/23845/zImage',
35*d5674412SThomas Huth        'baa43205e74a7220ed8482188c5e9ce497226712abb7f4e7e4f825ce19ff9656')
36*d5674412SThomas Huth
37*d5674412SThomas Huth    def test_uboot(self):
38*d5674412SThomas Huth        """
39*d5674412SThomas Huth        U-Boot and checks that the console is operational.
40*d5674412SThomas Huth        """
41*d5674412SThomas Huth        self.set_machine('gdbsim-r5f562n8')
42*d5674412SThomas Huth
43*d5674412SThomas Huth        uboot_path_gz = self.ASSET_UBOOT.fetch()
44*d5674412SThomas Huth        uboot_path = os.path.join(self.workdir, 'u-boot.bin')
45*d5674412SThomas Huth        gzip_uncompress(uboot_path_gz, uboot_path)
46*d5674412SThomas Huth
47*d5674412SThomas Huth        self.vm.set_console()
48*d5674412SThomas Huth        self.vm.add_args('-bios', uboot_path,
49*d5674412SThomas Huth                         '-no-reboot')
50*d5674412SThomas Huth        self.vm.launch()
51*d5674412SThomas Huth        uboot_version = 'U-Boot 2016.05-rc3-23705-ga1ef3c71cb-dirty'
52*d5674412SThomas Huth        wait_for_console_pattern(self, uboot_version)
53*d5674412SThomas Huth        gcc_version = 'rx-unknown-linux-gcc (GCC) 9.0.0 20181105 (experimental)'
54*d5674412SThomas Huth        # FIXME limit baudrate on chardev, else we type too fast
55*d5674412SThomas Huth        #exec_command_and_wait_for_pattern(self, 'version', gcc_version)
56*d5674412SThomas Huth
57*d5674412SThomas Huth    @skipUnless(os.getenv('QEMU_TEST_FLAKY_TESTS'), 'Test is unstable on GitLab')
58*d5674412SThomas Huth    def test_linux_sash(self):
59*d5674412SThomas Huth        """
60*d5674412SThomas Huth        Boots a Linux kernel and checks that the console is operational.
61*d5674412SThomas Huth        """
62*d5674412SThomas Huth        self.set_machine('gdbsim-r5f562n7')
63*d5674412SThomas Huth
64*d5674412SThomas Huth        dtb_path = self.ASSET_DTB.fetch()
65*d5674412SThomas Huth        kernel_path = self.ASSET_KERNEL.fetch()
66*d5674412SThomas Huth
67*d5674412SThomas Huth        self.vm.set_console()
68*d5674412SThomas Huth        kernel_command_line = self.KERNEL_COMMON_COMMAND_LINE + 'earlycon'
69*d5674412SThomas Huth        self.vm.add_args('-kernel', kernel_path,
70*d5674412SThomas Huth                         '-dtb', dtb_path,
71*d5674412SThomas Huth                         '-no-reboot')
72*d5674412SThomas Huth        self.vm.launch()
73*d5674412SThomas Huth        wait_for_console_pattern(self, 'Sash command shell (version 1.1.1)',
74*d5674412SThomas Huth                                 failure_message='Kernel panic - not syncing')
75*d5674412SThomas Huth        exec_command_and_wait_for_pattern(self, 'printenv', 'TERM=linux')
76*d5674412SThomas Huth
77*d5674412SThomas Huthif __name__ == '__main__':
78*d5674412SThomas Huth    QemuSystemTest.main()
79