public void InitializeMigration(string compilerPath) { var executor = new StandardProcessExecutor(0, 0); var migrationsContractPath = Path.Combine(this.contractsDirectoryPath, MigrationsFileName); var arguments = new[] { "--optimize", "--abi", "--bin", migrationsContractPath }; var result = executor.Execute( compilerPath, string.Empty, DefaultTimeLimitInMilliseconds, DefaultMemoryLimitInBytes, arguments); if (!string.IsNullOrEmpty(result.ErrorOutput)) { throw new Exception($"Compiling {MigrationsFileName} threw an exception: {result.ErrorOutput}"); } var parts = result.ReceivedOutput.Split( new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length < 5) { return; } var byteCode = parts[2]; var abi = parts[4]; if (File.Exists(migrationsContractPath)) { File.Delete(migrationsContractPath); } this.CreateJsonBuildForContracts(new Dictionary <string, (string byteCode, string abi)> { { MigrationsContractName, (byteCode, abi) } }); }
public override ExecutionResult Execute(ExecutionContext executionContext) { var result = new ExecutionResult(); // Create a temp file with the submission code string submissionFilePath; try { submissionFilePath = this.CreateSubmissionFile(executionContext); } catch (ArgumentException exception) { result.IsCompiledSuccessfully = false; result.CompilerComment = exception.Message; return(result); } FileHelpers.UnzipFile(submissionFilePath, this.WorkingDirectory); string pomXmlPath = FileHelpers.FindFileMatchingPattern(this.WorkingDirectory, PomXmlFileNameAndExtension); string[] mavenArgs = new[] { $"-f {pomXmlPath} clean package -DskipTests" }; var mavenExecutor = new StandardProcessExecutor(); var packageExecutionResult = mavenExecutor.Execute( this.MavenPath, string.Empty, executionContext.TimeLimit, executionContext.MemoryLimit, mavenArgs, this.WorkingDirectory); File.AppendAllText("D:\\OjsFiles\\Logs\\MavenBuildOutput.txt", packageExecutionResult.ReceivedOutput + "\n"); Regex mavenBuildOutput = new Regex(MavenBuildOutputPattern); Regex mavenBuildErrors = new Regex(MavenBuildErrorPattern); Match compilationMatch = mavenBuildOutput.Match(packageExecutionResult.ReceivedOutput); Match errorMatch = mavenBuildErrors.Match(packageExecutionResult.ReceivedOutput); result.IsCompiledSuccessfully = compilationMatch.Groups[1].Value == "SUCCESS"; result.CompilerComment = $"{errorMatch.Groups[0]}"; if (!result.IsCompiledSuccessfully) { return(result); } var restrictedExe = new RestrictedProcessExecutor(); var arguments = new List <string>(); arguments.Add(this.ClassPath); arguments.Add(AdditionalExecutionArguments); arguments.Add(JUnitRunnerConsolePath); Regex testErrorMatcher = new Regex(JUnitFailedTestPattern); var checker = Checker.CreateChecker( executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); var testIndex = 0; foreach (var test in executionContext.Tests) { var testFile = this.TestNames[testIndex++]; arguments.Add(testFile); var processExecutionResult = restrictedExe.Execute( this.JavaExecutablePath, string.Empty, executionContext.TimeLimit, executionContext.MemoryLimit, arguments, this.WorkingDirectory); if (processExecutionResult.ReceivedOutput.Contains(JvmInsufficientMemoryMessage)) { throw new InsufficientMemoryException(JvmInsufficientMemoryMessage); } if (processExecutionResult.ReceivedOutput.Contains($"Could not find class: {testFile}")) { throw new FileLoadException("Tests could not be loaded, project structure is incorrect"); } string message = this.EvaluateJUnitOutput(processExecutionResult.ReceivedOutput, testErrorMatcher); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, message); result.TestResults.Add(testResult); arguments.Remove(testFile); } return(result); }
protected override IExecutionResult <TestResult> ExecuteAgainstTestsInput( IExecutionContext <TestsInputModel> executionContext) { var result = new ExecutionResult <TestResult>(); this.ExtractTestNames(executionContext.Input.Tests); // Compile the file var compileResult = this.ExecuteCompiling( executionContext, this.GetCompilerPathFunc, result); if (!compileResult.IsCompiledSuccessfully) { return(result); } var compiledContracts = GetCompiledContracts(Path.GetDirectoryName(compileResult.OutputFile)); var truffleProject = new TruffleProjectManager(this.WorkingDirectory, this.portNumber); truffleProject.InitializeMigration(this.GetCompilerPathFunc(executionContext.CompilerType)); truffleProject.CreateJsonBuildForContracts(compiledContracts); truffleProject.ImportJsUnitTests(executionContext.Input.Tests); var executor = new StandardProcessExecutor(this.BaseTimeUsed, this.BaseMemoryUsed); var checker = executionContext.Input.GetChecker(); ProcessExecutionResult processExecutionResult; // Run tests in the Ethereum Virtual Machine scope using (var ganache = new GanacheCli(this.nodeJsExecutablePath, this.ganacheCliNodeExecutablePath)) { ganache.Listen(this.portNumber); processExecutionResult = executor.Execute( this.nodeJsExecutablePath, string.Empty, executionContext.TimeLimit, executionContext.MemoryLimit, new[] { $"{this.truffleCliNodeExecutablePath} test" }, this.WorkingDirectory); } if (!string.IsNullOrWhiteSpace(processExecutionResult.ErrorOutput)) { throw new ArgumentException(processExecutionResult.ErrorOutput); } processExecutionResult.RemoveColorEncodingsFromReceivedOutput(); var(totalTestsCount, failingTestsCount) = ExtractFailingTestsCount(processExecutionResult.ReceivedOutput); if (totalTestsCount != executionContext.Input.Tests.Count()) { throw new ArgumentException( "Some of the tests contain more than one test per test case. Please contact an administrator"); } var errorsByTestNames = this.GetErrorsByTestNames(processExecutionResult.ReceivedOutput); if (errorsByTestNames.Count != failingTestsCount) { throw new ArgumentException("Failing tests not captured properly. Please contact an administrator"); } var testsCounter = 0; foreach (var test in executionContext.Input.Tests) { var message = "Test Passed!"; var testName = this.TestNames[testsCounter++]; if (errorsByTestNames.ContainsKey(testName)) { message = errorsByTestNames[testName]; } var testResult = this.ExecuteAndCheckTest( test, processExecutionResult, checker, message); result.Results.Add(testResult); } return(result); }
public override ExecutionResult Execute(ExecutionContext executionContext) { var result = new ExecutionResult(); // Create a temp file with the submission code string submissionFilePath; try { submissionFilePath = this.CreateSubmissionFile(executionContext.Code); } catch (ArgumentException exception) { result.IsCompiledSuccessfully = false; result.CompilerComment = exception.Message; return(result); } // Create a sandbox executor source file in the working directory var sandboxExecutorSourceFilePath = $"{this.workingDirectory}\\{SandboxExecutorClassName}"; File.WriteAllText(sandboxExecutorSourceFilePath, this.SandboxExecutorCode); // Compile all source files - sandbox executor and submission file var compilerPath = this.getCompilerPathFunc(executionContext.CompilerType); var compilerResult = this.CompileSourceFiles( executionContext.CompilerType, compilerPath, executionContext.AdditionalCompilerArguments, new[] { submissionFilePath, sandboxExecutorSourceFilePath }); // Assign compiled result info to the execution result result.IsCompiledSuccessfully = compilerResult.IsCompiledSuccessfully; result.CompilerComment = compilerResult.CompilerComment; if (!result.IsCompiledSuccessfully) { return(result); } // Prepare execution process arguments and time measurement info var classPathArgument = $"-classpath \"{this.workingDirectory}\""; var submissionFilePathLastIndexOfSlash = submissionFilePath.LastIndexOf('\\'); var classToExecute = submissionFilePath.Substring(submissionFilePathLastIndexOfSlash + 1); var timeMeasurementFilePath = $"{this.workingDirectory}\\{TimeMeasurementFileName}"; // Create an executor and a checker var executor = new StandardProcessExecutor(); var checker = Checker.CreateChecker(executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); // Process the submission and check each test foreach (var test in executionContext.Tests) { var processExecutionResult = executor.Execute( this.javaExecutablePath, test.Input, executionContext.TimeLimit, executionContext.MemoryLimit, new[] { classPathArgument, SandboxExecutorClassName, classToExecute, $"\"{timeMeasurementFilePath}\"" }); UpdateExecutionTime(timeMeasurementFilePath, processExecutionResult, executionContext.TimeLimit); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, processExecutionResult.ReceivedOutput); result.TestResults.Add(testResult); } return(result); }
public override ExecutionResult Execute(ExecutionContext executionContext) { var result = new ExecutionResult(); // Copy the sandbox executor source code to a file in the working directory File.WriteAllText(this.SandboxExecutorSourceFilePath, this.SandboxExecutorCode); // Create a temp file with the submission code string submissionFilePath; try { submissionFilePath = this.CreateSubmissionFile(executionContext); } catch (ArgumentException exception) { result.IsCompiledSuccessfully = false; result.CompilerComment = exception.Message; return(result); } var compilerResult = this.DoCompile(executionContext, submissionFilePath); // Assign compiled result info to the execution result result.IsCompiledSuccessfully = compilerResult.IsCompiledSuccessfully; result.CompilerComment = compilerResult.CompilerComment; if (!result.IsCompiledSuccessfully) { return(result); } // Prepare execution process arguments and time measurement info var classPathArgument = $"-classpath \"{this.WorkingDirectory}\""; var classToExecuteFilePath = compilerResult.OutputFile; var classToExecute = classToExecuteFilePath .Substring( this.WorkingDirectory.Length + 1, classToExecuteFilePath.Length - this.WorkingDirectory.Length - JavaCompiledFileExtension.Length - 1) .Replace('\\', '.'); var timeMeasurementFilePath = $"{this.WorkingDirectory}\\{TimeMeasurementFileName}"; // Create an executor and a checker var executor = new StandardProcessExecutor(); var checker = Checker.CreateChecker(executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); // Process the submission and check each test foreach (var test in executionContext.Tests) { var processExecutionResult = executor.Execute( this.javaExecutablePath, test.Input, executionContext.TimeLimit * 2, // Java virtual machine takes more time to start up executionContext.MemoryLimit, new[] { classPathArgument, SandboxExecutorClassName, classToExecute, $"\"{timeMeasurementFilePath}\"" }); UpdateExecutionTime(timeMeasurementFilePath, processExecutionResult, executionContext.TimeLimit); var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, processExecutionResult.ReceivedOutput); result.TestResults.Add(testResult); } return(result); }
public override ExecutionResult Execute(ExecutionContext executionContext) { var result = new ExecutionResult(); // Create a temp file with the submission code string submissionFilePath; try { submissionFilePath = this.CreateSubmissionFile(executionContext); } catch (ArgumentException exception) { result.IsCompiledSuccessfully = false; result.CompilerComment = exception.Message; return(result); } var compilerPath = this.GetCompilerPathFunc(executionContext.CompilerType); var combinedArguments = executionContext.AdditionalCompilerArguments + this.ClassPath; var executor = new RestrictedProcessExecutor(); var checker = Checker.CreateChecker( executionContext.CheckerAssemblyName, executionContext.CheckerTypeName, executionContext.CheckerParameter); if (!string.IsNullOrWhiteSpace(executionContext.TaskSkeletonAsString)) { FileHelpers.UnzipFile(submissionFilePath, this.WorkingDirectory); string className = JavaCodePreprocessorHelper.GetPublicClassName(executionContext.TaskSkeletonAsString); string filePath = $"{this.WorkingDirectory}\\{className}{GlobalConstants.JavaSourceFileExtension}"; File.WriteAllText(filePath, executionContext.TaskSkeletonAsString); FileHelpers.AddFilesToZipArchive(submissionFilePath, string.Empty, filePath); var preprocessCompileResult = this.Compile( executionContext.CompilerType, compilerPath, combinedArguments, submissionFilePath); result.IsCompiledSuccessfully = preprocessCompileResult.IsCompiledSuccessfully; result.CompilerComment = preprocessCompileResult.CompilerComment; if (!result.IsCompiledSuccessfully) { return(result); } var preprocessExecutor = new StandardProcessExecutor(); var preprocessArguments = new List <string>(); preprocessArguments.Add(this.ClassPath); preprocessArguments.Add(AdditionalExecutionArguments); preprocessArguments.Add(className); preprocessArguments.Add(this.WorkingDirectory); preprocessArguments.AddRange(this.UserClassNames); var preprocessExecutionResult = preprocessExecutor.Execute( this.JavaExecutablePath, string.Empty, executionContext.TimeLimit, executionContext.MemoryLimit, preprocessArguments, this.WorkingDirectory); if (preprocessExecutionResult.ReceivedOutput.Contains(JvmInsufficientMemoryMessage)) { throw new InsufficientMemoryException(JvmInsufficientMemoryMessage); } var filesToAdd = preprocessExecutionResult .ReceivedOutput .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); foreach (var file in filesToAdd) { var path = Path.GetDirectoryName(file); FileHelpers.AddFilesToZipArchive(submissionFilePath, path, this.WorkingDirectory + "\\" + file); } File.Delete(filePath); } var compilerResult = this.Compile( executionContext.CompilerType, compilerPath, combinedArguments, submissionFilePath); result.IsCompiledSuccessfully = compilerResult.IsCompiledSuccessfully; result.CompilerComment = compilerResult.CompilerComment; if (!result.IsCompiledSuccessfully) { return(result); } var arguments = new List <string>(); arguments.Add(this.ClassPath); arguments.Add(AdditionalExecutionArguments); arguments.Add(JUnitRunnerClassName); arguments.AddRange(this.UserClassNames); var processExecutionResult = executor.Execute( this.JavaExecutablePath, string.Empty, executionContext.TimeLimit, executionContext.MemoryLimit, arguments, this.WorkingDirectory, true); if (processExecutionResult.ReceivedOutput.Contains(JvmInsufficientMemoryMessage)) { throw new InsufficientMemoryException(JvmInsufficientMemoryMessage); } var errorsByFiles = this.GetTestErrors(processExecutionResult.ReceivedOutput); var testIndex = 0; foreach (var test in executionContext.Tests) { var message = "Test Passed!"; var testFile = this.TestNames[testIndex++]; if (errorsByFiles.ContainsKey(testFile)) { message = errorsByFiles[testFile]; } var testResult = this.ExecuteAndCheckTest(test, processExecutionResult, checker, message); result.TestResults.Add(testResult); } return(result); }