Most of the tests assumed that $(srcdir) == .
This makes it so "make check" passes in a non-srcdir build, i.e.,
"mkdir build && cd build && ../configure && make &&
make check"
Arrange for tests to pass in a non-srcdir build.
* tests/Makefile.am: Include the contents of the *data directories
in the make-dist-built tarball by adding each of that *data
directories to EXTRA_DIST.
Also add int-overflow (via $(test_scripts)) to EXTRA_DIST.
* tests/nodeinfotest.c: Prepend "$abs_top_srcdir/tests" to
each input file name.
* tests/qemuxml2argvtest.c: Likewise.
* tests/qemuxml2xmltest.c: Likewise.
* tests/sexpr2xmltest.c: Likewise.
* tests/test_conf.sh: Likewise.
* tests/virshtest.c: Likewise.
* tests/xencapstest.c: Likewise.
* tests/xmconfigtest.c: Likewise.
* tests/xml2sexprtest.c: Likewise.
---
tests/Makefile.am | 18 ++++++++++++++++--
tests/nodeinfotest.c | 14 +++++++++++---
tests/qemuxml2argvtest.c | 11 +++++++++--
tests/qemuxml2xmltest.c | 8 +++++++-
tests/sexpr2xmltest.c | 13 ++++++++++++-
tests/test_conf.sh | 5 +++--
tests/virshtest.c | 13 +++++++++----
tests/xencapstest.c | 22 +++++++++++++++++++---
tests/xmconfigtest.c | 21 +++++++++++++++++++--
tests/xml2sexprtest.c | 13 ++++++++++++-
10 files changed, 117 insertions(+), 21 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8a472f8..fec2f20 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -31,15 +31,29 @@ LDADDS = \
$(LIBVIRT) \
$(COVERAGE_LDFLAGS)
-EXTRA_DIST = xmlrpcserver.py test_conf.sh
+EXTRA_DIST = \
+ xmlrpcserver.py \
+ test_conf.sh \
+ confdata \
+ qemuxml2argvdata \
+ xml2sexprdata \
+ nodeinfodata \
+ virshdata \
+ xencapsdata \
+ sexpr2xmldata \
+ xmconfigdata
noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \
reconnect xmconfigtest xencapstest qemuxml2argvtest qemuxml2xmltest \
nodeinfotest
+test_scripts = \
+ int-overflow
+EXTRA_DIST += $(test_scripts)
+
TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh xmconfigtest \
xencapstest qemuxml2argvtest qemuxml2xmltest nodeinfotest \
- int-overflow
+ $(test_scripts)
if ENABLE_XEN_TESTS
TESTS += reconnect
endif
diff --git a/tests/nodeinfotest.c b/tests/nodeinfotest.c
index 604f5a4..8b22b71 100644
--- a/tests/nodeinfotest.c
+++ b/tests/nodeinfotest.c
@@ -10,6 +10,7 @@
#include "nodeinfo.h"
static char *progname;
+static char *abs_top_srcdir;
#define MAX_FILE 4096
@@ -67,9 +68,12 @@ static int linuxTestNodeInfo(const void *data) {
char cpuinfo[PATH_MAX];
char meminfo[PATH_MAX];
char output[PATH_MAX];
- snprintf(cpuinfo, PATH_MAX, "nodeinfodata/linux-%s.cpuinfo", (const
char*)data);
- snprintf(meminfo, PATH_MAX, "nodeinfodata/linux-%s.meminfo", (const
char*)data);
- snprintf(output, PATH_MAX, "nodeinfodata/linux-%s.txt", (const
char*)data);
+ snprintf(cpuinfo, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.cpuinfo",
+ abs_top_srcdir, (const char*)data);
+ snprintf(meminfo, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.meminfo",
+ abs_top_srcdir, (const char*)data);
+ snprintf(output, PATH_MAX, "%s/tests/nodeinfodata/linux-%s.txt",
+ abs_top_srcdir, (const char*)data);
return linuxTestCompareFiles(cpuinfo, meminfo, output);
}
#endif
@@ -90,6 +94,10 @@ main(int argc, char **argv)
"nodeinfo-6",
};
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
+ return EXIT_FAILURE;
+
progname = argv[0];
if (argc > 1) {
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index a91cd03..052f3f3 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -9,6 +9,7 @@
#include "internal.h"
static char *progname;
+static char *abs_top_srcdir;
struct qemud_driver driver;
#define MAX_FILE 4096
@@ -93,8 +94,10 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *cmd)
{
static int testCompareXMLToArgvHelper(const void *data) {
char xml[PATH_MAX];
char args[PATH_MAX];
- snprintf(xml, PATH_MAX, "qemuxml2argvdata/qemuxml2argv-%s.xml", (const
char*)data);
- snprintf(args, PATH_MAX, "qemuxml2argvdata/qemuxml2argv-%s.args", (const
char*)data);
+ snprintf(xml, PATH_MAX, "%s/tests/qemuxml2argvdata/qemuxml2argv-%s.xml",
+ abs_top_srcdir, (const char*)data);
+ snprintf(args, PATH_MAX, "%s/tests/qemuxml2argvdata/qemuxml2argv-%s.args",
+ abs_top_srcdir, (const char*)data);
return testCompareXMLToArgvFiles(xml, args);
}
@@ -112,6 +115,10 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
+ return 1;
+
if (virtTestRun("QEMU XML-2-ARGV minimal",
1, testCompareXMLToArgvHelper, "minimal") < 0)
ret = -1;
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 59eaf8a..11d8239 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -9,6 +9,7 @@
#include "internal.h"
static char *progname;
+static char *abs_top_srcdir;
struct qemud_driver driver;
#define MAX_FILE 4096
@@ -59,7 +60,8 @@ static int testCompareXMLToXMLFiles(const char *xml) {
static int testCompareXMLToXMLHelper(const void *data) {
char xml[PATH_MAX];
- snprintf(xml, PATH_MAX, "qemuxml2argvdata/qemuxml2argv-%s.xml", (const
char*)data);
+ snprintf(xml, PATH_MAX, "%s/tests/qemuxml2argvdata/qemuxml2argv-%s.xml",
+ abs_top_srcdir, (const char*)data);
return testCompareXMLToXMLFiles(xml);
}
@@ -76,6 +78,10 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
+ return 1;
+
if (virtTestRun("QEMU XML-2-ARGV minimal",
1, testCompareXMLToXMLHelper, "minimal") < 0)
ret = -1;
diff --git a/tests/sexpr2xmltest.c b/tests/sexpr2xmltest.c
index eda1397..563941b 100644
--- a/tests/sexpr2xmltest.c
+++ b/tests/sexpr2xmltest.c
@@ -8,16 +8,23 @@
#include "internal.h"
static char *progname;
+static char *abs_top_srcdir;
#define MAX_FILE 4096
-static int testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) {
+static int testCompareFiles(const char *xml_rel, const char *sexpr_rel,
+ int xendConfigVersion) {
char xmlData[MAX_FILE];
char sexprData[MAX_FILE];
char *gotxml = NULL;
char *xmlPtr = &(xmlData[0]);
char *sexprPtr = &(sexprData[0]);
int ret = -1;
+ char xml[PATH_MAX];
+ char sexpr[PATH_MAX];
+
+ snprintf(xml, sizeof xml - 1, "%s/tests/%s", abs_top_srcdir, xml_rel);
+ snprintf(sexpr, sizeof sexpr - 1, "%s/tests/%s", abs_top_srcdir, sexpr_rel);
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
goto fail;
@@ -175,6 +182,10 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
+ return 1;
+
if (virtTestRun("SEXPR-2-XML PV config (version 1)",
1, testComparePVversion1, NULL) != 0)
ret = -1;
diff --git a/tests/test_conf.sh b/tests/test_conf.sh
index b5a6366..7735a66 100755
--- a/tests/test_conf.sh
+++ b/tests/test_conf.sh
@@ -1,9 +1,10 @@
#!/bin/bash
+set -x
NOK=0
-for f in confdata/*.conf
+for f in $abs_top_srcdir/tests/confdata/*.conf
do
./conftest $f > conftest.$$
- outfile=`echo $f | sed s+\.conf+\.out+`
+ outfile=`echo "$f" | sed s+\.conf$+\.out+`
diff $outfile conftest.$$ > /dev/null
if [ $? != 0 ]
then
diff --git a/tests/virshtest.c b/tests/virshtest.c
index dc33c27..e26ef5c 100644
--- a/tests/virshtest.c
+++ b/tests/virshtest.c
@@ -9,6 +9,7 @@
#include "internal.h"
static char *progname;
+static char *abs_top_srcdir;
#define MAX_FILE 4096
static int testFilterLine(char *buffer,
@@ -27,11 +28,15 @@ static int testFilterLine(char *buffer,
return 0;
}
-static int testCompareOutput(const char *expect, const char *filter, const char *const
argv[]) {
+static int testCompareOutput(const char *expect_rel, const char *filter,
+ const char *const argv[]) {
char expectData[MAX_FILE];
char actualData[MAX_FILE];
char *expectPtr = &(expectData[0]);
char *actualPtr = &(actualData[0]);
+ char expect[PATH_MAX];
+
+ snprintf(expect, sizeof expect - 1, "%s/tests/%s", abs_top_srcdir,
expect_rel);
if (virtTestLoadFile(expect, &expectPtr, MAX_FILE) < 0)
return -1;
@@ -268,13 +273,13 @@ int
main(int argc, char **argv)
{
int ret = 0;
- char cwd[PATH_MAX];
char buffer[PATH_MAX];
- if (!getcwd(cwd, PATH_MAX-1))
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
return 1;
- snprintf(buffer, PATH_MAX-1, "test://%s/../docs/testnode.xml", cwd);
+ snprintf(buffer, PATH_MAX-1, "test://%s/docs/testnode.xml",
abs_top_srcdir);
buffer[PATH_MAX-1] = '\0';
progname = argv[0];
custom_uri = buffer;
diff --git a/tests/xencapstest.c b/tests/xencapstest.c
index 418bb7d..5744262 100644
--- a/tests/xencapstest.c
+++ b/tests/xencapstest.c
@@ -13,13 +13,14 @@
#include "xen_internal.h"
static char *progname;
+static char *abs_top_srcdir;
#define MAX_FILE 4096
static int testCompareFiles(const char *hostmachine,
- const char *xml,
- const char *cpuinfo,
- const char *capabilities) {
+ const char *xml_rel,
+ const char *cpuinfo_rel,
+ const char *capabilities_rel) {
char xmlData[MAX_FILE];
char *expectxml = &(xmlData[0]);
char *actualxml = NULL;
@@ -27,6 +28,17 @@ static int testCompareFiles(const char *hostmachine,
int ret = -1;
+ char xml[PATH_MAX];
+ char cpuinfo[PATH_MAX];
+ char capabilities[PATH_MAX];
+
+ snprintf(xml, sizeof xml - 1, "%s/tests/%s",
+ abs_top_srcdir, xml_rel);
+ snprintf(cpuinfo, sizeof cpuinfo - 1, "%s/tests/%s",
+ abs_top_srcdir, cpuinfo_rel);
+ snprintf(capabilities, sizeof capabilities - 1, "%s/tests/%s",
+ abs_top_srcdir, capabilities_rel);
+
if (virtTestLoadFile(xml, &expectxml, MAX_FILE) < 0)
goto fail;
@@ -152,6 +164,10 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
+ return 1;
+
virInitialize();
if (virtTestRun("Capabilities for i686, no PAE, no HVM",
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index 524ef52..10024b9 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -32,10 +32,12 @@
#include "conf.h"
static char *progname;
+static char *abs_top_srcdir;
#define MAX_FILE 4096
-static int testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
{
+static int testCompareParseXML(const char *xmcfg_rel, const char *xml_rel,
+ int xendConfigVersion) {
char xmlData[MAX_FILE];
char xmcfgData[MAX_FILE];
char gotxmcfgData[MAX_FILE];
@@ -48,6 +50,11 @@ static int testCompareParseXML(const char *xmcfg, const char *xml, int
xendConfi
int wrote = MAX_FILE;
void *old_priv;
struct _xenUnifiedPrivate priv;
+ char xmcfg[PATH_MAX];
+ char xml[PATH_MAX];
+
+ snprintf(xmcfg, sizeof xmcfg - 1, "%s/tests/%s", abs_top_srcdir,
xmcfg_rel);
+ snprintf(xml, sizeof xml - 1, "%s/tests/%s", abs_top_srcdir, xml_rel);
conn = virConnectOpenReadOnly("test:///default");
if (!conn) goto fail;
@@ -92,7 +99,8 @@ static int testCompareParseXML(const char *xmcfg, const char *xml, int
xendConfi
return ret;
}
-static int testCompareFormatXML(const char *xmcfg, const char *xml, int
xendConfigVersion) {
+static int testCompareFormatXML(const char *xmcfg_rel, const char *xml_rel,
+ int xendConfigVersion) {
char xmlData[MAX_FILE];
char xmcfgData[MAX_FILE];
char *xmlPtr = &(xmlData[0]);
@@ -103,6 +111,11 @@ static int testCompareFormatXML(const char *xmcfg, const char *xml,
int xendConf
virConnectPtr conn;
void *old_priv;
struct _xenUnifiedPrivate priv;
+ char xmcfg[PATH_MAX];
+ char xml[PATH_MAX];
+
+ snprintf(xmcfg, sizeof xmcfg - 1, "%s/tests/%s", abs_top_srcdir,
xmcfg_rel);
+ snprintf(xml, sizeof xml - 1, "%s/tests/%s", abs_top_srcdir, xml_rel);
conn = virConnectOpenReadOnly("test:///default");
if (!conn) goto fail;
@@ -259,6 +272,10 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
+ return 1;
+
/* Config -> XML */
if (virtTestRun("Paravirt old PVFB (Format)",
1, testCompareParavirtOldPVFBFormat, NULL) != 0)
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index 2fcc6b3..4b356d4 100644
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -9,10 +9,12 @@
#include "internal.h"
static char *progname;
+static char *abs_top_srcdir;
#define MAX_FILE 4096
-static int testCompareFiles(const char *xml, const char *sexpr, const char *name, int
xendConfigVersion) {
+static int testCompareFiles(const char *xml_rel, const char *sexpr_rel,
+ const char *name, int xendConfigVersion) {
char xmlData[MAX_FILE];
char sexprData[MAX_FILE];
char *gotname = NULL;
@@ -20,6 +22,11 @@ static int testCompareFiles(const char *xml, const char *sexpr, const
char *name
char *xmlPtr = &(xmlData[0]);
char *sexprPtr = &(sexprData[0]);
int ret = -1;
+ char xml[PATH_MAX];
+ char sexpr[PATH_MAX];
+
+ snprintf(xml, sizeof xml - 1, "%s/tests/%s", abs_top_srcdir, xml_rel);
+ snprintf(sexpr, sizeof sexpr - 1, "%s/tests/%s", abs_top_srcdir, sexpr_rel);
if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0)
goto fail;
@@ -225,6 +232,10 @@ main(int argc, char **argv)
progname = argv[0];
+ abs_top_srcdir = getenv("abs_top_srcdir");
+ if (!abs_top_srcdir)
+ return 1;
+
if (argc > 1) {
fprintf(stderr, "Usage: %s\n", progname);
exit(EXIT_FAILURE);
--
1.5.3.5.643.g40e25