public override ExecutionResult Execute(ExecutionContext executionContext) { var result = new ExecutionResult(); // PHP code is not compiled result.IsCompiledSuccessfully = true; var codeSavePath = FileHelpers.SaveStringToTempFile(executionContext.Code); // Process the submission and check each test var executor = new RestrictedProcessExecutor(); var checker = Checker.CreateChecker(executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); result.TestResults = new List<TestResult>(); foreach (var test in executionContext.Tests) { var processExecutionResult = executor.Execute( this.phpCliExecutablePath, test.Input, executionContext.TimeLimit, executionContext.MemoryLimit, new[] { codeSavePath }); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, processExecutionResult.ReceivedOutput); result.TestResults.Add(testResult); } // Clean up File.Delete(codeSavePath); return result; }
private static void StartRestrictedProcess(string applicationPath, string textToWrite, int timeLimit, int memoryLimit) { var restrictedProcessExecutor = new RestrictedProcessExecutor(); Console.WriteLine("-------------------- Starting RestrictedProcess... --------------------"); var result = restrictedProcessExecutor.Execute(applicationPath, textToWrite, timeLimit, memoryLimit); Console.WriteLine("------------ Process output: {0} symbols. First 2048 symbols: ------------ ", result.ReceivedOutput.Length); Console.WriteLine(result.ReceivedOutput.Substring(0, Math.Min(2048, result.ReceivedOutput.Length))); if (!string.IsNullOrWhiteSpace(result.ErrorOutput)) { Console.WriteLine( "------------ Process error: {0} symbols. First 2048 symbols: ------------ ", result.ErrorOutput.Length); Console.WriteLine(result.ErrorOutput.Substring(0, Math.Min(2048, result.ErrorOutput.Length))); } Console.WriteLine("------------ Process info ------------ "); Console.WriteLine(ProcessInfoFormat, "Type:", result.Type); Console.WriteLine(ProcessInfoFormat, "ExitCode:", string.Format("{0} ({1})", result.ExitCode, new Win32Exception(result.ExitCode).Message)); Console.WriteLine(ProcessInfoFormat, "Total time:", result.TimeWorked); Console.WriteLine(ProcessInfoFormat, "PrivilegedProcessorTime:", result.PrivilegedProcessorTime); Console.WriteLine(ProcessInfoFormat, "UserProcessorTime:", result.UserProcessorTime); Console.WriteLine(ProcessInfoFormat, "Memory:", string.Format("{0:0.00}MB", result.MemoryUsed / 1024.0 / 1024.0)); Console.WriteLine(new string('-', 79)); }
public override ExecutionResult Execute(ExecutionContext executionContext) { var result = new ExecutionResult(); // setting the IsCompiledSuccessfully variable to true as in the NodeJS // execution strategy there is no compilation result.IsCompiledSuccessfully = true; // Preprocess the user submission var codeToExecute = this.PreprocessJsSubmission(this.JsCodeTemplate, executionContext.Code); // Save the preprocessed submission which is ready for execution var codeSavePath = this.SaveStringToTempFile(codeToExecute); // Process the submission and check each test IExecutor executor = new RestrictedProcessExecutor(); IChecker checker = Checker.CreateChecker(executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); result.TestResults = new List<TestResult>(); foreach (var test in executionContext.Tests) { var processExecutionResult = executor.Execute(this.nodeJsExecutablePath, test.Input, executionContext.TimeLimit, executionContext.MemoryLimit, new[] { codeSavePath }); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, processExecutionResult.ReceivedOutput); result.TestResults.Add(testResult); } // Clean up File.Delete(codeSavePath); return result; }
public override ExecutionResult Execute(ExecutionContext executionContext) { var result = new ExecutionResult(); // setting the IsCompiledSuccessfully variable to true as in the NodeJS // execution strategy there is no compilation result.IsCompiledSuccessfully = true; // Preprocess the user submission var codeToExecute = this.PreprocessJsSubmission(this.JsCodeTemplate, executionContext.Code); // Save the preprocessed submission which is ready for execution var codeSavePath = FileHelpers.SaveStringToTempFile(codeToExecute); // Process the submission and check each test IExecutor executor = new RestrictedProcessExecutor(); IChecker checker = Checker.CreateChecker(executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); result.TestResults = this.ProcessTests(executionContext, executor, checker, codeSavePath); // Clean up File.Delete(codeSavePath); return result; }
public override ExecutionResult Execute(ExecutionContext executionContext) { var solution = executionContext.FileContent; var result = new ExecutionResult(); var compileResult = this.ExecuteCompiling(executionContext, this.getCompilerPathFunc, result); if (!compileResult.IsCompiledSuccessfully) { return result; } var outputAssemblyPath = this.PreprocessAndCompileTestRunner(executionContext, compileResult.OutputFile); IExecutor executor = new RestrictedProcessExecutor(); var processExecutionResult = executor.Execute(outputAssemblyPath, string.Empty, executionContext.TimeLimit, executionContext.MemoryLimit); var workingDirectory = compileResult.OutputFile; if (Directory.Exists(workingDirectory)) { Directory.Delete(workingDirectory, true); } this.ProcessTests(processExecutionResult, executionContext, result); return result; }
public override ExecutionResult Execute(ExecutionContext executionContext) { IExecutor executor = new RestrictedProcessExecutor(); var result = this.CompileExecuteAndCheck(executionContext, this.getCompilerPathFunc, executor); return result; }