Use the new single function instead of calling qemuMonitorJSONGetBlockStatsInfo and qemuMonitorJSONGetBlockStatsParamsNumber. This will allow to delete the functions later while still maintaining coverage. --- tests/qemumonitorjsontest.c | 62 +++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 41 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index da9cd6c..1380df1 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1435,11 +1435,9 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockStatsInfo(const void *data) { virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data; qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt); + virHashTablePtr blockstats = NULL; + qemuBlockStatsPtr stats; int ret = -1; - long long rd_req, rd_bytes, rd_total_times; - long long wr_req, wr_bytes, wr_total_times; - long long flush_req, flush_total_times; - int nparams; unsigned long long extent; const char *reply = @@ -1537,22 +1535,24 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockStatsInfo(const void *data) if (qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || - qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || - qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || - qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0 || qemuMonitorTestAddItem(test, "query-blockstats", reply) < 0) goto cleanup; #define CHECK0(var, value) \ - if (var != value) { \ + if (stats->var != value) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ "Invalid " #var " value: %lld, expected %d", \ - var, value); \ + stats->var, value); \ goto cleanup; \ } -#define CHECK(RD_REQ, RD_BYTES, RD_TOTAL_TIMES, WR_REQ, WR_BYTES, WR_TOTAL_TIMES, \ - FLUSH_REQ, FLUSH_TOTAL_TIMES) \ +#define CHECK(NAME, RD_REQ, RD_BYTES, RD_TOTAL_TIMES, WR_REQ, WR_BYTES, \ + WR_TOTAL_TIMES, FLUSH_REQ, FLUSH_TOTAL_TIMES) \ + if (!(stats = virHashLookup(blockstats, NAME))) { \ + virReportError(VIR_ERR_INTERNAL_ERROR, \ + "block stats for device '%s' is missing", NAME); \ + goto cleanup; \ + } \ CHECK0(rd_req, RD_REQ) \ CHECK0(rd_bytes, RD_BYTES) \ CHECK0(rd_total_times, RD_TOTAL_TIMES) \ @@ -1562,41 +1562,20 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockStatsInfo(const void *data) CHECK0(flush_req, FLUSH_REQ) \ CHECK0(flush_total_times, FLUSH_TOTAL_TIMES) - if (qemuMonitorJSONGetBlockStatsInfo(qemuMonitorTestGetMonitor(test), "virtio-disk0", - &rd_req, &rd_bytes, &rd_total_times, - &wr_req, &wr_bytes, &wr_total_times, - &flush_req, &flush_total_times) < 0) - goto cleanup; - - CHECK(1279, 28505088, 640616474, 174, 2845696, 530699221, 0, 0) - - if (qemuMonitorJSONGetBlockStatsInfo(qemuMonitorTestGetMonitor(test), "virtio-disk1", - &rd_req, &rd_bytes, &rd_total_times, - &wr_req, &wr_bytes, &wr_total_times, - &flush_req, &flush_total_times) < 0) + if (qemuMonitorGetAllBlockStatsInfo(qemuMonitorTestGetMonitor(test), + &blockstats, false) < 0) goto cleanup; - CHECK(85, 348160, 8232156, 0, 0, 0, 0, 0) - - if (qemuMonitorJSONGetBlockStatsInfo(qemuMonitorTestGetMonitor(test), "ide0-1-0", - &rd_req, &rd_bytes, &rd_total_times, - &wr_req, &wr_bytes, &wr_total_times, - &flush_req, &flush_total_times) < 0) - goto cleanup; - - CHECK(16, 49250, 1004952, 0, 0, 0, 0, 0) - - if (qemuMonitorJSONGetBlockStatsParamsNumber(qemuMonitorTestGetMonitor(test), - &nparams) < 0) - goto cleanup; - - if (nparams != 8) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "Invalid number of stats: %d, expected 8", - nparams); + if (!blockstats) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + "qemuMonitorJSONGetBlockStatsInfo didn't return stats"); goto cleanup; } + CHECK("virtio-disk0", 1279, 28505088, 640616474, 174, 2845696, 530699221, 0, 0) + CHECK("virtio-disk1", 85, 348160, 8232156, 0, 0, 0, 0, 0) + CHECK("ide0-1-0", 16, 49250, 1004952, 0, 0, 0, 0, 0) + if (qemuMonitorJSONGetBlockExtent(qemuMonitorTestGetMonitor(test), "virtio-disk0", &extent) < 0) goto cleanup; @@ -1637,6 +1616,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBlockStatsInfo(const void *data) cleanup: qemuMonitorTestFree(test); + virHashFree(blockstats); return ret; } -- 2.2.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list