4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief ClockService unit tests */
26 //#include "ClockService.test.hh"
27 //#include "ClockService.test.ih"
30 #include "ClockService.hh"
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
41 bool is_close_clock(senf::ClockService::clock_type a, senf::ClockService::clock_type b,
42 senf::ClockService::clock_type delta)
44 return (a<b ? b-a : a-b ) < delta;
47 void delay(unsigned long milliseconds)
50 ts.tv_sec = milliseconds / 1000;
51 ts.tv_nsec = (milliseconds % 1000) * 1000000;
52 while (nanosleep(&ts,&ts) < 0 && errno == EINTR) ;
57 SENF_AUTO_UNIT_TEST(clockService)
59 BOOST_CHECK( senf::ClockService::abstime(0).is_not_a_date_time());
61 char const * enabled (getenv("SENF_TIMING_CRITICAL_TESTS"));
62 BOOST_WARN_MESSAGE(enabled, "Set SENF_TIMING_CRITICAL_TESTS to not skip timing critical tests");
65 senf::ClockService::restart(); // So we know, when the signal will be delivered
67 senf::ClockService::clock_type t1 (senf::ClockService::now());
69 senf::ClockService::clock_type t2 (senf::ClockService::now());
71 BOOST_CHECK_PREDICATE( is_close_clock,
72 (t1 + senf::ClockService::milliseconds(200))
74 (senf::ClockService::milliseconds(100)) );
78 // Wait for SIGALRM and let the signal handler do the clock-skew detection
81 t2 = senf::ClockService::now();
83 BOOST_CHECK_PREDICATE( is_close_clock,
84 (t1 + senf::ClockService::seconds(1))
86 (senf::ClockService::milliseconds(500)) );
92 BOOST_CHECK_PREDICATE( is_close_clock,
93 (t1 + senf::ClockService::milliseconds(200))
94 (senf::ClockService::now())
95 (senf::ClockService::milliseconds(100)) );
97 // The next check validates that the clock service itimer/heartbeat_ is correctly reset after a
98 // clock-skew is detected
101 BOOST_CHECK_PREDICATE( is_close_clock,
102 (t1 + senf::ClockService::milliseconds(200))
103 (senf::ClockService::now())
104 (senf::ClockService::milliseconds(100)) );
107 ///////////////////////////////cc.e////////////////////////////////////////
114 // comment-column: 40
115 // c-file-style: "senf"
116 // indent-tabs-mode: nil
117 // ispell-local-dictionary: "american"
118 // compile-command: "scons -u test"