]> rtime.felk.cvut.cz Git - sojka/lightdm.git/commitdiff
Run each test in its own /tmp dir so they can't interfere with eachother
authorRobert Ancell <robert.ancell@canonical.com>
Mon, 11 Feb 2013 22:39:44 +0000 (11:39 +1300)
committerRobert Ancell <robert.ancell@canonical.com>
Mon, 11 Feb 2013 22:39:44 +0000 (11:39 +1300)
tests/src/libsystem.c
tests/src/test-runner.c

index 287835a79a0812e67e45b1da61dbcd7e9b25173e..5c20ddcea242abc8bdd60ac8ab0e2a751970155f 100644 (file)
@@ -2,6 +2,7 @@
 #include <string.h>
 #include <errno.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <pwd.h>
 #include <grp.h>
 #include <security/pam_appl.h>
@@ -142,13 +143,29 @@ setresuid (uid_t ruid, uid_t uuid, uid_t suid)
     return 0;
 }
 
+static gchar *
+redirect_path (const gchar *path)
+{ 
+    if (g_str_has_prefix (path, g_getenv ("LIGHTDM_TEST_ROOT")))
+        return g_strdup (path);
+    else if (strcmp (path, CONFIG_DIR "/lightdm.conf") == 0)
+        return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "lightdm", "lightdm.conf", NULL);
+    else if (g_str_has_prefix (path, "/tmp/"))
+        return g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "tmp", path + 5, NULL);
+    else
+        return g_strdup (path);
+}
+
 #ifdef __linux__
 static int
 open_wrapper (const char *func, const char *pathname, int flags, mode_t mode)
 {
-    int (*_open) (const char * pathname, int flags, mode_t mode);
+    int (*_open) (const char *pathname, int flags, mode_t mode);
+    gchar *new_path = NULL;
+    int fd;
+
+    _open = (int (*)(const char *pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, func);
 
-    _open = (int (*)(const char * pathname, int flags, mode_t mode)) dlsym (RTLD_NEXT, func);
     if (strcmp (pathname, "/dev/console") == 0)
     {
         if (console_fd < 0)
@@ -158,19 +175,12 @@ open_wrapper (const char *func, const char *pathname, int flags, mode_t mode)
         }
         return console_fd;
     }
-    else if (strcmp (pathname, CONFIG_DIR "/lightdm.conf") == 0)
-    {
-        gchar *path;
-        int fd;
 
-        path = g_build_filename (g_getenv ("LIGHTDM_TEST_ROOT"), "etc", "lightdm", "lightdm.conf", NULL);
-        fd = _open (path, flags, mode);
-        g_free (path);
+    new_path = redirect_path (pathname);
+    fd = _open (new_path, flags, mode);
+    g_free (new_path);
 
-        return fd;
-    }
-    else
-        return _open (pathname, flags, mode);
+    return fd;
 }
 
 int
index 961d2352637ce61bdaf8aa0de0d76c8045bc3e69..40e9a9378e8cd9b90ef8552be6f5f9f64d1343ed 100644 (file)
@@ -1291,6 +1291,7 @@ main (int argc, char **argv)
     /* Set up a skeleton file system */
     g_mkdir_with_parents (g_strdup_printf ("%s/etc", temp_dir), 0755);
     g_mkdir_with_parents (g_strdup_printf ("%s/usr/share", temp_dir), 0755);
+    g_mkdir_with_parents (g_strdup_printf ("%s/usr/tmp", temp_dir), 0755);
 
     /* Copy over the configuration */
     g_mkdir_with_parents (g_strdup_printf ("%s/etc/lightdm", temp_dir), 0755);