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:
Jarek Kobus
2022-04-01 15:02:23 +02:00
parent 8f427c1c95
commit 97132cf7f0
3 changed files with 37 additions and 1 deletions

View File

@@ -206,3 +206,21 @@ int ProcessTestApp::CrashAfterOneSecond::main()
doCrash();
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;
}

View File

@@ -70,6 +70,7 @@ public:
SUB_PROCESS(KillBlockingProcess);
SUB_PROCESS(EmitOneErrorOnCrash);
SUB_PROCESS(CrashAfterOneSecond);
SUB_PROCESS(RecursiveCrashingProcess);
// In order to get a value associated with the certain subprocess use SubProcessClass::envVar().
// 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";
// Expect ending lines detected at '|':
const char s_lineCallbackData[] =
static const char s_lineCallbackData[] =
"This is the first line\r\n|"
"Here comes the second one\r\n|"
"And a line without LF\n|"
@@ -117,4 +118,6 @@ enum class BlockType {
EventLoop
};
static const int s_crashCode = 123;
Q_DECLARE_METATYPE(BlockType)

View File

@@ -162,6 +162,7 @@ private slots:
void flushFinishedWhileWaitingForReadyRead();
void emitOneErrorOnCrash();
void crashAfterOneSecond();
void recursiveCrashingProcess();
void cleanupTestCase();
@@ -1206,6 +1207,20 @@ void tst_QtcProcess::crashAfterOneSecond()
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)
#include "tst_qtcprocess.moc"