This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtester.go
79 lines (69 loc) · 1.63 KB
/
tester.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
package tester
import (
"encoding/json"
"errors"
"fmt"
"log"
"os"
"strconv"
)
func Tester() {
// <-- step1 : validate
testCaseCount, err := strconv.ParseInt(os.Getenv("CASE_COUNT"), 10, 32)
if err != nil {
panic(err)
}
timeLimit, err := strconv.ParseInt(os.Getenv("TIME_LIMIT"), 10, 32)
if err != nil {
panic(err)
}
spaceLimit, err := strconv.ParseInt(os.Getenv("SPACE_LIMIT"), 10, 32)
if err != nil {
panic(err)
}
// todo: optimistic ? can we believe the scheduler and do less routine ???
if testCaseCount <= 0 {
panic(errors.New("invalid test case"))
}
for i := int64(1); i <= testCaseCount; i++ {
if !Exists(DockerCasePath(i)) {
panic(errors.New(fmt.Sprintf("Case #%d doesn't exist", i)))
}
}
execCommandRaw := os.Getenv("EXEC_COMMAND")
if execCommandRaw == "" {
panic(err)
}
var execCommandArr []string
if err := json.Unmarshal([]byte(execCommandRaw), &execCommandArr); err != nil {
panic(err)
}
execCommand, execArgs := execCommandArr[0], execCommandArr[1:]
if len(execCommandArr) == 1 {
if err := os.Chmod(execCommandArr[0], 0755); err != nil {
log.Println(err)
}
}
file, err := os.Create(DockerResultFile())
if err != nil {
panic(err)
}
defer func() {
_ = file.Close()
}()
// <-- step2 : get_result
testResult := make([]TestResult, testCaseCount)
for i := int64(1); i <= testCaseCount; i++ {
fmt.Printf("Test #%d Case...\n", i)
TestOne(&testResult[i-1], i, timeLimit, spaceLimit, execCommand, execArgs)
}
// <-- step3 : write info
result, err := json.Marshal(testResult)
if err != nil {
panic(err)
}
if _, err := file.Write(result); err != nil {
panic(err)
}
os.Exit(0)
}