While trying to debug a failure of virpcitest during 'make distcheck',
I noticed that with a VPATH build, 'cd tests; ./virpcitest' fails for
an entirely different reason. To reproduce the distcheck failure, I
had to run 'cd tests; abs_srcdir=/path/to/src ./virpcitest'. But we
document in HACKING that all of our tests are supposed to be runnable
without requiring extra environment variables.
The solution: hardcode the location of srcdir into the just-built
binaries, rather than requiring make to prepopulate environment
variables. With this, './virpcitest' passes even in a VPATH build
(provided that $(srcdir) is writable; a followup patch will fix the
conditions required by 'make distcheck').
* tests/Makefile.am (AM_CFLAGS): Define abs_srcdir in all compiled
tests.
* tests/testutils.h (abs_srcdir): Quit declaring.
* tests/testutils.c (virtTestMain): Rely on define rather than
environment variable.
* tests/virpcimock.c (pci_device_new_from_stub): Rely on define.
* tests/cputest.c (mymain): Adjust abs_top_srcdir default.
* tests/qemuxml2argvtest.c (mymain): Likewise.
* tests/qemuxmlnstest.c (mymain): Likewise.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
Pushing under the build-breaker rule.
tests/Makefile.am | 1 +
tests/cputest.c | 2 +-
tests/qemuxml2argvtest.c | 2 +-
tests/qemuxmlnstest.c | 2 +-
tests/testutils.c | 11 +----------
tests/testutils.h | 6 +++++-
tests/virpcimock.c | 12 ++++--------
7 files changed, 14 insertions(+), 22 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e46d5f7..520fd2a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -29,6 +29,7 @@ INCLUDES = \
AM_CFLAGS = \
-Dabs_builddir="\"`pwd`\"" \
+ -Dabs_srcdir="\"`cd '$(srcdir)'; pwd`\"" \
$(LIBXML_CFLAGS) \
$(GNUTLS_CFLAGS) \
$(SASL_CFLAGS) \
diff --git a/tests/cputest.c b/tests/cputest.c
index b80fac7..20bc544 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -503,7 +503,7 @@ mymain(void)
abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir)
- abs_top_srcdir = "..";
+ abs_top_srcdir = abs_srcdir "/..";
if (virAsprintf(&map, "%s/src/cpu/cpu_map.xml", abs_top_srcdir) < 0
||
cpuMapOverride(map) < 0) {
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index a290062..dad5973 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -297,7 +297,7 @@ mymain(void)
abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir)
- abs_top_srcdir = "..";
+ abs_top_srcdir = abs_srcdir "/..";
driver.config = virQEMUDriverConfigNew(false);
VIR_FREE(driver.config->spiceListen);
diff --git a/tests/qemuxmlnstest.c b/tests/qemuxmlnstest.c
index 2cc15d1..2093e1e 100644
--- a/tests/qemuxmlnstest.c
+++ b/tests/qemuxmlnstest.c
@@ -203,7 +203,7 @@ mymain(void)
abs_top_srcdir = getenv("abs_top_srcdir");
if (!abs_top_srcdir)
- abs_top_srcdir = "..";
+ abs_top_srcdir = abs_srcdir "/..";
driver.config = virQEMUDriverConfigNew(false);
if ((driver.caps = testQemuCapsInit()) == NULL)
diff --git a/tests/testutils.c b/tests/testutils.c
index 5d634b4..32fe374 100644
--- a/tests/testutils.c
+++ b/tests/testutils.c
@@ -69,7 +69,6 @@ static size_t testStart = 0;
static size_t testEnd = 0;
char *progname;
-char *abs_srcdir;
void virtTestResult(const char *name, int ret, const char *msg, ...)
{
@@ -535,15 +534,9 @@ int virtTestMain(int argc,
int (*func)(void))
{
int ret;
- bool abs_srcdir_cleanup = false;
char *testRange = NULL;
- abs_srcdir = getenv("abs_srcdir");
- if (!abs_srcdir) {
- abs_srcdir = getcwd(NULL, 0);
- abs_srcdir_cleanup = true;
- }
- if (!abs_srcdir)
+ if (!virFileExists(abs_srcdir))
return EXIT_AM_HARDFAIL;
progname = last_component(argv[0]);
@@ -599,8 +592,6 @@ int virtTestMain(int argc,
ret = (func)();
- if (abs_srcdir_cleanup)
- VIR_FREE(abs_srcdir);
virResetLastError();
if (!virTestGetVerbose() && ret != EXIT_AM_SKIP) {
if (testCounter == 0 || testCounter % 40)
diff --git a/tests/testutils.h b/tests/testutils.h
index 478b53c..674d3df 100644
--- a/tests/testutils.h
+++ b/tests/testutils.h
@@ -38,7 +38,11 @@
# endif
extern char *progname;
-extern char *abs_srcdir;
+
+/* Makefile.am provides these two definitions */
+# if !defined(abs_srcdir) || !defined(abs_builddir)
+# error Fix Makefile.am
+# endif
void virtTestResult(const char *name, int ret, const char *msg, ...)
ATTRIBUTE_FMT_PRINTF(3,4);
diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index 19062c3..48d5f16 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -305,14 +305,10 @@ pci_device_new_from_stub(const struct pciDevice *data)
char *configSrc, *configDst;
char tmp[32];
struct stat sb;
- char *abs_srcdir;
-
- abs_srcdir = getenv("abs_srcdir");
- if (!abs_srcdir)
- abs_srcdir = getcwd(NULL, 0);
if (VIR_ALLOC_QUIET(dev) < 0 ||
- virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config",
abs_srcdir, data->id) < 0 ||
+ virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config",
+ abs_srcdir, data->id) < 0 ||
virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfsdir,
data->id) < 0)
ABORT_OOM();
@@ -480,7 +476,7 @@ pci_driver_bind(struct pciDriver *driver,
char *devpath = NULL, *driverpath = NULL;
if (dev->driver) {
- /* Device already binded */
+ /* Device already bound */
errno = ENODEV;
return ret;
}
@@ -527,7 +523,7 @@ pci_driver_unbind(struct pciDriver *driver,
char *devpath = NULL, *driverpath = NULL;
if (dev->driver != driver) {
- /* Device not binded to the @driver */
+ /* Device not bound to the @driver */
errno = ENODEV;
return ret;
}
--
1.8.3.1