judger

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package judger is the go wrapper for https://github.com/sshwy/yaoj-judger.

Since this package requires a lot of depedencies and a "go generate" to initialize, it's not recommended to import this package.

To build (run) this package, you need to make sure auditd, flex, make, gengetopt, bison, xxd, strace, and clang toolkit (basically clang++) is available via command line. If not, install them. Before building, run go generate for some necessary files.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteValue

type ByteValue int64
const GB ByteValue = KB * MB
const KB ByteValue = 1024
const MB ByteValue = KB * KB

func (ByteValue) String

func (r ByteValue) String() string

type L

type L map[LimitType]int64

short cut for Limitation

type LimitType

type LimitType int

type Option

type Option struct {
	Logfile   string
	LogLevel  int
	LogColor  bool
	Policy    string
	PolicyDir string
	Argument  []string
	Environ   []string
	Limit     L
	Runner    Runner
}

type OptionProvider

type OptionProvider func(*Option)

func WithArgument

func WithArgument(argv ...string) OptionProvider

Runners differ in arguments.

For the General: [input] [output] [outerr] [exec] [arguments...]

For the Interactive: [exec] [interactor] [input_itct] [output_itct] [outerr_itct] [outerr]. Note that stdin and stdout of interactor and executable will be piped together in a two way communication.

func WithCpuTime

func WithCpuTime(duration time.Duration) OptionProvider

func WithEnviron

func WithEnviron(environ ...string) OptionProvider

default: os.Environ()

func WithFileno

func WithFileno(num int) OptionProvider

Set limitation on number of fileno

func WithJudger

func WithJudger(r Runner) OptionProvider

Specify the runner to be used. General (default) or Interactive.

func WithLog

func WithLog(file string, level int, color bool) OptionProvider

Set logging file. Default is "runtime.log".

func WithOutput

func WithOutput(space ByteValue) OptionProvider

func WithPolicy

func WithPolicy(name string) OptionProvider

specify (builtin) policy. default: builtin:free

func WithPolicyDir

func WithPolicyDir(dir string) OptionProvider

func WithRealMemory

func WithRealMemory(space ByteValue) OptionProvider

func WithRealTime

func WithRealTime(duration time.Duration) OptionProvider

Set real time limitation

func WithStack

func WithStack(space ByteValue) OptionProvider

func WithVirMemory

func WithVirMemory(space ByteValue) OptionProvider

Set virtual memory limitation

type Result

type Result struct {
	// Result status:OK/RE/MLE/...
	Code              StatusCode
	RealTime, CpuTime *time.Duration
	Memory            *ByteValue
	Signal            *int
	Msg               string
}

Code is required, others are optional

func Judge

func Judge(options ...OptionProvider) (*Result, error)
Example
package main

import (
	"log"
	"path"
	"time"

	"github.com/super-yaoj/yaoj-core/pkg/private/judger"
)

func main() {
	dir := "/tmp"
	res, err := judger.Judge(
		judger.WithArgument("/dev/null", path.Join(dir, "output"), "/dev/null", "/usr/bin/ls", "."),
		judger.WithJudger(judger.General),
		judger.WithPolicy("builtin:free"),
		judger.WithLog(path.Join(dir, "runtime.log"), 0, false),
		judger.WithRealMemory(3*judger.MB),
		judger.WithStack(3*judger.MB),
		judger.WithVirMemory(3*judger.MB),
		judger.WithRealTime(time.Millisecond*1000),
		judger.WithCpuTime(time.Millisecond*1000),
		judger.WithOutput(3*judger.MB),
		judger.WithFileno(10),
	)
	if err != nil {
		log.Fatal(err)
	}
	log.Print(*res)
}
Output:

func (*Result) ProcResult

func (r *Result) ProcResult() *processor.Result

func (Result) String

func (r Result) String() string

type Runner

type Runner int
const (
	General     Runner = 0
	Interactive Runner = 1
)

Runner type

type StatusCode

type StatusCode int

StatusCode describes final status of a execution. Note that Ok is the only status for success

const (
	Ok               StatusCode = C.OK
	RuntimeError     StatusCode = C.RE
	MemoryExceed     StatusCode = C.MLE
	TimeExceed       StatusCode = C.TLE
	OoutputExceed    StatusCode = C.OLE
	SystemError      StatusCode = C.SE
	DangerousSyscall StatusCode = C.DSC
	ExitError        StatusCode = C.ECE
)

Jump to

Keyboard shortcuts

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