Tests: areTimestampsClose() moved to common.hpp

This commit is contained in:
Pavel Kirienko
2014-03-09 17:58:17 +04:00
parent acca96f5a0
commit 5fa5962f6f
2 changed files with 11 additions and 12 deletions
+5
View File
@@ -90,3 +90,8 @@ static uavcan::CanFrame makeCanFrame(uint32_t id, const std::string& str_data, F
id |= (type == EXT) ? uavcan::CanFrame::FlagEFF : 0;
return uavcan::CanFrame(id, reinterpret_cast<const uint8_t*>(str_data.c_str()), str_data.length());
}
static bool areTimestampsClose(int64_t a, int64_t b, int64_t precision_usec = 10000)
{
return std::abs(a - b) < precision_usec;
}
+6 -12
View File
@@ -8,8 +8,6 @@
#include "common.hpp"
#include "transport/can/iface_mock.hpp"
static const unsigned int TimestampPrecisionMs = 10;
struct TimerCallCounter
{
std::vector<uavcan::TimerEvent> events_a;
@@ -21,11 +19,6 @@ struct TimerCallCounter
typedef uavcan::MethodBinder<TimerCallCounter*, void(TimerCallCounter::*)(const uavcan::TimerEvent&)> Binder;
};
static bool timestampsEqual(int64_t a, int64_t b)
{
return std::abs(a - b) < (TimestampPrecisionMs * 1000);
}
/*
* This test can fail on a non real time system. That's kinda sad but okay.
*/
@@ -67,8 +60,9 @@ TEST(Scheduler, Timers)
ASSERT_EQ(0, sch.spin(start_ts + 1000000));
ASSERT_EQ(1, tcc.events_a.size());
ASSERT_TRUE(timestampsEqual(tcc.events_a[0].scheduled_monotonic_deadline, start_ts + 100000));
ASSERT_TRUE(timestampsEqual(tcc.events_a[0].monotonic_timestamp, tcc.events_a[0].scheduled_monotonic_deadline));
ASSERT_TRUE(areTimestampsClose(tcc.events_a[0].scheduled_monotonic_deadline, start_ts + 100000));
ASSERT_TRUE(areTimestampsClose(tcc.events_a[0].monotonic_timestamp,
tcc.events_a[0].scheduled_monotonic_deadline));
ASSERT_EQ(&a, tcc.events_a[0].timer);
ASSERT_LT(900, tcc.events_b.size());
@@ -77,9 +71,9 @@ TEST(Scheduler, Timers)
uint64_t next_expected_deadline = start_ts + 1000;
for (unsigned int i = 0; i < tcc.events_b.size(); i++)
{
ASSERT_TRUE(timestampsEqual(tcc.events_b[i].scheduled_monotonic_deadline, next_expected_deadline));
ASSERT_TRUE(timestampsEqual(tcc.events_b[i].monotonic_timestamp,
tcc.events_b[i].scheduled_monotonic_deadline));
ASSERT_TRUE(areTimestampsClose(tcc.events_b[i].scheduled_monotonic_deadline, next_expected_deadline));
ASSERT_TRUE(areTimestampsClose(tcc.events_b[i].monotonic_timestamp,
tcc.events_b[i].scheduled_monotonic_deadline));
ASSERT_EQ(&b, tcc.events_b[i].timer);
next_expected_deadline += 1000;
}