]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
tests: pcimock: Use the temporary directory as fake root
authorAndrea Bolognani <abologna@redhat.com>
Fri, 4 Dec 2015 09:05:56 +0000 (10:05 +0100)
committerAndrea Bolognani <abologna@redhat.com>
Wed, 9 Dec 2015 14:22:58 +0000 (15:22 +0100)
We might need to mock files living outside PCI_SYSFS_PREFIX later on,
so it's better to treat the temporary directory we are passed via
the environment as the root of the fake filesystem and create
PCI_SYSFS_PREFIX inside it.

The environment variable name will be changed to reflect the new use
we're making of it in a later commit.

tests/virpcimock.c

index 6d00a4fd651c8d1d809a8232c4c5f0db0c081a96..f1517ce73b9a90abb3c101027048335128a7da8f 100644 (file)
@@ -49,6 +49,7 @@ static DIR * (*realopendir)(const char *name);
  * when passed as an arg to virAsprintf()
  * vircgroupmock.c:462:22: error: static variable 'fakesysfsdir' is used in an inline function with external linkage [-Werror,-Wstatic-in-inline]
  */
+char *fakerootdir;
 char *fakesysfsdir;
 
 # define PCI_SYSFS_PREFIX "/sys/bus/pci/"
@@ -800,12 +801,19 @@ init_syms(void)
 static void
 init_env(void)
 {
-    if (fakesysfsdir)
+    if (fakerootdir && fakesysfsdir)
         return;
 
-    if (!(fakesysfsdir = getenv("LIBVIRT_FAKE_SYSFS_DIR")))
+    if (!(fakerootdir = getenv("LIBVIRT_FAKE_SYSFS_DIR")))
         ABORT("Missing LIBVIRT_FAKE_SYSFS_DIR env variable\n");
 
+    if (virAsprintfQuiet(&fakesysfsdir, "%s%s",
+                         fakerootdir, PCI_SYSFS_PREFIX) < 0)
+        ABORT_OOM();
+
+    if (virFileMakePath(fakesysfsdir) < 0)
+        ABORT("Unable to create: %s", fakesysfsdir);
+
     make_file(fakesysfsdir, "drivers_probe", NULL, -1);
 
 # define MAKE_PCI_DRIVER(name, ...)                                     \