-
Notifications
You must be signed in to change notification settings - Fork 6
/
noop_sandbox.go
93 lines (83 loc) · 2.21 KB
/
noop_sandbox.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package runner
import (
"github.com/omegaup/quark/common"
"math/big"
"os"
)
// NoopSandbox is a sandbox that does nothing and always grades runs as AC.
type NoopSandbox struct{}
var _ Sandbox = &NoopSandbox{}
// Supported returns true if the sandbox is available in the system.
func (*NoopSandbox) Supported() bool {
return true
}
// Compile performs a compilation in the specified language.
func (*NoopSandbox) Compile(
ctx *common.Context,
lang string,
inputFiles []string,
chdir, outputFile, errorFile, metaFile, target string,
extraFlags []string,
) (*RunMetadata, error) {
ctx.Log.Info("Running with the no-op Sandbox")
for _, filename := range []string{outputFile, errorFile, metaFile} {
f, err := os.Create(filename)
if err != nil {
return nil, err
}
f.Close()
}
return &RunMetadata{Verdict: "OK"}, nil
}
// Run uses a previously compiled program and runs it against a single test
// case with the supplied limits.
func (*NoopSandbox) Run(
ctx *common.Context,
limits *common.LimitsSettings,
lang, chdir, inputFile, outputFile, errorFile, metaFile, target string,
originalInputFile, originalOutputFile, runMetaFile *string,
extraParams []string,
extraMountPoints map[string]string,
) (*RunMetadata, error) {
for _, filename := range []string{outputFile, errorFile, metaFile} {
f, err := os.Create(filename)
if err != nil {
return nil, err
}
f.Close()
}
return &RunMetadata{Verdict: "OK"}, nil
}
// NoopSandboxFixupResult amends the result so that it is AC.
func NoopSandboxFixupResult(result *RunResult) {
// The no-op runner judges everything as AC.
result.Verdict = "AC"
result.Score = big.NewRat(1, 1)
result.ContestScore = new(big.Rat).Mul(
result.Score,
result.MaxScore,
)
for i := range result.Groups {
group := &result.Groups[i]
group.Score = new(big.Rat).Add(
&big.Rat{},
group.MaxScore,
)
group.ContestScore = new(big.Rat).Mul(
group.MaxScore,
result.ContestScore,
)
for j := range group.Cases {
caseResult := &group.Cases[j]
caseResult.Score = new(big.Rat).Add(
&big.Rat{},
caseResult.MaxScore,
)
caseResult.ContestScore = new(big.Rat).Mul(
caseResult.MaxScore,
result.ContestScore,
)
caseResult.Verdict = "AC"
}
}
}