From 221514b72f4214ac2d4383a7381eb970a77a8d2e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 16 Feb 2015 17:12:57 +0000 Subject: Add the start of some test framework, complete with hacky initialisations --- netfs/Jamfile.jam | 1 + netfs/unittests/Jamfile.jam | 28 +++++++++++++ netfs/unittests/client.xml | 14 +++++++ netfs/unittests/daemon.xml | 19 +++++++++ netfs/unittests/testCore.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+) create mode 100644 netfs/unittests/Jamfile.jam create mode 100644 netfs/unittests/client.xml create mode 100644 netfs/unittests/daemon.xml create mode 100644 netfs/unittests/testCore.cpp diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam index 70cd2d9..6df8110 100644 --- a/netfs/Jamfile.jam +++ b/netfs/Jamfile.jam @@ -18,6 +18,7 @@ lib slicer-xml : : : : /usr/include/slicer ; build-project daemon ; build-project fuse ; +build-project unittests ; explicit install ; package.install install : : fuse//netfs : daemon//netfsd ; diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam new file mode 100644 index 0000000..1c16bc7 --- /dev/null +++ b/netfs/unittests/Jamfile.jam @@ -0,0 +1,28 @@ +import testing ; + +lib boost_utf : : boost_unit_test_framework ; +lib boost_system ; +lib boost_filesystem ; +lib IceUtil ; +lib Ice ; + +path-constant me : . ; + +run + testCore.cpp + : : + client.xml + daemon.xml + : + BOOST_TEST_DYN_LINK + IceUtil + Ice + boost_system + boost_filesystem + boost_utf + ../daemon//netfsd + ../fuse//netfsClient + ../ice//netfsComms + ROOT=\"$(me)\" + : testCore ; + diff --git a/netfs/unittests/client.xml b/netfs/unittests/client.xml new file mode 100644 index 0000000..c159a24 --- /dev/null +++ b/netfs/unittests/client.xml @@ -0,0 +1,14 @@ + + + + + testvol + + unittest + + tcp -h localhost -p 4000 + + + + + diff --git a/netfs/unittests/daemon.xml b/netfs/unittests/daemon.xml new file mode 100644 index 0000000..8bf58a9 --- /dev/null +++ b/netfs/unittests/daemon.xml @@ -0,0 +1,19 @@ + + + + + unittest + + tcp -p 4000:udp -p 10000 + + + + + + unittest + + /usr/portage + + + + diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp new file mode 100644 index 0000000..b9a1836 --- /dev/null +++ b/netfs/unittests/testCore.cpp @@ -0,0 +1,95 @@ +#define BOOST_TEST_MODULE TestNetFSCore +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef ROOT +#error "ROOT needs to be defined at compilation time" +#endif + +#define XSTR(s) STR(s) +#define STR(s) #s +const boost::filesystem::path RootDir(XSTR(ROOT)); + +class FuseMock : public NetFS::FuseApp { + public: + FuseMock(int & argc, char ** argv) : + NetFS::FuseApp(argc, argv) + { + ::memset(&context, 0, sizeof(fuse_context)); + } + + struct fuse_context * fuse_get_context() override + { + return &context; + } + + int fuse_opt_parse(struct fuse_args * args, void * data, const struct fuse_opt [], fuse_opt_proc_t proc) override + { + for (int n = 0; n < args->argc; n += 1) { + proc(data, args->argv[n], n, args); + } + return 0; + } + private: + fuse_context context; +}; + +char * argv[] = { + strdup((RootDir / "client.xml:testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()) +}; + +class Core { + public: + Core() : + params({}), + ic(Ice::initialize(params)), + daemon(ic), + argc(2), + fuse(new FuseMock(argc, argv)) + { + ic->getProperties()->setProperty("NetFSD.ConfigPath", (RootDir / "daemon.xml").string()); + ic->getProperties()->setProperty("NetFSD.HostNameOverride", "unittest"); + daemon.start("NetFSDaemonAdapter", ic, {}); + char ** a = argv; + fuse->runint(argc, a); + fuse->init(NULL); + } + + ~Core() + { + delete fuse; + ic->destroy(); + } + + protected: + Ice::StringSeq params; + Ice::CommunicatorPtr ic; + NetFSDaemon daemon; + int argc; + FuseAppBase * fuse; +}; + +BOOST_FIXTURE_TEST_SUITE( NetfsCore, Core ) + +BOOST_AUTO_TEST_CASE ( daemonInitialised ) +{ + auto service = NetFS::ServicePrx::checkedCast(ic->stringToProxy("Service")); + BOOST_REQUIRE(service); + service->ice_ping(); +} + +BOOST_AUTO_TEST_CASE ( clientInitialised ) +{ + struct statvfs s; + fuse->statfs("/", &s); +} + +BOOST_AUTO_TEST_SUITE_END(); + -- cgit v1.2.3