From: George Guo <[email protected]> On LoongArch, QEMU provides only a minimal EFI stub with no runtime services and no ACPI tables, so machine_restart() falls through to its infinite idle loop and QEMU never exits after kexec.
Poll the serial output for the test verdict and kill QEMU once it appears, rather than waiting for QEMU to exit naturally. Signed-off-by: George Guo <[email protected]> --- tools/testing/selftests/kho/vmtest.sh | 35 +++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kho/vmtest.sh b/tools/testing/selftests/kho/vmtest.sh index a6ae9ac09595..3cb9674e4475 100755 --- a/tools/testing/selftests/kho/vmtest.sh +++ b/tools/testing/selftests/kho/vmtest.sh @@ -103,16 +103,37 @@ function run_qemu() { local qemu_cmd=$1 local cmdline=$2 local kernel=$3 + local arch=$4 local serial="$tmp_dir/qemu.serial" cmdline="$cmdline kho=on panic=-1" - $qemu_cmd -m 1G -smp 2 -no-reboot -nographic -nodefaults \ - -accel kvm -accel hvf -accel tcg \ - -serial file:"$serial" \ - -append "$cmdline" \ - -kernel "$kernel" \ - -initrd "$initrd" + local qemu_args=( + -m 1G -smp 2 -no-reboot -nographic -nodefaults + -accel kvm -accel hvf -accel tcg + -serial file:"$serial" + -append "$cmdline" + -kernel "$kernel" + -initrd "$initrd" + ) + + # On LoongArch, EFI runtime services are unavailable after kexec so + # machine_restart() hangs and QEMU never exits on its own. Run QEMU + # in the background, poll for the test result, then kill it. + if [[ "$arch" == "loongarch" ]]; then + $qemu_cmd "${qemu_args[@]}" & + local qemu_pid=$! + local timeout=100 + while ((timeout-- > 0)); do + grep -q "KHO restore succeeded\|KHO restore failed" \ + "$serial" 2>/dev/null && break + sleep 1 + done + kill "$qemu_pid" 2>/dev/null + wait "$qemu_pid" 2>/dev/null || true + else + $qemu_cmd "${qemu_args[@]}" + fi grep "KHO restore succeeded" "$serial" &> /dev/null || fail "KHO failed" } @@ -179,7 +200,7 @@ function main() { local kernel="$build_dir/arch/$arch/boot/$KERNEL_IMAGE" mkinitrd "$kernel" - run_qemu "$QEMU_CMD" "$KERNEL_CMDLINE" "$kernel" + run_qemu "$QEMU_CMD" "$KERNEL_CMDLINE" "$kernel" "$arch" ktap_test_pass "KHO succeeded" } -- 2.25.1

