From: g0dil Date: Fri, 15 May 2009 18:47:20 +0000 (+0000) Subject: Scheduler: Fix timer scheduling delay unit-test X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=82e8df5de8b11448423388632e8602ad97bc7885;p=senf.git Scheduler: Fix timer scheduling delay unit-test Scheduler: Fix EventHook API git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1208 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Scheduler/EventHook.cci b/Scheduler/EventHook.cci index 89e1b1a..8cbec85 100644 --- a/Scheduler/EventHook.cci +++ b/Scheduler/EventHook.cci @@ -34,8 +34,8 @@ // senf::scheduler::EventHook prefix_ senf::scheduler::EventHook::EventHook(std::string const & name, Callback const & cb, - bool initiallyEnabled, - detail::FIFORunner::TaskInfo::Priority priority) + detail::FIFORunner::TaskInfo::Priority priority, + bool initiallyEnabled) : detail::FIFORunner::TaskInfo(name, priority), cb_ (cb) { if (initiallyEnabled) diff --git a/Scheduler/EventHook.hh b/Scheduler/EventHook.hh index 4437780..0ab24c9 100644 --- a/Scheduler/EventHook.hh +++ b/Scheduler/EventHook.hh @@ -82,7 +82,7 @@ namespace scheduler { ///@{ EventHook(std::string const & name, Callback const & cb, - bool initiallyEnabled = true, Priority priority = POST); + Priority priority, bool initiallyEnabled = true); ///< Register an event hook /**< Registers \a cb to be called whenever any other event is signaled by the scheduler. If \a initiallyEnabled is diff --git a/Scheduler/Scheduler.test.cc b/Scheduler/Scheduler.test.cc index 0a13518..14e01bc 100644 --- a/Scheduler/Scheduler.test.cc +++ b/Scheduler/Scheduler.test.cc @@ -242,8 +242,8 @@ void schedulerTest() /////////////////////////////////////////////////////////////////////////// - senf::scheduler::EventHook evev ("eventCounter", eventeventhandler, true, - senf::scheduler::EventHook::PRE); + senf::scheduler::EventHook evev ("eventCounter", eventeventhandler, + senf::scheduler::EventHook::PRE); { senf::scheduler::FdEvent fde1 ("testFdEvent", boost::bind(&callback, sock, _1), diff --git a/Scheduler/TimerEvent.test.cc b/Scheduler/TimerEvent.test.cc index ff410e9..7801ad1 100644 --- a/Scheduler/TimerEvent.test.cc +++ b/Scheduler/TimerEvent.test.cc @@ -96,24 +96,37 @@ namespace { unsigned count (0); senf::ClockService::clock_type delay (0); + bool haveCb (false); void jitterCb(senf::scheduler::TimerEvent & tm) { std::cerr << senf::scheduler::now() << ' ' << tm.timeout() << '\n'; count ++; delay += senf::scheduler::now() - tm.timeout(); + haveCb = true; tm.timeout(randomDelay()); } - void logSchedulerTime() + void preCb() { - std::cerr << senf::scheduler::now() << '\n'; + haveCb = false; + } + + void postCb() + { + if (! haveCb) + std::cerr << senf::scheduler::now() << '\n'; } void jitterTest() { count = 0; delay = 0; + senf::scheduler::EventHook pre ("jitterTest::preCb", &preCb, + senf::scheduler::EventHook::PRE); + senf::scheduler::EventHook post ("jitterTest::postCb", &postCb, + senf::scheduler::EventHook::POST); + senf::scheduler::TimerEvent tm1 ("jitterTest::tm1", boost::bind(&jitterCb, boost::ref(tm1)), randomDelay()); senf::scheduler::TimerEvent tm2 ("jitterTest::tm2", boost::bind(&jitterCb, boost::ref(tm2)), @@ -124,9 +137,6 @@ namespace { senf::scheduler::TimerEvent timeout("jitterTest::timeout", &senf::scheduler::terminate, senf::scheduler::now() + senf::ClockService::seconds(5)); - senf::scheduler::EventHook timerCalled ("jitterTest::logSchedulerTime", &logSchedulerTime, - senf::scheduler::EventHook::PRE); - senf::scheduler::process(); std::cerr << "Average scheduling delay: " << delay/count << "\n";