CSPspEmu.AutoTests.AutoTestsProgram.RunExecutableAndGetOutput C# (CSharp) Method

RunExecutableAndGetOutput() protected method

protected RunExecutableAndGetOutput ( bool RunTestsViewOut, string PspAutoTestsFolder, string FileName, string &CapturedOutput, string FileNameBase ) : string
RunTestsViewOut bool
PspAutoTestsFolder string
FileName string
CapturedOutput string
FileNameBase string
return string
        protected string RunExecutableAndGetOutput(bool RunTestsViewOut, string PspAutoTestsFolder, string FileName, out string CapturedOutput, string FileNameBase)
        {
            var OutputString = "";

            IHleIoDriver HostDriver = null;

            //Console.WriteLine(FileNameBase);

            InjectContext _InjectContext = null;
            {
                //var Capture = false;
                var Capture = !RunTestsViewOut;
                CapturedOutput = ConsoleUtils.CaptureOutput(() =>
                {
                    _InjectContext = PspInjectContext.CreateInjectContext(StoredConfig, Test: true);
                    _InjectContext.SetInstanceType<HleOutputHandler, HleOutputHandlerMock>();

                    var CpuConfig = _InjectContext.GetInstance<CpuConfig>();
                    var HleConfig = _InjectContext.GetInstance<HleConfig>();
                    CpuConfig.DebugSyscalls = false;
                    CpuConfig.ShowInstructionStats = false;
                    HleConfig.TraceLastSyscalls = false;
                    HleConfig.DebugSyscalls = false;

                    //Console.Error.WriteLine("[1]");

                    var Start = DateTime.UtcNow;
                    _InjectContext.GetInstance<HleModuleManager>();
                    var End = DateTime.UtcNow;
                    Console.WriteLine(End - Start);

                    //Console.Error.WriteLine("[a]");

                    // GPU -> NULL
                    //PspEmulatorContext.SetInstanceType<GpuImpl>(typeof(GpuImplOpenglEs));
                    _InjectContext.SetInstanceType<GpuImpl>(typeof(GpuImplNull));

                    var GpuImpl = _InjectContext.GetInstance<GpuImpl>();
                    //GpuImpl.InitSynchronizedOnce();

                    //Console.Error.WriteLine("[b]");

                    var PspRunner = _InjectContext.GetInstance<PspRunner>();
                    PspRunner.StartSynchronized();

                    //Console.Error.WriteLine("[c]");

                    {
                        try
                        {
                            //PspRunner.CpuComponentThread.SetIso(PspAutoTestsFolder + "/../input/test.cso");
                            PspRunner.CpuComponentThread.SetIso(PspAutoTestsFolder + "/../input/cube.cso");
                            //Console.Error.WriteLine("[2]");

                            var HleIoManager = _InjectContext.GetInstance<HleIoManager>();
                            HostDriver = HleIoManager.GetDriver("host:");

                            try { HostDriver.IoRemove(null, "/__testoutput.txt"); } catch { }
                            try { HostDriver.IoRemove(null, "/__testerror.txt"); } catch { }

                            _InjectContext.GetInstance<PspHleRunningConfig>().FileNameBase = FileNameBase;
                            PspRunner.CpuComponentThread._LoadFile(FileName);
                            //Console.Error.WriteLine("[3]");
                            if (!PspRunner.CpuComponentThread.StoppedEndedEvent.WaitOne(TimeoutTime))
                            {
                                ConsoleUtils.SaveRestoreConsoleColor(ConsoleColor.Red, () =>
                                {
                                    Console.Error.WriteLine("Timeout!");
                                });
                            }
                        }
                        catch (Exception Exception)
                        {
                            Console.Error.WriteLine(Exception);
                        }
                    }

                    PspRunner.StopSynchronized();
                    GC.Collect();

                    using (var test_output = HostDriver.OpenRead("/__testoutput.txt"))
                    {
                        OutputString = test_output.ReadAllContentsAsString();
                    }
                },
                Capture: Capture
                );

                //var HleOutputHandlerMock = (HleOutputHandlerMock)PspEmulatorContext.GetInstance<HleOutputHandler>();
                //OutputString = HleOutputHandlerMock.OutputString;
            }
            _InjectContext.Dispose();

            return OutputString;
        }