runner

package
v1.9.68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2023 License: BSD-3-Clause Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxTokenLength represents the maximum length of a token, which is 4MB. Any
	// token longer than that is treated as EOF.
	MaxTokenLength = 4194304 // 4MiB
)

Variables

This section is empty.

Functions

func IsNonWhitespace

func IsNonWhitespace(r rune) bool

IsNonWhitespace returns true if the rune is neither an unicode space or a Java whitespace character. The only characters that seem to be Java whitespace but not unicode whitespace are: U+001C FILE SEPARATOR U+001D GROUP SEPARATOR U+001E RECORD SEPARATOR U+001F UNIT SEPARATOR

func IsNumeric

func IsNumeric(r rune) bool

IsNumeric returns true if the rune may be part of a number.

func NewCachedInputFactory added in v1.1.0

func NewCachedInputFactory(cachePath string) common.CachedInputFactory

NewCachedInputFactory creates a new CachedInputFactory.

func NewInputFactory added in v1.1.0

func NewInputFactory(
	client *http.Client,
	config *common.Config,
	baseURL *url.URL,
	problem string,
) common.InputFactory

NewInputFactory returns a new InputFactory.

func NoopSandboxFixupResult added in v1.1.8

func NoopSandboxFixupResult(result *RunResult)

NoopSandboxFixupResult amends the result so that it is AC.

Types

type BenchmarkResult

type BenchmarkResult struct {
	Time     float64
	WallTime float64
	Memory   base.Byte
}

A BenchmarkResult represents the result of a single benchmark run.

type BenchmarkResults

type BenchmarkResults map[string]BenchmarkResult

BenchmarkResults represents the results of running the whole suite of benchmarks.

func RunHostBenchmark

func RunHostBenchmark(
	ctx *common.Context,
	inputManager *common.InputManager,
	sandbox Sandbox,
	ioLock sync.Locker,
) (BenchmarkResults, error)

RunHostBenchmark runs the benchmarking suite and returns its results.

type CachedInputFactory added in v1.1.0

type CachedInputFactory struct {
	// contains filtered or unexported fields
}

CachedInputFactory restores Inputs from a directory in the filesystem.

func (*CachedInputFactory) GetInputHash added in v1.1.0

func (factory *CachedInputFactory) GetInputHash(
	dirname string,
	info os.FileInfo,
) (hash string, ok bool)

GetInputHash returns the hash of the input located at the specified directory.

func (*CachedInputFactory) NewInput added in v1.1.0

func (factory *CachedInputFactory) NewInput(
	hash string,
	mgr *common.InputManager,
) common.Input

NewInput returns the Input for the provided hash.

type CaseResult

type CaseResult struct {
	Verdict        string                 `json:"verdict"`
	Name           string                 `json:"name"`
	Score          *big.Rat               `json:"score"`
	ContestScore   *big.Rat               `json:"contest_score"`
	MaxScore       *big.Rat               `json:"max_score"`
	Meta           RunMetadata            `json:"meta"`
	IndividualMeta map[string]RunMetadata `json:"individual_meta,omitempty"`
}

A CaseResult represents the sub-results of a specific test case.

func (*CaseResult) MarshalJSON added in v1.1.0

func (c *CaseResult) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*CaseResult) UnmarshalJSON added in v1.1.0

func (c *CaseResult) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type GroupResult

type GroupResult struct {
	Group        string       `json:"group"`
	Score        *big.Rat     `json:"score"`
	ContestScore *big.Rat     `json:"contest_score"`
	MaxScore     *big.Rat     `json:"max_score"`
	Cases        []CaseResult `json:"cases"`
}

A GroupResult represents the sub-results of a specific group of test cases.

func (*GroupResult) MarshalJSON added in v1.1.0

func (g *GroupResult) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*GroupResult) UnmarshalJSON added in v1.1.0

func (g *GroupResult) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*GroupResult) Verdict added in v1.9.34

func (g *GroupResult) Verdict() string

Verdict returns the final verdict of the group.

type Input added in v1.1.0

type Input struct {
	// contains filtered or unexported fields
}

Input is a common.Input that can fetch the test case data from the grader.

func (*Input) Delete added in v1.1.0

func (input *Input) Delete() error

Delete removes the filesystem files for the Input.

func (*Input) Path added in v1.1.0

func (input *Input) Path() string

func (*Input) Persist added in v1.1.0

func (input *Input) Persist() error

Persist stores the Input into the filesystem.

func (*Input) Release added in v1.1.20

func (input *Input) Release()

Release removes the filesystem files for the Input.

func (*Input) Verify added in v1.1.0

func (input *Input) Verify() error

type InputFactory added in v1.1.0

type InputFactory struct {
	// contains filtered or unexported fields
}

InputFactory is a common.InputFactory that can fetch the test case data from the grader.

func (*InputFactory) NewInput added in v1.1.0

func (factory *InputFactory) NewInput(
	hash string,
	mgr *common.InputManager,
) common.Input

NewInput returns a new Input that corresponds to the specified hash.

type NoopSandbox added in v1.1.8

type NoopSandbox struct{}

NoopSandbox is a sandbox that does nothing and always grades runs as AC.

func (*NoopSandbox) Compile added in v1.1.8

func (*NoopSandbox) Compile(
	ctx *common.Context,
	lang string,
	inputFiles []string,
	chdir, outputFile, errorFile, metaFile, target string,
	extraFlags []string,
) (*RunMetadata, error)

Compile performs a compilation in the specified language.

func (*NoopSandbox) Run added in v1.1.8

func (*NoopSandbox) Run(
	ctx *common.Context,
	limits *common.LimitsSettings,
	lang, chdir, inputFile, outputFile, errorFile, metaFile, target string,
	originalInputFile, originalOutputFile, runMetaFile *string,
	extraParams []string,
	extraMountPoints map[string]string,
) (*RunMetadata, error)

Run uses a previously compiled program and runs it against a single test case with the supplied limits.

func (*NoopSandbox) Supported added in v1.1.8

func (*NoopSandbox) Supported() bool

Supported returns true if the sandbox is available in the system.

type OmegajailSandbox added in v1.1.0

type OmegajailSandbox struct {

	// AllowSigsysFallback allows omegajail to use the previous implementation of
	// the sigsys detector if it's running on an older pre-5.13 kernel.
	AllowSigsysFallback bool

	DisableSandboxing bool
	// contains filtered or unexported fields
}

OmegajailSandbox is an implementation of a Sandbox that uses the omegajail sandbox.

func NewOmegajailSandbox added in v1.1.37

func NewOmegajailSandbox(omegajailRoot string) *OmegajailSandbox

NewOmegajailSandbox creates a new OmegajailSandbox.

func (*OmegajailSandbox) Compile added in v1.1.0

func (o *OmegajailSandbox) Compile(
	ctx *common.Context,
	lang string,
	inputFiles []string,
	chdir, outputFile, errorFile, metaFile, target string,
	extraFlags []string,
) (*RunMetadata, error)

Compile compiles the contestant-supplied program using the specified configuration using the omegajail sandbox.

func (*OmegajailSandbox) Run added in v1.1.0

func (o *OmegajailSandbox) Run(
	ctx *common.Context,
	limits *common.LimitsSettings,
	lang, chdir, inputFile, outputFile, errorFile, metaFile, target string,
	originalInputFile, originalOutputFile, runMetaFile *string,
	extraParams []string,
	extraMountPoints map[string]string,
) (*RunMetadata, error)

Run invokes the contestant-supplied program against a specified input and run configuration using the omegajail sandbox.

func (*OmegajailSandbox) Supported added in v1.1.0

func (o *OmegajailSandbox) Supported() bool

Supported returns whether the omegajail binary is installed in the system.

type RunMetadata

type RunMetadata struct {
	Verdict    string    `json:"verdict"`
	ExitStatus int       `json:"exit_status,omitempty"`
	Time       float64   `json:"time"`
	SystemTime float64   `json:"sys_time"`
	WallTime   float64   `json:"wall_time"`
	Memory     base.Byte `json:"memory"`
	OutputSize base.Byte `json:"output_size"`
	Signal     *string   `json:"signal,omitempty"`
	Syscall    *string   `json:"syscall,omitempty"`
}

RunMetadata represents the results of an execution.

func (*RunMetadata) String added in v1.1.0

func (m *RunMetadata) String() string

type RunResult

type RunResult struct {
	Verdict       string                 `json:"verdict"`
	CompileError  *string                `json:"compile_error,omitempty"`
	CompileMeta   map[string]RunMetadata `json:"compile_meta"`
	Score         *big.Rat               `json:"score"`
	ContestScore  *big.Rat               `json:"contest_score"`
	MaxScore      *big.Rat               `json:"max_score"`
	Time          float64                `json:"time"`
	WallTime      float64                `json:"wall_time"`
	Memory        base.Byte              `json:"memory"`
	OverallOutput base.Byte              `json:"total_output"`
	JudgedBy      string                 `json:"judged_by,omitempty"`
	Groups        []GroupResult          `json:"groups"`
}

A RunResult represents the results of a run.

func Grade

func Grade(
	ctx *common.Context,
	filesWriter io.Writer,
	run *common.Run,
	input common.Input,
	sandbox Sandbox,
) (*RunResult, error)

Grade compiles and runs a contestant-provided program, supplies it with the Input-specified inputs, and computes its final score and verdict.

func NewRunResult added in v1.1.0

func NewRunResult(verdict string, maxScore *big.Rat) *RunResult

NewRunResult returns a new RunResult.

func (*RunResult) MarshalJSON added in v1.1.0

func (r *RunResult) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*RunResult) UnmarshalJSON added in v1.1.0

func (r *RunResult) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

type Sandbox

type Sandbox interface {
	// Supported returns true if the sandbox is available in the system.
	Supported() bool

	// Compile performs a compilation in the specified language.
	Compile(
		ctx *common.Context,
		lang string,
		inputFiles []string,
		chdir, outputFile, errorFile, metaFile, target string,
		extraFlags []string,
	) (*RunMetadata, error)

	// Run uses a previously compiled program and runs it against a single test
	// case with the supplied limits.
	Run(
		ctx *common.Context,
		limits *common.LimitsSettings,
		lang, chdir, inputFile, outputFile, errorFile, metaFile, target string,
		originalInputFile, originalOutputFile, runMetaFile *string,
		extraParams []string,
		extraMountPoints map[string]string,
	) (*RunMetadata, error)
}

A Sandbox provides a mechanism to compile and run contestant-provided programs in a safe manner.

type Token

type Token struct {
	Text         string
	Line, Column int
}

Token represents a token in the stream.

type TokenMismatch

type TokenMismatch struct {
	Contestant *Token
	Expected   *Token
}

TokenMismatch represents a validation error where two tokens are considered to be different.

func CalculateScore

func CalculateScore(
	settings *common.ValidatorSettings,
	expectedOutput, contestantOutput io.Reader,
) (*big.Rat, *TokenMismatch, error)

CalculateScore calculates the score of a contestantOutput by comparing it with the expectedOutput under the specified validator settings.

type Tokenizer

type Tokenizer struct {
	// contains filtered or unexported fields
}

Tokenizer has mostly the same functionality as bufio.Scanner, but also provides the line and column information of the scanned tokens.

func NewTokenizer

func NewTokenizer(r io.Reader, tokenizerFunc TokenizerFunc) *Tokenizer

NewTokenizer returns a new Tokenizer that reads from r and uses the specified tokenizer function.

func (*Tokenizer) Err

func (t *Tokenizer) Err() error

Err returns the first non-EOF error that was encountered by the Tokenizer.

func (*Tokenizer) Scan

func (t *Tokenizer) Scan() bool

Scan advances the Tokenizer to the next token, which is available through the Token method. It returns false when the tokenization stops, either by reaching the end of the input or an error. After Scan returns false, the Err method will return any error that ocurred during tokenization, except that if it was io.EOF, Err will return nil.

func (*Tokenizer) Token

func (t *Tokenizer) Token() *Token

Token returns the most recent token generated by a call to Scan as a newly allocated Token holding the buffer as a string and position information.

type TokenizerFunc

type TokenizerFunc func(rune) bool

TokenizerFunc is a callback that returns true if the rune is part of a token.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL