mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-01 04:21:36 +08:00
TransportPerfCounter - counting transfers and transport errors
This commit is contained in:
@@ -68,12 +68,12 @@ TEST(Dispatcher, Reception)
|
||||
static const int NUM_SUBSCRIBERS = 6;
|
||||
SubscriberPtr subscribers[NUM_SUBSCRIBERS] =
|
||||
{
|
||||
SubscriberPtr(new Subscriber(TYPES[0], poolmgr)), // msg
|
||||
SubscriberPtr(new Subscriber(TYPES[0], poolmgr)), // msg // Two similar, yes
|
||||
SubscriberPtr(new Subscriber(TYPES[1], poolmgr)), // msg
|
||||
SubscriberPtr(new Subscriber(TYPES[2], poolmgr)), // srv
|
||||
SubscriberPtr(new Subscriber(TYPES[3], poolmgr)), // srv
|
||||
SubscriberPtr(new Subscriber(TYPES[3], poolmgr)) // srv // Repeat again
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransportPerfCounter(), TYPES[0], poolmgr)), // msg
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransportPerfCounter(), TYPES[0], poolmgr)), // msg // Two similar
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransportPerfCounter(), TYPES[1], poolmgr)), // msg
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransportPerfCounter(), TYPES[2], poolmgr)), // srv
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransportPerfCounter(), TYPES[3], poolmgr)), // srv
|
||||
SubscriberPtr(new Subscriber(dispatcher.getTransportPerfCounter(), TYPES[3], poolmgr)) // srv // Repeat again
|
||||
};
|
||||
|
||||
static const std::string DATA[6] =
|
||||
@@ -212,6 +212,13 @@ TEST(Dispatcher, Reception)
|
||||
ASSERT_EQ(0, dispatcher.getNumMessageListeners());
|
||||
ASSERT_EQ(0, dispatcher.getNumServiceRequestListeners());
|
||||
ASSERT_EQ(0, dispatcher.getNumServiceResponseListeners());
|
||||
|
||||
/*
|
||||
* Perf counters
|
||||
*/
|
||||
EXPECT_LT(0, dispatcher.getTransportPerfCounter().getErrorCount()); // Repeated transfers
|
||||
EXPECT_EQ(0, dispatcher.getTransportPerfCounter().getTxTransferCount());
|
||||
EXPECT_EQ(9, dispatcher.getTransportPerfCounter().getRxTransferCount());
|
||||
}
|
||||
|
||||
|
||||
@@ -260,6 +267,13 @@ TEST(Dispatcher, Transmission)
|
||||
|
||||
ASSERT_TRUE(driver.ifaces.at(0).tx.empty());
|
||||
ASSERT_TRUE(driver.ifaces.at(1).tx.empty());
|
||||
|
||||
/*
|
||||
* Perf counters - all empty because dispatcher itself does not count TX transfers
|
||||
*/
|
||||
EXPECT_EQ(0, dispatcher.getTransportPerfCounter().getErrorCount());
|
||||
EXPECT_EQ(0, dispatcher.getTransportPerfCounter().getTxTransferCount());
|
||||
EXPECT_EQ(0, dispatcher.getTransportPerfCounter().getRxTransferCount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,8 @@ TEST(TransferListener, BasicMFT)
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
poolmgr.addPool(&pool);
|
||||
|
||||
TestListener<256, 1, 1> subscriber(type, poolmgr);
|
||||
uavcan::TransportPerfCounter perf;
|
||||
TestListener<256, 1, 1> subscriber(perf, type, poolmgr);
|
||||
|
||||
/*
|
||||
* Test data
|
||||
@@ -89,7 +90,8 @@ TEST(TransferListener, CrcFailure)
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr; // No dynamic memory
|
||||
TestListener<256, 2, 2> subscriber(type, poolmgr); // Static buffer only, 2 entries
|
||||
uavcan::TransportPerfCounter perf;
|
||||
TestListener<256, 2, 2> subscriber(perf, type, poolmgr); // Static buffer only, 2 entries
|
||||
|
||||
/*
|
||||
* Generating transfers with damaged payload (CRC is not valid)
|
||||
@@ -131,8 +133,9 @@ TEST(TransferListener, BasicSFT)
|
||||
{
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr; // No dynamic memory. At all.
|
||||
TestListener<0, 0, 5> subscriber(type, poolmgr); // Max buf size is 0, i.e. SFT-only
|
||||
uavcan::PoolManager<1> poolmgr; // No dynamic memory. At all.
|
||||
uavcan::TransportPerfCounter perf;
|
||||
TestListener<0, 0, 5> subscriber(perf, type, poolmgr); // Max buf size is 0, i.e. SFT-only
|
||||
|
||||
TransferListenerEmulator emulator(subscriber, type);
|
||||
const Transfer transfers[] =
|
||||
@@ -166,8 +169,9 @@ TEST(TransferListener, Cleanup)
|
||||
{
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr; // No dynamic memory
|
||||
TestListener<256, 1, 2> subscriber(type, poolmgr); // Static buffer only, 1 entry
|
||||
uavcan::PoolManager<1> poolmgr; // No dynamic memory
|
||||
uavcan::TransportPerfCounter perf;
|
||||
TestListener<256, 1, 2> subscriber(perf, type, poolmgr); // Static buffer only, 1 entry
|
||||
|
||||
/*
|
||||
* Generating transfers
|
||||
@@ -221,7 +225,8 @@ TEST(TransferListener, MaximumTransferLength)
|
||||
const uavcan::DataTypeDescriptor type(uavcan::DataTypeKindMessage, 123, uavcan::DataTypeSignature(123456789), "A");
|
||||
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
TestListener<uavcan::MaxTransferPayloadLen * 2, 2, 2> subscriber(type, poolmgr);
|
||||
uavcan::TransportPerfCounter perf;
|
||||
TestListener<uavcan::MaxTransferPayloadLen * 2, 2, 2> subscriber(perf, type, poolmgr);
|
||||
|
||||
static const std::string DATA_OK(uavcan::MaxTransferPayloadLen, 'z');
|
||||
|
||||
|
||||
@@ -369,7 +369,7 @@ TEST(TransferReceiver, Restart)
|
||||
ASSERT_TRUE(matchBufferContent(bufmgr.access(gen.bufmgr_key), "3456781234567812345678"));
|
||||
ASSERT_EQ(0x3231, rcv.getLastTransferCrc());
|
||||
|
||||
ASSERT_EQ(3, rcv.yieldErrorCount());
|
||||
ASSERT_EQ(1, rcv.yieldErrorCount());
|
||||
ASSERT_EQ(0, rcv.yieldErrorCount());
|
||||
}
|
||||
|
||||
|
||||
@@ -113,9 +113,9 @@ TEST(TransferSender, Basic)
|
||||
}
|
||||
}
|
||||
|
||||
TestListener<512, 2, 2> sub_msg(TYPES[0], poolmgr);
|
||||
TestListener<512, 2, 2> sub_srv_req(TYPES[1], poolmgr);
|
||||
TestListener<512, 2, 2> sub_srv_resp(TYPES[1], poolmgr);
|
||||
TestListener<512, 2, 2> sub_msg(dispatcher_rx.getTransportPerfCounter(), TYPES[0], poolmgr);
|
||||
TestListener<512, 2, 2> sub_srv_req(dispatcher_rx.getTransportPerfCounter(), TYPES[1], poolmgr);
|
||||
TestListener<512, 2, 2> sub_srv_resp(dispatcher_rx.getTransportPerfCounter(), TYPES[1], poolmgr);
|
||||
|
||||
dispatcher_rx.registerMessageListener(&sub_msg);
|
||||
dispatcher_rx.registerServiceRequestListener(&sub_srv_req);
|
||||
@@ -145,6 +145,17 @@ TEST(TransferSender, Basic)
|
||||
|
||||
ASSERT_TRUE(sub_srv_resp.matchAndPop(TRANSFERS[5]));
|
||||
ASSERT_TRUE(sub_srv_resp.matchAndPop(TRANSFERS[7]));
|
||||
|
||||
/*
|
||||
* Perf counters
|
||||
*/
|
||||
EXPECT_EQ(0, dispatcher_tx.getTransportPerfCounter().getErrorCount());
|
||||
EXPECT_EQ(8, dispatcher_tx.getTransportPerfCounter().getTxTransferCount());
|
||||
EXPECT_EQ(0, dispatcher_tx.getTransportPerfCounter().getRxTransferCount());
|
||||
|
||||
EXPECT_EQ(0, dispatcher_rx.getTransportPerfCounter().getErrorCount());
|
||||
EXPECT_EQ(0, dispatcher_rx.getTransportPerfCounter().getTxTransferCount());
|
||||
EXPECT_EQ(8, dispatcher_rx.getTransportPerfCounter().getRxTransferCount());
|
||||
}
|
||||
|
||||
|
||||
@@ -202,4 +213,8 @@ TEST(TransferSender, Loopback)
|
||||
ASSERT_EQ(3, listener.last_frame.getPayloadLen());
|
||||
ASSERT_TRUE(TX_NODE_ID == listener.last_frame.getSrcNodeID());
|
||||
ASSERT_TRUE(listener.last_frame.isLast());
|
||||
|
||||
EXPECT_EQ(0, dispatcher.getTransportPerfCounter().getErrorCount());
|
||||
EXPECT_EQ(1, dispatcher.getTransportPerfCounter().getTxTransferCount());
|
||||
EXPECT_EQ(0, dispatcher.getTransportPerfCounter().getRxTransferCount());
|
||||
}
|
||||
|
||||
@@ -119,8 +119,9 @@ class TestListener : public uavcan::TransferListener<MAX_BUF_SIZE, NUM_STATIC_BU
|
||||
std::queue<Transfer> transfers_;
|
||||
|
||||
public:
|
||||
TestListener(const uavcan::DataTypeDescriptor& data_type, uavcan::IAllocator& allocator)
|
||||
: Base(data_type, allocator)
|
||||
TestListener(uavcan::TransportPerfCounter& perf, const uavcan::DataTypeDescriptor& data_type,
|
||||
uavcan::IAllocator& allocator)
|
||||
: Base(perf, data_type, allocator)
|
||||
{ }
|
||||
|
||||
void handleIncomingTransfer(uavcan::IncomingTransfer& transfer)
|
||||
|
||||
Reference in New Issue
Block a user