protected void AddWrenchLogFiles(StreamReader stream) { string line; while ((line = stream.ReadLine()) != null) { if (!line.StartsWith("@MonkeyWrench: ", StringComparison.Ordinal)) { continue; } var cmd = line.Substring("@MonkeyWrench:".Length).TrimStart(); var colon = cmd.IndexOf(':'); if (colon <= 0) { continue; } var name = cmd.Substring(0, colon); switch (name) { case "AddFile": var src = cmd.Substring(name.Length + 1).Trim(); Logs.AddFile(src); break; default: Harness.HarnessLog.WriteLine("Unknown @MonkeyWrench command in {0}: {1}", TestName, name); break; } } }
public void AddFilePathNullTest() { using (var logs = new Logs(_directory)) { Assert.Throws <ArgumentNullException>(() => logs.AddFile(null, _description)); } }
protected override async Task RunTestAsync() { var projectDir = System.IO.Path.GetDirectoryName(ProjectFile); var name = System.IO.Path.GetFileName(projectDir); using (var resource = await NotifyAndAcquireDesktopResourceAsync()) { using (var proc = new Process()) { proc.StartInfo.FileName = "/Library/Frameworks/Mono.framework/Commands/mono"; var reporter = System.IO.Path.Combine(WorkingDirectory, "xtro-report/bin/Debug/xtro-report.exe"); var results = System.IO.Path.Combine(Logs.Directory, $"xtro-{Timestamp}"); proc.StartInfo.Arguments = $"--debug {reporter} {WorkingDirectory} {results}"; Jenkins.MainLog.WriteLine("Executing {0} ({1})", TestName, Mode); var log = Logs.Create($"execute-xtro-{Timestamp}.txt", LogType.ExecutionLog.ToString()); log.WriteLine("{0} {1}", proc.StartInfo.FileName, proc.StartInfo.Arguments); if (!Harness.DryRun) { ExecutionResult = TestExecutingResult.Running; var snapshot = new CrashReportSnapshot() { Device = false, Harness = Harness, Log = log, Logs = Logs, LogDirectory = LogDirectory }; await snapshot.StartCaptureAsync(); try { var timeout = TimeSpan.FromMinutes(20); var result = await ProcessManager.RunAsync(proc, log, timeout); if (result.TimedOut) { FailureMessage = $"Execution timed out after {timeout.TotalSeconds} seconds."; log.WriteLine(FailureMessage); ExecutionResult = TestExecutingResult.TimedOut; } else if (result.Succeeded) { ExecutionResult = TestExecutingResult.Succeeded; } else { ExecutionResult = TestExecutingResult.Failed; FailureMessage = result.ExitCode != 1 ? $"Test run crashed (exit code: {result.ExitCode})." : "Test run failed."; log.WriteLine(FailureMessage); } } finally { await snapshot.EndCaptureAsync(TimeSpan.FromSeconds(Succeeded ? 0 : 5)); } } Jenkins.MainLog.WriteLine("Executed {0} ({1})", TestName, Mode); Logs.AddFile(System.IO.Path.Combine(results, "index.html"), "HTML Report"); } } }
public void AddFileTest() { var fullPath = Path.Combine(directory, fileName); File.Create(fullPath); using (var logs = new Logs(directory)) { var fileLog = logs.AddFile(fullPath, description); Assert.AreEqual(fullPath, fileLog.Path, "path"); // path && fullPath are the same Assert.AreEqual(Path.Combine(directory, fileName), fileLog.FullPath, "full path"); Assert.AreEqual(description, fileLog.Description, "description"); } }
public void AddFileTest() { var fullPath = Path.Combine(_directory, _fileName); File.WriteAllText(fullPath, "foo"); using (var logs = new Logs(_directory)) { var fileLog = logs.AddFile(fullPath, _description); Assert.Equal(fullPath, fileLog.FullPath); // path && fullPath are the same Assert.Equal(Path.Combine(_directory, _fileName), fileLog.FullPath); Assert.Equal(_description, fileLog.Description); } }
public void AddFileNotInDirTest() { var fullPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileName); using (var stream = File.Create(fullPath)) using (var writer = new StreamWriter(stream)){ writer.WriteLine("Hello world!"); } using (var logs = new Logs(directory)) { var newPath = Path.Combine(directory, Path.GetFileNameWithoutExtension(fileName)); var fileLog = logs.AddFile(fileName, description); StringAssert.StartsWith(newPath, fileLog.Path, "path"); // assert new path StringAssert.StartsWith(newPath, fileLog.FullPath, "full path"); // assert new path is used Assert.IsTrue(File.Exists(fileLog.FullPath), "copy"); } }
public void AddFileNotInDirTest() { var dir1 = Path.Combine(directory, "dir1"); var dir2 = Path.Combine(directory, "dir2"); Directory.CreateDirectory(dir1); Directory.CreateDirectory(dir2); var filePath = Path.Combine(dir1, "test-file.txt"); File.WriteAllText(filePath, "Hello world!"); using (var logs = new Logs(dir2)) { var newPath = Path.Combine(dir2, Path.GetFileNameWithoutExtension(fileName)); var fileLog = logs.AddFile(filePath, description); StringAssert.StartsWith(newPath, fileLog.FullPath, "path"); // assert new path Assert.IsTrue(File.Exists(fileLog.FullPath), "copy"); } }
public async Task EndCaptureAsync(TimeSpan timeout) { // Check for crash reports var crash_report_search_done = false; var crash_report_search_timeout = timeout.TotalSeconds; var watch = new Stopwatch(); watch.Start(); do { var end_crashes = await Harness.CreateCrashReportsSnapshotAsync(Log, !Device, DeviceName); end_crashes.ExceptWith(InitialSet); Reports = end_crashes; if (end_crashes.Count > 0) { Log.WriteLine("Found {0} new crash report(s)", end_crashes.Count); List <ILogFile> crash_reports; if (!Device) { crash_reports = new List <ILogFile> (end_crashes.Count); foreach (var path in end_crashes) { Logs.AddFile(path, $"Crash report: {Path.GetFileName (path)}"); } } else { // Download crash reports from the device. We put them in the project directory so that they're automatically deleted on wrench // (if we put them in /tmp, they'd never be deleted). var downloaded_crash_reports = new List <ILogFile> (); foreach (var file in end_crashes) { var name = Path.GetFileName(file); var crash_report_target = Logs.Create(name, $"Crash report: {name}", timestamp: false); var sb = new List <string> (); sb.Add($"--download-crash-report={file}"); sb.Add($"--download-crash-report-to={crash_report_target.Path}"); sb.Add("--sdkroot"); sb.Add(Harness.XcodeRoot); if (!string.IsNullOrEmpty(DeviceName)) { sb.Add("--devname"); sb.Add(DeviceName); } var result = await ProcessHelper.ExecuteCommandAsync(Harness.MlaunchPath, sb, Log, TimeSpan.FromMinutes(1)); if (result.Succeeded) { Log.WriteLine("Downloaded crash report {0} to {1}", file, crash_report_target.Path); crash_report_target = await Harness.SymbolicateCrashReportAsync(Logs, Log, crash_report_target); downloaded_crash_reports.Add(crash_report_target); } else { Log.WriteLine("Could not download crash report {0}", file); } } crash_reports = downloaded_crash_reports; } foreach (var cp in crash_reports) { Harness.LogWrench("@MonkeyWrench: AddFile: {0}", cp.Path); Log.WriteLine(" {0}", cp.Path); } crash_report_search_done = true; } else { if (watch.Elapsed.TotalSeconds > crash_report_search_timeout) { crash_report_search_done = true; } else { Log.WriteLine("No crash reports, waiting a second to see if the crash report service just didn't complete in time ({0})", (int)(crash_report_search_timeout - watch.Elapsed.TotalSeconds)); Thread.Sleep(TimeSpan.FromSeconds(1)); } } } while (!crash_report_search_done); }