mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 14:33:33 +08:00
CAN HW filters are added using map container
This commit is contained in:
@@ -8,91 +8,40 @@
|
||||
TEST(DynamicMemory, Basic)
|
||||
{
|
||||
uavcan::PoolAllocator<128, 32> pool32;
|
||||
uavcan::PoolAllocator<256, 64> pool64;
|
||||
uavcan::PoolAllocator<512, 128> pool128;
|
||||
|
||||
EXPECT_EQ(4, pool32.getNumFreeBlocks());
|
||||
EXPECT_EQ(4, pool64.getNumFreeBlocks());
|
||||
EXPECT_EQ(4, pool128.getNumFreeBlocks());
|
||||
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
EXPECT_TRUE(poolmgr.addPool(&pool64)); // Order of insertion shall not matter
|
||||
EXPECT_TRUE(poolmgr.addPool(&pool32));
|
||||
EXPECT_FALSE(poolmgr.addPool(&pool128));
|
||||
|
||||
EXPECT_EQ(4 * 2, poolmgr.getNumBlocks());
|
||||
|
||||
const void* ptr1 = poolmgr.allocate(16);
|
||||
EXPECT_TRUE(ptr1);
|
||||
|
||||
const void* ptr2 = poolmgr.allocate(32);
|
||||
EXPECT_TRUE(ptr2);
|
||||
|
||||
const void* ptr3 = poolmgr.allocate(64);
|
||||
EXPECT_TRUE(ptr3);
|
||||
|
||||
EXPECT_FALSE(poolmgr.allocate(120));
|
||||
|
||||
EXPECT_EQ(2, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(1, pool64.getNumUsedBlocks());
|
||||
EXPECT_EQ(0, pool128.getNumUsedBlocks());
|
||||
|
||||
poolmgr.deallocate(ptr1);
|
||||
EXPECT_EQ(0, pool32.getPeakNumUsedBlocks());
|
||||
const void* ptr1 = pool32.allocate(16);
|
||||
ASSERT_TRUE(ptr1);
|
||||
EXPECT_EQ(1, pool32.getNumUsedBlocks());
|
||||
poolmgr.deallocate(ptr2);
|
||||
EXPECT_FALSE(pool32.allocate(120));
|
||||
EXPECT_EQ(1, pool32.getNumUsedBlocks());
|
||||
pool32.deallocate(ptr1);
|
||||
EXPECT_EQ(0, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(1, pool64.getNumUsedBlocks());
|
||||
poolmgr.deallocate(ptr3);
|
||||
EXPECT_EQ(0, pool64.getNumUsedBlocks());
|
||||
EXPECT_EQ(0, pool128.getNumUsedBlocks());
|
||||
EXPECT_EQ(1, pool32.getPeakNumUsedBlocks());
|
||||
}
|
||||
|
||||
TEST(DynamicMemory, OutOfMemory)
|
||||
{
|
||||
uavcan::PoolAllocator<64, 32> pool32;
|
||||
uavcan::PoolAllocator<128, 64> pool64;
|
||||
|
||||
EXPECT_EQ(2, pool32.getNumFreeBlocks());
|
||||
EXPECT_EQ(2, pool64.getNumFreeBlocks());
|
||||
EXPECT_EQ(0, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(0, pool32.getPeakNumUsedBlocks());
|
||||
|
||||
uavcan::PoolManager<4> poolmgr;
|
||||
EXPECT_TRUE(poolmgr.addPool(&pool64));
|
||||
EXPECT_TRUE(poolmgr.addPool(&pool32));
|
||||
|
||||
const void* ptr1 = poolmgr.allocate(32);
|
||||
EXPECT_TRUE(ptr1);
|
||||
EXPECT_TRUE(pool32.isInPool(ptr1));
|
||||
EXPECT_FALSE(pool64.isInPool(ptr1));
|
||||
|
||||
const void* ptr2 = poolmgr.allocate(32);
|
||||
EXPECT_TRUE(ptr2);
|
||||
EXPECT_TRUE(pool32.isInPool(ptr2));
|
||||
EXPECT_FALSE(pool64.isInPool(ptr2));
|
||||
|
||||
const void* ptr3 = poolmgr.allocate(32);
|
||||
EXPECT_TRUE(ptr3);
|
||||
EXPECT_FALSE(pool32.isInPool(ptr3));
|
||||
EXPECT_TRUE(pool64.isInPool(ptr3)); // One block went to the next pool
|
||||
const void* ptr1 = pool32.allocate(32);
|
||||
ASSERT_TRUE(ptr1);
|
||||
EXPECT_EQ(1, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(1, pool32.getPeakNumUsedBlocks());
|
||||
|
||||
const void* ptr2 = pool32.allocate(32);
|
||||
ASSERT_TRUE(ptr2);
|
||||
EXPECT_EQ(2, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(1, pool64.getNumUsedBlocks());
|
||||
EXPECT_EQ(2, pool32.getPeakNumUsedBlocks());
|
||||
|
||||
poolmgr.deallocate(ptr2);
|
||||
EXPECT_EQ(1, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(1, pool64.getNumUsedBlocks());
|
||||
|
||||
const void* ptr4 = poolmgr.allocate(64);
|
||||
EXPECT_TRUE(ptr4);
|
||||
EXPECT_EQ(1, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(2, pool64.getNumUsedBlocks()); // Top pool is 100% used
|
||||
|
||||
EXPECT_FALSE(poolmgr.allocate(64)); // No free blocks left --> NULL
|
||||
EXPECT_EQ(1, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(2, pool64.getNumUsedBlocks());
|
||||
|
||||
poolmgr.deallocate(ptr3); // This was small chunk allocated in big pool
|
||||
EXPECT_EQ(1, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(1, pool64.getNumUsedBlocks()); // Make sure it was properly deallocated
|
||||
ASSERT_FALSE(pool32.allocate(32)); // No free blocks left --> NULL
|
||||
EXPECT_EQ(2, pool32.getNumUsedBlocks());
|
||||
EXPECT_EQ(0, pool32.getNumFreeBlocks());
|
||||
EXPECT_EQ(2, pool32.getPeakNumUsedBlocks());
|
||||
}
|
||||
|
||||
TEST(DynamicMemory, LimitedPoolAllocator)
|
||||
@@ -101,6 +50,7 @@ TEST(DynamicMemory, LimitedPoolAllocator)
|
||||
uavcan::LimitedPoolAllocator lim(pool32, 2);
|
||||
|
||||
EXPECT_EQ(2, lim.getNumBlocks());
|
||||
EXPECT_EQ(0, pool32.getPeakNumUsedBlocks());
|
||||
|
||||
const void* ptr1 = lim.allocate(1);
|
||||
const void* ptr2 = lim.allocate(1);
|
||||
@@ -119,4 +69,6 @@ TEST(DynamicMemory, LimitedPoolAllocator)
|
||||
EXPECT_TRUE(ptr4);
|
||||
EXPECT_TRUE(ptr5);
|
||||
EXPECT_FALSE(ptr6);
|
||||
|
||||
EXPECT_EQ(2, pool32.getPeakNumUsedBlocks());
|
||||
}
|
||||
|
||||
@@ -20,17 +20,15 @@
|
||||
struct TestNode : public uavcan::INode
|
||||
{
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * 100, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
uavcan::OutgoingTransferRegistry<8> otr;
|
||||
uavcan::Scheduler scheduler;
|
||||
uint64_t internal_failure_count;
|
||||
|
||||
TestNode(uavcan::ICanDriver& can_driver, uavcan::ISystemClock& clock_driver, uavcan::NodeID self_node_id)
|
||||
: otr(poolmgr)
|
||||
, scheduler(can_driver, poolmgr, clock_driver, otr)
|
||||
: otr(pool)
|
||||
, scheduler(can_driver, pool, clock_driver, otr)
|
||||
, internal_failure_count(0)
|
||||
{
|
||||
poolmgr.addPool(&pool);
|
||||
setNodeID(self_node_id);
|
||||
}
|
||||
|
||||
@@ -40,7 +38,7 @@ struct TestNode : public uavcan::INode
|
||||
internal_failure_count++;
|
||||
}
|
||||
|
||||
virtual uavcan::PoolManager<1>& getAllocator() { return poolmgr; }
|
||||
virtual uavcan::IPoolAllocator& getAllocator() { return pool; }
|
||||
virtual uavcan::Scheduler& getScheduler() { return scheduler; }
|
||||
virtual const uavcan::Scheduler& getScheduler() const { return scheduler; }
|
||||
};
|
||||
@@ -75,15 +73,6 @@ struct PairableCanDriver : public uavcan::ICanDriver, public uavcan::ICanIface
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual const uavcan::ICanIface* getIface(uavcan::uint8_t iface_index) const
|
||||
{
|
||||
if (iface_index == 0)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual uavcan::uint8_t getNumIfaces() const { return 1; }
|
||||
|
||||
virtual uavcan::int16_t select(uavcan::CanSelectMasks& inout_masks, uavcan::MonotonicTime blocking_deadline)
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
TEST(dynamic_node_id_server_centralized_Storage, Initialization)
|
||||
{
|
||||
using namespace uavcan::dynamic_node_id_server::centralized;
|
||||
using namespace uavcan::dynamic_node_id_server;
|
||||
|
||||
// No data in the storage - initializing empty
|
||||
{
|
||||
@@ -20,95 +21,51 @@ TEST(dynamic_node_id_server_centralized_Storage, Initialization)
|
||||
ASSERT_EQ(0, storage.getNumKeys());
|
||||
ASSERT_LE(0, stor.init());
|
||||
|
||||
ASSERT_EQ(1, storage.getNumKeys());
|
||||
ASSERT_EQ(0, storage.getNumKeys());
|
||||
ASSERT_EQ(0, stor.getSize());
|
||||
|
||||
ASSERT_FALSE(stor.findByNodeID(1));
|
||||
ASSERT_FALSE(stor.findByNodeID(0));
|
||||
}
|
||||
// Nonempty storage, one item
|
||||
{
|
||||
MemoryStorageBackend storage;
|
||||
Storage stor(storage);
|
||||
|
||||
storage.set("size", "1");
|
||||
ASSERT_EQ(-uavcan::ErrFailure, stor.init()); // Expected one entry, none found
|
||||
ASSERT_EQ(1, storage.getNumKeys());
|
||||
|
||||
storage.set("0_unique_id", "00000000000000000000000000000000");
|
||||
storage.set("0_node_id", "0");
|
||||
ASSERT_EQ(-uavcan::ErrFailure, stor.init()); // Invalid entry - zero Node ID
|
||||
|
||||
storage.set("0_node_id", "1");
|
||||
ASSERT_LE(0, stor.init()); // OK now
|
||||
|
||||
ASSERT_EQ(3, storage.getNumKeys());
|
||||
ASSERT_EQ(1, stor.getSize());
|
||||
|
||||
ASSERT_TRUE(stor.findByNodeID(1));
|
||||
ASSERT_FALSE(stor.findByNodeID(0));
|
||||
}
|
||||
// Nonempty storage, broken data
|
||||
{
|
||||
MemoryStorageBackend storage;
|
||||
Storage stor(storage);
|
||||
|
||||
storage.set("size", "foobar");
|
||||
ASSERT_EQ(-uavcan::ErrFailure, stor.init()); // Bad value
|
||||
|
||||
storage.set("size", "128");
|
||||
ASSERT_EQ(-uavcan::ErrFailure, stor.init()); // Bad value
|
||||
|
||||
storage.set("size", "1");
|
||||
ASSERT_EQ(-uavcan::ErrFailure, stor.init()); // No items
|
||||
ASSERT_EQ(1, storage.getNumKeys());
|
||||
|
||||
storage.set("0_unique_id", "00000000000000000000000000000000");
|
||||
storage.set("0_node_id", "128"); // Bad value (127 max)
|
||||
ASSERT_EQ(-uavcan::ErrFailure, stor.init()); // Failed
|
||||
|
||||
storage.set("0_node_id", "127");
|
||||
ASSERT_LE(0, stor.init()); // OK now
|
||||
ASSERT_EQ(1, stor.getSize());
|
||||
|
||||
ASSERT_TRUE(stor.findByNodeID(127));
|
||||
ASSERT_FALSE(stor.findByNodeID(0));
|
||||
|
||||
ASSERT_EQ(3, storage.getNumKeys());
|
||||
ASSERT_FALSE(stor.isNodeIDOccupied(1));
|
||||
ASSERT_FALSE(stor.isNodeIDOccupied(0));
|
||||
}
|
||||
// Nonempty storage, many items
|
||||
{
|
||||
MemoryStorageBackend storage;
|
||||
Storage stor(storage);
|
||||
|
||||
storage.set("size", "2");
|
||||
storage.set("0_unique_id", "00000000000000000000000000000000");
|
||||
storage.set("0_node_id", "1");
|
||||
storage.set("1_unique_id", "0123456789abcdef0123456789abcdef");
|
||||
storage.set("1_node_id", "127");
|
||||
storage.set("occupation_mask", "0e000000000000000000000000000000"); // node ID 1, 2, 3
|
||||
ASSERT_LE(0, stor.init()); // OK
|
||||
|
||||
ASSERT_LE(0, stor.init()); // OK now
|
||||
ASSERT_EQ(5, storage.getNumKeys());
|
||||
ASSERT_EQ(2, stor.getSize());
|
||||
ASSERT_EQ(1, storage.getNumKeys());
|
||||
ASSERT_EQ(3, stor.getSize());
|
||||
|
||||
ASSERT_TRUE(stor.findByNodeID(1));
|
||||
ASSERT_TRUE(stor.findByNodeID(127));
|
||||
ASSERT_FALSE(stor.findByNodeID(0));
|
||||
ASSERT_TRUE(stor.isNodeIDOccupied(1));
|
||||
ASSERT_TRUE(stor.isNodeIDOccupied(2));
|
||||
ASSERT_TRUE(stor.isNodeIDOccupied(3));
|
||||
ASSERT_FALSE(stor.isNodeIDOccupied(0));
|
||||
ASSERT_FALSE(stor.isNodeIDOccupied(4));
|
||||
|
||||
uavcan::protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id uid;
|
||||
uid[0] = 0x01;
|
||||
uid[1] = 0x23;
|
||||
uid[2] = 0x45;
|
||||
uid[3] = 0x67;
|
||||
uid[4] = 0x89;
|
||||
uid[5] = 0xab;
|
||||
uid[6] = 0xcd;
|
||||
uid[7] = 0xef;
|
||||
uavcan::copy(uid.begin(), uid.begin() + 8, uid.begin() + 8);
|
||||
UniqueID uid_1;
|
||||
uid_1[0] = 1;
|
||||
|
||||
ASSERT_TRUE(stor.findByUniqueID(uid));
|
||||
ASSERT_EQ(127, stor.findByUniqueID(uid)->node_id.get());
|
||||
ASSERT_EQ(uid, stor.findByNodeID(127)->unique_id);
|
||||
UniqueID uid_2;
|
||||
uid_2[0] = 2;
|
||||
|
||||
UniqueID uid_3;
|
||||
uid_3[0] = 3;
|
||||
|
||||
ASSERT_FALSE(stor.getNodeIDForUniqueID(uid_1).isValid());
|
||||
ASSERT_FALSE(stor.getNodeIDForUniqueID(uid_2).isValid());
|
||||
ASSERT_FALSE(stor.getNodeIDForUniqueID(uid_3).isValid());
|
||||
ASSERT_FALSE(stor.isNodeIDOccupied(127));
|
||||
|
||||
storage.set("01000000000000000000000000000000", "1");
|
||||
storage.set("02000000000000000000000000000000", "2");
|
||||
storage.set("03000000000000000000000000000000", "3");
|
||||
|
||||
ASSERT_EQ(1, stor.getNodeIDForUniqueID(uid_1).get());
|
||||
ASSERT_EQ(2, stor.getNodeIDForUniqueID(uid_2).get());
|
||||
ASSERT_EQ(3, stor.getNodeIDForUniqueID(uid_3).get());
|
||||
ASSERT_FALSE(stor.isNodeIDOccupied(127));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,21 +80,19 @@ TEST(dynamic_node_id_server_centralized_Storage, Basic)
|
||||
ASSERT_EQ(0, storage.getNumKeys());
|
||||
ASSERT_LE(0, stor.init());
|
||||
storage.print();
|
||||
ASSERT_EQ(1, storage.getNumKeys());
|
||||
ASSERT_EQ(0, storage.getNumKeys());
|
||||
|
||||
/*
|
||||
* Adding one entry to the log, making sure it appears in the storage
|
||||
*/
|
||||
Storage::Entry entry;
|
||||
entry.node_id = 1;
|
||||
entry.unique_id[0] = 1;
|
||||
ASSERT_LE(0, stor.add(entry.node_id, entry.unique_id));
|
||||
uavcan::dynamic_node_id_server::UniqueID unique_id;
|
||||
unique_id[0] = 1;
|
||||
ASSERT_LE(0, stor.add(1, unique_id));
|
||||
|
||||
ASSERT_EQ("1", storage.get("size"));
|
||||
ASSERT_EQ("01000000000000000000000000000000", storage.get("0_unique_id"));
|
||||
ASSERT_EQ("1", storage.get("0_node_id"));
|
||||
ASSERT_EQ("02000000000000000000000000000000", storage.get("occupation_mask"));
|
||||
ASSERT_EQ("1", storage.get("01000000000000000000000000000000"));
|
||||
|
||||
ASSERT_EQ(3, storage.getNumKeys());
|
||||
ASSERT_EQ(2, storage.getNumKeys());
|
||||
ASSERT_EQ(1, stor.getSize());
|
||||
|
||||
/*
|
||||
@@ -145,30 +100,31 @@ TEST(dynamic_node_id_server_centralized_Storage, Basic)
|
||||
*/
|
||||
storage.failOnSetCalls(true);
|
||||
|
||||
ASSERT_EQ(3, storage.getNumKeys());
|
||||
ASSERT_EQ(2, storage.getNumKeys());
|
||||
|
||||
entry.node_id = 2;
|
||||
entry.unique_id[0] = 2;
|
||||
ASSERT_GT(0, stor.add(entry.node_id, entry.unique_id));
|
||||
unique_id[0] = 2;
|
||||
ASSERT_GT(0, stor.add(2, unique_id));
|
||||
|
||||
ASSERT_EQ(3, storage.getNumKeys()); // No new entries, we failed
|
||||
ASSERT_EQ(2, storage.getNumKeys()); // No new entries, we failed
|
||||
|
||||
ASSERT_EQ(1, stor.getSize());
|
||||
|
||||
/*
|
||||
* Making sure add() fails when the log is full
|
||||
* Adding a lot of entries
|
||||
*/
|
||||
storage.failOnSetCalls(false);
|
||||
|
||||
while (stor.getSize() < stor.Capacity)
|
||||
uavcan::NodeID node_id(2);
|
||||
while (stor.getSize() < 127)
|
||||
{
|
||||
ASSERT_LE(0, stor.add(entry.node_id, entry.unique_id));
|
||||
ASSERT_LE(0, stor.add(node_id, unique_id));
|
||||
|
||||
entry.node_id = uint8_t(uavcan::min(entry.node_id.get() + 1U, 127U));
|
||||
entry.unique_id[0] = uint8_t(entry.unique_id[0] + 1U);
|
||||
ASSERT_TRUE(stor.getNodeIDForUniqueID(unique_id).isValid());
|
||||
ASSERT_TRUE(stor.isNodeIDOccupied(node_id));
|
||||
|
||||
node_id = uint8_t(uavcan::min(node_id.get() + 1U, 127U));
|
||||
unique_id[0] = uint8_t(unique_id[0] + 1U);
|
||||
}
|
||||
|
||||
ASSERT_GT(0, stor.add(123, entry.unique_id)); // Failing because full
|
||||
|
||||
storage.print();
|
||||
}
|
||||
|
||||
@@ -203,6 +203,26 @@ TEST(NodeInfoRetriever, Basic)
|
||||
EXPECT_EQ(13, listener.status_message_cnt);
|
||||
EXPECT_EQ(7, listener.status_change_cnt); // node 2 online/offline + 2 test nodes above online/offline + 1
|
||||
EXPECT_EQ(3, listener.info_unavailable_cnt);
|
||||
|
||||
/*
|
||||
* Forcing the class to forget everything
|
||||
*/
|
||||
std::cout << "Invalidation" << std::endl;
|
||||
|
||||
retr.invalidateAll();
|
||||
|
||||
ASSERT_FALSE(retr.isRetrievingInProgress());
|
||||
ASSERT_EQ(0, retr.getNumPendingRequests());
|
||||
|
||||
tid.increment();
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(10), 0, 60, tid);
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(11), 0, 60, tid);
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(12), 0, 60, tid);
|
||||
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(200));
|
||||
|
||||
ASSERT_TRUE(retr.isRetrievingInProgress());
|
||||
ASSERT_EQ(3, retr.getNumPendingRequests());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -232,7 +232,6 @@ public:
|
||||
}
|
||||
|
||||
virtual uavcan::ICanIface* getIface(uavcan::uint8_t iface_index) { return &ifaces.at(iface_index); }
|
||||
virtual const uavcan::ICanIface* getIface(uavcan::uint8_t iface_index) const { return &ifaces.at(iface_index); }
|
||||
virtual uavcan::uint8_t getNumIfaces() const { return uavcan::uint8_t(ifaces.size()); }
|
||||
};
|
||||
|
||||
|
||||
@@ -23,15 +23,13 @@ TEST(CanIOManager, Reception)
|
||||
{
|
||||
// Memory
|
||||
uavcan::PoolAllocator<sizeof(uavcan::CanTxQueue::Entry) * 4, sizeof(uavcan::CanTxQueue::Entry)> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
// Platform interface
|
||||
SystemClockMock clockmock;
|
||||
CanDriverMock driver(2, clockmock);
|
||||
|
||||
// IO Manager
|
||||
uavcan::CanIOManager iomgr(driver, poolmgr, clockmock);
|
||||
uavcan::CanIOManager iomgr(driver, pool, clockmock);
|
||||
ASSERT_EQ(2, iomgr.getNumIfaces());
|
||||
|
||||
/*
|
||||
@@ -120,15 +118,13 @@ TEST(CanIOManager, Transmission)
|
||||
|
||||
// Memory
|
||||
uavcan::PoolAllocator<sizeof(CanTxQueue::Entry) * 4, sizeof(CanTxQueue::Entry)> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
// Platform interface
|
||||
SystemClockMock clockmock;
|
||||
CanDriverMock driver(2, clockmock);
|
||||
|
||||
// IO Manager
|
||||
CanIOManager iomgr(driver, poolmgr, clockmock, 9999);
|
||||
CanIOManager iomgr(driver, pool, clockmock, 9999);
|
||||
ASSERT_EQ(2, iomgr.getNumIfaces());
|
||||
|
||||
const int ALL_IFACES_MASK = 3;
|
||||
@@ -312,15 +308,13 @@ TEST(CanIOManager, Loopback)
|
||||
|
||||
// Memory
|
||||
uavcan::PoolAllocator<sizeof(CanTxQueue::Entry) * 4, sizeof(CanTxQueue::Entry)> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
// Platform interface
|
||||
SystemClockMock clockmock;
|
||||
CanDriverMock driver(2, clockmock);
|
||||
|
||||
// IO Manager
|
||||
CanIOManager iomgr(driver, poolmgr, clockmock);
|
||||
CanIOManager iomgr(driver, pool, clockmock);
|
||||
ASSERT_EQ(2, iomgr.getNumIfaces());
|
||||
|
||||
CanFrame fr1;
|
||||
|
||||
@@ -68,12 +68,10 @@ TEST(CanTxQueue, TxQueue)
|
||||
ASSERT_GE(40, sizeof(CanTxQueue::Entry)); // should be true for any platforms, though not required
|
||||
|
||||
uavcan::PoolAllocator<40 * 4, 40> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
SystemClockMock clockmock;
|
||||
|
||||
CanTxQueue queue(poolmgr, clockmock, 99999);
|
||||
CanTxQueue queue(pool, clockmock, 99999);
|
||||
EXPECT_TRUE(queue.isEmpty());
|
||||
|
||||
const uavcan::CanIOFlags flags = 0;
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>,
|
||||
* Ilia Sheremet <illia.sheremet@gmail.com>
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <cassert>
|
||||
|
||||
#include <uavcan/transport/can_acceptance_filter_configurator.hpp>
|
||||
#include "../node/test_node.hpp"
|
||||
#include "uavcan/node/subscriber.hpp"
|
||||
#include <uavcan/equipment/camera_gimbal/AngularCommand.hpp>
|
||||
#include <uavcan/equipment/air_data/Sideslip.hpp>
|
||||
#include <uavcan/equipment/air_data/TrueAirspeed.hpp>
|
||||
#include <uavcan/equipment/air_data/AngleOfAttack.hpp>
|
||||
#include <uavcan/equipment/ahrs/AHRS.hpp>
|
||||
#include <uavcan/equipment/air_data/StaticPressure.hpp>
|
||||
#include <uavcan/protocol/file/BeginFirmwareUpdate.hpp>
|
||||
#include <uavcan/node/service_client.hpp>
|
||||
#include <uavcan/node/service_server.hpp>
|
||||
#include <iostream>
|
||||
#include <bitset>
|
||||
|
||||
#if UAVCAN_CPP_VERSION >= UAVCAN_CPP11
|
||||
|
||||
template <typename DataType>
|
||||
struct SubscriptionListener
|
||||
{
|
||||
typedef uavcan::ReceivedDataStructure<DataType> ReceivedDataStructure;
|
||||
|
||||
struct ReceivedDataStructureCopy
|
||||
{
|
||||
uavcan::MonotonicTime ts_monotonic;
|
||||
uavcan::UtcTime ts_utc;
|
||||
uavcan::TransferType transfer_type;
|
||||
uavcan::TransferID transfer_id;
|
||||
uavcan::NodeID src_node_id;
|
||||
uavcan::uint8_t iface_index;
|
||||
DataType msg;
|
||||
|
||||
ReceivedDataStructureCopy(const ReceivedDataStructure& s) :
|
||||
ts_monotonic(s.getMonotonicTimestamp()),
|
||||
ts_utc(s.getUtcTimestamp()),
|
||||
transfer_type(s.getTransferType()),
|
||||
transfer_id(s.getTransferID()),
|
||||
src_node_id(s.getSrcNodeID()),
|
||||
iface_index(s.getIfaceIndex()),
|
||||
msg(s)
|
||||
{ }
|
||||
};
|
||||
|
||||
std::vector<DataType> simple;
|
||||
std::vector<ReceivedDataStructureCopy> extended;
|
||||
|
||||
void receiveExtended(ReceivedDataStructure& msg)
|
||||
{
|
||||
extended.push_back(msg);
|
||||
}
|
||||
|
||||
void receiveSimple(DataType& msg)
|
||||
{
|
||||
simple.push_back(msg);
|
||||
}
|
||||
|
||||
typedef SubscriptionListener<DataType> SelfType;
|
||||
typedef uavcan::MethodBinder<SelfType*, void(SelfType::*) (ReceivedDataStructure&)> ExtendedBinder;
|
||||
typedef uavcan::MethodBinder<SelfType*, void(SelfType::*) (DataType&)> SimpleBinder;
|
||||
|
||||
ExtendedBinder bindExtended() { return ExtendedBinder(this, &SelfType::receiveExtended); }
|
||||
SimpleBinder bindSimple() { return SimpleBinder(this, &SelfType::receiveSimple); }
|
||||
};
|
||||
|
||||
static void writeServiceServerCallback(
|
||||
const uavcan::ReceivedDataStructure<uavcan::protocol::file::BeginFirmwareUpdate::Request>& req,
|
||||
uavcan::protocol::file::BeginFirmwareUpdate::Response& rsp)
|
||||
{
|
||||
std::cout << req << std::endl;
|
||||
rsp.error = rsp.ERROR_UNKNOWN;
|
||||
}
|
||||
|
||||
TEST(CanAcceptanceFilter, Basic_test)
|
||||
{
|
||||
uavcan::GlobalDataTypeRegistry::instance().reset();
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::equipment::camera_gimbal::AngularCommand> _reg1;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::equipment::air_data::Sideslip> _reg2;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::equipment::air_data::TrueAirspeed> _reg3;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::equipment::air_data::AngleOfAttack> _reg4;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::equipment::ahrs::AHRS> _reg5;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::equipment::air_data::StaticPressure> _reg6;
|
||||
uavcan::DefaultDataTypeRegistrator<uavcan::protocol::file::BeginFirmwareUpdate> _reg7;
|
||||
|
||||
SystemClockDriver clock_driver;
|
||||
CanDriverMock can_driver(1, clock_driver);
|
||||
TestNode node(can_driver, clock_driver, 24);
|
||||
|
||||
uavcan::Subscriber<uavcan::equipment::camera_gimbal::AngularCommand,
|
||||
SubscriptionListener<uavcan::equipment::camera_gimbal::AngularCommand>::ExtendedBinder> sub_1(node);
|
||||
uavcan::Subscriber<uavcan::equipment::air_data::Sideslip,
|
||||
SubscriptionListener<uavcan::equipment::air_data::Sideslip>::ExtendedBinder> sub_2(node);
|
||||
uavcan::Subscriber<uavcan::equipment::air_data::TrueAirspeed,
|
||||
SubscriptionListener<uavcan::equipment::air_data::TrueAirspeed>::ExtendedBinder> sub_3(node);
|
||||
uavcan::Subscriber<uavcan::equipment::air_data::AngleOfAttack,
|
||||
SubscriptionListener<uavcan::equipment::air_data::AngleOfAttack>::ExtendedBinder> sub_4(node);
|
||||
uavcan::Subscriber<uavcan::equipment::ahrs::AHRS,
|
||||
SubscriptionListener<uavcan::equipment::ahrs::AHRS>::ExtendedBinder> sub_5(node);
|
||||
uavcan::Subscriber<uavcan::equipment::air_data::StaticPressure,
|
||||
SubscriptionListener<uavcan::equipment::air_data::StaticPressure>::ExtendedBinder> sub_6(node);
|
||||
uavcan::Subscriber<uavcan::equipment::air_data::StaticPressure,
|
||||
SubscriptionListener<uavcan::equipment::air_data::StaticPressure>::ExtendedBinder> sub_6_1(node);
|
||||
uavcan::ServiceServer<uavcan::protocol::file::BeginFirmwareUpdate> server(node);
|
||||
|
||||
SubscriptionListener<uavcan::equipment::camera_gimbal::AngularCommand> listener_1;
|
||||
SubscriptionListener<uavcan::equipment::air_data::Sideslip> listener_2;
|
||||
SubscriptionListener<uavcan::equipment::air_data::TrueAirspeed> listener_3;
|
||||
SubscriptionListener<uavcan::equipment::air_data::AngleOfAttack> listener_4;
|
||||
SubscriptionListener<uavcan::equipment::ahrs::AHRS> listener_5;
|
||||
SubscriptionListener<uavcan::equipment::air_data::StaticPressure> listener_6;
|
||||
|
||||
sub_1.start(listener_1.bindExtended());
|
||||
sub_2.start(listener_2.bindExtended());
|
||||
sub_3.start(listener_3.bindExtended());
|
||||
sub_4.start(listener_4.bindExtended());
|
||||
sub_5.start(listener_5.bindExtended());
|
||||
sub_6.start(listener_6.bindExtended());
|
||||
sub_6_1.start(listener_6.bindExtended());
|
||||
server.start(writeServiceServerCallback);
|
||||
std::cout << "Subscribers are initialized ..." << std::endl;
|
||||
|
||||
uavcan::CanAcceptanceFilterConfigurator test_configurator(node);
|
||||
int configure_filters_assert = test_configurator.configureFilters();
|
||||
if (configure_filters_assert == 0)
|
||||
{
|
||||
std::cout << "Filters are configured ..." << std::endl;
|
||||
}
|
||||
|
||||
const auto& configure_array = test_configurator.getConfiguration();
|
||||
uint32_t configure_array_size = configure_array.getSize();
|
||||
|
||||
ASSERT_EQ(configure_filters_assert, 0);
|
||||
ASSERT_EQ(configure_array_size, 4);
|
||||
|
||||
for (uint16_t i = 0; i<configure_array_size; i++)
|
||||
{
|
||||
std::cout << "config.ID [" << i << "]= " << configure_array.getByIndex(i)->id << std::endl;
|
||||
std::cout << "config.MK [" << i << "]= " << configure_array.getByIndex(i)->mask << std::endl;
|
||||
}
|
||||
|
||||
ASSERT_EQ(configure_array.getByIndex(0)->id, 268435456);
|
||||
ASSERT_EQ(configure_array.getByIndex(0)->mask, 469762048);
|
||||
ASSERT_EQ(configure_array.getByIndex(1)->id, 363069440);
|
||||
ASSERT_EQ(configure_array.getByIndex(1)->mask, 536739840);
|
||||
ASSERT_EQ(configure_array.getByIndex(2)->id, 16777216);
|
||||
ASSERT_EQ(configure_array.getByIndex(2)->mask, 124452864);
|
||||
ASSERT_EQ(configure_array.getByIndex(3)->id, 18874368);
|
||||
ASSERT_EQ(configure_array.getByIndex(3)->mask, 133169152);
|
||||
}
|
||||
#endif
|
||||
@@ -53,15 +53,13 @@ static const uavcan::NodeID SELF_NODE_ID(64);
|
||||
TEST(Dispatcher, Reception)
|
||||
{
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * 8, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
SystemClockMock clockmock(100);
|
||||
CanDriverMock driver(2, clockmock);
|
||||
|
||||
uavcan::OutgoingTransferRegistry<8> out_trans_reg(poolmgr);
|
||||
uavcan::OutgoingTransferRegistry<8> out_trans_reg(pool);
|
||||
|
||||
uavcan::Dispatcher dispatcher(driver, poolmgr, clockmock, out_trans_reg);
|
||||
uavcan::Dispatcher dispatcher(driver, pool, clockmock, out_trans_reg);
|
||||
ASSERT_TRUE(dispatcher.setNodeID(SELF_NODE_ID)); // Can be set only once
|
||||
ASSERT_FALSE(dispatcher.setNodeID(SELF_NODE_ID));
|
||||
ASSERT_EQ(SELF_NODE_ID, dispatcher.getNodeID());
|
||||
@@ -93,12 +91,12 @@ TEST(Dispatcher, Reception)
|
||||
static const int NUM_SUBSCRIBERS = 6;
|
||||
SubscriberPtr subscribers[NUM_SUBSCRIBERS] =
|
||||
{
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[0], poolmgr)), // msg
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[0], poolmgr)), // msg // Two similar
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[1], poolmgr)), // msg
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[2], poolmgr)), // srv
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[3], poolmgr)), // srv
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[3], poolmgr)) // srv // Repeat again
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[0], pool)), // msg
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[0], pool)), // msg // Two similar
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[1], pool)), // msg
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[2], pool)), // srv
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[3], pool)), // srv
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransferPerfCounter(), TYPES[3], pool)) // srv // Repeat again
|
||||
};
|
||||
|
||||
static const std::string DATA[6] =
|
||||
@@ -259,15 +257,13 @@ TEST(Dispatcher, Reception)
|
||||
TEST(Dispatcher, Transmission)
|
||||
{
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * 8, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
SystemClockMock clockmock(100);
|
||||
CanDriverMock driver(2, clockmock);
|
||||
|
||||
uavcan::OutgoingTransferRegistry<8> out_trans_reg(poolmgr);
|
||||
uavcan::OutgoingTransferRegistry<8> out_trans_reg(pool);
|
||||
|
||||
uavcan::Dispatcher dispatcher(driver, poolmgr, clockmock, out_trans_reg);
|
||||
uavcan::Dispatcher dispatcher(driver, pool, clockmock, out_trans_reg);
|
||||
ASSERT_TRUE(dispatcher.setNodeID(SELF_NODE_ID)); // Can be set only once
|
||||
ASSERT_FALSE(dispatcher.setNodeID(SELF_NODE_ID));
|
||||
|
||||
@@ -324,7 +320,7 @@ TEST(Dispatcher, Transmission)
|
||||
|
||||
TEST(Dispatcher, Spin)
|
||||
{
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
NullAllocator poolmgr;
|
||||
|
||||
SystemClockMock clockmock(100);
|
||||
CanDriverMock driver(2, clockmock);
|
||||
@@ -370,7 +366,7 @@ struct DispatcherTestLoopbackFrameListener : public uavcan::LoopbackFrameListene
|
||||
|
||||
TEST(Dispatcher, Loopback)
|
||||
{
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
NullAllocator poolmgr;
|
||||
|
||||
SystemClockMock clockmock(100);
|
||||
CanDriverMock driver(2, clockmock);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <uavcan/transport/transfer_listener.hpp>
|
||||
#include "../clock.hpp"
|
||||
#include "transfer_test_helpers.hpp"
|
||||
|
||||
|
||||
static uavcan::RxFrame makeFrame()
|
||||
@@ -71,7 +72,7 @@ TEST(MultiFrameIncomingTransfer, Basic)
|
||||
using uavcan::RxFrame;
|
||||
using uavcan::MultiFrameIncomingTransfer;
|
||||
|
||||
uavcan::PoolManager<1> poolmgr; // We don't need dynamic memory
|
||||
NullAllocator poolmgr; // We don't need dynamic memory
|
||||
uavcan::TransferBufferManager<256, 1> bufmgr(poolmgr);
|
||||
|
||||
const RxFrame frame = makeFrame();
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <uavcan/transport/outgoing_transfer_registry.hpp>
|
||||
#include "../clock.hpp"
|
||||
#include "transfer_test_helpers.hpp"
|
||||
|
||||
|
||||
TEST(OutgoingTransferRegistry, Basic)
|
||||
{
|
||||
using uavcan::OutgoingTransferRegistryKey;
|
||||
uavcan::PoolManager<1> poolmgr; // Empty
|
||||
NullAllocator poolmgr; // Empty
|
||||
uavcan::OutgoingTransferRegistry<4> otr(poolmgr);
|
||||
|
||||
otr.cleanup(tsMono(1000));
|
||||
|
||||
@@ -133,10 +133,8 @@ TEST(DynamicTransferBufferManagerEntry, Basic)
|
||||
static const int MAX_SIZE = TEST_BUFFER_SIZE;
|
||||
static const int POOL_BLOCKS = 8;
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
DynamicTransferBufferManagerEntry buf(poolmgr, MAX_SIZE);
|
||||
DynamicTransferBufferManagerEntry buf(pool, MAX_SIZE);
|
||||
|
||||
uint8_t local_buffer[TEST_BUFFER_SIZE * 2];
|
||||
const uint8_t* const test_data_ptr = reinterpret_cast<const uint8_t*>(TEST_DATA.c_str());
|
||||
@@ -233,11 +231,9 @@ TEST(TransferBufferManager, Basic)
|
||||
|
||||
static const int POOL_BLOCKS = 6;
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
typedef TransferBufferManager<MGR_MAX_BUFFER_SIZE, 2> TransferBufferManagerType;
|
||||
std::auto_ptr<TransferBufferManagerType> mgr(new TransferBufferManagerType(poolmgr));
|
||||
std::auto_ptr<TransferBufferManagerType> mgr(new TransferBufferManagerType(pool));
|
||||
|
||||
// Empty
|
||||
ASSERT_FALSE(mgr->access(TransferBufferManagerKey(0, uavcan::TransferTypeMessageUnicast)));
|
||||
|
||||
@@ -36,11 +36,9 @@ TEST(TransferListener, BasicMFT)
|
||||
|
||||
static const int NUM_POOL_BLOCKS = 12; // This number is just enough to pass the test
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * NUM_POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
uavcan::TransferPerfCounter perf;
|
||||
TestListener<256, 1, 1> subscriber(perf, type, poolmgr);
|
||||
TestListener<256, 1, 1> subscriber(perf, type, pool);
|
||||
|
||||
/*
|
||||
* Test data
|
||||
@@ -97,7 +95,7 @@ TEST(TransferListener, CrcFailure)
|
||||
{
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr; // No dynamic memory
|
||||
NullAllocator poolmgr; // No dynamic memory
|
||||
uavcan::TransferPerfCounter perf;
|
||||
TestListener<256, 2, 2> subscriber(perf, type, poolmgr); // Static buffer only, 2 entries
|
||||
|
||||
@@ -140,7 +138,7 @@ TEST(TransferListener, BasicSFT)
|
||||
{
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr; // No dynamic memory. At all.
|
||||
NullAllocator poolmgr; // No dynamic memory. At all.
|
||||
uavcan::TransferPerfCounter perf;
|
||||
TestListener<0, 0, 5> subscriber(perf, type, poolmgr); // Max buf size is 0, i.e. SFT-only
|
||||
|
||||
@@ -176,7 +174,7 @@ TEST(TransferListener, Cleanup)
|
||||
{
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr; // No dynamic memory
|
||||
NullAllocator poolmgr; // No dynamic memory
|
||||
uavcan::TransferPerfCounter perf;
|
||||
TestListener<256, 1, 2> subscriber(perf, type, poolmgr); // Static buffer only, 1 entry
|
||||
|
||||
@@ -231,7 +229,7 @@ TEST(TransferListener, MaximumTransferLength)
|
||||
{
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
NullAllocator poolmgr;
|
||||
uavcan::TransferPerfCounter perf;
|
||||
TestListener<uavcan::MaxPossibleTransferPayloadLen * 2, 3, 3> subscriber(perf, type, poolmgr);
|
||||
|
||||
@@ -260,7 +258,7 @@ TEST(TransferListener, AnonymousTransfers)
|
||||
{
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
NullAllocator poolmgr;
|
||||
uavcan::TransferPerfCounter perf;
|
||||
TestListener<0, 0, 0> subscriber(perf, type, poolmgr);
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <uavcan/transport/transfer_receiver.hpp>
|
||||
#include "../clock.hpp"
|
||||
#include "transfer_test_helpers.hpp"
|
||||
|
||||
/*
|
||||
* Beware!
|
||||
@@ -46,17 +47,16 @@ struct RxFrameGenerator
|
||||
const uavcan::TransferBufferManagerKey RxFrameGenerator::DEFAULT_KEY(42, uavcan::TransferTypeMessageBroadcast);
|
||||
|
||||
|
||||
template <unsigned BUFSIZE>
|
||||
template <unsigned BufSize>
|
||||
struct Context
|
||||
{
|
||||
uavcan::PoolManager<1> poolmgr; // We don't need dynamic memory for this test
|
||||
uavcan::TransferReceiver receiver; // Must be default constructible and copyable
|
||||
uavcan::TransferBufferManager<BUFSIZE, 1> bufmgr;
|
||||
NullAllocator pool; // We don't need dynamic memory for this test
|
||||
uavcan::TransferReceiver receiver; // Must be default constructible and copyable
|
||||
uavcan::TransferBufferManager<BufSize, 1> bufmgr;
|
||||
|
||||
Context()
|
||||
: bufmgr(poolmgr)
|
||||
Context() : bufmgr(pool)
|
||||
{
|
||||
assert(poolmgr.allocate(1) == NULL);
|
||||
assert(pool.allocate(1) == NULL);
|
||||
}
|
||||
|
||||
~Context()
|
||||
@@ -144,8 +144,8 @@ TEST(TransferReceiver, Basic)
|
||||
|
||||
ASSERT_TRUE(matchBufferContent(bufmgr.access(gen.bufmgr_key), "345678abcdefgh"));
|
||||
ASSERT_EQ(0x789A, rcv.getLastTransferCrc());
|
||||
ASSERT_GT(TransferReceiver::getDefaultTransferInterval(), rcv.getInterval());
|
||||
ASSERT_LT(TransferReceiver::getMinTransferInterval(), rcv.getInterval());
|
||||
ASSERT_GE(TransferReceiver::getDefaultTransferInterval(), rcv.getInterval());
|
||||
ASSERT_LE(TransferReceiver::getMinTransferInterval(), rcv.getInterval());
|
||||
ASSERT_EQ(1000, rcv.getLastTransferTimestampMonotonic().toUSec());
|
||||
ASSERT_FALSE(rcv.isTimedOut(tsMono(1000)));
|
||||
ASSERT_FALSE(rcv.isTimedOut(tsMono(5000)));
|
||||
@@ -174,33 +174,47 @@ TEST(TransferReceiver, Basic)
|
||||
CHECK_SINGLE_FRAME(rcv.addFrame(gen(0, "", 0, true, 4, 3600), bk));
|
||||
ASSERT_EQ(3600, rcv.getLastTransferTimestampMonotonic().toUSec());
|
||||
|
||||
std::cout << "Interval: " << rcv.getInterval().toString() << std::endl;
|
||||
|
||||
/*
|
||||
* Timeouts
|
||||
*/
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(1, "qwe", 0, true, 1, 100000), bk)); // Wrong iface - ignored
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(1, "qwe", 0, true, 1, 5000), bk)); // Wrong iface - ignored
|
||||
CHECK_SINGLE_FRAME(rcv.addFrame(gen(1, "qwe", 0, true, 6, 1500000), bk)); // Accepted due to iface timeout
|
||||
ASSERT_EQ(1500000, rcv.getLastTransferTimestampMonotonic().toUSec());
|
||||
|
||||
std::cout << "Interval: " << rcv.getInterval().toString() << std::endl;
|
||||
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(0, "qwe", 0, true, 7, 1500100), bk)); // Ignored - old iface 0
|
||||
CHECK_SINGLE_FRAME(rcv.addFrame(gen(1, "qwe", 0, true, 7, 1500100), bk));
|
||||
ASSERT_EQ(1500100, rcv.getLastTransferTimestampMonotonic().toUSec());
|
||||
|
||||
std::cout << "Interval: " << rcv.getInterval().toString() << std::endl;
|
||||
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(1, "qwe", 0, true, 7, 1500100), bk)); // Old TID
|
||||
CHECK_SINGLE_FRAME(rcv.addFrame(gen(0, "qwe", 0, true, 7, 100000000), bk)); // Accepted - global timeout
|
||||
ASSERT_EQ(100000000, rcv.getLastTransferTimestampMonotonic().toUSec());
|
||||
|
||||
std::cout << "Interval: " << rcv.getInterval().toString() << std::endl;
|
||||
|
||||
CHECK_SINGLE_FRAME(rcv.addFrame(gen(0, "qwe", 0, true, 0, 100000100), bk));
|
||||
ASSERT_EQ(100000100, rcv.getLastTransferTimestampMonotonic().toUSec());
|
||||
|
||||
std::cout << "Interval: " << rcv.getInterval().toString() << std::endl;
|
||||
|
||||
ASSERT_TRUE(rcv.isTimedOut(tsMono(900000000)));
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(1, "\x78\x56" "345678", 0, false, 0, 900000000), bk)); // Global timeout
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(0, "12345678", 0, false, 0, 900000100), bk)); // Wrong iface
|
||||
CHECK_NOT_COMPLETE(rcv.addFrame(gen(0, "qwe", 1, true, 0, 900000200), bk)); // Wrong iface
|
||||
CHECK_COMPLETE( rcv.addFrame(gen(1, "qwe", 1, true, 0, 900000200), bk));
|
||||
|
||||
ASSERT_EQ(900000000, rcv.getLastTransferTimestampMonotonic().toUSec());
|
||||
std::cout << "Interval: " << rcv.getInterval().toString() << std::endl;
|
||||
|
||||
ASSERT_FALSE(rcv.isTimedOut(tsMono(1000)));
|
||||
ASSERT_FALSE(rcv.isTimedOut(tsMono(900000200)));
|
||||
ASSERT_TRUE(rcv.isTimedOut(tsMono(1000 * 1000000)));
|
||||
ASSERT_FALSE(rcv.isTimedOut(tsMono(900000300)));
|
||||
ASSERT_TRUE(rcv.isTimedOut(tsMono(990000000)));
|
||||
|
||||
ASSERT_LT(TransferReceiver::getDefaultTransferInterval(), rcv.getInterval());
|
||||
ASSERT_LE(TransferReceiver::getMinTransferInterval(), rcv.getInterval());
|
||||
ASSERT_GE(TransferReceiver::getMaxTransferInterval(), rcv.getInterval());
|
||||
|
||||
@@ -29,7 +29,7 @@ static int sendOne(uavcan::TransferSender& sender, const std::string& data,
|
||||
|
||||
TEST(TransferSender, Basic)
|
||||
{
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
NullAllocator poolmgr;
|
||||
|
||||
SystemClockMock clockmock(100);
|
||||
CanDriverMock driver(2, clockmock);
|
||||
@@ -185,7 +185,7 @@ struct TransferSenderTestLoopbackFrameListener : public uavcan::LoopbackFrameLis
|
||||
|
||||
TEST(TransferSender, Loopback)
|
||||
{
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
NullAllocator poolmgr;
|
||||
|
||||
SystemClockMock clockmock(100);
|
||||
CanDriverMock driver(2, clockmock);
|
||||
@@ -226,7 +226,7 @@ TEST(TransferSender, Loopback)
|
||||
|
||||
TEST(TransferSender, PassiveMode)
|
||||
{
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
NullAllocator poolmgr;
|
||||
|
||||
SystemClockMock clockmock(100);
|
||||
CanDriverMock driver(2, clockmock);
|
||||
|
||||
@@ -10,10 +10,8 @@
|
||||
TEST(TransferTestHelpers, Transfer)
|
||||
{
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * 8, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
uavcan::TransferBufferManager<128, 1> mgr(poolmgr);
|
||||
uavcan::TransferBufferManager<128, 1> mgr(pool);
|
||||
uavcan::TransferBufferAccessor tba(mgr, uavcan::TransferBufferManagerKey(0, uavcan::TransferTypeMessageUnicast));
|
||||
|
||||
uavcan::RxFrame frame(uavcan::Frame(123, uavcan::TransferTypeMessageBroadcast, 1, 0, 0, 0, true),
|
||||
|
||||
@@ -323,3 +323,14 @@ public:
|
||||
|
||||
template <int SIZE> void send(const Transfer (&transfers)[SIZE]) { send(transfers, SIZE); }
|
||||
};
|
||||
|
||||
/**
|
||||
* Zero allocator - always fails
|
||||
*/
|
||||
class NullAllocator : public uavcan::IPoolAllocator
|
||||
{
|
||||
public:
|
||||
virtual void* allocate(std::size_t) { return NULL; }
|
||||
virtual void deallocate(const void*) { }
|
||||
virtual uint16_t getNumBlocks() const { return 0; }
|
||||
};
|
||||
|
||||
@@ -45,11 +45,9 @@ TEST(Map, Basic)
|
||||
|
||||
static const int POOL_BLOCKS = 3;
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
typedef Map<std::string, std::string, 2> MapType;
|
||||
std::auto_ptr<MapType> map(new MapType(poolmgr));
|
||||
std::auto_ptr<MapType> map(new MapType(pool));
|
||||
|
||||
// Empty
|
||||
ASSERT_FALSE(map->access("hi"));
|
||||
@@ -208,11 +206,9 @@ TEST(Map, NoStatic)
|
||||
|
||||
static const int POOL_BLOCKS = 3;
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
typedef Map<std::string, std::string> MapType;
|
||||
std::auto_ptr<MapType> map(new MapType(poolmgr));
|
||||
std::auto_ptr<MapType> map(new MapType(pool));
|
||||
|
||||
// Empty
|
||||
ASSERT_FALSE(map->access("hi"));
|
||||
@@ -241,11 +237,9 @@ TEST(Map, PrimitiveKey)
|
||||
|
||||
static const int POOL_BLOCKS = 3;
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
typedef Map<short, short, 2> MapType;
|
||||
std::auto_ptr<MapType> map(new MapType(poolmgr));
|
||||
std::auto_ptr<MapType> map(new MapType(pool));
|
||||
|
||||
// Empty
|
||||
ASSERT_FALSE(map->access(1));
|
||||
|
||||
@@ -70,11 +70,9 @@ TEST(Multiset, Basic)
|
||||
|
||||
static const int POOL_BLOCKS = 3;
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
typedef Multiset<std::string, 2> MultisetType;
|
||||
std::auto_ptr<MultisetType> mset(new MultisetType(poolmgr));
|
||||
std::auto_ptr<MultisetType> mset(new MultisetType(pool));
|
||||
|
||||
typedef SummationOperator<std::string> StringConcatenationOperator;
|
||||
|
||||
@@ -220,11 +218,9 @@ TEST(Multiset, PrimitiveKey)
|
||||
|
||||
static const int POOL_BLOCKS = 3;
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
typedef Multiset<int, 2> MultisetType;
|
||||
std::auto_ptr<MultisetType> mset(new MultisetType(poolmgr));
|
||||
std::auto_ptr<MultisetType> mset(new MultisetType(pool));
|
||||
|
||||
// Empty
|
||||
mset->removeFirst(8);
|
||||
@@ -272,11 +268,9 @@ TEST(Multiset, NoncopyableWithCounter)
|
||||
|
||||
static const int POOL_BLOCKS = 3;
|
||||
uavcan::PoolAllocator<uavcan::MemPoolBlockSize * POOL_BLOCKS, uavcan::MemPoolBlockSize> pool;
|
||||
uavcan::PoolManager<2> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
typedef Multiset<NoncopyableWithCounter, 2> MultisetType;
|
||||
std::auto_ptr<MultisetType> mset(new MultisetType(poolmgr));
|
||||
std::auto_ptr<MultisetType> mset(new MultisetType(pool));
|
||||
|
||||
ASSERT_EQ(0, NoncopyableWithCounter::num_objects);
|
||||
ASSERT_EQ(0, mset->emplace()->value);
|
||||
|
||||
Reference in New Issue
Block a user