forked from qt-creator/qt-creator
iOS: Move process id gathering from devicectl to a function
And add a test to document what we expect from devicectl. Change-Id: Ic69af99a472976a6c06801a646af59f8139d5624 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
@@ -96,4 +96,15 @@ Utils::expected_str<QUrl> parseAppInfo(const QByteArray &rawOutput, const QStrin
|
||||
return {};
|
||||
}
|
||||
|
||||
Utils::expected_str<qint64> parseProcessIdentifier(const QByteArray &rawOutput)
|
||||
{
|
||||
const expected_str<QJsonValue> result = parseDevicectlResult(rawOutput);
|
||||
if (!result)
|
||||
return make_unexpected(result.error());
|
||||
const QJsonArray matchingProcesses = (*result)["runningProcesses"].toArray();
|
||||
if (matchingProcesses.size() > 0)
|
||||
return matchingProcesses.first()["processIdentifier"].toInteger(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace Ios::Internal
|
||||
|
@@ -23,5 +23,6 @@ Utils::expected_str<QJsonValue> parseDevicectlResult(const QByteArray &rawOutput
|
||||
Utils::expected_str<QMap<QString, QString>> parseDeviceInfo(const QByteArray &rawOutput,
|
||||
const QString &deviceUsbId);
|
||||
Utils::expected_str<QUrl> parseAppInfo(const QByteArray &rawOutput, const QString &bundleIdentifier);
|
||||
Utils::expected_str<qint64> parseProcessIdentifier(const QByteArray &rawOutput);
|
||||
|
||||
} // namespace Ios::Internal
|
||||
|
@@ -178,17 +178,12 @@ GroupItem DeviceCtlRunner::findProcess(Storage<AppInfo> &appInfo)
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
const auto onDone = [this, appInfo](const Process &process) {
|
||||
const Utils::expected_str<QJsonValue> resultValue = parseDevicectlResult(
|
||||
process.rawStdOut());
|
||||
if (resultValue) {
|
||||
const QJsonArray matchingProcesses = (*resultValue)["runningProcesses"].toArray();
|
||||
if (matchingProcesses.size() > 0) {
|
||||
appInfo->processIdentifier
|
||||
= matchingProcesses.first()["processIdentifier"].toInteger(-1);
|
||||
}
|
||||
const Utils::expected_str<qint64> pid = parseProcessIdentifier(process.rawStdOut());
|
||||
if (pid) {
|
||||
appInfo->processIdentifier = *pid;
|
||||
return DoneResult::Success;
|
||||
}
|
||||
reportFailure(resultValue.error());
|
||||
reportFailure(pid.error());
|
||||
return DoneResult::Error;
|
||||
};
|
||||
return ProcessTask(onSetup, onDone);
|
||||
|
@@ -19,6 +19,8 @@ private slots:
|
||||
void parseDeviceInfo();
|
||||
|
||||
void parseAppInfo();
|
||||
|
||||
void parseProcessIdentifier();
|
||||
};
|
||||
|
||||
void tst_Devicectlutils::parseError_data()
|
||||
@@ -363,6 +365,48 @@ void tst_Devicectlutils::parseAppInfo()
|
||||
"FAEC04B7-41E6-4A3C-952E-D89792DA053C/cmake_widgets.app/"));
|
||||
}
|
||||
|
||||
void tst_Devicectlutils::parseProcessIdentifier()
|
||||
{
|
||||
const QByteArray data(R"raw(
|
||||
{
|
||||
"info" : {
|
||||
"arguments" : [
|
||||
"devicectl",
|
||||
"device",
|
||||
"info",
|
||||
"processes",
|
||||
"--device",
|
||||
"00000000-0000000000000000",
|
||||
"--quiet",
|
||||
"--json-output",
|
||||
"-",
|
||||
"--filter",
|
||||
"executable.path BEGINSWITH '/private/var/containers/Bundle/Application/00000000-0000-0000-0000-000000000000/test.app'"
|
||||
],
|
||||
"commandType" : "devicectl.device.info.processes",
|
||||
"environment" : {
|
||||
"TERM" : "xterm-256color"
|
||||
},
|
||||
"jsonVersion" : 2,
|
||||
"outcome" : "success",
|
||||
"version" : "355.7.7"
|
||||
},
|
||||
"result" : {
|
||||
"deviceIdentifier" : "00000000-0000-0000-0000-000000000000",
|
||||
"runningProcesses" : [
|
||||
{
|
||||
"executable" : "file:///private/var/containers/Bundle/Application/00000000-0000-0000-0000-000000000000/test.app/test",
|
||||
"processIdentifier" : 1000
|
||||
}
|
||||
]
|
||||
}
|
||||
})raw");
|
||||
|
||||
const Utils::expected_str<qint64> result = Ios::Internal::parseProcessIdentifier(data);
|
||||
QVERIFY(result);
|
||||
QCOMPARE(*result, 1000);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(tst_Devicectlutils)
|
||||
|
||||
#include "tst_devicectlutils.moc"
|
||||
|
Reference in New Issue
Block a user