mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-19 23:49:06 +08:00
Added test for maximum transfer length
This commit is contained in:
parent
1886f0a8a9
commit
06d74d3213
@ -12,6 +12,8 @@
|
||||
namespace uavcan
|
||||
{
|
||||
|
||||
enum { MAX_TRANSFER_PAYLOAD_LEN = 439 }; ///< According to the standard
|
||||
|
||||
enum TransferType
|
||||
{
|
||||
TRANSFER_TYPE_SERVICE_RESPONSE = 0,
|
||||
|
||||
@ -198,7 +198,7 @@ TEST(Transfer, FrameParsing)
|
||||
can.data[0] = 41;
|
||||
ASSERT_TRUE(frame.parse(can));
|
||||
|
||||
can.id = CanFrame::FLAG_EFF |
|
||||
can.id = CanFrame::FLAG_EFF | // cppcheck-suppress duplicateExpression
|
||||
(2 << 0) | (1 << 3) | (0 << 4) | (0 << 10) | (uavcan::TRANSFER_TYPE_MESSAGE_UNICAST << 17) | (456 << 19);
|
||||
ASSERT_FALSE(frame.parse(can)); // Broadcast Src Node ID
|
||||
}
|
||||
|
||||
@ -265,3 +265,30 @@ TEST(TransferListener, Cleanup)
|
||||
ASSERT_TRUE(subscriber.matchAndPop(tr_mft));
|
||||
ASSERT_TRUE(subscriber.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
TEST(TransferListener, MaximumTransferLength)
|
||||
{
|
||||
uavcan::DataTypeDescriptor type(uavcan::DATA_TYPE_KIND_MESSAGE, 123, uavcan::DataTypeHash());
|
||||
for (int i = 0; i < uavcan::DataTypeHash::NUM_BYTES; i++)
|
||||
type.hash.value[i] = i | (i << 4);
|
||||
|
||||
uavcan::PoolManager<1> poolmgr;
|
||||
TestSubscriber<uavcan::MAX_TRANSFER_PAYLOAD_LEN * 2, 2, 2> subscriber(&type, &poolmgr);
|
||||
|
||||
static const std::string DATA_OK(uavcan::MAX_TRANSFER_PAYLOAD_LEN, 'z');
|
||||
|
||||
Emulator emulator(subscriber, type);
|
||||
const Transfer transfers[] =
|
||||
{
|
||||
emulator.makeTransfer(uavcan::TRANSFER_TYPE_MESSAGE_UNICAST, 1, DATA_OK),
|
||||
emulator.makeTransfer(uavcan::TRANSFER_TYPE_MESSAGE_BROADCAST, 1, DATA_OK)
|
||||
};
|
||||
|
||||
emulator.send(transfers);
|
||||
|
||||
ASSERT_TRUE(subscriber.matchAndPop(transfers[1])); // Broadcast is shorter, so will complete first
|
||||
ASSERT_TRUE(subscriber.matchAndPop(transfers[0]));
|
||||
|
||||
ASSERT_TRUE(subscriber.isEmpty());
|
||||
}
|
||||
|
||||
@ -184,8 +184,8 @@ std::vector<uavcan::RxFrame> serializeTransfer(const Transfer& transfer, uavcan:
|
||||
frm.makeLast();
|
||||
|
||||
offset += spres;
|
||||
EXPECT_GE(uavcan::Frame::INDEX_MAX, frame_index);
|
||||
frame_index++;
|
||||
EXPECT_TRUE(uavcan::Frame::INDEX_MAX >= frame_index);
|
||||
|
||||
const uavcan::RxFrame rxfrm(frm, ts_monotonic, ts_utc, 0);
|
||||
ts_monotonic += 1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user