Skip to content

Commit

Permalink
fix(gabriel): run DiffScorer in different working directory per thread (
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar authored Jul 2, 2023
1 parent 9d08fe7 commit f219d16
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public abstract class BlackboxGradingEngine implements GradingEngine {
private File gradingDir;
private File compilationDir;
private File evaluationDir;
private File scoringDir;

private GradingConfig config;
private GradingLanguage language;
Expand Down Expand Up @@ -141,8 +140,6 @@ private void createGradingDirs() throws PreparationException {
FileUtils.forceMkdir(compilationDir);
evaluationDir = new File(gradingDir, "evaluation");
FileUtils.forceMkdir(evaluationDir);
scoringDir = new File(gradingDir, "scoring");
FileUtils.forceMkdir(scoringDir);
} catch (IOException e) {
throw new PreparationException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@
import judgels.gabriel.api.Verdict;

public class DiffScorer implements Scorer {
private final File evaluationDir;

public DiffScorer(File evaluationDir) {
this.evaluationDir = evaluationDir;
}

@Override
public ScoringResult score(File input, File output, File evaluationOutput) throws ScoringException {
String[] scoringCommand = new String[]{"/bin/bash", "-c", String.format(""
+ "cat \"%s\" | tr '[\\t\\r\\n]' ' ' | xargs > _output_tokenized.out; "
+ "cat \"%s\" | tr '[\\t\\r\\n]' ' ' | xargs > _evaluation_tokenized.out; "
+ "diff --brief _output_tokenized.out _evaluation_tokenized.out; result=$?; "
+ "rm _output_tokenized.out _evaluation_tokenized.out; "
+ "exit $result;",
+ "exit $result",
output.getAbsolutePath(),
evaluationOutput.getAbsolutePath())};

ProcessBuilder pb = new ProcessBuilder(scoringCommand);
pb.directory(evaluationDir);

int exitCode;
try {
exitCode = pb.start().waitFor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private ScorerRegistry() {}
public static Scorer getAndPrepare(
Optional<String> customScorer,
Map<String, File> helperFiles,
@Nullable Sandbox sandbox,
@Nullable Sandbox sandbox,
File evaluationDir) throws PreparationException {

if (customScorer.isPresent()) {
Expand All @@ -27,7 +27,7 @@ public static Scorer getAndPrepare(
scorer.prepare(sandbox, evaluationDir, language, scorerFile);
return scorer;
} else {
return new DiffScorer();
return new DiffScorer(evaluationDir);
}
}
}

0 comments on commit f219d16

Please sign in to comment.