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