From a7a06d6f791b08fa331ef79527e6b6b531951757 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 1 Feb 2024 14:21:03 +0100 Subject: [PATCH] iOS: Move launch result from devicectl to a function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And add a test to document what we expect from devicectl. Change-Id: I1a7f03c50393b99eddb2bfd34b5857e15b28d0a7 Reviewed-by: Tor Arne Vestbø Reviewed-by: --- src/plugins/ios/devicectlutils.cpp | 13 ++++ src/plugins/ios/devicectlutils.h | 1 + src/plugins/ios/iosrunner.cpp | 15 ++--- .../ios/devicectlutils/tst_devicectlutils.cpp | 67 +++++++++++++++++++ 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/src/plugins/ios/devicectlutils.cpp b/src/plugins/ios/devicectlutils.cpp index c9d48d9f015..f8d47caf0be 100644 --- a/src/plugins/ios/devicectlutils.cpp +++ b/src/plugins/ios/devicectlutils.cpp @@ -107,4 +107,17 @@ Utils::expected_str parseProcessIdentifier(const QByteArray &rawOutput) return -1; } +Utils::expected_str parseLaunchResult(const QByteArray &rawOutput) +{ + const Utils::expected_str 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 diff --git a/src/plugins/ios/devicectlutils.h b/src/plugins/ios/devicectlutils.h index fa8fe7c6718..106fee78a23 100644 --- a/src/plugins/ios/devicectlutils.h +++ b/src/plugins/ios/devicectlutils.h @@ -24,5 +24,6 @@ Utils::expected_str> parseDeviceInfo(const QByteArray &ra const QString &deviceUsbId); Utils::expected_str parseAppInfo(const QByteArray &rawOutput, const QString &bundleIdentifier); Utils::expected_str parseProcessIdentifier(const QByteArray &rawOutput); +Utils::expected_str parseLaunchResult(const QByteArray &rawOutput); } // namespace Ios::Internal diff --git a/src/plugins/ios/iosrunner.cpp b/src/plugins/ios/iosrunner.cpp index 9f24f4ac40b..57922d03564 100644 --- a/src/plugins/ios/iosrunner.cpp +++ b/src/plugins/ios/iosrunner.cpp @@ -247,22 +247,15 @@ GroupItem DeviceCtlRunner::launchTask(const QString &bundleIdentifier) reportFailure(Tr::tr("Failed to run devicectl: %1.").arg(process.errorString())); return DoneResult::Error; } - const Utils::expected_str resultValue = parseDevicectlResult( - process.rawStdOut()); - if (resultValue) { - // 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; - } + const Utils::expected_str pid = parseLaunchResult(process.rawStdOut()); + if (pid) { + m_processIdentifier = *pid; m_pollTimer.start(); reportStarted(); return DoneResult::Success; } // failure - reportFailure(resultValue.error()); + reportFailure(pid.error()); return DoneResult::Error; }; return ProcessTask(onSetup, onDone); diff --git a/tests/auto/ios/devicectlutils/tst_devicectlutils.cpp b/tests/auto/ios/devicectlutils/tst_devicectlutils.cpp index 11d093d8e4d..f75497f68a3 100644 --- a/tests/auto/ios/devicectlutils/tst_devicectlutils.cpp +++ b/tests/auto/ios/devicectlutils/tst_devicectlutils.cpp @@ -21,6 +21,8 @@ private slots: void parseAppInfo(); void parseProcessIdentifier(); + + void parseLaunchResult(); }; void tst_Devicectlutils::parseError_data() @@ -407,6 +409,71 @@ void tst_Devicectlutils::parseProcessIdentifier() 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 result = Ios::Internal::parseLaunchResult(data); + QVERIFY(result); + QCOMPARE(*result, 1802); +} + QTEST_GUILESS_MAIN(tst_Devicectlutils) #include "tst_devicectlutils.moc"