private async Task GetTestDefinitionIfRequired(JsonTestDefinition testDefinition) { await GetMovieIfRequired(testDefinition.MovieUrl, testDefinition.MovieSha256); //TODO: Sha256 check var testRomFilename = Path.Combine(TestRomsPath, testDefinition.TestRom.RomSha256); if (!File.Exists(testRomFilename)) { _logger.Information("Need to download test ROM for test {testDefinitionId}", testDefinition.TestDefinitionId); var client = new HttpClient(); var result = await client.GetAsync(testDefinition.TestRom.RomUrl); if (result.IsSuccessStatusCode) { _logger.Information("Download Completed, Saving"); using (var file = File.OpenWrite(testRomFilename)) await result.Content.CopyToAsync(file); } else { _logger.Error("Download Failed {statusCode} {reason}", result.StatusCode, result.ReasonPhrase); throw new Exception("Failed to download testDefinition.TestRom " + testDefinition.TestDefinitionId); } } }
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!"); }