Process: Change signature of waitForXxx() functions

Change the arg to QDeadlineTimer type.

Change-Id: Id3dee0717e44130c16baf7925e5b06346a1a1ad1
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2024-01-22 18:59:10 +01:00
parent f86ada790a
commit 63fc22e274
25 changed files with 78 additions and 67 deletions

View File

@@ -12,6 +12,8 @@
Q_LOGGING_CATEGORY(deviceShellLog, "qtc.utils.deviceshell", QtWarningMsg) Q_LOGGING_CATEGORY(deviceShellLog, "qtc.utils.deviceshell", QtWarningMsg)
using namespace std::chrono_literals;
namespace Utils { namespace Utils {
/* /*
@@ -277,7 +279,7 @@ expected_str<void> DeviceShell::installShellScript()
m_shellProcess->writeRaw(scriptCmd); m_shellProcess->writeRaw(scriptCmd);
while (m_shellScriptState == State::Unknown) { while (m_shellScriptState == State::Unknown) {
if (!m_shellProcess->waitForReadyRead(5000)) { if (!m_shellProcess->waitForReadyRead(5s)) {
return make_unexpected(Tr::tr("Timeout while waiting for shell script installation.")); return make_unexpected(Tr::tr("Timeout while waiting for shell script installation."));
} }
@@ -305,7 +307,7 @@ void DeviceShell::closeShellProcess()
if (m_shellProcess) { if (m_shellProcess) {
if (m_shellProcess->isRunning()) { if (m_shellProcess->isRunning()) {
m_shellProcess->write("exit\nexit\n"); m_shellProcess->write("exit\nexit\n");
if (!m_shellProcess->waitForFinished(2000)) if (!m_shellProcess->waitForFinished(2s))
m_shellProcess->terminate(); m_shellProcess->terminate();
} }
m_shellProcess.reset(); m_shellProcess.reset();

View File

@@ -837,7 +837,7 @@ public:
emit (q->*signalName)(); emit (q->*signalName)();
} }
bool waitForSignal(ProcessSignalType signalType, int msecs); bool waitForSignal(ProcessSignalType signalType, QDeadlineTimer timeout);
Qt::ConnectionType connectionType() const; Qt::ConnectionType connectionType() const;
void sendControlSignal(ControlSignal controlSignal); void sendControlSignal(ControlSignal controlSignal);
@@ -1062,11 +1062,10 @@ void GeneralProcessBlockingImpl::appendSignal(ProcessInterfaceSignal *newSignal)
m_signals.append(newSignal); m_signals.append(newSignal);
} }
bool ProcessPrivate::waitForSignal(ProcessSignalType newSignal, int msecs) bool ProcessPrivate::waitForSignal(ProcessSignalType newSignal, QDeadlineTimer timeout)
{ {
const QDeadlineTimer timeout(msecs);
const QDeadlineTimer currentKillTimeout(m_killTimer.remainingTime()); const QDeadlineTimer currentKillTimeout(m_killTimer.remainingTime());
const bool needsSplit = m_killTimer.isActive() ? timeout > currentKillTimeout : false; const bool needsSplit = m_killTimer.isActive() && timeout > currentKillTimeout;
const QDeadlineTimer mainTimeout = needsSplit ? currentKillTimeout : timeout; const QDeadlineTimer mainTimeout = needsSplit ? currentKillTimeout : timeout;
bool result = m_blockingInterface->waitForSignal(newSignal, mainTimeout.remainingTime()); bool result = m_blockingInterface->waitForSignal(newSignal, mainTimeout.remainingTime());
@@ -1441,6 +1440,7 @@ static bool askToKill(const CommandLine &command)
// occurs on stderr/stdout as opposed to waitForFinished()). Returns false if a timeout // occurs on stderr/stdout as opposed to waitForFinished()). Returns false if a timeout
// occurs. Checking of the process' exit state/code still has to be done. // occurs. Checking of the process' exit state/code still has to be done.
// TODO: Is it really needed?
bool Process::readDataFromProcess(QByteArray *stdOut, QByteArray *stdErr, int timeoutS) bool Process::readDataFromProcess(QByteArray *stdOut, QByteArray *stdErr, int timeoutS)
{ {
enum { syncDebug = 0 }; enum { syncDebug = 0 };
@@ -1455,7 +1455,7 @@ bool Process::readDataFromProcess(QByteArray *stdOut, QByteArray *stdErr, int ti
bool finished = false; bool finished = false;
bool hasData = false; bool hasData = false;
do { do {
finished = waitForFinished(timeoutS > 0 ? timeoutS * 1000 : -1) finished = waitForFinished(timeoutS > 0 ? seconds(timeoutS) : seconds(-1))
|| state() == QProcess::NotRunning; || state() == QProcess::NotRunning;
// First check 'stdout' // First check 'stdout'
const QByteArray newStdOut = readAllRawStandardOutput(); const QByteArray newStdOut = readAllRawStandardOutput();
@@ -1541,7 +1541,7 @@ qint64 Process::processId() const
return d->m_processId; return d->m_processId;
} }
bool Process::waitForStarted(int msecs) bool Process::waitForStarted(QDeadlineTimer timeout)
{ {
QTC_ASSERT(d->m_process, return false); QTC_ASSERT(d->m_process, return false);
if (d->m_state == QProcess::Running) if (d->m_state == QProcess::Running)
@@ -1549,23 +1549,23 @@ bool Process::waitForStarted(int msecs)
if (d->m_state == QProcess::NotRunning) if (d->m_state == QProcess::NotRunning)
return false; return false;
return s_waitForStarted.measureAndRun(&ProcessPrivate::waitForSignal, d, return s_waitForStarted.measureAndRun(&ProcessPrivate::waitForSignal, d,
ProcessSignalType::Started, msecs); ProcessSignalType::Started, timeout);
} }
bool Process::waitForReadyRead(int msecs) bool Process::waitForReadyRead(QDeadlineTimer timeout)
{ {
QTC_ASSERT(d->m_process, return false); QTC_ASSERT(d->m_process, return false);
if (d->m_state == QProcess::NotRunning) if (d->m_state == QProcess::NotRunning)
return false; return false;
return d->waitForSignal(ProcessSignalType::ReadyRead, msecs); return d->waitForSignal(ProcessSignalType::ReadyRead, timeout);
} }
bool Process::waitForFinished(int msecs) bool Process::waitForFinished(QDeadlineTimer timeout)
{ {
QTC_ASSERT(d->m_process, return false); QTC_ASSERT(d->m_process, return false);
if (d->m_state == QProcess::NotRunning) if (d->m_state == QProcess::NotRunning)
return false; return false;
return d->waitForSignal(ProcessSignalType::Done, msecs); return d->waitForSignal(ProcessSignalType::Done, timeout);
} }
QByteArray Process::readAllRawStandardOutput() QByteArray Process::readAllRawStandardOutput()
@@ -1884,7 +1884,7 @@ void Process::runBlocking(seconds timeout, EventLoopMode eventLoopMode)
if (state() == QProcess::NotRunning) if (state() == QProcess::NotRunning)
return; return;
stop(); stop();
QTC_CHECK(waitForFinished(2000)); QTC_CHECK(waitForFinished(2s));
}; };
if (eventLoopMode == EventLoopMode::On) { if (eventLoopMode == EventLoopMode::On) {
@@ -1919,7 +1919,7 @@ void Process::runBlocking(seconds timeout, EventLoopMode eventLoopMode)
#endif #endif
} else { } else {
handleStart(); handleStart();
if (!waitForFinished(duration_cast<milliseconds>(timeout).count())) if (!waitForFinished(timeout))
handleTimeout(); handleTimeout();
} }
if (blockingThresholdMs > 0) { if (blockingThresholdMs > 0) {

View File

@@ -14,6 +14,7 @@
#include <solutions/tasking/tasktree.h> #include <solutions/tasking/tasktree.h>
#include <QDeadlineTimer>
#include <QProcess> #include <QProcess>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@@ -73,10 +74,9 @@ public:
QProcess::ProcessError error() const; QProcess::ProcessError error() const;
QString errorString() const; QString errorString() const;
// TODO: Change to std::chrono::milliseconds. bool waitForStarted(QDeadlineTimer timeout = std::chrono::seconds(30));
bool waitForStarted(int msecs = 30000); bool waitForReadyRead(QDeadlineTimer timeout = std::chrono::seconds(30));
bool waitForReadyRead(int msecs = 30000); bool waitForFinished(QDeadlineTimer timeout = std::chrono::seconds(30));
bool waitForFinished(int msecs = 30000);
// ProcessSetupData related // ProcessSetupData related

View File

@@ -22,6 +22,7 @@
using namespace Utils; using namespace Utils;
using namespace std; using namespace std;
using namespace std::chrono_literals;
namespace Android::Internal { namespace Android::Internal {
@@ -100,7 +101,7 @@ static CreateAvdInfo createAvdCommand(const AndroidConfig &config, const CreateA
QString errorOutput; QString errorOutput;
QByteArray question; QByteArray question;
while (errorOutput.isEmpty()) { while (errorOutput.isEmpty()) {
proc.waitForReadyRead(500); proc.waitForReadyRead(500ms);
question += proc.readAllRawStandardOutput(); question += proc.readAllRawStandardOutput();
if (question.endsWith(QByteArray("]:"))) { if (question.endsWith(QByteArray("]:"))) {
// truncate to last line // truncate to last line
@@ -271,7 +272,7 @@ bool AndroidAvdManager::startAvdAsync(const QString &avdName) const
qCDebug(avdManagerLog).noquote() << "Running command (startAvdAsync):" << cmd.toUserOutput(); qCDebug(avdManagerLog).noquote() << "Running command (startAvdAsync):" << cmd.toUserOutput();
avdProcess->setCommand(cmd); avdProcess->setCommand(cmd);
avdProcess->start(); avdProcess->start();
return avdProcess->waitForStarted(-1); return avdProcess->waitForStarted(QDeadlineTimer::Forever);
} }
QString AndroidAvdManager::findAvd(const QString &avdName) const QString AndroidAvdManager::findAvd(const QString &avdName) const

View File

@@ -53,6 +53,8 @@
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
using namespace std::chrono_literals;
namespace Android::Internal { namespace Android::Internal {
static Q_LOGGING_CATEGORY(deployStepLog, "qtc.android.build.androiddeployqtstep", QtWarningMsg) static Q_LOGGING_CATEGORY(deployStepLog, "qtc.android.build.androiddeployqtstep", QtWarningMsg)
@@ -398,7 +400,7 @@ AndroidDeployQtStep::DeployErrorCode AndroidDeployQtStep::runDeploy(QPromise<voi
emit addOutput(Tr::tr("Starting: \"%1\"").arg(cmd.toUserOutput()), OutputFormat::NormalMessage); emit addOutput(Tr::tr("Starting: \"%1\"").arg(cmd.toUserOutput()), OutputFormat::NormalMessage);
while (!process.waitForFinished(200)) { while (!process.waitForFinished(200ms)) {
if (process.state() == QProcess::NotRunning) if (process.state() == QProcess::NotRunning)
break; break;
@@ -576,7 +578,7 @@ void AndroidDeployQtStep::runCommand(const CommandLine &command)
OutputFormat::NormalMessage); OutputFormat::NormalMessage);
buildProc.setCommand(command); buildProc.setCommand(command);
buildProc.runBlocking(std::chrono::minutes(2), EventLoopMode::On); buildProc.runBlocking(2min, EventLoopMode::On);
if (buildProc.result() != ProcessResult::FinishedWithSuccess) if (buildProc.result() != ProcessResult::FinishedWithSuccess)
reportWarningOrError(buildProc.exitMessage(), Task::Error); reportWarningOrError(buildProc.exitMessage(), Task::Error);
} }

View File

@@ -656,7 +656,7 @@ Process *startAdbProcess(const QStringList &args, QString *err)
qCDebug(androidManagerLog).noquote() << "Running command (async):" << command.toUserOutput(); qCDebug(androidManagerLog).noquote() << "Running command (async):" << command.toUserOutput();
process->setCommand(command); process->setCommand(command);
process->start(); process->start();
if (process->waitForStarted(500) && process->state() == QProcess::Running) if (process->waitForStarted(500ms) && process->state() == QProcess::Running)
return process.release(); return process.release();
const QString errorStr = process->readAllStandardError(); const QString errorStr = process->readAllStandardError();

View File

@@ -517,7 +517,7 @@ void Android::Internal::AndroidRunnerWorker::asyncStartLogcat()
<< CommandLine(adb, logcatArgs).toUserOutput(); << CommandLine(adb, logcatArgs).toUserOutput();
m_adbLogcatProcess->setCommand({adb, logcatArgs}); m_adbLogcatProcess->setCommand({adb, logcatArgs});
m_adbLogcatProcess->start(); m_adbLogcatProcess->start();
if (m_adbLogcatProcess->waitForStarted(500) && m_adbLogcatProcess->state() == QProcess::Running) if (m_adbLogcatProcess->waitForStarted(500ms) && m_adbLogcatProcess->state() == QProcess::Running)
m_adbLogcatProcess->setObjectName("AdbLogcatProcess"); m_adbLogcatProcess->setObjectName("AdbLogcatProcess");
} }
@@ -768,7 +768,7 @@ void AndroidRunnerWorker::handleJdbSettled()
qCDebug(androidRunWorkerLog) << "Handle JDB settled"; qCDebug(androidRunWorkerLog) << "Handle JDB settled";
auto waitForCommand = [this] { auto waitForCommand = [this] {
for (int i = 0; i < 120 && m_jdbProcess->state() == QProcess::Running; ++i) { for (int i = 0; i < 120 && m_jdbProcess->state() == QProcess::Running; ++i) {
m_jdbProcess->waitForReadyRead(500); m_jdbProcess->waitForReadyRead(500ms);
const QByteArray lines = m_jdbProcess->readAllRawStandardOutput(); const QByteArray lines = m_jdbProcess->readAllRawStandardOutput();
const auto linesList = lines.split('\n'); const auto linesList = lines.split('\n');
for (const auto &line : linesList) { for (const auto &line : linesList) {
@@ -787,7 +787,7 @@ void AndroidRunnerWorker::handleJdbSettled()
m_jdbProcess->write(QString("%1\n").arg(command)); m_jdbProcess->write(QString("%1\n").arg(command));
} }
if (!m_jdbProcess->waitForFinished(s_jdbTimeout.count())) { if (!m_jdbProcess->waitForFinished(s_jdbTimeout)) {
m_jdbProcess.reset(); m_jdbProcess.reset();
} else if (m_jdbProcess->exitStatus() == QProcess::NormalExit && m_jdbProcess->exitCode() == 0) { } else if (m_jdbProcess->exitStatus() == QProcess::NormalExit && m_jdbProcess->exitCode() == 0) {
qCDebug(androidRunWorkerLog) << "JDB settled"; qCDebug(androidRunWorkerLog) << "JDB settled";

View File

@@ -27,6 +27,7 @@ const char commonArgsKey[] = "Common Arguments:";
using namespace Utils; using namespace Utils;
using namespace std::chrono; using namespace std::chrono;
using namespace std::chrono_literals;
namespace Android { namespace Android {
namespace Internal { namespace Internal {
@@ -528,7 +529,7 @@ void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdPromise &fi)
licenseCommand.start(); licenseCommand.start();
QTextCodec *codec = QTextCodec::codecForLocale(); QTextCodec *codec = QTextCodec::codecForLocale();
int inputCounter = 0, steps = -1; int inputCounter = 0, steps = -1;
while (!licenseCommand.waitForFinished(200)) { while (!licenseCommand.waitForFinished(200ms)) {
QString stdOut = codec->toUnicode(licenseCommand.readAllRawStandardOutput()); QString stdOut = codec->toUnicode(licenseCommand.readAllRawStandardOutput());
bool assertionFound = false; bool assertionFound = false;
if (!stdOut.isEmpty()) if (!stdOut.isEmpty())
@@ -556,9 +557,9 @@ void AndroidSdkManagerPrivate::getPendingLicense(SdkCmdPromise &fi)
if (fi.isCanceled()) { if (fi.isCanceled()) {
licenseCommand.terminate(); licenseCommand.terminate();
if (!licenseCommand.waitForFinished(300)) { if (!licenseCommand.waitForFinished(300ms)) {
licenseCommand.kill(); licenseCommand.kill();
licenseCommand.waitForFinished(200); licenseCommand.waitForFinished(200ms);
} }
} }
if (licenseCommand.state() == QProcess::NotRunning) if (licenseCommand.state() == QProcess::NotRunning)

View File

@@ -120,7 +120,7 @@ public:
QVersionNumber version() const QVersionNumber version() const
{ {
if (m_process.state() != QProcess::NotRunning) if (m_process.state() != QProcess::NotRunning)
m_process.waitForFinished(-1); m_process.waitForFinished(QDeadlineTimer::Forever);
return m_versionNumber; return m_versionNumber;
} }

View File

@@ -19,7 +19,7 @@ CppcheckRunner::CppcheckRunner(CppcheckTool &tool) : m_tool(tool)
Process getConf; Process getConf;
getConf.setCommand({"getconf", {"ARG_MAX"}}); getConf.setCommand({"getconf", {"ARG_MAX"}});
getConf.start(); getConf.start();
getConf.waitForFinished(2000); getConf.waitForFinished(std::chrono::seconds(2));
const QByteArray argMax = getConf.rawStdOut().replace("\n", ""); const QByteArray argMax = getConf.rawStdOut().replace("\n", "");
m_maxArgumentsLength = std::max(argMax.toInt(), m_maxArgumentsLength); m_maxArgumentsLength = std::max(argMax.toInt(), m_maxArgumentsLength);
} }

View File

@@ -213,7 +213,7 @@ void LldbEngine::setupEngine()
void LldbEngine::handleLldbStarted() void LldbEngine::handleLldbStarted()
{ {
m_lldbProc.waitForReadyRead(1000); m_lldbProc.waitForReadyRead(std::chrono::seconds(1));
showStatusMessage(Tr::tr("Setting up inferior...")); showStatusMessage(Tr::tr("Setting up inferior..."));

View File

@@ -14,7 +14,6 @@
#include <CoreFoundation/CoreFoundation.h> #include <CoreFoundation/CoreFoundation.h>
#endif #endif
#include <chrono>
#include <memory> #include <memory>
#include <QJsonArray> #include <QJsonArray>
@@ -23,7 +22,9 @@
#include <QLoggingCategory> #include <QLoggingCategory>
using namespace Utils; using namespace Utils;
using namespace std; using namespace std;
using namespace std::chrono;
namespace { namespace {
static Q_LOGGING_CATEGORY(simulatorLog, "qtc.ios.simulator", QtWarningMsg) static Q_LOGGING_CATEGORY(simulatorLog, "qtc.ios.simulator", QtWarningMsg)
@@ -31,7 +32,7 @@ static Q_LOGGING_CATEGORY(simulatorLog, "qtc.ios.simulator", QtWarningMsg)
namespace Ios::Internal { namespace Ios::Internal {
const std::chrono::seconds simulatorStartTimeout = std::chrono::seconds(60); const seconds simulatorStartTimeout = seconds(60);
// simctl Json Tags and tokens. // simctl Json Tags and tokens.
const char deviceTypeTag[] = "devicetypes"; const char deviceTypeTag[] = "devicetypes";
@@ -61,7 +62,7 @@ static expected_str<void> runCommand(
return make_unexpected(Tr::tr("Failed to start process.")); return make_unexpected(Tr::tr("Failed to start process."));
forever { forever {
if (shouldStop() || p.waitForFinished(1000)) if (shouldStop() || p.waitForFinished(seconds(1)))
break; break;
} }

View File

@@ -49,11 +49,10 @@ QString McuPackageExecutableVersionDetector::parseVersion(const FilePath &packag
break; break;
} }
const int timeout = 3000; // usually runs below 1s, but we want to be on the safe side
Process process; Process process;
process.setCommand({binaryPath, m_detectionArgs}); process.setCommand({binaryPath, m_detectionArgs});
process.start(); process.start();
if (!process.waitForFinished(timeout) || process.result() != ProcessResult::FinishedWithSuccess) if (!process.waitForFinished(std::chrono::seconds(3)) || process.result() != ProcessResult::FinishedWithSuccess)
return {}; return {};
return matchRegExp(process.allOutput(), m_detectionRegExp); return matchRegExp(process.allOutput(), m_detectionRegExp);

View File

@@ -390,7 +390,7 @@ void ProcessExtraCompiler::runInThread(QPromise<FileNameToContentsHash> &promise
return; return;
while (!promise.isCanceled()) { while (!promise.isCanceled()) {
if (process.waitForFinished(200)) if (process.waitForFinished(std::chrono::milliseconds(200)))
break; break;
} }

View File

@@ -1325,7 +1325,7 @@ void SimpleTargetRunnerPrivate::stop()
switch (m_state) { switch (m_state) {
case Run: case Run:
m_process.stop(); m_process.stop();
if (!m_process.waitForFinished(2000)) { // TODO: it may freeze on some devices if (!m_process.waitForFinished(std::chrono::seconds(2))) { // TODO: it may freeze on some devices
q->appendMessage(Tr::tr("Remote process did not finish in time. " q->appendMessage(Tr::tr("Remote process did not finish in time. "
"Connectivity lost?"), ErrorMessageFormat); "Connectivity lost?"), ErrorMessageFormat);
m_process.close(); m_process.close();

View File

@@ -229,7 +229,7 @@ QString QbsProfileManager::runQbsConfig(QbsConfigOp op, const QString &key, cons
Utils::Process qbsConfig; Utils::Process qbsConfig;
qbsConfig.setCommand({qbsConfigExe, args}); qbsConfig.setCommand({qbsConfigExe, args});
qbsConfig.start(); qbsConfig.start();
if (!qbsConfig.waitForFinished(5000)) { if (!qbsConfig.waitForFinished(std::chrono::seconds(5))) {
Core::MessageManager::writeFlashing( Core::MessageManager::writeFlashing(
Tr::tr("Failed to run qbs config: %1").arg(qbsConfig.errorString())); Tr::tr("Failed to run qbs config: %1").arg(qbsConfig.errorString()));
} else if (qbsConfig.exitCode() != 0) { } else if (qbsConfig.exitCode() != 0) {

View File

@@ -215,7 +215,7 @@ QbsSession::~QbsSession()
d->qbsProcess->disconnect(this); d->qbsProcess->disconnect(this);
if (d->qbsProcess->state() == QProcess::Running) { if (d->qbsProcess->state() == QProcess::Running) {
sendQuitPacket(); sendQuitPacket();
d->qbsProcess->waitForFinished(10000); d->qbsProcess->waitForFinished(std::chrono::seconds(10));
} }
delete d->qbsProcess; delete d->qbsProcess;
} }

View File

@@ -35,7 +35,7 @@ static QString getQbsVersion(const FilePath &qbsExe)
Process qbsProc; Process qbsProc;
qbsProc.setCommand({qbsExe, {"--version"}}); qbsProc.setCommand({qbsExe, {"--version"}});
qbsProc.start(); qbsProc.start();
if (!qbsProc.waitForFinished(5000) || qbsProc.exitCode() != 0) if (!qbsProc.waitForFinished(std::chrono::seconds(5)) || qbsProc.exitCode() != 0)
return {}; return {};
return QString::fromLocal8Bit(qbsProc.rawStdOut()).trimmed(); return QString::fromLocal8Bit(qbsProc.rawStdOut()).trimmed();
} }

View File

@@ -107,7 +107,7 @@ EnvironmentItems QnxUtils::qnxEnvironmentFromEnvFile(const FilePath &filePath)
// waiting for finish // waiting for finish
QApplication::setOverrideCursor(Qt::BusyCursor); QApplication::setOverrideCursor(Qt::BusyCursor);
bool waitResult = process.waitForFinished(10000); bool waitResult = process.waitForFinished(std::chrono::seconds(10));
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();
if (!waitResult) if (!waitResult)
return items; return items;

View File

@@ -450,7 +450,7 @@ bool SshProcessInterface::runInShell(const CommandLine &command, const QByteArra
process.setCommand(cmd); process.setCommand(cmd);
process.setWriteData(data); process.setWriteData(data);
process.start(); process.start();
bool isFinished = process.waitForFinished(2000); // It may freeze on some devices bool isFinished = process.waitForFinished(std::chrono::seconds(2)); // It may freeze on some devices
if (!isFinished) { if (!isFinished) {
Core::MessageManager::writeFlashing(tr("Can't send control signal to the %1 device. " Core::MessageManager::writeFlashing(tr("Can't send control signal to the %1 device. "
"The device might have been disconnected.") "The device might have been disconnected.")

View File

@@ -51,7 +51,7 @@ static bool isSilverSearcherAvailable()
Process silverSearcherProcess; Process silverSearcherProcess;
silverSearcherProcess.setCommand({"ag", {"--version"}}); silverSearcherProcess.setCommand({"ag", {"--version"}});
silverSearcherProcess.start(); silverSearcherProcess.start();
return silverSearcherProcess.waitForFinished(1000) return silverSearcherProcess.waitForFinished(std::chrono::seconds(1))
&& silverSearcherProcess.cleanedStdOut().contains("ag version"); && silverSearcherProcess.cleanedStdOut().contains("ag version");
} }

View File

@@ -23,6 +23,8 @@
using namespace Utils; using namespace Utils;
using namespace std::chrono_literals;
namespace TextEditor { namespace TextEditor {
void formatCurrentFile(const Command &command, int startPos, int endPos) void formatCurrentFile(const Command &command, int startPos, int endPos)
@@ -66,7 +68,7 @@ static FormatTask format(FormatTask task)
options.replaceInStrings(QLatin1String("%file"), sourceFile.filePath().toString()); options.replaceInStrings(QLatin1String("%file"), sourceFile.filePath().toString());
Process process; Process process;
process.setCommand({executable, options}); process.setCommand({executable, options});
process.runBlocking(std::chrono::seconds(5)); process.runBlocking(5s);
if (process.result() != ProcessResult::FinishedWithSuccess) { if (process.result() != ProcessResult::FinishedWithSuccess) {
task.error = Tr::tr("Failed to format: %1.").arg(process.exitMessage()); task.error = Tr::tr("Failed to format: %1.").arg(process.exitMessage());
return task; return task;
@@ -94,7 +96,7 @@ static FormatTask format(FormatTask task)
process.setCommand({executable, options}); process.setCommand({executable, options});
process.setWriteData(task.sourceData.toUtf8()); process.setWriteData(task.sourceData.toUtf8());
process.start(); process.start();
if (!process.waitForFinished(5000)) { if (!process.waitForFinished(5s)) {
task.error = Tr::tr("Cannot call %1 or some other error occurred. Timeout " task.error = Tr::tr("Cannot call %1 or some other error occurred. Timeout "
"reached while formatting file %2.") "reached while formatting file %2.")
.arg(executable.toUserOutput(), task.filePath.displayName()); .arg(executable.toUserOutput(), task.filePath.displayName());

View File

@@ -192,7 +192,7 @@ void ValgrindMemcheckParserTest::initTest(const QString &testfile, const QString
m_process->setCommand({FilePath::fromString(fakeValgrind), args + otherArgs}); m_process->setCommand({FilePath::fromString(fakeValgrind), args + otherArgs});
m_process->start(); m_process->start();
QVERIFY(m_process->waitForStarted(5000)); QVERIFY(m_process->waitForStarted(std::chrono::seconds(5)));
QCOMPARE(m_process->state(), QProcess::Running); QCOMPARE(m_process->state(), QProcess::Running);
QVERIFY2(m_process->error() == QProcess::UnknownError, qPrintable(m_process->errorString())); QVERIFY2(m_process->error() == QProcess::UnknownError, qPrintable(m_process->errorString()));
QVERIFY(m_server->waitForNewConnection(5000)); QVERIFY(m_server->waitForNewConnection(5000));

View File

@@ -25,6 +25,8 @@
using namespace Utils; using namespace Utils;
using namespace std::chrono_literals;
static QHash<const char *, ProcessTestApp::SubProcessMain> s_subProcesses = {}; static QHash<const char *, ProcessTestApp::SubProcessMain> s_subProcesses = {};
ProcessTestApp::ProcessTestApp() = default; ProcessTestApp::ProcessTestApp() = default;
@@ -289,12 +291,12 @@ int ProcessTestApp::RecursiveBlockingProcess::main()
process.setProcessChannelMode(QProcess::ForwardedChannels); process.setProcessChannelMode(QProcess::ForwardedChannels);
process.start(); process.start();
while (true) { while (true) {
if (process.waitForFinished(10)) if (process.waitForFinished(10ms))
return 0; return 0;
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
if (s_terminate.load()) { if (s_terminate.load()) {
process.terminate(); process.terminate();
process.waitForFinished(-1); process.waitForFinished(QDeadlineTimer::Forever);
break; break;
} }
#endif #endif

View File

@@ -281,17 +281,17 @@ void tst_Process::multiRead()
QVERIFY(process.waitForStarted()); QVERIFY(process.waitForStarted());
process.writeRaw("hi\n"); process.writeRaw("hi\n");
QVERIFY(process.waitForReadyRead(1000)); QVERIFY(process.waitForReadyRead(1s));
buffer = readData(&process, processChannel); buffer = readData(&process, processChannel);
QCOMPARE(buffer, QByteArray("hi")); QCOMPARE(buffer, QByteArray("hi"));
process.writeRaw("you\n"); process.writeRaw("you\n");
QVERIFY(process.waitForReadyRead(1000)); QVERIFY(process.waitForReadyRead(1s));
buffer = readData(&process, processChannel); buffer = readData(&process, processChannel);
QCOMPARE(buffer, QByteArray("you")); QCOMPARE(buffer, QByteArray("you"));
process.writeRaw("exit\n"); process.writeRaw("exit\n");
QVERIFY(process.waitForFinished(1000)); QVERIFY(process.waitForFinished(1s));
} }
void tst_Process::splitArgs_data() void tst_Process::splitArgs_data()
@@ -1154,15 +1154,16 @@ void tst_Process::notRunningAfterStartingNonExistingProgram()
QElapsedTimer timer; QElapsedTimer timer;
timer.start(); timer.start();
const int maxWaitTimeMs = 1000; const seconds timeout = 1s;
switch (signalType) { switch (signalType) {
case ProcessSignalType::Started: QVERIFY(!process.waitForStarted(maxWaitTimeMs)); break; case ProcessSignalType::Started: QVERIFY(!process.waitForStarted(timeout)); break;
case ProcessSignalType::ReadyRead: QVERIFY(!process.waitForReadyRead(maxWaitTimeMs)); break; case ProcessSignalType::ReadyRead: QVERIFY(!process.waitForReadyRead(timeout)); break;
case ProcessSignalType::Done: QVERIFY(!process.waitForFinished(maxWaitTimeMs)); break; case ProcessSignalType::Done: QVERIFY(!process.waitForFinished(timeout)); break;
} }
QVERIFY(timer.elapsed() < maxWaitTimeMs); // shouldn't wait, should finish immediately // shouldn't wait, should finish immediately
QVERIFY(timer.elapsed() < duration_cast<milliseconds>(timeout).count());
QCOMPARE(process.state(), QProcess::NotRunning); QCOMPARE(process.state(), QProcess::NotRunning);
QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitStatus(), QProcess::NormalExit);
QCOMPARE(process.error(), QProcess::FailedToStart); QCOMPARE(process.error(), QProcess::FailedToStart);
@@ -1284,7 +1285,7 @@ void tst_Process::destroyBlockingProcess()
process.start(); process.start();
QVERIFY(process.waitForStarted()); QVERIFY(process.waitForStarted());
QVERIFY(process.isRunning()); QVERIFY(process.isRunning());
QVERIFY(!process.waitForFinished(1000)); QVERIFY(!process.waitForFinished(1s));
} }
void tst_Process::flushFinishedWhileWaitingForReadyRead_data() void tst_Process::flushFinishedWhileWaitingForReadyRead_data()
@@ -1314,7 +1315,7 @@ void tst_Process::flushFinishedWhileWaitingForReadyRead()
QDeadlineTimer timer(1000); QDeadlineTimer timer(1000);
QByteArray reply; QByteArray reply;
while (process.state() == QProcess::Running) { while (process.state() == QProcess::Running) {
process.waitForReadyRead(500); process.waitForReadyRead(500ms);
if (processChannel == QProcess::StandardOutput) if (processChannel == QProcess::StandardOutput)
reply += process.readAllRawStandardOutput(); reply += process.readAllRawStandardOutput();
else else
@@ -1335,7 +1336,7 @@ void tst_Process::crash()
subConfig.setupSubProcess(&process); subConfig.setupSubProcess(&process);
process.start(); process.start();
QVERIFY(process.waitForStarted(1000)); QVERIFY(process.waitForStarted(1s));
QVERIFY(process.isRunning()); QVERIFY(process.isRunning());
QEventLoop loop; QEventLoop loop;
@@ -1353,11 +1354,11 @@ void tst_Process::crashAfterOneSecond()
subConfig.setupSubProcess(&process); subConfig.setupSubProcess(&process);
process.start(); process.start();
QVERIFY(process.waitForStarted(1000)); QVERIFY(process.waitForStarted(1s));
QElapsedTimer timer; QElapsedTimer timer;
timer.start(); timer.start();
QVERIFY(process.waitForFinished(30000)); QVERIFY(process.waitForFinished(30s));
QVERIFY(timer.elapsed() < 30000); QVERIFY(timer.elapsed() < 30000); // in milliseconds
QCOMPARE(process.state(), QProcess::NotRunning); QCOMPARE(process.state(), QProcess::NotRunning);
QCOMPARE(process.error(), QProcess::Crashed); QCOMPARE(process.error(), QProcess::Crashed);
} }
@@ -1370,7 +1371,7 @@ void tst_Process::recursiveCrashingProcess()
Process process; Process process;
subConfig.setupSubProcess(&process); subConfig.setupSubProcess(&process);
process.start(); process.start();
QVERIFY(process.waitForStarted(1000)); QVERIFY(process.waitForStarted(1s));
QVERIFY(process.waitForFinished()); QVERIFY(process.waitForFinished());
QCOMPARE(process.state(), QProcess::NotRunning); QCOMPARE(process.state(), QProcess::NotRunning);
QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitStatus(), QProcess::NormalExit);
@@ -1544,7 +1545,7 @@ void tst_Process::tarPipe()
if (targetProcess.isRunning()) { if (targetProcess.isRunning()) {
targetProcess.closeWriteChannel(); targetProcess.closeWriteChannel();
QVERIFY(targetProcess.waitForFinished(2000)); QVERIFY(targetProcess.waitForFinished(2s));
} }
QCOMPARE(targetProcess.exitCode(), 0); QCOMPARE(targetProcess.exitCode(), 0);