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 ¶
- type ByteValue
- type L
- type LimitType
- type Option
- type OptionProvider
- func WithArgument(argv ...string) OptionProvider
- func WithCpuTime(duration time.Duration) OptionProvider
- func WithEnviron(environ ...string) OptionProvider
- func WithFileno(num int) OptionProvider
- func WithJudger(r Runner) OptionProvider
- func WithLog(file string, level int, color bool) OptionProvider
- func WithOutput(space ByteValue) OptionProvider
- func WithPolicy(name string) OptionProvider
- func WithPolicyDir(dir string) OptionProvider
- func WithRealMemory(space ByteValue) OptionProvider
- func WithRealTime(duration time.Duration) OptionProvider
- func WithStack(space ByteValue) OptionProvider
- func WithVirMemory(space ByteValue) OptionProvider
- type Result
- type Runner
- type StatusCode
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
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 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/sshwy/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)
}
func (*Result) ProcResult ¶
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 )