Skip to content

Commit

Permalink
Merge pull request #421 from mp-access/feature/show-exec-commands-#402
Browse files Browse the repository at this point in the history
Add used console- testcommand attr to exec result #402.
  • Loading branch information
mech-studi authored Dec 11, 2019
2 parents fe2d3a1 + b7b9d8c commit 05405c9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private ExecResult executeSmokeTest(Path workPath, CodeSubmission submission, Ex
.collect(Collectors.toList());

final String fullCommand = String.join(" ; ", commands);
return mapSmokeToExecResult(runner.attachVolumeAndRunBash(workPath.toString(), fullCommand, executionLimits));
return mapSmokeToExecResult(runner.attachVolumeAndRunBash(workPath.toString(), fullCommand, executionLimits), executeScriptCommand, testCommand);
}

private ExecResult executeSubmission(Path workPath, CodeSubmission submission, Exercise exercise, CodeExecutionLimits executionLimits) throws IOException, DockerException, InterruptedException {
Expand All @@ -104,16 +104,34 @@ private ExecResult executeSubmission(Path workPath, CodeSubmission submission, E

protected ExecResult mapSubmissionToExecResult(RunResult runResult) {
if (!runResult.isTimeout() && !runResult.isOomKilled()) {
return new ExecResult("", "", extractEvalLog(runResult));
return ExecResult.builder()
.stdout("").testLog("")
.evalLog(extractEvalLog(runResult))
.build();
}
return new ExecResult(runResult.getConsole(), "", "");

return ExecResult.builder()
.stdout(runResult.getConsole())
.testLog("").evalLog("")
.build();
}

protected ExecResult mapSmokeToExecResult(RunResult runResult) {
protected ExecResult mapSmokeToExecResult(RunResult runResult, String exeCommand, String testCommand) {
if (!runResult.isTimeout() && !runResult.isOomKilled()) {
return new ExecResult(extractConsole(runResult), extractTestOutput(runResult), "");
return ExecResult.builder()
.stdout(extractConsole(runResult))
.testLog(extractTestOutput(runResult))
.evalLog("")
.usedConsoleCommand(exeCommand).usedTestCommand(testCommand)
.build();
}
return new ExecResult(runResult.getConsole(), runResult.getStdErr(), "");

return ExecResult.builder()
.stdout(runResult.getConsole())
.testLog(runResult.getStdErr())
.evalLog("")
.usedConsoleCommand(exeCommand).usedTestCommand(testCommand)
.build();
}

private String extractConsole(RunResult res) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/ch/uzh/ifi/access/student/model/ExecResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -13,6 +15,9 @@ public class ExecResult {
private String stdout;
private String testLog;

private String usedConsoleCommand;
private String usedTestCommand;

@JsonIgnore
private String evalLog;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void execute() throws Exception {
studentSubmission.setId(submissionId);
studentSubmission = repository.save(studentSubmission);

ExecResult result = new ExecResult("Hello, stdout", "Hello, stderr", "Hello, private test log");
ExecResult result = new ExecResult("Hello, stdout", "Hello, stderr", "Hello, private test log", null, null);
when(codeRunner.execSubmissionForExercise(any(CodeSubmission.class), any(Exercise.class))).thenReturn(result);
when(courseService.getExerciseById(anyString())).thenReturn(Optional.of(TestObjectFactory.createCodeExercise("")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void limitConsole() {
}
RunResult rr = new RunResult(sb.toString(), null, null, 1000, false, false);

ExecResult execResult = new SubmissionCodeRunner(null, new FSHierarchySerializer()).mapSmokeToExecResult(rr);
ExecResult execResult = new SubmissionCodeRunner(null, new FSHierarchySerializer()).mapSmokeToExecResult(rr, null, null);

Assertions.assertThat(execResult.getStdout().length()).isLessThan(100055);
Assertions.assertThat(execResult.getStdout()).contains("Logs size exceeded limit. Log has been truncated.");
Expand Down

0 comments on commit 05405c9

Please sign in to comment.