Anubis

package module
v0.0.0-...-c5f8a9b Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: MIT Imports: 11 Imported by: 0

README

Anubis

Anubis is a library for securely running and automatically judging competitive programming submissions.

Installation

go get -u github.com/collcaz/anubis

Features

  • Blazingly Fast
  • Securly run code using ioi/isolate
  • Supports multiple programming languages
  • Easily add more programming languages
  • Can judge multiple submissions at the same time

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddProgLang

func AddProgLang(name, extension string, runner CodeRunner)

Types

type Anubis

type Anubis struct {
	Logger        *slog.Logger
	CommandRunner CommandRunner
}

func NewAnubis

func NewAnubis(ac AnubisConfig) Anubis

func (*Anubis) NewSubmission

func (a *Anubis) NewSubmission(codeFilePath string, testCases TestCases) Submission

type AnubisConfig

type AnubisConfig struct {
	Logger        *slog.Logger
	CommandRunner CommandRunner
}

type CodeRunner

type CodeRunner func(codeFile string, commandRunner CommandRunner) (RunOutput, error)

type CommandRunner

type CommandRunner interface {
	RunCommand(command *exec.Cmd) (RunOutput, error)
	SetInput(file *os.File)
}

type LineChecker

type LineChecker func(expectedLine, actualLine string, lineNumber int) (bool, int)

maps test input files with their expected output files

type LocalCmdRunner

type LocalCmdRunner struct {
	Input *os.File
}

func (*LocalCmdRunner) RunCommand

func (lcr *LocalCmdRunner) RunCommand(command *exec.Cmd) (RunOutput, error)

func (*LocalCmdRunner) SetInput

func (lcr *LocalCmdRunner) SetInput(file *os.File)

type LocalIsolateRunner

type LocalIsolateRunner struct {
	Input *os.File
}

func (*LocalIsolateRunner) RunCommand

func (lir *LocalIsolateRunner) RunCommand(command *exec.Cmd) (RunOutput, error)

func (*LocalIsolateRunner) SetInput

func (lir *LocalIsolateRunner) SetInput(file *os.File)

type ProgLang

type ProgLang struct {
	Name   string
	Runner CodeRunner
}

Programming Languages

func GetProgLang

func GetProgLang(filePath string) (ProgLang, error)

type RunOutput

type RunOutput struct {
	ExitStatus int
	StdOut     io.Reader
	StdErr     io.Reader
}

func LuaRunner

func LuaRunner(codeFile string, commandRunner CommandRunner) (RunOutput, error)

func PythonRunner

func PythonRunner(codeFile string, commandRunner CommandRunner) (RunOutput, error)

func Run

func Run(codeFile string, commandRunner CommandRunner, logger *slog.Logger) (RunOutput, error)

func (*RunOutput) String

func (rr *RunOutput) String() string

type Submission

type Submission struct {
	CodeFile      string
	TestCases     TestCases
	CommandRunner CommandRunner
	Logger        *slog.Logger
}

func (*Submission) CheckAll

func (s *Submission) CheckAll() (SubmissionOut, error)

type SubmissionOut

type SubmissionOut struct {
	Status SubmissionStatus
	// 0 if no failure, otherwise the first failed test case
	FailedOn int
	StdOut   io.Reader
	StdErr   io.Reader
}

type SubmissionStatus

type SubmissionStatus int
const (
	AC SubmissionStatus = iota
	CompileError
	RunTimeError
	Failed
	InternalError
)

type TestCases

type TestCases struct {
	InputOutput map[string]string
	LineChecker LineChecker
}

Jump to

Keyboard shortcuts

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