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
This commit is contained in:
parent
7716c35f77
commit
8eeb82e169
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/projects/fuse2/; revision=344727
@ -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
|
||||
|
@ -27,10 +27,43 @@
|
||||
* 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);
|
||||
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user