1#!/usr/bin/env python3
2#
3# Test that Linux kernel boots on ppc powernv machines and check the console
4#
5# Copyright (c) 2018, 2020 Red Hat, Inc.
6#
7# This work is licensed under the terms of the GNU GPL, version 2 or
8# later.  See the COPYING file in the top-level directory.
9
10from qemu_test import QemuSystemTest, Asset
11from qemu_test import wait_for_console_pattern
12
13class powernvMachine(QemuSystemTest):
14
15    timeout = 90
16    KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 console=hvc0 '
17    panic_message = 'Kernel panic - not syncing'
18    good_message = 'VFS: Cannot open root device'
19
20    ASSET_KERNEL = Asset(
21        ('https://archives.fedoraproject.org/pub/archive/fedora-secondary/'
22         'releases/29/Everything/ppc64le/os/ppc/ppc64/vmlinuz'),
23        '383c2f5c23bc0d9d32680c3924d3fd7ee25cc5ef97091ac1aa5e1d853422fc5f')
24
25    def do_test_linux_boot(self, command_line = KERNEL_COMMON_COMMAND_LINE):
26        self.require_accelerator("tcg")
27        kernel_path = self.ASSET_KERNEL.fetch()
28
29        self.vm.set_console()
30        self.vm.add_args('-kernel', kernel_path,
31                         '-append', command_line)
32        self.vm.launch()
33
34    def test_linux_boot(self):
35        self.set_machine('powernv')
36        self.do_test_linux_boot()
37        console_pattern = 'VFS: Cannot open root device'
38        wait_for_console_pattern(self, console_pattern, self.panic_message)
39
40    def test_linux_smp_boot(self):
41        self.set_machine('powernv')
42        self.vm.add_args('-smp', '4')
43        self.do_test_linux_boot()
44        console_pattern = 'smp: Brought up 1 node, 4 CPUs'
45        wait_for_console_pattern(self, console_pattern, self.panic_message)
46        wait_for_console_pattern(self, self.good_message, self.panic_message)
47
48    def test_linux_smp_hpt_boot(self):
49        self.set_machine('powernv')
50        self.vm.add_args('-smp', '4')
51        self.do_test_linux_boot(self.KERNEL_COMMON_COMMAND_LINE +
52                                'disable_radix')
53        console_pattern = 'smp: Brought up 1 node, 4 CPUs'
54        wait_for_console_pattern(self, 'hash-mmu: Initializing hash mmu',
55                                 self.panic_message)
56        wait_for_console_pattern(self, console_pattern, self.panic_message)
57        wait_for_console_pattern(self, self.good_message, self.panic_message)
58
59    def test_linux_smt_boot(self):
60        self.set_machine('powernv')
61        self.vm.add_args('-smp', '4,threads=4')
62        self.do_test_linux_boot()
63        console_pattern = 'CPU maps initialized for 4 threads per core'
64        wait_for_console_pattern(self, console_pattern, self.panic_message)
65        console_pattern = 'smp: Brought up 1 node, 4 CPUs'
66        wait_for_console_pattern(self, console_pattern, self.panic_message)
67        wait_for_console_pattern(self, self.good_message, self.panic_message)
68
69    def test_linux_big_boot(self):
70        self.set_machine('powernv')
71        self.vm.add_args('-smp', '16,threads=4,cores=2,sockets=2')
72
73        # powernv does not support NUMA
74        self.do_test_linux_boot()
75        console_pattern = 'CPU maps initialized for 4 threads per core'
76        wait_for_console_pattern(self, console_pattern, self.panic_message)
77        console_pattern = 'smp: Brought up 2 nodes, 16 CPUs'
78        wait_for_console_pattern(self, console_pattern, self.panic_message)
79        wait_for_console_pattern(self, self.good_message, self.panic_message)
80
81if __name__ == '__main__':
82    QemuSystemTest.main()
83