[libvirt] [PATCH 0/5] JSON test improvements

{ "BLURB": "HERE" } Ján Tomko (5): virjsontest: store name in testInfo virjsontest: use name instead of doc for deflatten test virjsontest: use the test name in AddRemove test Test parsing of large numbers in JSON tests: pass ULLONG_MAX to qemuMonitorJSONGetBalloonInfo tests/qemumonitorjsontest.c | 4 ++-- tests/virjsontest.c | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) -- 2.16.4

Give the testing function access to the test name instead of only passing it to virTestRun. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index d42413d11d..779bf441bd 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -12,6 +12,7 @@ #define VIR_FROM_THIS VIR_FROM_NONE struct testInfo { + const char *name; const char *doc; const char *expect; bool pass; @@ -481,7 +482,7 @@ mymain(void) #define DO_TEST_FULL(name, cmd, doc, expect, pass) \ do { \ - struct testInfo info = { doc, expect, pass }; \ + struct testInfo info = { name, doc, expect, pass }; \ if (virTestRun(name, testJSON ## cmd, &info) < 0) \ ret = -1; \ } while (0) -- 2.16.4

On Tue, Aug 28, 2018 at 12:22:51PM +0200, Ján Tomko wrote:
Give the testing function access to the test name instead of only passing it to virTestRun.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

This test gets its JSON docs from files. Now that we have a 'name' field in testInfo, use it instead of abusing the 'doc' field. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 779bf441bd..6f2f7f56ed 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -326,9 +326,9 @@ testJSONDeflatten(const void *data) int ret = -1; if (virAsprintf(&infile, "%s/virjsondata/deflatten-%s-in.json", - abs_srcdir, info->doc) < 0 || + abs_srcdir, info->name) < 0 || virAsprintf(&outfile, "%s/virjsondata/deflatten-%s-out.json", - abs_srcdir, info->doc) < 0) + abs_srcdir, info->name) < 0) goto cleanup; if (virTestLoadFile(infile, &indata) < 0) @@ -339,7 +339,7 @@ testJSONDeflatten(const void *data) if ((deflattened = virJSONValueObjectDeflatten(injson))) { if (!info->pass) { - VIR_TEST_VERBOSE("%s: deflattening should have failed\n", info->doc); + VIR_TEST_VERBOSE("%s: deflattening should have failed\n", info->name); goto cleanup; } } else { @@ -638,7 +638,7 @@ mymain(void) ObjectFormatSteal, NULL, NULL, true); #define DO_TEST_DEFLATTEN(name, pass) \ - DO_TEST_FULL(name, Deflatten, name, NULL, pass) + DO_TEST_FULL(name, Deflatten, NULL, NULL, pass) DO_TEST_DEFLATTEN("unflattened", true); DO_TEST_DEFLATTEN("basic-file", true); -- 2.16.4

On Tue, Aug 28, 2018 at 12:22:52PM +0200, Ján Tomko wrote:
This test gets its JSON docs from files.
Now that we have a 'name' field in testInfo, use it instead of abusing the 'doc' field.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Instead of printing the whole JSON in error messages, print just the test name. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 6f2f7f56ed..195d8279f0 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -78,7 +78,7 @@ testJSONAddRemove(const void *data) json = virJSONValueFromString(info->doc); if (!json) { - VIR_TEST_VERBOSE("Fail to parse %s\n", info->doc); + VIR_TEST_VERBOSE("Fail to parse %s\n", info->name); ret = -1; goto cleanup; } @@ -87,7 +87,7 @@ testJSONAddRemove(const void *data) case 1: if (!info->pass) { VIR_TEST_VERBOSE("should not remove from non-object %s\n", - info->doc); + info->name); goto cleanup; } break; @@ -95,11 +95,11 @@ testJSONAddRemove(const void *data) if (!info->pass) ret = 0; else - VIR_TEST_VERBOSE("Fail to recognize non-object %s\n", info->doc); + VIR_TEST_VERBOSE("Fail to recognize non-object %s\n", info->name); goto cleanup; default: VIR_TEST_VERBOSE("unexpected result when removing from %s\n", - info->doc); + info->name); goto cleanup; } if (STRNEQ_NULLABLE(virJSONValueGetString(name), "sample")) { -- 2.16.4

On Tue, Aug 28, 2018 at 12:22:53PM +0200, Ján Tomko wrote:
Instead of printing the whole JSON in error messages, print just the test name.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

We expect to get numbers as big as ULLONG_MAX from QEMU, add a test for them. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/virjsontest.c b/tests/virjsontest.c index 195d8279f0..baf1070c5a 100644 --- a/tests/virjsontest.c +++ b/tests/virjsontest.c @@ -589,6 +589,9 @@ mymain(void) DO_TEST_PARSE("float without garbage", "[ 1.024e19 ]", "[1.024e19]"); DO_TEST_PARSE_FAIL("float with garbage", "[ 0.0314159ee+100 ]"); + DO_TEST_PARSE("unsigned minus one", "[ 18446744073709551615 ]", "[18446744073709551615]"); + DO_TEST_PARSE("another big number", "[ 9223372036854775808 ]", "[9223372036854775808]"); + DO_TEST_PARSE("string", "[ \"The meaning of life\" ]", "[\"The meaning of life\"]"); DO_TEST_PARSE_FAIL("unterminated string", "[ \"The meaning of lif ]"); -- 2.16.4

On Tue, Aug 28, 2018 at 12:22:54PM +0200, Ján Tomko wrote:
We expect to get numbers as big as ULLONG_MAX from QEMU, add a test for them.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/virjsontest.c | 3 +++ 1 file changed, 3 insertions(+)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|

Test that we correctly accept 64-bit unsigned numbers for QEMU. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/qemumonitorjsontest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 2859d3e82f..36263aad68 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1515,7 +1515,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBalloonInfo(const void *data) if (qemuMonitorTestAddItem(test, "query-balloon", "{" " \"return\": {" - " \"actual\": 4294967296" + " \"actual\": 18446744073709551615" " }," " \"id\": \"libvirt-9\"" "}") < 0) @@ -1524,7 +1524,7 @@ testQemuMonitorJSONqemuMonitorJSONGetBalloonInfo(const void *data) if (qemuMonitorJSONGetBalloonInfo(qemuMonitorTestGetMonitor(test), &currmem) < 0) goto cleanup; - if (currmem != (4294967296ULL/1024)) { + if (currmem != (18446744073709551615ULL/1024)) { virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected currmem value: %llu", currmem); goto cleanup; -- 2.16.4

On Tue, Aug 28, 2018 at 12:22:55PM +0200, Ján Tomko wrote:
Test that we correctly accept 64-bit unsigned numbers for QEMU.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tests/qemumonitorjsontest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (2)
-
Daniel P. Berrangé
-
Ján Tomko