-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
119 lines (101 loc) · 2.11 KB
/
main.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"flag"
"fmt"
"os"
"os/signal"
)
// func main_old() {
// var i int
// fmt.Scanf("%d", &i)
// cmd := chord.NewNodeConsole(int32(i))
// cmd.Run()
// }
var (
help bool
version bool
level int
nointerrupt bool
)
func init() {
flag.BoolVar(&help, "h", false, "give help")
flag.BoolVar(&version, "v", false, "version")
flag.BoolVar(&nointerrupt, "n", false, "can not use ctrl-c to interrupt program")
flag.IntVar(&level, "l", -2, "levels of tests(0 for all, 1 for advanced)")
flag.Usage = usage
flag.Parse()
fmt.Println("ppca-dht 2019-7 v0.0.1")
if help {
flag.Usage()
os.Exit(0)
}
if version {
os.Exit(0)
}
if level == -2 {
os.Exit(0)
}
if nointerrupt {
go func() {
for {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
s := <-c
fmt.Println("Got signal:", s)
}
}()
}
}
func failrate() float64 {
return float64(totalFail) / float64(totalCnt)
}
func main() {
green.Println("Start Testing")
finalScore = 0
switch level {
case -1:
naiveTest()
totalCnt = 0
totalFail = 0
case 0:
blue.Println("Start Standard Tests")
if standardTest(); maxFail > failrate() {
green.Println("Passed Standard Tests with", failrate())
} else {
red.Println("Failed Standard Tests")
os.Exit(0)
}
finalScore += failrate()
totalCnt = 0
totalFail = 0
fallthrough
case 1:
blue.Println("Start Advanced Tests")
if advancedTest(); maxFail > failrate() {
green.Println("Passed Advanced Tests with", failrate())
} else {
red.Println("Failed Advanced Tests")
// os.Exit(0)
}
totalCnt = 0
totalFail = 0
blue.Println("Start Force Quit Tests")
if testForceQuit(2); maxFail > failrate()/50 {
green.Println("Passed Force Quit with", failrate())
} else {
red.Println("Failed Advanced Tests")
os.Exit(0)
}
finalScore += failrate()
default:
red.Print("Select error, ask -h for help")
os.Exit(0)
}
green.Printf("\nNot necessary, but tell finall score: %.2f\n", 1-finalScore)
}
func usage() {
fmt.Fprintf(os.Stderr, `Usage: ppca-dht [-h help] [-v version] [-a addition-test]
Options:
`)
flag.PrintDefaults()
}