-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathReportBuildDict2Html.tcl
452 lines (405 loc) · 17.5 KB
/
ReportBuildDict2Html.tcl
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File Name: ReportBuildDict2Html.tcl
# Purpose: Convert OSVVM YAML build reports to HTML
# Revision: OSVVM MODELS STANDARD VERSION
#
# Maintainer: Jim Lewis email: jim@synthworks.com
# Contributor(s):
# Jim Lewis email: jim@synthworks.com
#
# Description
# Convert OSVVM Build Dictionary into HTML Build Report
# Visible externally: ReportBuildDict2Html
# Must call ReportBuildYaml2Dict first.
#
# Developed by:
# SynthWorks Design Inc.
# VHDL Training Classes
# OSVVM Methodology and Model Library
# 11898 SW 128th Ave. Tigard, Or 97223
# http://www.SynthWorks.com
#
# Revision History:
# Date Version Description
# 07/2024 2024.07 Handling for GenericDict and naming updates.
# 05/2024 2024.05 Refactored. Must call ReportBuildYaml2Dict first.
# 04/2024 2024.04 Updated report formatting
# 07/2023 2023.07 Updated file handler to search for user defined HTML headers
# 12/2022 2022.12 Refactored to only use static OSVVM information
# 05/2022 2022.05 Updated directory handling
# 02/2022 2022.02 Added links for code coverage.
# 10/2021 Initial Initial Revision
#
#
# This file is part of OSVVM.
#
# Copyright (c) 2021 - 2024 by SynthWorks Design Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package require yaml
# Notes:
# The following variables are set by GetPathSettings that read the YAML file
# Report2HtmlThemeDirectory
# Report2BaseDirectory
# Report2ReportsSubdirectory
# Report2LogSubdirectory
# Report2HtmlThemeSourceDirectory
# Report2RequirementsSubdirectory - value is "" if requirements not used
# Report2CoverageSubdirectory - value is "" if coverage not used
#
# -------------------------------------------------
# ReportBuildDict2Html
#
proc ReportBuildDict2Html {} {
variable ResultsFile
variable ReportFileRoot
# Open results file
set ResultsFile [open ${ReportFileRoot}.html w]
# Convert YAML file to HTML & catch results
set ErrorCode [catch {LocalReportBuildDict2Html} errmsg]
# Close Results file - done here s.t. it is closed even if it fails
close $ResultsFile
if {$ErrorCode} {
CallbackOnError_ReportBuildDict2Html ${ReportFileRoot}.html $errmsg
}
}
# -------------------------------------------------
# LocalReportBuildDict2Html
#
proc LocalReportBuildDict2Html {} {
variable ResultsFile
variable ReportBuildName
variable BuildDict
CreateOsvvmReportHeader $ResultsFile "$ReportBuildName Build Report"
CreateHtmlSummary $BuildDict
CreateTestSuiteSummary
CreateTestCaseSummaries $BuildDict
CreateOsvvmReportFooter $ResultsFile
}
# -------------------------------------------------
# CreateHtmlSummary
#
proc CreateHtmlSummary {TestDict} {
variable ResultsFile
variable ReportBuildName
variable ReportBuildErrorCode
variable ReportAnalyzeErrorCount
variable ReportSimulateErrorCount
variable BuildStatus
variable ReportStartTime
variable ReportFinishTime
variable ElapsedTimeSeconds
variable ElapsedTimeSecondsInt
variable ElapsedTimeHms
variable ReportSimulator
variable ReportSimulatorVersion
variable OsvvmVersion
variable RequirementsRelativeHtml
variable TestCasesPassed
variable TestCasesFailed
variable TestCasesSkipped
variable TestCasesRun
set PassedClass ""
set FailedClass ""
set SkippedClass ""
if { ${BuildStatus} eq "PASSED" } {
set StatusClass "class=\"passed\""
set PassedClass "class=\"passed\""
} elseif { ${BuildStatus} eq "FAILED" } {
set StatusClass "class=\"failed\""
set FailedClass "class=\"failed\""
} else {
set StatusClass "class=\"skipped\""
set SkippedClass "class=\"skipped\""
}
if {$ReportAnalyzeErrorCount} {
set AnalyzeClass "class=\"failed\""
} else {
set AnalyzeClass ""
}
if {$ReportSimulateErrorCount} {
set SimulateClass "class=\"failed\""
} else {
set SimulateClass ""
}
puts $ResultsFile " <div class=\"summary-parent\">"
puts $ResultsFile " <div class=\"summary-table\">"
puts $ResultsFile " <table class=\"summary-table\">"
puts $ResultsFile " <thead>"
puts $ResultsFile " <tr class=\"column-header\"><th>Build</th> <th>$ReportBuildName</th></tr>"
puts $ResultsFile " </thead>"
puts $ResultsFile " <tbody>"
puts $ResultsFile " <tr ${StatusClass}><td>Status</td> <td>$BuildStatus</td></tr>"
puts $ResultsFile " <tr ${PassedClass}><td>PASSED</td> <td>$TestCasesPassed</td></tr>"
puts $ResultsFile " <tr ${FailedClass}><td>FAILED</td> <td>$TestCasesFailed</td></tr>"
puts $ResultsFile " <tr ${SkippedClass}><td>SKIPPED</td> <td>$TestCasesSkipped</td></tr>"
puts $ResultsFile " <tr ${AnalyzeClass}><td>Analyze Failures</td> <td>$ReportAnalyzeErrorCount</td></tr>"
puts $ResultsFile " <tr ${SimulateClass}><td>Simulate Failures</td> <td>$ReportSimulateErrorCount</td></tr>"
# Print BuildInfo
if {$ReportStartTime ne ""} {
puts $ResultsFile " <tr><td>Start Time</td> <td>$ReportStartTime</td></tr>"
}
if {$ReportFinishTime ne ""} {
puts $ResultsFile " <tr><td>Finish Time</td> <td>$ReportFinishTime</td></tr>"
}
puts $ResultsFile " <tr><td>Elapsed Time (h:m:s)</td> <td>$ElapsedTimeHms</td></tr>"
puts $ResultsFile " <tr><td>Simulator (Version)</td> <td>${ReportSimulator} ($ReportSimulatorVersion)</td></tr>"
if {$OsvvmVersion ne ""} {
puts $ResultsFile " <tr><td>OSVVM Version</td> <td>$OsvvmVersion</td></tr>"
}
if {$::osvvm::Report2SimulationLogFile ne ""} {
puts $ResultsFile " <tr><td>Simulation Transcript</td><td><a href=\"${::osvvm::Report2SimulationLogFile}\">${ReportBuildName}.log</a></td></tr>"
}
if {$::osvvm::Report2SimulationHtmlLogFile ne ""} {
puts $ResultsFile " <tr><td>HTML Simulation Transcript</td><td><a href=\"${::osvvm::Report2SimulationHtmlLogFile}\">${ReportBuildName}_log.html</a></td></tr>"
}
if {$RequirementsRelativeHtml ne ""} {
puts $ResultsFile " <tr><td>Requirements Summary</td><td><a href=\"${RequirementsRelativeHtml}\">[file tail $RequirementsRelativeHtml]</a></td></tr>"
}
if {$::osvvm::Report2CoverageSubdirectory ne ""} {
puts $ResultsFile " <tr><td>Code Coverage</td><td><a href=\"${::osvvm::Report2CoverageSubdirectory}\">Code Coverage Results</a></td></tr>"
}
puts $ResultsFile " </tbody>"
puts $ResultsFile " </table>"
puts $ResultsFile " </div>"
LinkLogoFile $ResultsFile
puts $ResultsFile " </div>"
}
# -------------------------------------------------
# CreateTestSuiteSummary
#
proc CreateTestSuiteSummary {} {
variable HaveTestSuites
variable TestSuiteSummaryArrayOfDictionaries
variable ResultsFile
variable ReportBuildName
if { $HaveTestSuites } {
puts $ResultsFile " <div class=\"testsuite\">"
puts $ResultsFile " <details open=\"open\" class=\"testsuite-details\"><summary>Test Suite Summary</summary>"
puts $ResultsFile " <table class=\"testsuite-summary-table\">"
puts $ResultsFile " <thead>"
puts $ResultsFile " <tr><th rowspan=\"2\">TestSuites</th>"
puts $ResultsFile " <th rowspan=\"2\">Status</th>"
puts $ResultsFile " <th colspan=\"3\">Test Cases</th>"
puts $ResultsFile " <th rowspan=\"2\">Requirements<br>passed / goal</th>"
puts $ResultsFile " <th rowspan=\"2\">Disabled<br>Alerts</th>"
puts $ResultsFile " <th rowspan=\"2\">Elapsed<br>Time</th>"
puts $ResultsFile " </tr>"
puts $ResultsFile " <tr>"
puts $ResultsFile " <th>PASSED </th>"
puts $ResultsFile " <th>FAILED </th>"
puts $ResultsFile " <th>SKIPPED</th>"
puts $ResultsFile " </tr>"
puts $ResultsFile " </thead>"
puts $ResultsFile " <tbody>"
foreach TestSuite $TestSuiteSummaryArrayOfDictionaries {
set SuiteName [dict get $TestSuite Name]
set SuiteStatus [dict get $TestSuite Status]
set PassedClass ""
set FailedClass ""
if { ${SuiteStatus} eq "PASSED" } {
set StatusClass "class=\"passed\""
set PassedClass "class=\"passed\""
} elseif { ${SuiteStatus} eq "FAILED" } {
set StatusClass "class=\"failed\""
set FailedClass "class=\"failed\""
} else {
set StatusClass "class=\"skipped\""
}
puts $ResultsFile " <tr>"
puts $ResultsFile " <td><a href=\"#${SuiteName}\">${SuiteName}</a></td>"
puts $ResultsFile " <td ${StatusClass}>$SuiteStatus</td>"
puts $ResultsFile " <td ${PassedClass}>[dict get $TestSuite PASSED] </td>"
puts $ResultsFile " <td ${FailedClass}>[dict get $TestSuite FAILED] </td>"
puts $ResultsFile " <td>[dict get $TestSuite SKIPPED]</td>"
set RequirementRelativeHtml [file join $::osvvm::Report2RequirementsSubdirectory $ReportBuildName ${SuiteName}_req.html]
set RequirementsHtml [file join $::osvvm::Report2BaseDirectory $RequirementRelativeHtml]
set ReqGoal [dict get $TestSuite ReqGoal]
set ReqPassed [dict get $TestSuite ReqPassed]
if {[file exists $RequirementsHtml]} {
puts $ResultsFile " <td><a href=\"${RequirementRelativeHtml}\">$ReqPassed / $ReqGoal</a></td>"
} else {
if {($ReqGoal > 0) || ($ReqPassed > 0)} {
puts $ResultsFile " <td>$ReqPassed / $ReqGoal</td>"
} else {
puts $ResultsFile " <td>⸻</td>"
}
}
puts $ResultsFile " <td>[dict get $TestSuite DisabledAlerts]</td>"
puts $ResultsFile " <td>[dict get $TestSuite ElapsedTime]</td>"
puts $ResultsFile " </tr>"
}
puts $ResultsFile " </tbody>"
puts $ResultsFile " </table>"
puts $ResultsFile " </details>"
puts $ResultsFile " </div>"
}
}
# -------------------------------------------------
# CreateTestCaseSummaries
#
proc CreateTestCaseSummaries {TestDict} {
variable ResultsFile
if { [dict exists $TestDict TestSuites] } {
foreach TestSuite [dict get $TestDict TestSuites] {
set SuiteName [dict get $TestSuite Name]
puts $ResultsFile " <div class=\"testcase\">"
puts $ResultsFile " <details open><summary id=\"$SuiteName\">$SuiteName Test Case Summary</summary>"
puts $ResultsFile " <table class=\"testcase-summary-table\">"
puts $ResultsFile " <thead>"
puts $ResultsFile " <tr><th rowspan=\"2\">Test Case</th>"
puts $ResultsFile " <th rowspan=\"2\">Status</th>"
puts $ResultsFile " <th colspan=\"3\">Checks</th>"
puts $ResultsFile " <th colspan=\"2\">Requirements</th>"
puts $ResultsFile " <th rowspan=\"2\">Functional<br>Coverage</th>"
puts $ResultsFile " <th rowspan=\"2\">Disabled<br>Alerts</th>"
puts $ResultsFile " <th rowspan=\"2\">Elapsed<br>Time</th>"
puts $ResultsFile " </tr>"
puts $ResultsFile " <tr>"
puts $ResultsFile " <th>Total</th>"
puts $ResultsFile " <th>Passed</th>"
puts $ResultsFile " <th>Failed</th>"
puts $ResultsFile " <th>Goal</th>"
puts $ResultsFile " <th>Passed</th>"
puts $ResultsFile " </tr>"
puts $ResultsFile " </thead>"
puts $ResultsFile " <tbody>"
set ReportsDirectory [file join $::osvvm::Report2ReportsSubdirectory $SuiteName]
foreach TestCase [dict get $TestSuite TestCases] {
set TestName [dict get $TestCase TestCaseName]
if { [dict exists $TestCase Status] } {
set TestStatus [dict get $TestCase Status]
set TestResults [dict get $TestCase Results]
if { $TestStatus eq "SKIPPED" } {
set TestReport "NONE"
set Reason [dict get $TestResults Reason]
} else {
set TestReport "REPORT"
set VhdlName [dict get $TestCase Name]
}
} elseif { ![dict exists $TestCase FunctionalCoverage] } {
set TestReport "NONE"
set TestStatus "FAILED"
set Reason "Simulate Did Not Run"
} else {
set TestReport "NONE"
set TestStatus "FAILED"
set Reason "No VHDL Results. Test did not call EndOfTestReports"
}
set PassedClass ""
set FailedClass ""
if { ${TestReport} eq "REPORT"} {
if { ${TestName} ne ${VhdlName} } {
set TestStatus "NAME_MISMATCH"
set StatusClass "class=\"warning\""
set PassedClass "class=\"warning\""
set FailedClass "class=\"warning\""
} elseif { ${TestStatus} eq "PASSED" } {
set StatusClass "class=\"passed\""
set PassedClass "class=\"passed\""
} else {
set StatusClass "class=\"failed\""
set FailedClass "class=\"failed\""
}
} else {
if { ${TestStatus} eq "SKIPPED" } {
set StatusClass "class=\"skipped\""
set PassedClass "class=\"skipped\""
set FailedClass "class=\"skipped\""
} else {
set StatusClass "class=\"failed\""
set FailedClass "class=\"failed\""
}
}
if { [dict exists $TestCase TestCaseFileName] } {
set TestFileName [dict get $TestCase TestCaseFileName]
} else {
set TestFileName $TestName
}
set TestCaseHtmlFile [file join ${ReportsDirectory} ${TestFileName}.html]
set TestCaseName $TestName
if { [dict exists $TestCase Generics] } {
set TestCaseGenerics [dict get $TestCase Generics]
if {${TestCaseGenerics} ne ""} {
set GenericValueList [dict values $TestCaseGenerics]
set i 0
set ListLen [llength ${GenericValueList}]
append TestCaseName " ("
foreach GenericValue $GenericValueList {
incr i
if {$i != $ListLen} {
append TestCaseName $GenericValue " ,"
} else {
append TestCaseName $GenericValue ")"
}
}
}
}
puts $ResultsFile " <tr>"
puts $ResultsFile " <td><a href=\"${TestCaseHtmlFile}\">${TestCaseName}</a></td>"
puts $ResultsFile " <td ${StatusClass}>$TestStatus</td>"
if { $TestReport eq "REPORT" } {
puts $ResultsFile " <td ${PassedClass}>[dict get $TestResults AffirmCount]</td>"
puts $ResultsFile " <td ${PassedClass}>[dict get $TestResults PassedCount]</td>"
puts $ResultsFile " <td ${FailedClass}>[dict get $TestResults TotalErrors]</td>"
set RequirementsGoal [dict get $TestResults RequirementsGoal]
set RequirementsPassed [dict get $TestResults RequirementsPassed]
if {($RequirementsGoal > 0) || ($RequirementsPassed > 0)} {
puts $ResultsFile " <td>$RequirementsGoal</td>"
puts $ResultsFile " <td>$RequirementsPassed</td>"
} else {
puts $ResultsFile " <td>⸻</td>"
puts $ResultsFile " <td>⸻</td>"
}
if { [dict exists $TestCase FunctionalCoverage] } {
set FunctionalCov [dict get $TestCase FunctionalCoverage]
} else {
set FunctionalCov ""
}
if { ${FunctionalCov} ne "" } {
puts $ResultsFile " <td><a href=\"${TestCaseHtmlFile}#FunctionalCoverage\">${FunctionalCov}</a></td>"
} else {
puts $ResultsFile " <td>⸻</td>"
}
puts $ResultsFile " <td>[SumAlertCount [dict get $TestResults DisabledAlertCount]]</td>"
if {[dict exists $TestCase ElapsedTime]} {
set TestCaseElapsedTime [dict get $TestCase ElapsedTime]
} else {
set TestCaseElapsedTime missing
}
puts $ResultsFile " <td>$TestCaseElapsedTime</td>"
} else {
puts $ResultsFile " <td style=\"text-align: left\" colspan=\"8\">   $Reason</td>"
}
puts $ResultsFile " </tr>"
}
puts $ResultsFile " </tbody>"
puts $ResultsFile " </table>"
puts $ResultsFile " </details>"
puts $ResultsFile " </div>"
}
}
}
# -------------------------------------------------
# SumAlertCount
#
proc SumAlertCount {AlertCountDict} {
return [expr [dict get $AlertCountDict Failure] + [dict get $AlertCountDict Error] + [dict get $AlertCountDict Warning]]
}
# -------------------------------------------------
# Report2Html - provided for backward compatibility
#
proc Report2Html {BuildYamlFile} {
ReportBuildYaml2Dict ${BuildYamlFile}
ReportBuildDict2Html
}