From 42fdadba2c3730ce4f39cb30f8b5d003666aae83 Mon Sep 17 00:00:00 2001 From: Pavel Kirienko Date: Sun, 23 Mar 2014 21:34:42 +0400 Subject: [PATCH] Tests: Clock mock and test node got some fixes --- libuavcan/test/clock.hpp | 10 +++++++++- libuavcan/test/node/test_node.hpp | 6 +++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libuavcan/test/clock.hpp b/libuavcan/test/clock.hpp index 6b20454ba1..7ef9d94ecc 100644 --- a/libuavcan/test/clock.hpp +++ b/libuavcan/test/clock.hpp @@ -16,17 +16,22 @@ public: mutable uint64_t utc; uavcan::UtcDuration last_adjustment; int64_t monotonic_auto_advance; + bool preserve_utc; SystemClockMock(uint64_t initial = 0) : monotonic(initial) , utc(initial) , monotonic_auto_advance(0) + , preserve_utc(false) { } void advance(uint64_t usec) const { monotonic += usec; - utc += usec; + if (!preserve_utc) + { + utc += usec; + } } uavcan::MonotonicTime getMonotonic() const @@ -46,7 +51,10 @@ public: void adjustUtc(uavcan::UtcDuration adjustment) { assert(this); + const uint64_t prev_utc = utc; + utc += adjustment.toUSec(); last_adjustment = adjustment; + std::cout << "Clock adjustment " << prev_utc << " --> " << utc << std::endl; } }; diff --git a/libuavcan/test/node/test_node.hpp b/libuavcan/test/node/test_node.hpp index 6a4126757b..967afb788f 100644 --- a/libuavcan/test/node/test_node.hpp +++ b/libuavcan/test/node/test_node.hpp @@ -150,9 +150,9 @@ struct InterlinkedTestNodes int spinBoth(uavcan::MonotonicDuration duration) { - assert(duration.isPositive()); - unsigned int nspins2 = duration.toMSec() / 2 + 1; - assert(nspins2 > 0); + assert(!duration.isNegative()); + unsigned int nspins2 = duration.toMSec() / 2; + nspins2 = nspins2 ? nspins2 : 1; while (nspins2 --> 0) { int ret = -1;