-
Notifications
You must be signed in to change notification settings - Fork 0
/
registerTest.py
248 lines (199 loc) · 9.21 KB
/
registerTest.py
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import os
import sys
import json
import time
from optparse import OptionParser
import uuid
import ngFECSendCommand as sendCommands
import logging
host = 'localhost'
from registerTest_setDefaults import registerTest_setDefaults_bridge
from registerTest_setDefaults import registerTest_setDefaults_igloo
from registerTest_setDefaults import registerTest_setDefaults_qie
from registerTest_ro import registerTest_ro_bridge
from registerTest_ro import registerTest_ro_igloo
#from registerTest_ro import registerTest_ro_qie
from registerTest_rw import registerTest_rw_bridge
from registerTest_rw import registerTest_rw_igloo
from registerTest_rw import registerTest_rw_qie
def writeToCmdLog(output, cmdlogfile):
for item in output:
cmdlogfile.write("%s\n" % item)
def makeOutputPath(uID):
extension = 1
while os.path.exists( "/home/hcalpro/DATA/RegTestResults/{0}_v{1}/".format(uID, extension) ):
extension += 1
while os.path.exists( "./registerTestResults/{0}_v{1}/".format(uID, extension) ):
extension += 1
path = "./registerTestResults/{0}_v{1}/".format(uID, extension)
return path
def backplanereset(crate, halfback, port):
logger = logging.getLogger(__name__)
logger.info('resetting backplane {0}{1}'.format(crate,halfback))
cmds = []
cmds.append('put HB{0}{1}-bkp_pwr_enable 1'.format(crate,halfback))
cmds.append('put HB{0}{1}-bkp_reset 1'.format(crate,halfback))
cmds.append('put HB{0}{1}-bkp_reset 0'.format(crate,halfback))
output = sendCommands.send_commands(cmds=cmds, script=False, port=port, control_hub=host)
for entry in output:
result = entry['result']
if not 'OK' in result:
logger.critical('trouble with put command: {0}'.format(entry))
writeToCmdLog(output, cmdlogfile)
sys.exit()
return output
def checktemp(crate, rm, slot, port):
logger = logging.getLogger(__name__)
logger.info('checking the bridge temperature')
cmds = []
cmds.append('get HB{0}-{1}-{2}-B_SHT_temp_f'.format(crate, rm, slot))
output = sendCommands.send_commands(cmds=cmds, script=True, port=port, control_hub=host)
for entry in output:
result = entry['result']
if "ERROR" in result:
logger.critical('trouble with get command: {0}'.format(output[0]))
writeToCmdLog(output, cmdlogfile)
sys.exit()
temp = result.split()
logger.info('bridge has temperature: {0}'.format(temp[0]))
return output
def checkid(crate, rm, slot, port):
logger = logging.getLogger(__name__)
logger.info('checking UniqueID')
cmds = []
cmds.append('get HB{0}-{1}-{2}-UniqueID'.format(crate, rm, slot))
output = sendCommands.send_commands(cmds=cmds, script=True, port=port, control_hub=host)
for entry in output:
result = entry['result']
if "ERROR" in result:
logger.critical('trouble with get command: {0}'.format(output[0]))
writeToCmdLog(output, cmdlogfile)
sys.exit()
uID = output[0]['result']
uID = uID.split(" ")
uID = uID[1]+"_"+uID[2]
logger.info('UniqueID is: {0}'.format(uID))
return output, uID
if __name__ == "__main__":
parser = OptionParser()
parser.add_option("-p", "--port", dest="port", default = 64000, type = "int", help = "port needed for server")
parser.add_option("-n", "--num", dest="n", default = 5, type = "int", help = "number of interations")
parser.add_option("-S", "--side", dest="side", default = "", type = "str", help = "which half backplane")
parser.add_option("-c", "--crate", dest="c", default = -1, type = "int", help = "crate number")
parser.add_option("-r", "--rm", dest="r", default = -1, type = "int", help = "readout module number")
parser.add_option("-s", "--slot", dest="s", default = -1, type = "int", help = "slot number within the readout module")
parser.add_option("-t", "--tester",dest="t", default = "hcaldaq",type= "str", help = "name of person running tests")
parser.add_option("-C", "--comments",dest="C", default = "n/a", type = "str", help = "comments provided by tester")
(options, args) = parser.parse_args()
port = options.port
n = options.n
halfp = options.side
tester_name = options.t
test_comments = options.C
print tester_name
print test_comments
crate = options.c
if not (crate>-1):
logger.critical('specify a crate number!')
logger.critical('required registerTest options: python registerTest.py --crate X --readoutmodule Y --slot Z')
sys.exit()
rm = options.r
if not (rm==1 or rm==2 or rm==3 or rm==4):
logger.critical('specify a proper readout module number!')
logger.critical('required registerTest options: python registerTest.py --crate X --readoutmodule Y --slot Z')
sys.exit()
slot = options.s
if not (slot==1 or slot==2 or slot==3 or slot==4):
logger.critical('specify a proper slot number!')
logger.critical('required registerTest options: python registerTest.py --crate X --readoutmodule Y --slot Z')
sys.exit()
tempname = str(uuid.uuid4())
templogname = "{0}.runlog.tmp".format(tempname)
logging.basicConfig(filename=templogname, level=logging.DEBUG)
console = logging.StreamHandler()
console.setLevel(logging.INFO)
logging.getLogger('').addHandler(console)
logger = logging.getLogger(__name__)
logger.info("##########")
logger.info('your temporary run log: ./{0}'.format(templogname))
logger.info(time.ctime(time.time()))
logger.info('begin crate {0}, rm {1}, slot {2}'.format(crate, rm, slot))
# log all commands
tempcmdlogname = "{0}.cmdlog.tmp".format(tempname)
cmdlogfile = open(tempcmdlogname, 'w+')
logger.info('your temporary command log: ./{0}'.format(tempcmdlogname))
# reset the backplane
#output = []
#if (rm==1 or rm==2):
# output = backplanereset(crate, "")
#elif (rm==3 or rm==4):
# output = backplanereset(crate, "")
output = backplanereset(crate, halfp, port)
writeToCmdLog(output, cmdlogfile)
# check the temperature sensor
output = checktemp(crate, rm, slot, port)
writeToCmdLog(output, cmdlogfile)
# check for the unique id
output, uID = checkid(crate, rm, slot, port)
writeToCmdLog(output, cmdlogfile)
outputPath = makeOutputPath(uID)
os.makedirs(outputPath)
# rename test log file to have uID in name
runlog_fname = outputPath+"run.log"
os.rename(templogname, runlog_fname)
logger.info('the run log file has been renamed: {0}'.format(runlog_fname))
# rename command log file to have uID in name
runcmdlog_fname = outputPath+"cmd.log"
os.rename(tempcmdlogname, runcmdlog_fname)
logger.info('the command log file has been renamed: {0}'.format(runcmdlog_fname))
# set defaults
output, pass_setDefaults_bridge = registerTest_setDefaults_bridge(crate, rm, slot, port)
writeToCmdLog(output, cmdlogfile)
output, pass_setDefaults_igloo = registerTest_setDefaults_igloo(crate, rm, slot, port)
writeToCmdLog(output, cmdlogfile)
output, pass_setDefaults_qie = registerTest_setDefaults_qie(crate, rm, slot, port)
writeToCmdLog(output, cmdlogfile)
# run bridge tests
output, pass_ro_bridge, per_reg_pass_ro_bridge = registerTest_ro_bridge(crate, rm, slot, port, n)
writeToCmdLog(output, cmdlogfile)
output, pass_rw_bridge, per_reg_pass_rw_bridge = registerTest_rw_bridge(crate, rm, slot, port, n)
writeToCmdLog(output, cmdlogfile)
output, pass_setDefaults_bridge = registerTest_setDefaults_bridge(crate, rm, slot, port)
writeToCmdLog(output, cmdlogfile)
# run igloo tests
output, pass_ro_igloo, per_reg_pass_ro_iTop, per_reg_pass_ro_iBot = registerTest_ro_igloo(crate, rm, slot, port, n)
writeToCmdLog(output, cmdlogfile)
output, pass_rw_igloo, per_reg_pass_rw_igloo = registerTest_rw_igloo(crate, rm, slot, port, n)
writeToCmdLog(output, cmdlogfile)
output, pass_setDefaults_igloo = registerTest_setDefaults_igloo(crate, rm, slot, port)
writeToCmdLog(output, cmdlogfile)
# run qie tests
#output, pass_ro_qie = registerTest_ro_qie(crate, rm, slot)
#writeToCmdLog(output, cmdlogfile)
output, pass_rw_qie, per_reg_pass_rw_qie = registerTest_rw_qie(crate, rm, slot, port, n)
writeToCmdLog(output, cmdlogfile)
output, pass_setDefaults_qie = registerTest_setDefaults_qie(crate, rm, slot, port)
writeToCmdLog(output, cmdlogfile)
testresults = {
"uID" : uID,
#"bridge_ro" : int(pass_ro_bridge),
#"bridge_rw" : int(pass_rw_bridge),
#"igloo_ro" : int(pass_ro_igloo),
#"igloo_rw" : int(pass_rw_igloo),
#"#qie_rw" : int(pass_rw_qie),
"Comments" : test_comments,
"Tester_Name" : tester_name
}
testresults.update(per_reg_pass_ro_bridge)
testresults.update(per_reg_pass_rw_bridge)
testresults.update(per_reg_pass_ro_iTop)
testresults.update(per_reg_pass_ro_iBot)
testresults.update(per_reg_pass_rw_igloo)
testresults.update(per_reg_pass_rw_qie)
with open(outputPath+"results.json", 'w') as testresultsfile:
json.dump(testresults, testresultsfile)
#testresultsfile.write(str(testresults))
logger.info('the test results have been saved as {0}results.log'.format(outputPath))
logger.info('finished crate {0}, rm {1}, slot {2}'.format(crate, rm, slot))
logger.info(time.ctime(time.time()))
logger.info("##########")