|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r65884 - in sandbox/chrono/libs/chrono: src/posix test test/clock test/clock/errored test/clock/hires test/clock/monotonic test/clock/process test/clock/system test/clock/thread
From: vicente.botet_at_[hidden]
Date: 2010-10-10 12:51:12
Author: viboes
Date: 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
New Revision: 65884
URL: http://svn.boost.org/trac/boost/changeset/65884
Log:
Chrono:
* Refactor compatibility with Boost.Systems system_category break
* Added more test with now error code
Added:
sandbox/chrono/libs/chrono/test/clock/errored/
sandbox/chrono/libs/chrono/test/clock/errored/consistency.pass.cpp (contents, props changed)
sandbox/chrono/libs/chrono/test/clock/errored/now.pass.cpp (contents, props changed)
sandbox/chrono/libs/chrono/test/clock/errored_clock.hpp (contents, props changed)
Text files modified:
sandbox/chrono/libs/chrono/src/posix/chrono.cpp | 24 ++++--------------------
sandbox/chrono/libs/chrono/test/Jamfile.v2 | 13 ++++++++-----
sandbox/chrono/libs/chrono/test/clock/check_clock_now.hpp | 35 +++++++++++++++++++++++++++++++++++
sandbox/chrono/libs/chrono/test/clock/hires/consistency.pass.cpp | 3 +--
sandbox/chrono/libs/chrono/test/clock/hires/now.pass.cpp | 5 +++--
sandbox/chrono/libs/chrono/test/clock/monotonic/consistency.pass.cpp | 30 +++---------------------------
sandbox/chrono/libs/chrono/test/clock/monotonic/now.pass.cpp | 24 ++++++------------------
sandbox/chrono/libs/chrono/test/clock/process/consistency.pass.cpp | 3 +--
sandbox/chrono/libs/chrono/test/clock/process/now.pass.cpp | 11 ++++++++++-
sandbox/chrono/libs/chrono/test/clock/system/consistency.pass.cpp | 31 +++----------------------------
sandbox/chrono/libs/chrono/test/clock/system/now.pass.cpp | 25 ++++++-------------------
sandbox/chrono/libs/chrono/test/clock/thread/consistency.pass.cpp | 3 +--
sandbox/chrono/libs/chrono/test/clock/thread/now.pass.cpp | 1 +
13 files changed, 82 insertions(+), 126 deletions(-)
Modified: sandbox/chrono/libs/chrono/src/posix/chrono.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/src/posix/chrono.cpp (original)
+++ sandbox/chrono/libs/chrono/src/posix/chrono.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -24,11 +24,7 @@
if ( ::clock_gettime( CLOCK_REALTIME, &ts ) )
{
boost::throw_exception(
-#if ((BOOST_VERSION / 100000) < 2) && ((BOOST_VERSION / 100 % 1000) < 44)
- system::system_error( errno, system::system_category, "chrono::system_clock" ));
-#else
- system::system_error( errno, system::system_category(), "chrono::system_clock" ));
-#endif
+ system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::system_clock" ));
}
return time_point(duration(
@@ -40,11 +36,7 @@
timespec ts;
if ( ::clock_gettime( CLOCK_REALTIME, &ts ) )
{
-#if ((BOOST_VERSION / 100000) < 2) && ((BOOST_VERSION / 100 % 1000) < 44)
- ec.assign( errno, system::system_category );
-#else
- ec.assign( errno, system::system_category() );
-#endif
+ ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
return time_point();
}
@@ -71,11 +63,7 @@
if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
{
boost::throw_exception(
-#if ((BOOST_VERSION / 100000) < 2) && ((BOOST_VERSION / 100 % 1000) < 44)
- system::system_error( errno, system::system_category, "chrono::monotonic_clock" ));
-#else
- system::system_error( errno, system::system_category(), "chrono::monotonic_clock" ));
-#endif
+ system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::monotonic_clock" ));
}
return time_point(duration(
@@ -87,11 +75,7 @@
timespec ts;
if ( ::clock_gettime( CLOCK_MONOTONIC, &ts ) )
{
-#if ((BOOST_VERSION / 100000) < 2) && ((BOOST_VERSION / 100 % 1000) < 44)
- ec.assign( errno, system::system_category );
-#else
- ec.assign( errno, system::system_category() );
-#endif
+ ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY );
return time_point();
}
Modified: sandbox/chrono/libs/chrono/test/Jamfile.v2
==============================================================================
--- sandbox/chrono/libs/chrono/test/Jamfile.v2 (original)
+++ sandbox/chrono/libs/chrono/test/Jamfile.v2 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -210,23 +210,26 @@
test-suite "clock"
:
- [ run clock/hires/consistency.pass.cpp : : : <link>static : clock.hires.consistency.pass ]
+ [ compile clock/hires/consistency.pass.cpp : : clock.hires.consistency.pass ]
[ run clock/hires/now.pass.cpp : : : <link>static : clock.hires.now.pass ]
- [ run clock/monotonic/consistency.pass.cpp : : : <link>static : clock.monotonic.consistency.pass ]
+ [ compile clock/monotonic/consistency.pass.cpp : : clock.monotonic.consistency.pass ]
[ run clock/monotonic/now.pass.cpp : : : <link>static : clock.monotonic.now.pass ]
- [ run clock/system/consistency.pass.cpp : : : <link>static : clock.system.consistency.pass ]
+ [ compile clock/system/consistency.pass.cpp : : clock.system.consistency.pass ]
[ run clock/system/now.pass.cpp : : : <link>static : clock.system.now.pass ]
[ run clock/system/from_time_t.pass.cpp : : : <link>static : clock.system.from_time_t.pass ]
[ run clock/system/rep_signed.pass.cpp : : : <link>static : clock.system.rep_signed.pass ]
[ run clock/system/to_time_t.pass.cpp : : : <link>static : clock.system.to_time_t.pass ]
- [ run clock/process/consistency.pass.cpp : : : <link>static : clock.process.consistency.pass ]
+ [ compile clock/process/consistency.pass.cpp : : clock.process.consistency.pass ]
[ run clock/process/now.pass.cpp : : : <link>static : clock.process.now.pass ]
- [ run clock/thread/consistency.pass.cpp : : : <link>static : clock.thread.consistency.pass ]
+ [ compile clock/thread/consistency.pass.cpp : : clock.thread.consistency.pass ]
[ run clock/thread/now.pass.cpp : : : <link>static : clock.thread.now.pass ]
+
+ [ compile clock/errored/consistency.pass.cpp : : clock.errored.consistency.pass ]
+ [ run clock/errored/now.pass.cpp : : : <link>static : clock.errored.now.pass ]
;
Modified: sandbox/chrono/libs/chrono/test/clock/check_clock_now.hpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/check_clock_now.hpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/check_clock_now.hpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -6,6 +6,8 @@
#define BOOST_CHRONO_CHECK_CLOCK_NOW_HPP
#include <boost/chrono.hpp>
+#include <boost/system/system_error.hpp>
+#include <boost/detail/lightweight_test.hpp>
template <typename Clock>
void check_clock_now()
@@ -13,4 +15,37 @@
typename Clock::time_point t1 = Clock::now();
}
+template <typename Clock>
+void check_clock_now_ec()
+{
+ boost::system::error_code ec;
+ typename Clock::time_point t1 = Clock::now(ec);
+ BOOST_TEST(ec.value()==0);
+}
+
+template <typename Clock>
+void check_clock_now_err(int err)
+{
+ Clock::set_errno(err);
+ try {
+ typename Clock::time_point t1 = Clock::now();
+ } catch (boost::system::system_error& ex) {
+ BOOST_TEST(ex.code().value()==err);
+// BOOST_TEST(ex.code().category() == BOOST_CHRONO_SYSTEM_CATEGORY);
+// BOOST_TEST(std::string(ex.what()) == std::string("errored_clock"));
+ }
+ Clock::set_errno(0);
+}
+
+template <typename Clock>
+void check_clock_now_ec_err(int err)
+{
+ Clock::set_errno(err);
+ boost::system::error_code ec;
+ typename Clock::time_point t1 = Clock::now(ec);
+ BOOST_TEST(ec.value()==err);
+// BOOST_TEST(ec.category() == BOOST_CHRONO_SYSTEM_CATEGORY);
+ Clock::set_errno(0);
+}
+
#endif
Added: sandbox/chrono/libs/chrono/test/clock/errored/consistency.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/clock/errored/consistency.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -0,0 +1,12 @@
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+//#include <boost/chrono.hpp>
+#include "../errored_clock.hpp"
+#include <libs/chrono/test/clock/check_clock_invariants.hpp>
+
+void test()
+{
+ check_clock_invariants<errored_clock>();
+}
Added: sandbox/chrono/libs/chrono/test/clock/errored/now.pass.cpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/clock/errored/now.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -0,0 +1,15 @@
+// Copyright 2010 Vicente J. Botet Escriba
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#include "../errored_clock.hpp"
+#include "../check_clock_now.hpp"
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+{
+ check_clock_now_err<errored_clock>(1);
+ check_clock_now_ec_err<errored_clock>(1);
+
+ return boost::report_errors();
+}
Added: sandbox/chrono/libs/chrono/test/clock/errored_clock.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/test/clock/errored_clock.hpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -0,0 +1,52 @@
+// chrono.hpp --------------------------------------------------------------//
+
+// Copyright 2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+#ifndef BOOST_CHRONO_SYSTEM_CLOCKS_HPP
+#define BOOST_CHRONO_SYSTEM_CLOCKS_HPP
+
+#include <boost/chrono/config.hpp>
+#include <boost/chrono/duration.hpp>
+#include <boost/chrono/time_point.hpp>
+#include <boost/system/error_code.hpp>
+#include <boost/system/system_error.hpp>
+#include <boost/throw_exception.hpp>
+#include <boost/chrono/detail/system.hpp>
+
+ class errored_clock
+ {
+ public:
+ typedef boost::chrono::nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef boost::chrono::time_point<errored_clock> time_point;
+ static const bool is_monotonic = true;
+ static int errno_;
+
+ static void set_errno(int err) {
+ errno_=err;
+ }
+
+ // throws on error
+ static time_point now() {
+ boost::throw_exception(
+ boost::system::system_error(
+ errno_,
+ BOOST_CHRONO_SYSTEM_CATEGORY,
+ "errored_clock"
+ )
+ );
+ return time_point();
+ }
+ // never throws and set ec
+ static time_point now(boost::system::error_code & ec) {
+ ec.assign( errno_, BOOST_CHRONO_SYSTEM_CATEGORY );
+ return time_point();
+ };
+ };
+ int errored_clock::errno_;
+
+#endif
Modified: sandbox/chrono/libs/chrono/test/clock/hires/consistency.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/hires/consistency.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/hires/consistency.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -5,8 +5,7 @@
#include <boost/chrono.hpp>
#include <libs/chrono/test/clock/check_clock_invariants.hpp>
-int main()
+void test()
{
check_clock_invariants<boost::chrono::high_resolution_clock>();
- return 0;
}
Modified: sandbox/chrono/libs/chrono/test/clock/hires/now.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/hires/now.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/hires/now.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -3,11 +3,12 @@
// See http://www.boost.org/LICENSE_1_0.txt
#include <boost/chrono.hpp>
-//#include <libs/chrono/test/clock/check_clock_now.hpp>
#include "../check_clock_now.hpp"
+#include <boost/detail/lightweight_test.hpp>
int main()
{
check_clock_now<boost::chrono::high_resolution_clock>();
- return 0;
+ check_clock_now_ec<boost::chrono::high_resolution_clock>();
+ return boost::report_errors();
}
Modified: sandbox/chrono/libs/chrono/test/clock/monotonic/consistency.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/monotonic/consistency.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/monotonic/consistency.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -2,36 +2,12 @@
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
-// Adapted from llvm/libcxx/test/utilities/chrono
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <chrono>
-
-// monotonic_clock
-
-// check clock invariants
-
#include <boost/chrono.hpp>
-#include <boost/type_traits/is_same.hpp>
-#if !defined(BOOST_NO_STATIC_ASSERT)
-#define NOTHING ""
-#endif
+#include <libs/chrono/test/clock/check_clock_invariants.hpp>
-int main()
+void test()
{
#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::monotonic_clock C;
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<C::rep, C::duration::rep>::value), NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<C::period, C::duration::period>::value), NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<C::duration, C::time_point::duration>::value), NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT(C::is_monotonic, NOTHING, ());
+ check_clock_invariants<boost::chrono::monotonic_clock>();
#endif
- return 0;
}
Modified: sandbox/chrono/libs/chrono/test/clock/monotonic/now.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/monotonic/now.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/monotonic/now.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -2,32 +2,20 @@
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
-// Adapted from llvm/libcxx/test/utilities/chrono
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <chrono>
-
// monotonic_clock
// static time_point now();
#include <boost/chrono.hpp>
-#include <cassert>
+#include "../check_clock_now.hpp"
+#include <boost/detail/lightweight_test.hpp>
int main()
{
#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::monotonic_clock C;
- C::time_point t1 = C::now();
- C::time_point t2 = C::now();
- assert(t2 >= t1);
+ check_clock_now<boost::chrono::high_resolution_clock>();
+ check_clock_now_ec<boost::chrono::high_resolution_clock>();
#endif
- return 0;
+ return boost::report_errors();
}
+
Modified: sandbox/chrono/libs/chrono/test/clock/process/consistency.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/process/consistency.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/process/consistency.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -6,11 +6,10 @@
#include <boost/chrono/process_cpu_clocks.hpp>
#include "../check_clock_invariants.hpp"
-int main()
+void test()
{
check_clock_invariants<boost::chrono::process_real_cpu_clock>();
check_clock_invariants<boost::chrono::process_user_cpu_clock>();
check_clock_invariants<boost::chrono::process_system_cpu_clock>();
check_clock_invariants<boost::chrono::process_cpu_clock>();
- return 0;
}
Modified: sandbox/chrono/libs/chrono/test/clock/process/now.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/process/now.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/process/now.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -5,12 +5,21 @@
#include "../check_clock_now.hpp"
#include <boost/chrono/process_cpu_clocks.hpp>
#include <boost/chrono.hpp>
+#include <boost/detail/lightweight_test.hpp>
int main()
{
check_clock_now<boost::chrono::process_real_cpu_clock>();
+ check_clock_now_ec<boost::chrono::process_real_cpu_clock>();
+
check_clock_now<boost::chrono::process_user_cpu_clock>();
+ check_clock_now_ec<boost::chrono::process_user_cpu_clock>();
+
check_clock_now<boost::chrono::process_system_cpu_clock>();
+ check_clock_now_ec<boost::chrono::process_system_cpu_clock>();
+
check_clock_now<boost::chrono::process_cpu_clock>();
- return 0;
+ check_clock_now_ec<boost::chrono::process_cpu_clock>();
+
+ return boost::report_errors();
}
Modified: sandbox/chrono/libs/chrono/test/clock/system/consistency.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/system/consistency.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/system/consistency.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -2,35 +2,10 @@
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
-// Adapted from llvm/libcxx/test/utilities/chrono
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <chrono>
-
-// system_clock
-
-// check clock invariants
-
#include <boost/chrono.hpp>
-#include <boost/type_traits/is_same.hpp>
-#if !defined(BOOST_NO_STATIC_ASSERT)
-#define NOTHING ""
-#endif
+#include <libs/chrono/test/clock/check_clock_invariants.hpp>
-int main()
+void test()
{
- typedef boost::chrono::system_clock C;
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<C::rep, C::duration::rep>::value), NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<C::period, C::duration::period>::value), NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<C::duration, C::time_point::duration>::value), NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT((boost::is_same<C::time_point::clock, C>::value), NOTHING, ());
- BOOST_CHRONO_STATIC_ASSERT((C::is_monotonic || !C::is_monotonic), NOTHING, ());
- return 0;
+ check_clock_invariants<boost::chrono::system_clock>();
}
Modified: sandbox/chrono/libs/chrono/test/clock/system/now.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/system/now.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/system/now.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -2,27 +2,14 @@
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
-// Adapted from llvm/libcxx/test/utilities/chrono
-//===----------------------------------------------------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-// <chrono>
-
-// system_clock
-
-// static time_point now();
-
#include <boost/chrono.hpp>
+#include "../check_clock_now.hpp"
+#include <boost/detail/lightweight_test.hpp>
int main()
{
- typedef boost::chrono::system_clock C;
- C::time_point t1 = C::now();
- return 0;
+ check_clock_now<boost::chrono::system_clock>();
+ check_clock_now_ec<boost::chrono::system_clock>();
+
+ return boost::report_errors();
}
Modified: sandbox/chrono/libs/chrono/test/clock/thread/consistency.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/thread/consistency.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/thread/consistency.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -6,10 +6,9 @@
#include <boost/chrono/thread_clock.hpp>
#include "../check_clock_invariants.hpp"
-int main()
+void test()
{
#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
check_clock_invariants<boost::chrono::thread_clock>();
#endif
- return 0;
}
Modified: sandbox/chrono/libs/chrono/test/clock/thread/now.pass.cpp
==============================================================================
--- sandbox/chrono/libs/chrono/test/clock/thread/now.pass.cpp (original)
+++ sandbox/chrono/libs/chrono/test/clock/thread/now.pass.cpp 2010-10-10 12:51:09 EDT (Sun, 10 Oct 2010)
@@ -6,6 +6,7 @@
#include "../check_clock_now.hpp"
#include <boost/chrono/thread_clock.hpp>
#include <boost/chrono.hpp>
+#include <boost/detail/lightweight_test.hpp>
int main()
{
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk