public void DumpBugReport() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string pathToDumpBugReport = Path.Join(s_scratchAndOutputPath, $"{Path.GetRandomFileName()}.zip"); runner.DumpBugReport(pathToDumpBugReport); _processManager.Verify(pm => pm.Run(s_adbPath, $"bugreport {pathToDumpBugReport}", TimeSpan.FromMinutes(5)), Times.Once); Assert.Equal("Sample BugReport Output", File.ReadAllText(pathToDumpBugReport)); }
public void DumpBugReport() { var runner = new AdbRunner(_mainLog.Object, _processManager.Object, s_adbPath); string pathToDumpBugReport = Path.Join(s_scratchAndOutputPath, Path.GetRandomFileName()); runner.GetDevice(requiredDeviceId: _fakeDeviceList.First().DeviceSerial); runner.DumpBugReport(pathToDumpBugReport); VerifyAdbCall("bugreport", $"{pathToDumpBugReport}.zip"); Assert.Equal("Sample BugReport Output", File.ReadAllText($"{pathToDumpBugReport}.zip")); }
public ExitCode RunApkInstrumentation( string apkPackageName, string?instrumentationName, Dictionary <string, string> instrumentationArguments, string outputDirectory, string?deviceOutputFolder, TimeSpan timeout, int expectedExitCode) { int?instrumentationExitCode = null; // No class name = default Instrumentation ProcessExecutionResults result = _runner.RunApkInstrumentation(apkPackageName, instrumentationName, instrumentationArguments, timeout); bool processCrashed = false; bool failurePullingFiles = false; bool logCatSucceeded; using (_logger.BeginScope("Post-test copy and cleanup")) { if (result.ExitCode == (int)ExitCode.SUCCESS) { (instrumentationExitCode, processCrashed, failurePullingFiles) = ParseInstrumentationResult(apkPackageName, outputDirectory, result.StandardOutput); } // Optionally copy off an entire folder if (!string.IsNullOrEmpty(deviceOutputFolder)) { try { var logs = _runner.PullFiles(apkPackageName, deviceOutputFolder, outputDirectory); foreach (string log in logs) { _logger.LogDebug($"Found output file: {log}"); } } catch (Exception toLog) { _logger.LogError(toLog, "Hit error (typically permissions) trying to pull {filePathOnDevice}", deviceOutputFolder); failurePullingFiles = true; } } logCatSucceeded = _runner.TryDumpAdbLog(Path.Combine(outputDirectory, $"adb-logcat-{apkPackageName}-{(instrumentationName ?? "default")}.log")); if (processCrashed) { _runner.DumpBugReport(Path.Combine(outputDirectory, $"adb-bugreport-{apkPackageName}")); } } // In case emulator crashes halfway through, we can tell by failing to pull ADB logs from it if (!logCatSucceeded) { return(ExitCode.SIMULATOR_FAILURE); } if (result.ExitCode == (int)AdbExitCodes.INSTRUMENTATION_TIMEOUT) { return(ExitCode.TIMED_OUT); } if (processCrashed) { return(ExitCode.APP_CRASH); } if (failurePullingFiles) { _logger.LogError($"Received expected instrumentation exit code ({instrumentationExitCode}), " + "but we hit errors pulling files from the device (see log for details.)"); return(ExitCode.DEVICE_FILE_COPY_FAILURE); } if (!instrumentationExitCode.HasValue) { return(ExitCode.RETURN_CODE_NOT_SET); } if (instrumentationExitCode != expectedExitCode) { _logger.LogError($"Non-success instrumentation exit code: {instrumentationExitCode}, expected: {expectedExitCode}"); return(ExitCode.TESTS_FAILED); } return(ExitCode.SUCCESS); }