-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.rb
197 lines (126 loc) · 4.62 KB
/
run.rb
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#! /usr/local/bin/ruby
utfroot=File.dirname(File.expand_path(__FILE__))
ENV["UTFROOT"]=utfroot
ENV["UTFGLOBALFILE"]=utfroot+"/test/_global.conf"
ENV["LOGFILE"]=utfroot+"/log/test.log"
$LOAD_PATH << ENV["UTFROOT"]+"/lib"
require 'optparse'
load "log.rb"
load "utf.rb"
#--------- Start of parse option
options = {}
optparse = OptionParser.new do|opts|
opts.on( '-h', '--help', 'Display this screen' ) { puts opts; UTF.showExample(); exit }
options[:testGroup] = []
opts.on( '-s', '--testsuite ts1,ts2,ts3', Array, "run tests suite" ){|tg| options[:testGroup] = tg }
options[:testCase] = []
opts.on( '-t', '--testcase tc1,tc2,tc3', Array, "run test cases" ){|t| options[:testCase] = t }
options[:runConf] = []
opts.on( '-f', '--runconf ', "run xml configuration file" ){|f| options[:runConf] = f }
options[:verbose] = :basic
opts.on( '-v', '--verbose OPT [basic, verbose, veryverbose]', [:basic, :verbose, :veryverbose],'verbose output Level' ) {|v| options[:verbose] = v }
# opts.on( '-v', '--verbose', 'verbose display' ) { options[:verbose] = verbose }
# opts.on( '-z', '--veryverbose', 'very verbose display' ) { options[:verbose] = veryverbose }
options[:pcapenable] = false
opts.on( '-p', '--pcap', 'enable pacp' ) { options[:pcapenable] = true }
options[:listSuite] = false
opts.on( '-g', '--listSuite', "List TestSuite" ) { options[:listSuite] = true }
options[:listCase] = false
opts.on( '-c', '--listCase', "List TestCase" ) { options[:listCase] = true }
end
begin
optparse.parse!
rescue
LOG.colorPuts("command syntax not correct, see usage")
system(" #{__FILE__} -h")
exit
end
#p options
if !(options[:runConf].empty?) and !(options[:testGroup].empty?)
LOG.warn("basic", "runConf and testGroup can NOT show at same time")
exit
end
if !(options[:runConf].empty?) and !(options[:testCase].empty?)
LOG.warn("basic", "runConf and testCase can NOT show at same time")
exit
end
if !(options[:testCase].empty?) and options[:testGroup].empty? and (options[:runConf].empty?)
LOG.warn("basic", "need specify testGroup or using runConf")
exit
end
tGLength=options[:testGroup].length
if !(options[:testCase].empty?) and tGLength > 1
LOG.warn("basic", "You specified #{tGLength} test group with testCae. \nOnly 1 testGroup in CLI supported when run testCase, \n using -f runConf or testGroup only to run whole testSuite")
exit
end
(UTF.listTestSuite();exit) if options[:listSuite]
(testsuite=UTF.getTestSuite() ; testsuite.each{|ts| UTF.listTestCase(ts) }; exit ) if options[:listCase]
options[:pcapenable] ? ENV["pcapenable"]="yes" : ENV["pcapenable"]="no"
case options[:verbose].to_s
when "basic"
ENV["LOGLEVEL"]="basic"
when "verbose"
ENV["LOGLEVEL"]="verbose"
when "veryverbose"
ENV["LOGLEVEL"]="veryverbose"
else
ENV["LOGLEVEL"]="basic"
end
(system(" #{__FILE__} -h") ;exit) if (options[:testGroup].empty? \
and options[:testCase].empty? and !options[:listSuite] \
and options[:runConf].empty? \
and !options[:listCase] )
testSCStatus=true
options[:testGroup].each{|tg|
s= UTF.checkTestSuiteExist(tg)
testSCStatus= (testSCStatus and s)
} #
exit if !testSCStatus
tcrunArr=[]
tcrunHash={}
if options[:runConf].empty?
if options[:testCase].empty? #if no testcase gave in cli, puts all testsuite.
options[:testGroup].each{|tg|
tcrunHash[tg] = UTF.getTestCase(tg)
}
else
options[:testCase].each{|tc| tcrunArr<<tc}
tcrunHash[options[:testGroup][0]] = tcrunArr # #cmd line only accept 1 test suite with test case
end
end
if !(options[:runConf].empty?)
tcrunHash=UTF.parseRunXML(options[:runConf])
end
testSCStatus=true
tcrunHash.each{|tsname,tcarr|
s= UTF.checkTestSuiteExist(tsname)
testSCStatus= (testSCStatus and s)
tcarr.each{|tcname| s=UTF.checkTestCaseExist(tsname,tcname)
testSCStatus=(testSCStatus and s)
}
} #
exit if !testSCStatus
tcrunHash.each{|key,value|
print "Will Run Suite: " ; LOG.msg("basic", "#{key}")
value.each{|tcname| puts "\t#{tcname}" }
} #
#p tcrunHash
#exit
tcrunHash.each{|keyTS,valueTC|
tcrunHash[keyTS].uniq.each{ |tc|
#begin
testscript="#{ENV["UTFROOT"]}/test/#{keyTS}/#{tc}"
if File.exist?(testscript)
#p "run #{testscript}"
#system("ruby #{testscript}")
TC.run(testscript)
else
LOG.warn("basic", "#{tc}, no such file #{testscript} ")
end
#rescue
# puts "error run #{tc}"
#end
}#tcarr.uniq.each{ |tc|
} #tcrunHash.each{|key,value}
exit
#--------- End of parse option