1#!/usr/bin/env python3 2# 3# SPDX-License-Identifier: GPL-2.0-or-later 4# 5# LoongArch virt test. 6# 7# Copyright (c) 2023 Loongson Technology Corporation Limited 8# 9 10from qemu_test import QemuSystemTest, Asset 11from qemu_test import exec_command_and_wait_for_pattern 12from qemu_test import wait_for_console_pattern 13 14class LoongArchMachine(QemuSystemTest): 15 KERNEL_COMMON_COMMAND_LINE = 'printk.time=0 ' 16 17 timeout = 120 18 19 ASSET_KERNEL = Asset( 20 ('https://github.com/yangxiaojuan-loongson/qemu-binary/' 21 'releases/download/2024-05-30/vmlinuz.efi'), 22 '08b88a45f48a5fd92260bae895be4e5175be2397481a6f7821b9f39b2965b79e') 23 ASSET_INITRD = Asset( 24 ('https://github.com/yangxiaojuan-loongson/qemu-binary/' 25 'releases/download/2024-05-30/ramdisk'), 26 '03d6fb6f8ee64ecac961120a0bdacf741f17b3bee2141f17fa01908c8baf176a') 27 ASSET_BIOS = Asset( 28 ('https://github.com/yangxiaojuan-loongson/qemu-binary/' 29 'releases/download/2024-05-30/QEMU_EFI.fd'), 30 '937c1e7815e2340150c194a9f8f0474259038a3d7b8845ed62cc08163c46bea1') 31 32 def wait_for_console_pattern(self, success_message, vm=None): 33 wait_for_console_pattern(self, success_message, 34 failure_message='Kernel panic - not syncing', 35 vm=vm) 36 37 def test_loongarch64_devices(self): 38 39 self.set_machine('virt') 40 41 kernel_path = self.ASSET_KERNEL.fetch() 42 initrd_path = self.ASSET_INITRD.fetch() 43 bios_path = self.ASSET_BIOS.fetch() 44 45 self.vm.set_console() 46 kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + 47 'root=/dev/ram rdinit=/sbin/init console=ttyS0,115200') 48 self.vm.add_args('-nographic', 49 '-smp', '4', 50 '-m', '1024', 51 '-cpu', 'la464', 52 '-kernel', kernel_path, 53 '-initrd', initrd_path, 54 '-bios', bios_path, 55 '-append', kernel_command_line) 56 self.vm.launch() 57 self.wait_for_console_pattern('Run /sbin/init as init process') 58 exec_command_and_wait_for_pattern(self, 'cat /proc/cpuinfo', 59 'processor : 3') 60 61if __name__ == '__main__': 62 QemuSystemTest.main() 63