-
Notifications
You must be signed in to change notification settings - Fork 0
/
testlib.go
67 lines (55 loc) · 1.44 KB
/
testlib.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
package checker
import (
"bytes"
"fmt"
"os/exec"
"strings"
"syscall"
"github.com/mraron/njudge/pkg/problems"
)
// Testlib is [polygon]'s default checker format
//
// [polygon]: https://polygon.codeforces.com
type Testlib struct {
path string
}
func NewTestlib(path string) Testlib {
return Testlib{path: path}
}
func (Testlib) Name() string {
return "testlib"
}
func (t Testlib) Check(tc *problems.Testcase) error {
output := &bytes.Buffer{}
args := []string{t.path, tc.InputPath, tc.OutputPath, tc.AnswerPath}
cmd := exec.Command("/bin/sh", "-c", "ulimit -s unlimited && "+strings.Join(args, " "))
cmd.Stdout = output
cmd.Stderr = output
err := cmd.Run()
tc.CheckerOutput = problems.Truncate(output.String())
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok {
if status.ExitStatus() == 1 {
tc.VerdictName = problems.VerdictWA
} else if status.ExitStatus() == 2 {
tc.VerdictName = problems.VerdictPE
} else if status.ExitStatus() == 7 { //only support quitp
tc.VerdictName = problems.VerdictPC
rel := 0
fmt.Sscanf(output.String(), "points %d", &rel)
tc.Score = float64(rel) / 100.0 * tc.MaxScore
} else { //3 -> fail
tc.VerdictName = problems.VerdictXX
}
}
} else {
tc.VerdictName = problems.VerdictXX
return err
}
} else {
tc.Score = tc.MaxScore
tc.VerdictName = problems.VerdictAC
}
return nil
}