From 8c4165a04351941a87befd08483ab8832a3e5fb5 Mon Sep 17 00:00:00 2001 From: Carlos Llamas Date: Thu, 15 Jul 2021 03:18:05 +0000 Subject: [PATCH] BACKPORT: selftests/binderfs: add test for feature files Verify that feature files are created successfully after mounting a binderfs instance. Note that only "oneway_spam_detection" feature is tested with this patch as it is currently the only feature listed. Acked-by: Christian Brauner Signed-off-by: Carlos Llamas Link: https://lore.kernel.org/r/20210715031805.1725878-3-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 07e913418ce4ba5eb620dd4668bf91ec94e11136) Bug: 191910201 Signed-off-by: Carlos Llamas [cmllamas: fix merge issues due to missing eaa163caa4cc] Change-Id: I86d7ef34b3099c8714c319e48029aaf3dbf87081 --- .../filesystems/binderfs/binderfs_test.c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c index 8c2ed962e1c7..e6e679a03bc9 100644 --- a/tools/testing/selftests/filesystems/binderfs/binderfs_test.c +++ b/tools/testing/selftests/filesystems/binderfs/binderfs_test.c @@ -17,6 +17,10 @@ #include #include "../../kselftest.h" +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#endif + static ssize_t write_nointr(int fd, const void *buf, size_t count) { ssize_t ret; @@ -140,6 +144,10 @@ static void __do_binderfs_test(void) bool keep = false; struct binderfs_device device = { 0 }; struct binder_version version = { 0 }; + char device_path[sizeof("/dev/binderfs/") + BINDERFS_MAX_NAME]; + static const char * const binder_features[] = { + "oneway_spam_detection", + }; change_to_mountns(); @@ -241,6 +249,20 @@ static void __do_binderfs_test(void) /* binder-control device removal failed as expected */ ksft_inc_xfail_cnt(); + for (int i = 0; i < ARRAY_SIZE(binder_features); i++) { + snprintf(device_path, sizeof(device_path), + "/dev/binderfs/features/%s", binder_features[i]); + fd = open(device_path, O_CLOEXEC | O_RDONLY); + if (fd < 0) { + ksft_exit_fail_msg("%s - Failed to open binder feature: %s", + strerror(errno), binder_features[i]); + } + close(fd); + } + + /* success: binder feature files found */ + ksft_inc_pass_cnt(); + on_error: ret = umount2("/dev/binderfs", MNT_DETACH); keep ?: rmdir_protect_errno("/dev/binderfs");