X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FDaemon%2FDaemon.test.cc;h=b62d7ba15bfacd06f284c451d8f96ac8b43842ca;hb=5443435c4c2b6e4386c5334b5b8358273f2bae93;hp=cdf74b8f2a464f509b9c8939bed54ed31d599ce7;hpb=925317c7f45c32b01ab9292023db3f372b74bf0f;p=senf.git diff --git a/Utils/Daemon/Daemon.test.cc b/Utils/Daemon/Daemon.test.cc index cdf74b8..b62d7ba 100644 --- a/Utils/Daemon/Daemon.test.cc +++ b/Utils/Daemon/Daemon.test.cc @@ -21,7 +21,7 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief Daemon.test unit tests */ + \brief Daemon unit tests */ //#include "Daemon.test.hh" //#include "Daemon.test.ih" @@ -34,11 +34,11 @@ #include #include #include "Daemon.hh" -#include "../Utils/Exception.hh" -#include "../Utils/Backtrace.hh" -#include "../Scheduler/Scheduler.hh" +#include "../Exception.hh" +#include "../Backtrace.hh" +#include "../../Scheduler/Scheduler.hh" -#include "../Utils/auto_unit_test.hh" +#include "../auto_unit_test.hh" #include #define prefix_ @@ -65,15 +65,16 @@ namespace { void init() { std::cout << "Running init()" << std::endl; + std::cerr << "(stderr)" << std::endl; } void run() { std::cout << "Running run()" << std::endl; - delay(1500); + delay(2000); } }; - int myMain(int argc, char ** argv) + int myMain(int argc, char const ** argv) { MyDaemon instance; return instance.start(argc, argv); @@ -88,12 +89,13 @@ namespace { ::kill(::getpid(), SIGABRT); }; - int run(int argc, char ** argv) + int run(int argc, char const ** argv) { pid = ::fork(); if (pid < 0) throw senf::SystemException("::fork()"); if (pid == 0) { signal(SIGABRT, &backtrace); + signal(SIGCHLD, SIG_IGN); try { ::_exit(myMain(argc, argv)); } catch (std::exception & ex) { @@ -103,6 +105,7 @@ namespace { } ::_exit(125); } + signal(SIGCHLD, SIG_DFL); int status; if (::waitpid(pid, &status, 0) < 0) throw senf::SystemException("::waitpid()"); @@ -118,10 +121,11 @@ namespace { BOOST_AUTO_UNIT_TEST(testDaemon) { - char * args[] = { "run", - "--console-log=testDaemon.log", - "--pid-file=testDaemon.pid" }; - BOOST_CHECK_EQUAL( run(sizeof(args)/sizeof(*args),args), 0 ); + char const * args[] = { "run", + "--console-log=testDaemon.log", + "--pid-file=testDaemon.pid" }; + + SENF_CHECK_NO_THROW( BOOST_CHECK_EQUAL( run(sizeof(args)/sizeof(*args), args), 0 ) ); BOOST_CHECK( ! boost::filesystem::exists("invalid.log") ); BOOST_CHECK( ! boost::filesystem::exists("invalid.pid") ); @@ -138,7 +142,7 @@ BOOST_AUTO_UNIT_TEST(testDaemon) ::kill(pid, SIGHUP); } - delay(1000); + delay(2000); BOOST_CHECK( ! boost::filesystem::exists("testDaemon.pid") ); BOOST_CHECK( boost::filesystem::exists("testDaemon.log") ); BOOST_CHECK( boost::filesystem::exists("testDaemon.log.1") ); @@ -146,9 +150,9 @@ BOOST_AUTO_UNIT_TEST(testDaemon) std::ifstream log ("testDaemon.log.1"); std::stringstream data; data << log.rdbuf(); - BOOST_CHECK_EQUAL( data.str(), "Running init()\nRunning run()\n" ); - BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log") ); - BOOST_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log.1") ); + BOOST_CHECK_EQUAL( data.str(), "Running init()\n(stderr)\nRunning run()\n" ); + SENF_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log") ); + SENF_CHECK_NO_THROW( boost::filesystem::remove("testDaemon.log.1") ); } ///////////////////////////////cc.e////////////////////////////////////////