From 26d63f7864341a6ce254449209bd7b8069b4ee45 Mon Sep 17 00:00:00 2001
From: Xianglai Li <lixianglai@loongson.cn>
Date: Wed, 28 Feb 2024 02:16:23 -0500
Subject: [PATCH 4/4] Add test cases for loongarch

Add some basic test cases for loongarch.

Signed-off-by: Xianglai Li <lixianglai@loongson.cn>
---
 .../capabilities/kvm-loongarch64-domcaps.xml  | 167 ++++++++++++++++++
 tests/data/capabilities/kvm-loongarch64.xml   |  28 +++
 .../virt-install-kvm-loongarch64-basic.xml    |  99 +++++++++++
 tests/test_cli.py                             |   8 +
 tests/utils.py                                |   1 +
 5 files changed, 303 insertions(+)
 create mode 100644 tests/data/capabilities/kvm-loongarch64-domcaps.xml
 create mode 100644 tests/data/capabilities/kvm-loongarch64.xml
 create mode 100644 tests/data/cli/compare/virt-install-kvm-loongarch64-basic.xml

diff --git a/tests/data/capabilities/kvm-loongarch64-domcaps.xml b/tests/data/capabilities/kvm-loongarch64-domcaps.xml
new file mode 100644
index 0000000..2013da3
--- /dev/null
+++ b/tests/data/capabilities/kvm-loongarch64-domcaps.xml
@@ -0,0 +1,167 @@
+<domainCapabilities>
+  <path>/usr/bin/qemu-system-loongarch64</path>
+  <domain>kvm</domain>
+  <machine>virt</machine>
+  <arch>loongarch64</arch>
+  <vcpu max='256'/>
+  <iothreads supported='yes'/>
+  <os supported='yes'>
+    <enum name='firmware'/>
+    <loader supported='yes'>
+      <value>/obviously/fake/firmware1.fd</value>
+      <value>/obviously/fake/firmware2.fd</value>
+      <enum name='type'>
+        <value>rom</value>
+        <value>pflash</value>
+      </enum>
+      <enum name='readonly'>
+        <value>yes</value>
+        <value>no</value>
+      </enum>
+      <enum name='secure'>
+        <value>no</value>
+      </enum>
+    </loader>
+  </os>
+  <cpu>
+    <mode name='host-passthrough' supported='yes'>
+      <enum name='hostPassthroughMigratable'>
+        <value>off</value>
+      </enum>
+    </mode>
+    <mode name='maximum' supported='yes'>
+      <enum name='maximumMigratable'>
+        <value>on</value>
+        <value>off</value>
+      </enum>
+    </mode>
+    <mode name='host-model' supported='no'/>
+    <mode name='custom' supported='yes'>
+      <model usable='unknown' vendor='unknown'>la132</model>
+      <model usable='unknown' vendor='unknown'>la464</model>
+      <model usable='unknown' vendor='unknown'>max</model>
+    </mode>
+  </cpu>
+  <memoryBacking supported='yes'>
+    <enum name='sourceType'>
+      <value>file</value>
+      <value>anonymous</value>
+      <value>memfd</value>
+    </enum>
+  </memoryBacking>
+  <devices>
+    <disk supported='yes'>
+      <enum name='diskDevice'>
+        <value>disk</value>
+        <value>cdrom</value>
+        <value>floppy</value>
+        <value>lun</value>
+      </enum>
+      <enum name='bus'>
+        <value>fdc</value>
+        <value>scsi</value>
+        <value>virtio</value>
+        <value>usb</value>
+        <value>sata</value>
+      </enum>
+      <enum name='model'>
+        <value>virtio</value>
+        <value>virtio-transitional</value>
+        <value>virtio-non-transitional</value>
+      </enum>
+    </disk>
+    <graphics supported='yes'>
+      <enum name='type'>
+        <value>sdl</value>
+        <value>vnc</value>
+        <value>spice</value>
+        <value>dbus</value>
+      </enum>
+    </graphics>
+    <video supported='yes'>
+      <enum name='modelType'>
+        <value>vga</value>
+        <value>cirrus</value>
+        <value>virtio</value>
+        <value>none</value>
+        <value>bochs</value>
+        <value>ramfb</value>
+      </enum>
+    </video>
+    <hostdev supported='yes'>
+      <enum name='mode'>
+        <value>subsystem</value>
+      </enum>
+      <enum name='startupPolicy'>
+        <value>default</value>
+        <value>mandatory</value>
+        <value>requisite</value>
+        <value>optional</value>
+      </enum>
+      <enum name='subsysType'>
+        <value>usb</value>
+        <value>pci</value>
+        <value>scsi</value>
+      </enum>
+      <enum name='capsType'/>
+      <enum name='pciBackend'>
+        <value>default</value>
+        <value>vfio</value>
+      </enum>
+    </hostdev>
+    <rng supported='yes'>
+      <enum name='model'>
+        <value>virtio</value>
+        <value>virtio-transitional</value>
+        <value>virtio-non-transitional</value>
+      </enum>
+      <enum name='backendModel'>
+        <value>random</value>
+        <value>egd</value>
+        <value>builtin</value>
+      </enum>
+    </rng>
+    <filesystem supported='yes'>
+      <enum name='driverType'>
+        <value>path</value>
+        <value>handle</value>
+        <value>virtiofs</value>
+      </enum>
+    </filesystem>
+    <tpm supported='no'/>
+    <redirdev supported='yes'>
+      <enum name='bus'>
+        <value>usb</value>
+      </enum>
+    </redirdev>
+    <channel supported='yes'>
+      <enum name='type'>
+        <value>pty</value>
+        <value>unix</value>
+        <value>spicevmc</value>
+      </enum>
+    </channel>
+    <crypto supported='yes'>
+      <enum name='model'>
+        <value>virtio</value>
+      </enum>
+      <enum name='type'>
+        <value>qemu</value>
+      </enum>
+      <enum name='backendModel'>
+        <value>builtin</value>
+        <value>lkcf</value>
+      </enum>
+    </crypto>
+  </devices>
+  <features>
+    <gic supported='no'/>
+    <vmcoreinfo supported='yes'/>
+    <genid supported='no'/>
+    <backingStoreInput supported='yes'/>
+    <backup supported='yes'/>
+    <async-teardown supported='yes'/>
+    <sev supported='no'/>
+    <sgx supported='no'/>
+  </features>
+</domainCapabilities>
diff --git a/tests/data/capabilities/kvm-loongarch64.xml b/tests/data/capabilities/kvm-loongarch64.xml
new file mode 100644
index 0000000..c15d4d9
--- /dev/null
+++ b/tests/data/capabilities/kvm-loongarch64.xml
@@ -0,0 +1,28 @@
+<capabilities>
+
+  <host>
+    <cpu>
+      <arch>loongarch64</arch>
+    </cpu>
+    <power_management/>
+    <iommu support='no'/>
+  </host>
+
+  <guest>
+    <os_type>hvm</os_type>
+    <arch name='loongarch64'>
+      <wordsize>64</wordsize>
+      <emulator>/usr/bin/qemu-system-loongarch64</emulator>
+      <domain type='qemu'/>
+      <domain type='kvm'/>
+    </arch>
+    <features>
+      <acpi default='on' toggle='yes'/>
+      <cpuselection/>
+      <deviceboot/>
+      <disksnapshot default='on' toggle='no'/>
+      <externalSnapshot/>
+    </features>
+  </guest>
+
+</capabilities>
diff --git a/tests/data/cli/compare/virt-install-kvm-loongarch64-basic.xml b/tests/data/cli/compare/virt-install-kvm-loongarch64-basic.xml
new file mode 100644
index 0000000..83444ba
--- /dev/null
+++ b/tests/data/cli/compare/virt-install-kvm-loongarch64-basic.xml
@@ -0,0 +1,99 @@
+<domain type="kvm">
+  <name>fedora19</name>
+  <uuid>00000000-1111-2222-3333-444444444444</uuid>
+  <metadata>
+    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+      <libosinfo:os id="http://fedoraproject.org/fedora/19"/>
+    </libosinfo:libosinfo>
+  </metadata>
+  <memory>65536</memory>
+  <currentMemory>65536</currentMemory>
+  <vcpu>2</vcpu>
+  <os>
+    <type arch="loongarch64">hvm</type>
+    <boot dev="network"/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <cpu mode="custom" match="exact">
+    <model>la464</model>
+  </cpu>
+  <clock offset="utc"/>
+  <devices>
+    <emulator>/usr/bin/qemu-system-loongarch64</emulator>
+    <controller type="usb" model="qemu-xhci" ports="15"/>
+    <interface type="bridge">
+      <source bridge="testsuitebr0"/>
+      <mac address="00:11:22:33:44:55"/>
+      <model type="virtio"/>
+    </interface>
+    <console type="pty"/>
+    <channel type="unix">
+      <source mode="bind"/>
+      <target type="virtio" name="org.qemu.guest_agent.0"/>
+    </channel>
+    <channel type="spicevmc">
+      <target type="virtio" name="com.redhat.spice.0"/>
+    </channel>
+    <input type="tablet" bus="usb"/>
+    <input type="keyboard" bus="usb"/>
+    <graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
+      <image compression="off"/>
+    </graphics>
+    <sound model="ich6"/>
+    <video>
+      <model type="virtio"/>
+    </video>
+  </devices>
+  <on_reboot>destroy</on_reboot>
+</domain>
+<domain type="kvm">
+  <name>fedora19</name>
+  <uuid>00000000-1111-2222-3333-444444444444</uuid>
+  <metadata>
+    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+      <libosinfo:os id="http://fedoraproject.org/fedora/19"/>
+    </libosinfo:libosinfo>
+  </metadata>
+  <memory>65536</memory>
+  <currentMemory>65536</currentMemory>
+  <vcpu>2</vcpu>
+  <os>
+    <type arch="loongarch64">hvm</type>
+    <boot dev="network"/>
+  </os>
+  <features>
+    <acpi/>
+  </features>
+  <cpu mode="custom" match="exact">
+    <model>la464</model>
+  </cpu>
+  <clock offset="utc"/>
+  <devices>
+    <emulator>/usr/bin/qemu-system-loongarch64</emulator>
+    <controller type="usb" model="qemu-xhci" ports="15"/>
+    <interface type="bridge">
+      <source bridge="testsuitebr0"/>
+      <mac address="00:11:22:33:44:55"/>
+      <model type="virtio"/>
+    </interface>
+    <console type="pty"/>
+    <channel type="unix">
+      <source mode="bind"/>
+      <target type="virtio" name="org.qemu.guest_agent.0"/>
+    </channel>
+    <channel type="spicevmc">
+      <target type="virtio" name="com.redhat.spice.0"/>
+    </channel>
+    <input type="tablet" bus="usb"/>
+    <input type="keyboard" bus="usb"/>
+    <graphics type="spice" port="-1" tlsPort="-1" autoport="yes">
+      <image compression="off"/>
+    </graphics>
+    <sound model="ich6"/>
+    <video>
+      <model type="virtio"/>
+    </video>
+  </devices>
+</domain>
diff --git a/tests/test_cli.py b/tests/test_cli.py
index 774db09..65123f5 100644
--- a/tests/test_cli.py
+++ b/tests/test_cli.py
@@ -1179,6 +1179,14 @@ c.add_compare("--connect %(URI-KVM-AARCH64)s --osinfo fedora30 --arch aarch64 --
 
 
 
+#####################
+# loongarch64 tests #
+#####################
+
+c.add_compare("--osinfo fedora19 --nodisks --pxe --connect " + utils.URIs.kvm_loongarch64, "kvm-loongarch64-basic")
+
+
+
 #################
 # AMD sev tests #
 #################
diff --git a/tests/utils.py b/tests/utils.py
index 5c813f6..6d91a14 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -105,6 +105,7 @@ class _URIs(object):
         self.kvm_ppc64le = _uri_qemu + _caps("kvm-ppc64le.xml") + _domcaps("kvm-ppc64le-domcaps.xml")
         self.kvm_s390x = _uri_qemu + _caps("kvm-s390x.xml") + _domcaps("kvm-s390x-domcaps.xml")
         self.qemu_riscv64 = _uri_qemu + _caps("qemu-riscv64.xml") + _domcaps("qemu-riscv64-domcaps.xml")
+        self.kvm_loongarch64 = _uri_qemu + _caps("kvm-loongarch64.xml") + _domcaps("kvm-loongarch64-domcaps.xml")
 
 
 
-- 
2.27.0