StdioTest

class StdioTest(val distro: LangDockerfile, val config: StdioTest.Config, val id: Int, val file: String, val input: StdioTest.InputSrc?, val expected: StdioTest.InputSrc, val visibility: TestCase.Visibility, val hidden: Set<TestCase.HiddenItem>, val args: List<String>?, val score: Double?) : DockerPipelineStage, Reportable

Pipeline stage for grading based on standard input and output.

Effectively executes a file with provided STDIN, and pipes all STDOUT output to a file.

Parameters

distro

Distro image to run the test on.

config

The configuration to instantiate this class.

id

The ID of the test case.

file

File to execute.

input

File contents to pipe as String into STDIN.

expected

Expected STDOUT result for comparison

visibility

The visibility of this test case.

args

Arguments to pass into the executable.

score

The score of this test case. If null, implies that scoring is disabled for this stage.

Constructors

Link copied to clipboard
constructor(distro: LangDockerfile, config: StdioTest.Config, testCase: TestCase)

Secondary constructor for convenience.

constructor(distro: LangDockerfile, config: StdioTest.Config, id: Int, file: String, input: StdioTest.InputSrc?, expected: StdioTest.InputSrc, visibility: TestCase.Visibility, hidden: Set<TestCase.HiddenItem>, args: List<String>?, score: Double?)

Types

Link copied to clipboard
data class Config(val testCases: List<TestCase>, val _denyStderr: Boolean?, val diff_ignore_flags: List<Settings.DiffIgnoreFlag>?, val additional_packages: List<String>?, val additional_pip_packages: List<String>?) : ConfigUnit
Link copied to clipboard
sealed class InputSrc
Link copied to clipboard
data class Report(val file: String, val id: Int, val args: String, val stdin: List<String>?, val stdout: List<String>?, val stderr: List<String>?, val stderrEmpty: Boolean, val denyStderr: Boolean, val exitCode: Int, val expect: List<String>, val visibility: TestCase.Visibility, val diff: List<String>?, val diffStderr: List<String>?, val hasTimedOut: Boolean, val scoreGenerator: ScoreGenerator, val exeExitCode: Int, val diffExitCode: Int) : DockerPipelineStage.ExecutableReport, StageReportUnit.Scorable

Properties

Link copied to clipboard
protected lateinit var _runner: Runner
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
protected open val allowNetwork: Boolean

Whether the container is allowed network access.

Link copied to clipboard
private val args: List<String>?
Link copied to clipboard
open val className: String
Link copied to clipboard
open val cmdLang: CmdLang

Command language used for constructing the command specification.

Link copied to clipboard

Handler describing how the stage performs necessary IO actions to retrieve stage execution outputs.

Link copied to clipboard
protected open override val cmdSpec: CmdBuilder

Command to execute during the pipeline stage.

Link copied to clipboard
open override val config: StdioTest.Config
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private val diff: CmdUtils.Var
Link copied to clipboard
Link copied to clipboard
protected val distro: BaseDockerfile

Base distro image for this pipeline stage.

Link copied to clipboard
protected lateinit var docker: DockerDaemon

Instance to the Docker daemon.

Link copied to clipboard
protected open override val dockerfileSpec: DockerfileBuilder.() -> Unit

Additional specifications to add to the Dockerfile.

Link copied to clipboard
protected open val environmentVars: List<String>

Environment variables to provide to the runtime environment.

Link copied to clipboard

Convenience property for retrieving exitcode of a variable.

Link copied to clipboard
private val expect: CmdUtils.Var
Link copied to clipboard
Link copied to clipboard
private val file: String
Link copied to clipboard
protected open override val hasDynamicDockerfileSpec: Boolean = true

Whether the dockerfileSpec contains directives which are evaluated at pipeline execution time.

Link copied to clipboard
protected var hasTimedOut: Boolean
Link copied to clipboard
Link copied to clipboard
protected var hostPath: Path?

Path to mount to the host system as part of the pipeline, if this stage accepts/emits a HostVolume.

Link copied to clipboard
private val id: Int
Link copied to clipboard
protected val imageTag: String?

Image tag to use for caching pipeline stage images.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
private val isCacheImage: Boolean = true

Whether to cache this image in the local Docker registry.

Link copied to clipboard
protected val logger: Logger
Link copied to clipboard
Link copied to clipboard
protected open val mntMountMode: AccessMode

Mode to mount the mountPath as.

Link copied to clipboard
protected val mountPath: Path? = null

Path to mount to the host system for supplementary use, if any.

Link copied to clipboard

The logger output are stored in logs of outputLogger after stage execution

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val reportUnit: StdioTest.Report
Link copied to clipboard

The system resources which control what the container is allowed to access.

Link copied to clipboard
private val result: CmdUtils.Var
Link copied to clipboard
open override val runner: DockerRunner
Link copied to clipboard
private val score: Double?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Convenience property for retrieving stderr content of a variable line-by-line.

Link copied to clipboard
private val stdin: CmdUtils.Var
Link copied to clipboard

Convenience property for retrieving stdout content of a variable line-by-line.

Link copied to clipboard
Link copied to clipboard
protected open val volMountMode: AccessMode

Mode to mount the in-place volume as.

Link copied to clipboard
protected open override val workingDir: String

Working directory of the container.

Functions

Link copied to clipboard
fun buildCmd(configure: CmdBuilder.() -> Unit): CmdBuilder

Builder method for CmdBuilder using the command language cmdLang of the stage.

Link copied to clipboard

Builder method for CmdBuilder using the command language cmdLang of the stage.

Link copied to clipboard

Configures the container during execution of the pipeline.

Link copied to clipboard
protected fun <R> CmdUtils.Var.Result<R>.contentOrDefault(default: R): R

Returns the content of this result (stdout, stderr, or exitCode); Otherwise returns a default value generated by default.

Link copied to clipboard
protected suspend override fun execute(input: StageResult): StageResult
Link copied to clipboard
Link copied to clipboard
private suspend fun getDockerfile(): Path

Base Dockerfile for all pipeline stage.

Link copied to clipboard
protected suspend fun getDockerImage(force: Boolean = false): DockerImage

Builds a Docker image based on the Dockerfile specification as defined by this stage, overwriting any previously cached image if exists.

Link copied to clipboard
private suspend fun getHostConfig(inVolume: DockerVolume?): Pair<HostConfig, DockerVolume?>

Determines the host configuration of the container.

Link copied to clipboard
fun installPackages(additionalPackages: List<String> = emptyList(), vararg packages: String): DockerfileBuilder.() -> Unit

Dockerfile spec for installing packages

Link copied to clipboard
protected suspend fun logContainerInfo(image: DockerImage, hostConfig: HostConfig)

Logs the information used to create the container for this pipeline stage.

Link copied to clipboard
protected fun markStageAsTimedOut()
Link copied to clipboard
protected open suspend override fun onExecComplete()
Link copied to clipboard
protected fun onExecFailed(tr: Throwable)
Link copied to clipboard
protected open override fun onExecFailedImpl(tr: Throwable)
Link copied to clipboard
protected open fun onInitParserContext(configContext: ConfigParsable.Context)
Link copied to clipboard
protected suspend fun postExecCleanup(startTime: Instant, success: Boolean)

Performs cleanup after the execution of the container.

Link copied to clipboard
Link copied to clipboard
fun putRunner(runner: Runner)
Link copied to clipboard
private fun redactMsg(): List<String>?
Link copied to clipboard
private suspend fun removeContainer()

Removes the container and temporary log volume created by this pipeline stage.

Link copied to clipboard
protected open suspend fun runContainer(input: StageResult, hostConfig: HostConfig, outVolume: DockerVolume?): DockerVolume?

Builds the Docker image backing this pipeline stage, and runs the container.

Link copied to clipboard

Depending on the nature of src, builds the corresponding command to read in the src in a shell Var. A InputSrc.Literal is read-in using heredoc, while a InputSrc.Path to a file is cat-ed in.

Link copied to clipboard
private fun transformResult(outVolume: DockerVolume?): StageResult

Transforms the result of the stage into a StageResult.

Link copied to clipboard
fun Var(baseName: String): CmdUtils.Var

Variable builder inheriting the CmdLang of this stage.