static void ShowData(OutputData odata) { if(!string.IsNullOrEmpty(odata.System_Error)) { Console.WriteLine("System error:"); Console.WriteLine(odata.System_Error); } else { Console.WriteLine("Errors:"); Console.WriteLine(odata.Errors); Console.WriteLine("Warnings:"); Console.WriteLine(odata.Warnings); Console.WriteLine("Output:"); Console.WriteLine(odata.Output); Console.WriteLine("Exit status:"); Console.WriteLine(odata.Exit_Status); Console.WriteLine("Stats:"); Console.WriteLine(odata.Stats); } }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if(!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)CompileTimeMs/(double)1000), 2); return odata; } if(!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using(Process process = new Process()) { process.StartInfo.FileName = ParentRootPath+"parent.py"; process.StartInfo.Arguments = cdata.Executor+(string.IsNullOrEmpty(cdata.Executor) ? "" : " ")+cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if(!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if(index != -1 && index+1 < error.Output.Length && Int32.TryParse(error.Output.Substring(index+1), out exitcode)) { odata.ExitCode = exitcode; switch(exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); } } odata.Errors = error.Output; odata.Output = output.Output; } watch.Stop(); if(idata.Lang != Languages.Python) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec", Math.Round((double)CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } else { odata.Stats = string.Format("Absolute running time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } return odata; } catch(Exception ex) { return new OutputData() { System_Error = ex.Message }; } finally { if(cdata != null) Cleanup(cdata.CleanThis); } }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if (!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)cdata.CompileTimeMs / (double)1000, 2)); return(odata); } if (!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using (Process process = new Process()) { process.StartInfo.FileName = ParentRootPath + "parent.py"; //process.StartInfo.FileName = "/home/ren/a.out"; process.StartInfo.Arguments = cdata.Executor + (string.IsNullOrEmpty(cdata.Executor) ? "" : " ") + cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.Start(); if (!string.IsNullOrEmpty(idata.Input)) { InputWriter input = new InputWriter(process.StandardInput, idata.Input); Thread inputWriter = new Thread(new ThreadStart(input.Writeinput)); inputWriter.Start(); } OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if (!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if (index != -1 && index + 1 < error.Output.Length) { string[] info = error.Output.Substring(index + 1).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (info.Length > 0 && Int32.TryParse(info[0], out exitcode)) { odata.ExitCode = exitcode; switch (exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); if (info.Length > 1) { double cpuTime; Double.TryParse(info[1], out cpuTime); CpuTimeInSec = cpuTime; } if (info.Length > 2) { int memory; Int32.TryParse(info[2], out memory); MemoryPickInKilobytes = memory; } } } } odata.Errors = error.Output; odata.Output = output.Output; if (idata.Lang == Languages.Octave) { string bad_err = "error: No such file or directory" + Environment.NewLine + "error: ignoring octave_execution_exception while preparing to exit"; if (odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if (string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } List <FileData> files = new List <FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } if (idata.Lang == Languages.R) { string bad_err = "sh: /bin/rm: Permission denied"; if (odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if (string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } if (File.Exists(Path.Combine(cdata.CleanThis, "Rplots.pdf"))) { using (var p = new Process()) { process.StartInfo.FileName = "pdftoppm"; process.StartInfo.WorkingDirectory = cdata.CleanThis; process.StartInfo.Arguments = "-png Rplots.pdf plots"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); process.WaitForExit(); } List <FileData> files = new List <FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } } } watch.Stop(); if (Utils.IsCompiled(idata.Lang)) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, memory peak: {3} Mb", Math.Round((double)cdata.CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes / 1024); } else { odata.Stats = string.Format("Absolute running time: {0} sec, cpu time: {1} sec, memory peak: {2} Mb", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes / 1024); } return(odata); } catch (Exception ex) { return(new OutputData() { System_Error = ex.Message }); } finally { if (cdata != null) { Cleanup(cdata.CleanThis); } } }
static OutputData TestEngineThroughService(string Program, string Input, Languages Lang, string Args) { OutputData odata; bool bytes = true; using(var s = new runPythonWrapper.api.rextester.com.Service()) { Stopwatch watch = new Stopwatch(); watch.Start(); runPythonWrapper.api.rextester.com.Result res = s.DoWork(Program, Input, (runPythonWrapper.api.rextester.com.Languages)Lang, GlobalUtils.TopSecret.ServiceUser, GlobalUtils.TopSecret.ServicePass, Args, bytes, false, false); watch.Stop(); if(res != null) { if(string.IsNullOrEmpty(res.Stats)) res.Stats = ""; else res.Stats += ", "; res.Stats += string.Format("absolute service time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds/(double)1000, 2)); } odata = new OutputData() { Errors = res.Errors, Warnings = res.Warnings, Stats = res.Stats, Output = res.Output, Exit_Status = res.Exit_Status, System_Error = res.System_Error }; if(bytes) { if(res.Errors_Bytes != null) odata.Errors = System.Text.Encoding.Unicode.GetString(res.Errors_Bytes); if(res.Warnings_Bytes != null) odata.Warnings = System.Text.Encoding.Unicode.GetString(res.Warnings_Bytes); if(res.Output_Bytes != null) odata.Output = System.Text.Encoding.Unicode.GetString(res.Output_Bytes); } } return odata; }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if (!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)CompileTimeMs / (double)1000), 2); return(odata); } if (!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using (Process process = new Process()) { process.StartInfo.FileName = ParentRootPath + "parent.py"; process.StartInfo.Arguments = cdata.Executor + (string.IsNullOrEmpty(cdata.Executor) ? "" : " ") + cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.Start(); OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if (!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if (index != -1 && index + 1 < error.Output.Length && Int32.TryParse(error.Output.Substring(index + 1), out exitcode)) { odata.ExitCode = exitcode; switch (exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); } } odata.Errors = error.Output; odata.Output = output.Output; } watch.Stop(); if (idata.Lang != Languages.Python) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec", Math.Round((double)CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } else { odata.Stats = string.Format("Absolute running time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2)); } return(odata); } catch (Exception ex) { return(new OutputData() { System_Error = ex.Message }); } finally { if (cdata != null) { Cleanup(cdata.CleanThis); } } }
static void TestEngineThroughService(string Program, Languages Lang) { OutputData odata; bool bytes = true; using(var s = new n226589_s_dedikuoti_lt.Service()) { Stopwatch watch = new Stopwatch(); watch.Start(); Test.n226589_s_dedikuoti_lt.Result res = s.DoWork(Program, (Test.n226589_s_dedikuoti_lt.Languages)Lang, "test", "test", bytes); watch.Stop(); if(res != null) { if(string.IsNullOrEmpty(res.Stats)) res.Stats = ""; else res.Stats += ", "; res.Stats += string.Format("absolute service time: {0} sec", Math.Round((double)watch.ElapsedMilliseconds/(double)1000, 2)); } odata = new OutputData() { Errors = res.Errors, Warnings = res.Warnings, Stats = res.Stats, Output = res.Output, Exit_Status = res.Exit_Status, System_Error = res.System_Error }; if(bytes) { if(res.Errors_Bytes != null) odata.Errors = System.Text.Encoding.Unicode.GetString(res.Errors_Bytes); if(res.Warnings_Bytes != null) odata.Warnings = System.Text.Encoding.Unicode.GetString(res.Warnings_Bytes); if(res.Output_Bytes != null) odata.Output = System.Text.Encoding.Unicode.GetString(res.Output_Bytes); } } ShowData(odata); }
public OutputData DoWork(InputData idata) { CompilerData cdata = null; try { OutputData odata = new OutputData(); cdata = CreateExecutable(idata); if(!cdata.Success) { odata.Errors = cdata.Error; odata.Warnings = cdata.Warning; odata.Stats = string.Format("Compilation time: {0} sec", Math.Round((double)cdata.CompileTimeMs/(double)1000, 2)); return odata; } if(!string.IsNullOrEmpty(cdata.Warning)) { odata.Warnings = cdata.Warning; } Stopwatch watch = new Stopwatch(); watch.Start(); using(Process process = new Process()) { process.StartInfo.FileName = ParentRootPath+"parent.py"; //process.StartInfo.FileName = "/home/ren/a.out"; process.StartInfo.Arguments = cdata.Executor+(string.IsNullOrEmpty(cdata.Executor) ? "" : " ")+cdata.ExecuteThis; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardInput = true; process.Start(); if (!string.IsNullOrEmpty(idata.Input)) { InputWriter input = new InputWriter(process.StandardInput, idata.Input); Thread inputWriter = new Thread(new ThreadStart(input.Writeinput)); inputWriter.Start(); } OutputReader output = new OutputReader(process.StandardOutput); Thread outputReader = new Thread(new ThreadStart(output.ReadOutput)); outputReader.Start(); OutputReader error = new OutputReader(process.StandardError); Thread errorReader = new Thread(new ThreadStart(error.ReadOutput)); errorReader.Start(); process.WaitForExit(); errorReader.Join(5000); outputReader.Join(5000); if(!string.IsNullOrEmpty(error.Output)) { int index = error.Output.LastIndexOf('\n'); int exitcode; if(index != -1 && index+1 < error.Output.Length) { string[] info = error.Output.Substring(index+1).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if(info.Length > 0 && Int32.TryParse(info[0], out exitcode)) { odata.ExitCode = exitcode; switch(exitcode) { case -8: odata.Exit_Status = "Floating point exception (SIGFPE)"; break; case -9: odata.Exit_Status = "Kill signal (SIGKILL)"; break; case -11: odata.Exit_Status = "Invalid memory reference (SIGSEGV)"; break; case -6: odata.Exit_Status = "Abort signal from abort(3) (SIGABRT)"; break; case -4: odata.Exit_Status = "Illegal instruction (SIGILL)"; break; case -13: odata.Exit_Status = "Broken pipe: write to pipe with no readers (SIGPIPE)"; break; case -14: odata.Exit_Status = "Timer signal from alarm(2) (SIGALRM)"; break; case -15: odata.Exit_Status = "Termination signal (SIGTERM)"; break; case -19: odata.Exit_Status = "Stop process (SIGSTOP)"; break; case -17: odata.Exit_Status = "Child stopped or terminated (SIGCHLD)"; break; default: odata.Exit_Status = string.Format("Exit code: {0} (see 'man 7 signal' for explanation)", exitcode); break; } error.Output = error.Output.Substring(0, index); if(info.Length > 1) { double cpuTime; Double.TryParse(info[1], out cpuTime); CpuTimeInSec = cpuTime; } if(info.Length > 2) { int memory; Int32.TryParse(info[2], out memory); MemoryPickInKilobytes = memory; } } } } odata.Errors = error.Output; odata.Output = output.Output; if(idata.Lang == Languages.Octave) { string bad_err = "error: No such file or directory"+Environment.NewLine+"error: ignoring octave_execution_exception while preparing to exit"; if(odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if(string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } List<FileData> files = new List<FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } if(idata.Lang == Languages.R) { string bad_err = "sh: /bin/rm: Permission denied"; if(odata.Errors != null && odata.Errors.Contains(bad_err)) { odata.Errors = odata.Errors.Replace(bad_err, ""); if(string.IsNullOrEmpty(odata.Errors.Trim())) { odata.Errors = null; } } if(File.Exists(Path.Combine(cdata.CleanThis, "Rplots.pdf"))) { using(var p = new Process()) { process.StartInfo.FileName = "pdftoppm"; process.StartInfo.WorkingDirectory = cdata.CleanThis; process.StartInfo.Arguments = "-png Rplots.pdf plots"; process.StartInfo.UseShellExecute = false; process.StartInfo.CreateNoWindow = true; process.Start(); process.WaitForExit(); } List<FileData> files = new List<FileData>(); foreach (string file_name in Directory.GetFiles(cdata.CleanThis, "*.png")) { var file = new FileData(); file.Data = File.ReadAllBytes(file_name); file.CreationDate = File.GetCreationTime(file_name); files.Add(file); } odata.Files = files.OrderBy(f => f.CreationDate).Select(f => f.Data).ToList(); } } } watch.Stop(); if(Utils.IsCompiled(idata.Lang)) { odata.Stats = string.Format("Compilation time: {0} sec, absolute running time: {1} sec, cpu time: {2} sec, memory peak: {3} Mb", Math.Round((double)cdata.CompileTimeMs / (double)1000, 2), Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes/1024); } else { odata.Stats = string.Format("Absolute running time: {0} sec, cpu time: {1} sec, memory peak: {2} Mb", Math.Round((double)watch.ElapsedMilliseconds / (double)1000, 2), Math.Round(CpuTimeInSec, 2), MemoryPickInKilobytes/1024); } return odata; } catch(Exception ex) { return new OutputData() { System_Error = ex.Message }; } finally { if(cdata != null) Cleanup(cdata.CleanThis); } }