@samitouri / QOSamiQemu / commits / 94a75309f9

tests/qtest/migration: Add migration test on loongarch

Add migration qtest on loongarch64 system, the test passes to run with the following result: qemu:qtest+qtest-loongarch64/qtest-loongarch64/migration-test OK 15.94s 9 subtests passed Signed-off-by: Bibo Mao <maobibo@loongson.cn> Acked-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com> Link: https://lore.kernel.org/r/20260611084312.70042-1-maobibo@loongson.cn Signed-off-by: Peter Xu <peterx@redhat.com>

Bibo Mao committed Jun 11, 2026 at 16:43 UTC 94a75309f9281e614e9b390dc59c52e987f473da
9 files changed +106 -2
MAINTAINERS
+1
@@ -1359,6 +1359,7 @@ F: hw/intc/loongarch_*.c
1359 F: hw/intc/loongson_ipi_common.c
1360 F: hw/rtc/ls7a_rtc.c
1361 F: gdbstub/gdb-xml/loongarch*.xml
1362 +F: tests/qtest/migration/loongarch64/
1363
1364 M68K Machines
1365 -------------
tests/qtest/meson.build
+2 -1
@@ -155,7 +155,8 @@ qtests_loongarch64 = qtests_filter + \
155 (config_all_devices.has_key('CONFIG_LOONGARCH_VIRT') ? ['numa-test'] : []) + \
156 (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \
157 ['boot-serial-test',
158 - 'cpu-plug-test']
158 + 'cpu-plug-test',
159 + 'migration-test']
160
161 qtests_m68k = ['boot-serial-test'] + \
162 qtests_filter
tests/qtest/migration/Makefile
+3 -1
@@ -5,7 +5,7 @@
5 # See the COPYING file in the top-level directory.
6 #
7
8 -TARGET_LIST = i386 aarch64 s390x ppc64
8 +TARGET_LIST = i386 aarch64 s390x ppc64 loongarch64
9
10 SRC_PATH = ../../../..
11
@@ -23,6 +23,8 @@ help:
23 @echo " Possible targets are: $(TARGET_LIST)"
24
25 override define __note
26 +/* SPDX-License-Identifier: GPL-2.0-or-later */
27 +
28 /*
29 * This file is automatically generated from the assembly file in
30 * tests/qtest/migration/$@. Edit that file and then run "make"
tests/qtest/migration/bootfile.c
+4
@@ -19,6 +19,7 @@
19 #include "bootfile.h"
20 #include "i386/a-b-bootblock.h"
21 #include "aarch64/a-b-kernel.h"
22 +#include "loongarch64/a-b-kernel.h"
23 #include "ppc64/a-b-kernel.h"
24 #include "s390x/a-b-bios.h"
25
@@ -57,6 +58,9 @@ char *bootfile_create(const char *arch, const char *dir, bool suspend_me)
58 content = aarch64_kernel;
59 len = sizeof(aarch64_kernel);
60 g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
61 + } else if (strcmp(arch, "loongarch64") == 0) {
62 + content = loongarch64_kernel;
63 + len = sizeof(loongarch64_kernel);
64 } else {
65 g_assert_not_reached();
66 }
tests/qtest/migration/bootfile.h
+4
@@ -42,6 +42,10 @@
42 */
43 #define ARM_TEST_MAX_KERNEL_SIZE (512 * 1024)
44
45 +/* LoongArch64 */
46 +#define LOONGARCH_TEST_MEM_START (32 * 1024 * 1024)
47 +#define LOONGARCH_TEST_MEM_END (100 * 1024 * 1024)
48 +
49 #ifndef MIGRATION_GUEST_CODE
50 void bootfile_delete(void);
51 char *bootfile_create(const char *arch, const char *dir, bool suspend_me);
tests/qtest/migration/framework.c
+6
@@ -360,6 +360,12 @@ int migrate_args(char **from, char **to, MigrateStart *args)
360 arch_opts = g_strdup_printf("-cpu max -kernel %s", bootpath);
361 start_address = ARM_TEST_MEM_START;
362 end_address = ARM_TEST_MEM_END;
363 + } else if (strcmp(arch, "loongarch64") == 0) {
364 + memory_size = "256M";
365 + machine_alias = "virt";
366 + arch_opts = g_strdup_printf("-bios %s", bootpath);
367 + start_address = LOONGARCH_TEST_MEM_START;
368 + end_address = LOONGARCH_TEST_MEM_END;
369 } else {
370 g_assert_not_reached();
371 }
tests/qtest/migration/loongarch64/Makefile new
+20
@@ -0,0 +1,20 @@
1 +# SPDX-License-Identifier: GPL-2.0-or-later
2 +
3 +# To specify cross compiler prefix, use CROSS_PREFIX=
4 +# $ make CROSS_PREFIX=loongarch64-linux-gnu-
5 +
6 +.PHONY: all clean
7 +all: a-b-kernel.h
8 +
9 +a-b-kernel.h: loongarch64.kernel
10 + echo "$$__note" > $@
11 + xxd -i $< | sed -e 's/.*int.*//' >> $@
12 +
13 +loongarch64.kernel: loongarch64.elf
14 + $(CROSS_PREFIX)objcopy -j .text -O binary $< $@
15 +
16 +loongarch64.elf: a-b-kernel.S
17 + $(CROSS_PREFIX)gcc -o $@ -nostdlib -Wl,--build-id=none $<
18 +
19 +clean:
20 + $(RM) *.kernel *.elf
tests/qtest/migration/loongarch64/a-b-kernel.S new
+46
@@ -0,0 +1,46 @@
1 +/* SPDX-License-Identifier: GPL-2.0-or-later */
2 +
3 +#include "../bootfile.h"
4 +
5 +#define LOONGARCH_CSR_CRMD 0
6 +#define LOONGARCH_VIRT_UART 0x1FE001E0
7 +.section .text
8 +
9 + .globl _start
10 +_start:
11 + /* output char 'A' to UART16550 */
12 + li.d $t0, LOONGARCH_VIRT_UART
13 + li.w $t1, 'A'
14 + st.b $t1, $t0, 0
15 +
16 + /* traverse test memory region */
17 + li.d $t0, LOONGARCH_TEST_MEM_START
18 + li.d $t1, LOONGARCH_TEST_MEM_END
19 + li.d $t2, TEST_MEM_PAGE_SIZE
20 + li.d $t4, LOONGARCH_VIRT_UART
21 + li.w $t5, 'B'
22 +
23 +clean:
24 + st.b $zero, $t0, 0
25 + add.d $t0, $t0, $t2
26 + bne $t0, $t1, clean
27 + /* keeps a counter so we can limit the output speed */
28 + addi.d $t6, $zero, 0
29 +
30 +mainloop:
31 + li.d $t0, LOONGARCH_TEST_MEM_START
32 +
33 +innerloop:
34 + ld.bu $t3, $t0, 0
35 + addi.w $t3, $t3, 1
36 + ext.w.b $t3, $t3
37 + st.b $t3, $t0, 0
38 + add.d $t0, $t0, $t2
39 + bne $t0, $t1, innerloop
40 +
41 + addi.d $t6, $t6, 1
42 + andi $t6, $t6, 31
43 + bnez $t6, mainloop
44 +
45 + st.b $t5, $t4, 0
46 + b mainloop
tests/qtest/migration/loongarch64/a-b-kernel.h new
+20
@@ -0,0 +1,20 @@
1 +/* SPDX-License-Identifier: GPL-2.0-or-later */
2 +
3 +/*
4 + * This file is automatically generated from the assembly file in
5 + * tests/qtest/migration/loongarch64. Edit that file and then run "make"
6 + * inside tests/qtest/migration to update, and then remember to send both
7 + * the header and the assembler differences in your patch submission.
8 + */
9 +unsigned char loongarch64_kernel[] = {
10 + 0x0c, 0xc0, 0x3f, 0x14, 0x8c, 0x81, 0x87, 0x03, 0x0d, 0x04, 0x81, 0x03,
11 + 0x8d, 0x01, 0x00, 0x29, 0x0c, 0x00, 0x04, 0x14, 0x0d, 0x80, 0x0c, 0x14,
12 + 0x2e, 0x00, 0x00, 0x14, 0x10, 0xc0, 0x3f, 0x14, 0x10, 0x82, 0x87, 0x03,
13 + 0x11, 0x08, 0x81, 0x03, 0x80, 0x01, 0x00, 0x29, 0x8c, 0xb9, 0x10, 0x00,
14 + 0x8d, 0xf9, 0xff, 0x5f, 0x12, 0x00, 0xc0, 0x02, 0x0c, 0x00, 0x04, 0x14,
15 + 0x8f, 0x01, 0x00, 0x2a, 0xef, 0x05, 0x80, 0x02, 0xef, 0x5d, 0x00, 0x00,
16 + 0x8f, 0x01, 0x00, 0x29, 0x8c, 0xb9, 0x10, 0x00, 0x8d, 0xed, 0xff, 0x5f,
17 + 0x52, 0x06, 0xc0, 0x02, 0x52, 0x7e, 0x40, 0x03, 0x5f, 0xde, 0xff, 0x47,
18 + 0x11, 0x02, 0x00, 0x29, 0xff, 0xd7, 0xff, 0x53
19 +};
20 +