master
py 239 lines 10.5 KB
Raw
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
10 from qemu_test import LinuxKernelTest, Asset
11 from qemu_test import wait_for_console_pattern
12 from qemu_test import exec_command_and_wait_for_pattern
13
14 class PowernvMachine(LinuxKernelTest):
15
16 timeout = 90
17 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 console=hvc0 '
18 panic_message = 'Kernel panic - not syncing'
19 good_message = 'VFS: Cannot open root device'
20
21 ASSET_KERNEL = Asset(
22 ('https://github.com/legoater/qemu-ppc-boot/raw/refs/heads/main/'
23 'buildroot/qemu_ppc64le_powernv8-2025.02/vmlinux'),
24 '6fd29aff9ad4362511ea5d0acbb510667c7031928e97d64ec15bbc5daf4b8151')
25
26 ASSET_INITRD = Asset(
27 ('https://github.com/legoater/qemu-ppc-boot/raw/refs/heads/main/'
28 'buildroot/qemu_ppc64le_powernv8-2025.02/rootfs.ext2'),
29 'aee2192b692077c4bde31cb56ce474424b358f17cec323d5c94af3970c9aada2')
30
31 # testdtb for power11, which contains string "hello world" in command line
32 ASSET_SAMPLE_DTB = Asset(
33 ('https://github.com/roz3x/qemu/raw/refs/heads/sample-dtb/qemu-powernv11.dtb'),
34 'ea1271516264eea1eb58a067a99d0c2ca9528be8dc7d4e46bb2d5ae0d42fc568')
35
36 def shell_exec_command_check_fail(self, command):
37 fail_msg="Fail"
38 self.shell_exec_command(f"export __FAIL_MSG={fail_msg}")
39
40 # If the exit code for the command is non 0, print fail message
41 command = command + " || echo $__FAIL_MSG"
42 exec_command_and_wait_for_pattern(self, command, '#', fail_msg)
43
44 def shell_exec_command(self, command):
45 exec_command_and_wait_for_pattern(self, command, '#', self.panic_message)
46
47 def do_test_linux_boot(self, command_line = KERNEL_COMMON_COMMAND_LINE):
48 self.require_accelerator("tcg")
49 kernel_path = self.ASSET_KERNEL.fetch()
50
51 self.vm.set_console()
52 self.vm.add_args('-kernel', kernel_path,
53 '-append', command_line)
54 self.vm.launch()
55
56 def test_linux_boot(self):
57 self.set_machine('powernv')
58 self.do_test_linux_boot()
59 console_pattern = 'VFS: Cannot open root device'
60 wait_for_console_pattern(self, console_pattern, self.panic_message)
61
62 def test_linux_smp_boot(self):
63 self.set_machine('powernv')
64 self.vm.add_args('-smp', '4')
65 self.do_test_linux_boot()
66 console_pattern = 'smp: Brought up 1 node, 4 CPUs'
67 wait_for_console_pattern(self, console_pattern, self.panic_message)
68 wait_for_console_pattern(self, self.good_message, self.panic_message)
69
70 def test_linux_smp_hpt_boot(self):
71 self.set_machine('powernv')
72 self.vm.add_args('-smp', '4')
73 self.do_test_linux_boot(self.KERNEL_COMMON_COMMAND_LINE +
74 'disable_radix')
75 console_pattern = 'smp: Brought up 1 node, 4 CPUs'
76 wait_for_console_pattern(self, 'hash-mmu: Initializing hash mmu',
77 self.panic_message)
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 def test_linux_smt_boot(self):
82 self.set_machine('powernv')
83 self.vm.add_args('-smp', '4,threads=4')
84 self.do_test_linux_boot()
85 console_pattern = 'CPU maps initialized for 4 threads per core'
86 wait_for_console_pattern(self, console_pattern, self.panic_message)
87 console_pattern = 'smp: Brought up 1 node, 4 CPUs'
88 wait_for_console_pattern(self, console_pattern, self.panic_message)
89 wait_for_console_pattern(self, self.good_message, self.panic_message)
90
91 def test_linux_remote_interrupts(self):
92 self.require_accelerator("tcg")
93 self.require_netdev('user')
94 self.set_machine('powernv')
95
96 # Have below setup in this test:
97 # 1. e1000e attached to pcie.6, which is from 7th PHB, belonging to 2nd
98 # socket (chip 1), in a powernv boot with default 6 PHBs per socket
99 # 2. CPU on 2nd socket (chip 1) disabled
100 # 3. RX IRQ's affinity to chip 2, and TX IRQ's affinity to chip 3
101 #
102 # Then ping is done, to generate interrupts from e1000e which should go
103 # to IRQ server on the remote sockets
104 self.vm.add_args('-smp', '4,sockets=4,cores=1,threads=1')
105 self.vm.add_args('-netdev', 'user,id=net0')
106 self.vm.add_args('-device', 'e1000e,netdev=net0,bus=pcie.6')
107
108 kernel_path = self.ASSET_KERNEL.fetch()
109 rootfs_path = self.ASSET_INITRD.fetch()
110 self.vm.set_console()
111 self.vm.add_args('-kernel', kernel_path,
112 '-drive',
113 f'file={rootfs_path},format=raw,if=none,id=drive0,readonly=on',
114 '-append', 'root=/dev/nvme0n1 console=hvc0',
115 '-device', 'nvme,drive=drive0,bus=pcie.2,addr=0x0,serial=1234')
116 self.vm.launch()
117
118 # Wait for boot to complete
119 console_pattern = 'CPU maps initialized for 1 thread per core'
120 wait_for_console_pattern(self, console_pattern, self.panic_message)
121 console_pattern = 'smp: Brought up 4 nodes, 4 CPUs'
122 wait_for_console_pattern(self, console_pattern, self.panic_message)
123 wait_for_console_pattern(self, 'Run /sbin/init as init process',
124 self.panic_message)
125
126 # Wait for login prompt and login as root (no password in buildroot)
127 wait_for_console_pattern(self, 'login:', self.panic_message)
128 exec_command_and_wait_for_pattern(self, 'root', '#', self.panic_message)
129
130 # e1000e is connected to socket 1, disable the CPU on socket 1
131 self.shell_exec_command("echo 0 > /sys/devices/system/cpu/cpu1/online")
132 self.shell_exec_command(
133 "export CPU1_STATE=$(cat /sys/devices/system/cpu/cpu1/online)")
134 self.shell_exec_command_check_fail("[ $CPU1_STATE -eq 0 ]")
135
136 # RX, TX interrupts to chip/cpu 2 & 3 respectively
137 self.shell_exec_command(
138 "export RX_IRQ=$(awk '/eth0-rx/ {print $1}' /proc/interrupts | tr -d ':')")
139 self.shell_exec_command(
140 "export TX_IRQ=$(awk '/eth0-tx/ {print $1}' /proc/interrupts | tr -d ':')")
141 self.shell_exec_command("echo 2 > /proc/irq/$RX_IRQ/smp_affinity_list")
142 self.shell_exec_command("echo 3 > /proc/irq/$TX_IRQ/smp_affinity_list")
143
144 # Capture interrupt counts before generating traffic
145 self.shell_exec_command(
146 "export RX_BEFORE=$(awk '/eth0-rx/ {print $3}' /proc/interrupts)")
147 self.shell_exec_command(
148 "export TX_BEFORE=$(awk '/eth0-tx/ {print $4}' /proc/interrupts)")
149
150 # Wait up to 15 seconds for eth0 link to come up
151 self.shell_exec_command(
152 "c=0; while ! ip addr show eth0 | grep 'inet 10.0.2'; do "
153 "sleep 1; c=$((c+1)); [ $c -gt 15 ] && break; done")
154
155 self.shell_exec_command_check_fail(
156 "ip addr show eth0 | grep 'inet 10.0.2'")
157
158 # Generate network traffic to trigger remote interrupts
159 # Ping QEMU's user-mode network gateway (10.0.2.2)
160 self.shell_exec_command("ping -W2 -c5 10.0.2.2")
161
162 # Show final interrupt counts to verify remote interrupts occurred
163 self.shell_exec_command("cat /proc/interrupts | grep eth0")
164
165 # Verify interrupt counts increased (whether interrupts were delivered)
166 self.shell_exec_command(
167 "export RX_AFTER=$(awk '/eth0-rx/ {print $3}' /proc/interrupts)")
168 self.shell_exec_command(
169 "export TX_AFTER=$(awk '/eth0-tx/ {print $4}' /proc/interrupts)")
170
171 # Check that interrupt counts increased
172 self.shell_exec_command_check_fail("[ $RX_AFTER -gt $RX_BEFORE ]")
173 self.shell_exec_command_check_fail("[ $TX_AFTER -gt $TX_BEFORE ]")
174
175 def test_linux_big_boot(self):
176 self.set_machine('powernv')
177 self.vm.add_args('-smp', '16,threads=4,cores=2,sockets=2')
178
179 # powernv does not support NUMA
180 self.do_test_linux_boot()
181 console_pattern = 'CPU maps initialized for 4 threads per core'
182 wait_for_console_pattern(self, console_pattern, self.panic_message)
183 console_pattern = 'smp: Brought up 2 nodes, 16 CPUs'
184 wait_for_console_pattern(self, console_pattern, self.panic_message)
185 wait_for_console_pattern(self, self.good_message, self.panic_message)
186
187 def do_test_ppc64_powernv(self, proc):
188 self.require_accelerator("tcg")
189 kernel_path = self.ASSET_KERNEL.fetch()
190 initrd_path = self.ASSET_INITRD.fetch()
191 self.vm.set_console()
192 self.vm.add_args('-kernel', kernel_path,
193 '-drive',
194 f'file={initrd_path},format=raw,if=none,id=drive0,readonly=on',
195 '-append', 'root=/dev/nvme0n1 console=tty0 console=hvc0',
196 '-device', 'pcie-pci-bridge,id=bridge1,bus=pcie.1,addr=0x0',
197 '-device', 'nvme,drive=drive0,bus=pcie.2,addr=0x0,serial=1234',
198 '-device', 'e1000e,bus=bridge1,addr=0x3',
199 '-device', 'nec-usb-xhci,bus=bridge1,addr=0x2')
200 self.vm.launch()
201
202 self.wait_for_console_pattern("CPU: " + proc + " generation processor")
203 self.wait_for_console_pattern("INIT: Starting kernel at ")
204 self.wait_for_console_pattern("Run /sbin/init as init process")
205 # Device detection output driven by udev probing is sometimes cut off
206 # from console output, suspect S14silence-console init script.
207
208 def test_ppc64_powernv_external_dtb(self):
209 self.set_machine('powernv11')
210 self.require_accelerator("tcg")
211
212 kernel_path = self.ASSET_KERNEL.fetch()
213 sample_dtb_path = self.ASSET_SAMPLE_DTB.fetch()
214 self.vm.set_console()
215 self.vm.add_args('-kernel', kernel_path,
216 '-dtb', sample_dtb_path)
217 self.vm.launch()
218
219 # check if custom dtb is reflected or not
220 wait_for_console_pattern(self, "Kernel command line: hello world", self.panic_message)
221
222 def test_powernv8(self):
223 self.set_machine('powernv8')
224 self.do_test_ppc64_powernv('P8')
225
226 def test_powernv9(self):
227 self.set_machine('powernv9')
228 self.do_test_ppc64_powernv('P9')
229
230 def test_powernv10(self):
231 self.set_machine('powernv10')
232 self.do_test_ppc64_powernv('P10')
233
234 def test_powernv11(self):
235 self.set_machine('powernv11')
236 self.do_test_ppc64_powernv('Power11')
237
238 if __name__ == '__main__':
239 LinuxKernelTest.main()