tests: add qemumonitorjson tests for query-cpus-fast

Extended the json monitor test program with support for query-cpus-fast
and added a sample file set for x86 data obtained using the it.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
Viktor Mihajlovski 2018-04-04 16:45:04 +02:00 committed by John Ferlan
parent 41e335f99b
commit 37bd4571c7
6 changed files with 452 additions and 26 deletions

View File

@ -0,0 +1,126 @@
{
"return": [
{
"arch": "x86",
"cpu-index": 0,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 0
},
"qom-path": "/machine/unattached/device[0]",
"thread-id": 895040
},
{
"arch": "x86",
"cpu-index": 1,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 1
},
"qom-path": "/machine/peripheral/vcpu1",
"thread-id": 895056
},
{
"arch": "x86",
"cpu-index": 2,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 2
},
"qom-path": "/machine/peripheral/vcpu2",
"thread-id": 895057
},
{
"arch": "x86",
"cpu-index": 3,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 3
},
"qom-path": "/machine/peripheral/vcpu3",
"thread-id": 895058
},
{
"arch": "x86",
"cpu-index": 4,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 4
},
"qom-path": "/machine/peripheral/vcpu4",
"thread-id": 895059
},
{
"arch": "x86",
"cpu-index": 5,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 5
},
"qom-path": "/machine/peripheral/vcpu5",
"thread-id": 895060
},
{
"arch": "x86",
"cpu-index": 6,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 6
},
"qom-path": "/machine/peripheral/vcpu6",
"thread-id": 895061
},
{
"arch": "x86",
"cpu-index": 7,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 7
},
"qom-path": "/machine/peripheral/vcpu7",
"thread-id": 895062
},
{
"arch": "x86",
"cpu-index": 8,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 8
},
"qom-path": "/machine/peripheral/vcpu8",
"thread-id": 895063
},
{
"arch": "x86",
"cpu-index": 9,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 9
},
"qom-path": "/machine/peripheral/vcpu9",
"thread-id": 895064
},
{
"arch": "x86",
"cpu-index": 10,
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 10
},
"qom-path": "/machine/peripheral/vcpu10",
"thread-id": 895065
}
],
"id": "libvirt-52"
}

View File

@ -0,0 +1,115 @@
{
"return": [
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 10
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu10",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 9
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu9",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 8
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu8",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 7
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu7",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 6
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu6",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 5
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu5",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 4
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu4",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 3
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu3",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 2
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu2",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 1
},
"vcpus-count": 1,
"qom-path": "/machine/peripheral/vcpu1",
"type": "Broadwell-x86_64-cpu"
},
{
"props": {
"core-id": 0,
"thread-id": 0,
"socket-id": 0
},
"vcpus-count": 1,
"qom-path": "/machine/unattached/device[0]",
"type": "Broadwell-x86_64-cpu"
}
],
"id": "libvirt-51"
}

View File

@ -0,0 +1,109 @@
[vcpu libvirt-id='0']
online=yes
hotpluggable=no
thread-id='895040'
enable-id='1'
query-cpus-id='0'
type='Broadwell-x86_64-cpu'
qom_path='/machine/unattached/device[0]'
topology: socket='0' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='1']
online=yes
hotpluggable=yes
thread-id='895056'
enable-id='2'
query-cpus-id='1'
type='Broadwell-x86_64-cpu'
alias='vcpu1'
qom_path='/machine/peripheral/vcpu1'
topology: socket='1' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='2']
online=yes
hotpluggable=yes
thread-id='895057'
enable-id='3'
query-cpus-id='2'
type='Broadwell-x86_64-cpu'
alias='vcpu2'
qom_path='/machine/peripheral/vcpu2'
topology: socket='2' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='3']
online=yes
hotpluggable=yes
thread-id='895058'
enable-id='4'
query-cpus-id='3'
type='Broadwell-x86_64-cpu'
alias='vcpu3'
qom_path='/machine/peripheral/vcpu3'
topology: socket='3' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='4']
online=yes
hotpluggable=yes
thread-id='895059'
enable-id='5'
query-cpus-id='4'
type='Broadwell-x86_64-cpu'
alias='vcpu4'
qom_path='/machine/peripheral/vcpu4'
topology: socket='4' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='5']
online=yes
hotpluggable=yes
thread-id='895060'
enable-id='6'
query-cpus-id='5'
type='Broadwell-x86_64-cpu'
alias='vcpu5'
qom_path='/machine/peripheral/vcpu5'
topology: socket='5' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='6']
online=yes
hotpluggable=yes
thread-id='895061'
enable-id='7'
query-cpus-id='6'
type='Broadwell-x86_64-cpu'
alias='vcpu6'
qom_path='/machine/peripheral/vcpu6'
topology: socket='6' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='7']
online=yes
hotpluggable=yes
thread-id='895062'
enable-id='8'
query-cpus-id='7'
type='Broadwell-x86_64-cpu'
alias='vcpu7'
qom_path='/machine/peripheral/vcpu7'
topology: socket='7' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='8']
online=yes
hotpluggable=yes
thread-id='895063'
enable-id='9'
query-cpus-id='8'
type='Broadwell-x86_64-cpu'
alias='vcpu8'
qom_path='/machine/peripheral/vcpu8'
topology: socket='8' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='9']
online=yes
hotpluggable=yes
thread-id='895064'
enable-id='10'
query-cpus-id='9'
type='Broadwell-x86_64-cpu'
alias='vcpu9'
qom_path='/machine/peripheral/vcpu9'
topology: socket='9' core='0' thread='0' vcpus='1'
[vcpu libvirt-id='10']
online=yes
hotpluggable=yes
thread-id='895065'
enable-id='11'
query-cpus-id='10'
type='Broadwell-x86_64-cpu'
alias='vcpu10'
qom_path='/machine/peripheral/vcpu10'
topology: socket='10' core='0' thread='0' vcpus='1'

View File

@ -1366,21 +1366,60 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCpusEntr
}
static int
testQEMUMonitorJSONqemuMonitorJSONQueryCPUsHelper(qemuMonitorTestPtr test,
struct qemuMonitorQueryCpusEntry *expect,
bool fast,
size_t num)
{
struct qemuMonitorQueryCpusEntry *cpudata = NULL;
size_t ncpudata = 0;
size_t i;
int ret = -1;
if (qemuMonitorJSONQueryCPUs(qemuMonitorTestGetMonitor(test),
&cpudata, &ncpudata, true, fast) < 0)
goto cleanup;
if (ncpudata != num) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"Expecting ncpupids = %zu but got %zu", num, ncpudata);
goto cleanup;
}
for (i = 0; i < ncpudata; i++) {
if (!testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(cpudata + i,
expect + i)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"vcpu entry %zu does not match expected data", i);
goto cleanup;
}
}
ret = 0;
cleanup:
qemuMonitorQueryCpusFree(cpudata, ncpudata);
return ret;
}
static int
testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
{
virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
int ret = -1;
struct qemuMonitorQueryCpusEntry *cpudata = NULL;
struct qemuMonitorQueryCpusEntry expect[] = {
{0, 17622, (char *) "/machine/unattached/device[0]", true},
{1, 17624, (char *) "/machine/unattached/device[1]", true},
{2, 17626, (char *) "/machine/unattached/device[2]", true},
{3, 17628, NULL, true},
struct qemuMonitorQueryCpusEntry expect_slow[] = {
{0, 17622, (char *) "/machine/unattached/device[0]", true},
{1, 17624, (char *) "/machine/unattached/device[1]", true},
{2, 17626, (char *) "/machine/unattached/device[2]", true},
{3, 17628, NULL, true},
};
struct qemuMonitorQueryCpusEntry expect_fast[] = {
{0, 17629, (char *) "/machine/unattached/device[0]", false},
{1, 17630, (char *) "/machine/unattached/device[1]", false},
};
size_t ncpudata = 0;
size_t i;
if (!test)
return -1;
@ -1424,29 +1463,37 @@ testQemuMonitorJSONqemuMonitorJSONQueryCPUs(const void *data)
"}") < 0)
goto cleanup;
if (qemuMonitorJSONQueryCPUs(qemuMonitorTestGetMonitor(test),
&cpudata, &ncpudata, true, false) < 0)
if (qemuMonitorTestAddItem(test, "query-cpus-fast",
"{"
" \"return\": ["
" {"
" \"cpu-index\": 0,"
" \"qom-path\": \"/machine/unattached/device[0]\","
" \"thread-id\": 17629"
" },"
" {"
" \"cpu-index\": 1,"
" \"qom-path\": \"/machine/unattached/device[1]\","
" \"thread-id\": 17630"
" }"
" ],"
" \"id\": \"libvirt-8\""
"}") < 0)
goto cleanup;
if (ncpudata != 4) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"Expecting ncpupids = 4 but got %zu", ncpudata);
/* query-cpus */
if (testQEMUMonitorJSONqemuMonitorJSONQueryCPUsHelper(test, expect_slow,
false, 4))
goto cleanup;
}
for (i = 0; i < ncpudata; i++) {
if (!testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(cpudata + i,
expect + i)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"vcpu entry %zu does not match expected data", i);
goto cleanup;
}
}
/* query-cpus-fast */
if (testQEMUMonitorJSONqemuMonitorJSONQueryCPUsHelper(test, expect_fast,
true, 2))
goto cleanup;
ret = 0;
cleanup:
qemuMonitorQueryCpusFree(cpudata, ncpudata);
qemuMonitorTestFree(test);
return ret;
}
@ -2531,6 +2578,7 @@ struct testCPUInfoData {
const char *name;
size_t maxvcpus;
virDomainXMLOptionPtr xmlopt;
bool fast;
};
@ -2600,12 +2648,14 @@ testQemuMonitorCPUInfo(const void *opaque)
{
const struct testCPUInfoData *data = opaque;
qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, data->xmlopt);
virDomainObjPtr vm = NULL;
char *queryCpusFile = NULL;
char *queryHotpluggableFile = NULL;
char *dataFile = NULL;
char *queryCpusStr = NULL;
char *queryHotpluggableStr = NULL;
char *actual = NULL;
const char *queryCpusFunction;
qemuMonitorCPUInfoPtr vcpus = NULL;
int rc;
int ret = -1;
@ -2634,11 +2684,20 @@ testQemuMonitorCPUInfo(const void *opaque)
queryHotpluggableStr) < 0)
goto cleanup;
if (qemuMonitorTestAddItem(test, "query-cpus", queryCpusStr) < 0)
if (data->fast)
queryCpusFunction = "query-cpus-fast";
else
queryCpusFunction = "query-cpus";
if (qemuMonitorTestAddItem(test, queryCpusFunction, queryCpusStr) < 0)
goto cleanup;
vm = qemuMonitorTestGetDomainObj(test);
if (!vm)
return -1;
rc = qemuMonitorGetCPUInfo(qemuMonitorTestGetMonitor(test),
&vcpus, data->maxvcpus, true, false);
&vcpus, data->maxvcpus, true, data->fast);
if (rc < 0)
goto cleanup;
@ -2849,7 +2908,15 @@ mymain(void)
#define DO_TEST_CPU_INFO(name, maxvcpus) \
do { \
struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt}; \
struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt, false}; \
if (virTestRun("GetCPUInfo(" name ")", testQemuMonitorCPUInfo, \
&data) < 0) \
ret = -1; \
} while (0)
#define DO_TEST_CPU_INFO_FAST(name, maxvcpus) \
do { \
struct testCPUInfoData data = {name, maxvcpus, driver.xmlopt, true}; \
if (virTestRun("GetCPUInfo(" name ")", testQemuMonitorCPUInfo, \
&data) < 0) \
ret = -1; \
@ -2932,6 +2999,7 @@ mymain(void)
DO_TEST_CPU_INFO("x86-basic-pluggable", 8);
DO_TEST_CPU_INFO("x86-full", 11);
DO_TEST_CPU_INFO("x86-node-full", 8);
DO_TEST_CPU_INFO_FAST("x86-full-fast", 11);
DO_TEST_CPU_INFO("ppc64-basic", 24);
DO_TEST_CPU_INFO("ppc64-hotplug-1", 24);

View File

@ -1518,3 +1518,10 @@ qemuMonitorTestGetAgent(qemuMonitorTestPtr test)
{
return test->agent;
}
virDomainObjPtr
qemuMonitorTestGetDomainObj(qemuMonitorTestPtr test)
{
return test->vm;
}

View File

@ -99,5 +99,6 @@ void qemuMonitorTestFree(qemuMonitorTestPtr test);
qemuMonitorPtr qemuMonitorTestGetMonitor(qemuMonitorTestPtr test);
qemuAgentPtr qemuMonitorTestGetAgent(qemuMonitorTestPtr test);
virDomainObjPtr qemuMonitorTestGetDomainObj(qemuMonitorTestPtr test);
#endif /* __VIR_QEMU_MONITOR_TEST_UTILS_H__ */