From 947d2db31b1eed76dac390f75a1fbc068eae64e0 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 23 Oct 2020 09:07:02 +0200 Subject: [PATCH] Use virHashForEachSorted in tested code The simplest way to write tests is to check the output against expected output, but we must ensure that the output is stable. We can use virHashForEachSorted as a hash iterator to ensure stable ordering. This patch fixes 3 instances of hash iteration which is tested in various parts, including test output changes in appropriate places. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza Reviewed-by: Matt Coleman --- src/qemu/qemu_domain.c | 6 +- src/util/virmacmap.c | 2 +- tests/qemumonitorjsontest.c | 2 +- .../blockjob-blockdev-in.xml | 116 +++++++++--------- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d7dbca487a..e770940aca 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2223,9 +2223,9 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf, virTristateBoolTypeToString(virTristateBoolFromBool(bj))); if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && - virHashForEach(priv->blockjobs, - qemuDomainObjPrivateXMLFormatBlockjobIterator, - &iterdata) < 0) + virHashForEachSorted(priv->blockjobs, + qemuDomainObjPrivateXMLFormatBlockjobIterator, + &iterdata) < 0) return -1; virXMLFormatElement(buf, "blockjobs", &attrBuf, &childBuf); diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c index 2d203e72af..fe71b06dd7 100644 --- a/src/util/virmacmap.c +++ b/src/util/virmacmap.c @@ -244,7 +244,7 @@ virMacMapDumpStrLocked(virMacMapPtr mgr, arr = virJSONValueNewArray(); - if (virHashForEach(mgr->macs, virMACMapHashDumper, arr) < 0) + if (virHashForEachSorted(mgr->macs, virMACMapHashDumper, arr) < 0) goto cleanup; if (!(*str = virJSONValueToString(arr, true))) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 2a0377bae3..9231fa835a 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2792,7 +2792,7 @@ testBlockNodeNameDetect(const void *opaque) blockstatsJson))) goto cleanup; - virHashForEach(nodedata, testBlockNodeNameDetectFormat, &buf); + virHashForEachSorted(nodedata, testBlockNodeNameDetectFormat, &buf); virBufferTrim(&buf, "\n"); diff --git a/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml b/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml index 8ffc91bdcb..c70742418b 100644 --- a/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml +++ b/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml @@ -234,9 +234,12 @@ - - - + + + + + + @@ -244,9 +247,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -284,61 +339,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -2