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 LinuxKernelTest, Asset
11from qemu_test import wait_for_console_pattern
12
13class powernvMachine(LinuxKernelTest):
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
81
82    ASSET_EPAPR_KERNEL = Asset(
83        ('https://github.com/open-power/op-build/releases/download/v2.7/'
84         'zImage.epapr'),
85        '0ab237df661727e5392cee97460e8674057a883c5f74381a128fa772588d45cd')
86
87    def do_test_ppc64_powernv(self, proc):
88        self.require_accelerator("tcg")
89        kernel_path = self.ASSET_EPAPR_KERNEL.fetch()
90        self.vm.set_console()
91        self.vm.add_args('-kernel', kernel_path,
92                         '-append', 'console=tty0 console=hvc0',
93                         '-device', 'pcie-pci-bridge,id=bridge1,bus=pcie.1,addr=0x0',
94                         '-device', 'nvme,bus=pcie.2,addr=0x0,serial=1234',
95                         '-device', 'e1000e,bus=bridge1,addr=0x3',
96                         '-device', 'nec-usb-xhci,bus=bridge1,addr=0x2')
97        self.vm.launch()
98
99        self.wait_for_console_pattern("CPU: " + proc + " generation processor")
100        self.wait_for_console_pattern("zImage starting: loaded")
101        self.wait_for_console_pattern("Run /init as init process")
102        # Device detection output driven by udev probing is sometimes cut off
103        # from console output, suspect S14silence-console init script.
104
105    def test_powernv8(self):
106        self.set_machine('powernv8')
107        self.do_test_ppc64_powernv('P8')
108
109    def test_powernv9(self):
110        self.set_machine('powernv9')
111        self.do_test_ppc64_powernv('P9')
112
113    def test_powernv10(self):
114        self.set_machine('powernv10')
115        self.do_test_ppc64_powernv('P10')
116
117if __name__ == '__main__':
118    LinuxKernelTest.main()
119