예제 #1
0
        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
            });
        }
예제 #2
0
        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);
        }