forked from qt-creator/qt-creator
iOS: Move launch result from devicectl to a function
And add a test to document what we expect from devicectl. Change-Id: I1a7f03c50393b99eddb2bfd34b5857e15b28d0a7 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -107,4 +107,17 @@ Utils::expected_str<qint64> parseProcessIdentifier(const QByteArray &rawOutput)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Utils::expected_str<qint64> parseLaunchResult(const QByteArray &rawOutput)
|
||||||
|
{
|
||||||
|
const Utils::expected_str<QJsonValue> result = parseDevicectlResult(rawOutput);
|
||||||
|
if (!result)
|
||||||
|
return make_unexpected(result.error());
|
||||||
|
const qint64 pid = (*result)["process"]["processIdentifier"].toInteger(-1);
|
||||||
|
if (pid < 0) {
|
||||||
|
// something unexpected happened ...
|
||||||
|
return make_unexpected(Tr::tr("devicectl returned unexpected output ... running failed."));
|
||||||
|
}
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Ios::Internal
|
} // namespace Ios::Internal
|
||||||
|
@@ -24,5 +24,6 @@ Utils::expected_str<QMap<QString, QString>> parseDeviceInfo(const QByteArray &ra
|
|||||||
const QString &deviceUsbId);
|
const QString &deviceUsbId);
|
||||||
Utils::expected_str<QUrl> parseAppInfo(const QByteArray &rawOutput, const QString &bundleIdentifier);
|
Utils::expected_str<QUrl> parseAppInfo(const QByteArray &rawOutput, const QString &bundleIdentifier);
|
||||||
Utils::expected_str<qint64> parseProcessIdentifier(const QByteArray &rawOutput);
|
Utils::expected_str<qint64> parseProcessIdentifier(const QByteArray &rawOutput);
|
||||||
|
Utils::expected_str<qint64> parseLaunchResult(const QByteArray &rawOutput);
|
||||||
|
|
||||||
} // namespace Ios::Internal
|
} // namespace Ios::Internal
|
||||||
|
@@ -247,22 +247,15 @@ GroupItem DeviceCtlRunner::launchTask(const QString &bundleIdentifier)
|
|||||||
reportFailure(Tr::tr("Failed to run devicectl: %1.").arg(process.errorString()));
|
reportFailure(Tr::tr("Failed to run devicectl: %1.").arg(process.errorString()));
|
||||||
return DoneResult::Error;
|
return DoneResult::Error;
|
||||||
}
|
}
|
||||||
const Utils::expected_str<QJsonValue> resultValue = parseDevicectlResult(
|
const Utils::expected_str<qint64> pid = parseLaunchResult(process.rawStdOut());
|
||||||
process.rawStdOut());
|
if (pid) {
|
||||||
if (resultValue) {
|
m_processIdentifier = *pid;
|
||||||
// success
|
|
||||||
m_processIdentifier = (*resultValue)["process"]["processIdentifier"].toInteger(-1);
|
|
||||||
if (m_processIdentifier < 0) {
|
|
||||||
// something unexpected happened ...
|
|
||||||
reportFailure(Tr::tr("devicectl returned unexpected output ... running failed."));
|
|
||||||
return DoneResult::Error;
|
|
||||||
}
|
|
||||||
m_pollTimer.start();
|
m_pollTimer.start();
|
||||||
reportStarted();
|
reportStarted();
|
||||||
return DoneResult::Success;
|
return DoneResult::Success;
|
||||||
}
|
}
|
||||||
// failure
|
// failure
|
||||||
reportFailure(resultValue.error());
|
reportFailure(pid.error());
|
||||||
return DoneResult::Error;
|
return DoneResult::Error;
|
||||||
};
|
};
|
||||||
return ProcessTask(onSetup, onDone);
|
return ProcessTask(onSetup, onDone);
|
||||||
|
@@ -21,6 +21,8 @@ private slots:
|
|||||||
void parseAppInfo();
|
void parseAppInfo();
|
||||||
|
|
||||||
void parseProcessIdentifier();
|
void parseProcessIdentifier();
|
||||||
|
|
||||||
|
void parseLaunchResult();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_Devicectlutils::parseError_data()
|
void tst_Devicectlutils::parseError_data()
|
||||||
@@ -407,6 +409,71 @@ void tst_Devicectlutils::parseProcessIdentifier()
|
|||||||
QCOMPARE(*result, 1000);
|
QCOMPARE(*result, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_Devicectlutils::parseLaunchResult()
|
||||||
|
{
|
||||||
|
const QByteArray data(R"raw(
|
||||||
|
{
|
||||||
|
"info" : {
|
||||||
|
"arguments" : [
|
||||||
|
"devicectl",
|
||||||
|
"device",
|
||||||
|
"process",
|
||||||
|
"launch",
|
||||||
|
"--device",
|
||||||
|
"00000000-0000000000000000",
|
||||||
|
"--quiet",
|
||||||
|
"--json-output",
|
||||||
|
"-",
|
||||||
|
"org.iuehrg.cmake-widgets"
|
||||||
|
],
|
||||||
|
"commandType" : "devicectl.device.process.launch",
|
||||||
|
"environment" : {
|
||||||
|
"TERM" : "xterm-256color"
|
||||||
|
},
|
||||||
|
"jsonVersion" : 2,
|
||||||
|
"outcome" : "success",
|
||||||
|
"version" : "355.7.7"
|
||||||
|
},
|
||||||
|
"result" : {
|
||||||
|
"deviceIdentifier" : "00000000-0000-0000-0000-000000000000",
|
||||||
|
"launchOptions" : {
|
||||||
|
"activatedWhenStarted" : true,
|
||||||
|
"arguments" : [
|
||||||
|
|
||||||
|
],
|
||||||
|
"environmentVariables" : {
|
||||||
|
"TERM" : "xterm-256color"
|
||||||
|
},
|
||||||
|
"platformSpecificOptions" : {
|
||||||
|
|
||||||
|
},
|
||||||
|
"startStopped" : false,
|
||||||
|
"terminateExistingInstances" : false,
|
||||||
|
"user" : {
|
||||||
|
"active" : true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"process" : {
|
||||||
|
"auditToken" : [
|
||||||
|
4294967295,
|
||||||
|
501,
|
||||||
|
501,
|
||||||
|
501,
|
||||||
|
501,
|
||||||
|
1802,
|
||||||
|
0,
|
||||||
|
5118
|
||||||
|
],
|
||||||
|
"executable" : "file:///private/var/containers/Bundle/Application/00000000-0000-0000-0000-000000000000/test.app/test",
|
||||||
|
"processIdentifier" : 1802
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})raw");
|
||||||
|
const Utils::expected_str<qint64> result = Ios::Internal::parseLaunchResult(data);
|
||||||
|
QVERIFY(result);
|
||||||
|
QCOMPARE(*result, 1802);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_GUILESS_MAIN(tst_Devicectlutils)
|
QTEST_GUILESS_MAIN(tst_Devicectlutils)
|
||||||
|
|
||||||
#include "tst_devicectlutils.moc"
|
#include "tst_devicectlutils.moc"
|
||||||
|
Reference in New Issue
Block a user