[PATCH 5/5] tests: Add migration test for loongarch64

Bibo Mao posted 5 patches 8 months, 3 weeks ago
Maintainers: Song Gao <gaosong@loongson.cn>, Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
There is a newer version of this series
[PATCH 5/5] tests: Add migration test for loongarch64
Posted by Bibo Mao 8 months, 3 weeks ago
This patch adds migration test support for loongarch64. The test code
comes from aarch64 mostly, only that it it booted as bios in qemu since
kernel requires elf format and bios uses binary format.

In addition to providing the binary, this patch also includes the source
code and the build script in tests/migration/loongarch64. So users can
change the source and/or re-compile the binary as they wish.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 tests/migration/Makefile                 |  2 +-
 tests/migration/loongarch64/Makefile     | 18 ++++++++++
 tests/migration/loongarch64/a-b-kernel.S | 46 ++++++++++++++++++++++++
 tests/migration/loongarch64/a-b-kernel.h | 13 +++++++
 tests/migration/migration-test.h         |  3 ++
 tests/qtest/meson.build                  |  4 +++
 tests/qtest/migration-test.c             | 10 ++++++
 7 files changed, 95 insertions(+), 1 deletion(-)
 create mode 100644 tests/migration/loongarch64/Makefile
 create mode 100644 tests/migration/loongarch64/a-b-kernel.S
 create mode 100644 tests/migration/loongarch64/a-b-kernel.h

diff --git a/tests/migration/Makefile b/tests/migration/Makefile
index 13e99b1692..cfebfe23f8 100644
--- a/tests/migration/Makefile
+++ b/tests/migration/Makefile
@@ -5,7 +5,7 @@
 # See the COPYING file in the top-level directory.
 #
 
-TARGET_LIST = i386 aarch64 s390x
+TARGET_LIST = i386 aarch64 s390x loongarch64
 
 SRC_PATH = ../..
 
diff --git a/tests/migration/loongarch64/Makefile b/tests/migration/loongarch64/Makefile
new file mode 100644
index 0000000000..5d8719205f
--- /dev/null
+++ b/tests/migration/loongarch64/Makefile
@@ -0,0 +1,18 @@
+# To specify cross compiler prefix, use CROSS_PREFIX=
+#   $ make CROSS_PREFIX=loongarch64-linux-gnu-
+
+.PHONY: all clean
+all: a-b-kernel.h
+
+a-b-kernel.h: loongarch64.kernel
+	echo "$$__note" > $@
+	xxd -i $< | sed -e 's/.*int.*//' >> $@
+
+loongarch64.kernel: loongarch64.elf
+	$(CROSS_PREFIX)objcopy -j .text -O binary $< $@
+
+loongarch64.elf: a-b-kernel.S
+	$(CROSS_PREFIX)gcc -o $@ -nostdlib -Wl,--build-id=none $<
+
+clean:
+	$(RM) *.kernel *.elf
diff --git a/tests/migration/loongarch64/a-b-kernel.S b/tests/migration/loongarch64/a-b-kernel.S
new file mode 100644
index 0000000000..078f91b306
--- /dev/null
+++ b/tests/migration/loongarch64/a-b-kernel.S
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2024 Loongson Technology Corporation Limited
+ */
+#include "../migration-test.h"
+
+#define LOONGARCH_CSR_CRMD          0
+#define LOONGARCH_VIRT_UART         0x1FE001E0
+.section .text
+
+        .globl  _start
+_start:
+        /* output char 'A' to UART16550 */
+        li.d    $t0, LOONGARCH_VIRT_UART
+        li.w    $t1, 'A'
+        st.b    $t1, $t0, 0
+
+        /* traverse test memory region */
+	li.d    $t0, LOONGARCH_TEST_MEM_START
+        li.d    $t1, LOONGARCH_TEST_MEM_END
+        li.d    $t2, TEST_MEM_PAGE_SIZE
+
+clean:
+        st.b    $zero, $t0, 0
+        add.d   $t0,   $t0, $t2
+        bne     $t0,   $t1, clean
+
+mainloop:
+        li.d    $t0, LOONGARCH_TEST_MEM_START
+        li.d    $t1, LOONGARCH_TEST_MEM_END
+        li.d    $t2, TEST_MEM_PAGE_SIZE
+
+        li.d    $t4, LOONGARCH_VIRT_UART
+        li.w    $t5, 'B'
+
+innerloop:
+        ld.bu   $t3, $t0, 0
+        addi.w  $t3, $t3, 1
+        ext.w.b $t3, $t3
+        st.b    $t3, $t0, 0
+        add.d   $t0, $t0, $t2
+        bne     $t0, $t1, innerloop
+
+        st.b    $t5, $t4, 0
+        b       mainloop
+        nop
diff --git a/tests/migration/loongarch64/a-b-kernel.h b/tests/migration/loongarch64/a-b-kernel.h
new file mode 100644
index 0000000000..6019450229
--- /dev/null
+++ b/tests/migration/loongarch64/a-b-kernel.h
@@ -0,0 +1,13 @@
+
+unsigned char loongarch64_kernel[] = {
+  0x0c, 0xc0, 0x3f, 0x14, 0x8c, 0x81, 0x87, 0x03, 0x0d, 0x04, 0x81, 0x03,
+  0x8d, 0x01, 0x00, 0x29, 0x0c, 0x00, 0x01, 0x14, 0x0d, 0x80, 0x0c, 0x14,
+  0x2e, 0x00, 0x00, 0x14, 0x80, 0x01, 0x00, 0x29, 0x8c, 0xb9, 0x10, 0x00,
+  0x8d, 0xf9, 0xff, 0x5f, 0x0c, 0x00, 0x01, 0x14, 0x0d, 0x80, 0x0c, 0x14,
+  0x2e, 0x00, 0x00, 0x14, 0x10, 0xc0, 0x3f, 0x14, 0x10, 0x82, 0x87, 0x03,
+  0x11, 0x08, 0x81, 0x03, 0x8f, 0x01, 0x00, 0x2a, 0xef, 0x05, 0x80, 0x02,
+  0xef, 0x5d, 0x00, 0x00, 0x8f, 0x01, 0x00, 0x29, 0x8c, 0xb9, 0x10, 0x00,
+  0x8d, 0xed, 0xff, 0x5f, 0x11, 0x02, 0x00, 0x29, 0xff, 0xcf, 0xff, 0x53,
+  0x00, 0x00, 0x40, 0x03
+};
+
diff --git a/tests/migration/migration-test.h b/tests/migration/migration-test.h
index 68512c0b1b..b6e9914f9c 100644
--- a/tests/migration/migration-test.h
+++ b/tests/migration/migration-test.h
@@ -32,4 +32,7 @@
  */
 #define ARM_TEST_MAX_KERNEL_SIZE (512 * 1024)
 
+/* LoongArch64 */
+#define LOONGARCH_TEST_MEM_START (8 * 1024 * 1024)
+#define LOONGARCH_TEST_MEM_END   (100 * 1024 * 1024)
 #endif /* MIGRATION_TEST_H */
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 2b89e8634b..b634587b0a 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -249,6 +249,10 @@ qtests_s390x = \
 qtests_riscv32 = \
   (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : [])
 
+qtests_loongarch64 = \
+  qtests_filter + \
+  ['migration-test']
+
 qos_test_ss = ss.source_set()
 qos_test_ss.add(
   'ac97-test.c',
diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
index 8a5bb1752e..8a25edfa77 100644
--- a/tests/qtest/migration-test.c
+++ b/tests/qtest/migration-test.c
@@ -132,6 +132,7 @@ static char *bootpath;
 #include "tests/migration/i386/a-b-bootblock.h"
 #include "tests/migration/aarch64/a-b-kernel.h"
 #include "tests/migration/s390x/a-b-bios.h"
+#include "tests/migration/loongarch64/a-b-kernel.h"
 
 static void bootfile_create(char *dir, bool suspend_me)
 {
@@ -158,6 +159,9 @@ static void bootfile_create(char *dir, bool suspend_me)
         content = aarch64_kernel;
         len = sizeof(aarch64_kernel);
         g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
+    } else if (strcmp(arch, "loongarch64") == 0) {
+        content = loongarch64_kernel;
+        len = sizeof(loongarch64_kernel);
     } else {
         g_assert_not_reached();
     }
@@ -823,6 +827,12 @@ static int test_migrate_start(QTestState **from, QTestState **to,
         arch_opts = g_strdup_printf("-cpu max -kernel %s", bootpath);
         start_address = ARM_TEST_MEM_START;
         end_address = ARM_TEST_MEM_END;
+    } else if (strcmp(arch, "loongarch64") == 0) {
+        memory_size = "256M";
+        machine_alias = "virt";
+        arch_opts = g_strdup_printf("-cpu max -bios %s", bootpath);
+        start_address = LOONGARCH_TEST_MEM_START;
+        end_address = LOONGARCH_TEST_MEM_END;
     } else {
         g_assert_not_reached();
     }
-- 
2.39.3
Re: [PATCH 5/5] tests: Add migration test for loongarch64
Posted by Fabiano Rosas 8 months, 3 weeks ago
Bibo Mao <maobibo@loongson.cn> writes:

> This patch adds migration test support for loongarch64. The test code
> comes from aarch64 mostly, only that it it booted as bios in qemu since
> kernel requires elf format and bios uses binary format.
>
> In addition to providing the binary, this patch also includes the source
> code and the build script in tests/migration/loongarch64. So users can
> change the source and/or re-compile the binary as they wish.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>

Just a nit below.

Reviewed-by: Fabiano Rosas <farosas@suse.de>

> ---
>  tests/migration/Makefile                 |  2 +-
>  tests/migration/loongarch64/Makefile     | 18 ++++++++++
>  tests/migration/loongarch64/a-b-kernel.S | 46 ++++++++++++++++++++++++
>  tests/migration/loongarch64/a-b-kernel.h | 13 +++++++
>  tests/migration/migration-test.h         |  3 ++
>  tests/qtest/meson.build                  |  4 +++
>  tests/qtest/migration-test.c             | 10 ++++++
>  7 files changed, 95 insertions(+), 1 deletion(-)
>  create mode 100644 tests/migration/loongarch64/Makefile
>  create mode 100644 tests/migration/loongarch64/a-b-kernel.S
>  create mode 100644 tests/migration/loongarch64/a-b-kernel.h
>
> diff --git a/tests/migration/Makefile b/tests/migration/Makefile
> index 13e99b1692..cfebfe23f8 100644
> --- a/tests/migration/Makefile
> +++ b/tests/migration/Makefile
> @@ -5,7 +5,7 @@
>  # See the COPYING file in the top-level directory.
>  #
>  
> -TARGET_LIST = i386 aarch64 s390x
> +TARGET_LIST = i386 aarch64 s390x loongarch64
>  
>  SRC_PATH = ../..
>  
> diff --git a/tests/migration/loongarch64/Makefile b/tests/migration/loongarch64/Makefile
> new file mode 100644
> index 0000000000..5d8719205f
> --- /dev/null
> +++ b/tests/migration/loongarch64/Makefile
> @@ -0,0 +1,18 @@
> +# To specify cross compiler prefix, use CROSS_PREFIX=
> +#   $ make CROSS_PREFIX=loongarch64-linux-gnu-
> +
> +.PHONY: all clean
> +all: a-b-kernel.h
> +
> +a-b-kernel.h: loongarch64.kernel
> +	echo "$$__note" > $@
> +	xxd -i $< | sed -e 's/.*int.*//' >> $@
> +
> +loongarch64.kernel: loongarch64.elf
> +	$(CROSS_PREFIX)objcopy -j .text -O binary $< $@
> +
> +loongarch64.elf: a-b-kernel.S
> +	$(CROSS_PREFIX)gcc -o $@ -nostdlib -Wl,--build-id=none $<
> +
> +clean:
> +	$(RM) *.kernel *.elf
> diff --git a/tests/migration/loongarch64/a-b-kernel.S b/tests/migration/loongarch64/a-b-kernel.S
> new file mode 100644
> index 0000000000..078f91b306
> --- /dev/null
> +++ b/tests/migration/loongarch64/a-b-kernel.S
> @@ -0,0 +1,46 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (c) 2024 Loongson Technology Corporation Limited
> + */
> +#include "../migration-test.h"
> +
> +#define LOONGARCH_CSR_CRMD          0
> +#define LOONGARCH_VIRT_UART         0x1FE001E0
> +.section .text
> +
> +        .globl  _start
> +_start:
> +        /* output char 'A' to UART16550 */
> +        li.d    $t0, LOONGARCH_VIRT_UART
> +        li.w    $t1, 'A'
> +        st.b    $t1, $t0, 0
> +
> +        /* traverse test memory region */
> +	li.d    $t0, LOONGARCH_TEST_MEM_START

Stray tab here.

> +        li.d    $t1, LOONGARCH_TEST_MEM_END
> +        li.d    $t2, TEST_MEM_PAGE_SIZE
> +
> +clean:
> +        st.b    $zero, $t0, 0
> +        add.d   $t0,   $t0, $t2
> +        bne     $t0,   $t1, clean
> +
> +mainloop:
> +        li.d    $t0, LOONGARCH_TEST_MEM_START
> +        li.d    $t1, LOONGARCH_TEST_MEM_END
> +        li.d    $t2, TEST_MEM_PAGE_SIZE
> +
> +        li.d    $t4, LOONGARCH_VIRT_UART
> +        li.w    $t5, 'B'
> +
> +innerloop:
> +        ld.bu   $t3, $t0, 0
> +        addi.w  $t3, $t3, 1
> +        ext.w.b $t3, $t3
> +        st.b    $t3, $t0, 0
> +        add.d   $t0, $t0, $t2
> +        bne     $t0, $t1, innerloop
> +
> +        st.b    $t5, $t4, 0
> +        b       mainloop
> +        nop
> diff --git a/tests/migration/loongarch64/a-b-kernel.h b/tests/migration/loongarch64/a-b-kernel.h
> new file mode 100644
> index 0000000000..6019450229
> --- /dev/null
> +++ b/tests/migration/loongarch64/a-b-kernel.h
> @@ -0,0 +1,13 @@
> +
> +unsigned char loongarch64_kernel[] = {
> +  0x0c, 0xc0, 0x3f, 0x14, 0x8c, 0x81, 0x87, 0x03, 0x0d, 0x04, 0x81, 0x03,
> +  0x8d, 0x01, 0x00, 0x29, 0x0c, 0x00, 0x01, 0x14, 0x0d, 0x80, 0x0c, 0x14,
> +  0x2e, 0x00, 0x00, 0x14, 0x80, 0x01, 0x00, 0x29, 0x8c, 0xb9, 0x10, 0x00,
> +  0x8d, 0xf9, 0xff, 0x5f, 0x0c, 0x00, 0x01, 0x14, 0x0d, 0x80, 0x0c, 0x14,
> +  0x2e, 0x00, 0x00, 0x14, 0x10, 0xc0, 0x3f, 0x14, 0x10, 0x82, 0x87, 0x03,
> +  0x11, 0x08, 0x81, 0x03, 0x8f, 0x01, 0x00, 0x2a, 0xef, 0x05, 0x80, 0x02,
> +  0xef, 0x5d, 0x00, 0x00, 0x8f, 0x01, 0x00, 0x29, 0x8c, 0xb9, 0x10, 0x00,
> +  0x8d, 0xed, 0xff, 0x5f, 0x11, 0x02, 0x00, 0x29, 0xff, 0xcf, 0xff, 0x53,
> +  0x00, 0x00, 0x40, 0x03
> +};
> +
> diff --git a/tests/migration/migration-test.h b/tests/migration/migration-test.h
> index 68512c0b1b..b6e9914f9c 100644
> --- a/tests/migration/migration-test.h
> +++ b/tests/migration/migration-test.h
> @@ -32,4 +32,7 @@
>   */
>  #define ARM_TEST_MAX_KERNEL_SIZE (512 * 1024)
>  
> +/* LoongArch64 */
> +#define LOONGARCH_TEST_MEM_START (8 * 1024 * 1024)
> +#define LOONGARCH_TEST_MEM_END   (100 * 1024 * 1024)
>  #endif /* MIGRATION_TEST_H */
> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
> index 2b89e8634b..b634587b0a 100644
> --- a/tests/qtest/meson.build
> +++ b/tests/qtest/meson.build
> @@ -249,6 +249,10 @@ qtests_s390x = \
>  qtests_riscv32 = \
>    (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : [])
>  
> +qtests_loongarch64 = \
> +  qtests_filter + \
> +  ['migration-test']
> +
>  qos_test_ss = ss.source_set()
>  qos_test_ss.add(
>    'ac97-test.c',
> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
> index 8a5bb1752e..8a25edfa77 100644
> --- a/tests/qtest/migration-test.c
> +++ b/tests/qtest/migration-test.c
> @@ -132,6 +132,7 @@ static char *bootpath;
>  #include "tests/migration/i386/a-b-bootblock.h"
>  #include "tests/migration/aarch64/a-b-kernel.h"
>  #include "tests/migration/s390x/a-b-bios.h"
> +#include "tests/migration/loongarch64/a-b-kernel.h"
>  
>  static void bootfile_create(char *dir, bool suspend_me)
>  {
> @@ -158,6 +159,9 @@ static void bootfile_create(char *dir, bool suspend_me)
>          content = aarch64_kernel;
>          len = sizeof(aarch64_kernel);
>          g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
> +    } else if (strcmp(arch, "loongarch64") == 0) {
> +        content = loongarch64_kernel;
> +        len = sizeof(loongarch64_kernel);
>      } else {
>          g_assert_not_reached();
>      }
> @@ -823,6 +827,12 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>          arch_opts = g_strdup_printf("-cpu max -kernel %s", bootpath);
>          start_address = ARM_TEST_MEM_START;
>          end_address = ARM_TEST_MEM_END;
> +    } else if (strcmp(arch, "loongarch64") == 0) {
> +        memory_size = "256M";
> +        machine_alias = "virt";
> +        arch_opts = g_strdup_printf("-cpu max -bios %s", bootpath);
> +        start_address = LOONGARCH_TEST_MEM_START;
> +        end_address = LOONGARCH_TEST_MEM_END;
>      } else {
>          g_assert_not_reached();
>      }
Re: [PATCH 5/5] tests: Add migration test for loongarch64
Posted by maobibo 8 months, 3 weeks ago

On 2024/2/22 上午5:24, Fabiano Rosas wrote:
> Bibo Mao <maobibo@loongson.cn> writes:
> 
>> This patch adds migration test support for loongarch64. The test code
>> comes from aarch64 mostly, only that it it booted as bios in qemu since
>> kernel requires elf format and bios uses binary format.
>>
>> In addition to providing the binary, this patch also includes the source
>> code and the build script in tests/migration/loongarch64. So users can
>> change the source and/or re-compile the binary as they wish.
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> 
> Just a nit below.
> 
> Reviewed-by: Fabiano Rosas <farosas@suse.de>
> 
>> ---
>>   tests/migration/Makefile                 |  2 +-
>>   tests/migration/loongarch64/Makefile     | 18 ++++++++++
>>   tests/migration/loongarch64/a-b-kernel.S | 46 ++++++++++++++++++++++++
>>   tests/migration/loongarch64/a-b-kernel.h | 13 +++++++
>>   tests/migration/migration-test.h         |  3 ++
>>   tests/qtest/meson.build                  |  4 +++
>>   tests/qtest/migration-test.c             | 10 ++++++
>>   7 files changed, 95 insertions(+), 1 deletion(-)
>>   create mode 100644 tests/migration/loongarch64/Makefile
>>   create mode 100644 tests/migration/loongarch64/a-b-kernel.S
>>   create mode 100644 tests/migration/loongarch64/a-b-kernel.h
>>
>> diff --git a/tests/migration/Makefile b/tests/migration/Makefile
>> index 13e99b1692..cfebfe23f8 100644
>> --- a/tests/migration/Makefile
>> +++ b/tests/migration/Makefile
>> @@ -5,7 +5,7 @@
>>   # See the COPYING file in the top-level directory.
>>   #
>>   
>> -TARGET_LIST = i386 aarch64 s390x
>> +TARGET_LIST = i386 aarch64 s390x loongarch64
>>   
>>   SRC_PATH = ../..
>>   
>> diff --git a/tests/migration/loongarch64/Makefile b/tests/migration/loongarch64/Makefile
>> new file mode 100644
>> index 0000000000..5d8719205f
>> --- /dev/null
>> +++ b/tests/migration/loongarch64/Makefile
>> @@ -0,0 +1,18 @@
>> +# To specify cross compiler prefix, use CROSS_PREFIX=
>> +#   $ make CROSS_PREFIX=loongarch64-linux-gnu-
>> +
>> +.PHONY: all clean
>> +all: a-b-kernel.h
>> +
>> +a-b-kernel.h: loongarch64.kernel
>> +	echo "$$__note" > $@
>> +	xxd -i $< | sed -e 's/.*int.*//' >> $@
>> +
>> +loongarch64.kernel: loongarch64.elf
>> +	$(CROSS_PREFIX)objcopy -j .text -O binary $< $@
>> +
>> +loongarch64.elf: a-b-kernel.S
>> +	$(CROSS_PREFIX)gcc -o $@ -nostdlib -Wl,--build-id=none $<
>> +
>> +clean:
>> +	$(RM) *.kernel *.elf
>> diff --git a/tests/migration/loongarch64/a-b-kernel.S b/tests/migration/loongarch64/a-b-kernel.S
>> new file mode 100644
>> index 0000000000..078f91b306
>> --- /dev/null
>> +++ b/tests/migration/loongarch64/a-b-kernel.S
>> @@ -0,0 +1,46 @@
>> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> +/*
>> + * Copyright (c) 2024 Loongson Technology Corporation Limited
>> + */
>> +#include "../migration-test.h"
>> +
>> +#define LOONGARCH_CSR_CRMD          0
>> +#define LOONGARCH_VIRT_UART         0x1FE001E0
>> +.section .text
>> +
>> +        .globl  _start
>> +_start:
>> +        /* output char 'A' to UART16550 */
>> +        li.d    $t0, LOONGARCH_VIRT_UART
>> +        li.w    $t1, 'A'
>> +        st.b    $t1, $t0, 0
>> +
>> +        /* traverse test memory region */
>> +	li.d    $t0, LOONGARCH_TEST_MEM_START
> 
> Stray tab here.
Good catch, there is tab here. Will fix it in next version.

Regards
Bibo Mao
> 
>> +        li.d    $t1, LOONGARCH_TEST_MEM_END
>> +        li.d    $t2, TEST_MEM_PAGE_SIZE
>> +
>> +clean:
>> +        st.b    $zero, $t0, 0
>> +        add.d   $t0,   $t0, $t2
>> +        bne     $t0,   $t1, clean
>> +
>> +mainloop:
>> +        li.d    $t0, LOONGARCH_TEST_MEM_START
>> +        li.d    $t1, LOONGARCH_TEST_MEM_END
>> +        li.d    $t2, TEST_MEM_PAGE_SIZE
>> +
>> +        li.d    $t4, LOONGARCH_VIRT_UART
>> +        li.w    $t5, 'B'
>> +
>> +innerloop:
>> +        ld.bu   $t3, $t0, 0
>> +        addi.w  $t3, $t3, 1
>> +        ext.w.b $t3, $t3
>> +        st.b    $t3, $t0, 0
>> +        add.d   $t0, $t0, $t2
>> +        bne     $t0, $t1, innerloop
>> +
>> +        st.b    $t5, $t4, 0
>> +        b       mainloop
>> +        nop
>> diff --git a/tests/migration/loongarch64/a-b-kernel.h b/tests/migration/loongarch64/a-b-kernel.h
>> new file mode 100644
>> index 0000000000..6019450229
>> --- /dev/null
>> +++ b/tests/migration/loongarch64/a-b-kernel.h
>> @@ -0,0 +1,13 @@
>> +
>> +unsigned char loongarch64_kernel[] = {
>> +  0x0c, 0xc0, 0x3f, 0x14, 0x8c, 0x81, 0x87, 0x03, 0x0d, 0x04, 0x81, 0x03,
>> +  0x8d, 0x01, 0x00, 0x29, 0x0c, 0x00, 0x01, 0x14, 0x0d, 0x80, 0x0c, 0x14,
>> +  0x2e, 0x00, 0x00, 0x14, 0x80, 0x01, 0x00, 0x29, 0x8c, 0xb9, 0x10, 0x00,
>> +  0x8d, 0xf9, 0xff, 0x5f, 0x0c, 0x00, 0x01, 0x14, 0x0d, 0x80, 0x0c, 0x14,
>> +  0x2e, 0x00, 0x00, 0x14, 0x10, 0xc0, 0x3f, 0x14, 0x10, 0x82, 0x87, 0x03,
>> +  0x11, 0x08, 0x81, 0x03, 0x8f, 0x01, 0x00, 0x2a, 0xef, 0x05, 0x80, 0x02,
>> +  0xef, 0x5d, 0x00, 0x00, 0x8f, 0x01, 0x00, 0x29, 0x8c, 0xb9, 0x10, 0x00,
>> +  0x8d, 0xed, 0xff, 0x5f, 0x11, 0x02, 0x00, 0x29, 0xff, 0xcf, 0xff, 0x53,
>> +  0x00, 0x00, 0x40, 0x03
>> +};
>> +
>> diff --git a/tests/migration/migration-test.h b/tests/migration/migration-test.h
>> index 68512c0b1b..b6e9914f9c 100644
>> --- a/tests/migration/migration-test.h
>> +++ b/tests/migration/migration-test.h
>> @@ -32,4 +32,7 @@
>>    */
>>   #define ARM_TEST_MAX_KERNEL_SIZE (512 * 1024)
>>   
>> +/* LoongArch64 */
>> +#define LOONGARCH_TEST_MEM_START (8 * 1024 * 1024)
>> +#define LOONGARCH_TEST_MEM_END   (100 * 1024 * 1024)
>>   #endif /* MIGRATION_TEST_H */
>> diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
>> index 2b89e8634b..b634587b0a 100644
>> --- a/tests/qtest/meson.build
>> +++ b/tests/qtest/meson.build
>> @@ -249,6 +249,10 @@ qtests_s390x = \
>>   qtests_riscv32 = \
>>     (config_all_devices.has_key('CONFIG_SIFIVE_E_AON') ? ['sifive-e-aon-watchdog-test'] : [])
>>   
>> +qtests_loongarch64 = \
>> +  qtests_filter + \
>> +  ['migration-test']
>> +
>>   qos_test_ss = ss.source_set()
>>   qos_test_ss.add(
>>     'ac97-test.c',
>> diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c
>> index 8a5bb1752e..8a25edfa77 100644
>> --- a/tests/qtest/migration-test.c
>> +++ b/tests/qtest/migration-test.c
>> @@ -132,6 +132,7 @@ static char *bootpath;
>>   #include "tests/migration/i386/a-b-bootblock.h"
>>   #include "tests/migration/aarch64/a-b-kernel.h"
>>   #include "tests/migration/s390x/a-b-bios.h"
>> +#include "tests/migration/loongarch64/a-b-kernel.h"
>>   
>>   static void bootfile_create(char *dir, bool suspend_me)
>>   {
>> @@ -158,6 +159,9 @@ static void bootfile_create(char *dir, bool suspend_me)
>>           content = aarch64_kernel;
>>           len = sizeof(aarch64_kernel);
>>           g_assert(sizeof(aarch64_kernel) <= ARM_TEST_MAX_KERNEL_SIZE);
>> +    } else if (strcmp(arch, "loongarch64") == 0) {
>> +        content = loongarch64_kernel;
>> +        len = sizeof(loongarch64_kernel);
>>       } else {
>>           g_assert_not_reached();
>>       }
>> @@ -823,6 +827,12 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>>           arch_opts = g_strdup_printf("-cpu max -kernel %s", bootpath);
>>           start_address = ARM_TEST_MEM_START;
>>           end_address = ARM_TEST_MEM_END;
>> +    } else if (strcmp(arch, "loongarch64") == 0) {
>> +        memory_size = "256M";
>> +        machine_alias = "virt";
>> +        arch_opts = g_strdup_printf("-cpu max -bios %s", bootpath);
>> +        start_address = LOONGARCH_TEST_MEM_START;
>> +        end_address = LOONGARCH_TEST_MEM_END;
>>       } else {
>>           g_assert_not_reached();
>>       }


Re: [PATCH 5/5] tests: Add migration test for loongarch64
Posted by Peter Xu 8 months, 3 weeks ago
On Tue, Feb 20, 2024 at 08:41:26PM +0800, Bibo Mao wrote:
> @@ -823,6 +827,12 @@ static int test_migrate_start(QTestState **from, QTestState **to,
>          arch_opts = g_strdup_printf("-cpu max -kernel %s", bootpath);
>          start_address = ARM_TEST_MEM_START;
>          end_address = ARM_TEST_MEM_END;
> +    } else if (strcmp(arch, "loongarch64") == 0) {
> +        memory_size = "256M";
> +        machine_alias = "virt";
> +        arch_opts = g_strdup_printf("-cpu max -bios %s", bootpath);
> +        start_address = LOONGARCH_TEST_MEM_START;
> +        end_address = LOONGARCH_TEST_MEM_END;
>      } else {
>          g_assert_not_reached();
>      }

Acked-by: Peter Xu <peterx@redhat.com>

One thing to mention is that Fabiano recently added a compatibility test
for old qemu binaries, in which we would prefer any tests in
migration-test.c to use stable qemu cmdline ABI (IOW, avoid using
"max"/"virt" if any of them can change its abi in newer QEMU binaries).

It's not a problem for now, but only a problem if loongarch also wants to
enable it some day.  More of a heads-up.  Feel free to see
migration-compat-x86_64 in .gitlab-ci.d/buildtest.yml for more info;
currently it's only enabled on x86_64.  Comment above
migration-compat-aarch64 explains what's missing for arm, which is similar.

Thanks,

-- 
Peter Xu
Re: [PATCH 5/5] tests: Add migration test for loongarch64
Posted by Thomas Huth 8 months, 3 weeks ago
On 20/02/2024 13.41, Bibo Mao wrote:
> This patch adds migration test support for loongarch64. The test code
> comes from aarch64 mostly, only that it it booted as bios in qemu since
> kernel requires elf format and bios uses binary format.
> 
> In addition to providing the binary, this patch also includes the source
> code and the build script in tests/migration/loongarch64. So users can
> change the source and/or re-compile the binary as they wish.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   tests/migration/Makefile                 |  2 +-
>   tests/migration/loongarch64/Makefile     | 18 ++++++++++
>   tests/migration/loongarch64/a-b-kernel.S | 46 ++++++++++++++++++++++++
>   tests/migration/loongarch64/a-b-kernel.h | 13 +++++++
>   tests/migration/migration-test.h         |  3 ++
>   tests/qtest/meson.build                  |  4 +++
>   tests/qtest/migration-test.c             | 10 ++++++
>   7 files changed, 95 insertions(+), 1 deletion(-)
>   create mode 100644 tests/migration/loongarch64/Makefile
>   create mode 100644 tests/migration/loongarch64/a-b-kernel.S
>   create mode 100644 tests/migration/loongarch64/a-b-kernel.h

FWIW:
Acked-by: Thomas Huth <thuth@redhat.com>