tests: Move fakerootdir handling to common logic

Instead of having each test manually initialize and cleanup
its own fakerootdir, do that as part of the common test
initialization logic in virTestMain().

In most cases we can simply drop the relevant code from the
test program, but scsihosttest uses the value of fakerootdir
as a starting point to build another path, so we need to do
things slightly differently. In order to keep things working,
we retrieve the value from the LIBVIRT_FAKE_ROOT_DIR
environment variable, same as all the mock libraries are
already doing.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Andrea Bolognani
2023-03-01 11:06:14 +01:00
parent 457a0183d6
commit 87b30e6965
9 changed files with 8 additions and 47 deletions

View File

@@ -231,10 +231,10 @@ static int
mymain(void)
{
int ret = -1;
g_autofree char *fakerootdir = NULL;
const char *fakerootdir = NULL;
g_autofree char *fakesysfsdir = NULL;
if (!(fakerootdir = virTestFakeRootDirInit()))
if (!(fakerootdir = g_getenv("LIBVIRT_FAKE_ROOT_DIR")))
return EXIT_FAILURE;
fakesysfsdir = g_strdup_printf("%s/sys", fakerootdir);
@@ -262,7 +262,6 @@ mymain(void)
ret = 0;
cleanup:
virTestFakeRootDirCleanup(fakerootdir);
VIR_FREE(scsihost_class_path);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}