Skip to content

Commit

Permalink
Adding success exit codes parameter into exec boxes.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Jul 22, 2024
1 parent 11cd0b6 commit 4a7e444
Show file tree
Hide file tree
Showing 16 changed files with 163 additions and 83 deletions.
3 changes: 2 additions & 1 deletion app/helpers/ExerciseConfig/Pipeline/Box/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public function validateMetadata()
// same, but if types are not the same and default port is undefined
// there can be any type in the output port
throw new ExerciseConfigException(
"Default output port '{$defaultOutPort->getName()}' missing or malformed in box '{$this->getName()}'"
"Default output port '{$defaultOutPort->getName()}' missing or malformed in box '"
. $this->getName() . "'"
);
}
}
Expand Down
23 changes: 11 additions & 12 deletions app/helpers/ExerciseConfig/Pipeline/Box/Boxes/ElfExecutionBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ public static function init()
{
if (!self::$initialized) {
self::$initialized = true;
self::$defaultInputPorts = array(
new Port((new PortMeta())->setName(self::$ARGS_PORT_KEY)->setType(VariableTypes::$STRING_ARRAY_TYPE)),
new Port((new PortMeta())->setName(self::$STDIN_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$INPUT_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$BINARY_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE))
);
self::$defaultOutputPorts = array(
new Port((new PortMeta())->setName(self::$STDOUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$OUTPUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE))
);
self::$defaultInputPorts = Box::constructPorts([
self::$BINARY_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$ARGS_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
self::$STDIN_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$INPUT_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$SUCCESS_EXIT_CODES_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
]);
self::$defaultOutputPorts = Box::constructPorts([
self::$STDOUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$OUTPUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,19 @@ public static function init()
{
if (!self::$initialized) {
self::$initialized = true;
self::$defaultInputPorts = array(
new Port((new PortMeta())->setName(self::$BINARY_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$SOURCE_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$STDIN_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$INPUT_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$ENTRY_POINT_KEY)->setType(VariableTypes::$STRING_TYPE)),
new Port(
(new PortMeta())->setName(self::$EXTRA_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
);
self::$defaultOutputPorts = array(
new Port((new PortMeta())->setName(self::$STDOUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$OUTPUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE))
);
self::$defaultInputPorts = Box::constructPorts([
self::$BINARY_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$SOURCE_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$STDIN_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$INPUT_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$ENTRY_POINT_KEY => VariableTypes::$STRING_TYPE,
self::$EXTRA_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$SUCCESS_EXIT_CODES_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
]);
self::$defaultOutputPorts = Box::constructPorts([
self::$STDOUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$OUTPUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static function init()
self::$JAR_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$RUNNER_EXEC_PORT_KEY => VariableTypes::$STRING_TYPE,
self::$CLASSPATH_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
self::$SUCCESS_EXIT_CODES_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
]);
self::$defaultOutputPorts = Box::constructPorts([
self::$STDOUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,21 @@ public static function init()
{
if (!self::$initialized) {
self::$initialized = true;
self::$defaultInputPorts = array(
new Port(
(new PortMeta())->setName(self::$SOURCE_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$ARGS_PORT_KEY)->setType(VariableTypes::$STRING_ARRAY_TYPE)),
new Port((new PortMeta())->setName(self::$STDIN_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$INPUT_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$ENTRY_POINT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$EXTRA_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$RUNTIME_PATH_PORT_KEY)->setType(VariableTypes::$STRING_TYPE)),
new Port(
(new PortMeta())->setName(self::$RUNTIME_ARGS_PORT_KEY)->setType(VariableTypes::$STRING_ARRAY_TYPE)
),
);
self::$defaultOutputPorts = array(
new Port((new PortMeta())->setName(self::$STDOUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$OUTPUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE))
);
self::$defaultInputPorts = Box::constructPorts([
self::$SOURCE_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$ARGS_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
self::$STDIN_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$INPUT_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$ENTRY_POINT_KEY => VariableTypes::$FILE_TYPE,
self::$EXTRA_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$RUNTIME_PATH_PORT_KEY => VariableTypes::$STRING_TYPE,
self::$RUNTIME_ARGS_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
self::$SUCCESS_EXIT_CODES_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
]);
self::$defaultOutputPorts = Box::constructPorts([
self::$STDOUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$OUTPUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE
]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,19 @@ public static function init()
{
if (!self::$initialized) {
self::$initialized = true;
self::$defaultInputPorts = array(
new Port((new PortMeta())->setName(self::$ARGS_PORT_KEY)->setType(VariableTypes::$STRING_ARRAY_TYPE)),
new Port((new PortMeta())->setName(self::$STDIN_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port(
(new PortMeta())->setName(self::$INPUT_FILES_PORT_KEY)->setType(VariableTypes::$FILE_ARRAY_TYPE)
),
new Port((new PortMeta())->setName(self::$BINARY_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$RUNTIME_PATH_PORT_KEY)->setType(VariableTypes::$STRING_TYPE)),
new Port(
(new PortMeta())->setName(self::$RUNTIME_ARGS_PORT_KEY)->setType(VariableTypes::$STRING_ARRAY_TYPE)
),
);
self::$defaultOutputPorts = array(
new Port((new PortMeta())->setName(self::$STDOUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE)),
new Port((new PortMeta())->setName(self::$OUTPUT_FILE_PORT_KEY)->setType(VariableTypes::$FILE_TYPE))
);
self::$defaultInputPorts = Box::constructPorts([
self::$ARGS_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
self::$STDIN_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$INPUT_FILES_PORT_KEY => VariableTypes::$FILE_ARRAY_TYPE,
self::$BINARY_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$RUNTIME_PATH_PORT_KEY => VariableTypes::$STRING_TYPE,
self::$RUNTIME_ARGS_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
self::$SUCCESS_EXIT_CODES_PORT_KEY => VariableTypes::$STRING_ARRAY_TYPE,
]);
self::$defaultOutputPorts = Box::constructPorts([
self::$STDOUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
self::$OUTPUT_FILE_PORT_KEY => VariableTypes::$FILE_TYPE,
]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ abstract class CompilationBox extends Box
public static $EXTRA_FILES_PORT_KEY = "extra-files";
public static $RUNNER_FILE_PORT_KEY = "runner";
public static $COMPILER_EXEC_PATH_PORT_KEY = "compiler-exec-path";
public static $EXISTS_FAILED_MSG = "Compilation process was completed correctly but no executable file was yielded. Unable to proceed with testing.";
public static $EXISTS_FAILED_MSG =
"Compilation process completed correctly but no executable file was yielded. Unable to proceed with testing.";


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
abstract class DataInBox extends Box
{

/**
* If data for this box is remote, fill this with the right variable reference.
* @var ?Variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ abstract class ExecutionBox extends Box
public static $ENTRY_POINT_KEY = "entry-point";
public static $EXTRA_FILES_PORT_KEY = "extra-files";
public static $BINARY_FILE_PORT_KEY = "binary-file";
public static $SUCCESS_EXIT_CODES_PORT_KEY = "success-exit-codes";


/**
Expand Down Expand Up @@ -86,6 +87,18 @@ protected function compileBaseTask(CompilationParams $params): Task

$task->setSandboxConfig($sandbox);

if ($this->hasInputPortValue(self::$SUCCESS_EXIT_CODES_PORT_KEY)) {
$codes = $this->getInputPortValue(self::$SUCCESS_EXIT_CODES_PORT_KEY)->getValue();
foreach ($codes as &$code) {
$code = trim($code);
if (preg_match('/^(?<from>[0-9]+)\s*-+\s*(?<to>[0-9]+)$/', $code, $matches)) {
// convert string range representation ('from-to') into tuple of ints [from, to]
$code = [ (int)$matches['from'], (int)$matches['to'] ];
}
}
$task->setSuccessExitCodes($codes);
}

return $task;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
abstract class FetchBox extends Box
{

/**
* DataInBox constructor.
* @param BoxMeta $meta
Expand Down
26 changes: 20 additions & 6 deletions app/helpers/JobConfig/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,26 @@ public function loadBoundDirectoryConfig($data, $taskId = ""): BoundDirectoryCon

if (!isset($data[BoundDirectoryConfig::SRC_KEY])) {
throw new JobConfigLoadingException(
"Task '" . $taskId . "': bound directory does not contain required field '" . BoundDirectoryConfig::SRC_KEY . "'"
"Task '" . $taskId . "': bound directory does not contain required field '"
. BoundDirectoryConfig::SRC_KEY . "'"
);
}
$boundDir->setSource($data[BoundDirectoryConfig::SRC_KEY]);
unset($data[BoundDirectoryConfig::SRC_KEY]);

if (!isset($data[BoundDirectoryConfig::DST_KEY])) {
throw new JobConfigLoadingException(
"Task '" . $taskId . "': bound directory does not contain required field '" . BoundDirectoryConfig::DST_KEY . "'"
"Task '" . $taskId . "': bound directory does not contain required field '"
. BoundDirectoryConfig::DST_KEY . "'"
);
}
$boundDir->setDestination($data[BoundDirectoryConfig::DST_KEY]);
unset($data[BoundDirectoryConfig::DST_KEY]);

if (!isset($data[BoundDirectoryConfig::MODE_KEY])) {
throw new JobConfigLoadingException(
"Task '" . $taskId . "': bound directory does not contain required field '" . BoundDirectoryConfig::MODE_KEY . "'"
"Task '" . $taskId . "': bound directory does not contain required field '"
. BoundDirectoryConfig::MODE_KEY . "'"
);
}
$boundDir->setMode($data[BoundDirectoryConfig::MODE_KEY]);
Expand Down Expand Up @@ -115,7 +118,8 @@ public function loadLimits($data, $taskId = ""): Limits

if (!isset($data[Limits::HW_GROUP_ID_KEY])) {
throw new JobConfigLoadingException(
"Task '" . $taskId . "': sandbox limits section does not contain required field '" . Limits::HW_GROUP_ID_KEY . "'"
"Task '" . $taskId . "': sandbox limits section does not contain required field '"
. Limits::HW_GROUP_ID_KEY . "'"
);
}
$limits->setId($data[Limits::HW_GROUP_ID_KEY]);
Expand Down Expand Up @@ -194,7 +198,8 @@ public function loadSandboxConfig($data, $taskId = ""): SandboxConfig

if (!isset($data[SandboxConfig::NAME_KEY])) {
throw new JobConfigLoadingException(
"Task '" . $taskId . "': sandbox section does not contain required field '" . SandboxConfig::NAME_KEY . "'"
"Task '" . $taskId . "': sandbox section does not contain required field '"
. SandboxConfig::NAME_KEY . "'"
);
}
$sandboxConfig->setName($data[SandboxConfig::NAME_KEY]);
Expand Down Expand Up @@ -292,7 +297,8 @@ public function loadTask($data): Task

if (!isset($data[Task::CMD_KEY][Task::CMD_BIN_KEY])) {
throw new JobConfigLoadingException(
"Task '" . $taskId . "' does not contain required field '" . Task::CMD_KEY . "." . Task::CMD_BIN_KEY . "'"
"Task '" . $taskId . "' does not contain required field '"
. Task::CMD_KEY . "." . Task::CMD_BIN_KEY . "'"
);
}
$task->setCommandBinary($data[Task::CMD_KEY][Task::CMD_BIN_KEY]);
Expand Down Expand Up @@ -324,6 +330,14 @@ public function loadTask($data): Task
unset($data[Task::CMD_KEY][Task::CMD_ARGS_KEY]);
}

if (
isset($data[Task::CMD_KEY][Task::CMD_SUCCESS_EXIT_CODES_KEY])
&& is_array($data[Task::CMD_KEY][Task::CMD_SUCCESS_EXIT_CODES_KEY])
) {
$task->setSuccessExitCodes($data[Task::CMD_KEY][Task::CMD_SUCCESS_EXIT_CODES_KEY]);
unset($data[Task::CMD_KEY][Task::CMD_SUCCESS_EXIT_CODES_KEY]);
}

if (isset($data[Task::TYPE_KEY])) {
$task->setType($data[Task::TYPE_KEY]);
unset($data[Task::TYPE_KEY]);
Expand Down
Loading

0 comments on commit 4a7e444

Please sign in to comment.