Date: Sat, 2 Mar 2019 16:28:29 +0000 (UTC) From: Alan Somers <asomers@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r344727 - projects/fuse2/tests/sys/fs/fuse Message-ID: <201903021628.x22GSTTV073206@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: asomers Date: Sat Mar 2 16:28:29 2019 New Revision: 344727 URL: https://svnweb.freebsd.org/changeset/base/344727 Log: fuse(4) use a global environment check. This is marginally faster than using an environment check in each test case. Also, if the global check fails then all of the tests are skipped. Oddly, it's not possible to skip a test in any other way. Also, allow the test to run as a normal user if vfs.usermount=1 and /dev/fuse is accessible. Reported by: ngie Sponsored by: The FreeBSD Foundation Modified: projects/fuse2/tests/sys/fs/fuse/Makefile projects/fuse2/tests/sys/fs/fuse/utils.cc projects/fuse2/tests/sys/fs/fuse/utils.hh Modified: projects/fuse2/tests/sys/fs/fuse/Makefile ============================================================================== --- projects/fuse2/tests/sys/fs/fuse/Makefile Sat Mar 2 16:10:11 2019 (r344726) +++ projects/fuse2/tests/sys/fs/fuse/Makefile Sat Mar 2 16:28:29 2019 (r344727) @@ -25,7 +25,6 @@ SRCS.setattr+= utils.cc # TODO: drastically increase timeout after test development is mostly complete TEST_METADATA+= timeout=10 -TEST_METADATA+= required_user=root FUSEFS= ${.CURDIR:H:H:H:H}/sys/fs/fuse MOUNT= ${.CURDIR:H:H:H:H}/sbin/mount Modified: projects/fuse2/tests/sys/fs/fuse/utils.cc ============================================================================== --- projects/fuse2/tests/sys/fs/fuse/utils.cc Sat Mar 2 16:10:11 2019 (r344726) +++ projects/fuse2/tests/sys/fs/fuse/utils.cc Sat Mar 2 16:28:29 2019 (r344727) @@ -27,11 +27,44 @@ * SUCH DAMAGE. */ +#include <sys/param.h> +#include <sys/module.h> +#include <sys/sysctl.h> + #include <gtest/gtest.h> #include <unistd.h> #include "mockfs.hh" +#include "utils.hh" +class FuseEnv: public ::testing::Environment { + virtual void SetUp() { + const char *mod_name = "fuse"; + const char *devnode = "/dev/fuse"; + const char *usermount_node = "vfs.usermount"; + int usermount_val = 0; + size_t usermount_size = sizeof(usermount_val); + if (modfind(mod_name) == -1) { + FAIL() << "Module " << mod_name << + " could not be resolved"; + } + if (eaccess(devnode, R_OK | W_OK)) { + if (errno == ENOENT) { + FAIL() << devnode << " does not exist"; + } else if (errno == EACCES) { + FAIL() << devnode << + " is not accessible by the current user"; + } else { + FAIL() << strerror(errno); + } + } + sysctlbyname(usermount_node, &usermount_val, &usermount_size, + NULL, 0); + if (geteuid() != 0 && !usermount_val) + FAIL() << "current user is not allowed to mount"; + } +}; + static void usage(char* progname) { fprintf(stderr, "Usage: %s [-v]\n\t-v increase verbosity\n", progname); exit(2); @@ -39,8 +72,10 @@ static void usage(char* progname) { int main(int argc, char **argv) { int ch; + FuseEnv *fuse_env = new FuseEnv; ::testing::InitGoogleTest(&argc, argv); + ::testing::AddGlobalTestEnvironment(fuse_env); while ((ch = getopt(argc, argv, "v")) != -1) { switch (ch) { Modified: projects/fuse2/tests/sys/fs/fuse/utils.hh ============================================================================== --- projects/fuse2/tests/sys/fs/fuse/utils.hh Sat Mar 2 16:10:11 2019 (r344726) +++ projects/fuse2/tests/sys/fs/fuse/utils.hh Sat Mar 2 16:28:29 2019 (r344727) @@ -27,27 +27,12 @@ * SUCH DAMAGE. */ -#include <sys/module.h> - -#define GTEST_REQUIRE_KERNEL_MODULE(_mod_name) do { \ - if (modfind(_mod_name) == -1) { \ - printf("module %s could not be resolved: %s\n", \ - _mod_name, strerror(errno)); \ - /* - * TODO: enable GTEST_SKIP once GoogleTest 1.8.2 merges - * GTEST_SKIP() - */ \ - FAIL() << "Module " << _mod_name << " could not be resolved\n";\ - } \ -} while(0) - class FuseTest : public ::testing::Test { protected: MockFS *m_mock = NULL; public: void SetUp() { - GTEST_REQUIRE_KERNEL_MODULE("fuse"); try { m_mock = new MockFS{}; } catch (std::system_error err) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201903021628.x22GSTTV073206>