fix backtace output

fix some tests to make sure they have enough time to verify
This commit is contained in:
Simon Stürz 2016-03-04 10:53:27 +01:00 committed by Michael Zanetti
parent c1a4d35387
commit da7cfc27f8
4 changed files with 82 additions and 40 deletions

View File

@ -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) { if (begin_name && begin_offset && end_offset && begin_name < begin_offset) {
int status; int status;
*begin_name++ = '\0'; *begin_name++ = '\0';
@ -80,14 +79,29 @@ static void printBacktrace()
char* ret = abi::__cxa_demangle(begin_name, functionName, &funktionNameSize, &status); char* ret = abi::__cxa_demangle(begin_name, functionName, &funktionNameSize, &status);
if (status == 0) { if (status == 0) {
functionName = ret; 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 { } 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")); qCCritical(dcApplication) << QString(" %1").arg(line.remove("\n"));
#endif // QT_VERSION
} }
free(functionName); free(functionName);
free(symbolList); free(symbolList);
} }
@ -109,7 +123,7 @@ static void catchUnixSignals(const std::vector<int>& quitSignals, const std::vec
qCDebug(dcApplication) << "Cought SIGHUP quit signal..."; qCDebug(dcApplication) << "Cought SIGHUP quit signal...";
break; break;
case SIGSEGV: { case SIGSEGV: {
qCCritical(dcApplication) << "Cought SIGSEGV signal. Segmentation fault!"; qCDebug(dcApplication) << "Cought SIGSEGV signal. Segmentation fault!";
printBacktrace(); printBacktrace();
exit(1); exit(1);
} }

View File

@ -160,7 +160,7 @@ QVariant GuhTestBase::injectAndWait(const QString &method, const QVariantMap &pa
QVariant GuhTestBase::checkNotification(const QSignalSpy &spy, const QString &notification) QVariant GuhTestBase::checkNotification(const QSignalSpy &spy, const QString &notification)
{ {
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++) { for (int i = 0; i < spy.count(); i++) {
// Make sure the response it a valid JSON string // Make sure the response it a valid JSON string
QJsonParseError error; QJsonParseError error;
@ -180,7 +180,7 @@ QVariant GuhTestBase::checkNotification(const QSignalSpy &spy, const QString &no
QVariantList GuhTestBase::checkNotifications(const QSignalSpy &spy, const QString &notification) QVariantList GuhTestBase::checkNotifications(const QSignalSpy &spy, const QString &notification)
{ {
qDebug() << "Got" << spy.count() << "notifications while waiting for" << notification; //qDebug() << "Got" << spy.count() << "notifications while waiting for" << notification;
QVariantList notificationList; QVariantList notificationList;
for (int i = 0; i < spy.count(); i++) { for (int i = 0; i < spy.count(); i++) {
// Make sure the response it a valid JSON string // Make sure the response it a valid JSON string

View File

@ -206,39 +206,49 @@ void TestJSONRPC::stateChangeEmitsNotifications()
QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray))); QSignalSpy clientSpy(m_mockTcpServer, SIGNAL(outgoingData(QUuid,QByteArray)));
// trigger state change in mock device // trigger state change in mock device
int newVal = 1111; int newVal = 38;
QUuid stateTypeId("80baec19-54de-4948-ac46-31eabfaceb83"); 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))); QNetworkRequest request(QUrl(QString("http://localhost:%1/setstate?%2=%3").arg(m_mockDevice1Port).arg(stateTypeId.toString()).arg(newVal)));
QNetworkReply *reply = nam.get(request); QNetworkReply *reply = nam.get(request);
reply->deleteLater(); reply->deleteLater();
clientSpy.wait(); clientSpy.wait(2000);
// Make sure the notification contains all the stuff we expect // Make sure the notification contains all the stuff we expect
QVariant stateChangedVariants = checkNotification(clientSpy, "Devices.StateChanged"); QVariantList stateChangedVariants = checkNotifications(clientSpy, "Devices.StateChanged");
QVERIFY2(!stateChangedVariants.isNull(), "Did not get Devices.StateChanged notification."); 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 // Make sure the notification contains all the stuff we expect
QVariant loggEntryAddedVariant = checkNotification(clientSpy, "Logging.LogEntryAdded"); QVariantList eventTriggeredVariants = checkNotifications(clientSpy, "Events.EventTriggered");
QVERIFY2(!loggEntryAddedVariant.isNull(), "Did not get Logging.LogEntryAdded notification."); 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 found = false;
QVariant eventTriggeredVariant = checkNotification(clientSpy, "Events.EventTriggered"); foreach (const QVariant &eventTriggeredVariant, eventTriggeredVariants) {
QVERIFY2(!eventTriggeredVariant.isNull(), "Did not get Events.EventTriggered notification."); if (eventTriggeredVariant.toMap().value("params").toMap().value("event").toMap().value("eventTypeId").toUuid() == stateTypeId) {
//QCOMPARE(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); 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 // Now turn off notifications
QCOMPARE(disableNotifications(), true); QCOMPARE(disableNotifications(), true);
@ -250,8 +260,8 @@ void TestJSONRPC::stateChangeEmitsNotifications()
reply = nam.get(request); reply = nam.get(request);
reply->deleteLater(); reply->deleteLater();
// Lets wait a max of 100ms for the notification // Lets wait a max of 500ms for notifications
clientSpy.wait(); clientSpy.wait(500);
// but make sure it doesn't come // but make sure it doesn't come
QCOMPARE(clientSpy.count(), 0); QCOMPARE(clientSpy.count(), 0);
@ -285,7 +295,7 @@ void TestJSONRPC::deviceAddedRemovedNotifications()
params.insert("name", "Mock device"); params.insert("name", "Mock device");
params.insert("deviceParams", deviceParams); params.insert("deviceParams", deviceParams);
QVariant response = injectAndWait("Devices.AddConfiguredDevice", params); QVariant response = injectAndWait("Devices.AddConfiguredDevice", params);
clientSpy.wait(); clientSpy.wait(2000);
verifyDeviceError(response); verifyDeviceError(response);
QVariantMap notificationDeviceMap = checkNotification(clientSpy, "Devices.DeviceAdded").toMap().value("params").toMap().value("device").toMap(); 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.clear(); response.clear(); clientSpy.clear();
params.insert("deviceId", deviceId); params.insert("deviceId", deviceId);
response = injectAndWait("Devices.RemoveConfiguredDevice", params); response = injectAndWait("Devices.RemoveConfiguredDevice", params);
clientSpy.wait(); clientSpy.wait(2000);
verifyDeviceError(response); verifyDeviceError(response);
checkNotification(clientSpy, "Devices.DeviceRemoved"); checkNotification(clientSpy, "Devices.DeviceRemoved");
@ -350,7 +360,7 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
params.insert("stateEvaluator", stateEvaluator); params.insert("stateEvaluator", stateEvaluator);
QVariant response = injectAndWait("Rules.AddRule", params); QVariant response = injectAndWait("Rules.AddRule", params);
clientSpy.wait(); clientSpy.wait(2000);
QVariantMap notificationRuleMap = checkNotification(clientSpy, "Rules.RuleAdded").toMap().value("params").toMap().value("rule").toMap(); QVariantMap notificationRuleMap = checkNotification(clientSpy, "Rules.RuleAdded").toMap().value("params").toMap().value("rule").toMap();
verifyRuleError(response); verifyRuleError(response);
@ -365,12 +375,11 @@ void TestJSONRPC::ruleAddedRemovedNotifications()
QCOMPARE(notificationRuleMap.value("eventDescriptors").toList(), QVariantList() << eventDescriptor); QCOMPARE(notificationRuleMap.value("eventDescriptors").toList(), QVariantList() << eventDescriptor);
QCOMPARE(notificationRuleMap.value("exitActions").toList(), QVariantList()); QCOMPARE(notificationRuleMap.value("exitActions").toList(), QVariantList());
// now remove the rule and check the RuleRemoved notification // now remove the rule and check the RuleRemoved notification
params.clear(); response.clear(); clientSpy.clear(); params.clear(); response.clear(); clientSpy.clear();
params.insert("ruleId", ruleId); params.insert("ruleId", ruleId);
response = injectAndWait("Rules.RemoveRule", params); response = injectAndWait("Rules.RemoveRule", params);
clientSpy.wait(); clientSpy.wait(2000);
checkNotification(clientSpy, "Devices.DeviceRemoved"); checkNotification(clientSpy, "Devices.DeviceRemoved");
verifyRuleError(response); verifyRuleError(response);
@ -510,8 +519,8 @@ void TestJSONRPC::deviceChangedNotifications()
} }
} }
// EDIT // RECONFIGURE
// now edit the device and check the deviceChanged notification // now reconfigure the device and check the deviceChanged notification
QVariantList newDeviceParams; QVariantList newDeviceParams;
QVariantMap newHttpportParam; QVariantMap newHttpportParam;
newHttpportParam.insert("name", "httpport"); newHttpportParam.insert("name", "httpport");
@ -522,7 +531,7 @@ void TestJSONRPC::deviceChangedNotifications()
params.insert("deviceId", deviceId); params.insert("deviceId", deviceId);
params.insert("deviceParams", newDeviceParams); params.insert("deviceParams", newDeviceParams);
response = injectAndWait("Devices.ReconfigureDevice", params); response = injectAndWait("Devices.ReconfigureDevice", params);
clientSpy.wait(); clientSpy.wait(2000);
verifyDeviceError(response); verifyDeviceError(response);
QVariantMap reconfigureDeviceNotificationMap = checkNotification(clientSpy, "Devices.DeviceChanged").toMap().value("params").toMap().value("device").toMap(); QVariantMap reconfigureDeviceNotificationMap = checkNotification(clientSpy, "Devices.DeviceChanged").toMap().value("params").toMap().value("device").toMap();
QCOMPARE(reconfigureDeviceNotificationMap.value("deviceClassId").toString(), mockDeviceClassId.toString()); 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 // REMOVE
// now remove the device and check the device removed notification // now remove the device and check the device removed notification
params.clear(); response.clear(); clientSpy.clear(); params.clear(); response.clear(); clientSpy.clear();

View File

@ -91,7 +91,7 @@ void TestRules::cleanupMockHistory() {
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
QNetworkRequest request(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockDevice1Port).arg(mockEvent1Id.toString()))); QNetworkRequest request(QUrl(QString("http://localhost:%1/clearactionhistory").arg(m_mockDevice1Port).arg(mockEvent1Id.toString())));
QNetworkReply *reply = nam.get(request); QNetworkReply *reply = nam.get(request);
spy.wait(500); spy.wait(1000);
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
reply->deleteLater(); reply->deleteLater();
} }
@ -134,7 +134,7 @@ void TestRules::verifyRuleExecuted(const ActionTypeId &actionTypeId)
QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*))); QSignalSpy spy(&nam, SIGNAL(finished(QNetworkReply*)));
QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockDevice1Port))); QNetworkRequest request(QUrl(QString("http://localhost:%1/actionhistory").arg(m_mockDevice1Port)));
QNetworkReply *reply = nam.get(request); QNetworkReply *reply = nam.get(request);
spy.wait(500); spy.wait(1000);
QCOMPARE(spy.count(), 1); QCOMPARE(spy.count(), 1);
QByteArray actionHistory = reply->readAll(); QByteArray actionHistory = reply->readAll();
@ -823,6 +823,9 @@ void TestRules::executeRuleActions()
response = injectAndWait("Rules.ExecuteActions", executeParams); response = injectAndWait("Rules.ExecuteActions", executeParams);
verifyRuleError(response, ruleError); verifyRuleError(response, ruleError);
// give the ruleeingine time to execute the actions
QTest::qWait(1000);
if (ruleError == RuleEngine::RuleErrorNoError) { if (ruleError == RuleEngine::RuleErrorNoError) {
verifyRuleExecuted(mockActionIdWithParams); verifyRuleExecuted(mockActionIdWithParams);
} else { } else {
@ -835,6 +838,9 @@ void TestRules::executeRuleActions()
response = injectAndWait("Rules.ExecuteExitActions", executeParams); response = injectAndWait("Rules.ExecuteExitActions", executeParams);
verifyRuleError(response, ruleError); verifyRuleError(response, ruleError);
// give the ruleeingine time to execute the actions
QTest::qWait(1000);
if (ruleError == RuleEngine::RuleErrorNoError) { if (ruleError == RuleEngine::RuleErrorNoError) {
verifyRuleExecuted(mockActionIdNoParams); verifyRuleExecuted(mockActionIdNoParams);
} else { } else {