[libvirt] [PATCH v2 0/2] Add test case for node name detection

Patch 2/2 was originallly included in the node name detection refactor. v2 does not contain an ugly hack to make virTestCompareToFile, but rather fixes the function to treat NULL as an empty string. Peter Krempa (2): tests: utils: Allow NULL strings to be equal to empty file in virTestCompareToFile tests: qemumonitorjson: Old and empty test case for node name detection .../qemumonitorjson-nodename-empty-blockstats.json | 2 + ...qemumonitorjson-nodename-empty-named-nodes.json | 2 + .../qemumonitorjson-nodename-empty.result | 0 .../qemumonitorjson-nodename-old-blockstats.json | 160 +++++++++++++++++++++ .../qemumonitorjson-nodename-old-named-nodes.json | 2 + .../qemumonitorjson-nodename-old.result | 0 tests/qemumonitorjsontest.c | 2 + tests/testutils.c | 5 + 8 files changed, 173 insertions(+) create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-blockstats.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-named-nodes.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty.result create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old-blockstats.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old-named-nodes.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old.result -- 2.13.2

Treat an NULL string equivalent to an empty string in virTestCompareToFile so that callers don't need to add additional logic in case when a test produces no output. --- tests/testutils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/testutils.c b/tests/testutils.c index 40e9650fd..71692f1fa 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -777,6 +777,8 @@ int virTestDifferenceBin(FILE *stream, /* * @param strcontent: String input content * @param filename: File to compare strcontent against + * + * If @strcontent is NULL, it's treated as an empty string. */ int virTestCompareToFile(const char *strcontent, @@ -787,6 +789,9 @@ virTestCompareToFile(const char *strcontent, char *fixedcontent = NULL; const char *cmpcontent = strcontent; + if (!cmpcontent) + cmpcontent = ""; + if (virTestLoadFile(filename, &filecontent) < 0 && !virTestGetRegenerate()) goto failure; -- 2.13.2

On 07/28/2017 05:43 AM, Peter Krempa wrote:
Treat an NULL string equivalent to an empty string in virTestCompareToFile so that callers don't need to add additional logic in case when a test produces no output. --- tests/testutils.c | 5 +++++ 1 file changed, 5 insertions(+)
Works for me! -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org

Prior to qemu 2.5 the node names would not be generated, thus would be missing from 'query-blockstats' and 'query-named-block-nodes'. Test that the code correctly detects nothing. Additionally make sure that a VM without disks does not cause problems. The test case change is necessary as our test file checker does not play well with empty files. --- .../qemumonitorjson-nodename-empty-blockstats.json | 2 + ...qemumonitorjson-nodename-empty-named-nodes.json | 2 + .../qemumonitorjson-nodename-empty.result | 0 .../qemumonitorjson-nodename-old-blockstats.json | 160 +++++++++++++++++++++ .../qemumonitorjson-nodename-old-named-nodes.json | 2 + .../qemumonitorjson-nodename-old.result | 0 tests/qemumonitorjsontest.c | 2 + 7 files changed, 168 insertions(+) create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-blockstats.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-named-nodes.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty.result create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old-blockstats.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old-named-nodes.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old.result diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-blockstats.json b/tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-blockstats.json new file mode 100644 index 000000000..0d4f101c7 --- /dev/null +++ b/tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-blockstats.json @@ -0,0 +1,2 @@ +[ +] diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-named-nodes.json b/tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-named-nodes.json new file mode 100644 index 000000000..0d4f101c7 --- /dev/null +++ b/tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-named-nodes.json @@ -0,0 +1,2 @@ +[ +] diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-empty.result b/tests/qemumonitorjsondata/qemumonitorjson-nodename-empty.result new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-old-blockstats.json b/tests/qemumonitorjsondata/qemumonitorjson-nodename-old-blockstats.json new file mode 100644 index 000000000..26c14f9f2 --- /dev/null +++ b/tests/qemumonitorjsondata/qemumonitorjson-nodename-old-blockstats.json @@ -0,0 +1,160 @@ +[ + { + "device": "drive-virtio-disk0", + "parent": { + "stats": { + "flush_total_time_ns": 0, + "wr_highest_offset": 32899072, + "wr_total_time_ns": 0, + "failed_wr_operations": 0, + "failed_rd_operations": 0, + "wr_merged": 0, + "wr_bytes": 0, + "timed_stats": [ + + ], + "failed_flush_operations": 0, + "account_invalid": false, + "rd_total_time_ns": 0, + "flush_operations": 0, + "wr_operations": 0, + "rd_merged": 0, + "rd_bytes": 0, + "invalid_flush_operations": 0, + "account_failed": false, + "rd_operations": 0, + "invalid_wr_operations": 0, + "invalid_rd_operations": 0 + } + }, + "stats": { + "flush_total_time_ns": 452246313, + "wr_highest_offset": 8072282112, + "wr_total_time_ns": 4803102521, + "failed_wr_operations": 0, + "failed_rd_operations": 0, + "wr_merged": 8, + "wr_bytes": 6517248, + "timed_stats": [ + + ], + "failed_flush_operations": 0, + "account_invalid": true, + "rd_total_time_ns": 11065169148, + "flush_operations": 10, + "wr_operations": 129, + "rd_merged": 77, + "rd_bytes": 76399104, + "invalid_flush_operations": 0, + "account_failed": true, + "idle_time_ns": 22663656304, + "rd_operations": 4038, + "invalid_wr_operations": 0, + "invalid_rd_operations": 0 + }, + "backing": { + "parent": { + "stats": { + "flush_total_time_ns": 0, + "wr_highest_offset": 0, + "wr_total_time_ns": 0, + "failed_wr_operations": 0, + "failed_rd_operations": 0, + "wr_merged": 0, + "wr_bytes": 0, + "timed_stats": [ + + ], + "failed_flush_operations": 0, + "account_invalid": false, + "rd_total_time_ns": 0, + "flush_operations": 0, + "wr_operations": 0, + "rd_merged": 0, + "rd_bytes": 0, + "invalid_flush_operations": 0, + "account_failed": false, + "rd_operations": 0, + "invalid_wr_operations": 0, + "invalid_rd_operations": 0 + } + }, + "stats": { + "flush_total_time_ns": 0, + "wr_highest_offset": 0, + "wr_total_time_ns": 0, + "failed_wr_operations": 0, + "failed_rd_operations": 0, + "wr_merged": 0, + "wr_bytes": 0, + "timed_stats": [ + + ], + "failed_flush_operations": 0, + "account_invalid": false, + "rd_total_time_ns": 0, + "flush_operations": 0, + "wr_operations": 0, + "rd_merged": 0, + "rd_bytes": 0, + "invalid_flush_operations": 0, + "account_failed": false, + "rd_operations": 0, + "invalid_wr_operations": 0, + "invalid_rd_operations": 0 + }, + "backing": { + "parent": { + "stats": { + "flush_total_time_ns": 0, + "wr_highest_offset": 0, + "wr_total_time_ns": 0, + "failed_wr_operations": 0, + "failed_rd_operations": 0, + "wr_merged": 0, + "wr_bytes": 0, + "timed_stats": [ + + ], + "failed_flush_operations": 0, + "account_invalid": false, + "rd_total_time_ns": 0, + "flush_operations": 0, + "wr_operations": 0, + "rd_merged": 0, + "rd_bytes": 0, + "invalid_flush_operations": 0, + "account_failed": false, + "rd_operations": 0, + "invalid_wr_operations": 0, + "invalid_rd_operations": 0 + } + }, + "stats": { + "flush_total_time_ns": 0, + "wr_highest_offset": 0, + "wr_total_time_ns": 0, + "failed_wr_operations": 0, + "failed_rd_operations": 0, + "wr_merged": 0, + "wr_bytes": 0, + "timed_stats": [ + + ], + "failed_flush_operations": 0, + "account_invalid": false, + "rd_total_time_ns": 0, + "flush_operations": 0, + "wr_operations": 0, + "rd_merged": 0, + "rd_bytes": 0, + "invalid_flush_operations": 0, + "account_failed": false, + "rd_operations": 0, + "invalid_wr_operations": 0, + "invalid_rd_operations": 0 + } + } + } + } +] diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-old-named-nodes.json b/tests/qemumonitorjsondata/qemumonitorjson-nodename-old-named-nodes.json new file mode 100644 index 000000000..0d4f101c7 --- /dev/null +++ b/tests/qemumonitorjsondata/qemumonitorjson-nodename-old-named-nodes.json @@ -0,0 +1,2 @@ +[ +] diff --git a/tests/qemumonitorjsondata/qemumonitorjson-nodename-old.result b/tests/qemumonitorjsondata/qemumonitorjson-nodename-old.result new file mode 100644 index 000000000..e69de29bb diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index f2090a4ca..df3ef0a93 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2933,6 +2933,8 @@ mymain(void) DO_TEST_BLOCK_NODE_DETECT("blockjob"); DO_TEST_BLOCK_NODE_DETECT("luks"); DO_TEST_BLOCK_NODE_DETECT("iscsi"); + DO_TEST_BLOCK_NODE_DETECT("old"); + DO_TEST_BLOCK_NODE_DETECT("empty"); #undef DO_TEST_BLOCK_NODE_DETECT -- 2.13.2

On Fri, Jul 28, 2017 at 12:43:43PM +0200, Peter Krempa wrote:
Patch 2/2 was originallly included in the node name detection refactor. v2 does not contain an ugly hack to make virTestCompareToFile, but rather fixes the function to treat NULL as an empty string.
Peter Krempa (2): tests: utils: Allow NULL strings to be equal to empty file in virTestCompareToFile tests: qemumonitorjson: Old and empty test case for node name detection
.../qemumonitorjson-nodename-empty-blockstats.json | 2 + ...qemumonitorjson-nodename-empty-named-nodes.json | 2 + .../qemumonitorjson-nodename-empty.result | 0 .../qemumonitorjson-nodename-old-blockstats.json | 160 +++++++++++++++++++++ .../qemumonitorjson-nodename-old-named-nodes.json | 2 + .../qemumonitorjson-nodename-old.result | 0 tests/qemumonitorjsontest.c | 2 + tests/testutils.c | 5 + 8 files changed, 173 insertions(+) create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-blockstats.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty-named-nodes.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-empty.result create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old-blockstats.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old-named-nodes.json create mode 100644 tests/qemumonitorjsondata/qemumonitorjson-nodename-old.result
ACK series Jan
participants (3)
-
Eric Blake
-
Ján Tomko
-
Peter Krempa