[libvirt] [PATCH] test: Use nodeInfo content for virNodeGetCPUMap

Cole Robinson crobinso at redhat.com
Thu Apr 25 12:57:11 UTC 2019


Right now the test driver implementation of virNodeGetCPUMap uses
hardcoded data. Instead use cpu data from our nodeInfo, which can be
overridden with input test XML. This helps to emulate some virsh
commands (vcpupin, hostcpumap) with a large number of host cpus. [1]

The content reported for test:///default is now slightly different:
previously it would report 8 total cpus with 0,2,4 online. Now it
reports 16 cpus with all online, which is the pre-existing nodeInfo
default.

[1] https://www.redhat.com/archives/libvir-list/2019-March/msg02042.html

Signed-off-by: Cole Robinson <crobinso at redhat.com>
---
John, in trying to understand and test your bitmap patch, I added
this to the test driver. I think there's a bigger issue at play
but I'm still trying to work it out, I'll send a follow up email
when I've collected my thoughts

 src/test/test_driver.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index d5eecf4b7f..f00b6eb1c8 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5811,23 +5811,46 @@ static int testConnectListAllDomains(virConnectPtr conn,
 }
 
 static int
-testNodeGetCPUMap(virConnectPtr conn ATTRIBUTE_UNUSED,
+testNodeGetCPUMap(virConnectPtr conn,
                   unsigned char **cpumap,
                   unsigned int *online,
                   unsigned int flags)
 {
+    testDriverPtr privconn = conn->privateData;
+    int maxcpus = VIR_NODEINFO_MAXCPUS(privconn->nodeInfo);
+    virBitmapPtr cpus = NULL;
+    int ret = -1;
+    int dummy;
+    size_t i;
+
     virCheckFlags(0, -1);
 
+    if (!cpumap && !online)
+        return maxcpus;
+
+    if (!(cpus = virBitmapNew(maxcpus)))
+        goto cleanup;
+
     if (cpumap) {
-        if (VIR_ALLOC_N(*cpumap, 1) < 0)
-            return -1;
-        *cpumap[0] = 0x15;
+        for (i = 0; i < privconn->nodeInfo.cpus; i++) {
+            if (virBitmapSetBit(cpus, i) < 0)
+                goto cleanup;
+        }
+
+        if (virBitmapToData(cpus, cpumap, &dummy) < 0)
+            goto cleanup;
     }
 
     if (online)
-        *online = 3;
+        *online = privconn->nodeInfo.cpus;
 
-    return  8;
+    ret = maxcpus;
+
+ cleanup:
+    if (ret < 0 && cpumap)
+        VIR_FREE(*cpumap);
+    VIR_FREE(cpus);
+    return ret;
 }
 
 static char *
-- 
2.21.0




More information about the libvir-list mailing list