]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/stopwatches/test/stopwatch/simple_stopwatch_reporter_pass.cpp
Add patch for failing prerm scripts
[ceph.git] / ceph / src / boost / libs / chrono / stopwatches / test / stopwatch / simple_stopwatch_reporter_pass.cpp
1 // Copyright 2010-2011 Vicente J. Botet Escriba
2 // Copyright (c) Microsoft Corporation 2014
3 // Distributed under the Boost Software License, Version 1.0.
4 // See http://www.boost.org/LICENSE_1_0.txt
5
6 #define BOOST_CHRONO_VERSION 2
7
8 #include <iostream>
9 #include <boost/type_traits/is_same.hpp>
10 #include <boost/chrono/stopwatches/strict_stopwatch.hpp>
11 #include "../cycle_count.hpp"
12 #include <boost/chrono/stopwatches/reporters/stopwatch_reporter.hpp>
13 #include <boost/chrono/stopwatches/reporters/system_default_formatter.hpp>
14
15 #include <boost/chrono/chrono_io.hpp>
16 #include <boost/system/system_error.hpp>
17 #include <boost/detail/lightweight_test.hpp>
18
19 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
20 #define NOTHING ""
21 #endif
22
23 using namespace boost::chrono;
24
25
26 template <typename Reporter>
27 void check_invariants()
28 {
29 typedef Reporter Stopwatch;
30 BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::rep, typename Stopwatch::clock::duration::rep>::value), NOTHING, ());
31 BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::period, typename Stopwatch::clock::duration::period>::value), NOTHING, ());
32 BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::duration, typename Stopwatch::clock::time_point::duration>::value), NOTHING, ());
33 BOOST_CHRONO_STATIC_ASSERT(Stopwatch::is_steady == Stopwatch::clock::is_steady, NOTHING, ());
34 BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::stopwatch_type, strict_stopwatch<typename Stopwatch::clock> >::value), NOTHING, ());
35 }
36
37 template <typename Reporter>
38 void check_default_constructor()
39 {
40 Reporter _;
41 }
42
43 struct file_line {
44 file_line(const char* file, std::size_t line)
45 : fmt("%1%[%2%] Elapsed time:")
46 {
47 fmt % file % line;
48 }
49 ~file_line()
50 {
51 std::cout << fmt;
52 }
53 boost::format fmt;
54
55 };
56
57 template <typename Reporter>
58 void check_file_line2()
59 {
60 Reporter _("%1%\n");
61 file_line fl(__FILE__, __LINE__);
62 ex::sleep_for<typename Reporter::clock>(milliseconds(100));
63
64 }
65 template <typename Reporter>
66 void check_file_line()
67 {
68 Reporter rp("%1%[%2%] Elapsed time: %3%\n");
69 rp.format() % __FILE__ % __LINE__;
70
71 ex::sleep_for<typename Reporter::clock>(milliseconds(100));
72
73 }
74
75
76 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
77 template <typename Reporter>
78 void check_constructor_ec()
79 {
80 boost::system::error_code ec;
81 Reporter _(ec);
82 BOOST_TEST(ec.value()==0);
83 }
84
85 template <typename Reporter>
86 void check_constructor_throws()
87 {
88 Reporter _(boost::throws());
89 }
90 #endif
91
92 template <typename Reporter>
93 void check_elapsed(bool check=true)
94 {
95 Reporter sw;
96 ex::sleep_for<typename Reporter::clock>(milliseconds(100));
97 typename Reporter::duration d=sw.elapsed();
98 std::cout << d << std::endl;
99 if (check)
100 BOOST_TEST(d >= milliseconds(100));
101 }
102
103 template <typename Reporter>
104 void check_report()
105 {
106 Reporter sw;
107 ex::sleep_for<typename Reporter::clock>(milliseconds(100));
108 sw.report();
109 }
110
111 template <typename Clock>
112 void check_all(bool check=true)
113 {
114 typedef stopwatch_reporter<strict_stopwatch<Clock> > Reporter;
115 typedef stopwatch_reporter<strict_stopwatch<Clock>, elapsed_formatter > ReporterE;
116
117 check_invariants<Reporter>();
118 check_default_constructor<Reporter>();
119 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
120 check_constructor_ec<Reporter>();
121 check_constructor_throws<Reporter>();
122 #endif
123 check_elapsed<Reporter>(check);
124 check_report<Reporter>();
125 check_file_line<ReporterE>();
126 }
127
128 int main()
129 {
130 typedef strict_stopwatch<high_resolution_clock > Stopwatch;
131 typedef basic_stopwatch_reporter_default_formatter<char, Stopwatch>::type Formatter;
132 typedef stopwatch_reporter<Stopwatch> Reporter;
133 static Formatter fmtr;
134
135 Reporter _(fmtr);
136
137 check_all<ex::cycle_count<1500> >(true);
138
139 #if 0
140 std::cout << "high_resolution_clock=\n";
141
142 check_all<high_resolution_clock>();
143 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
144 std::cout << "steady_clock=\n";
145 check_all<steady_clock>(false);
146 #endif
147 std::cout << "system_clock=\n";
148 check_all<system_clock>(false);
149
150 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
151 std::cout << "thread_clock=\n";
152 check_all<thread_clock>(false);
153 #endif
154
155 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
156 std::cout << "process_real_cpu_clock=\n";
157 check_all<process_real_cpu_clock>(false);
158 #if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP
159 std::cout << "process_user_cpu_clock=\n";
160 check_all<process_user_cpu_clock>(false);
161 std::cout << "process_system_cpu_clock=\n";
162 check_all<process_system_cpu_clock>(false);
163 std::cout << "process_cpu_clock=\n";
164 check_all<process_cpu_clock>(false);
165 #endif
166 #endif
167 #endif
168
169 return boost::report_errors();
170 }