diff options
author | Simon McVittie <smcv@debian.org> | 2019-06-26 09:29:47 +0100 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2019-07-16 09:19:47 +0100 |
commit | 3caaf7a9cf6043bc968a74e795b44176ee09c2a8 (patch) | |
tree | 4947db8866dd0ff920d264d6b1861221e551ccec | |
parent | 268c9117c5ac045e6a3bb1f7b86405fa7b6226ca (diff) |
test-doc-portal: Check for FUSE support more thoroughly
Some CI pipelines do the build as root, which means /dev/fuse is
writable, but if we do not have appropriate permissions then we cannot
actually mount FUSE filesystems.
Signed-off-by: Simon McVittie <smcv@debian.org>
Gbp-Pq: Name test-doc-portal-Check-for-FUSE-support-more-thoroughly.patch
-rw-r--r-- | document-portal/document-portal-fuse.c | 3 | ||||
-rw-r--r-- | tests/Makefile.am.inc | 3 | ||||
-rw-r--r-- | tests/test-doc-portal.c | 101 |
3 files changed, 84 insertions, 23 deletions
diff --git a/document-portal/document-portal-fuse.c b/document-portal/document-portal-fuse.c index 2705402..f1935ec 100644 --- a/document-portal/document-portal-fuse.c +++ b/document-portal/document-portal-fuse.c @@ -2537,7 +2537,8 @@ xdp_fuse_init (GError **error) main_ch = fuse_mount (path, &args); if (main_ch == NULL) { - g_set_error (error, XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_FAILED, "Can't mount fuse fs"); + g_set_error (error, XDG_DESKTOP_PORTAL_ERROR, XDG_DESKTOP_PORTAL_ERROR_FAILED, + "Can't mount fuse fs on %s: %s", path, g_strerror (errno)); return FALSE; } diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index fcc6a76..7418b69 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -13,10 +13,11 @@ testdb_LDADD = \ $(NULL) testdb_SOURCES = tests/testdb.c $(DB_SOURCES) -test_doc_portal_CFLAGS = $(AM_CFLAGS) $(BASE_CFLAGS) +test_doc_portal_CFLAGS = $(AM_CFLAGS) $(BASE_CFLAGS) $(FUSE_CFLAGS) test_doc_portal_LDADD = \ $(AM_LDADD) \ $(BASE_LIBS) \ + $(FUSE_LIBS) \ $(NULL) test_doc_portal_SOURCES = tests/test-doc-portal.c nodist_test_doc_portal_SOURCES = document-portal/document-portal-dbus.c diff --git a/tests/test-doc-portal.c b/tests/test-doc-portal.c index 10b9b5d..fb199d3 100644 --- a/tests/test-doc-portal.c +++ b/tests/test-doc-portal.c @@ -11,6 +11,10 @@ #include <gio/gio.h> #include <gio/gunixfdlist.h> +#include <glib/gstdio.h> + +#define FUSE_USE_VERSION 26 +#include <fuse_lowlevel.h> #include "document-portal/document-portal-dbus.h" @@ -22,7 +26,7 @@ GTestDBus *dbus; GDBusConnection *session_bus; XdpDbusDocuments *documents; char *mountpoint; -static gboolean have_fuse; +static gchar *cannot_use_fuse = NULL; static gboolean set_contents_trunc (const gchar *filename, @@ -352,9 +356,9 @@ test_create_doc (void) const char *basename = "a-file"; GError *error = NULL; - if (!have_fuse) + if (cannot_use_fuse != NULL) { - g_test_skip ("this test requires FUSE"); + g_test_skip (cannot_use_fuse); return; } @@ -467,9 +471,9 @@ test_recursive_doc (void) g_autofree char *path = NULL; g_autofree char *app_path = NULL; - if (!have_fuse) + if (cannot_use_fuse != NULL) { - g_test_skip ("this test requires FUSE"); + g_test_skip (cannot_use_fuse); return; } @@ -509,9 +513,9 @@ test_create_docs (void) const char *basenames[] = { "doc1", "doc2" }; int i; - if (!have_fuse) + if (cannot_use_fuse != NULL) { - g_test_skip ("this test requires FUSE"); + g_test_skip (cannot_use_fuse); return; } @@ -582,9 +586,9 @@ test_add_named (void) GError *error = NULL; gboolean res; - if (!have_fuse) + if (cannot_use_fuse != NULL) { - g_test_skip ("this test requires FUSE"); + g_test_skip (cannot_use_fuse); return; } @@ -696,23 +700,78 @@ test_add_named (void) assert_doc_not_exist (id1, basename1, "com.test.App2"); } +/* + * If we cannot use FUSE, set cannot_use_fuse and return %FALSE. + */ +static gboolean +check_fuse (void) +{ + g_autofree gchar *fusermount = NULL; + g_autofree gchar *path = NULL; + char *argv[] = { "xdp-fuse-test" }; + struct fuse_args args = FUSE_ARGS_INIT (G_N_ELEMENTS (argv), argv); + struct fuse_chan *chan = NULL; + g_autoptr(GError) error = NULL; + + if (cannot_use_fuse != NULL) + return FALSE; + + if (access ("/dev/fuse", W_OK) != 0) + { + cannot_use_fuse = g_strdup_printf ("access /dev/fuse: %s", + g_strerror (errno)); + return FALSE; + } + + fusermount = g_find_program_in_path ("fusermount"); + + if (fusermount == NULL) + { + cannot_use_fuse = g_strdup ("fusermount not found in PATH"); + return FALSE; + } + + if (!g_file_test (fusermount, G_FILE_TEST_IS_EXECUTABLE)) + { + cannot_use_fuse = g_strdup_printf ("%s not executable", fusermount); + return FALSE; + } + + path = g_dir_make_tmp ("xdp-test.XXXXXX", &error); + g_assert_no_error (error); + + chan = fuse_mount (path, &args); + + if (chan == NULL) + { + cannot_use_fuse = g_strdup_printf ("fuse_mount: %s", + g_strerror (errno)); + return FALSE; + } + + g_test_message ("Successfully set up test FUSE fs on %s", path); + + fuse_unmount (path, chan); + + if (g_rmdir (path) != 0) + g_error ("rmdir %s: %s", path, g_strerror (errno)); + + return TRUE; +} + static void global_setup (void) { gboolean inited; - g_autofree gchar *fusermount = NULL; GError *error = NULL; g_autofree gchar *services = NULL; int fd; - fusermount = g_find_program_in_path ("fusermount"); - /* cache result so subsequent tests can be marked as skipped */ - have_fuse = (access ("/dev/fuse", W_OK) == 0 && - fusermount != NULL && - g_file_test (fusermount, G_FILE_TEST_IS_EXECUTABLE)); - - if (!have_fuse) - return; + if (!check_fuse ()) + { + g_assert_cmpstr (cannot_use_fuse, !=, NULL); + return; + } g_mkdtemp (outdir); g_print ("outdir: %s\n", outdir); @@ -805,7 +864,7 @@ global_teardown (void) g_autoptr(GFile) outdir_file = g_file_new_for_path (outdir); int res, i; - if (!have_fuse) + if (cannot_use_fuse != NULL) return; res = stat (by_app_dir, &buf); @@ -858,9 +917,9 @@ global_teardown (void) static void test_version (void) { - if (!have_fuse) + if (cannot_use_fuse != NULL) { - g_test_skip ("this test requires FUSE"); + g_test_skip (cannot_use_fuse); return; } |