judger

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2021 License: MIT Imports: 3 Imported by: 0

README

Judger

A golang judger, encapsulated from QingdaoU/Judger.

Build static link library: cd build && cmake . && make

Documentation

Index

Constants

View Source
const (
	ArgsMaxNumber = 256
	EnvMaxNumber  = 256
)
View Source
const (
	ErrInvalidConfig     resultError = "invalid config"
	ErrForkFailed        resultError = "fork failed"
	ErrPthreadFailed     resultError = "pthread failed"
	ErrWaitFailed        resultError = "wait failed"
	ErrRootRequired      resultError = "root required"
	ErrLoadSeccompFailed resultError = "load seccomp failed"
	ErrSetRLimitFailed   resultError = "setrlimit failed"
	ErrDup2Failed        resultError = "dup2 failed"
	ErrSetuidFailed      resultError = "setuid failed"
	ErrExecveFailed      resultError = "execve failed"
	ErrSetOOMFailed      resultError = "set OOM failed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	MaxCPUTime           int      // max cpu time(ms) this process can cost, -1 for unlimited
	MaxRealTime          int      // max time(ms) this process can run, -1 for unlimited
	MaxMemory            int      // max size(byte) of the process' virtual memory (address space), -1 for unlimited
	MaxStack             int      // max size(byte) of the process' stack size
	MaxProcessNumber     int      // max number of processes that can be created for the real user id of the calling process, -1 for unlimited
	MaxOutputSize        int      // max size(byte) of data this process can output to stdout, stderr and file, -1 for unlimited
	MemoryLimitCheckOnly int      // if this value equals 0, we will only check memory usage number, because setrlimit(maxrss) will cause some crash issues
	ExePath              string   // path of file to run
	InputPath            string   // redirect content of this file to process's stdin
	OutputPath           string   // redirect process's stdout to this file
	ErrorPath            string   // redirect process's stderr to this file
	Args                 []string // arguments to run this process
	Env                  []string // environment variables this process can get
	LogPath              string   // judger log path
	SeccompRuleName      string   // seccomp rules used to limit process system calls.
	// Name is used to call corresponding functions.
	// Possible values are: c_cpp, c_cpp_file_io, general
	Uid uint32 // user to run this process
	Gid uint32 // user group this process belongs to
}

Config is struct used to record the running configuration.

type JudgeResult

type JudgeResult int
const (
	SUCCESS JudgeResult = iota
	CPU_TIME_LIMIT_EXCEEDED
	REAL_TIME_LIMIT_EXCEEDED
	MEMORY_LIMIT_EXCEEDED
	RUNTIME_ERROR
	SYSTEM_ERROR
)

type Result

type Result struct {
	CPUTime  int         // cpu time the process has used
	RealTime int         // actual running time of the process
	Memory   int         // max value of memory used by the process
	Signal   int         // signal number
	ExitCode int         // process's exit code
	Result   JudgeResult // Judge result
}

Result is a struct used to record the running result.

func Run

func Run(config Config) (result Result, err error)

Run runs the program in the sandbox according to the config and returns the result.

Jump to

Keyboard shortcuts

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