>From dd4239cedaa125b6a9a50428d82a0b78eed9d38a Mon Sep 17 00:00:00 2001
From: Jim Fehlig <jfehlig@suse.com>
Date: Fri, 10 Nov 2017 13:03:16 -0700
Subject: [PATCH 5/5] libxlxml2domconfigtest: add test for vNUMA config

From: Wim ten Have <wim.ten.have@oracle.com>

Add tests to ensure the libxl_domain_config generator properly
handles vNUMA configuration.

Signed-off-by: Wim ten Have <wim.ten.have@oracle.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
---
 tests/libxlxml2domconfigdata/vnuma-hvm.json | 178 ++++++++++++++++++++++++++++
 tests/libxlxml2domconfigdata/vnuma-hvm.xml  | 100 ++++++++++++++++
 tests/libxlxml2domconfigtest.c              |   1 +
 tests/virmocklibxl.c                        |  13 ++
 4 files changed, 292 insertions(+)

diff --git a/tests/libxlxml2domconfigdata/vnuma-hvm.json b/tests/libxlxml2domconfigdata/vnuma-hvm.json
new file mode 100644
index 000000000..3a5071e14
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/vnuma-hvm.json
@@ -0,0 +1,178 @@
+{
+    "c_info": {
+        "type": "hvm",
+        "name": "test-hvm",
+        "uuid": "2147d599-9cc6-c0dc-92ab-4064b5446e9b"
+    },
+    "b_info": {
+        "max_vcpus": 6,
+        "avail_vcpus": [
+            0,
+            1,
+            2,
+            3,
+            4,
+            5
+        ],
+        "vnuma_nodes": [
+            {
+                "memkb": 2097152,
+                "distances": [
+                    10,
+                    21,
+                    31,
+                    41,
+                    51,
+                    61
+                ],
+                "vcpus": [
+                    0
+                ]
+            },
+            {
+                "memkb": 2097152,
+                "distances": [
+                    21,
+                    10,
+                    21,
+                    31,
+                    41,
+                    51
+                ],
+                "vcpus": [
+                    1
+                ]
+            },
+            {
+                "memkb": 2097152,
+                "distances": [
+                    31,
+                    21,
+                    10,
+                    21,
+                    31,
+                    41
+                ],
+                "vcpus": [
+                    2
+                ]
+            },
+            {
+                "memkb": 2097152,
+                "distances": [
+                    41,
+                    31,
+                    21,
+                    10,
+                    21,
+                    31
+                ],
+                "vcpus": [
+                    3
+                ]
+            },
+            {
+                "memkb": 2097152,
+                "distances": [
+                    51,
+                    41,
+                    31,
+                    21,
+                    10,
+                    21
+                ],
+                "vcpus": [
+                    4
+                ]
+            },
+            {
+                "memkb": 2097152,
+                "distances": [
+                    61,
+                    51,
+                    41,
+                    31,
+                    21,
+                    10
+                ],
+                "vcpus": [
+                    5
+                ]
+            }
+        ],
+        "max_memkb": 1048576,
+        "target_memkb": 1048576,
+        "video_memkb": 8192,
+        "shadow_memkb": 14336,
+        "device_model_version": "qemu_xen",
+        "device_model": "/bin/true",
+        "sched_params": {
+            "weight": 1000
+        },
+        "type.hvm": {
+            "pae": "True",
+            "apic": "True",
+            "acpi": "True",
+            "nested_hvm": "True",
+            "vga": {
+                "kind": "cirrus"
+            },
+            "vnc": {
+                "enable": "True",
+                "listen": "0.0.0.0",
+                "findunused": "False"
+            },
+            "sdl": {
+                "enable": "False"
+            },
+            "spice": {
+
+            },
+            "boot": "c",
+            "rdm": {
+
+            }
+        },
+        "arch_arm": {
+
+        }
+    },
+    "disks": [
+        {
+            "pdev_path": "/var/lib/xen/images/test-hvm.img",
+            "vdev": "hda",
+            "backend": "qdisk",
+            "format": "raw",
+            "removable": 1,
+            "readwrite": 1
+        }
+    ],
+    "nics": [
+        {
+            "devid": 0,
+            "mac": "00:16:3e:66:12:b4",
+            "bridge": "br0",
+            "script": "/etc/xen/scripts/vif-bridge",
+            "nictype": "vif_ioemu"
+        }
+    ],
+    "vfbs": [
+        {
+	    "devid": -1,
+            "vnc": {
+                "enable": "True",
+                "listen": "0.0.0.0",
+                "findunused": "False"
+            },
+            "sdl": {
+                "enable": "False"
+            }
+        }
+    ],
+    "vkbs": [
+        {
+            "devid": -1
+        }
+    ],
+    "on_reboot": "restart"
+}
diff --git a/tests/libxlxml2domconfigdata/vnuma-hvm.xml b/tests/libxlxml2domconfigdata/vnuma-hvm.xml
new file mode 100644
index 000000000..28ad923e8
--- /dev/null
+++ b/tests/libxlxml2domconfigdata/vnuma-hvm.xml
@@ -0,0 +1,100 @@
+<domain type='xen'>
+  <name>test-hvm</name>
+  <description>None</description>
+  <uuid>2147d599-9cc6-c0dc-92ab-4064b5446e9b</uuid>
+  <memory>1048576</memory>
+  <currentMemory>1048576</currentMemory>
+  <vcpu>6</vcpu>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <clock sync='utc'/>
+  <os>
+    <type>hvm</type>
+    <loader>/usr/lib/xen/boot/hvmloader</loader>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <apic/>
+    <acpi/>
+    <pae/>
+  </features>
+  <cpu mode='host-passthrough'>
+    <numa>
+      <cell id='0' cpus='0' memory='2097152' unit='KiB'>
+        <distances>
+          <sibling id='0' value='10'/>
+          <sibling id='1' value='21'/>
+          <sibling id='2' value='31'/>
+          <sibling id='3' value='41'/>
+          <sibling id='4' value='51'/>
+          <sibling id='5' value='61'/>
+        </distances>
+      </cell>
+      <cell id='1' cpus='1' memory='2097152' unit='KiB'>
+        <distances>
+          <sibling id='0' value='21'/>
+          <sibling id='1' value='10'/>
+          <sibling id='2' value='21'/>
+          <sibling id='3' value='31'/>
+          <sibling id='4' value='41'/>
+          <sibling id='5' value='51'/>
+        </distances>
+      </cell>
+      <cell id='2' cpus='2' memory='2097152' unit='KiB'>
+        <distances>
+          <sibling id='0' value='31'/>
+          <sibling id='1' value='21'/>
+          <sibling id='2' value='10'/>
+          <sibling id='3' value='21'/>
+          <sibling id='4' value='31'/>
+          <sibling id='5' value='41'/>
+        </distances>
+      </cell>
+      <cell id='3' cpus='3' memory='2097152' unit='KiB'>
+        <distances>
+          <sibling id='0' value='41'/>
+          <sibling id='1' value='31'/>
+          <sibling id='2' value='21'/>
+          <sibling id='3' value='10'/>
+          <sibling id='4' value='21'/>
+          <sibling id='5' value='31'/>
+        </distances>
+      </cell>
+      <cell id='4' cpus='4' memory='2097152' unit='KiB'>
+        <distances>
+          <sibling id='0' value='51'/>
+          <sibling id='1' value='41'/>
+          <sibling id='2' value='31'/>
+          <sibling id='3' value='21'/>
+          <sibling id='4' value='10'/>
+          <sibling id='5' value='21'/>
+        </distances>
+      </cell>
+      <cell id='5' cpus='5' memory='2097152' unit='KiB'>
+        <distances>
+          <sibling id='0' value='61'/>
+          <sibling id='1' value='51'/>
+          <sibling id='2' value='41'/>
+          <sibling id='3' value='31'/>
+          <sibling id='4' value='21'/>
+          <sibling id='5' value='10'/>
+        </distances>
+      </cell>
+    </numa>
+  </cpu>
+  <devices>
+    <emulator>/bin/true</emulator>
+    <disk type='file' device='disk'>
+      <driver name='qemu'/>
+      <source file='/var/lib/xen/images/test-hvm.img'/>
+      <target dev='hda'/>
+    </disk>
+    <interface type='bridge'>
+      <source bridge='br0'/>
+      <mac address='00:16:3e:66:12:b4'/>
+      <script path='/etc/xen/scripts/vif-bridge'/>
+    </interface>
+    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'/>
+  </devices>
+</domain>
diff --git a/tests/libxlxml2domconfigtest.c b/tests/libxlxml2domconfigtest.c
index 564d95ed2..c8379f1fa 100644
--- a/tests/libxlxml2domconfigtest.c
+++ b/tests/libxlxml2domconfigtest.c
@@ -189,6 +189,7 @@ mymain(void)
     DO_TEST("basic-pv");
     DO_TEST("basic-hvm");
     DO_TEST("moredevs-hvm");
+    DO_TEST("vnuma-hvm");
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/virmocklibxl.c b/tests/virmocklibxl.c
index bc4b53d68..747f9f8f8 100644
--- a/tests/virmocklibxl.c
+++ b/tests/virmocklibxl.c
@@ -52,6 +52,19 @@ VIR_MOCK_STUB_RET_ARGS(xc_interface_close,
                        int, 0,
                        xc_interface *, handle)
 
+VIR_MOCK_STUB_RET_ARGS(xc_physinfo,
+                       int, 0,
+                       xc_interface *, handle,
+                       xc_physinfo_t *, put_info)
+
+VIR_MOCK_STUB_RET_ARGS(xc_sharing_freed_pages,
+                       long, 0,
+                       xc_interface *, handle)
+
+VIR_MOCK_STUB_RET_ARGS(xc_sharing_used_frames,
+                       long, 0,
+                       xc_interface *, handle)
+
 VIR_MOCK_STUB_VOID_ARGS(xs_daemon_close,
                         struct xs_handle *, handle)
 
-- 
2.15.0

