Mix of halted and non-halted VCPUs used for verification. Signed-off-by: Viktor Mihajlovski <mihajlov@xxxxxxxxxxxxxxxxxx> Reviewed-by: Bjoern Walk <bwalk@xxxxxxxxxxxxxxxxxx> Signed-off-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxxxxxxx> --- tests/qemumonitorjsontest.c | 106 +++++++++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 40 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index f698c14..555af7f 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1210,57 +1210,64 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUInfo(const void *data) int ret = -1; pid_t *cpupids = NULL; pid_t expected_cpupids[] = {17622, 17624, 17626, 17628}; - int ncpupids; + bool *cpuhalted = NULL; + bool expected_cpuhalted[] = {true, true, false, false}; + int ncpusfound; size_t i; + const char *replystring; if (!test) return -1; - if (qemuMonitorTestAddItem(test, "query-cpus", - "{" - " \"return\": [" - " {" - " \"current\": true," - " \"CPU\": 0," - " \"pc\": -2130530478," - " \"halted\": true," - " \"thread_id\": 17622" - " }," - " {" - " \"current\": false," - " \"CPU\": 1," - " \"pc\": -2130530478," - " \"halted\": true," - " \"thread_id\": 17624" - " }," - " {" - " \"current\": false," - " \"CPU\": 2," - " \"pc\": -2130530478," - " \"halted\": true," - " \"thread_id\": 17626" - " }," - " {" - " \"current\": false," - " \"CPU\": 3," - " \"pc\": -2130530478," - " \"halted\": true," - " \"thread_id\": 17628" - " }" - " ]," - " \"id\": \"libvirt-7\"" - "}") < 0) - goto cleanup; + replystring = + "{" + " \"return\": [" + " {" + " \"current\": true," + " \"CPU\": 0," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17622" + " }," + " {" + " \"current\": false," + " \"CPU\": 1," + " \"pc\": -2130530478," + " \"halted\": true," + " \"thread_id\": 17624" + " }," + " {" + " \"current\": false," + " \"CPU\": 2," + " \"pc\": -2130530478," + " \"halted\": false," + " \"thread_id\": 17626" + " }," + " {" + " \"current\": false," + " \"CPU\": 3," + " \"pc\": -2130530478," + " \"halted\": false," + " \"thread_id\": 17628" + " }" + " ]," + " \"id\": \"libvirt-7\"" + "}"; - ncpupids = qemuMonitorJSONGetCPUInfo(qemuMonitorTestGetMonitor(test), &cpupids); + if (qemuMonitorTestAddItem(test, "query-cpus", replystring) < 0) + goto cleanup; + if (qemuMonitorTestAddItem(test, "query-cpus", replystring) < 0) + goto cleanup; - if (ncpupids != 4) { + ncpusfound = qemuMonitorJSONGetCPUInfo(qemuMonitorTestGetMonitor(test), + &cpupids); + if (ncpusfound != 4) { virReportError(VIR_ERR_INTERNAL_ERROR, - "Expecting ncpupids = 4 but got %d", ncpupids); + "Expecting ncpusfound = 4 but got %d", ncpusfound); goto cleanup; } - for (i = 0; i < ncpupids; i++) { + for (i = 0; i < ncpusfound; i++) { if (cpupids[i] != expected_cpupids[i]) { virReportError(VIR_ERR_INTERNAL_ERROR, "Expecting cpupids[%zu] = %d but got %d", @@ -1269,10 +1276,29 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUInfo(const void *data) } } + ncpusfound = qemuMonitorJSONGetCPUState(qemuMonitorTestGetMonitor(test), + &cpuhalted); + + if (ncpusfound != 4) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Expecting ncpusfound = 4 but got %d", ncpusfound); + goto cleanup; + } + + for (i = 0; i < ncpusfound; i++) { + if (cpuhalted[i] != expected_cpuhalted[i]) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "Expecting cpuhalted[%zu] = %d but got %d", + i, expected_cpuhalted[i], cpuhalted[i]); + goto cleanup; + } + } + ret = 0; cleanup: VIR_FREE(cpupids); + VIR_FREE(cpuhalted); qemuMonitorTestFree(test); return ret; } -- 1.9.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list