]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Move fakerootdir handling to common logic
authorAndrea Bolognani <abologna@redhat.com>
Wed, 1 Mar 2023 10:06:14 +0000 (11:06 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Fri, 3 Mar 2023 12:52:37 +0000 (13:52 +0100)
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>
tests/qemuhotplugtest.c
tests/qemumemlocktest.c
tests/qemustatusxml2xmltest.c
tests/qemuxml2argvtest.c
tests/qemuxml2xmltest.c
tests/scsihosttest.c
tests/testutils.c
tests/virhostdevtest.c
tests/virpcitest.c

index 429928aa7f2b87fffd697d3ef4ef4bea6b34e337..2e8ac05e5ef4b44a764b0781d0c996069537775a 100644 (file)
@@ -664,13 +664,8 @@ mymain(void)
     int ret = 0;
     struct qemuHotplugTestData data = {0};
     struct testQemuHotplugCpuParams cpudata;
-    g_autofree char *fakerootdir = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
 
-    if (!(fakerootdir = virTestFakeRootDirInit())) {
-        return EXIT_FAILURE;
-    }
-
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
@@ -997,8 +992,6 @@ mymain(void)
     DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-22", true, true, true);
     DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", true, true, true);
 
-    virTestFakeRootDirCleanup(fakerootdir);
-
     qemuTestDriverFree(&driver);
     virObjectUnref(data.vm);
     return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
index 184d8ede19cd11793dc0ddab2c65a8160fee79df..a03ed20a456d29cba1b55fbe46797bca91b66aca 100644 (file)
@@ -46,12 +46,8 @@ static int
 mymain(void)
 {
     int ret = 0;
-    g_autofree char *fakerootdir = NULL;
     g_autoptr(virQEMUCaps) qemuCaps = NULL;
 
-    if (!(fakerootdir = virTestFakeRootDirInit()))
-        return EXIT_FAILURE;
-
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
@@ -129,8 +125,6 @@ mymain(void)
     DO_TEST("pseries-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
 
  cleanup:
-    virTestFakeRootDirCleanup(fakerootdir);
-
     qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
index a29aa723e63bd98c0196c2b975b3bf57ceca7f4e..7587c4c34ff632868b1a88f459b8cc937b44f78f 100644 (file)
@@ -74,7 +74,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    g_autofree char *fakerootdir = NULL;
     g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
     g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
     g_autoptr(virConnect) conn = NULL;
@@ -85,9 +84,6 @@ mymain(void)
     if (!capslatest)
         return EXIT_FAILURE;
 
-    if (!(fakerootdir = virTestFakeRootDirInit()))
-        return EXIT_FAILURE;
-
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
@@ -134,8 +130,6 @@ mymain(void)
     DO_TEST_STATUS("backup-pull");
 
  cleanup:
-    virTestFakeRootDirCleanup(fakerootdir);
-
     qemuTestDriverFree(&driver);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
index 3f5eda533edd30f242faaa747416d1d35be20a15..f46fc29f32e9cd01cc6bac46951c3f18d53e7c96 100644 (file)
@@ -800,7 +800,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    g_autofree char *fakerootdir = NULL;
     g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
     g_autoptr(GHashTable) qapiSchemaCache = virHashNew((GDestroyNotify) g_hash_table_unref);
     g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
@@ -811,9 +810,6 @@ mymain(void)
     if (!capslatest)
         return EXIT_FAILURE;
 
-    if (!(fakerootdir = virTestFakeRootDirInit()))
-        return EXIT_FAILURE;
-
     /* Set the timezone because we are mocking the time() function.
      * If we don't do that, then localtime() may return unpredictable
      * results. In order to detect things that just work by a blind
@@ -2987,8 +2983,6 @@ mymain(void)
 
     DO_TEST_CAPS_LATEST("crypto-builtin");
 
-    virTestFakeRootDirCleanup(fakerootdir);
-
     VIR_FREE(driver.config->nbdTLSx509certdir);
     qemuTestDriverFree(&driver);
     virFileWrapperClearPrefixes();
index 2b6006fcc73a3e8c164c679649c5a033e9ab32b3..69bff80376a1b317c22eef7b17b7aed268681199 100644 (file)
@@ -117,7 +117,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    g_autofree char *fakerootdir = NULL;
     g_autoptr(virQEMUDriverConfig) cfg = NULL;
     g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
     g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
@@ -129,9 +128,6 @@ mymain(void)
     if (!capslatest)
         return EXIT_FAILURE;
 
-    if (!(fakerootdir = virTestFakeRootDirInit()))
-        return EXIT_FAILURE;
-
     /* Required for tpm-emulator tests
      */
     virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware",
@@ -1325,8 +1321,6 @@ mymain(void)
     DO_TEST_CAPS_LATEST("crypto-builtin");
 
  cleanup:
-    virTestFakeRootDirCleanup(fakerootdir);
-
     qemuTestDriverFree(&driver);
     virFileWrapperClearPrefixes();
 
index 37d2b86c0af91ac23268ee042e004fa0848e0479..7f2dcb68a202a8a501ffa3d53910907c4a495c80 100644 (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;
 }
index fe7677ebfb128dcd18b7dee8a4b3a475f05cfaea..e717895fbf12fa6c558f8dbb2abbb0affe6bc750 100644 (file)
@@ -808,6 +808,7 @@ int virTestMain(int argc,
     g_autofree const char **preloads = NULL;
     size_t npreloads = 0;
     g_autofree char *mock = NULL;
+    g_autofree char *fakerootdir = NULL;
 
     if (getenv("VIR_TEST_FILE_ACCESS")) {
         preloads = g_renew(const char *, preloads, npreloads + 2);
@@ -888,6 +889,9 @@ int virTestMain(int argc,
 
     failedTests = virBitmapNew(1);
 
+    if (!(fakerootdir = virTestFakeRootDirInit()))
+        return EXIT_FAILURE;
+
     ret = (func)();
 
     virResetLastError();
@@ -897,6 +901,8 @@ int virTestMain(int argc,
         fprintf(stderr, " %-3zu %s\n", testCounter, ret == 0 ? "OK" : "FAIL");
     }
 
+    virTestFakeRootDirCleanup(fakerootdir);
+
     switch (ret) {
     case EXIT_FAILURE:
     case EXIT_SUCCESS:
index c64940458fec4a280fa247ae4e7efa10ae0175ce..ee0d1c1e6b8b908eb7985962923bbb6d298e9b53 100644 (file)
@@ -588,10 +588,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    g_autofree char *fakerootdir = NULL;
-
-    if (!(fakerootdir = virTestFakeRootDirInit()))
-        return EXIT_FAILURE;
 
 # define DO_TEST(fnc) \
     do { \
@@ -601,7 +597,6 @@ mymain(void)
 
     if (myInit() < 0) {
         fprintf(stderr, "Init data structures failed.");
-        virTestFakeRootDirCleanup(fakerootdir);
         return EXIT_FAILURE;
     }
 
@@ -614,8 +609,6 @@ mymain(void)
 
     myCleanup();
 
-    virTestFakeRootDirCleanup(fakerootdir);
-
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
index 5ddf4de0bdec7849c20f1ac59b48f8db30a5da18..769175d7c46f78d39db44f6537edd14b6dddfbaf 100644 (file)
@@ -367,10 +367,6 @@ static int
 mymain(void)
 {
     int ret = 0;
-    g_autofree char *fakerootdir = NULL;
-
-    if (!(fakerootdir = virTestFakeRootDirInit()))
-        return EXIT_FAILURE;
 
 # define DO_TEST(fnc) \
     do { \
@@ -438,8 +434,6 @@ mymain(void)
 
     DO_TEST_PCI(testVirPCIDeviceGetVPD, 0, 0x03, 0, 0);
 
-    virTestFakeRootDirCleanup(fakerootdir);
-
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }