From 8a0331d5a9d129ad9fc851eb58e4d30c434c544f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Jul 2015 00:57:14 +0100 Subject: Classify test cases into their own files --- netfs/unittests/Jamfile.jam | 33 +++++++++++++++--- netfs/unittests/testCore.cpp | 70 --------------------------------------- netfs/unittests/testEdgeCases.cpp | 60 +++++++++++++++++++++++++++++++++ netfs/unittests/testGlacier.cpp | 41 +++++++++++++++++++++++ 4 files changed, 129 insertions(+), 75 deletions(-) create mode 100644 netfs/unittests/testEdgeCases.cpp create mode 100644 netfs/unittests/testGlacier.cpp diff --git a/netfs/unittests/Jamfile.jam b/netfs/unittests/Jamfile.jam index 3b4694b..79f77e3 100644 --- a/netfs/unittests/Jamfile.jam +++ b/netfs/unittests/Jamfile.jam @@ -8,19 +8,42 @@ lib Ice ; path-constant me : . ; -run - testCore.cpp mockDaemon.cpp mockFuse.cpp +lib testMocks : + [ glob mock*.cpp ] : : - : - BOOST_TEST_DYN_LINK IceUtil Ice boost_system boost_filesystem - boost_utf ../daemon//netfsd ../fuse//netfsClient ../ice//netfsComms ROOT=\"$(me)\" + : + boost_system + boost_filesystem + ROOT=\"$(me)\" + ; + + +run testCore.cpp + : : : + BOOST_TEST_DYN_LINK + boost_utf + testMocks : testCore ; +run testGlacier.cpp + : : : + BOOST_TEST_DYN_LINK + boost_utf + testMocks + : testGlacier ; + +run testEdgeCases.cpp + : : : + BOOST_TEST_DYN_LINK + boost_utf + testMocks + : testEdgeCases ; + diff --git a/netfs/unittests/testCore.cpp b/netfs/unittests/testCore.cpp index 6589838..75d55a4 100644 --- a/netfs/unittests/testCore.cpp +++ b/netfs/unittests/testCore.cpp @@ -1,10 +1,5 @@ #define BOOST_TEST_MODULE TestNetFSCore #include -#include -#include -#include -#include -#include #include "mockDaemon.h" #include "mockFuse.h" #include @@ -58,68 +53,3 @@ BOOST_AUTO_TEST_CASE ( clientInitialised ) BOOST_AUTO_TEST_SUITE_END(); -BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) -{ - MockDaemonHost daemon(testEndpoint); - FuseMockHost fuse(testEndpoint, 2, defaultFuseArgv); - - struct statvfs s; - BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); - - const char * fileName = "/createMe"; - BOOST_CHECKPOINT("Create a new file"); - struct fuse_file_info fh; - memset(&fh, 0, sizeof(fh)); - fh.flags = O_WRONLY | O_CREAT | O_APPEND; - BOOST_REQUIRE_EQUAL(0, fuse.fuse->create(fileName, 0100644, &fh)); - BOOST_REQUIRE(fh.fh); - - BOOST_CHECKPOINT("Fetch file attributes"); - struct stat st; - BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); - BOOST_REQUIRE_EQUAL(st.st_size, 0); - BOOST_REQUIRE_EQUAL(st.st_uid, getuid()); - BOOST_REQUIRE_EQUAL(st.st_gid, getgid()); - - BOOST_CHECKPOINT("Write some data"); - char someData[890]; - BOOST_REQUIRE_EQUAL(sizeof(someData), fuse.fuse->write(fileName, someData, sizeof(someData), 0, &fh)); - - BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); - BOOST_REQUIRE_EQUAL(st.st_size, sizeof(someData)); - - BOOST_CHECKPOINT("Restart daemon object"); - daemon.restart(); - - BOOST_CHECKPOINT("Fetch file attributes again"); - BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); - - BOOST_CHECKPOINT("Close file"); - BOOST_REQUIRE_EQUAL(0, fuse.fuse->release(fileName, &fh)); -} - -BOOST_AUTO_TEST_CASE ( withRouter ) -{ - BOOST_REQUIRE_EQUAL(0, - system("/usr/bin/glacier2router --Glacier2.Client.Endpoints='tcp -p 4063' --Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier --daemon --pidfile /tmp/glacier.pid")); - sleep(1); - - BOOST_SCOPE_EXIT(void) { - system("kill $(cat /tmp/glacier.pid)"); - } BOOST_SCOPE_EXIT_END; - - { - char * glacierFuseArgv[] = { - strdup((RootDir / ":testvol").string().c_str()), - strdup((RootDir / "test").string().c_str()), - strdup("--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 4063") - }; - - MockDaemonHost daemon(testEndpoint); - FuseMockHost fuse(testEndpoint, 3, glacierFuseArgv); - - struct statvfs s; - BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); - } -} - diff --git a/netfs/unittests/testEdgeCases.cpp b/netfs/unittests/testEdgeCases.cpp new file mode 100644 index 0000000..afa2338 --- /dev/null +++ b/netfs/unittests/testEdgeCases.cpp @@ -0,0 +1,60 @@ +#define BOOST_TEST_MODULE TestNetFSEdgeCases +#include +#include "mockDaemon.h" +#include "mockFuse.h" +#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)); +const std::string testEndpoint("tcp -h localhost -p 12014"); + +char * defaultFuseArgv[] = { + strdup((RootDir / ":testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()) +}; + +BOOST_AUTO_TEST_CASE ( createAndDaemonRestart ) +{ + MockDaemonHost daemon(testEndpoint); + FuseMockHost fuse(testEndpoint, 2, defaultFuseArgv); + + struct statvfs s; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + + const char * fileName = "/createMe"; + BOOST_CHECKPOINT("Create a new file"); + struct fuse_file_info fh; + memset(&fh, 0, sizeof(fh)); + fh.flags = O_WRONLY | O_CREAT | O_APPEND; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->create(fileName, 0100644, &fh)); + BOOST_REQUIRE(fh.fh); + + BOOST_CHECKPOINT("Fetch file attributes"); + struct stat st; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + BOOST_REQUIRE_EQUAL(st.st_size, 0); + BOOST_REQUIRE_EQUAL(st.st_uid, getuid()); + BOOST_REQUIRE_EQUAL(st.st_gid, getgid()); + + BOOST_CHECKPOINT("Write some data"); + char someData[890]; + BOOST_REQUIRE_EQUAL(sizeof(someData), fuse.fuse->write(fileName, someData, sizeof(someData), 0, &fh)); + + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + BOOST_REQUIRE_EQUAL(st.st_size, sizeof(someData)); + + BOOST_CHECKPOINT("Restart daemon object"); + daemon.restart(); + + BOOST_CHECKPOINT("Fetch file attributes again"); + BOOST_REQUIRE_EQUAL(0, fuse.fuse->fgetattr(fileName, &st, &fh)); + + BOOST_CHECKPOINT("Close file"); + BOOST_REQUIRE_EQUAL(0, fuse.fuse->release(fileName, &fh)); +} + diff --git a/netfs/unittests/testGlacier.cpp b/netfs/unittests/testGlacier.cpp new file mode 100644 index 0000000..17f892a --- /dev/null +++ b/netfs/unittests/testGlacier.cpp @@ -0,0 +1,41 @@ +#define BOOST_TEST_MODULE TestNetFSGlacier +#include +#include "mockDaemon.h" +#include "mockFuse.h" +#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)); +const std::string testEndpoint("tcp -h localhost -p 12013"); + +BOOST_AUTO_TEST_CASE ( withRouter ) +{ + BOOST_REQUIRE_EQUAL(0, + system("/usr/bin/glacier2router --Glacier2.Client.Endpoints='tcp -p 4063' --Glacier2.PermissionsVerifier=Glacier2/NullPermissionsVerifier --daemon --pidfile /tmp/glacier.pid")); + sleep(1); + + BOOST_SCOPE_EXIT(void) { + system("kill $(cat /tmp/glacier.pid)"); + } BOOST_SCOPE_EXIT_END; + + { + char * glacierFuseArgv[] = { + strdup((RootDir / ":testvol").string().c_str()), + strdup((RootDir / "test").string().c_str()), + strdup("--Ice.Default.Router=Glacier2/router:tcp -h localhost -p 4063") + }; + + MockDaemonHost daemon(testEndpoint); + FuseMockHost fuse(testEndpoint, 3, glacierFuseArgv); + + struct statvfs s; + BOOST_REQUIRE_EQUAL(0, fuse.fuse->statfs("/", &s)); + } +} + -- cgit v1.2.3