/// <summary> /// Throws an exception if we fail to fetch the build /// </summary> private async Task GetBuildIfRequired(JsonCitraBuild build) { if (!Directory.Exists(BuildsPath)) { Directory.CreateDirectory(BuildsPath); } var buildPath = Path.Combine(BuildsPath, build.CitraBuildId.ToString()); if (!Directory.Exists(buildPath) || !Directory.EnumerateFiles(buildPath, CitraExecutable, SearchOption.AllDirectories).Any()) { _logger.Information("Need to download build {buildId}", build.CitraBuildId); var client = new HttpClient(); var result = await client.GetAsync(UrlForOurOs(build)); if (result.IsSuccessStatusCode) { _logger.Information("Download Completed, Extracting"); var tmpFileName = Path.GetTempFileName(); using (var file = File.OpenWrite(tmpFileName)) await result.Content.CopyToAsync(file); //TODO: Unzip or use others, this is windows zip only ZipFile.ExtractToDirectory(tmpFileName, buildPath, true); } else { _logger.Error("Download Failed {statusCode} {reason}", result.StatusCode, result.ReasonPhrase); throw new Exception("Failed to download build " + build.CitraBuildId); } } }
public async Task RunTest(JsonCitraBuild build, JsonTestDefinition testDefinition) { _logger.Information("Preparing to Run Test {testDefinitionId} for Build {citraBuildId}", testDefinition.TestDefinitionId, build.CitraBuildId); var movieFilename = Path.GetFullPath(Path.Combine(MoviesPath, testDefinition.MovieSha256)); var testRomFilename = Path.GetFullPath(Path.Combine(TestRomsPath, testDefinition.TestRom.RomSha256)); var runResult = await RunCitra(build, movieFilename, testRomFilename, "--movie-test", null); //TODO: If the app crashed or timed out there won't be any screenshot files var screenshotTop = GetRotatedPngScreenshot(Path.Combine(TempPath, "screenshot_top.bmp")); var screenshotBottom = GetRotatedPngScreenshot(Path.Combine(TempPath, "screenshot_bottom.bmp")); _logger.Information("Submitting result"); await _client.ApiTestResultsAddPostAsync(new NewTestResult { JanitraBotId = Options.JanitraBotId, AccessKey = Options.AccessKey, CitraBuildId = build.CitraBuildId, TestDefinitionId = testDefinition.TestDefinitionId, Log = Encoding.UTF8.GetBytes(runResult.Log), ExecutionResult = runResult.ExecutionResult, TimeTakenSeconds = runResult.Elapsed.TotalSeconds, ScreenshotTop = screenshotTop, ScreenshotBottom = screenshotBottom }); _logger.Information("Done!"); }
private string UrlForOurOs(JsonCitraBuild build) { switch (Environment.OSVersion.Platform) { case PlatformID.MacOSX: return(build.OsxUrl); case PlatformID.Unix: return(build.LinuxUrl); case PlatformID.Win32NT: return(build.WindowsUrl); default: throw new Exception("Don't know what platform matches " + Environment.OSVersion.Platform); } }
private async Task RunRomMovie(JsonCitraBuild build, JsonRom rom, Rom romToUse, JsonRomMovie movie) { _logger.Information("Preparing to Run Rom {romName} with Movie {movie} for Build {citraBuildId}", rom.Name, movie.Name, build.CitraBuildId); var movieFilename = Path.GetFullPath(Path.Combine(MoviesPath, movie.MovieSha256)); var settings = new CitraSettings { RegionValue = movie.CitraRegionValue }; var result = await RunCitra(build, movieFilename, romToUse.FullPath, "--movie-test-continuous", settings); _logger.Information("Finished running {romName}, result: {executionResult}", rom.Name, result.ExecutionResult); var screenshots = new List <NewScreenshot>(); foreach (var file in Directory.EnumerateFiles(TempPath, "*_top.bmp")) { //screenshot_%i_top.bmp (and bottom) screenshots.Add(new NewScreenshot { FrameNumber = int.Parse(Path.GetFileName(file).Replace("screenshot_", "").Replace("_top.bmp", "")), TopImage = GetRotatedPngScreenshot(file), BottomImage = GetRotatedPngScreenshot(file.Replace("_top.bmp", "_bottom.bmp")) }); } await _client.ApiRomMovieResultsAddPostAsync(new NewRomMovieResult { CitraBuildId = build.CitraBuildId, JanitraBotId = Options.JanitraBotId, RomMovieId = movie.RomMovieId, AccessKey = Options.AccessKey, Log = Encoding.UTF8.GetBytes(result.Log), ExecutionResult = Enum.Parse <NewRomMovieResultExecutionResult>(result.ExecutionResult.ToString()), Screenshots = screenshots, TimeTakenSeconds = result.Elapsed.TotalSeconds }); }
private string GetBuildExecutablePath(JsonCitraBuild build) { var buildPath = Path.Combine(BuildsPath, build.CitraBuildId.ToString()); return(Directory.EnumerateFiles(buildPath, CitraExecutable, SearchOption.AllDirectories).SingleOrDefault()); }
private async Task <RunResult> RunCitra(JsonCitraBuild build, string movieFilename, string testRomFilename, string mode, CitraSettings citraSettings) { PlaceProfile(); if (citraSettings != null) { SetProfileRegion(citraSettings.RegionValue); } foreach (var file in Directory.EnumerateFiles(TempPath)) { File.Delete(file); } var executable = GetBuildExecutablePath(build); var process = new Process(); process.StartInfo.FileName = executable; process.StartInfo.Arguments = $"--movie-play \"{movieFilename}\" {mode} \"{testRomFilename}\""; process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.WorkingDirectory = Path.GetFullPath(TempPath); var log = new StringBuilder(); process.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs eventArgs) { lock (log) log.AppendLine(eventArgs.Data); }; process.OutputDataReceived += delegate(object sender, DataReceivedEventArgs eventArgs) { lock (log) log.AppendLine(eventArgs.Data); }; var result = NewTestResultExecutionResult.Completed; _logger.Information("Starting test"); var stopwatch = Stopwatch.StartNew(); process.Start(); process.BeginErrorReadLine(); process.BeginOutputReadLine(); if (!process.WaitForExit(5 * 60 * 1000)) //if (!process.WaitForExit(10 * 1000)) { process.Kill(); result = NewTestResultExecutionResult.Timeout; } stopwatch.Stop(); if (process.ExitCode != 0 && result != NewTestResultExecutionResult.Timeout) { result = NewTestResultExecutionResult.Crash; } _logger.Information("Test finished, result {result}", result); _logger.Information("Got {logLength} bytes of logs", log.Length); var runResult = new RunResult { Elapsed = stopwatch.Elapsed, ExecutionResult = result, Log = log.ToString() }; return(runResult); }