mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
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:
1 parent
69d20452ce
commit
0aa873d741
7 files changed
+14
-22
No files matched your search
+1
-10
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user