summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorLuis Henriques <luis@igalia.com>2026-10-01 17:49:12 +0100
committerMiklos Szeredi <mszeredi@redhat.com>2026-10-15 14:01:13 +0200
commitc7d054ac8ee905801db370b3fddbf2bd0775ca5d (patch)
treedaf45a0c00d950941014f5c1dd728d8cff1adac7 /tools
parentf8c36bf9a9e5c6910be12905359a4403091978ea (diff)
downloadlinux-c7d054ac8ee905801db370b3fddbf2bd0775ca5d.tar.gz
linux-c7d054ac8ee905801db370b3fddbf2bd0775ca5d.zip
selftests/fuse: factor-out test fixture setup/teardown
In order to reduce new tests setup/teardown code duplication, factor-out these functions from the existing acl_cache test into a new fuse_common.c file that can be reused in other tests. While there, also move some of the FIXTURE members into a fuse_common_ctx structure that can be passed into setup/teardown instead of passing them by reference. Signed-off-by: Luis Henriques <luis@igalia.com> Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/filesystems/fuse/Makefile8
-rw-r--r--tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c70
-rw-r--r--tools/testing/selftests/filesystems/fuse/fuse_common.c58
-rw-r--r--tools/testing/selftests/filesystems/fuse/fuse_common.h33
4 files changed, 110 insertions, 59 deletions
diff --git a/tools/testing/selftests/filesystems/fuse/Makefile b/tools/testing/selftests/filesystems/fuse/Makefile
index fb3b4a13dd77..e08a1a91dbde 100644
--- a/tools/testing/selftests/filesystems/fuse/Makefile
+++ b/tools/testing/selftests/filesystems/fuse/Makefile
@@ -21,8 +21,12 @@ ifeq ($(VAR_LDLIBS),)
VAR_LDLIBS := -lfuse3 -pthread
endif
+CFLAGS += $(VAR_CFLAGS)
+LDLIBS += $(VAR_LDLIBS)
+
$(OUTPUT)/fuse_mnt: CFLAGS += $(VAR_CFLAGS)
$(OUTPUT)/fuse_mnt: LDLIBS += $(VAR_LDLIBS)
-$(OUTPUT)/fuse_acl_cache_test: CFLAGS += $(VAR_CFLAGS)
-$(OUTPUT)/fuse_acl_cache_test: LDLIBS += $(VAR_LDLIBS)
+$(OUTPUT)/fuse_acl_cache_test: fuse_common.c fuse_acl_cache_test.c
+
+EXTRA_CLEAN := fuse_common.o
diff --git a/tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c b/tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c
index 2411a6e285f1..91ad41cc92b6 100644
--- a/tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c
+++ b/tools/testing/selftests/filesystems/fuse/fuse_acl_cache_test.c
@@ -33,23 +33,15 @@
*/
#define _GNU_SOURCE
-#include <errno.h>
#include <fcntl.h>
#include <linux/limits.h>
-#include <pthread.h>
#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
#include <sys/xattr.h>
-#include <unistd.h>
-
-#define FUSE_USE_VERSION 31
-#include <fuse_lowlevel.h>
#include "kselftest_harness.h"
+#include "fuse_common.h"
+
/* ---- ACL binary encoding ------------------------------------------------ */
/*
* POSIX ACL v2 xattr format (little-endian):
@@ -176,69 +168,33 @@ static const struct fuse_lowlevel_ops fs_ops = {
.getxattr = fs_getxattr,
};
-/* ---- Daemon thread ------------------------------------------------------- */
-
-static void *run_daemon(void *arg)
-{
- fuse_session_loop((struct fuse_session *)arg);
- return NULL;
-}
-
/* ---- kselftest harness --------------------------------------------------- */
FIXTURE(acl_cache) {
- struct fuse_session *se;
- char mountpoint[PATH_MAX];
- char file_path[PATH_MAX];
- pthread_t thread;
+ struct fuse_common_ctx ctx;
+ char file_path[PATH_MAX];
};
FIXTURE_SETUP(acl_cache)
{
- char *fuse_argv[] = { "fuse_acl_cache_test", NULL };
- struct fuse_args args = FUSE_ARGS_INIT(1, fuse_argv);
+ char err[MAX_ERR_MSG];
- g_ds.acl = acl_a;
- g_ds.acl_size = sizeof(acl_a);
+ pthread_mutex_lock(&g_ds.lock);
+ g_ds.acl = acl_a;
+ g_ds.acl_size = sizeof(acl_a);
g_ds.getxattr_count = 0;
+ pthread_mutex_unlock(&g_ds.lock);
- strcpy(self->mountpoint, "/tmp/acl_cache_test_XXXXXX");
- if (!mkdtemp(self->mountpoint))
- SKIP(return, "mkdtemp: %s", strerror(errno));
+ if (fs_setup(&fs_ops, &self->ctx, err))
+ SKIP(return, err);
snprintf(self->file_path, sizeof(self->file_path),
- "%s/" FILE_NAME, self->mountpoint);
-
- self->se = fuse_session_new(&args, &fs_ops, sizeof(fs_ops), NULL);
- if (!self->se) {
- rmdir(self->mountpoint);
- SKIP(return, "fuse_session_new failed");
- }
-
- if (fuse_session_mount(self->se, self->mountpoint)) {
- fuse_session_destroy(self->se);
- rmdir(self->mountpoint);
- SKIP(return, "fuse_session_mount failed "
- "(missing fusermount3 or insufficient privileges)");
- }
-
- if (pthread_create(&self->thread, NULL, run_daemon, self->se)) {
- fuse_session_unmount(self->se);
- fuse_session_destroy(self->se);
- rmdir(self->mountpoint);
- SKIP(return, "pthread_create: %s", strerror(errno));
- }
-
- fuse_opt_free_args(&args);
+ "%s/" FILE_NAME, self->ctx.mountpoint);
}
FIXTURE_TEARDOWN(acl_cache)
{
- fuse_session_exit(self->se);
- fuse_session_unmount(self->se);
- pthread_join(self->thread, NULL);
- fuse_session_destroy(self->se);
- rmdir(self->mountpoint);
+ fs_teardown(&self->ctx);
}
static int do_force_statx(const char *path)
diff --git a/tools/testing/selftests/filesystems/fuse/fuse_common.c b/tools/testing/selftests/filesystems/fuse/fuse_common.c
new file mode 100644
index 000000000000..d1d3dfd2ea67
--- /dev/null
+++ b/tools/testing/selftests/filesystems/fuse/fuse_common.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include "fuse_common.h"
+
+static void *run_daemon(void *arg)
+{
+ fuse_session_loop((struct fuse_session *)arg);
+ return NULL;
+}
+
+int fs_setup(const struct fuse_lowlevel_ops *fs_ops,
+ struct fuse_common_ctx *ctx, char *err)
+{
+ char *fuse_argv[] = { "fuse_test", NULL };
+ struct fuse_args args = FUSE_ARGS_INIT(1, fuse_argv);
+
+ strcpy(ctx->mountpoint, MOUNTPOINT_TEMPLATE);
+ if (!mkdtemp(ctx->mountpoint)) {
+ snprintf(err, MAX_ERR_MSG, "mkdtemp: %s", strerror(errno));
+ return -1;
+ }
+
+ ctx->se = fuse_session_new(&args, fs_ops, sizeof(*fs_ops), NULL);
+ if (!ctx->se) {
+ rmdir(ctx->mountpoint);
+ snprintf(err, MAX_ERR_MSG, "fuse_session_new failed");
+ return -1;
+ }
+
+ if (fuse_session_mount(ctx->se, ctx->mountpoint)) {
+ fuse_session_destroy(ctx->se);
+ rmdir(ctx->mountpoint);
+ snprintf(err, MAX_ERR_MSG, "fuse_session_mount failed "
+ "(missing fusermount3 or insufficient privileges)");
+ return -1;
+ }
+
+ if (pthread_create(&ctx->thread, NULL, run_daemon, ctx->se)) {
+ fuse_session_unmount(ctx->se);
+ fuse_session_destroy(ctx->se);
+ rmdir(ctx->mountpoint);
+ snprintf(err, MAX_ERR_MSG, "pthread_create: %s", strerror(errno));
+ return -1;
+ }
+
+ fuse_opt_free_args(&args);
+
+ return 0;
+}
+
+void fs_teardown(struct fuse_common_ctx *ctx)
+{
+ fuse_session_exit(ctx->se);
+ fuse_session_unmount(ctx->se);
+ pthread_join(ctx->thread, NULL);
+ fuse_session_destroy(ctx->se);
+ rmdir(ctx->mountpoint);
+}
diff --git a/tools/testing/selftests/filesystems/fuse/fuse_common.h b/tools/testing/selftests/filesystems/fuse/fuse_common.h
new file mode 100644
index 000000000000..5beb6bf89425
--- /dev/null
+++ b/tools/testing/selftests/filesystems/fuse/fuse_common.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __SELFTEST_FUSE_COMMON_H__
+#define __SELFTEST_FUSE_COMMON_H__
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <limits.h>
+
+#define FUSE_USE_VERSION 31
+#include <fuse_lowlevel.h>
+
+#define MAX_ERR_MSG 256
+
+#define MOUNTPOINT_TEMPLATE "/tmp/fuse_test_XXXXXX"
+#define MOUNTPOINT_SZ 64
+
+struct fuse_common_ctx {
+ struct fuse_session *se;
+ char mountpoint[MOUNTPOINT_SZ];
+ pthread_t thread;
+};
+
+int fs_setup(const struct fuse_lowlevel_ops *fs_ops,
+ struct fuse_common_ctx *ctx, char *err);
+void fs_teardown(struct fuse_common_ctx *ctx);
+
+#endif /* __SELFTEST_FUSE_COMMON_H__ */