1# Test class to boot aspeed machines
2#
3# SPDX-License-Identifier: GPL-2.0-or-later
4
5from .cmd import exec_command_and_wait_for_pattern
6from .linuxkernel import LinuxKernelTest
7
8class AspeedTest(LinuxKernelTest):
9
10    def do_test_arm_aspeed(self, machine, image):
11        self.set_machine(machine)
12        self.vm.set_console()
13        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
14                         '-net', 'nic', '-snapshot')
15        self.vm.launch()
16
17        self.wait_for_console_pattern("U-Boot 2016.07")
18        self.wait_for_console_pattern("## Loading kernel from FIT Image at 20080000")
19        self.wait_for_console_pattern("Starting kernel ...")
20        self.wait_for_console_pattern("Booting Linux on physical CPU 0x0")
21        self.wait_for_console_pattern(
22                "aspeed-smc 1e620000.spi: read control register: 203b0641")
23        self.wait_for_console_pattern("ftgmac100 1e660000.ethernet eth0: irq ")
24        self.wait_for_console_pattern("systemd[1]: Set hostname to")
25
26    def do_test_arm_aspeed_buildroot_start(self, image, cpu_id, pattern='Aspeed EVB'):
27        self.require_netdev('user')
28        self.vm.set_console()
29        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw,read-only=true',
30                         '-net', 'nic', '-net', 'user')
31        self.vm.launch()
32
33        self.wait_for_console_pattern('U-Boot 2019.04')
34        self.wait_for_console_pattern('## Loading kernel from FIT Image')
35        self.wait_for_console_pattern('Starting kernel ...')
36        self.wait_for_console_pattern('Booting Linux on physical CPU ' + cpu_id)
37        self.wait_for_console_pattern('lease of 10.0.2.15')
38        # the line before login:
39        self.wait_for_console_pattern(pattern)
40        exec_command_and_wait_for_pattern(self, 'root', 'Password:')
41        exec_command_and_wait_for_pattern(self, 'passw0rd', '#')
42
43    def do_test_arm_aspeed_buildroot_poweroff(self):
44        exec_command_and_wait_for_pattern(self, 'poweroff',
45                                          'reboot: System halted');
46
47    def do_test_arm_aspeed_sdk_start(self, image):
48        self.require_netdev('user')
49        self.vm.set_console()
50        self.vm.add_args('-drive', 'file=' + image + ',if=mtd,format=raw',
51                         '-net', 'nic', '-net', 'user', '-snapshot')
52        self.vm.launch()
53
54        self.wait_for_console_pattern('U-Boot 2019.04')
55        self.wait_for_console_pattern('## Loading kernel from FIT Image')
56        self.wait_for_console_pattern('Starting kernel ...')
57