diff --git a/tests/Makefile.am b/tests/Makefile.am index e46d5f7632..520fd2ac76 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 b80fac7b3c..20bc544c8d 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 a290062dd9..dad597394e 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 2cc15d1500..2093e1e1b2 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 5d634b4024..32fe3745c3 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 478b53cfe4..674d3df98d 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 19062c3705..48d5f163dc 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; }