4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief ClockService unit tests */
31 //#include "ClockService.test.hh"
32 //#include "ClockService.test.ih"
35 #include "ClockService.hh"
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 bool is_close_clock(senf::ClockService::clock_type a, senf::ClockService::clock_type b,
47 senf::ClockService::clock_type delta)
49 return (a<b ? b-a : a-b ) < delta;
52 void delay(unsigned long milliseconds)
55 ts.tv_sec = milliseconds / 1000;
56 ts.tv_nsec = (milliseconds % 1000) * 1000000;
57 while (nanosleep(&ts,&ts) < 0 && errno == EINTR) ;
62 SENF_AUTO_UNIT_TEST(clockService)
64 BOOST_CHECK( senf::ClockService::abstime(senf::ClockService::clock_type(0)).is_not_a_date_time());
66 char const * enabled (getenv("SENF_TIMING_CRITICAL_TESTS"));
67 BOOST_WARN_MESSAGE(enabled, "Set SENF_TIMING_CRITICAL_TESTS to not skip timing critical tests");
70 senf::ClockService::restart(); // So we know, when the signal will be delivered
72 senf::ClockService::clock_type t1 (senf::ClockService::now());
74 senf::ClockService::clock_type t2 (senf::ClockService::now());
76 BOOST_CHECK_PREDICATE( is_close_clock,
77 (t1 + senf::ClockService::milliseconds(200))
79 (senf::ClockService::milliseconds(100)) );
83 // Wait for SIGALRM and let the signal handler do the clock-skew detection
86 t2 = senf::ClockService::now();
88 BOOST_CHECK_PREDICATE( is_close_clock,
89 (t1 + senf::ClockService::seconds(1))
91 (senf::ClockService::milliseconds(500)) );
97 BOOST_CHECK_PREDICATE( is_close_clock,
98 (t1 + senf::ClockService::milliseconds(200))
99 (senf::ClockService::now())
100 (senf::ClockService::milliseconds(100)) );
102 // The next check validates that the clock service itimer/heartbeat_ is correctly reset after a
103 // clock-skew is detected
106 BOOST_CHECK_PREDICATE( is_close_clock,
107 (t1 + senf::ClockService::milliseconds(200))
108 (senf::ClockService::now())
109 (senf::ClockService::milliseconds(100)) );
112 //-/////////////////////////////////////////////////////////////////////////////////////////////////
119 // comment-column: 40
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u test"