-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathReportBuildYaml2Dict.tcl
333 lines (297 loc) · 10.7 KB
/
ReportBuildYaml2Dict.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
# File Name: ReportBuildYaml2Dict.tcl
# Purpose: Convert OSVVM YAML build reports to HTML
# Revision: OSVVM MODELS STANDARD VERSION
#
# Maintainer: Jim Lewis email: [email protected]
# Contributor(s):
# Jim Lewis email: [email protected]
#
# Description
# Convert OSVVM YAML build reports to TCL Dictionary
# Visible externally: ReportBuildYaml2Dict
#
# 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 NOCHECKS as FAIL or PASS. Naming updates
# 05/2024 2024.05 Refactored. Decoupled. Yaml = source of information.
# 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
#
# -------------------------------------------------
# CreateBuildReports
#
proc CreateBuildReports {ReportFile} {
ReportBuildYaml2Dict ${ReportFile}
ReportBuildDict2Html
ReportBuildDict2Junit
}
# -------------------------------------------------
# ReportBuildYaml2Dict
#
proc ReportBuildYaml2Dict {ReportFile} {
variable ReportFileRoot
variable ReportBuildName
variable BuildDict
# Extract BuildName and HtmlFileName from ReportFile
set ReportFileRoot [file rootname $ReportFile]
set ReportBuildName [file tail $ReportFileRoot]
# Read the YAML file into a dictionary
set BuildDict [::yaml::yaml2dict -file ${ReportFile}]
# Convert YAML file to HTML & catch results
set ErrorCode [catch {LocalReportBuildYaml2Dict $BuildDict} errmsg]
if {$ErrorCode} {
CallbackOnError_ReportBuildYaml2Dict $ReportFile $errmsg
}
}
# -------------------------------------------------
# LocalReportBuildYaml2Dict
#
proc LocalReportBuildYaml2Dict {BuildDict} {
variable ReportBuildName
GetOsvvmPathSettings $BuildDict
ElaborateTestSuites $BuildDict
GetBuildStatus $BuildDict
}
# -------------------------------------------------
# ReportBuildStatus
#
proc ReportBuildStatus {} {
variable ReportBuildName
variable ReportBuildErrorCode
variable ReportAnalyzeErrorCount
variable ReportSimulateErrorCount
variable BuildStatus
variable TestCasesPassed
variable TestCasesFailed
variable TestCasesSkipped
variable TestCasesRun
if {$BuildStatus eq "PASSED"} {
puts "Build: ${ReportBuildName} ${BuildStatus}, Passed: ${TestCasesPassed}, Failed: ${TestCasesFailed}, Skipped: ${TestCasesSkipped}, Analyze Errors: ${ReportAnalyzeErrorCount}, Simulate Errors: ${ReportSimulateErrorCount}"
} else {
puts "BuildError: ${ReportBuildName} ${BuildStatus}, Passed: ${TestCasesPassed}, Failed: ${TestCasesFailed}, Skipped: ${TestCasesSkipped}, Analyze Errors: ${ReportAnalyzeErrorCount}, Simulate Errors: ${ReportSimulateErrorCount}, Build Error Code: $ReportBuildErrorCode"
}
}
# -------------------------------------------------
# ElaborateTestSuites
#
proc ElaborateTestSuites {TestDict} {
# Summary dictionaries
variable TestSuiteSummaryArrayOfDictionaries ""
variable HaveTestSuites
# Detailed Build Status
variable BuildStatus "PASSED"
variable TestCasesPassed 0
variable TestCasesFailed 0
variable TestCasesSkipped 0
variable TestCasesRun 0
set HaveTestSuites [dict exists $TestDict TestSuites]
if { $HaveTestSuites } {
foreach TestSuite [dict get $TestDict TestSuites] {
set SuitePassed 0
set SuiteFailed 0
set SuiteSkipped 0
set SuiteReqPassed 0
set SuiteReqGoal 0
set SuiteDisabledAlerts 0
set SuiteName [dict get $TestSuite Name]
foreach TestCase [dict get $TestSuite TestCases] {
set TestName [dict get $TestCase TestCaseName]
if { [dict exists $TestCase Results] } {
set TestStatus [dict get $TestCase Status]
set TestResults [dict get $TestCase Results]
if { $TestStatus ne "SKIPPED" } {
set TestReqGoal [dict get $TestResults RequirementsGoal]
set TestReqPassed [dict get $TestResults RequirementsPassed]
set SuiteDisabledAlerts [expr $SuiteDisabledAlerts + [SumAlertCount [dict get $TestResults DisabledAlertCount]]]
set VhdlName [dict get $TestCase Name]
} else {
set TestReqGoal 0
set TestReqPassed 0
set VhdlName $TestName
}
} else {
set TestStatus "FAILED"
set TestReqGoal 0
set TestReqPassed 0
set VhdlName $TestName
}
if { $TestStatus eq "SKIPPED" } {
incr SuiteSkipped
incr TestCasesSkipped
} else {
incr TestCasesRun
if { ${TestName} ne ${VhdlName} } {
incr SuiteFailed
incr TestCasesFailed
} elseif { ($TestStatus eq "PASSED") || (($TestStatus eq "NOCHECKS") && !($::osvvm::FailOnNoChecks)) } {
incr SuitePassed
incr TestCasesPassed
if { $TestReqGoal > 0 } {
incr SuiteReqGoal
if { $TestReqPassed >= $TestReqGoal } {
incr SuiteReqPassed
}
}
} else {
# TestStatus = FAILED or TIMEOUT
# TestStatus = NOCHECKS if OsvvmVersionCompatibility is 2024.07 (or later) or
# FailOnNoChecks is set to TRUE in OsvvmSettingsLocal.tcl
incr SuiteFailed
incr TestCasesFailed
}
}
}
if {[dict exists $TestSuite ElapsedTime]} {
set SuiteElapsedTime [dict get $TestSuite ElapsedTime]
} else {
set SuiteElapsedTime 0
}
if { $SuitePassed > 0 && $SuiteFailed == 0 } {
set SuiteStatus "PASSED"
} else {
set SuiteStatus "FAILED"
set BuildStatus "FAILED"
}
set SuiteDict [dict create Name $SuiteName]
dict append SuiteDict Status $SuiteStatus
dict append SuiteDict PASSED $SuitePassed
dict append SuiteDict FAILED $SuiteFailed
dict append SuiteDict SKIPPED $SuiteSkipped
dict append SuiteDict ReqPassed $SuiteReqPassed
dict append SuiteDict ReqGoal $SuiteReqGoal
dict append SuiteDict DisabledAlerts $SuiteDisabledAlerts
dict append SuiteDict ElapsedTime $SuiteElapsedTime
lappend TestSuiteSummaryArrayOfDictionaries $SuiteDict
}
}
}
# -------------------------------------------------
# GetBuildStatus
#
proc GetBuildStatus {TestDict} {
variable ReportBuildName
variable ReportBuildErrorCode
variable ReportAnalyzeErrorCount
variable ReportSimulateErrorCount
variable BuildStatus
variable ReportStartTime
variable ReportIsoStartTime
variable ReportFinishTime
variable ElapsedTimeSeconds
variable ElapsedTimeSecondsInt
variable ElapsedTimeHms
variable ReportSimulator
variable ReportSimulatorVersion
variable OsvvmVersion
variable RequirementsRelativeHtml
if { [dict exists $TestDict BuildInfo] } {
set RunInfo [dict get $TestDict BuildInfo]
} else {
set RunInfo [dict create BuildErrorCode 1]
}
if {[dict exists $RunInfo BuildErrorCode]} {
set ReportBuildErrorCode [dict get $RunInfo BuildErrorCode]
} else {
set ReportBuildErrorCode 1
}
if {[dict exists $RunInfo AnalyzeErrorCount]} {
set ReportAnalyzeErrorCount [dict get $RunInfo AnalyzeErrorCount]
} else {
set ReportAnalyzeErrorCount 0
}
if {[dict exists $RunInfo SimulateErrorCount]} {
set ReportSimulateErrorCount [dict get $RunInfo SimulateErrorCount]
} else {
set ReportSimulateErrorCount 0
}
if {($ReportBuildErrorCode != 0) || $ReportAnalyzeErrorCount || $ReportSimulateErrorCount} {
set BuildStatus "FAILED"
}
# Print BuildInfo
set BuildInfo $RunInfo
if {[dict exists $RunInfo StartTime]} {
set ReportIsoStartTime [dict get $RunInfo StartTime]
set ReportStartTime [IsoToOsvvmTime $ReportIsoStartTime]
} else {
set ReportIsoStartTime ""
set ReportStartTime ""
}
if {[dict exists $RunInfo FinishTime]} {
set ReportFinishTime [IsoToOsvvmTime [dict get $RunInfo FinishTime]]
} else {
set ReportFinishTime ""
}
if {[dict exists $RunInfo Elapsed]} {
set ElapsedTimeSeconds [dict get $RunInfo Elapsed]
} else {
set ElapsedTimeSeconds 0.0
}
set ElapsedTimeSecondsInt [expr {round($ElapsedTimeSeconds)}]
set ElapsedTimeHms [format %d:%02d:%02d [expr ($ElapsedTimeSecondsInt/(60*60))] [expr (($ElapsedTimeSecondsInt/60)%60)] [expr (${ElapsedTimeSecondsInt}%60)]]
if {[dict exists $RunInfo Simulator]} {
set ReportSimulator [dict get $RunInfo Simulator]
} else {
set ReportSimulator "Unknown"
}
if {[dict exists $RunInfo SimulatorVersion]} {
set ReportSimulatorVersion [dict get $RunInfo SimulatorVersion]
} else {
set ReportSimulatorVersion "Unknown"
}
if {[dict exists $RunInfo OsvvmVersion]} {
set OsvvmVersion [dict get $RunInfo OsvvmVersion]
} else {
set OsvvmVersion ""
}
if {$::osvvm::Report2RequirementsSubdirectory ne ""} {
set RequirementsRelativeHtml [file join $::osvvm::Report2RequirementsSubdirectory ${ReportBuildName}_req.html]
} else {
set RequirementsRelativeHtml ""
}
}
# -------------------------------------------------
# IsoToOsvvmTime
#
proc IsoToOsvvmTime {IsoTime} {
set TimeInSec [clock scan $IsoTime -format {%Y-%m-%dT%H:%M:%S%z} ]
return [clock format $TimeInSec -format {%Y-%m-%d - %H:%M:%S (%Z)}]
}