runners

package
v0.0.0-...-1388524 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package runners is used to execute programs using the sandbox ExecService, providing a higher-level abstraction.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgFunc

type ArgFunc func(prog *runpb.CompiledProgram) *CommandArgs

An ArgFunc takes provides the CommandArgs necessary to run a compiled program.

type CommandArgs

type CommandArgs struct {
	// The executable file that should be run.
	Command string

	// The arguments that should be provided to the program.
	Args []string

	// The working directory the command should be executed.
	WorkingDirectory string
}

A CommandArgs represents how a program should be executed; the command used, what arguments are necessery and so on.

type ExecArgs

type ExecArgs struct {
	Command          string
	Args             []string
	WorkingDirectory string
	InputPath        string
	OutputPath       string
	ErrorPath        string
	ExtraReadPaths   []string
	ExtraWritePaths  []string
	TimeLimitMs      int32
	MemoryLimitKb    int32
	ReuseContainer   bool
}

type ExecResult

type ExecResult struct {
	// How how the program exited.
	ExitType ExitType

	// The exit code. Only set if the program exited with a code.
	ExitCode int32

	// The termination singal. Only set if the program exited with a signal.
	Signal int32

	// The time the execution used.
	TimeUsageMs int32

	// The memory the execution used.
	MemoryUsageKb int32
}

An ExecResult describes the result of a single execution.

func (ExecResult) Crashed

func (res ExecResult) Crashed() bool

Crashed checks whether the program crashed.

func (ExecResult) CrashedWith

func (res ExecResult) CrashedWith(code int32) bool

CrashedWith checks whether the program exited normally with the given code.

func (ExecResult) MemoryExceeded

func (res ExecResult) MemoryExceeded() bool

MemoryExceeded checks whether the program exceeded its memory limit or not.

func (ExecResult) TimedOut

func (res ExecResult) TimedOut() bool

TimedOut checks whether the program exceeded its time limit or not.

type ExitType

type ExitType int

An ExitType describes why a program exited.

const (
	// Exited means the program exited normally with an exit code.
	Exited ExitType = iota

	// Signaled means the program was killed by a signal.
	Signaled

	// TimedOut means the program was killed due to exceeding its time limit.
	TimedOut

	// MemoryExceeded means the program was killed due to exceeding its allocated memory.
	MemoryExceeded
)

type FileLinker

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

FileLinker can be used to easily link in any files into two directories based on its writability.

The main use case it for easily swapping out readable and writable files that should have the same name within a container executing a program multiple times, such as input and output files. It keeps all links in a small number of directories, which makes it easy to clear up the file system environment between runs.

func NewFileLinker

func NewFileLinker(dir string) (*FileLinker, error)

NewFileLinker returns a new file linker, rooted at the given path.

func (*FileLinker) Clear

func (fl *FileLinker) Clear() error

Clear resets the environment for a new execution.

func (*FileLinker) LinkFile

func (fl *FileLinker) LinkFile(path, inName string, writeable bool) error

LinkFile hard links the file path into the inside root.

func (*FileLinker) PathFor

func (fl *FileLinker) PathFor(inName string, writeable bool) string

PathFor returns the path that a file will get inside the linker.

type Program

type Program interface {
	// SetArgs sets the arguments for the next execution.
	SetArgs(*ProgramArgs)

	// Execute executes the program with the given arguments.
	Execute() (*ExecResult, error)
}

A Program is an abstraction around a program that can be run.

type ProgramArgs

type ProgramArgs struct {
	// The file path that should be mapped to stdin in the execution.
	InputPath string
	// The file path that should be mapped to stdout in the execution.
	OutputPath string
	// The file path that should be mapped to stderr in the execution.
	ErrorPath string
	// The time limit to enforce on the execution.
	TimeLimitMs int32
	// The memory limit to enforce on the execution.
	MemoryLimitKb int32
	// Potential extra arguments that should be provided to the program.
	ExtraArgs []string
}

A ProgramArgs represents the arguments for a particular execution of a Program.

type RunFunc

A RunFunc takes a compiled program and an executor and returns an executable program.

func CommandProgram

func CommandProgram(argFunc ArgFunc) RunFunc

CommandProgram returns a RunFunc that creates programs based on the given ArgFunc.

Jump to

Keyboard shortcuts

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