[glib/wip/hadess/installed-tests: 24/27] tests: Don't run tests that require fuse on rootless containers



commit fc95385627e48ffa877d398fcc90c14f515620ed
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Nov 20 16:54:19 2019 +0100

    tests: Don't run tests that require fuse on rootless containers
    
    If the fuse module is loaded but /dev/fuse doesn't exist, it's likely
    that we're running in a rootless container, or a badly setup one, and we
    won't be able to use fuse, so skip this test.
    
    This happened on my local system using podman running as a normal user,
    but this apparently works as expected in our CI[1].
    
    [1]: https://gitlab.gnome.org/GNOME/glib/merge_requests/466

 gio/tests/g-file-info-filesystem-readonly.c | 30 +++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
---
diff --git a/gio/tests/g-file-info-filesystem-readonly.c b/gio/tests/g-file-info-filesystem-readonly.c
index a715ef8d0..60937b143 100644
--- a/gio/tests/g-file-info-filesystem-readonly.c
+++ b/gio/tests/g-file-info-filesystem-readonly.c
@@ -61,6 +61,24 @@ assert_remove (const gchar *file)
     g_error ("failed to remove %s: %s", file, g_strerror (errno));
 }
 
+static gboolean
+fuse_module_loaded (void)
+{
+  char *contents = NULL;
+  gboolean ret;
+
+  if (!g_file_get_contents ("/proc/modules", &contents, NULL, NULL) ||
+      contents == NULL)
+    {
+      g_free (contents);
+      return FALSE;
+    }
+
+  ret = (strstr (contents, "\nfuse ") != NULL);
+  g_free (contents);
+  return ret;
+}
+
 static void
 test_filesystem_readonly (gconstpointer with_mount_monitor)
 {
@@ -87,6 +105,18 @@ test_filesystem_readonly (gconstpointer with_mount_monitor)
       return;
     }
 
+  /* If the fuse module is loaded but there's no /dev/fuse, then we're
+   * we're probably in a rootless container and won't be able to
+   * use bindfs to run our tests */
+  if (fuse_module_loaded () &&
+      !g_file_test ("/dev/fuse", G_FILE_TEST_EXISTS))
+    {
+      g_test_skip ("fuse support is needed to run this test (rootless container?)");
+      g_free (fusermount);
+      g_free (bindfs);
+      return;
+    }
+
   curdir = g_get_current_dir ();
   dir_to_mount = g_strdup_printf ("%s/dir_bindfs_to_mount", curdir);
   file_in_mount = g_strdup_printf ("%s/example.txt", dir_to_mount);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]