mirror of https://gitee.com/openkylin/libvirt.git
tests: guarantee abs_srcdir in all C tests
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'). [Note: the makefile must still pass on directory variables to the test environment of shell scripts, since those aren't compiled. So while this solves the case of a compiled test, it still requires environment variables to pass a VPATH build of any shell script test case that relies on srcdir.] * 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@redhat.com>
This commit is contained in:
parent
69d20452ce
commit
0aa873d741
|
@ -29,6 +29,7 @@ INCLUDES = \
|
|||
|
||||
AM_CFLAGS = \
|
||||
-Dabs_builddir="\"`pwd`\"" \
|
||||
-Dabs_srcdir="\"`cd '$(srcdir)'; pwd`\"" \
|
||||
$(LIBXML_CFLAGS) \
|
||||
$(GNUTLS_CFLAGS) \
|
||||
$(SASL_CFLAGS) \
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue