From owner-svn-src-projects@freebsd.org Sat Mar 2 16:28:30 2019 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 98A201503E6A for ; Sat, 2 Mar 2019 16:28:30 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 38E146E662; Sat, 2 Mar 2019 16:28:30 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1FF467467; Sat, 2 Mar 2019 16:28:30 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x22GSTQH073209; Sat, 2 Mar 2019 16:28:29 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x22GSTTV073206; Sat, 2 Mar 2019 16:28:29 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201903021628.x22GSTTV073206@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Sat, 2 Mar 2019 16:28:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r344727 - projects/fuse2/tests/sys/fs/fuse X-SVN-Group: projects X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: projects/fuse2/tests/sys/fs/fuse X-SVN-Commit-Revision: 344727 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 38E146E662 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.97 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-1.00)[-0.999,0]; NEURAL_HAM_SHORT(-0.97)[-0.971,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Mar 2019 16:28:30 -0000 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 +#include +#include + #include #include #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 - -#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) {