feat(runner): compile Go and check answers per test group
This commit is contained in:
1 parent
e95c681165
commit
afee564bf4
61 files changed
+2592
-143
No files matched your search
@@ -38,11 +38,17 @@ func (s *BearerAuth) SetRoles(val []string) {
|
||||
s.Roles = val
|
||||
}
|
||||
|
||||
// How the standard output of a test is compared with `expected_output`. Future kinds, such as a float
|
||||
// tolerance or a custom checker, add a `kind` value and their own optional parameters to this object.
|
||||
// How the standard output of a test is compared with `expected_output`. `numbers` requires
|
||||
// `abs_tolerance`, `rel_tolerance`, or both; `custom` requires `program`. Other kinds take no
|
||||
// parameter. New kinds add a `kind` value and their own optional parameters.
|
||||
// Ref: #/components/schemas/Checker
|
||||
type Checker struct {
|
||||
Kind CheckerKind `json:"kind"`
|
||||
// Largest accepted absolute difference of two numeric tokens.
|
||||
AbsTolerance OptFloat64 `json:"abs_tolerance"`
|
||||
// Largest accepted difference of two numeric tokens relative to the expected value.
|
||||
RelTolerance OptFloat64 `json:"rel_tolerance"`
|
||||
Program OptCheckerProgram `json:"program"`
|
||||
}
|
||||
|
||||
// GetKind returns the value of Kind.
|
||||
@@ -50,21 +56,56 @@ func (s *Checker) GetKind() CheckerKind {
|
||||
return s.Kind
|
||||
}
|
||||
|
||||
// GetAbsTolerance returns the value of AbsTolerance.
|
||||
func (s *Checker) GetAbsTolerance() OptFloat64 {
|
||||
return s.AbsTolerance
|
||||
}
|
||||
|
||||
// GetRelTolerance returns the value of RelTolerance.
|
||||
func (s *Checker) GetRelTolerance() OptFloat64 {
|
||||
return s.RelTolerance
|
||||
}
|
||||
|
||||
// GetProgram returns the value of Program.
|
||||
func (s *Checker) GetProgram() OptCheckerProgram {
|
||||
return s.Program
|
||||
}
|
||||
|
||||
// SetKind sets the value of Kind.
|
||||
func (s *Checker) SetKind(val CheckerKind) {
|
||||
s.Kind = val
|
||||
}
|
||||
|
||||
// SetAbsTolerance sets the value of AbsTolerance.
|
||||
func (s *Checker) SetAbsTolerance(val OptFloat64) {
|
||||
s.AbsTolerance = val
|
||||
}
|
||||
|
||||
// SetRelTolerance sets the value of RelTolerance.
|
||||
func (s *Checker) SetRelTolerance(val OptFloat64) {
|
||||
s.RelTolerance = val
|
||||
}
|
||||
|
||||
// SetProgram sets the value of Program.
|
||||
func (s *Checker) SetProgram(val OptCheckerProgram) {
|
||||
s.Program = val
|
||||
}
|
||||
|
||||
// - exact: both texts are equal after replacing CRLF with LF, removing trailing spaces and tabs at
|
||||
// the end of each line, and removing trailing empty lines.
|
||||
// - tokens: both texts split on ASCII whitespace give the same sequence of tokens.
|
||||
// - numbers: like tokens, but two finite numeric tokens are equal when their difference is within
|
||||
// abs_tolerance or within rel_tolerance times the expected value; other tokens must be equal.
|
||||
// - custom: the checker program of the task family decides in the sandbox.
|
||||
//
|
||||
// Ref: #/components/schemas/CheckerKind
|
||||
type CheckerKind string
|
||||
|
||||
const (
|
||||
CheckerKindExact CheckerKind = "exact"
|
||||
CheckerKindTokens CheckerKind = "tokens"
|
||||
CheckerKindExact CheckerKind = "exact"
|
||||
CheckerKindTokens CheckerKind = "tokens"
|
||||
CheckerKindNumbers CheckerKind = "numbers"
|
||||
CheckerKindCustom CheckerKind = "custom"
|
||||
)
|
||||
|
||||
// AllValues returns all CheckerKind values.
|
||||
@@ -72,6 +113,8 @@ func (CheckerKind) AllValues() []CheckerKind {
|
||||
return []CheckerKind{
|
||||
CheckerKindExact,
|
||||
CheckerKindTokens,
|
||||
CheckerKindNumbers,
|
||||
CheckerKindCustom,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +125,10 @@ func (s CheckerKind) MarshalText() ([]byte, error) {
|
||||
return []byte(s), nil
|
||||
case CheckerKindTokens:
|
||||
return []byte(s), nil
|
||||
case CheckerKindNumbers:
|
||||
return []byte(s), nil
|
||||
case CheckerKindCustom:
|
||||
return []byte(s), nil
|
||||
default:
|
||||
return nil, errors.Errorf("invalid value: %q", s)
|
||||
}
|
||||
@@ -96,11 +143,48 @@ func (s *CheckerKind) UnmarshalText(data []byte) error {
|
||||
case CheckerKindTokens:
|
||||
*s = CheckerKindTokens
|
||||
return nil
|
||||
case CheckerKindNumbers:
|
||||
*s = CheckerKindNumbers
|
||||
return nil
|
||||
case CheckerKindCustom:
|
||||
*s = CheckerKindCustom
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid value: %q", data)
|
||||
}
|
||||
}
|
||||
|
||||
// Checker program of the task family. It runs in the sandbox with the same isolation as the solution
|
||||
// and fixed limits of its own (5 s CPU, 256 MiB). Its arguments are the paths of three read-only
|
||||
// files: the test input, the expected output, and the actual output. Exit status 0 accepts, 1 rejects,
|
||||
// and anything else, a signal, or a limit is a checker failure, which makes the run
|
||||
// infrastructure_failure. Its own output is discarded and never returned.
|
||||
// Ref: #/components/schemas/CheckerProgram
|
||||
type CheckerProgram struct {
|
||||
Language RunLanguage `json:"language"`
|
||||
Source string `json:"source"`
|
||||
}
|
||||
|
||||
// GetLanguage returns the value of Language.
|
||||
func (s *CheckerProgram) GetLanguage() RunLanguage {
|
||||
return s.Language
|
||||
}
|
||||
|
||||
// GetSource returns the value of Source.
|
||||
func (s *CheckerProgram) GetSource() string {
|
||||
return s.Source
|
||||
}
|
||||
|
||||
// SetLanguage sets the value of Language.
|
||||
func (s *CheckerProgram) SetLanguage(val RunLanguage) {
|
||||
s.Language = val
|
||||
}
|
||||
|
||||
// SetSource sets the value of Source.
|
||||
func (s *CheckerProgram) SetSource(val string) {
|
||||
s.Source = val
|
||||
}
|
||||
|
||||
// Ref: #/components/schemas/CompileResult
|
||||
type CompileResult struct {
|
||||
Outcome RunOutcome `json:"outcome"`
|
||||
@@ -233,6 +317,52 @@ func (s *GroupResult) SetTests(val []TestResult) {
|
||||
s.Tests = val
|
||||
}
|
||||
|
||||
// NewOptCheckerProgram returns new OptCheckerProgram with value set to v.
|
||||
func NewOptCheckerProgram(v CheckerProgram) OptCheckerProgram {
|
||||
return OptCheckerProgram{
|
||||
Value: v,
|
||||
Set: true,
|
||||
}
|
||||
}
|
||||
|
||||
// OptCheckerProgram is optional CheckerProgram.
|
||||
type OptCheckerProgram struct {
|
||||
Value CheckerProgram
|
||||
Set bool
|
||||
}
|
||||
|
||||
// IsSet returns true if OptCheckerProgram was set.
|
||||
func (o OptCheckerProgram) IsSet() bool { return o.Set }
|
||||
|
||||
// Reset unsets value.
|
||||
func (o *OptCheckerProgram) Reset() {
|
||||
var v CheckerProgram
|
||||
o.Value = v
|
||||
o.Set = false
|
||||
}
|
||||
|
||||
// SetTo sets value to v.
|
||||
func (o *OptCheckerProgram) SetTo(v CheckerProgram) {
|
||||
o.Set = true
|
||||
o.Value = v
|
||||
}
|
||||
|
||||
// Get returns value and boolean that denotes whether value was set.
|
||||
func (o OptCheckerProgram) Get() (v CheckerProgram, ok bool) {
|
||||
if !o.Set {
|
||||
return v, false
|
||||
}
|
||||
return o.Value, true
|
||||
}
|
||||
|
||||
// Or returns value if set, or given parameter if does not.
|
||||
func (o OptCheckerProgram) Or(d CheckerProgram) CheckerProgram {
|
||||
if v, ok := o.Get(); ok {
|
||||
return v
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// NewOptCompileResult returns new OptCompileResult with value set to v.
|
||||
func NewOptCompileResult(v CompileResult) OptCompileResult {
|
||||
return OptCompileResult{
|
||||
@@ -279,6 +409,52 @@ func (o OptCompileResult) Or(d CompileResult) CompileResult {
|
||||
return d
|
||||
}
|
||||
|
||||
// NewOptFloat64 returns new OptFloat64 with value set to v.
|
||||
func NewOptFloat64(v float64) OptFloat64 {
|
||||
return OptFloat64{
|
||||
Value: v,
|
||||
Set: true,
|
||||
}
|
||||
}
|
||||
|
||||
// OptFloat64 is optional float64.
|
||||
type OptFloat64 struct {
|
||||
Value float64
|
||||
Set bool
|
||||
}
|
||||
|
||||
// IsSet returns true if OptFloat64 was set.
|
||||
func (o OptFloat64) IsSet() bool { return o.Set }
|
||||
|
||||
// Reset unsets value.
|
||||
func (o *OptFloat64) Reset() {
|
||||
var v float64
|
||||
o.Value = v
|
||||
o.Set = false
|
||||
}
|
||||
|
||||
// SetTo sets value to v.
|
||||
func (o *OptFloat64) SetTo(v float64) {
|
||||
o.Set = true
|
||||
o.Value = v
|
||||
}
|
||||
|
||||
// Get returns value and boolean that denotes whether value was set.
|
||||
func (o OptFloat64) Get() (v float64, ok bool) {
|
||||
if !o.Set {
|
||||
return v, false
|
||||
}
|
||||
return o.Value, true
|
||||
}
|
||||
|
||||
// Or returns value if set, or given parameter if does not.
|
||||
func (o OptFloat64) Or(d float64) float64 {
|
||||
if v, ok := o.Get(); ok {
|
||||
return v
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
// NewOptInt32 returns new OptInt32 with value set to v.
|
||||
func NewOptInt32(v int32) OptInt32 {
|
||||
return OptInt32{
|
||||
@@ -868,18 +1044,23 @@ func (s *ProblemStatusCode) SetResponse(val Problem) {
|
||||
}
|
||||
|
||||
// Language and runtime of the source. `python3` runs the Python 3 interpreter of the runner image with
|
||||
// isolated mode and no bytecode writes; a syntax check runs first and fails with compile_error.
|
||||
// isolated mode and no bytecode writes; a syntax check runs first and fails with compile_error. `go`
|
||||
// compiles one `package main` file with the Go toolchain of the runner image against a prebuilt
|
||||
// standard library (no modules, no cgo, no network) in a separate compile phase with its own limits; a
|
||||
// compile or link error is compile_error and no test runs.
|
||||
// Ref: #/components/schemas/RunLanguage
|
||||
type RunLanguage string
|
||||
|
||||
const (
|
||||
RunLanguagePython3 RunLanguage = "python3"
|
||||
RunLanguageGo RunLanguage = "go"
|
||||
)
|
||||
|
||||
// AllValues returns all RunLanguage values.
|
||||
func (RunLanguage) AllValues() []RunLanguage {
|
||||
return []RunLanguage{
|
||||
RunLanguagePython3,
|
||||
RunLanguageGo,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -888,6 +1069,8 @@ func (s RunLanguage) MarshalText() ([]byte, error) {
|
||||
switch s {
|
||||
case RunLanguagePython3:
|
||||
return []byte(s), nil
|
||||
case RunLanguageGo:
|
||||
return []byte(s), nil
|
||||
default:
|
||||
return nil, errors.Errorf("invalid value: %q", s)
|
||||
}
|
||||
@@ -899,6 +1082,9 @@ func (s *RunLanguage) UnmarshalText(data []byte) error {
|
||||
case RunLanguagePython3:
|
||||
*s = RunLanguagePython3
|
||||
return nil
|
||||
case RunLanguageGo:
|
||||
*s = RunLanguageGo
|
||||
return nil
|
||||
default:
|
||||
return errors.Errorf("invalid value: %q", data)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user