-
Notifications
You must be signed in to change notification settings - Fork 0
/
mbfasttest.py
401 lines (330 loc) · 11.4 KB
/
mbfasttest.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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/bin/env python3
from iceboot.iceboot_session import getParser
import codecs
import os
import sys
import platform
import datetime
import time
import fwswversion
import dacscan
import scope
import sensorcheck
import pulserCalib
import hvcheck
from addparser_iceboot import AddParser
import onboardsensor
def main():
parser = getParser()
scope.AddParser(parser)
(options, args) = parser.parse_args()
print (options.channel)
snum = options.mbsnum
if len(snum.split('/')) > 1:
print('Do not use "/" in the MB serial number. Exit.')
sys.exit(0)
date = datetime.date.today()
index = 1
prepath = f'results/FastTest/{snum}/{date}/Run'
path = f'{prepath}{index}'
while os.path.isdir(path):
index = index + 1
path = f'{prepath}{index}'
print(f'=== File path is: {path}. ===')
os.system(f'mkdir -p {path}')
makereport(parser,snum,path)
os.system(f'rm {path}/*.aux {path}/*.log')
def makereport(parser,snum,path='.'):
(options, args) = parser.parse_args()
ofilename = f'test_{snum}.tex'
ofpath = f'{path}/{ofilename}'
inforeport = getConfInfo(parser)
finalacc = 1
sensorreport, sensorbool = rep_sensor(parser)
i2csensorrep = rep_I2Csensor(parser,path)
finalacc *= sensorbool
dacscanreport, dacscanbool = rep_dacscan(parser,path)
finalacc *= dacscanbool
pulserreport = rep_pulser(parser,path)
f = codecs.open(ofpath,'w', 'utf-8')
f.write(preamble(parser,snum))
f.write(beginconts(finalacc))
### add contents below
f.write(inforeport)
f.write(sensorreport)
f.write(i2csensorrep)
f.write(dacscanreport)
f.write(pulserreport)
if int(options.hven)!=-1:
f.write(put_figures(snum,hvcheck.main(parser,path),path))
### above
f.write(endconts())
f.close()
os.system(f'pdflatex -output-directory {path} {ofilename}')
os.system(f'pdflatex -output-directory {path} {ofilename}')
PASS = r'''{\begin{center} \checkbox{black!30!green} PASS \hspace{2ex} \checkbox{white} FAIL \end{center}}'''
FAIL = r'''{\begin{center} \checkbox{white} PASS \hspace{2ex} \checkbox{red} FAIL \end{center}}'''
def rep_sensor(parser):
(options, args) = parser.parse_args()
thresMin, thresMax, out, outbool, citems, units = sensorcheck.main(parser)
SECTIONNAME = r'''\section{Slow Monitoring and Sensors}'''
CONTENTSBEGIN = r'''
\begin{table}[h]
\centering
\caption{Slow Monitoring ADC \& Sensors Test Summary.}
\begin{tabular}{lrclrc}
\toprule
SLO ADC or Sensor & \multicolumn{3}{c}{Criteria} & \multicolumn{1}{c}{Observed} & Acceptance \\
\midrule '''
omittest = [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0]
if int(options.hven) == 0: # HV0 enabled, HV1 disabled
omittest[8] = 0
omittest[9] = 0
elif int(options.hven) == 1: # HV0 disabled, HV1 enabled
omittest[10] = 0
omittest[11] = 0
elif int(options.hven) == 2: # HV0 enabled, HV1 enabled
omittest[8] = 0
omittest[9] = 0
omittest[10] = 0
omittest[11] = 0
result = 1
for i in range(len(out)):
criterion = citems[i] + ' & ' + str(thresMin[i] ) + r'''& \llap{$\leq$} $x$ \rlap{$\leq$}& ''' + str(thresMax[i] ) + ' & ' + str(out[i] ) + units[i] + ' & \judgemark{' + str(outbool[i] ) + '} '
CONTENTSBEGIN += criterion + r'''\\'''
if omittest[i]==0:
result *= outbool[i]
CONTENTSEND = r'''
\bottomrule
\end{tabular}
\end{table}
'''
CONTENTS = CONTENTSBEGIN + CONTENTSEND
if result==1:
CONTENTS = SECTIONNAME + PASS + CONTENTS
else:
CONTENTS = SECTIONNAME + FAIL + CONTENTS
return CONTENTS, result
def rep_I2Csensor(parser,path='testitems'):
axel, magn, pres, temp = onboardsensor.main(parser,path)
(options, args) = parser.parse_args()
meanmagn = magn[0][3]*1e9
errmmagn = magn[1][3]*1e9
CONTENTS = r'''
\begin{table}[h]
\centering
\caption{Mean outputs from I$^2$C sensors.}
\begin{tabular}{crcll}
\toprule
Sensor & \multicolumn{4}{c}{Observed Value} \\
\midrule
Accelerometer & ''' + f'{axel[0][3]:.4f}' + r' & \makebox[0pt][c]{$\pm$} & ' + f'{axel[1][3]:.4f}' + r''' & m$/$s$^2$ \\
Magnetometer & ''' + f'{meanmagn:.4f}' + r' & \makebox[0pt][c]{$\pm$} & ' + f'{errmmagn:.4f}' + r''' & nT\\
Pressure & ''' + f'{pres[0]:.4f}' + r' & \makebox[0pt][c]{$\pm$} & ' + f'{pres[1]:.4f}' + r''' & hPa \\
Temperature & ''' + f'{temp[0]:.4f}' + r' & \makebox[0pt][c]{$\pm$} & ' + f'{temp[1]:.4f}' + r''' & $^\circ$C \\
\bottomrule
\end{tabular}
\end{table} '''
return CONTENTS
def rep_pulser(parser,path='testitems'):
results, minvalues = pulserCalib.pulserCalib(parser,path)
(options, args) = parser.parse_args()
SECTIONNAME = r'''\section{AFE Pulser Calibration}'''
FIGURE = r'''
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw' + '''/PlsrCalibPlot.pdf}
\caption{AFE pulser calibration plot.}
\end{figure}
'''
FIGURE = FIGURE + r'''
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw' + '''/PlsrCalib_WF.pdf}
\caption{Waveform example with the FE pulse.}
\end{figure}
'''
CONTENTS = SECTIONNAME + FIGURE
return CONTENTS
def put_figures(snum,figurenames,path='testitems'):
if len(figurenames) < 4:
return ""
FIGURE = r'''
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw/{figurenames[0]}' + r'''}
\caption{''' + str(figurenames[1]) + r'''}
\end{figure}
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw/{figurenames[2]}' + r'''}
\caption{''' + str(figurenames[3]) + '''}
\end{figure}
'''
return FIGURE
def rep_dacscan(parser,path='testitems'):
results, minvalues = dacscan.dacscan(parser,path)
(options, args) = parser.parse_args()
SECTIONNAME = r'''\section{DAC Scan Result}'''
FIGURE = r'''
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw' + '''/DACscanPlot.pdf}
\caption{DAC scan plot.}
\end{figure}
'''
FIGURE2 = r'''
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw' + r'''/DACscanFFT0Plot.pdf}
\caption{Channel 0 FFT plot at the DAC value where the noise RMS is minimum. }
\end{figure}
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw' + r'''/DACscanFFT1Plot.pdf}
\caption{Channel 1 FFT plot at the DAC value where the noise RMS is minimum. }
\end{figure}
'''
FIGURE2 = FIGURE2 + r'''
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw' + r'''/DACscanMFFT0Plot.pdf}
\caption{Channel 0 FFT plot at the DAC value where the noise RMS is maximum. }
\end{figure}
\begin{figure}[h]
\centering
\includegraphics[width=.9\textwidth]{''' + f'{path}/raw' + r'''/DACscanMFFT1Plot.pdf}
\caption{Channel 1 FFT plot at the DAC value where the noise RMS is maximum. }
\end{figure}
'''
CONTENTS = ''
if len(results) != 2:
CONTENTS = SECTIONNAME + FAIL + 'COULDN\'T GET DATA...'
else:
result = results[0] * results[1]
TABLEBEGIN = r'''
\begin{table}[h]
\centering
\caption{DAC Scan Summary.}
\begin{tabular}{ccrc}
\toprule
ADC Ch\# & Criteria & \multicolumn{1}{c}{Min(Obs)} & Acceptance \\
\midrule '''
TABLEEND = r'''
\bottomrule
\end{tabular}
\end{table} '''
for i in range(2):
TABLEBEGIN += str(i) + '& Min(Obs) $<$ 2.5 &' + f'{minvalues[i]:.2f}' + '~[LSB] & \judgemark{' + str(results[i]) + r'''} \\'''
if result==1:
CONTENTS = SECTIONNAME + PASS + TABLEBEGIN + TABLEEND + FIGURE + FIGURE2
else:
CONTENTS = SECTIONNAME + FAIL + TABLEBEGIN + TABLEEND + FIGURE + FIGURE2
return CONTENTS, result
def getConfInfo(parser):
(options, args) = parser.parse_args()
isLoaded = 0
while isLoaded==0:
fwVer, swVer, flashLS, swid, fpgaId, flashId = fwswversion.main(parser)
print(f'{fpgaId}, {fpgaId!="0xffffffffffffffff"}')
if fpgaId!="0xffffffffffffffff":
isLoaded = 1
CONTENTS = r'''
\section{Test Configuration}
Successfully installed the firmware from the flash memory on the mainboard.
\begin{table}[h]
\centering
\caption{Test Configuration Summary.}
\begin{tabular}{ll}
\toprule
Contents & Values \\ \midrule '''
flashLSoutput = str(flashLS[len(flashLS)-1]['Name']).split('_')
fnameinflash = ''
for i in range(len(flashLSoutput)):
fnameinflash += flashLSoutput[i]
if i+1 < len(flashLSoutput):
fnameinflash += '\_'
ipcomments = ''
if str(options.host) != 'localhost':
ipcomments = 'Using Ethernet connection'
else:
ipcomments = 'Using Mini-FieldHub'
Names = ['Flash ID','FPGA Chip ID','Host IP Address', 'Port Number','FPGA FW Ver.', 'Iceboot SW Ver.']
Values = [str(flashId), str(fpgaId), f'{options.host}; {ipcomments}', str(options.port), f'0x{fwVer:x}; File: {fnameinflash}', f'{swVer:x}; ID: {swid}']
for i in range(len(Names)):
CONTENTS += f'{Names[i]} & {Values[i]}' + r' \\'
if i==1:
CONTENTS += r'''\midrule '''
hvcomments = ['HV0: Not connected, HV1: Not connected.','HV0: Connected, HV1: Not connected.', 'HV0: Not connected, HV1: Connected.', 'HV0: Connected, HV1: Connected.']
CONTENTS += r'''
\midrule
HV Boards & ''' + hvcomments[int(options.hven)+1] + r''' \\
Camera & Not connected. \\
\midrule
OS & '''
platformoutput = platform.platform().split('_')
for i in range(len(platformoutput)):
CONTENTS += platformoutput[i]
if i+1 < len(platformoutput):
CONTENTS += r'\_'
CONTENTS += r'''\\
Python Ver. & ''' + sys.version + r''' \\
Test Date & ''' + (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M:%S") + r''' \\
\bottomrule
\end{tabular}
\end{table}'''
return CONTENTS
def beginconts(result):
CONTENTS = r'''
\begin{document}
\maketitle
\thispagestyle{mypagestyle}
\begin{screen}\centering\Large \underline{FINAL ACCEPTANCE}
'''
if result==1:
CONTENTS = CONTENTS + PASS + '\end{screen}'
else:
CONTENTS = CONTENTS + FAIL + '\end{screen}'
return CONTENTS
def endconts():
CONTENTS = r'''
\end{document}
'''
return CONTENTS
def preamble(parser,snum):
(options, args) = parser.parse_args()
PREAMBLE = r'''
\documentclass[a4paper,11pt]{article}
\usepackage[vmargin={2.8cm,3cm}, hmargin=2.8cm]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{palatino}
\usepackage{mathpazo}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{ascmac}
\usepackage{fancybox}
\usepackage{booktabs}
\usepackage{ifthen}
\fancypagestyle{mypagestyle}{
\renewcommand{\headrulewidth}{0pt}
\lhead{\textit{MB} \#\underline{\ '''+ snum + r'''\ }}
\rhead{\textit{Date:}\underline{\ \today\ }}
\cfoot{\thepage\ / \pageref{LastPage}}
}
\pagestyle{mypagestyle}
\newcommand{\checkbox}[1]{\hspace{2ex}\fbox{\textcolor{#1}{\LARGE{\checkmark}}}}
\newcommand{\judgemark}[1]{\ifthenelse{\equal{#1}{1}}{\textcolor{black!30!green}{\textbf{PASS}}}{\textcolor{red}{\textbf{FAIL}}}}
\usepackage{afterpage,array,rotating}
\newcolumntype{Y}{>{\centering\arraybackslash}p{1ex}}
'''
TITLE = r'''
\title{\sffamily D-Egg Mainboard Fast-Test Report \\[1ex] for \#
\underline{\ ''' + snum + r'''\ }}'''
authorname = str(options.author)
AUTHOR = r'''
\author{Tested by: '''+ authorname + '}'
return PREAMBLE + TITLE + AUTHOR
if __name__ == "__main__":
main()