Skip to content

Commit 9d1baf6

Browse files
authored
fix(grader): consider communication TLE as TLE, not ERR (#503)
1 parent d62304f commit 9d1baf6

File tree

4 files changed

+54
-3
lines changed

4 files changed

+54
-3
lines changed

judgels-backends/judgels-grader-engines/src/integTest/java/judgels/gabriel/engines/interactive/InteractiveGradingEngineIntegrationTests.java

+28
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,21 @@
33
import static judgels.gabriel.api.Verdict.ACCEPTED;
44
import static judgels.gabriel.api.Verdict.COMPILATION_ERROR;
55
import static judgels.gabriel.api.Verdict.OK;
6+
import static judgels.gabriel.api.Verdict.TIME_LIMIT_EXCEEDED;
67
import static judgels.gabriel.api.Verdict.WRONG_ANSWER;
78
import static org.assertj.core.api.Assertions.assertThat;
89
import static org.assertj.core.api.Assertions.assertThatThrownBy;
910

1011
import com.google.common.collect.ImmutableList;
1112
import com.google.common.collect.ImmutableSet;
1213
import java.util.List;
14+
import java.util.Optional;
1315
import judgels.gabriel.api.EvaluationException;
1416
import judgels.gabriel.api.GradingException;
1517
import judgels.gabriel.api.GradingResult;
1618
import judgels.gabriel.api.GradingResultDetails;
1719
import judgels.gabriel.api.PreparationException;
20+
import judgels.gabriel.api.SandboxExecutionStatus;
1821
import judgels.gabriel.api.TestCase;
1922
import judgels.gabriel.api.TestGroup;
2023
import judgels.gabriel.engines.BlackboxGradingEngineIntegrationTests;
@@ -114,6 +117,31 @@ void wa_90() throws GradingException {
114117
subtaskResult(-1, OK, 90)));
115118
}
116119

120+
@Test
121+
void tle_when_communication_timed_out() throws GradingException {
122+
addSourceFile("source", "trigger-communication-TLE.cpp");
123+
assertResult(
124+
new InteractiveGradingConfig.Builder().from(CONFIG)
125+
.communicator("communicator-TLE.cpp").build(),
126+
TIME_LIMIT_EXCEEDED,
127+
0,
128+
List.of(
129+
testGroupResult(
130+
0,
131+
testCaseResult(TIME_LIMIT_EXCEEDED, "", Optional.of(SandboxExecutionStatus.TIMED_OUT), 0),
132+
testCaseResult(TIME_LIMIT_EXCEEDED, "", Optional.of(SandboxExecutionStatus.TIMED_OUT), 0),
133+
testCaseResult(TIME_LIMIT_EXCEEDED, "", Optional.of(SandboxExecutionStatus.TIMED_OUT), 0)),
134+
testGroupResult(
135+
-1,
136+
testCaseResult(TIME_LIMIT_EXCEEDED, "0.0", Optional.of(SandboxExecutionStatus.TIMED_OUT), -1),
137+
testCaseResult(TIME_LIMIT_EXCEEDED, "0.0", Optional.of(SandboxExecutionStatus.TIMED_OUT), -1),
138+
testCaseResult(TIME_LIMIT_EXCEEDED, "0.0", Optional.of(SandboxExecutionStatus.TIMED_OUT), -1),
139+
testCaseResult(TIME_LIMIT_EXCEEDED, "0.0", Optional.of(SandboxExecutionStatus.TIMED_OUT), -1),
140+
testCaseResult(TIME_LIMIT_EXCEEDED, "0.0", Optional.of(SandboxExecutionStatus.TIMED_OUT), -1))),
141+
List.of(
142+
subtaskResult(-1, TIME_LIMIT_EXCEEDED, 0)));
143+
}
144+
117145
@Test
118146
void ce() throws GradingException {
119147
addSourceFile("source", "binsearch-CE.cpp");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <cstdio>
2+
#include <cstdlib>
3+
#include <cstring>
4+
5+
int N;
6+
7+
int main(int argc, char* argv[])
8+
{
9+
FILE* in = fopen(argv[1], "r");
10+
fscanf(in, "%d", &N);
11+
12+
return 10;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This solution intentionally TLE to trigger the whole communication to get TLE.
2+
int main() {
3+
return 10;
4+
}

judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/helpers/communicator/Communicator.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package judgels.gabriel.helpers.communicator;
22

3+
import static judgels.gabriel.api.SandboxExecutionStatus.TIMED_OUT;
34
import static judgels.gabriel.api.SandboxExecutionStatus.ZERO_EXIT_CODE;
45

56
import com.google.common.collect.ImmutableList;
@@ -172,8 +173,13 @@ public EvaluationResult communicate(File input) throws EvaluationException {
172173
solutionResult = ignoreSignal13(solutionResult);
173174
communicatorResult = ignoreSignal13(communicatorResult);
174175

175-
// If the communicator did not exit successfully, it means there is something wrong with it.
176-
if (communicatorResult.getStatus() != ZERO_EXIT_CODE) {
176+
SandboxExecutionResult finalResult = solutionResult;
177+
178+
if (communicatorResult.getStatus() == TIMED_OUT) {
179+
// If the interaction timed out, and the communicator sandbox reported TLE, take this result (instead of ERR)
180+
finalResult = communicatorResult;
181+
} else if (communicatorResult.getStatus() != ZERO_EXIT_CODE) {
182+
// Otherwise, if the communicator did not exit successfully, it means there is something wrong with it.
177183
throw new EvaluationException(String.join(" ", command) + " resulted in " + communicatorResult);
178184
}
179185

@@ -186,7 +192,7 @@ public EvaluationResult communicate(File input) throws EvaluationException {
186192

187193
return new EvaluationResult.Builder()
188194
.verdict(verdict.get())
189-
.executionResult(solutionResult)
195+
.executionResult(finalResult)
190196
.build();
191197
}
192198

0 commit comments

Comments
 (0)