From 169311e02034743714eb58f35d1c126ceafeb710 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Mon, 13 Nov 2023 20:24:21 +0100 Subject: [PATCH] #2154: Use std::chrono for TimeType --- src/vt/elm/elm_lb_data.cc | 2 +- src/vt/elm/elm_lb_data.h | 2 +- src/vt/event/event_record.h | 2 +- src/vt/messaging/active.cc | 8 +- src/vt/messaging/request_holder.h | 2 +- src/vt/runtime/component/diagnostic.impl.h | 4 +- src/vt/runtime/component/diagnostic_value.h | 11 +- src/vt/runtime/component/meter/timer.h | 6 +- src/vt/scheduler/scheduler.h | 4 +- src/vt/timetrigger/trigger.h | 5 +- src/vt/timing/timing.h | 2 +- src/vt/timing/timing_type.h | 122 +++++++----------- src/vt/trace/trace_lite.h | 4 +- src/vt/trace/trace_log.h | 4 +- src/vt/trace/trace_user.h | 10 +- src/vt/vrt/collection/balance/baselb/baselb.h | 6 +- .../balance/hierarchicallb/hierlb.cc | 6 +- .../balance/hierarchicallb/hierlb.h | 2 +- .../test_scheduler_progress.extended.cc | 4 +- .../unit/scheduler/test_scheduler_timings.cc | 6 +- .../timetrigger/test_time_trigger.extended.cc | 24 ++-- 21 files changed, 106 insertions(+), 130 deletions(-) diff --git a/src/vt/elm/elm_lb_data.cc b/src/vt/elm/elm_lb_data.cc index 71796b3b60..2538c5931c 100644 --- a/src/vt/elm/elm_lb_data.cc +++ b/src/vt/elm/elm_lb_data.cc @@ -69,7 +69,7 @@ void ElementLBData::stop(TimeType time) { auto const started = cur_time_started_; if (started) { cur_time_started_ = false; - addTime(total_time.seconds()); + addTime(total_time.seconds().count()); } vt_debug_print( diff --git a/src/vt/elm/elm_lb_data.h b/src/vt/elm/elm_lb_data.h index 01b6c4c8b6..c65fe39d59 100644 --- a/src/vt/elm/elm_lb_data.h +++ b/src/vt/elm/elm_lb_data.h @@ -129,7 +129,7 @@ struct ElementLBData { protected: bool cur_time_started_ = false; - TimeType cur_time_ = TimeType{0.0}; + TimeType cur_time_ = TimeType{}; PhaseType cur_phase_ = fst_lb_phase; std::unordered_map phase_timings_ = {}; std::unordered_map phase_comm_ = {}; diff --git a/src/vt/event/event_record.h b/src/vt/event/event_record.h index 84ba9ea012..76953bea85 100644 --- a/src/vt/event/event_record.h +++ b/src/vt/event/event_record.h @@ -138,7 +138,7 @@ struct EventRecord { # if vt_check_enabled(diagnostics) /// the time this event record was created - TimeType creation_time_stamp_ = TimeType{0.}; + TimeType creation_time_stamp_ = TimeType{}; # endif }; diff --git a/src/vt/messaging/active.cc b/src/vt/messaging/active.cc index 02f3f61753..8f2bf44f73 100644 --- a/src/vt/messaging/active.cc +++ b/src/vt/messaging/active.cc @@ -349,7 +349,7 @@ EventType ActiveMessenger::sendMsgMPI( { VT_ALLOW_MPI_CALLS; #if vt_check_enabled(trace_enabled) - auto tr_begin = TimeType{0.}; + auto tr_begin = TimeType{}; if (theConfig()->vt_trace_mpi) { tr_begin = vt::timing::getCurrentTime(); } @@ -581,7 +581,7 @@ std::tuple ActiveMessenger::sendDataMPI( ); { #if vt_check_enabled(trace_enabled) - auto tr_begin = TimeType{0.}; + auto tr_begin = TimeType{}; if (theConfig()->vt_trace_mpi) { tr_begin = vt::timing::getCurrentTime(); } @@ -771,7 +771,7 @@ void ActiveMessenger::recvDataDirect( ); #if vt_check_enabled(trace_enabled) - auto tr_begin = TimeType{0.}; + auto tr_begin = TimeType{}; if (theConfig()->vt_trace_mpi) { tr_begin = vt::timing::getCurrentTime(); } @@ -1008,7 +1008,7 @@ bool ActiveMessenger::tryProcessIncomingActiveMsg() { { #if vt_check_enabled(trace_enabled) - auto tr_begin = TimeType{0.}; + auto tr_begin = TimeType{}; if (theConfig()->vt_trace_mpi) { tr_begin = vt::timing::getCurrentTime(); } diff --git a/src/vt/messaging/request_holder.h b/src/vt/messaging/request_holder.h index bf48e5b098..6a8e22b331 100644 --- a/src/vt/messaging/request_holder.h +++ b/src/vt/messaging/request_holder.h @@ -98,7 +98,7 @@ struct RequestHolder { bool testAll(Callable c, int& num_mpi_tests) { # if vt_check_enabled(trace_enabled) std::size_t const holder_size_start = holder_.size(); - auto tr_begin = TimeType{0.0}; + auto tr_begin = TimeType{}; if (theConfig()->vt_trace_irecv_polling) { tr_begin = vt::timing::getCurrentTime(); } diff --git a/src/vt/runtime/component/diagnostic.impl.h b/src/vt/runtime/component/diagnostic.impl.h index 77fd279b53..37155aed25 100644 --- a/src/vt/runtime/component/diagnostic.impl.h +++ b/src/vt/runtime/component/diagnostic.impl.h @@ -93,7 +93,7 @@ meter::Timer Diagnostic::registerTimerT( ) { auto sum = registerDiagnostic( key + " [sum]", desc, DiagnosticUpdate::Sum, unit, - DiagnosticTypeEnum::PerformanceDiagnostic, T{0} + DiagnosticTypeEnum::PerformanceDiagnostic, T{} ); auto min = registerDiagnostic( key + " [min]", desc, DiagnosticUpdate::Min, unit, @@ -105,7 +105,7 @@ meter::Timer Diagnostic::registerTimerT( ); auto avg = registerDiagnostic( key + " [avg]", desc, DiagnosticUpdate::Avg, unit, - DiagnosticTypeEnum::PerformanceDiagnostic, T{0} + DiagnosticTypeEnum::PerformanceDiagnostic, T{} ); return meter::Timer{sum, avg, max, min}; } diff --git a/src/vt/runtime/component/diagnostic_value.h b/src/vt/runtime/component/diagnostic_value.h index 3e8eef2e8c..ee4e9f157d 100644 --- a/src/vt/runtime/component/diagnostic_value.h +++ b/src/vt/runtime/component/diagnostic_value.h @@ -168,7 +168,7 @@ struct DiagnosticValueWrapper { * * \return the max value */ - T max() const { return N_ == 0 ? T{0} : max_; } + T max() const { return N_ == 0 ? T{} : max_; } /** * \internal \brief Get sum of values (use after reduction) @@ -182,7 +182,7 @@ struct DiagnosticValueWrapper { * * \return the min value */ - T min() const { return N_ == 0 ? T{0} : min_; } + T min() const { return N_ == 0 ? T{} : min_; } /** * \internal \brief Get the arithmetic mean value (use after reduction) @@ -237,7 +237,12 @@ struct DiagnosticValueWrapper { */ T getComputedValue() const { if (N_ > 0) { - return value_ / N_; + // silence nvcc warning + if constexpr (std::is_same_v) { + return value_ / N_; + } else { + return value_ / static_cast(N_); + } } else { return value_; } diff --git a/src/vt/runtime/component/meter/timer.h b/src/vt/runtime/component/meter/timer.h index f5dc220980..fb2a135deb 100644 --- a/src/vt/runtime/component/meter/timer.h +++ b/src/vt/runtime/component/meter/timer.h @@ -102,9 +102,9 @@ struct Timer : DiagnosticStatsPack { * \brief Stop the timer and record the interval */ void stop() { - if (start_time_ != TimeType{0.}) { + if (start_time_ != TimeType{}) { update(start_time_, timing::getCurrentTime()); - start_time_ = TimeType{0.}; + start_time_ = TimeType{}; } } @@ -116,7 +116,7 @@ struct Timer : DiagnosticStatsPack { } private: - T start_time_ = T{0}; + T start_time_ = T{}; }; }}}} /* end namespace vt::runtime::component::meter */ diff --git a/src/vt/scheduler/scheduler.h b/src/vt/scheduler/scheduler.h index 85fbb2a58f..160506e968 100644 --- a/src/vt/scheduler/scheduler.h +++ b/src/vt/scheduler/scheduler.h @@ -178,7 +178,7 @@ struct Scheduler : runtime::component::Component { * * \param[in] current_time current time */ - void runProgress(bool msg_only = false, TimeType current_time = TimeType{0.0} ); + void runProgress(bool msg_only = false, TimeType current_time = TimeType{} ); /** * \brief Runs the scheduler until a condition is met. @@ -438,7 +438,7 @@ struct Scheduler : runtime::component::Component { EventTriggerContType event_triggers; EventTriggerContType event_triggers_once; - TimeType last_progress_time_ = TimeType{0.0}; + TimeType last_progress_time_ = TimeType{}; bool progress_time_enabled_ = false; int32_t processed_after_last_progress_ = 0; diff --git a/src/vt/timetrigger/trigger.h b/src/vt/timetrigger/trigger.h index ebc5a947de..6bdbb322ed 100644 --- a/src/vt/timetrigger/trigger.h +++ b/src/vt/timetrigger/trigger.h @@ -85,8 +85,7 @@ struct Trigger { * \return the next time this should be triggered */ TimeType nextTriggerTime() const { - return TimeType{ - (last_trigger_time_.milliseconds() + period_.count()) / 1000.0}; + return TimeType{last_trigger_time_.milliseconds() + period_}; } /** @@ -142,7 +141,7 @@ struct Trigger { private: std::chrono::milliseconds period_; /**< The trigger's period */ ActionType trigger_ = nullptr; /**< The action to trigger */ - TimeType last_trigger_time_ = TimeType{0.}; /**< The last time it was triggered */ + TimeType last_trigger_time_ = TimeType{}; /**< The last time it was triggered */ int id_ = -1; /**< The trigger's id */ }; diff --git a/src/vt/timing/timing.h b/src/vt/timing/timing.h index 59679e6888..a7d485e4dd 100644 --- a/src/vt/timing/timing.h +++ b/src/vt/timing/timing.h @@ -76,7 +76,7 @@ struct formatter<::vt::TimeTypeWrapper> { auto format(::vt::TimeTypeWrapper const& t, FormatContext& ctx) const { return fmt::format_to( ctx.out(), "{}", - to_engineering_string(t.seconds(), 5, eng_exponential, "s") + to_engineering_string(t.seconds().count(), 5, eng_exponential, "s") ); } }; diff --git a/src/vt/timing/timing_type.h b/src/vt/timing/timing_type.h index 8dc16c0922..2ad0ba7ba9 100644 --- a/src/vt/timing/timing_type.h +++ b/src/vt/timing/timing_type.h @@ -44,7 +44,7 @@ #if !defined INCLUDED_VT_TIMING_TIMING_TYPE_H #define INCLUDED_VT_TIMING_TIMING_TYPE_H -#include +#include #include #include @@ -52,10 +52,34 @@ namespace vt { struct TimeTypeWrapper { using TimeTypeInternal = double; - explicit constexpr TimeTypeWrapper(const TimeTypeInternal time = 0.0) - : time_(time) { } - explicit operator double() const { return time_; } + using Seconds = std::chrono::duration; + using Milliseconds = std::chrono::duration; + using Microseconds = std::chrono::duration; + + template + explicit TimeTypeWrapper( + T time, + typename std::enable_if< + std::is_integral::value || std::is_floating_point::value>::type* = + nullptr) + : time_(Seconds(static_cast(time))) { } + + template + explicit TimeTypeWrapper( + const std::chrono::duration& time = + std::chrono::duration(0)) + : time_(std::chrono::duration_cast(time)) { } + + template + explicit TimeTypeWrapper(const std::chrono::duration& time) + : time_(std::chrono::duration_cast(time)) { } + + template + explicit TimeTypeWrapper(const Seconds& time) + : time_(std::chrono::duration_cast(time)) { } + + explicit operator TimeTypeInternal() const { return time_.count(); } TimeTypeWrapper& operator+=(const TimeTypeWrapper& other) { time_ += other.time_; @@ -67,14 +91,9 @@ struct TimeTypeWrapper { return *this; } - TimeTypeWrapper& operator*=(const double scalar) { - time_ *= scalar; - return *this; - } - - TimeTypeWrapper& operator/=(const double scalar) { - time_ /= scalar; - return *this; + friend TimeTypeWrapper + operator/(const TimeTypeWrapper& lhs, const TimeTypeWrapper& rhs) { + return TimeTypeWrapper{lhs.time_ / rhs.time_}; } friend TimeTypeWrapper @@ -87,36 +106,6 @@ struct TimeTypeWrapper { return TimeTypeWrapper(lhs.time_ - rhs.time_); } - friend TimeTypeWrapper - operator*(const TimeTypeWrapper& lhs, const TimeTypeWrapper& rhs) { - return TimeTypeWrapper(lhs.time_ * rhs.time_); - } - - friend TimeTypeWrapper - operator*(const TimeTypeWrapper& time, const double scalar) { - return TimeTypeWrapper(time.time_ * scalar); - } - - friend TimeTypeWrapper - operator*(const double scalar, const TimeTypeWrapper& time) { - return TimeTypeWrapper(time.time_ * scalar); - } - - friend TimeTypeWrapper - operator/(const double scalar, const TimeTypeWrapper& time) { - return TimeTypeWrapper(scalar / time.time_); - } - - friend TimeTypeWrapper - operator/(const TimeTypeWrapper& time, const double scalar) { - return TimeTypeWrapper(time.time_ / scalar); - } - - friend TimeTypeWrapper - operator/(const TimeTypeWrapper& lhs, const TimeTypeWrapper& rhs) { - return TimeTypeWrapper(lhs.time_ / rhs.time_); - } - friend bool operator<(const TimeTypeWrapper& lhs, const TimeTypeWrapper& rhs) { return lhs.time_ < rhs.time_; @@ -147,13 +136,22 @@ struct TimeTypeWrapper { return lhs.time_ != rhs.time_; } - friend TimeTypeWrapper sqrt(const TimeTypeWrapper& time) { - return TimeTypeWrapper{std::sqrt(time.time_)}; + template + std::chrono::duration seconds() const { + return std::chrono::duration_cast>(time_); } - TimeTypeInternal seconds() const { return time_; } - TimeTypeInternal milliseconds() const { return time_ * 1000; } - TimeTypeInternal microseconds() const { return time_ * 1000000; } + template + std::chrono::duration milliseconds() const { + return std::chrono::duration_cast>( + time_); + } + + template + std::chrono::duration microseconds() const { + return std::chrono::duration_cast>( + time_); + } template void serialize(Serializer& s) { @@ -161,37 +159,11 @@ struct TimeTypeWrapper { } private: - TimeTypeInternal time_; + std::chrono::duration time_; }; using TimeType = TimeTypeWrapper; } /* end namespace vt */ -namespace std { -template <> -class numeric_limits { - using Type = typename vt::TimeTypeWrapper::TimeTypeInternal; - -public: - static constexpr vt::TimeTypeWrapper max() noexcept { - return vt::TimeTypeWrapper(std::numeric_limits::max()); - } - - static constexpr vt::TimeTypeWrapper lowest() noexcept { - return vt::TimeTypeWrapper(std::numeric_limits::lowest()); - } - - inline vt::TimeTypeWrapper - min(const vt::TimeTypeWrapper& lhs, const vt::TimeTypeWrapper& rhs) { - return vt::TimeTypeWrapper(std::min(lhs.seconds(), rhs.seconds())); - } - - inline vt::TimeTypeWrapper - max(const vt::TimeTypeWrapper& lhs, const vt::TimeTypeWrapper& rhs) { - return vt::TimeTypeWrapper(std::max(lhs.seconds(), rhs.seconds())); - } -}; -} // namespace std - -#endif /*INCLUDED_VT_TIMING_TIMING_TYPE_H*/ +#endif // INCLUDED_VT_TIMING_TIMING_TYPE_H diff --git a/src/vt/trace/trace_lite.h b/src/vt/trace/trace_lite.h index e1d53a4316..3e9a2141dc 100644 --- a/src/vt/trace/trace_lite.h +++ b/src/vt/trace/trace_lite.h @@ -249,7 +249,7 @@ struct TraceLite { * \return time in microsecond as integer */ static inline TimeIntegerType timeToMicros(TimeType const time) { - return time.microseconds(); + return time.microseconds().count(); } /** @@ -385,7 +385,7 @@ struct TraceLite { TraceEventIDType cur_event_ = 1; UserEventIDType flush_event_ = no_user_event_id; bool enabled_ = true; - TimeType start_time_ = TimeType{0.0}; + TimeType start_time_ = TimeType{}; std::string prog_name_ = ""; std::string trace_name_ = ""; std::string full_trace_name_ = ""; diff --git a/src/vt/trace/trace_log.h b/src/vt/trace/trace_log.h index 1b8443f700..51837fbc17 100644 --- a/src/vt/trace/trace_log.h +++ b/src/vt/trace/trace_log.h @@ -351,10 +351,10 @@ struct Log final { // Excluding sys/user-specific data, expected ~24 bytes // Time of the event - all events need a time. - TimeType time = TimeType{0.0}; + TimeType time = TimeType{}; // If a duration can be expressed in a single event. // (Currently only for user-events.. could elim explicit end events.) - TimeType end_time = TimeType{0.0}; + TimeType end_time = TimeType{}; TraceConstantsType type = TraceConstantsType::InvalidTraceType; TraceEntryIDType ep = no_trace_entry_id; diff --git a/src/vt/trace/trace_user.h b/src/vt/trace/trace_user.h index a9aa2a8d3e..512357e204 100644 --- a/src/vt/trace/trace_user.h +++ b/src/vt/trace/trace_user.h @@ -193,7 +193,7 @@ struct TraceScopedEventHash final { } private: - TimeType begin_ = TimeType{0.0}; + TimeType begin_ = TimeType{}; std::string str_ = ""; UserEventIDType event_ = no_user_event_id; }; @@ -215,7 +215,7 @@ struct TraceScopedEvent final { * \c registerEventCollective ) */ explicit TraceScopedEvent(UserEventIDType event) - : begin_(event != no_user_event_id ? TraceLite::getCurrentTime() : TimeType{0.}), + : begin_(event != no_user_event_id ? TraceLite::getCurrentTime() : TimeType{}), event_(event) { } @@ -249,7 +249,7 @@ struct TraceScopedEvent final { } private: - TimeType begin_ = TimeType{0.0}; + TimeType begin_ = TimeType{}; UserEventIDType event_ = no_user_event_id; }; @@ -272,7 +272,7 @@ struct TraceScopedNote final { */ TraceScopedNote( std::string const& in_note, TraceEventIDType const in_event = no_trace_event - ) : begin_(in_event != no_trace_event ? TraceLite::getCurrentTime() : TimeType{0.}), + ) : begin_(in_event != no_trace_event ? TraceLite::getCurrentTime() : TimeType{}), event_(in_event), note_(in_note) { } @@ -313,7 +313,7 @@ struct TraceScopedNote final { } private: - TimeType begin_ = TimeType{0.0}; + TimeType begin_ = TimeType{}; TraceEventIDType event_ = no_trace_event; std::string note_ = ""; }; diff --git a/src/vt/vrt/collection/balance/baselb/baselb.h b/src/vt/vrt/collection/balance/baselb/baselb.h index 9c6cd27b63..9664df7170 100644 --- a/src/vt/vrt/collection/balance/baselb/baselb.h +++ b/src/vt/vrt/collection/balance/baselb/baselb.h @@ -134,6 +134,8 @@ struct BaseLB { balance::DataMapType const& in_data_map ); + static LoadType loadMilli(LoadType const& load); + void notifyCurrentHostNodeOfObjectsDeparting( TransferMsg* msg ); @@ -141,8 +143,6 @@ struct BaseLB { TransferMsg* msg ); - LoadType loadMilli(LoadType const& load); - void applyMigrations( TransferVecType const& transfers, MigrationCountCB migration_count_callback ); @@ -167,7 +167,7 @@ struct BaseLB { protected: void getArgs(PhaseType phase); - TimeType start_time_ = TimeType{0.0}; + TimeType start_time_ = TimeType{}; ElementCommType const* comm_data = nullptr; objgroup::proxy::Proxy proxy_ = {}; PhaseType phase_ = 0; diff --git a/src/vt/vrt/collection/balance/hierarchicallb/hierlb.cc b/src/vt/vrt/collection/balance/hierarchicallb/hierlb.cc index 9eab2a25fe..2bd27f3b79 100644 --- a/src/vt/vrt/collection/balance/hierarchicallb/hierlb.cc +++ b/src/vt/vrt/collection/balance/hierarchicallb/hierlb.cc @@ -154,7 +154,7 @@ void HierarchicalLB::inputParams(balance::ConfigEntry* config) { } } -void HierarchicalLB::setupTree(TimeType const threshold) { +void HierarchicalLB::setupTree(LoadType const threshold) { vtAssert( tree_setup == false, "Tree must not already be set up when is this called" @@ -163,7 +163,7 @@ void HierarchicalLB::setupTree(TimeType const threshold) { auto const& this_node = theContext()->getNode(); auto const& num_nodes = theContext()->getNumNodes(); - this_threshold = threshold.seconds(); + this_threshold = threshold; vt_debug_print( terse, hierlb, @@ -794,7 +794,7 @@ void HierarchicalLB::clearObj(ObjSampleType& objs) { void HierarchicalLB::runLB(LoadType total_load) { this_load = loadMilli(total_load); buildHistogram(); - setupTree(TimeType{min_threshold}); + setupTree(min_threshold); proxy.allreduce<&HierarchicalLB::setupDone>(); } diff --git a/src/vt/vrt/collection/balance/hierarchicallb/hierlb.h b/src/vt/vrt/collection/balance/hierarchicallb/hierlb.h index eb1ec66eb6..55ef4156fd 100644 --- a/src/vt/vrt/collection/balance/hierarchicallb/hierlb.h +++ b/src/vt/vrt/collection/balance/hierarchicallb/hierlb.h @@ -77,7 +77,7 @@ struct HierarchicalLB : LoadSamplerBaseLB { static std::unordered_map getInputKeysWithHelp(); - void setupTree(TimeType const threshold); + void setupTree(LoadType const threshold); void calcLoadOver(HeapExtractEnum const extract); void loadOverBin(ObjBinType bin, ObjBinListType& bin_list); void procDataIn(ElementLoadType const& data_in); diff --git a/tests/unit/scheduler/test_scheduler_progress.extended.cc b/tests/unit/scheduler/test_scheduler_progress.extended.cc index 100fe98488..3f5ae09040 100644 --- a/tests/unit/scheduler/test_scheduler_progress.extended.cc +++ b/tests/unit/scheduler/test_scheduler_progress.extended.cc @@ -86,7 +86,7 @@ TEST_F(TestSchedProgress, test_scheduler_progress_1) { // This ought to take close to a second EXPECT_GT( - TimeType{vt::timing::getCurrentTime() - cur_time}.seconds(), + TimeType{vt::timing::getCurrentTime() - cur_time}.seconds().count(), vt::theConfig()->vt_sched_progress_sec * fudge ); @@ -125,7 +125,7 @@ TEST_F(TestSchedProgress, test_scheduler_progress_2) { // This ought to take close to a second EXPECT_GT( - (vt::timing::getCurrentTime() - cur_time).seconds(), + (vt::timing::getCurrentTime() - cur_time).seconds().count(), vt::theConfig()->vt_sched_progress_sec * fudge ); diff --git a/tests/unit/scheduler/test_scheduler_timings.cc b/tests/unit/scheduler/test_scheduler_timings.cc index 2d61d49cce..ecd5f00460 100644 --- a/tests/unit/scheduler/test_scheduler_timings.cc +++ b/tests/unit/scheduler/test_scheduler_timings.cc @@ -132,11 +132,11 @@ TEST_F(TestSchedTimings, test_sched_msg) { sched->runSchedulerWhile([&]{ return count < num_iter; }); double const fudge = 0.8; - auto observed_time = 1000.0 *(vt::timing::getCurrentTime() - start_time); + auto observed_time = vt::timing::getCurrentTime() - start_time; // This ought to take close to a second (with ms_delay = 100) EXPECT_GT( - observed_time.seconds(), + observed_time.seconds().count(), vt::theConfig()->vt_sched_progress_sec * fudge ); @@ -144,7 +144,7 @@ TEST_F(TestSchedTimings, test_sched_msg) { fmt::print("expected time={}, observed time={}\n", sum_time, observed_time); //double margin =30+ sum_time*0.2; //EXPECT_NEAR(sum_time, observed_time, margin ); - EXPECT_GT(observed_time.seconds(), sum_time); + EXPECT_GT(observed_time.milliseconds().count(), sum_time); } diff --git a/tests/unit/timetrigger/test_time_trigger.extended.cc b/tests/unit/timetrigger/test_time_trigger.extended.cc index 8f804c1183..df7c2b18ab 100644 --- a/tests/unit/timetrigger/test_time_trigger.extended.cc +++ b/tests/unit/timetrigger/test_time_trigger.extended.cc @@ -59,34 +59,34 @@ TEST_F(TestTimeTrigger, test_time_trigger) { using namespace std::chrono; using namespace std::chrono_literals; - auto trigger_period_ms = 100ms; - auto trigger_period_s = duration(trigger_period_ms).count(); + auto trigger_period_ms = TimeType{100ms}; + auto trigger_period_s = trigger_period_ms.seconds(); int trigger_id = 42; int triggered = 0; - vt::timetrigger::Trigger trigger{trigger_period_ms, [&triggered](){ + vt::timetrigger::Trigger trigger{trigger_period_ms.milliseconds(), [&triggered](){ triggered++; }, trigger_id}; EXPECT_EQ(trigger.getID(), trigger_id); - EXPECT_DOUBLE_EQ(trigger.getLastTriggerTime().seconds(), 0.0); - EXPECT_DOUBLE_EQ(trigger.nextTriggerTime().seconds(), 0.0 + trigger_period_s); + EXPECT_DOUBLE_EQ(trigger.getLastTriggerTime().seconds().count(), 0.0); + EXPECT_DOUBLE_EQ(trigger.nextTriggerTime().seconds().count(), 0.0 + trigger_period_s.count()); EXPECT_EQ(triggered, 0); - TimeType start_time = TimeType{4.0}; + auto start_time = TimeType{4.0}; trigger.runAction(start_time); - EXPECT_DOUBLE_EQ(trigger.getLastTriggerTime().seconds(), start_time.seconds()); - EXPECT_DOUBLE_EQ(trigger.nextTriggerTime().seconds(), start_time.seconds() + trigger_period_s); + EXPECT_DOUBLE_EQ(trigger.getLastTriggerTime().seconds().count(), start_time.seconds().count()); + EXPECT_DOUBLE_EQ(trigger.nextTriggerTime().seconds().count(), (start_time.seconds() + trigger_period_s).count()); EXPECT_EQ(trigger.ready(start_time + TimeType{trigger_period_s}), false); - EXPECT_EQ(trigger.ready(start_time + TimeType{trigger_period_s + 0.001}), true); + EXPECT_EQ(trigger.ready(start_time + TimeType{trigger_period_s} + TimeType{1ms}), true); EXPECT_EQ(triggered, 1); } TEST_F(TestTimeTrigger, test_time_trigger_manager_add_trigger) { using namespace std::chrono_literals; - TimeType current_time = TimeType{5.2}; + auto current_time = TimeType{5.2}; auto trigger_period_ms = 100ms; int triggered = 0; @@ -110,9 +110,9 @@ TEST_F(TestTimeTrigger, test_time_trigger_manager_trigger_ready) { using namespace std::chrono; using namespace std::chrono_literals; - TimeType current_time = TimeType{5.2}; + auto current_time = TimeType{5.2}; auto trigger_period_ms = 100ms; - auto trigger_period_s = duration(trigger_period_ms).count(); + auto trigger_period_s = TimeType{trigger_period_ms}.seconds().count(); int triggered = 0; auto trigger_manager =