-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoTest.go
More file actions
120 lines (94 loc) · 3.29 KB
/
autoTest.go
File metadata and controls
120 lines (94 loc) · 3.29 KB
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
120
package main
import (
"flag"
"fmt"
"time"
//"io/ioutil"
"os"
"path/filepath"
"xmltest/btalkTest/TestEngine"
)
const (
DEFAULT_EXTENSION = "xml"
RESET_ITERATION = 100000
SLEEP_BETWEEN_TEST = 100 // milisecond
TIME_OUT_FOR_READ = 10
)
// DEBUG FLAGS
var DEBUG_COMPARE_POINTER bool = false
var DEBUG_COMPARE_SLICE bool = false
var DEBUG_COMPARE_STRUCT bool = false
var DEBUG_CLEANING_UP bool = false
var DEBUG_PARSING_MESSAGE bool = false
var DEBUG_SENDING_MESSAGE bool = false
var DEBUG_READING_MESSAGE bool = false
var DEBUG_IGNORING_MESSAGE bool = false
var DEBUG_CALLING_FUNC bool = false
var BYPASS_CONNECTION_SERVER bool = false
var timeOut int
var flagMap map[string]bool
// visit a file path
// if the file is a .xml (test file), call TestEngine to run the test
func visit(currentPath string, f os.FileInfo, err error) error {
fmt.Printf("Visited: %s\n", currentPath)
if !f.IsDir() {
var fileName = f.Name()
var strLen = len(fileName)
if strLen >= len(DEFAULT_EXTENSION) &&
fileName[strLen-len(DEFAULT_EXTENSION):strLen] == DEFAULT_EXTENSION {
// run file with extension "xml"
TestEngine.ExecuteTest(
flagMap,
currentPath, timeOut)
}
}
return err
}
func main() {
var inputDir string
var numIteration int
var sleepTime int
flag.StringVar(&inputDir, "inputDir", "TestCase", "The inputDir to be parsed")
flag.IntVar(&numIteration, "numItr", -1, "The number of iteration to run. Negative means infinite")
flag.BoolVar(&DEBUG_COMPARE_POINTER, "cmp_ptr", false, "Debug compare pointer")
flag.BoolVar(&DEBUG_COMPARE_SLICE, "cmp_slc", false, "Debug compare slice")
flag.BoolVar(&DEBUG_COMPARE_STRUCT, "cmp_str", false, "Debug compare struct")
flag.BoolVar(&DEBUG_CLEANING_UP, "clean", false, "Debug clean up")
flag.BoolVar(&DEBUG_PARSING_MESSAGE, "parse", false, "Debug parse messages")
flag.BoolVar(&DEBUG_READING_MESSAGE, "read", false, "Debug read messages")
flag.BoolVar(&DEBUG_SENDING_MESSAGE, "send", false, "Debug send messages")
flag.BoolVar(&DEBUG_IGNORING_MESSAGE, "ignore", false, "Debug ignore messages")
flag.BoolVar(&DEBUG_CALLING_FUNC, "func", false, "Debug calling function")
flag.BoolVar(&BYPASS_CONNECTION_SERVER, "bypass", false, "Bypass connection server")
flag.IntVar(&timeOut, "timeOut", TIME_OUT_FOR_READ, "The time (s) to wait when trying to read from server")
flag.IntVar(&sleepTime, "sleepTime", SLEEP_BETWEEN_TEST, "The time (ms) to wait between subsequent iterations")
flag.Parse()
flagMap = make(map[string]bool)
flagMap["cmpPtr"] = DEBUG_COMPARE_POINTER
flagMap["cmpSlc"] = DEBUG_COMPARE_SLICE
flagMap["cmpStr"] = DEBUG_COMPARE_STRUCT
flagMap["clean"] = DEBUG_CLEANING_UP
flagMap["parse"] = DEBUG_PARSING_MESSAGE
flagMap["send"] = DEBUG_SENDING_MESSAGE
flagMap["read"] = DEBUG_READING_MESSAGE
flagMap["ignore"] = DEBUG_IGNORING_MESSAGE
flagMap["func"] = DEBUG_CALLING_FUNC
flagMap["bypass"] = BYPASS_CONNECTION_SERVER
fmt.Println("List of debug flag:", flagMap)
fmt.Println("Input directory: ", inputDir)
iteration := 0
for {
if iteration == numIteration {
break
}
iteration++
fmt.Println("ITERATION NUMBER:", iteration)
root := inputDir
err := filepath.Walk(root, visit)
if err != nil {
fmt.Println(err)
}
sleepDuration, _ := time.ParseDuration(fmt.Sprintf("%dms", sleepTime))
time.Sleep(sleepDuration)
}
}