228 lines
8.8 KiB
C++
228 lines
8.8 KiB
C++
/****************************************************************************
|
|
*
|
|
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
|
|
*
|
|
* QGroundControl is licensed according to the terms in the file
|
|
* COPYING.md in the root of the source code directory.
|
|
*
|
|
****************************************************************************/
|
|
|
|
|
|
#include "ParameterManagerTest.h"
|
|
#include "MultiVehicleManager.h"
|
|
#include "Vehicle.h"
|
|
#include "ParameterManager.h"
|
|
#include "MockLinkFTP.h"
|
|
|
|
#include <QtTest/QTest>
|
|
#include <QtTest/QSignalSpy>
|
|
|
|
/// Test failure modes which should still lead to param load success
|
|
void ParameterManagerTest::_noFailureWorker(MockConfiguration::FailureMode_t failureMode)
|
|
{
|
|
Q_ASSERT(!_mockLink);
|
|
_mockLink = MockLink::startPX4MockLink(false, failureMode);
|
|
|
|
MultiVehicleManager* vehicleMgr = MultiVehicleManager::instance();
|
|
QVERIFY(vehicleMgr);
|
|
|
|
// Wait for the Vehicle to get created
|
|
QSignalSpy spyVehicle(vehicleMgr, SIGNAL(activeVehicleAvailableChanged(bool)));
|
|
QCOMPARE(spyVehicle.wait(5000), true);
|
|
QCOMPARE(spyVehicle.count(), 1);
|
|
QList<QVariant> arguments = spyVehicle.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toBool(), true);
|
|
|
|
Vehicle* vehicle = vehicleMgr->activeVehicle();
|
|
QVERIFY(vehicle);
|
|
|
|
// We should get progress bar updates during load
|
|
QSignalSpy spyProgress(vehicle->parameterManager(), SIGNAL(loadProgressChanged(float)));
|
|
QCOMPARE(spyProgress.wait(2000), true);
|
|
arguments = spyProgress.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QVERIFY(arguments.at(0).toFloat() > 0.0f);
|
|
|
|
// When param load is complete we get the param ready signal
|
|
QSignalSpy spyParamsReady(vehicleMgr, SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
|
|
QCOMPARE(spyParamsReady.wait(60000), true);
|
|
arguments = spyParamsReady.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toBool(), true);
|
|
|
|
// Progress should have been set back to 0
|
|
arguments = spyProgress.takeLast();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toFloat(), 0.0f);
|
|
}
|
|
|
|
|
|
void ParameterManagerTest::_noFailure(void)
|
|
{
|
|
_noFailureWorker(MockConfiguration::FailNone);
|
|
}
|
|
|
|
void ParameterManagerTest::_requestListMissingParamSuccess(void)
|
|
{
|
|
_noFailureWorker(MockConfiguration::FailMissingParamOnInitialReqest);
|
|
}
|
|
|
|
// Test no response to param_request_list
|
|
void ParameterManagerTest::_requestListNoResponse(void)
|
|
{
|
|
Q_ASSERT(!_mockLink);
|
|
_mockLink = MockLink::startPX4MockLink(false, MockConfiguration::FailParamNoReponseToRequestList);
|
|
|
|
MultiVehicleManager* vehicleMgr = MultiVehicleManager::instance();
|
|
QVERIFY(vehicleMgr);
|
|
|
|
// Wait for the Vehicle to get created
|
|
QSignalSpy spyVehicle(vehicleMgr, SIGNAL(activeVehicleAvailableChanged(bool)));
|
|
QCOMPARE(spyVehicle.wait(5000), true);
|
|
QCOMPARE(spyVehicle.count(), 1);
|
|
QList<QVariant> arguments = spyVehicle.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toBool(), true);
|
|
|
|
Vehicle* vehicle = vehicleMgr->activeVehicle();
|
|
QVERIFY(vehicle);
|
|
|
|
QSignalSpy spyParamsReady(vehicleMgr, SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
|
|
QSignalSpy spyProgress(vehicle->parameterManager(), SIGNAL(loadProgressChanged(float)));
|
|
|
|
// We should not get any progress bar updates, nor a parameter ready signal
|
|
QCOMPARE(spyProgress.wait(500), false);
|
|
QCOMPARE(spyParamsReady.wait(40000), false);
|
|
}
|
|
|
|
// MockLink will fail to send a param on initial request, it will also fail to send it on subsequent
|
|
// param_read requests.
|
|
void ParameterManagerTest::_requestListMissingParamFail(void)
|
|
{
|
|
Q_ASSERT(!_mockLink);
|
|
_mockLink = MockLink::startPX4MockLink(false, MockConfiguration::FailMissingParamOnAllRequests);
|
|
|
|
MultiVehicleManager* vehicleMgr = MultiVehicleManager::instance();
|
|
QVERIFY(vehicleMgr);
|
|
|
|
// Wait for the Vehicle to get created
|
|
QSignalSpy spyVehicle(vehicleMgr, SIGNAL(activeVehicleAvailableChanged(bool)));
|
|
QCOMPARE(spyVehicle.wait(5000), true);
|
|
QCOMPARE(spyVehicle.count(), 1);
|
|
QList<QVariant> arguments = spyVehicle.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toBool(), true);
|
|
|
|
Vehicle* vehicle = vehicleMgr->activeVehicle();
|
|
QVERIFY(vehicle);
|
|
|
|
QSignalSpy spyParamsReady(vehicleMgr, SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
|
|
QSignalSpy spyProgress(vehicle->parameterManager(), SIGNAL(loadProgressChanged(float)));
|
|
|
|
// We will get progress bar updates, since it will fail after getting partially through the request
|
|
QCOMPARE(spyProgress.wait(2000), true);
|
|
arguments = spyProgress.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QVERIFY(arguments.at(0).toFloat() > 0.0f);
|
|
|
|
// We should get a parameters ready signal, but Vehicle should indicate missing params
|
|
QCOMPARE(spyParamsReady.wait(40000), true);
|
|
QCOMPARE(vehicle->parameterManager()->missingParameters(), true);
|
|
}
|
|
|
|
void ParameterManagerTest::_FTPnoFailure()
|
|
{
|
|
Q_ASSERT(!_mockLink);
|
|
_mockLink = MockLink::startAPMArduPlaneMockLink(false, MockConfiguration::FailParamNoReponseToRequestList);
|
|
_mockLink->mockLinkFTP()->enableBinParamFile(true);
|
|
MultiVehicleManager* vehicleMgr = MultiVehicleManager::instance();
|
|
QVERIFY(vehicleMgr);
|
|
|
|
// Wait for the Vehicle to get created
|
|
QSignalSpy spyVehicle(vehicleMgr, SIGNAL(activeVehicleAvailableChanged(bool)));
|
|
// When param load is complete we get the param ready signal
|
|
QSignalSpy spyParamsReady(vehicleMgr, SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
|
|
QCOMPARE(spyVehicle.wait(5000), true);
|
|
QCOMPARE(spyVehicle.count(), 1);
|
|
QList<QVariant> arguments = spyVehicle.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toBool(), true);
|
|
Vehicle* vehicle = vehicleMgr->activeVehicle();
|
|
QVERIFY(vehicle);
|
|
|
|
spyParamsReady.wait(5000);
|
|
QCOMPARE(spyParamsReady.count(), 1);
|
|
arguments = spyParamsReady.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toBool(), true);
|
|
|
|
// Request all parameters again and check the progress bar. The initial parameterdownload
|
|
// is so fast that I cannot connect to the loadprogress early enough.
|
|
QSignalSpy spyProgress(vehicle->parameterManager(), SIGNAL(loadProgressChanged(float)));
|
|
vehicle->parameterManager()->refreshAllParameters();
|
|
spyParamsReady.wait(5000);
|
|
QVERIFY(spyProgress.count() > 1);
|
|
arguments = spyProgress.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QVERIFY(arguments.at(0).toFloat() > 0.0f);
|
|
// Progress should have been set back to 0
|
|
arguments = spyProgress.takeLast();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toFloat(), 0.0f);
|
|
}
|
|
|
|
#if 0
|
|
void ParameterManagerTest::_FTPChangeParam()
|
|
{
|
|
Q_ASSERT(!_mockLink);
|
|
_mockLink = MockLink::startAPMArduPlaneMockLink(false, MockConfiguration::FailParamNoReponseToRequestList);
|
|
_mockLink->mockLinkFTP()->enableBinParamFile(true);
|
|
MultiVehicleManager* vehicleMgr = MultiVehicleManager::instance();
|
|
QVERIFY(vehicleMgr);
|
|
|
|
// Wait for the Vehicle to get created
|
|
QSignalSpy spyVehicle(vehicleMgr, SIGNAL(activeVehicleAvailableChanged(bool)));
|
|
// When param load is complete we get the param ready signal
|
|
QSignalSpy spyParamsReady(vehicleMgr, SIGNAL(parameterReadyVehicleAvailableChanged(bool)));
|
|
QCOMPARE(spyVehicle.wait(5000), true);
|
|
QCOMPARE(spyVehicle.count(), 1);
|
|
QList<QVariant> arguments = spyVehicle.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toBool(), true);
|
|
Vehicle* vehicle = vehicleMgr->activeVehicle();
|
|
QVERIFY(vehicle);
|
|
|
|
if (spyParamsReady.count() == 0)
|
|
spyParamsReady.wait(5000);
|
|
QCOMPARE(spyParamsReady.count(), 1);
|
|
arguments = spyParamsReady.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toBool(), true);
|
|
|
|
// Now try to change a parameter and check the progress
|
|
QSignalSpy spyProgress(vehicle->parameterManager(), SIGNAL(loadProgressChanged(float)));
|
|
Fact* fact = vehicle->parameterManager()->getParameter(MAV_COMP_ID_AUTOPILOT1, "THR_MIN");
|
|
QVERIFY(fact);
|
|
float value = fact->rawValue().toFloat();
|
|
QCOMPARE(value, 0.0);
|
|
float testvalue = 0.87f;
|
|
QVariant sendv = testvalue;
|
|
fact->setRawValue(sendv); // This should trigger a parameter upload to the vehicle
|
|
/* That should set the progress to 0.5 and then back to 0 */
|
|
spyProgress.wait(1000);
|
|
if (spyProgress.count() < 2)
|
|
spyProgress.wait(1000);
|
|
QCOMPARE(spyProgress.count(), 2);
|
|
arguments = spyProgress.takeFirst();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QVERIFY(arguments.at(0).toFloat() > 0.4f);
|
|
|
|
// Progress should have been set back to 0
|
|
Q_ASSERT(!spyProgress.empty());
|
|
arguments = spyProgress.takeLast();
|
|
QCOMPARE(arguments.count(), 1);
|
|
QCOMPARE(arguments.at(0).toFloat(), 0.0f);
|
|
}
|
|
#endif
|