-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #912 from MarathonLabs/feature/simulator-log
feat(apple): add simulator log dump per batch at device-logs
- Loading branch information
Showing
9 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ase/src/main/kotlin/com/malinskiy/marathon/apple/bin/xcrun/simctl/service/SpawnService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.malinskiy.marathon.apple.bin.xcrun.simctl.service | ||
|
||
import com.malinskiy.marathon.apple.bin.xcrun.simctl.SimctlService | ||
import com.malinskiy.marathon.apple.cmd.CommandExecutor | ||
import com.malinskiy.marathon.apple.cmd.CommandResult | ||
import com.malinskiy.marathon.apple.cmd.CommandSession | ||
import com.malinskiy.marathon.config.vendor.apple.ios.Permission | ||
import com.malinskiy.marathon.config.vendor.apple.TimeoutConfiguration | ||
import java.time.Duration | ||
|
||
class SpawnService(commandExecutor: CommandExecutor, | ||
private val timeoutConfiguration: TimeoutConfiguration, | ||
) : SimctlService(commandExecutor) { | ||
/** | ||
* Spawn a process by executing a given executable on a device | ||
*/ | ||
suspend fun spawn(udid: String, args: Array<String>, timeout: Duration = timeoutConfiguration.shell): CommandResult { | ||
return criticalExec( | ||
timeout = timeout, | ||
"spawn", udid, *args | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...le/ios/src/main/kotlin/com/malinskiy/marathon/apple/ios/listener/log/DeviceLogListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.malinskiy.marathon.apple.ios.listener.log | ||
|
||
import com.malinskiy.marathon.apple.extensions.Durations | ||
import com.malinskiy.marathon.apple.ios.AppleSimulatorDevice | ||
import com.malinskiy.marathon.apple.listener.AppleTestRunListener | ||
import com.malinskiy.marathon.apple.model.Sdk | ||
import com.malinskiy.marathon.device.DevicePoolId | ||
import com.malinskiy.marathon.device.toDeviceInfo | ||
import com.malinskiy.marathon.io.FileType | ||
import com.malinskiy.marathon.log.MarathonLogging | ||
import com.malinskiy.marathon.test.TestBatch | ||
import kotlin.system.measureTimeMillis | ||
|
||
class DeviceLogListener( | ||
private val device: AppleSimulatorDevice, | ||
private val enabled: Boolean, | ||
private val pool: DevicePoolId, | ||
private val testBatch: TestBatch, | ||
) : AppleTestRunListener { | ||
|
||
private var pid: String? = null | ||
private val logger = MarathonLogging.logger {} | ||
private val supported by lazy { | ||
when (device.sdk) { | ||
Sdk.IPHONESIMULATOR, Sdk.TV_SIMULATOR, Sdk.WATCH_SIMULATOR, Sdk.VISION_SIMULATOR -> { | ||
true | ||
} | ||
|
||
else -> false | ||
} | ||
} | ||
|
||
override suspend fun beforeTestRun() { | ||
super.beforeTestRun() | ||
if (!enabled) return | ||
|
||
if (!supported) { | ||
logger.warn { "Device ${device.serialNumber} does not support capturing device logs" } | ||
return | ||
} | ||
|
||
val remoteLogPath = device.remoteFileManager.remoteLog() | ||
val result = | ||
device.commandExecutor.criticalExecute( | ||
Durations.INFINITE, | ||
"sh", | ||
"-c", | ||
"xcrun simctl spawn ${device.udid} log stream --type log --color none --style compact 2>/dev/null > $remoteLogPath & echo $!" | ||
) | ||
val possiblePid = result.combinedStdout.trim() | ||
if (result.successful && possiblePid.toIntOrNull() != null) { | ||
pid = result.combinedStdout.trim() | ||
} | ||
} | ||
|
||
override suspend fun afterTestRun() { | ||
super.afterTestRun() | ||
if (!enabled) return | ||
if (!supported) { | ||
logger.warn { "Device ${device.serialNumber} does not support capturing device logs" } | ||
return | ||
} | ||
|
||
if (pid != null) { | ||
device.executeWorkerCommand(listOf("sh", "-c", "kill -s INT $pid")) | ||
pullLogfile() | ||
} | ||
} | ||
|
||
private suspend fun pullLogfile() { | ||
val localLogFile = | ||
device.fileManager.createFile(FileType.DEVICE_LOG, pool, device.toDeviceInfo(), test = null, testBatchId = testBatch.id) | ||
val remoteFilePath = device.remoteFileManager.remoteLog() | ||
val millis = measureTimeMillis { | ||
device.pullFile(remoteFilePath, localLogFile) | ||
} | ||
logger.debug { "Pulling finished in ${millis}ms $remoteFilePath " } | ||
} | ||
} |