Skip to content

Commit 07e996c

Browse files
committed
Adding exit code ok status as a flag in the test results.
1 parent c60f564 commit 07e996c

3 files changed

Lines changed: 61 additions & 5 deletions

File tree

app/helpers/Evaluation/EvaluationResults/TestResult.php

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,17 +253,51 @@ public function isMemoryOK(): bool
253253
}
254254

255255
/**
256-
* Get the return code
257-
* @return int If all tasks are successful, return 0. If not, return first nonzero code returned.
256+
* Get the exit code. If multiple processes are executed, the exit code is determined by priorities:
257+
* - regular non-success exit codes
258+
* - irregular (timeout, signal) non-success exit codes
259+
* - success exit codes
260+
* EXIT_CODE_UNKNOWN is returned if no process was executed
261+
* @return int exit code
258262
*/
259263
public function getExitCode(): int
260264
{
265+
// first, try to find regular but non-success exit code
261266
foreach ($this->sandboxResultsList as $results) {
262-
if ($results->getExitCode() !== 0) {
267+
if ($results->getStatus() === ISandboxResults::STATUS_RE) {
263268
return $results->getExitCode();
264269
}
265270
}
266-
return 0;
271+
272+
// then, try to find any non-success code
273+
foreach ($this->sandboxResultsList as $results) {
274+
if ($results->getStatus() !== ISandboxResults::STATUS_OK) {
275+
return $results->getExitCode();
276+
}
277+
}
278+
279+
// finally, try to find the first successful exit code
280+
foreach ($this->sandboxResultsList as $results) {
281+
if ($results->getStatus() === ISandboxResults::STATUS_OK) {
282+
return $results->getExitCode();
283+
}
284+
}
285+
286+
return ISandboxResults::EXIT_CODE_UNKNOWN; // default fallback
287+
}
288+
289+
/**
290+
* Check if the exit code indicates successful termination of the process.
291+
* @return bool True if all tasks ended in OK state.
292+
*/
293+
public function isExitCodeOk(): bool
294+
{
295+
foreach ($this->sandboxResultsList as $results) {
296+
if ($results->getStatus() !== ISandboxResults::STATUS_OK) {
297+
return false;
298+
}
299+
}
300+
return true;
267301
}
268302

269303
/**

app/model/entity/TestResult.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct(
2020
$this->status = $result->getStatus();
2121
$this->score = $result->getScore();
2222
$this->exitCode = $result->getExitCode();
23+
$this->exitCodeOk = $result->isExitCodeOk();
2324
$this->exitCodeNative = $result->isExitCodeNative();
2425
$this->exitSignal = $result->getExitSignal();
2526
$this->usedMemory = $result->getUsedMemory();
@@ -115,6 +116,12 @@ public function __construct(
115116
*/
116117
protected $exitCode;
117118

119+
/**
120+
* @ORM\Column(type="boolean")
121+
* Whether the exit code corresponds to configured success exit codes.
122+
*/
123+
protected $exitCodeOk;
124+
118125
/**
119126
* @ORM\Column(type="boolean")
120127
* Whether the exit code was produced by regular termination (not by signal, timeout, or sandbox error).
@@ -193,6 +200,7 @@ public function getDataForView(SubmissionViewOptions $options)
193200
"wallTimeExceeded" => $this->wallTimeExceeded,
194201
"cpuTimeExceeded" => $this->cpuTimeExceeded,
195202
"exitCode" => $this->exitCode,
203+
"exitCodeOk" => $this->exitCodeOk,
196204
"exitCodeNative" => $this->exitCodeNative,
197205
"exitSignal" => $this->exitSignal,
198206
"message" => $this->message,
@@ -274,6 +282,11 @@ public function getExitCode(): int
274282
return $this->exitCode;
275283
}
276284

285+
public function isExitCodeOk(): bool
286+
{
287+
return $this->exitCodeOk;
288+
}
289+
277290
public function isExitCodeNative(): bool
278291
{
279292
return $this->exitCodeNative;

migrations/Version20240716161149.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function up(Schema $schema): void
4242
// this up() migration is auto-generated, please modify it to your needs
4343
$this->addSql('ALTER TABLE assignment ADD can_view_measured_values TINYINT(1) NOT NULL');
4444
$this->addSql('ALTER TABLE test_result ADD exit_code_native TINYINT(1) NOT NULL');
45+
$this->addSql('ALTER TABLE test_result ADD exit_code_ok TINYINT(1) NOT NULL');
4546

4647
$this->addSql('ALTER TABLE assignment_localized_exercise DROP FOREIGN KEY FK_9C8F78CD19302F8');
4748
$this->addSql('ALTER TABLE assignment_localized_exercise ADD CONSTRAINT FK_9DF069D6D19302F8 FOREIGN KEY (assignment_id) REFERENCES assignment (id) ON DELETE CASCADE');
@@ -75,7 +76,14 @@ public function postUp(Schema $schema): void
7576
$this->connection->executeQuery(
7677
"UPDATE test_result SET exit_code_native = 1 WHERE `status` = 'OK' OR
7778
(`status` = 'FAILED' AND memory_exceeded = 0 AND wall_time_exceeded = 0 AND
78-
exit_signal IS NULL AND exit_code >= 0 AND message NOT LIKE '%Caught%')"
79+
(exit_signal IS NULL OR exit_signal = 0) AND exit_code >= 0 AND message NOT LIKE '%Caught%')"
80+
);
81+
82+
/*
83+
* fill newly created exit_code_ok column
84+
*/
85+
$this->connection->executeQuery(
86+
"UPDATE test_result SET exit_code_ok = 1 WHERE exit_code_native = 1 AND exit_code = 0"
7987
);
8088

8189
/*
@@ -184,6 +192,7 @@ public function down(Schema $schema): void
184192
// this down() migration is auto-generated, please modify it to your needs
185193
$this->addSql('ALTER TABLE assignment DROP can_view_measured_values');
186194
$this->addSql('ALTER TABLE test_result DROP exit_code_native');
195+
$this->addSql('ALTER TABLE test_result DROP exit_code_ok');
187196

188197
$this->addSql('ALTER TABLE assignment_localized_exercise DROP FOREIGN KEY FK_9DF069D6D19302F8');
189198
$this->addSql('ALTER TABLE assignment_localized_exercise ADD CONSTRAINT FK_9C8F78CD19302F8 FOREIGN KEY (assignment_id) REFERENCES assignment (id) ON DELETE CASCADE');

0 commit comments

Comments
 (0)