forked from qt-creator/qt-creator
tst_QtcProcess: Add a test that invokes a process recursively
After the required depth of recursion is met, the most nested process waits for one seconds and crashes. Change-Id: I8d9b359459fc7aa1983734685e5c5f19eb49ee94 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -206,3 +206,21 @@ int ProcessTestApp::CrashAfterOneSecond::main()
|
|||||||
doCrash();
|
doCrash();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ProcessTestApp::RecursiveCrashingProcess::main()
|
||||||
|
{
|
||||||
|
const int currentDepth = qEnvironmentVariableIntValue(envVar());
|
||||||
|
if (currentDepth == 0) {
|
||||||
|
QThread::sleep(1);
|
||||||
|
doCrash();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
SubProcessConfig subConfig(envVar(), QString::number(currentDepth - 1));
|
||||||
|
QtcProcess process;
|
||||||
|
subConfig.setupSubProcess(&process);
|
||||||
|
process.start();
|
||||||
|
process.waitForFinished();
|
||||||
|
if (process.exitStatus() == QProcess::NormalExit)
|
||||||
|
return process.exitCode();
|
||||||
|
return s_crashCode;
|
||||||
|
}
|
||||||
|
@@ -70,6 +70,7 @@ public:
|
|||||||
SUB_PROCESS(KillBlockingProcess);
|
SUB_PROCESS(KillBlockingProcess);
|
||||||
SUB_PROCESS(EmitOneErrorOnCrash);
|
SUB_PROCESS(EmitOneErrorOnCrash);
|
||||||
SUB_PROCESS(CrashAfterOneSecond);
|
SUB_PROCESS(CrashAfterOneSecond);
|
||||||
|
SUB_PROCESS(RecursiveCrashingProcess);
|
||||||
|
|
||||||
// In order to get a value associated with the certain subprocess use SubProcessClass::envVar().
|
// In order to get a value associated with the certain subprocess use SubProcessClass::envVar().
|
||||||
// The classes above define different custom executables. Inside invokeSubProcess(), called
|
// The classes above define different custom executables. Inside invokeSubProcess(), called
|
||||||
@@ -100,7 +101,7 @@ static const char s_simpleTestData[] = "Test process successfully executed.";
|
|||||||
static const char s_runBlockingStdOutSubProcessMagicWord[] = "42";
|
static const char s_runBlockingStdOutSubProcessMagicWord[] = "42";
|
||||||
|
|
||||||
// Expect ending lines detected at '|':
|
// Expect ending lines detected at '|':
|
||||||
const char s_lineCallbackData[] =
|
static const char s_lineCallbackData[] =
|
||||||
"This is the first line\r\n|"
|
"This is the first line\r\n|"
|
||||||
"Here comes the second one\r\n|"
|
"Here comes the second one\r\n|"
|
||||||
"And a line without LF\n|"
|
"And a line without LF\n|"
|
||||||
@@ -117,4 +118,6 @@ enum class BlockType {
|
|||||||
EventLoop
|
EventLoop
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const int s_crashCode = 123;
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(BlockType)
|
Q_DECLARE_METATYPE(BlockType)
|
||||||
|
@@ -162,6 +162,7 @@ private slots:
|
|||||||
void flushFinishedWhileWaitingForReadyRead();
|
void flushFinishedWhileWaitingForReadyRead();
|
||||||
void emitOneErrorOnCrash();
|
void emitOneErrorOnCrash();
|
||||||
void crashAfterOneSecond();
|
void crashAfterOneSecond();
|
||||||
|
void recursiveCrashingProcess();
|
||||||
|
|
||||||
void cleanupTestCase();
|
void cleanupTestCase();
|
||||||
|
|
||||||
@@ -1206,6 +1207,20 @@ void tst_QtcProcess::crashAfterOneSecond()
|
|||||||
QCOMPARE(process.error(), QProcess::Crashed);
|
QCOMPARE(process.error(), QProcess::Crashed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QtcProcess::recursiveCrashingProcess()
|
||||||
|
{
|
||||||
|
const int recursionDepth = 5; // must be at least 1
|
||||||
|
SubProcessConfig subConfig(ProcessTestApp::RecursiveCrashingProcess::envVar(),
|
||||||
|
QString::number(recursionDepth));
|
||||||
|
TestProcess process;
|
||||||
|
subConfig.setupSubProcess(&process);
|
||||||
|
process.start();
|
||||||
|
QVERIFY(process.waitForStarted(1000));
|
||||||
|
QVERIFY(process.waitForFinished(3000));
|
||||||
|
QCOMPARE(process.state(), QProcess::NotRunning);
|
||||||
|
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
|
||||||
|
QCOMPARE(process.exitCode(), s_crashCode);
|
||||||
|
}
|
||||||
QTEST_MAIN(tst_QtcProcess)
|
QTEST_MAIN(tst_QtcProcess)
|
||||||
|
|
||||||
#include "tst_qtcprocess.moc"
|
#include "tst_qtcprocess.moc"
|
||||||
|
Reference in New Issue
Block a user