[libvirt] [PATCH 0/6] tests: misc collection of improvments

Small collection of test suite improvements that were getting mixed in with other patches I'm working on. Patch #1 is a REGENERATE tweak for qemu argvs (this is already on list) Patch #2 fixes running schema tests from top git dir Patch #3-4 simplify the domain xml2xml tests Patch #5 adds a new driver agnostic genericxml2xml test (to be used later) Patch #6 adds QEMUCaps plumbing to qemuxml2xml (to be used later) Cole Robinson (6): tests: Add newlines with VIR_TEST_REGENERATE_OUTPUT tests: Fix running schematests directly from topdir tests: Share domain XML2XML compare helper tests: qemuxml2xml: drop early file loading tests: add genericxml2xmltest tests: qemuxml2xml: Wire up QEMUCaps usage tests/Makefile.am | 9 ++ tests/bhyvexml2xmltest.c | 30 +------ tests/capabilityschematest | 2 +- tests/domaincapsschematest | 2 +- tests/domainschematest | 4 +- tests/domainsnapshotschematest | 2 +- tests/genericxml2xmlindata/generic-disk-virtio.xml | 45 ++++++++++ .../genericxml2xmloutdata/generic-disk-virtio.xml | 45 ++++++++++ tests/genericxml2xmltest.c | 83 +++++++++++++++++++ tests/interfaceschematest | 2 +- tests/lxcxml2xmltest.c | 50 +---------- tests/networkschematest | 2 +- tests/nodedevschematest | 2 +- tests/nwfilterschematest | 2 +- tests/qemuxml2xmltest.c | 96 ++++++---------------- tests/secretschematest | 2 +- tests/storagepoolschematest | 2 +- tests/storagevolschematest | 2 +- tests/test-lib.sh | 9 +- tests/testutils.c | 47 ++++++++++- tests/testutils.h | 6 ++ 21 files changed, 281 insertions(+), 163 deletions(-) create mode 100644 tests/genericxml2xmlindata/generic-disk-virtio.xml create mode 100644 tests/genericxml2xmloutdata/generic-disk-virtio.xml create mode 100644 tests/genericxml2xmltest.c -- 2.5.0

Since test files are formatted predictably nowadays, we can make VIR_TEST_REGENERATE_OUTPUT handle most cases for us with a simple replacement. test-wrap-argv.pl is still canon, but this bit makes it easier to confirm test output changes during active development. --- tests/testutils.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/testutils.c b/tests/testutils.c index 6645d61..0091fcd 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -469,10 +469,19 @@ virtTestDifferenceFullInternal(FILE *stream, actualStart = actual; actualEnd = actual + (strlen(actual)-1); - if (regenerate && virTestGetRegenerate() > 0) { + if (regenerate && (virTestGetRegenerate() > 0) && expectName && actual) { + char *regencontent; + + /* Try to properly indent qemu argv files */ + if (!(regencontent = virStringReplace(actual, " -", " \\\n-"))) + return -1; + if (expectName && actual && - virFileWriteStr(expectName, actual, 0666) < 0) + virFileWriteStr(expectName, regencontent, 0666) < 0) { + VIR_FREE(regencontent); return -1; + } + VIR_FREE(regencontent); } if (!virTestGetDebug()) -- 2.5.0

On 01/08/2016 07:13 PM, Cole Robinson wrote:
Since test files are formatted predictably nowadays, we can make VIR_TEST_REGENERATE_OUTPUT handle most cases for us with a simple replacement. test-wrap-argv.pl is still canon, but this bit makes it easier to confirm test output changes during active development. --- tests/testutils.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/tests/testutils.c b/tests/testutils.c index 6645d61..0091fcd 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -469,10 +469,19 @@ virtTestDifferenceFullInternal(FILE *stream, actualStart = actual; actualEnd = actual + (strlen(actual)-1);
- if (regenerate && virTestGetRegenerate() > 0) { + if (regenerate && (virTestGetRegenerate() > 0) && expectName && actual) { + char *regencontent; + + /* Try to properly indent qemu argv files */ + if (!(regencontent = virStringReplace(actual, " -", " \\\n-"))) + return -1; + if (expectName && actual && - virFileWriteStr(expectName, actual, 0666) < 0) + virFileWriteStr(expectName, regencontent, 0666) < 0) { + VIR_FREE(regencontent); return -1; + } + VIR_FREE(regencontent); }
if (!virTestGetDebug())
ACK (although the whole REGENERATE_OUTPUT thing makes me worry that someone may be lulled into blindly regenerating the test output in some case where the test really is catching a regression)

On 01/08/2016 08:59 PM, Laine Stump wrote:
On 01/08/2016 07:13 PM, Cole Robinson wrote:
Since test files are formatted predictably nowadays, we can make VIR_TEST_REGENERATE_OUTPUT handle most cases for us with a simple replacement. test-wrap-argv.pl is still canon, but this bit makes it easier to confirm test output changes during active development. --- tests/testutils.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/tests/testutils.c b/tests/testutils.c index 6645d61..0091fcd 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -469,10 +469,19 @@ virtTestDifferenceFullInternal(FILE *stream, actualStart = actual; actualEnd = actual + (strlen(actual)-1); - if (regenerate && virTestGetRegenerate() > 0) { + if (regenerate && (virTestGetRegenerate() > 0) && expectName && actual) { + char *regencontent; + + /* Try to properly indent qemu argv files */ + if (!(regencontent = virStringReplace(actual, " -", " \\\n-"))) + return -1; + if (expectName && actual && - virFileWriteStr(expectName, actual, 0666) < 0) + virFileWriteStr(expectName, regencontent, 0666) < 0) { + VIR_FREE(regencontent); return -1; + } + VIR_FREE(regencontent); } if (!virTestGetDebug())
ACK (although the whole REGENERATE_OUTPUT thing makes me worry that someone may be lulled into blindly regenerating the test output in some case where the test really is catching a regression)
Yeah it's a risk, but that's what code review is for :) The alternative of hand editing XML files is exhausting I've pushed these patches now, thanks for the review! - Cole

On 01/08/2016 09:21 PM, Cole Robinson wrote:
On 01/08/2016 08:59 PM, Laine Stump wrote:
On 01/08/2016 07:13 PM, Cole Robinson wrote:
Since test files are formatted predictably nowadays, we can make VIR_TEST_REGENERATE_OUTPUT handle most cases for us with a simple replacement. test-wrap-argv.pl is still canon, but this bit makes it easier to confirm test output changes during active development. --- tests/testutils.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
FWIW: Coverity has a complaint...
diff --git a/tests/testutils.c b/tests/testutils.c index 6645d61..0091fcd 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -469,10 +469,19 @@ virtTestDifferenceFullInternal(FILE *stream, actualStart = actual; actualEnd = actual + (strlen(actual)-1); - if (regenerate && virTestGetRegenerate() > 0) { + if (regenerate && (virTestGetRegenerate() > 0) && expectName && actual) {
(3) Event check_after_deref: Null-checking "actual" suggests that it may be null, but it has already been dereferenced on all paths leading to the check. Also of note is a few lines earlier: 464 if (!actual) 465 actual = ""; Did perhaps you want to see if actual was an empty string? John
+ char *regencontent; + + /* Try to properly indent qemu argv files */ + if (!(regencontent = virStringReplace(actual, " -", " \\\n-"))) + return -1; + if (expectName && actual && - virFileWriteStr(expectName, actual, 0666) < 0) + virFileWriteStr(expectName, regencontent, 0666) < 0) { + VIR_FREE(regencontent); return -1; + } + VIR_FREE(regencontent); } if (!virTestGetDebug())
ACK (although the whole REGENERATE_OUTPUT thing makes me worry that someone may be lulled into blindly regenerating the test output in some case where the test really is catching a regression)
Yeah it's a risk, but that's what code review is for :) The alternative of hand editing XML files is exhausting
I've pushed these patches now, thanks for the review!
- Cole
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 01/12/2016 08:29 AM, John Ferlan wrote:
On 01/08/2016 09:21 PM, Cole Robinson wrote:
On 01/08/2016 08:59 PM, Laine Stump wrote:
On 01/08/2016 07:13 PM, Cole Robinson wrote:
Since test files are formatted predictably nowadays, we can make VIR_TEST_REGENERATE_OUTPUT handle most cases for us with a simple replacement. test-wrap-argv.pl is still canon, but this bit makes it easier to confirm test output changes during active development. --- tests/testutils.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
FWIW: Coverity has a complaint...
diff --git a/tests/testutils.c b/tests/testutils.c index 6645d61..0091fcd 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -469,10 +469,19 @@ virtTestDifferenceFullInternal(FILE *stream, actualStart = actual; actualEnd = actual + (strlen(actual)-1); - if (regenerate && virTestGetRegenerate() > 0) { + if (regenerate && (virTestGetRegenerate() > 0) && expectName && actual) {
(3) Event check_after_deref: Null-checking "actual" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
Also of note is a few lines earlier:
464 if (!actual) 465 actual = "";
Did perhaps you want to see if actual was an empty string?
There's a few bits wrong here, I didn't look closely at the new code when rebasing this patch. I'll send a fix. Thanks, Cole
John
+ char *regencontent; + + /* Try to properly indent qemu argv files */ + if (!(regencontent = virStringReplace(actual, " -", " \\\n-"))) + return -1; + if (expectName && actual && - virFileWriteStr(expectName, actual, 0666) < 0) + virFileWriteStr(expectName, regencontent, 0666) < 0) { + VIR_FREE(regencontent); return -1; + } + VIR_FREE(regencontent); } if (!virTestGetDebug())
ACK (although the whole REGENERATE_OUTPUT thing makes me worry that someone may be lulled into blindly regenerating the test output in some case where the test really is catching a regression)
Yeah it's a risk, but that's what code review is for :) The alternative of hand editing XML files is exhausting
I've pushed these patches now, thanks for the review!
- Cole
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

Previously it failed like: $ ./tests/domainschematest ./tests/domainschematest: line 4: ./test-lib.sh: No such file or directory --- tests/capabilityschematest | 2 +- tests/domaincapsschematest | 2 +- tests/domainschematest | 2 +- tests/domainsnapshotschematest | 2 +- tests/interfaceschematest | 2 +- tests/networkschematest | 2 +- tests/nodedevschematest | 2 +- tests/nwfilterschematest | 2 +- tests/secretschematest | 2 +- tests/storagepoolschematest | 2 +- tests/storagevolschematest | 2 +- tests/test-lib.sh | 9 +++++---- 12 files changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/capabilityschematest b/tests/capabilityschematest index 4439842..78fbc8e 100755 --- a/tests/capabilityschematest +++ b/tests/capabilityschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/domaincapsschematest b/tests/domaincapsschematest index 9baf44a..2c19ac4 100755 --- a/tests/domaincapsschematest +++ b/tests/domaincapsschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/domainschematest b/tests/domainschematest index ba90180..31ee536 100755 --- a/tests/domainschematest +++ b/tests/domainschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/domainsnapshotschematest b/tests/domainsnapshotschematest index 1bdc539..ba28e05 100755 --- a/tests/domainsnapshotschematest +++ b/tests/domainsnapshotschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/interfaceschematest b/tests/interfaceschematest index 1ddbc53..47745ea 100755 --- a/tests/interfaceschematest +++ b/tests/interfaceschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/networkschematest b/tests/networkschematest index 46f3fc5..fe46893 100755 --- a/tests/networkschematest +++ b/tests/networkschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/nodedevschematest b/tests/nodedevschematest index 03a1577..07b1f7b 100755 --- a/tests/nodedevschematest +++ b/tests/nodedevschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/nwfilterschematest b/tests/nwfilterschematest index 2c50c03..8703e21 100755 --- a/tests/nwfilterschematest +++ b/tests/nwfilterschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/secretschematest b/tests/secretschematest index f64d1a3..23b0e2f 100755 --- a/tests/secretschematest +++ b/tests/secretschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/storagepoolschematest b/tests/storagepoolschematest index d54b827..ebea711 100755 --- a/tests/storagepoolschematest +++ b/tests/storagepoolschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/storagevolschematest b/tests/storagevolschematest index 9045e6b..395df57 100755 --- a/tests/storagevolschematest +++ b/tests/storagevolschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/test-lib.sh b/tests/test-lib.sh index aff179c..920b01e 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -18,10 +18,11 @@ # # Based on an idea from GNU coreutils -test -z "$abs_srcdir" && abs_srcdir=$(pwd) -test -z "$abs_builddir" && abs_builddir=$(pwd) -test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. -test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/.. +_scriptdir="$(realpath $(dirname $0))" +test -z "$abs_srcdir" && abs_srcdir=$_scriptdir +test -z "$abs_builddir" && abs_builddir=$_scriptdir +test -z "$abs_top_srcdir" && abs_top_srcdir=$_scriptdir/.. +test -z "$abs_top_builddir" && abs_top_builddir=$_scriptdir/.. test -z "$LC_ALL" && LC_ALL=C # Skip this test if the shell lacks support for functions. -- 2.5.0

On 01/08/2016 07:13 PM, Cole Robinson wrote:
Previously it failed like:
$ ./tests/domainschematest ./tests/domainschematest: line 4: ./test-lib.sh: No such file or directory --- tests/capabilityschematest | 2 +- tests/domaincapsschematest | 2 +- tests/domainschematest | 2 +- tests/domainsnapshotschematest | 2 +- tests/interfaceschematest | 2 +- tests/networkschematest | 2 +- tests/nodedevschematest | 2 +- tests/nwfilterschematest | 2 +- tests/secretschematest | 2 +- tests/storagepoolschematest | 2 +- tests/storagevolschematest | 2 +- tests/test-lib.sh | 9 +++++---- 12 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/tests/capabilityschematest b/tests/capabilityschematest index 4439842..78fbc8e 100755 --- a/tests/capabilityschematest +++ b/tests/capabilityschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/domaincapsschematest b/tests/domaincapsschematest index 9baf44a..2c19ac4 100755 --- a/tests/domaincapsschematest +++ b/tests/domaincapsschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/domainschematest b/tests/domainschematest index ba90180..31ee536 100755 --- a/tests/domainschematest +++ b/tests/domainschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/domainsnapshotschematest b/tests/domainsnapshotschematest index 1bdc539..ba28e05 100755 --- a/tests/domainsnapshotschematest +++ b/tests/domainsnapshotschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/interfaceschematest b/tests/interfaceschematest index 1ddbc53..47745ea 100755 --- a/tests/interfaceschematest +++ b/tests/interfaceschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/networkschematest b/tests/networkschematest index 46f3fc5..fe46893 100755 --- a/tests/networkschematest +++ b/tests/networkschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/nodedevschematest b/tests/nodedevschematest index 03a1577..07b1f7b 100755 --- a/tests/nodedevschematest +++ b/tests/nodedevschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/nwfilterschematest b/tests/nwfilterschematest index 2c50c03..8703e21 100755 --- a/tests/nwfilterschematest +++ b/tests/nwfilterschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/secretschematest b/tests/secretschematest index f64d1a3..23b0e2f 100755 --- a/tests/secretschematest +++ b/tests/secretschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/storagepoolschematest b/tests/storagepoolschematest index d54b827..ebea711 100755 --- a/tests/storagepoolschematest +++ b/tests/storagepoolschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/storagevolschematest b/tests/storagevolschematest index 9045e6b..395df57 100755 --- a/tests/storagevolschematest +++ b/tests/storagevolschematest @@ -1,6 +1,6 @@ #!/bin/sh
-: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh
diff --git a/tests/test-lib.sh b/tests/test-lib.sh index aff179c..920b01e 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -18,10 +18,11 @@ # # Based on an idea from GNU coreutils
-test -z "$abs_srcdir" && abs_srcdir=$(pwd) -test -z "$abs_builddir" && abs_builddir=$(pwd) -test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. -test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/.. +_scriptdir="$(realpath $(dirname $0))"
Is there a reason you are doing $(realpath $(dirname $0)) here, but just $(dirname $0) in the individual scripts? If there's a reasonable answer to that, then ACK.
+test -z "$abs_srcdir" && abs_srcdir=$_scriptdir +test -z "$abs_builddir" && abs_builddir=$_scriptdir +test -z "$abs_top_srcdir" && abs_top_srcdir=$_scriptdir/.. +test -z "$abs_top_builddir" && abs_top_builddir=$_scriptdir/.. test -z "$LC_ALL" && LC_ALL=C
# Skip this test if the shell lacks support for functions.

On 01/08/2016 09:04 PM, Laine Stump wrote:
On 01/08/2016 07:13 PM, Cole Robinson wrote:
Previously it failed like:
$ ./tests/domainschematest ./tests/domainschematest: line 4: ./test-lib.sh: No such file or directory --- tests/capabilityschematest | 2 +- tests/domaincapsschematest | 2 +- tests/domainschematest | 2 +- tests/domainsnapshotschematest | 2 +- tests/interfaceschematest | 2 +- tests/networkschematest | 2 +- tests/nodedevschematest | 2 +- tests/nwfilterschematest | 2 +- tests/secretschematest | 2 +- tests/storagepoolschematest | 2 +- tests/storagevolschematest | 2 +- tests/test-lib.sh | 9 +++++---- 12 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/tests/capabilityschematest b/tests/capabilityschematest index 4439842..78fbc8e 100755 --- a/tests/capabilityschematest +++ b/tests/capabilityschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/domaincapsschematest b/tests/domaincapsschematest index 9baf44a..2c19ac4 100755 --- a/tests/domaincapsschematest +++ b/tests/domaincapsschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/domainschematest b/tests/domainschematest index ba90180..31ee536 100755 --- a/tests/domainschematest +++ b/tests/domainschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/domainsnapshotschematest b/tests/domainsnapshotschematest index 1bdc539..ba28e05 100755 --- a/tests/domainsnapshotschematest +++ b/tests/domainsnapshotschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/interfaceschematest b/tests/interfaceschematest index 1ddbc53..47745ea 100755 --- a/tests/interfaceschematest +++ b/tests/interfaceschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/networkschematest b/tests/networkschematest index 46f3fc5..fe46893 100755 --- a/tests/networkschematest +++ b/tests/networkschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/nodedevschematest b/tests/nodedevschematest index 03a1577..07b1f7b 100755 --- a/tests/nodedevschematest +++ b/tests/nodedevschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/nwfilterschematest b/tests/nwfilterschematest index 2c50c03..8703e21 100755 --- a/tests/nwfilterschematest +++ b/tests/nwfilterschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/secretschematest b/tests/secretschematest index f64d1a3..23b0e2f 100755 --- a/tests/secretschematest +++ b/tests/secretschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/storagepoolschematest b/tests/storagepoolschematest index d54b827..ebea711 100755 --- a/tests/storagepoolschematest +++ b/tests/storagepoolschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/storagevolschematest b/tests/storagevolschematest index 9045e6b..395df57 100755 --- a/tests/storagevolschematest +++ b/tests/storagevolschematest @@ -1,6 +1,6 @@ #!/bin/sh -: ${srcdir=.} +: ${srcdir=$(dirname $0)} . $srcdir/test-lib.sh . $abs_srcdir/schematestutils.sh diff --git a/tests/test-lib.sh b/tests/test-lib.sh index aff179c..920b01e 100644 --- a/tests/test-lib.sh +++ b/tests/test-lib.sh @@ -18,10 +18,11 @@ # # Based on an idea from GNU coreutils -test -z "$abs_srcdir" && abs_srcdir=$(pwd) -test -z "$abs_builddir" && abs_builddir=$(pwd) -test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/.. -test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/.. +_scriptdir="$(realpath $(dirname $0))"
Is there a reason you are doing $(realpath $(dirname $0)) here, but just $(dirname $0) in the individual scripts? If there's a reasonable answer to that, then ACK.
Yes, because we need the absolute path here for these abs_* variables. The individual scripts just need the relative path from dirname Thanks, Cole
+test -z "$abs_srcdir" && abs_srcdir=$_scriptdir +test -z "$abs_builddir" && abs_builddir=$_scriptdir +test -z "$abs_top_srcdir" && abs_top_srcdir=$_scriptdir/.. +test -z "$abs_top_builddir" && abs_top_builddir=$_scriptdir/.. test -z "$LC_ALL" && LC_ALL=C # Skip this test if the shell lacks support for functions.

This creates a shared function in testutils.c that consolidates all the slightly different implementations. --- tests/bhyvexml2xmltest.c | 30 +++----------------------- tests/lxcxml2xmltest.c | 50 +++---------------------------------------- tests/qemuxml2xmltest.c | 55 ++++-------------------------------------------- tests/testutils.c | 34 ++++++++++++++++++++++++++++++ tests/testutils.h | 6 ++++++ 5 files changed, 50 insertions(+), 125 deletions(-) diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index 826baea..d860a41 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -11,31 +11,6 @@ static bhyveConn driver; -static int -testCompareXMLToXMLFiles(const char *inxml, const char *outxml) -{ - char *actual = NULL; - virDomainDefPtr def = NULL; - int ret = -1; - - if (!(def = virDomainDefParseFile(inxml, driver.caps, driver.xmlopt, - VIR_DOMAIN_DEF_PARSE_INACTIVE))) - goto fail; - - if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE))) - goto fail; - - if (virtTestCompareToFile(actual, outxml) < 0) - goto fail; - - ret = 0; - - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - struct testInfo { const char *name; bool different; @@ -55,8 +30,9 @@ testCompareXMLToXMLHelper(const void *data) abs_srcdir, info->name) < 0) goto cleanup; - ret = testCompareXMLToXMLFiles(xml_in, - info->different ? xml_out : xml_in); + ret = testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, xml_in, + info->different ? xml_out : xml_in, + false); cleanup: VIR_FREE(xml_in); diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 8d824b9..e460d0a 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -22,35 +22,6 @@ static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; -static int -testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) -{ - char *actual = NULL; - int ret = -1; - virDomainDefPtr def = NULL; - - if (!(def = virDomainDefParseFile(inxml, caps, xmlopt, - live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE))) - goto fail; - - if (!virDomainDefCheckABIStability(def, def)) { - fprintf(stderr, "ABI stability check failed on %s", inxml); - goto fail; - } - - if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE))) - goto fail; - - if (virtTestCompareToFile(actual, outxml) < 0) - goto fail; - - ret = 0; - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - struct testInfo { const char *name; int different; @@ -71,24 +42,9 @@ testCompareXMLToXMLHelper(const void *data) abs_srcdir, info->name) < 0) goto cleanup; - if (info->different) { - if (testCompareXMLToXMLFiles(xml_in, xml_out, false) < 0) - goto cleanup; - } else { - if (testCompareXMLToXMLFiles(xml_in, xml_in, false) < 0) - goto cleanup; - } - if (!info->inactive_only) { - if (info->different) { - if (testCompareXMLToXMLFiles(xml_in, xml_out, true) < 0) - goto cleanup; - } else { - if (testCompareXMLToXMLFiles(xml_in, xml_in, true) < 0) - goto cleanup; - } - } - - ret = 0; + ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, + info->different ? xml_out : xml_in, + !info->inactive_only); cleanup: VIR_FREE(xml_in); VIR_FREE(xml_out); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index d654182..312bb53 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -40,56 +40,12 @@ struct testInfo { }; static int -testXML2XMLHelper(const char *inxml, - const char *inXmlData, - const char *outxml, - const char *outXmlData, - bool live) -{ - char *actual = NULL; - int ret = -1; - virDomainDefPtr def = NULL; - unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; - unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; - if (!live) - format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; - - if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt, - parse_flags))) - goto fail; - - if (!virDomainDefCheckABIStability(def, def)) { - VIR_TEST_DEBUG("ABI stability check failed on %s", inxml); - goto fail; - } - - if (!(actual = virDomainDefFormat(def, format_flags))) - goto fail; - - if (STRNEQ(outXmlData, actual)) { - virtTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml); - goto fail; - } - - ret = 0; - - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - - -static int testXML2XMLActive(const void *opaque) { const struct testInfo *info = opaque; - return testXML2XMLHelper(info->inName, - info->inFile, - info->outActiveName, - info->outActiveFile, - true); + return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, + info->inName, info->outActiveName, true); } @@ -98,11 +54,8 @@ testXML2XMLInactive(const void *opaque) { const struct testInfo *info = opaque; - return testXML2XMLHelper(info->inName, - info->inFile, - info->outInactiveName, - info->outInactiveFile, - false); + return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName, + info->outInactiveName, false); } diff --git a/tests/testutils.c b/tests/testutils.c index 0091fcd..4ffea0c 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1072,6 +1072,40 @@ virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void) } +int +testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, + const char *infile, const char *outfile, bool live) +{ + char *actual = NULL; + int ret = -1; + virDomainDefPtr def = NULL; + unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; + unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; + if (!live) + format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; + + if (!(def = virDomainDefParseFile(infile, caps, xmlopt, parse_flags))) + goto fail; + + if (!virDomainDefCheckABIStability(def, def)) { + VIR_TEST_DEBUG("ABI stability check failed on %s", infile); + goto fail; + } + + if (!(actual = virDomainDefFormat(def, format_flags))) + goto fail; + + if (virtTestCompareToFile(actual, outfile) < 0) + goto fail; + + ret = 0; + fail: + VIR_FREE(actual); + virDomainDefFree(def); + return ret; +} + + static int virtTestCounter; static char virtTestCounterStr[128]; static char *virtTestCounterPrefixEndOffset; diff --git a/tests/testutils.h b/tests/testutils.h index 3bd9004..b1d7397 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -137,4 +137,10 @@ int virtTestMain(int argc, virCapsPtr virTestGenericCapsInit(void); virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void); +int testCompareDomXML2XMLFiles(virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + const char *inxml, + const char *outfile, + bool live); + #endif /* __VIT_TEST_UTILS_H__ */ -- 2.5.0

On 01/08/2016 07:13 PM, Cole Robinson wrote:
This creates a shared function in testutils.c that consolidates all the slightly different implementations. --- tests/bhyvexml2xmltest.c | 30 +++----------------------- tests/lxcxml2xmltest.c | 50 +++---------------------------------------- tests/qemuxml2xmltest.c | 55 ++++-------------------------------------------- tests/testutils.c | 34 ++++++++++++++++++++++++++++++ tests/testutils.h | 6 ++++++ 5 files changed, 50 insertions(+), 125 deletions(-)
ACK (assuming that make check succeeds with the changes of course :-)
diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index 826baea..d860a41 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -11,31 +11,6 @@
static bhyveConn driver;
-static int -testCompareXMLToXMLFiles(const char *inxml, const char *outxml) -{ - char *actual = NULL; - virDomainDefPtr def = NULL; - int ret = -1; - - if (!(def = virDomainDefParseFile(inxml, driver.caps, driver.xmlopt, - VIR_DOMAIN_DEF_PARSE_INACTIVE))) - goto fail; - - if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_INACTIVE))) - goto fail; - - if (virtTestCompareToFile(actual, outxml) < 0) - goto fail; - - ret = 0; - - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - struct testInfo { const char *name; bool different; @@ -55,8 +30,9 @@ testCompareXMLToXMLHelper(const void *data) abs_srcdir, info->name) < 0) goto cleanup;
- ret = testCompareXMLToXMLFiles(xml_in, - info->different ? xml_out : xml_in); + ret = testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, xml_in, + info->different ? xml_out : xml_in, + false);
cleanup: VIR_FREE(xml_in); diff --git a/tests/lxcxml2xmltest.c b/tests/lxcxml2xmltest.c index 8d824b9..e460d0a 100644 --- a/tests/lxcxml2xmltest.c +++ b/tests/lxcxml2xmltest.c @@ -22,35 +22,6 @@ static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt;
-static int -testCompareXMLToXMLFiles(const char *inxml, const char *outxml, bool live) -{ - char *actual = NULL; - int ret = -1; - virDomainDefPtr def = NULL; - - if (!(def = virDomainDefParseFile(inxml, caps, xmlopt, - live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE))) - goto fail; - - if (!virDomainDefCheckABIStability(def, def)) { - fprintf(stderr, "ABI stability check failed on %s", inxml); - goto fail; - } - - if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_DEF_FORMAT_SECURE))) - goto fail; - - if (virtTestCompareToFile(actual, outxml) < 0) - goto fail; - - ret = 0; - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - struct testInfo { const char *name; int different; @@ -71,24 +42,9 @@ testCompareXMLToXMLHelper(const void *data) abs_srcdir, info->name) < 0) goto cleanup;
- if (info->different) { - if (testCompareXMLToXMLFiles(xml_in, xml_out, false) < 0) - goto cleanup; - } else { - if (testCompareXMLToXMLFiles(xml_in, xml_in, false) < 0) - goto cleanup; - } - if (!info->inactive_only) { - if (info->different) { - if (testCompareXMLToXMLFiles(xml_in, xml_out, true) < 0) - goto cleanup; - } else { - if (testCompareXMLToXMLFiles(xml_in, xml_in, true) < 0) - goto cleanup; - } - } - - ret = 0; + ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, + info->different ? xml_out : xml_in, + !info->inactive_only); cleanup: VIR_FREE(xml_in); VIR_FREE(xml_out); diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index d654182..312bb53 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -40,56 +40,12 @@ struct testInfo { };
static int -testXML2XMLHelper(const char *inxml, - const char *inXmlData, - const char *outxml, - const char *outXmlData, - bool live) -{ - char *actual = NULL; - int ret = -1; - virDomainDefPtr def = NULL; - unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; - unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; - if (!live) - format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; - - if (!(def = virDomainDefParseString(inXmlData, driver.caps, driver.xmlopt, - parse_flags))) - goto fail; - - if (!virDomainDefCheckABIStability(def, def)) { - VIR_TEST_DEBUG("ABI stability check failed on %s", inxml); - goto fail; - } - - if (!(actual = virDomainDefFormat(def, format_flags))) - goto fail; - - if (STRNEQ(outXmlData, actual)) { - virtTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml); - goto fail; - } - - ret = 0; - - fail: - VIR_FREE(actual); - virDomainDefFree(def); - return ret; -} - - -static int testXML2XMLActive(const void *opaque) { const struct testInfo *info = opaque;
- return testXML2XMLHelper(info->inName, - info->inFile, - info->outActiveName, - info->outActiveFile, - true); + return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, + info->inName, info->outActiveName, true); }
@@ -98,11 +54,8 @@ testXML2XMLInactive(const void *opaque) { const struct testInfo *info = opaque;
- return testXML2XMLHelper(info->inName, - info->inFile, - info->outInactiveName, - info->outInactiveFile, - false); + return testCompareDomXML2XMLFiles(driver.caps, driver.xmlopt, info->inName, + info->outInactiveName, false); }
diff --git a/tests/testutils.c b/tests/testutils.c index 0091fcd..4ffea0c 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -1072,6 +1072,40 @@ virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void) }
+int +testCompareDomXML2XMLFiles(virCapsPtr caps, virDomainXMLOptionPtr xmlopt, + const char *infile, const char *outfile, bool live) +{ + char *actual = NULL; + int ret = -1; + virDomainDefPtr def = NULL; + unsigned int parse_flags = live ? 0 : VIR_DOMAIN_DEF_PARSE_INACTIVE; + unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE; + if (!live) + format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE; + + if (!(def = virDomainDefParseFile(infile, caps, xmlopt, parse_flags))) + goto fail; + + if (!virDomainDefCheckABIStability(def, def)) { + VIR_TEST_DEBUG("ABI stability check failed on %s", infile); + goto fail; + } + + if (!(actual = virDomainDefFormat(def, format_flags))) + goto fail; + + if (virtTestCompareToFile(actual, outfile) < 0) + goto fail; + + ret = 0; + fail: + VIR_FREE(actual); + virDomainDefFree(def); + return ret; +} + + static int virtTestCounter; static char virtTestCounterStr[128]; static char *virtTestCounterPrefixEndOffset; diff --git a/tests/testutils.h b/tests/testutils.h index 3bd9004..b1d7397 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -137,4 +137,10 @@ int virtTestMain(int argc, virCapsPtr virTestGenericCapsInit(void); virDomainXMLOptionPtr virTestGenericDomainXMLConfInit(void);
+int testCompareDomXML2XMLFiles(virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + const char *inxml, + const char *outfile, + bool live); + #endif /* __VIT_TEST_UTILS_H__ */

For the standard active/inactive XML testing, if we leave the file loading up to the generic XML2XML infrastructure, we get the benefit of VIR_TEST_REGENERATE_OUTPUT, at the price of a few more disk reads. Seems worth it. --- tests/qemuxml2xmltest.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 312bb53..9482f6c 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -30,13 +30,8 @@ enum { struct testInfo { char *inName; - char *inFile; - char *outActiveName; - char *outActiveFile; - char *outInactiveName; - char *outInactiveFile; }; static int @@ -95,13 +90,19 @@ testCompareStatusXMLToXMLFiles(const void *opaque) char *expect = NULL; char *actual = NULL; char *source = NULL; + char *inFile = NULL, *outActiveFile = NULL; int ret = -1; int keepBlanksDefault = xmlKeepBlanksDefault(0); + if (virtTestLoadFile(data->inName, &inFile) < 0) + goto cleanup; + if (virtTestLoadFile(data->outActiveName, &outActiveFile) < 0) + goto cleanup; + /* construct faked source status XML */ virBufferAdd(&buf, testStatusXMLPrefix, -1); virBufferAdjustIndent(&buf, 2); - virBufferAddStr(&buf, data->inFile); + virBufferAddStr(&buf, inFile); virBufferAdjustIndent(&buf, -2); virBufferAdd(&buf, testStatusXMLSuffix, -1); @@ -113,7 +114,7 @@ testCompareStatusXMLToXMLFiles(const void *opaque) /* construct the expect string */ virBufferAdd(&buf, testStatusXMLPrefix, -1); virBufferAdjustIndent(&buf, 2); - virBufferAddStr(&buf, data->outActiveFile); + virBufferAddStr(&buf, outActiveFile); virBufferAdjustIndent(&buf, -2); virBufferAdd(&buf, testStatusXMLSuffix, -1); @@ -158,6 +159,8 @@ testCompareStatusXMLToXMLFiles(const void *opaque) VIR_FREE(expect); VIR_FREE(actual); VIR_FREE(source); + VIR_FREE(inFile); + VIR_FREE(outActiveFile); return ret; } @@ -166,13 +169,8 @@ static void testInfoFree(struct testInfo *info) { VIR_FREE(info->inName); - VIR_FREE(info->inFile); - VIR_FREE(info->outActiveName); - VIR_FREE(info->outActiveFile); - VIR_FREE(info->outInactiveName); - VIR_FREE(info->outInactiveFile); } @@ -186,9 +184,6 @@ testInfoSet(struct testInfo *info, abs_srcdir, name) < 0) goto error; - if (virtTestLoadFile(info->inName, &info->inFile) < 0) - goto error; - if (when & WHEN_INACTIVE) { if (different) { if (virAsprintf(&info->outInactiveName, @@ -208,9 +203,6 @@ testInfoSet(struct testInfo *info, if (VIR_STRDUP(info->outInactiveName, info->inName) < 0) goto error; } - - if (virtTestLoadFile(info->outInactiveName, &info->outInactiveFile) < 0) - goto error; } if (when & WHEN_ACTIVE) { @@ -233,8 +225,6 @@ testInfoSet(struct testInfo *info, goto error; } - if (virtTestLoadFile(info->outActiveName, &info->outActiveFile) < 0) - goto error; } return 0; -- 2.5.0

On 01/08/2016 07:13 PM, Cole Robinson wrote:
For the standard active/inactive XML testing, if we leave the file loading up to the generic XML2XML infrastructure, we get the benefit of VIR_TEST_REGENERATE_OUTPUT, at the price of a few more disk reads. Seems worth it. --- tests/qemuxml2xmltest.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-)
ACK.

For testing hypervisor independent XML handling. Right now it's just populated with an example test case. --- tests/Makefile.am | 9 +++ tests/domainschematest | 2 +- tests/genericxml2xmlindata/generic-disk-virtio.xml | 45 ++++++++++++ .../genericxml2xmloutdata/generic-disk-virtio.xml | 45 ++++++++++++ tests/genericxml2xmltest.c | 83 ++++++++++++++++++++++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 tests/genericxml2xmlindata/generic-disk-virtio.xml create mode 100644 tests/genericxml2xmloutdata/generic-disk-virtio.xml create mode 100644 tests/genericxml2xmltest.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 1d57b39..ee16666 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -89,6 +89,8 @@ EXTRA_DIST = \ domainsnapshotxml2xmlin \ domainsnapshotxml2xmlout \ fchostdata \ + genericxml2xmlindata \ + genericxml2xmloutdata \ interfaceschemadata \ lxcconf2xmldata \ lxcxml2xmldata \ @@ -334,6 +336,8 @@ test_programs += metadatatest test_programs += secretxml2xmltest +test_programs += genericxml2xmltest + if WITH_LINUX test_programs += virusbtest \ virnetdevbandwidthtest \ @@ -800,6 +804,11 @@ secretxml2xmltest_SOURCES = \ testutils.c testutils.h secretxml2xmltest_LDADD = $(LDADDS) +genericxml2xmltest_SOURCES = \ + genericxml2xmltest.c \ + testutils.c testutils.h +genericxml2xmltest_LDADD = $(LDADDS) + if WITH_STORAGE storagevolxml2argvtest_SOURCES = \ diff --git a/tests/domainschematest b/tests/domainschematest index 31ee536..479fd23 100755 --- a/tests/domainschematest +++ b/tests/domainschematest @@ -8,7 +8,7 @@ DIRS="" DIRS="$DIRS domainschemadata qemuxml2argvdata sexpr2xmldata" DIRS="$DIRS xmconfigdata xml2sexprdata qemuxml2xmloutdata" DIRS="$DIRS lxcxml2xmldata lxcxml2xmloutdata" -DIRS="$DIRS bhyvexml2argvdata" +DIRS="$DIRS bhyvexml2argvdata genericxml2xmlindata genericxml2xmloutdata" SCHEMA="domain.rng" check_schema "$DIRS" "$SCHEMA" diff --git a/tests/genericxml2xmlindata/generic-disk-virtio.xml b/tests/genericxml2xmlindata/generic-disk-virtio.xml new file mode 100644 index 0000000..458c55d --- /dev/null +++ b/tests/genericxml2xmlindata/generic-disk-virtio.xml @@ -0,0 +1,45 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <disk type='block' device='cdrom'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest2'/> + <target dev='hdc' bus='ide'/> + <readonly/> + <address type='drive' controller='0' bus='1' target='0' unit='0'/> + </disk> + <disk type='file' device='disk'> + <driver name='qemu' type='raw'/> + <source file='/tmp/data.img'/> + <target dev='vda' bus='virtio'/> + </disk> + <disk type='file' device='disk'> + <driver name='qemu' type='raw'/> + <source file='/tmp/logs.img'/> + <target dev='vdb' bus='virtio'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/genericxml2xmloutdata/generic-disk-virtio.xml b/tests/genericxml2xmloutdata/generic-disk-virtio.xml new file mode 100644 index 0000000..458c55d --- /dev/null +++ b/tests/genericxml2xmloutdata/generic-disk-virtio.xml @@ -0,0 +1,45 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <disk type='block' device='cdrom'> + <driver name='qemu' type='raw'/> + <source dev='/dev/HostVG/QEMUGuest2'/> + <target dev='hdc' bus='ide'/> + <readonly/> + <address type='drive' controller='0' bus='1' target='0' unit='0'/> + </disk> + <disk type='file' device='disk'> + <driver name='qemu' type='raw'/> + <source file='/tmp/data.img'/> + <target dev='vda' bus='virtio'/> + </disk> + <disk type='file' device='disk'> + <driver name='qemu' type='raw'/> + <source file='/tmp/logs.img'/> + <target dev='vdb' bus='virtio'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/genericxml2xmltest.c b/tests/genericxml2xmltest.c new file mode 100644 index 0000000..7f79896 --- /dev/null +++ b/tests/genericxml2xmltest.c @@ -0,0 +1,83 @@ +#include <config.h> + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> + +#include <sys/types.h> +#include <fcntl.h> + +#include "testutils.h" +#include "internal.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_NONE + +static virCapsPtr caps; +static virDomainXMLOptionPtr xmlopt; + +struct testInfo { + const char *name; + int different; + bool inactive_only; +}; + +static int +testCompareXMLToXMLHelper(const void *data) +{ + const struct testInfo *info = data; + char *xml_in = NULL; + char *xml_out = NULL; + int ret = -1; + + if (virAsprintf(&xml_in, "%s/genericxml2xmlindata/generic-%s.xml", + abs_srcdir, info->name) < 0 || + virAsprintf(&xml_out, "%s/genericxml2xmloutdata/generic-%s.xml", + abs_srcdir, info->name) < 0) + goto cleanup; + + ret = testCompareDomXML2XMLFiles(caps, xmlopt, xml_in, + info->different ? xml_out : xml_in, + !info->inactive_only); + cleanup: + VIR_FREE(xml_in); + VIR_FREE(xml_out); + return ret; +} + + +static int +mymain(void) +{ + int ret = 0; + + if (!(caps = virTestGenericCapsInit())) + return EXIT_FAILURE; + + if (!(xmlopt = virTestGenericDomainXMLConfInit())) + return EXIT_FAILURE; + +#define DO_TEST_FULL(name, is_different, inactive) \ + do { \ + const struct testInfo info = {name, is_different, inactive}; \ + if (virtTestRun("GENERIC XML-2-XML " name, \ + testCompareXMLToXMLHelper, &info) < 0) \ + ret = -1; \ + } while (0) + +#define DO_TEST(name) \ + DO_TEST_FULL(name, 0, false) + +#define DO_TEST_DIFFERENT(name) \ + DO_TEST_FULL(name, 1, false) + + DO_TEST_DIFFERENT("disk-virtio"); + + virObjectUnref(caps); + virObjectUnref(xmlopt); + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIRT_TEST_MAIN(mymain) -- 2.5.0

On 01/08/2016 07:13 PM, Cole Robinson wrote:
For testing hypervisor independent XML handling. Right now it's just populated with an example test case. --- tests/Makefile.am | 9 +++ tests/domainschematest | 2 +- tests/genericxml2xmlindata/generic-disk-virtio.xml | 45 ++++++++++++ .../genericxml2xmloutdata/generic-disk-virtio.xml | 45 ++++++++++++ tests/genericxml2xmltest.c | 83 ++++++++++++++++++++++ 5 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 tests/genericxml2xmlindata/generic-disk-virtio.xml create mode 100644 tests/genericxml2xmloutdata/generic-disk-virtio.xml create mode 100644 tests/genericxml2xmltest.c
ACK.

Future changes will make some of these tests dependent on specific QEMUCaps flags, so wire up the basic handling. Flags will be added in future patches. --- tests/qemuxml2xmltest.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 9482f6c..ab20fca 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -32,6 +32,8 @@ struct testInfo { char *inName; char *outActiveName; char *outInactiveName; + + virQEMUCapsPtr qemuCaps; }; static int @@ -171,6 +173,8 @@ testInfoFree(struct testInfo *info) VIR_FREE(info->inName); VIR_FREE(info->outActiveName); VIR_FREE(info->outInactiveName); + + virObjectUnref(info->qemuCaps); } @@ -180,6 +184,13 @@ testInfoSet(struct testInfo *info, bool different, int when) { + if (!(info->qemuCaps = virQEMUCapsNew())) + goto error; + + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, name, + info->qemuCaps) < 0) + goto error; + if (virAsprintf(&info->inName, "%s/qemuxml2argvdata/qemuxml2argv-%s.xml", abs_srcdir, name) < 0) goto error; -- 2.5.0

On 01/08/2016 07:13 PM, Cole Robinson wrote:
Future changes will make some of these tests dependent on specific QEMUCaps flags, so wire up the basic handling. Flags will be added in future patches. --- tests/qemuxml2xmltest.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
Yeah, I've missed not having this a few times. ACK.
participants (3)
-
Cole Robinson
-
John Ferlan
-
Laine Stump