Update SENF to compile using g++ 4.3.2 (Ubuntu 8.10)
[senf.git] / Scheduler / ClockService.test.cc
index 88c68e9..8ffa717 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 #include "ClockService.hh"
 #include <errno.h>
 
-#include <boost/test/auto_unit_test.hpp>
+#include "../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
 
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
-namespace senf {
-namespace detail {
-
-    struct ClockServiceTest
-    {
-        static boost::posix_time::ptime & base() 
-            { return senf::ClockService::instance().base_; }
-        static boost::posix_time::ptime & heartbeat()
-            { return senf::ClockService::instance().heartbeat_; }
-    };
-
-}}
-
 namespace {
 
     bool is_close_clock(senf::ClockService::clock_type a, senf::ClockService::clock_type b, 
-                        unsigned long delta = 50000000ul)
-    {
-        return (a<b ? b-a : a-b ) < delta;
-    }
-
-    bool is_close_pt(boost::posix_time::ptime a, boost::posix_time::ptime b,
-                     boost::posix_time::time_duration delta = boost::posix_time::milliseconds(50) )
+                        unsigned long delta)
     {
         return (a<b ? b-a : a-b ) < delta;
     }
@@ -82,45 +63,35 @@ BOOST_AUTO_UNIT_TEST(clockService)
     senf::ClockService::clock_type t2 (senf::ClockService::now());
     BOOST_CHECK_PREDICATE( is_close_clock,
                            (t1 + senf::ClockService::milliseconds(200)) 
-                           (t2) );
+                           (t2)
+                           (senf::ClockService::milliseconds(100)) );
 
     t1 = t2;
-    // We shift both heartbeat() and base() back 1 minute. This is the same as
-    // moving the current time forward 1 minute.
-    boost::posix_time::ptime b (senf::detail::ClockServiceTest::base());
-    boost::posix_time::ptime h (senf::detail::ClockServiceTest::heartbeat());
-    senf::detail::ClockServiceTest::heartbeat() -= boost::posix_time::minutes(1);
-    senf::detail::ClockServiceTest::base() -= boost::posix_time::minutes(1);
 
     // Wait for SIGALRM and let the signal handler do the clock-skew detection
-    delay(senf::ClockService::CheckInterval*1000);
-
-    BOOST_CHECK_PREDICATE( is_close_pt,
-                           (b)
-                           (senf::detail::ClockServiceTest::base()) );
-    BOOST_CHECK_PREDICATE( is_close_pt,
-                           (h+boost::posix_time::seconds(senf::ClockService::CheckInterval))
-                           (senf::detail::ClockServiceTest::heartbeat()) );
+    delay(1*1000);
 
     t2 = senf::ClockService::now();
     BOOST_CHECK_PREDICATE( is_close_clock,
-                           (t1 + senf::ClockService::seconds(senf::ClockService::CheckInterval))
-                           (t2) );
+                           (t1 + senf::ClockService::seconds(1))
+                           (t2)
+                           (senf::ClockService::milliseconds(500)) );
 
     t1 = t2;
 
-    senf::detail::ClockServiceTest::heartbeat() -= boost::posix_time::minutes(1);
-    senf::detail::ClockServiceTest::base() -= boost::posix_time::minutes(1);
-
-    // Let now() do the clock skew detection using getitimer() ...
     delay(200);
     BOOST_CHECK_PREDICATE( is_close_clock,
                            (t1 + senf::ClockService::milliseconds(200))
-                           (senf::ClockService::now()) );
-    
-    // We need restart the clock-service here to fix up the bad heartbeat value. That's faster
-    // than waiting another CheckInterval seconds for SIGALRM
-    senf::ClockService::restart();
+                           (senf::ClockService::now())
+                           (senf::ClockService::milliseconds(100)) );
+
+    // The next check validates that the clock service itimer/heartbeat_ is correctly reset after a
+    // clock-skew is detected
+
+    BOOST_CHECK_PREDICATE( is_close_clock,
+                           (t1 + senf::ClockService::milliseconds(200))
+                           (senf::ClockService::now()) 
+                           (senf::ClockService::milliseconds(100)) );
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////