summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-04-17 18:19:47 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2022-04-17 18:19:47 +0100
commit68116c031b893d97db4045a92d5d74f907d2fb47 (patch)
treea0a4c816a43ea8183465446679d6af17081223c5
parentPrefer pragma once (diff)
downloadnetfs-68116c031b893d97db4045a92d5d74f907d2fb47.tar.bz2
netfs-68116c031b893d97db4045a92d5d74f907d2fb47.tar.xz
netfs-68116c031b893d97db4045a92d5d74f907d2fb47.zip
Split out MockFuseApp from FuseMountPoint to address race conditions
-rw-r--r--netfs/unittests/mockMount.cpp40
-rw-r--r--netfs/unittests/mockMount.h39
-rw-r--r--netfs/unittests/testFuse.cpp4
3 files changed, 43 insertions, 40 deletions
diff --git a/netfs/unittests/mockMount.cpp b/netfs/unittests/mockMount.cpp
index 38c9857..adf1804 100644
--- a/netfs/unittests/mockMount.cpp
+++ b/netfs/unittests/mockMount.cpp
@@ -5,56 +5,48 @@
const std::string testEndpoint("tcp -h localhost -p 12015");
const std::string testUri("tcp://localhost:12015/testvol");
-FuseMountPoint::FuseMountPoint() :
- MockDaemonHost(::testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()}),
- NetFS::FuseApp({::testUri}), fargs {}
+MockFuseApp::MockFuseApp() : NetFS::FuseApp({::testUri}), fargs {}
{
- std::filesystem::remove_all(mntpnt);
- std::filesystem::create_directory(mntpnt);
::fuse_opt_add_arg(&fargs, selfExe.c_str());
::fuse_opt_add_arg(&fargs, "-onoauto_cache");
::fuse_opt_add_arg(&fargs, "-oattr_timeout=0");
::fuse_opt_add_arg(&fargs, "-oac_attr_timeout=0");
fs = ::fuse_new(&fargs, &operations, sizeof(fuse_operations), this);
BOOST_REQUIRE(fs);
- start();
}
-void
-FuseMountPoint::start()
+FuseMountPoint::FuseMountPoint() :
+ MockDaemonHost(::testEndpoint, {"--NetFSD.ConfigPath=" + (rootDir / "defaultDaemon.xml").string()})
{
- BOOST_REQUIRE(!th);
- BOOST_REQUIRE_EQUAL(0, ::fuse_mount(fs, mntpnt.c_str()));
- th = std::make_unique<std::thread>(::fuse_loop, fs);
+ std::filesystem::remove_all(mntpnt);
+ std::filesystem::create_directory(mntpnt);
+ BOOST_REQUIRE_EQUAL(0, ::fuse_mount(fuseApp.fs, mntpnt.c_str()));
+ th.emplace(::fuse_loop, fuseApp.fs);
BOOST_REQUIRE(th);
}
FuseMountPoint::~FuseMountPoint()
{
- stop();
+ ::fuse_exit(fuseApp.fs);
+ th->join();
+ ::fuse_unmount(fuseApp.fs);
std::filesystem::remove(mntpnt);
- ::fuse_destroy(fs);
- ::fuse_opt_free_args(&fargs);
}
-void
-FuseMountPoint::stop()
+MockFuseApp::~MockFuseApp()
{
- if (th) {
- ::fuse_unmount(fs);
- th->join();
- th.reset();
- }
+ ::fuse_destroy(fs);
+ ::fuse_opt_free_args(&fargs);
}
struct fuse_context *
-FuseMountPoint::fuse_get_context()
+MockFuseApp::fuse_get_context()
{
return ::fuse_get_context();
}
char *
-FuseMountPoint::vstrdupf(const char * fmt, va_list args)
+MockFuseApp::vstrdupf(const char * fmt, va_list args)
{
char * out {};
#pragma GCC diagnostic push
@@ -67,7 +59,7 @@ FuseMountPoint::vstrdupf(const char * fmt, va_list args)
}
void
-FuseMountPoint::vlogf(int, const char * fmt, va_list args) const noexcept
+MockFuseApp::vlogf(int, const char * fmt, va_list args) const noexcept
{
std::unique_ptr<char, void (*)(void *)> msg(vstrdupf(fmt, args), std::free);
static std::mutex btm;
diff --git a/netfs/unittests/mockMount.h b/netfs/unittests/mockMount.h
index 2eaad82..8495718 100644
--- a/netfs/unittests/mockMount.h
+++ b/netfs/unittests/mockMount.h
@@ -9,25 +9,36 @@
inline const std::filesystem::path mntpnt {binDir / "mnt"};
-class DLL_PUBLIC FuseMountPoint : public MockDaemonHost, public NetFS::FuseApp {
+class DLL_PUBLIC MockFuseApp : public NetFS::FuseApp {
public:
- FuseMountPoint();
-
- void start();
-
- ~FuseMountPoint() override;
-
- void stop();
-
- SPECIAL_MEMBERS_DELETE(FuseMountPoint);
+ MockFuseApp();
+ ~MockFuseApp() override;
+ SPECIAL_MEMBERS_DELETE(MockFuseApp);
struct fuse_context * fuse_get_context() override;
- static char * vstrdupf(const char * fmt, va_list args);
-
void vlogf(int, const char * fmt, va_list args) const noexcept override;
-
+ const auto &
+ getStatCache() const
+ {
+ return statCache;
+ }
+
+private:
+ friend class FuseMountPoint;
+ static char * vstrdupf(const char * fmt, va_list args);
struct fuse * fs;
struct fuse_args fargs;
- std::unique_ptr<std::thread> th;
+};
+
+class DLL_PUBLIC FuseMountPoint : public MockDaemonHost {
+public:
+ FuseMountPoint();
+ ~FuseMountPoint();
+ SPECIAL_MEMBERS_DELETE(FuseMountPoint);
+
+ MockFuseApp fuseApp;
+
+private:
+ std::optional<std::thread> th;
};
diff --git a/netfs/unittests/testFuse.cpp b/netfs/unittests/testFuse.cpp
index cbd2d66..ae99b55 100644
--- a/netfs/unittests/testFuse.cpp
+++ b/netfs/unittests/testFuse.cpp
@@ -57,13 +57,13 @@ BOOST_AUTO_TEST_CASE(fuse_ls, *boost::unit_test::timeout(5))
const auto st_local = get_lstat(lpath);
- BOOST_CHECK(!statCache.get("/me"));
+ BOOST_CHECK(!fuseApp.getStatCache().get("/me"));
std::set<std::filesystem::path> paths(std::filesystem::directory_iterator(mntpnt), {});
BOOST_REQUIRE_EQUAL(paths.size(), 1);
BOOST_CHECK_EQUAL(paths.begin()->filename(), "me");
- auto cached = statCache.get("/me");
+ auto cached = fuseApp.getStatCache().get("/me");
BOOST_REQUIRE(cached);
const auto & st_cache = (*cached);
BOOST_CHECK_EQUAL_STAT(st_cache, st_local);