]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: Fix SCSI test data filenames for Windows
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sat, 29 Mar 2014 10:58:32 +0000 (11:58 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Sat, 29 Mar 2014 20:14:15 +0000 (21:14 +0100)
Windows doesn't allow : in filenames.

Commit 6fdece9a332fc668a89bde96af94e7b7cbf6750d added files with a : in
their names. This broke git operations on Windows as git is not able to
create those files on clone or pull.

Replace : with - in the offending filenames and adapt the test case.
As the tested Linux specific code expects the files to exist with : in
their path use symlinks to provide the name that way.

tests/virscsidata/0-0-0-0/block/sda/dev [moved from tests/virscsidata/0:0:0:0/block/sda/dev with 100% similarity]
tests/virscsidata/0-0-0-0/model [moved from tests/virscsidata/0:0:0:0/model with 100% similarity]
tests/virscsidata/0-0-0-0/scsi_generic/sg0/dev [moved from tests/virscsidata/0:0:0:0/scsi_generic/sg0/dev with 100% similarity]
tests/virscsidata/0-0-0-0/vendor [moved from tests/virscsidata/0:0:0:0/vendor with 100% similarity]
tests/virscsidata/1-0-0-0/block/sdh/dev [moved from tests/virscsidata/1:0:0:0/block/sdh/dev with 100% similarity]
tests/virscsidata/1-0-0-0/model [moved from tests/virscsidata/1:0:0:0/model with 100% similarity]
tests/virscsidata/1-0-0-0/scsi_generic/sg8/dev [moved from tests/virscsidata/1:0:0:0/scsi_generic/sg8/dev with 100% similarity]
tests/virscsidata/1-0-0-0/vendor [moved from tests/virscsidata/1:0:0:0/vendor with 100% similarity]
tests/virscsitest.c

index b917e47aa7d7e50c949896effe3c0cb6b82af238..b4ed5e9b08684707f571f14c7f01c0be25c3e765 100644 (file)
 
 #include "virscsi.h"
 #include "testutils.h"
+#include "virlog.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
 #define VIR_SCSI_DATA "/virscsidata"
 
+VIR_LOG_INIT("tests.scsitest");
+
 static const char *abs_top_srcdir;
 static char *virscsi_prefix = NULL;
 
@@ -161,10 +164,39 @@ test2(const void *data ATTRIBUTE_UNUSED)
     return ret;
 }
 
+static int
+create_symlink(const char *tmpdir, const char *src_name, const char *dst_name)
+{
+    int ret = -1;
+    char *src_path = NULL;
+    char *dst_path = NULL;
+
+    if (virAsprintf(&src_path, "%s/%s", virscsi_prefix, src_name) < 0)
+        goto cleanup;
+
+    if (virAsprintf(&dst_path, "%s/%s", tmpdir, dst_name) < 0)
+        goto cleanup;
+
+    if (symlink(src_path, dst_path) < 0) {
+        VIR_WARN("Failed to create symlink '%s' to '%s'", src_path, dst_path);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(src_path);
+    VIR_FREE(dst_path);
+
+    return ret;
+}
+
 static int
 mymain(void)
 {
     int ret = 0;
+    char *tmpdir = NULL;
+    char template[] = "/tmp/libvirt_XXXXXX";
 
     abs_top_srcdir = getenv("abs_top_srcdir");
     if (!abs_top_srcdir)
@@ -175,12 +207,42 @@ mymain(void)
         goto cleanup;
     }
 
+    tmpdir = mkdtemp(template);
+
+    if (tmpdir == NULL) {
+        VIR_WARN("Failed to create temporary directory");
+        ret = -1;
+        goto cleanup;
+    }
+
+#define CREATE_SYMLINK(src_name, dst_name)                    \
+    do {                                                      \
+        if (create_symlink(tmpdir, src_name, dst_name) < 0) { \
+            ret = -1;                                         \
+            goto cleanup;                                     \
+        }                                                     \
+    } while (0)
+
+    CREATE_SYMLINK("0-0-0-0", "0:0:0:0");
+    CREATE_SYMLINK("1-0-0-0", "1:0:0:0");
+    CREATE_SYMLINK("sg0", "sg0");
+    CREATE_SYMLINK("sg8", "sg8");
+
+    VIR_FREE(virscsi_prefix);
+
+    if (VIR_STRDUP(virscsi_prefix, tmpdir) < 0) {
+        ret = -1;
+        goto cleanup;
+    }
+
     if (virtTestRun("test1", test1, NULL) < 0)
         ret = -1;
     if (virtTestRun("test2", test2, NULL) < 0)
         ret = -1;
 
  cleanup:
+    if (tmpdir && getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+        virFileDeleteTree(tmpdir);
     VIR_FREE(virscsi_prefix);
     return ret;
 }