mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-04-14 10:07:39 +08:00
NodeInfoRetriever basic test
This commit is contained in:
parent
2123853cae
commit
36dda9c017
@ -172,6 +172,8 @@ private:
|
||||
if (!TimerBase::isRunning())
|
||||
{
|
||||
TimerBase::startPeriodic(getTimerPollInterval());
|
||||
UAVCAN_TRACE("NodeInfoRetriever", "Timer started, interval %ld ms",
|
||||
static_cast<long>(getTimerPollInterval().toMSec()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -230,6 +232,7 @@ private:
|
||||
if (!requests_needed)
|
||||
{
|
||||
TimerBase::stop();
|
||||
UAVCAN_TRACE("NodeInfoRetriever", "Timer stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -398,6 +401,18 @@ public:
|
||||
{
|
||||
max_concurrent_requests_ = max(static_cast<uint8_t>(1), num);
|
||||
}
|
||||
|
||||
/**
|
||||
* These methods are needed mostly for testing.
|
||||
*/
|
||||
bool isRetrievingInProgress() const { return TimerBase::isRunning(); }
|
||||
|
||||
uint8_t getNumPendingRequests() const
|
||||
{
|
||||
const unsigned num = get_node_info_client_.getNumPendingCalls();
|
||||
UAVCAN_ASSERT(num <= 0xFF);
|
||||
return static_cast<uint8_t>(num);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -54,7 +54,8 @@ struct NodeInfoListener : public uavcan::INodeInfoListener
|
||||
|
||||
virtual void handleNodeStatusChange(const uavcan::NodeStatusMonitor::NodeStatusChangeEvent& event)
|
||||
{
|
||||
(void)event;
|
||||
std::cout << "NODE " << int(event.node_id.get()) << " STATUS CHANGE: "
|
||||
<< int(event.old_status.status_code) << " --> " << int(event.status.status_code) << std::endl;
|
||||
status_change_cnt++;
|
||||
}
|
||||
|
||||
@ -102,10 +103,16 @@ TEST(NodeInfoRetriever, Basic)
|
||||
|
||||
ASSERT_LE(0, provider->startAndPublish());
|
||||
|
||||
ASSERT_FALSE(retr.isRetrievingInProgress());
|
||||
ASSERT_EQ(0, retr.getNumPendingRequests());
|
||||
|
||||
/*
|
||||
* Waiting for discovery
|
||||
*/
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(1600));
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(50));
|
||||
ASSERT_TRUE(retr.isRetrievingInProgress());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(1500));
|
||||
ASSERT_FALSE(retr.isRetrievingInProgress());
|
||||
|
||||
ASSERT_EQ(2, listener.status_message_cnt);
|
||||
ASSERT_EQ(1, listener.status_change_cnt);
|
||||
@ -120,6 +127,8 @@ TEST(NodeInfoRetriever, Basic)
|
||||
/*
|
||||
* Declaring a bunch of different nodes that don't support GetNodeInfo
|
||||
*/
|
||||
ASSERT_FALSE(retr.isRetrievingInProgress());
|
||||
|
||||
retr.setNumRequestAttempts(3);
|
||||
|
||||
uavcan::TransferID tid;
|
||||
@ -128,12 +137,65 @@ TEST(NodeInfoRetriever, Basic)
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(11), 0, 10, tid);
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(12), 0, 10, tid);
|
||||
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(2100));
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(1, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(2, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(3, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(1000));
|
||||
ASSERT_TRUE(retr.isRetrievingInProgress());
|
||||
|
||||
tid.increment();
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(10), 0, 11, tid);
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(11), 0, 11, tid);
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(12), 0, 11, tid);
|
||||
|
||||
// TODO finish the test when the logic is fixed
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(1, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(2, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(3, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(1000));
|
||||
ASSERT_TRUE(retr.isRetrievingInProgress());
|
||||
|
||||
tid.increment();
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(10), 0, 12, tid);
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(11), 0, 12, tid);
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(12), 0, 10, tid); // Reset
|
||||
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(1, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(2, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(3, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(1000));
|
||||
ASSERT_TRUE(retr.isRetrievingInProgress());
|
||||
|
||||
EXPECT_EQ(11, listener.status_message_cnt);
|
||||
EXPECT_EQ(5, listener.status_change_cnt); // node 2 online/offline + 3 test nodes above
|
||||
EXPECT_EQ(2, listener.info_unavailable_cnt);
|
||||
|
||||
tid.increment();
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(12), 0, 11, tid);
|
||||
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(1, retr.getNumPendingRequests());
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(110));
|
||||
ASSERT_EQ(1, retr.getNumPendingRequests()); // Still one because two went offline
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(1200));
|
||||
ASSERT_TRUE(retr.isRetrievingInProgress());
|
||||
|
||||
tid.increment();
|
||||
publishNodeStatus(nodes.can_a, uavcan::NodeID(12), 0, 12, tid);
|
||||
|
||||
nodes.spinBoth(uavcan::MonotonicDuration::fromMSec(1200));
|
||||
ASSERT_FALSE(retr.isRetrievingInProgress()); // Out of attempts, stopping
|
||||
ASSERT_EQ(0, retr.getNumPendingRequests());
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user