fix backtace output
fix some tests to make sure they have enough time to verify
This commit is contained in:
parent
c1a4d35387
commit
da7cfc27f8
@ -70,8 +70,7 @@ static void printBacktrace()
|
||||
}
|
||||
}
|
||||
|
||||
qCCritical(dcApplication) << QString("[%1] %2").arg(i).arg(symbolList[i]);
|
||||
|
||||
QString functionString;
|
||||
if (begin_name && begin_offset && end_offset && begin_name < begin_offset) {
|
||||
int status;
|
||||
*begin_name++ = '\0';
|
||||
@ -80,14 +79,29 @@ static void printBacktrace()
|
||||
char* ret = abi::__cxa_demangle(begin_name, functionName, &funktionNameSize, &status);
|
||||
if (status == 0) {
|
||||
functionName = ret;
|
||||
qCritical(dcApplication) << QString(" %1").arg(QString().sprintf("%s+%s", functionName, begin_offset));
|
||||
functionString = QString(" %1").arg(QString().sprintf("%s+%s", functionName, begin_offset));
|
||||
} else {
|
||||
qCCritical(dcApplication) << QString(" %1").arg(QString().sprintf("%s()+%s", begin_name, begin_offset));
|
||||
functionString = QString(" %1").arg(QString().sprintf("%s()+%s", begin_name, begin_offset));
|
||||
}
|
||||
}
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 2, 0))
|
||||
// qCCritical was introduced int Qt 5.2.0
|
||||
qCWarning(dcApplication) << QString("[%1] %2").arg(i).arg(symbolList[i]);
|
||||
if (!functionString.isEmpty())
|
||||
qCWarning(dcApplication) << functionString;
|
||||
|
||||
qCWarning(dcApplication) << QString(" %1").arg(line.remove("\n"));
|
||||
#else
|
||||
qCCritical(dcApplication) << QString("[%1] %2").arg(i).arg(symbolList[i]);
|
||||
if (!functionString.isEmpty())
|
||||
qCCritical(dcApplication) << functionString;
|
||||
|
||||
qCCritical(dcApplication) << QString(" %1").arg(line.remove("\n"));
|
||||
#endif // QT_VERSION
|
||||
|
||||
}
|
||||
|
||||
free(functionName);
|
||||
free(symbolList);
|
||||
}
|
||||
@ -109,7 +123,7 @@ static void catchUnixSignals(const std::vector<int>& quitSignals, const std::vec
|
||||
qCDebug(dcApplication) << "Cought SIGHUP quit signal...";
|
||||
break;
|
||||
case SIGSEGV: {
|
||||
qCCritical(dcApplication) << "Cought SIGSEGV signal. Segmentation fault!";
|
||||
qCDebug(dcApplication) << "Cought SIGSEGV signal. Segmentation fault!";
|
||||
printBacktrace();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -160,7 +160,7 @@ QVariant GuhTestBase::injectAndWait(const QString &method, const QVariantMap &pa
|
||||
|
||||
QVariant GuhTestBase::checkNotification(const QSignalSpy &spy, const QString ¬ification)
|
||||
{
|
||||
qDebug() << "Got" << spy.count() << "notifications while waiting for" << notification;
|
||||
//qDebug() << "Got" << spy.count() << "notifications while waiting for" << notification;
|
||||
for (int i = 0; i < spy.count(); i++) {
|
||||
// Make sure the response it a valid JSON string
|
||||
QJsonParseError error;
|
||||
@ -180,7 +180,7 @@ QVariant GuhTestBase::checkNotification(const QSignalSpy &spy, const QString &no
|
||||
|
||||
QVariantList GuhTestBase::checkNotifications(const QSignalSpy &spy, const QString ¬ification)
|
||||
{
|
||||
qDebug() << "Got" << spy.count() << "notifications while waiting for" << notification;
|
||||
//qDebug() << "Got" << spy.count() << "notifications while waiting for" << notification;
|
||||
QVariantList notificationList;
|
||||
for (int i = 0; i < spy.count(); i++) {
|
||||
// Make sure the response it a valid JSON string
|
||||
|
||||
@ -206,39 +206,49 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
|
||||
|
||||
// trigger state change in mock device
|
||||
int newVal = 1111;
|
||||
int newVal = 38;
|
||||
QUuid stateTypeId("80baec19-54de-4948-ac46-31eabfaceb83");
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(stateTypeId.toString()).arg(newVal)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
reply->deleteLater();
|
||||
|
||||
clientSpy.wait();
|
||||
clientSpy.wait(2000);
|
||||
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
QVariant stateChangedVariants = checkNotification(clientSpy, "Devices.StateChanged");
|
||||
QVERIFY2(!stateChangedVariants.isNull(), "Did not get Devices.StateChanged notification.");
|
||||
QVariantList stateChangedVariants = checkNotifications(clientSpy, "Devices.StateChanged");
|
||||
QVERIFY2(!stateChangedVariants.isEmpty(), "Did not get Devices.StateChanged notification.");
|
||||
qDebug() << "got" << stateChangedVariants.count() << "Devices.StateChanged notifications";
|
||||
|
||||
// qDebug() << "got" << stateChangedVariants.count() << "Devices.StateChanged notifications";
|
||||
bool found = false;
|
||||
foreach (const QVariant &stateChangedVariant, stateChangedVariants) {
|
||||
if (stateChangedVariant.toMap().value("params").toMap().value("stateTypeId").toUuid() == stateTypeId) {
|
||||
found = true;
|
||||
QCOMPARE(stateChangedVariant.toMap().value("params").toMap().value("value").toInt(), newVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
QVERIFY2(found, "Could not find the correct Devices.StateChanged notification");
|
||||
|
||||
// Make sure the logg notification contains all the stuff we expect
|
||||
QVariantList loggEntryAddedVariant = checkNotifications(clientSpy, "Logging.LogEntryAdded");
|
||||
QVERIFY2(!loggEntryAddedVariant.isEmpty(), "Did not get Logging.LogEntryAdded notification.");
|
||||
qDebug() << "got" << loggEntryAddedVariant.count() << "Logging.LogEntryAdded notifications";
|
||||
|
||||
// bool found = false;
|
||||
// foreach (const QVariant &stateChangedVariant, stateChangedVariants) {
|
||||
// if (stateChangedVariant.toMap().value("params").toMap().value("stateTypeId").toUuid() == stateTypeId) {
|
||||
// QCOMPARE(stateChangedVariant.toMap().value("params").toMap().value("value").toInt(), newVal);
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// QCOMPARE(found, true);
|
||||
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
QVariant loggEntryAddedVariant = checkNotification(clientSpy, "Logging.LogEntryAdded");
|
||||
QVERIFY2(!loggEntryAddedVariant.isNull(), "Did not get Logging.LogEntryAdded notification.");
|
||||
QVariantList eventTriggeredVariants = checkNotifications(clientSpy, "Events.EventTriggered");
|
||||
QVERIFY2(!eventTriggeredVariants.isEmpty(), "Did not get Events.EventTriggered notification.");
|
||||
qDebug() << "got" << eventTriggeredVariants.count() << "Events.EventTriggered notifications";
|
||||
|
||||
// Make sure the notification contains all the stuff we expect
|
||||
QVariant eventTriggeredVariant = checkNotification(clientSpy, "Events.EventTriggered");
|
||||
QVERIFY2(!eventTriggeredVariant.isNull(), "Did not get Events.EventTriggered notification.");
|
||||
//QCOMPARE(eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("eventTypeId").toUuid(), stateTypeId);
|
||||
//QCOMPARE(eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("params").toList().first().toMap().value("value").toInt(), newVal);
|
||||
found = false;
|
||||
foreach (const QVariant &eventTriggeredVariant, eventTriggeredVariants) {
|
||||
if (eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("eventTypeId").toUuid() == stateTypeId) {
|
||||
found = true;
|
||||
QCOMPARE(eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("params").toList().first().toMap().value("value").toInt(), newVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
QVERIFY2(found, "Could not find the correct Devices.StateChanged notification");
|
||||
|
||||
// Now turn off notifications
|
||||
QCOMPARE(disableNotifications(), true);
|
||||
@ -250,8 +260,8 @@ void TestJSONRPC::stateChangeEmitsNotifications()
|
||||
reply = nam.get(request);
|
||||
reply->deleteLater();
|
||||
|
||||
// Lets wait a max of 100ms for the notification
|
||||
clientSpy.wait();
|
||||
// Lets wait a max of 500ms for notifications
|
||||
clientSpy.wait(500);
|
||||
// but make sure it doesn't come
|
||||
QCOMPARE(clientSpy.count(), 0);
|
||||
|
||||
@ -285,7 +295,7 @@ void TestJSONRPC::deviceAddedRemovedNotifications()
|
||||
params.insert("name", "Mock device");
|
||||
params.insert("deviceParams", deviceParams);
|
||||
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
|
||||
clientSpy.wait();
|
||||
clientSpy.wait(2000);
|
||||
verifyDeviceError(response);
|
||||
QVariantMap notificationDeviceMap = checkNotification(clientSpy, "Devices.DeviceAdded").toMap().value("params").toMap().value("device").toMap();
|
||||
|
||||
@ -305,7 +315,7 @@ void TestJSONRPC::deviceAddedRemovedNotifications()
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
response = injectAndWait("Devices.RemoveConfiguredDevice", params);
|
||||
clientSpy.wait();
|
||||
clientSpy.wait(2000);
|
||||
verifyDeviceError(response);
|
||||
checkNotification(clientSpy, "Devices.DeviceRemoved");
|
||||
|
||||
@ -350,7 +360,7 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
params.insert("stateEvaluator", stateEvaluator);
|
||||
|
||||
QVariant response = injectAndWait("Rules.AddRule", params);
|
||||
clientSpy.wait();
|
||||
clientSpy.wait(2000);
|
||||
QVariantMap notificationRuleMap = checkNotification(clientSpy, "Rules.RuleAdded").toMap().value("params").toMap().value("rule").toMap();
|
||||
verifyRuleError(response);
|
||||
|
||||
@ -365,12 +375,11 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
|
||||
QCOMPARE(notificationRuleMap.value("eventDescriptors").toList(), QVariantList() << eventDescriptor);
|
||||
QCOMPARE(notificationRuleMap.value("exitActions").toList(), QVariantList());
|
||||
|
||||
|
||||
// now remove the rule and check the RuleRemoved notification
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("ruleId", ruleId);
|
||||
response = injectAndWait("Rules.RemoveRule", params);
|
||||
clientSpy.wait();
|
||||
clientSpy.wait(2000);
|
||||
checkNotification(clientSpy, "Devices.DeviceRemoved");
|
||||
verifyRuleError(response);
|
||||
|
||||
@ -510,8 +519,8 @@ void TestJSONRPC::deviceChangedNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
// EDIT
|
||||
// now edit the device and check the deviceChanged notification
|
||||
// RECONFIGURE
|
||||
// now reconfigure the device and check the deviceChanged notification
|
||||
QVariantList newDeviceParams;
|
||||
QVariantMap newHttpportParam;
|
||||
newHttpportParam.insert("name", "httpport");
|
||||
@ -522,7 +531,7 @@ void TestJSONRPC::deviceChangedNotifications()
|
||||
params.insert("deviceId", deviceId);
|
||||
params.insert("deviceParams", newDeviceParams);
|
||||
response = injectAndWait("Devices.ReconfigureDevice", params);
|
||||
clientSpy.wait();
|
||||
clientSpy.wait(2000);
|
||||
verifyDeviceError(response);
|
||||
QVariantMap reconfigureDeviceNotificationMap = checkNotification(clientSpy, "Devices.DeviceChanged").toMap().value("params").toMap().value("device").toMap();
|
||||
QCOMPARE(reconfigureDeviceNotificationMap.value("deviceClassId").toString(), mockDeviceClassId.toString());
|
||||
@ -533,6 +542,19 @@ void TestJSONRPC::deviceChangedNotifications()
|
||||
}
|
||||
}
|
||||
|
||||
// EDIT device name
|
||||
QString deviceName = "Test device 1234";
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
params.insert("deviceId", deviceId);
|
||||
params.insert("name", deviceName);
|
||||
response = injectAndWait("Devices.EditDevice", params);
|
||||
clientSpy.wait(2000);
|
||||
verifyDeviceError(response);
|
||||
QVariantMap editDeviceNotificationMap = checkNotification(clientSpy, "Devices.DeviceChanged").toMap().value("params").toMap().value("device").toMap();
|
||||
QCOMPARE(editDeviceNotificationMap.value("deviceClassId").toString(), mockDeviceClassId.toString());
|
||||
QCOMPARE(editDeviceNotificationMap.value("id").toString(), deviceId.toString());
|
||||
QCOMPARE(editDeviceNotificationMap.value("name").toString(), deviceName);
|
||||
|
||||
// REMOVE
|
||||
// now remove the device and check the device removed notification
|
||||
params.clear(); response.clear(); clientSpy.clear();
|
||||
|
||||
@ -91,7 +91,7 @@ void TestRules::cleanupMockHistory() {
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockDevice1Port).arg(mockEvent1Id.toString())));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait(500);
|
||||
spy.wait(1000);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
reply->deleteLater();
|
||||
}
|
||||
@ -134,7 +134,7 @@ void TestRules::verifyRuleExecuted(const ActionTypeId &actionTypeId)
|
||||
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
|
||||
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockDevice1Port)));
|
||||
QNetworkReply *reply = nam.get(request);
|
||||
spy.wait(500);
|
||||
spy.wait(1000);
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
||||
QByteArray actionHistory = reply->readAll();
|
||||
@ -823,6 +823,9 @@ void TestRules::executeRuleActions()
|
||||
response = injectAndWait("Rules.ExecuteActions", executeParams);
|
||||
verifyRuleError(response, ruleError);
|
||||
|
||||
// give the ruleeingine time to execute the actions
|
||||
QTest::qWait(1000);
|
||||
|
||||
if (ruleError == RuleEngine::RuleErrorNoError) {
|
||||
verifyRuleExecuted(mockActionIdWithParams);
|
||||
} else {
|
||||
@ -835,6 +838,9 @@ void TestRules::executeRuleActions()
|
||||
response = injectAndWait("Rules.ExecuteExitActions", executeParams);
|
||||
verifyRuleError(response, ruleError);
|
||||
|
||||
// give the ruleeingine time to execute the actions
|
||||
QTest::qWait(1000);
|
||||
|
||||
if (ruleError == RuleEngine::RuleErrorNoError) {
|
||||
verifyRuleExecuted(mockActionIdNoParams);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user