mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 19:35:33 +08:00
Allow to test an ASSERT (like the crashdump test)
This commit is contained in:
committed by
Mat Sutcliffe
parent
44d8e043e0
commit
b0efdd78ec
@@ -1649,6 +1649,11 @@ namespace BlackCore
|
|||||||
CCrashHandler::instance()->simulateCrash();
|
CCrashHandler::instance()->simulateCrash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CApplication::simulateAssert()
|
||||||
|
{
|
||||||
|
CCrashHandler::instance()->simulateAssert();
|
||||||
|
}
|
||||||
|
|
||||||
void CApplication::enableCrashDumpUpload(bool enable)
|
void CApplication::enableCrashDumpUpload(bool enable)
|
||||||
{
|
{
|
||||||
CCrashHandler::instance()->setUploadsEnabled(enable);
|
CCrashHandler::instance()->setUploadsEnabled(enable);
|
||||||
|
|||||||
@@ -309,6 +309,10 @@ namespace BlackCore
|
|||||||
//! \private only for testing purposes
|
//! \private only for testing purposes
|
||||||
void simulateCrash();
|
void simulateCrash();
|
||||||
|
|
||||||
|
//! Simulate an ASSERT
|
||||||
|
//! \private only for testing purposes
|
||||||
|
void simulateAssert();
|
||||||
|
|
||||||
//! Enable crash upload
|
//! Enable crash upload
|
||||||
//! \remark only change for testing
|
//! \remark only change for testing
|
||||||
void enableCrashDumpUpload(bool enable);
|
void enableCrashDumpUpload(bool enable);
|
||||||
|
|||||||
@@ -99,8 +99,9 @@ namespace BlackGui
|
|||||||
if (sGui && sGui->isSupportingCrashpad())
|
if (sGui && sGui->isSupportingCrashpad())
|
||||||
{
|
{
|
||||||
ui->cb_CrashDumpUpload->setChecked(CCrashHandler::instance()->isCrashDumpUploadEnabled());
|
ui->cb_CrashDumpUpload->setChecked(CCrashHandler::instance()->isCrashDumpUploadEnabled());
|
||||||
connect(ui->pb_SimulateCrash, &QPushButton::released, this, &CInternalsComponent::simulateCrash);
|
connect(ui->pb_SimulateCrash, &QPushButton::released, this, &CInternalsComponent::simulateCrash, Qt::QueuedConnection);
|
||||||
connect(ui->cb_CrashDumpUpload, &QCheckBox::toggled, this, &CInternalsComponent::onCrashDumpUploadToggled);
|
connect(ui->pb_SimulateAssert, &QPushButton::released, this, &CInternalsComponent::simulateAssert, Qt::QueuedConnection);
|
||||||
|
connect(ui->cb_CrashDumpUpload, &QCheckBox::toggled, this, &CInternalsComponent::onCrashDumpUploadToggled);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -345,10 +346,23 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
|
|
||||||
const QMessageBox::StandardButton reply = QMessageBox::question(this, "crash simulation", "Really simulate crash?", QMessageBox::Yes | QMessageBox::No);
|
const QMessageBox::StandardButton reply = QMessageBox::question(this, "crash simulation", "Really simulate crash?", QMessageBox::Yes | QMessageBox::No);
|
||||||
if (reply != QMessageBox::Yes) { return; }
|
if (!sGui || reply != QMessageBox::Yes) { return; }
|
||||||
sGui->simulateCrash();
|
sGui->simulateCrash();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CInternalsComponent::simulateAssert()
|
||||||
|
{
|
||||||
|
if (CBuildConfig::isReleaseBuild())
|
||||||
|
{
|
||||||
|
QMessageBox::information(this, "ASSERT simulation", "Not possible in release builds!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QMessageBox::StandardButton reply = QMessageBox::question(this, "ASSERT simulation", "Really create an ASSERT?", QMessageBox::Yes | QMessageBox::No);
|
||||||
|
if (!sGui || reply != QMessageBox::Yes) { return; }
|
||||||
|
sGui->simulateAssert();
|
||||||
|
}
|
||||||
|
|
||||||
void CInternalsComponent::onCrashDumpUploadToggled(bool checked)
|
void CInternalsComponent::onCrashDumpUploadToggled(bool checked)
|
||||||
{
|
{
|
||||||
if (sGui && sGui->isSupportingCrashpad())
|
if (sGui && sGui->isSupportingCrashpad())
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ namespace BlackGui
|
|||||||
//! Simulate a crash
|
//! Simulate a crash
|
||||||
void simulateCrash();
|
void simulateCrash();
|
||||||
|
|
||||||
|
//! Simulate ASSERT
|
||||||
|
void simulateAssert();
|
||||||
|
|
||||||
//! Checkbox toggled
|
//! Checkbox toggled
|
||||||
void onCrashDumpUploadToggled(bool checked);
|
void onCrashDumpUploadToggled(bool checked);
|
||||||
|
|
||||||
|
|||||||
@@ -320,6 +320,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pb_SimulateAssert">
|
||||||
|
<property name="text">
|
||||||
|
<string>assert!</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -751,6 +758,7 @@
|
|||||||
<tabstop>cb_DebugContextApplication</tabstop>
|
<tabstop>cb_DebugContextApplication</tabstop>
|
||||||
<tabstop>cb_CrashDumpUpload</tabstop>
|
<tabstop>cb_CrashDumpUpload</tabstop>
|
||||||
<tabstop>pb_SimulateCrash</tabstop>
|
<tabstop>pb_SimulateCrash</tabstop>
|
||||||
|
<tabstop>pb_SimulateAssert</tabstop>
|
||||||
<tabstop>pb_LatestInterpolationLog</tabstop>
|
<tabstop>pb_LatestInterpolationLog</tabstop>
|
||||||
<tabstop>pb_LatestPartsLog</tabstop>
|
<tabstop>pb_LatestPartsLog</tabstop>
|
||||||
<tabstop>pte_NetworkCalls</tabstop>
|
<tabstop>pte_NetworkCalls</tabstop>
|
||||||
@@ -760,10 +768,10 @@
|
|||||||
<tabstop>pb_DisplayLog</tabstop>
|
<tabstop>pb_DisplayLog</tabstop>
|
||||||
<tabstop>pb_RequestFromNetwork</tabstop>
|
<tabstop>pb_RequestFromNetwork</tabstop>
|
||||||
<tabstop>tb_History</tabstop>
|
<tabstop>tb_History</tabstop>
|
||||||
<tabstop>pb_SendAircraftPartsGui</tabstop>
|
|
||||||
<tabstop>pb_CurrentParts</tabstop>
|
<tabstop>pb_CurrentParts</tabstop>
|
||||||
<tabstop>cb_AircraftPartsIncremental</tabstop>
|
<tabstop>cb_AircraftPartsIncremental</tabstop>
|
||||||
<tabstop>pb_SendAircraftPartsJson</tabstop>
|
<tabstop>pb_SendAircraftPartsJson</tabstop>
|
||||||
|
<tabstop>pb_SendAircraftPartsGui</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../blackmisc/blackmisc.qrc"/>
|
<include location="../../blackmisc/blackmisc.qrc"/>
|
||||||
|
|||||||
@@ -107,29 +107,29 @@ namespace BlackMisc
|
|||||||
false, true);
|
false, true);
|
||||||
|
|
||||||
this->crashAndLogAppendInfo(u"Init crash info at " % QDateTime::currentDateTimeUtc().toString());
|
this->crashAndLogAppendInfo(u"Init crash info at " % QDateTime::currentDateTimeUtc().toString());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCrashHandler::setUploadsEnabled(bool enable)
|
void CCrashHandler::setUploadsEnabled(bool enable)
|
||||||
{
|
{
|
||||||
#ifdef BLACK_USE_CRASHPAD
|
#ifdef BLACK_USE_CRASHPAD
|
||||||
if (!m_crashReportDatabase) { return; }
|
if (!m_crashReportDatabase) { return; }
|
||||||
crashpad::Settings *settings = m_crashReportDatabase->GetSettings();
|
crashpad::Settings *settings = m_crashReportDatabase->GetSettings();
|
||||||
settings->SetUploadsEnabled(enable);
|
settings->SetUploadsEnabled(enable);
|
||||||
#else
|
#else
|
||||||
Q_UNUSED(enable);
|
Q_UNUSED(enable);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCrashHandler::isCrashDumpUploadEnabled() const
|
bool CCrashHandler::isCrashDumpUploadEnabled() const
|
||||||
{
|
{
|
||||||
#ifdef BLACK_USE_CRASHPAD
|
#ifdef BLACK_USE_CRASHPAD
|
||||||
if (!m_crashReportDatabase) { return false; }
|
if (!m_crashReportDatabase) { return false; }
|
||||||
crashpad::Settings *settings = m_crashReportDatabase->GetSettings();
|
crashpad::Settings *settings = m_crashReportDatabase->GetSettings();
|
||||||
bool enabled = false;
|
bool enabled = false;
|
||||||
bool ok = settings->GetUploadsEnabled(&enabled);
|
bool ok = settings->GetUploadsEnabled(&enabled);
|
||||||
return ok && enabled;
|
return ok && enabled;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -171,16 +171,28 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CCrashHandler::simulateCrash()
|
void CCrashHandler::simulateCrash()
|
||||||
{
|
{
|
||||||
#ifdef BLACK_USE_CRASHPAD
|
# ifdef BLACK_USE_CRASHPAD
|
||||||
CLogMessage(this).info(u"Simulated crash dump!");
|
CLogMessage(this).info(u"Simulated crash dump!");
|
||||||
m_crashAndLogInfo.appendInfo("Simulated crash dump!");
|
m_crashAndLogInfo.appendInfo("Simulated crash dump!");
|
||||||
m_crashAndLogInfo.writeToFile();
|
m_crashAndLogInfo.writeToFile();
|
||||||
CRASHPAD_SIMULATE_CRASH();
|
CRASHPAD_SIMULATE_CRASH();
|
||||||
// real crash
|
// real crash
|
||||||
// raise(SIGSEGV); #include <signal.h>
|
// raise(SIGSEGV); #include <signal.h>
|
||||||
#else
|
# else
|
||||||
CLogMessage(this).warning(u"This compiler or platform does not support crashpad. Cannot simulate crash dump!");
|
CLogMessage(this).warning(u"This compiler or platform does not support crashpad. Cannot simulate crash dump!");
|
||||||
#endif
|
# endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCrashHandler::simulateAssert()
|
||||||
|
{
|
||||||
|
# ifdef BLACK_USE_CRASHPAD
|
||||||
|
CLogMessage(this).info(u"Simulated ASSERT!");
|
||||||
|
m_crashAndLogInfo.appendInfo("Simulated ASSERT!");
|
||||||
|
m_crashAndLogInfo.writeToFile();
|
||||||
|
Q_ASSERT_X(false, Q_FUNC_INFO, "Test server to test Crash handler");
|
||||||
|
# else
|
||||||
|
CLogMessage(this).warning(u"This compiler or platform does not support crashpad. Cannot simulate crash dump!");
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
CCrashHandler::CCrashHandler(QObject *parent) :
|
CCrashHandler::CCrashHandler(QObject *parent) :
|
||||||
|
|||||||
@@ -73,6 +73,9 @@ namespace BlackMisc
|
|||||||
//! Simulate a crash
|
//! Simulate a crash
|
||||||
void simulateCrash();
|
void simulateCrash();
|
||||||
|
|
||||||
|
//! Simulate an ASSERT
|
||||||
|
void simulateAssert();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCrashHandler(QObject *parent = nullptr);
|
CCrashHandler(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user