Commit 82dc1c34 authored by Don Gagne's avatar Don Gagne

Test APM missions

parent 3b9de374
...@@ -35,8 +35,9 @@ const MissionManagerTest::TestCase_t MissionManagerTest::_rgTestCases[] = { ...@@ -35,8 +35,9 @@ const MissionManagerTest::TestCase_t MissionManagerTest::_rgTestCases[] = {
{ "4\t0\t3\t21\t10\t20\t30\t40\t-10\t-20\t-30\t1\r\n", { 4, QGeoCoordinate(-10.0, -20.0, -30.0), MAV_CMD_NAV_LAND, 10.0, 20.0, 30.0, 40.0, true, false, MAV_FRAME_GLOBAL_RELATIVE_ALT } }, { "4\t0\t3\t21\t10\t20\t30\t40\t-10\t-20\t-30\t1\r\n", { 4, QGeoCoordinate(-10.0, -20.0, -30.0), MAV_CMD_NAV_LAND, 10.0, 20.0, 30.0, 40.0, true, false, MAV_FRAME_GLOBAL_RELATIVE_ALT } },
{ "5\t0\t3\t22\t10\t20\t30\t40\t-10\t-20\t-30\t1\r\n", { 5, QGeoCoordinate(-10.0, -20.0, -30.0), MAV_CMD_NAV_TAKEOFF, 10.0, 20.0, 30.0, 40.0, true, false, MAV_FRAME_GLOBAL_RELATIVE_ALT } }, { "5\t0\t3\t22\t10\t20\t30\t40\t-10\t-20\t-30\t1\r\n", { 5, QGeoCoordinate(-10.0, -20.0, -30.0), MAV_CMD_NAV_TAKEOFF, 10.0, 20.0, 30.0, 40.0, true, false, MAV_FRAME_GLOBAL_RELATIVE_ALT } },
{ "6\t0\t2\t112\t10\t20\t30\t40\t-10\t-20\t-30\t1\r\n", { 6, QGeoCoordinate(-10.0, -20.0, -30.0), MAV_CMD_CONDITION_DELAY, 10.0, 20.0, 30.0, 40.0, true, false, MAV_FRAME_MISSION } }, { "6\t0\t2\t112\t10\t20\t30\t40\t-10\t-20\t-30\t1\r\n", { 6, QGeoCoordinate(-10.0, -20.0, -30.0), MAV_CMD_CONDITION_DELAY, 10.0, 20.0, 30.0, 40.0, true, false, MAV_FRAME_MISSION } },
{ "7\t0\t2\t177\t10\t20\t30\t40\t-10\t-20\t-30\t1\r\n", { 7, QGeoCoordinate(-10.0, -20.0, -30.0), MAV_CMD_DO_JUMP, 10.0, 20.0, 30.0, 40.0, true, false, MAV_FRAME_MISSION } }, { "7\t0\t2\t177\t3\t20\t30\t40\t-10\t-20\t-30\t1\r\n", { 7, QGeoCoordinate(-10.0, -20.0, -30.0), MAV_CMD_DO_JUMP, 3, 20.0, 30.0, 40.0, true, false, MAV_FRAME_MISSION } },
}; };
const size_t MissionManagerTest::_cTestCases = sizeof(_rgTestCases)/sizeof(_rgTestCases[0]);
MissionManagerTest::MissionManagerTest(void) MissionManagerTest::MissionManagerTest(void)
: _mockLink(NULL) : _mockLink(NULL)
...@@ -44,7 +45,7 @@ MissionManagerTest::MissionManagerTest(void) ...@@ -44,7 +45,7 @@ MissionManagerTest::MissionManagerTest(void)
} }
void MissionManagerTest::init(void) void MissionManagerTest::_initForFirmwareType(MAV_AUTOPILOT firmwareType)
{ {
UnitTest::init(); UnitTest::init();
...@@ -53,6 +54,7 @@ void MissionManagerTest::init(void) ...@@ -53,6 +54,7 @@ void MissionManagerTest::init(void)
_mockLink = new MockLink(); _mockLink = new MockLink();
Q_CHECK_PTR(_mockLink); Q_CHECK_PTR(_mockLink);
_mockLink->setFirmwareType(firmwareType);
LinkManager::instance()->_addLink(_mockLink); LinkManager::instance()->_addLink(_mockLink);
linkMgr->connectLink(_mockLink); linkMgr->connectLink(_mockLink);
...@@ -110,7 +112,7 @@ void MissionManagerTest::_checkInProgressValues(bool inProgress) ...@@ -110,7 +112,7 @@ void MissionManagerTest::_checkInProgressValues(bool inProgress)
QCOMPARE(signalArgs[0].toBool(), inProgress); QCOMPARE(signalArgs[0].toBool(), inProgress);
} }
void MissionManagerTest::_readEmptyVehicle(void) void MissionManagerTest::_readEmptyVehicleWorker(void)
{ {
_missionManager->requestMissionItems(); _missionManager->requestMissionItems();
...@@ -125,8 +127,7 @@ void MissionManagerTest::_readEmptyVehicle(void) ...@@ -125,8 +127,7 @@ void MissionManagerTest::_readEmptyVehicle(void)
// inProgressChanged signal to signal completion. // inProgressChanged signal to signal completion.
_multiSpy->waitForSignalByIndex(newMissionItemsAvailableSignalIndex, _signalWaitTime); _multiSpy->waitForSignalByIndex(newMissionItemsAvailableSignalIndex, _signalWaitTime);
_multiSpy->waitForSignalByIndex(inProgressChangedSignalIndex, _signalWaitTime); _multiSpy->waitForSignalByIndex(inProgressChangedSignalIndex, _signalWaitTime);
QCOMPARE(_multiSpy->checkSignalByMask(newMissionItemsAvailableSignalMask | inProgressChangedSignalMask), true); QCOMPARE(_multiSpy->checkOnlySignalByMask(newMissionItemsAvailableSignalMask | inProgressChangedSignalMask), true);
QCOMPARE(_multiSpy->checkNoSignalByMask(canEditChangedSignalMask), true);
_checkInProgressValues(false); _checkInProgressValues(false);
// Vehicle should have no items at this point // Vehicle should have no items at this point
...@@ -143,7 +144,6 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f ...@@ -143,7 +144,6 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f
} }
// Setup our test case data // Setup our test case data
const size_t cTestCases = sizeof(_rgTestCases)/sizeof(_rgTestCases[0]);
QmlObjectListModel* list = new QmlObjectListModel(); QmlObjectListModel* list = new QmlObjectListModel();
// Editor has a home position item on the front, so we do the same // Editor has a home position item on the front, so we do the same
...@@ -156,7 +156,7 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f ...@@ -156,7 +156,7 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f
homeItem->setSequenceNumber(0); homeItem->setSequenceNumber(0);
list->insert(0, homeItem); list->insert(0, homeItem);
for (size_t i=0; i<cTestCases; i++) { for (size_t i=0; i<_cTestCases; i++) {
const TestCase_t* testCase = &_rgTestCases[i]; const TestCase_t* testCase = &_rgTestCases[i];
MissionItem* item = new MissionItem(list); MissionItem* item = new MissionItem(list);
...@@ -175,7 +175,7 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f ...@@ -175,7 +175,7 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f
} }
// Send the items to the vehicle // Send the items to the vehicle
_missionManager->writeMissionItems(*list, true /* skipFirstItem */); _missionManager->writeMissionItems(*list);
// writeMissionItems should emit these signals before returning: // writeMissionItems should emit these signals before returning:
// inProgressChanged // inProgressChanged
...@@ -197,8 +197,15 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f ...@@ -197,8 +197,15 @@ void MissionManagerTest::_writeItems(MockLinkMissionItemHandler::FailureMode_t f
// Validate inProgressChanged signal value // Validate inProgressChanged signal value
_checkInProgressValues(false); _checkInProgressValues(false);
// We should have gotten back all mission items // Validate item count in mission manager
QCOMPARE(_missionManager->missionItems()->count(), (int)cTestCases);
int expectedCount = (int)_cTestCases;
if (_mockLink->getFirmwareType() == MAV_AUTOPILOT_ARDUPILOTMEGA) {
// Home position at position 0 comes from vehicle
expectedCount++;
}
QCOMPARE(_missionManager->missionItems()->count(), expectedCount);
} else { } else {
// This should be a failed run // This should be a failed run
...@@ -260,6 +267,7 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode ...@@ -260,6 +267,7 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode
QCOMPARE(_multiSpy->checkSignalByMask(newMissionItemsAvailableSignalMask | inProgressChangedSignalMask), true); QCOMPARE(_multiSpy->checkSignalByMask(newMissionItemsAvailableSignalMask | inProgressChangedSignalMask), true);
QCOMPARE(_multiSpy->checkNoSignalByMask(canEditChangedSignalMask), true); QCOMPARE(_multiSpy->checkNoSignalByMask(canEditChangedSignalMask), true);
_checkInProgressValues(false); _checkInProgressValues(false);
} else { } else {
// This should be a failed run // This should be a failed run
...@@ -292,7 +300,11 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode ...@@ -292,7 +300,11 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode
size_t cMissionItemsExpected; size_t cMissionItemsExpected;
if (failureMode == MockLinkMissionItemHandler::FailNone || failFirstTimeOnly == true) { if (failureMode == MockLinkMissionItemHandler::FailNone || failFirstTimeOnly == true) {
cMissionItemsExpected = sizeof(_rgTestCases)/sizeof(_rgTestCases[0]); cMissionItemsExpected = (int)_cTestCases;
if (_mockLink->getFirmwareType() == MAV_AUTOPILOT_ARDUPILOTMEGA) {
// Home position at position 0 comes from vehicle
cMissionItemsExpected++;
}
} else { } else {
switch (failureMode) { switch (failureMode) {
case MockLinkMissionItemHandler::FailReadRequestListNoResponse: case MockLinkMissionItemHandler::FailReadRequestListNoResponse:
...@@ -316,27 +328,48 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode ...@@ -316,27 +328,48 @@ void MissionManagerTest::_roundTripItems(MockLinkMissionItemHandler::FailureMode
QCOMPARE(_missionManager->missionItems()->count(), (int)cMissionItemsExpected); QCOMPARE(_missionManager->missionItems()->count(), (int)cMissionItemsExpected);
QCOMPARE(_missionManager->canEdit(), true); QCOMPARE(_missionManager->canEdit(), true);
for (size_t i=0; i<cMissionItemsExpected; i++) { size_t firstActualItem = 0;
const TestCase_t* testCase = &_rgTestCases[i]; if (_mockLink->getFirmwareType() == MAV_AUTOPILOT_ARDUPILOTMEGA) {
MissionItem* actual = qobject_cast<MissionItem*>(_missionManager->missionItems()->get(i)); // First item is home position, don't validate it
firstActualItem++;
}
qDebug() << "Test case" << i; int testCaseIndex = 0;
QCOMPARE(actual->sequenceNumber(), testCase->expectedItem.sequenceNumber); for (size_t actualItemIndex=firstActualItem; actualItemIndex<cMissionItemsExpected; actualItemIndex++) {
const TestCase_t* testCase = &_rgTestCases[testCaseIndex];
int expectedSequenceNumber = testCase->expectedItem.sequenceNumber;
int expectedParam1 = (int)testCase->expectedItem.param1;
if (_mockLink->getFirmwareType() == MAV_AUTOPILOT_ARDUPILOTMEGA) {
// Account for home position in first item
expectedSequenceNumber++;
if (testCase->expectedItem.command == MAV_CMD_DO_JUMP) {
// Expected data in test case is for PX4
expectedParam1++;
}
}
MissionItem* actual = qobject_cast<MissionItem*>(_missionManager->missionItems()->get(actualItemIndex));
qDebug() << "Test case" << testCaseIndex;
QCOMPARE(actual->sequenceNumber(), expectedSequenceNumber);
QCOMPARE(actual->coordinate().latitude(), testCase->expectedItem.coordinate.latitude()); QCOMPARE(actual->coordinate().latitude(), testCase->expectedItem.coordinate.latitude());
QCOMPARE(actual->coordinate().longitude(), testCase->expectedItem.coordinate.longitude()); QCOMPARE(actual->coordinate().longitude(), testCase->expectedItem.coordinate.longitude());
QCOMPARE(actual->coordinate().altitude(), testCase->expectedItem.coordinate.altitude()); QCOMPARE(actual->coordinate().altitude(), testCase->expectedItem.coordinate.altitude());
QCOMPARE((int)actual->command(), (int)testCase->expectedItem.command); QCOMPARE((int)actual->command(), (int)testCase->expectedItem.command);
QCOMPARE((int)actual->param1(), (int)expectedParam1);
QCOMPARE(actual->param2(), testCase->expectedItem.param2); QCOMPARE(actual->param2(), testCase->expectedItem.param2);
QCOMPARE(actual->param3(), testCase->expectedItem.param3); QCOMPARE(actual->param3(), testCase->expectedItem.param3);
QCOMPARE(actual->param4(), testCase->expectedItem.param4); QCOMPARE(actual->param4(), testCase->expectedItem.param4);
QCOMPARE(actual->autoContinue(), testCase->expectedItem.autocontinue); QCOMPARE(actual->autoContinue(), testCase->expectedItem.autocontinue);
QCOMPARE(actual->frame(), testCase->expectedItem.frame); QCOMPARE(actual->frame(), testCase->expectedItem.frame);
QCOMPARE(actual->param1(), testCase->expectedItem.param1);
testCaseIndex++;
} }
} }
void MissionManagerTest::_testWriteFailureHandling(void) void MissionManagerTest::_testWriteFailureHandlingWorker(void)
{ {
/* /*
/// Called to send a MISSION_ACK message while the MissionManager is in idle state /// Called to send a MISSION_ACK message while the MissionManager is in idle state
...@@ -378,7 +411,7 @@ void MissionManagerTest::_testWriteFailureHandling(void) ...@@ -378,7 +411,7 @@ void MissionManagerTest::_testWriteFailureHandling(void)
} }
} }
void MissionManagerTest::_testReadFailureHandling(void) void MissionManagerTest::_testReadFailureHandlingWorker(void)
{ {
/* /*
/// Called to send a MISSION_ACK message while the MissionManager is in idle state /// Called to send a MISSION_ACK message while the MissionManager is in idle state
...@@ -417,3 +450,40 @@ void MissionManagerTest::_testReadFailureHandling(void) ...@@ -417,3 +450,40 @@ void MissionManagerTest::_testReadFailureHandling(void)
_mockLink->resetMissionItemHandler(); _mockLink->resetMissionItemHandler();
} }
} }
void MissionManagerTest::_testEmptyVehicleAPM(void)
{
_initForFirmwareType(MAV_AUTOPILOT_ARDUPILOTMEGA);
_readEmptyVehicleWorker();
}
void MissionManagerTest::_testEmptyVehiclePX4(void)
{
_initForFirmwareType(MAV_AUTOPILOT_ARDUPILOTMEGA);
_readEmptyVehicleWorker();
}
void MissionManagerTest::_testWriteFailureHandlingAPM(void)
{
_initForFirmwareType(MAV_AUTOPILOT_ARDUPILOTMEGA);
_testWriteFailureHandlingWorker();
}
void MissionManagerTest::_testReadFailureHandlingAPM(void)
{
_initForFirmwareType(MAV_AUTOPILOT_ARDUPILOTMEGA);
_testReadFailureHandlingWorker();
}
void MissionManagerTest::_testWriteFailureHandlingPX4(void)
{
_initForFirmwareType(MAV_AUTOPILOT_PX4);
_testWriteFailureHandlingWorker();
}
void MissionManagerTest::_testReadFailureHandlingPX4(void)
{
_initForFirmwareType(MAV_AUTOPILOT_PX4);
_testReadFailureHandlingWorker();
}
...@@ -39,18 +39,23 @@ public: ...@@ -39,18 +39,23 @@ public:
MissionManagerTest(void); MissionManagerTest(void);
private slots: private slots:
void init(void);
void cleanup(void); void cleanup(void);
void _testWriteFailureHandling(void); void _testEmptyVehicleAPM(void);
void _testReadFailureHandling(void); void _testEmptyVehiclePX4(void);
void _testWriteFailureHandlingAPM(void);
void _testReadFailureHandlingAPM(void);
void _testWriteFailureHandlingPX4(void);
void _testReadFailureHandlingPX4(void);
private: private:
void _initForFirmwareType(MAV_AUTOPILOT firmwareType);
void _checkInProgressValues(bool inProgress); void _checkInProgressValues(bool inProgress);
void _roundTripItems(MockLinkMissionItemHandler::FailureMode_t failureMode, MissionManager::ErrorCode_t errorCode, bool failFirstTimeOnly); void _roundTripItems(MockLinkMissionItemHandler::FailureMode_t failureMode, MissionManager::ErrorCode_t errorCode, bool failFirstTimeOnly);
void _writeItems(MockLinkMissionItemHandler::FailureMode_t failureMode, MissionManager::ErrorCode_t errorCode, bool failFirstTimeOnly); void _writeItems(MockLinkMissionItemHandler::FailureMode_t failureMode, MissionManager::ErrorCode_t errorCode, bool failFirstTimeOnly);
void _testWriteFailureHandlingWorker(void);
void _readEmptyVehicle(void); void _testReadFailureHandlingWorker(void);
void _readEmptyVehicleWorker(void);
MockLink* _mockLink; MockLink* _mockLink;
MissionManager* _missionManager; MissionManager* _missionManager;
...@@ -93,6 +98,7 @@ private: ...@@ -93,6 +98,7 @@ private:
} TestCase_t; } TestCase_t;
static const TestCase_t _rgTestCases[]; static const TestCase_t _rgTestCases[];
static const size_t _cTestCases;
static const int _signalWaitTime = MissionManager::_ackTimeoutMilliseconds * MissionManager::_maxRetryCount * 2; static const int _signalWaitTime = MissionManager::_ackTimeoutMilliseconds * MissionManager::_maxRetryCount * 2;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment