-
Notifications
You must be signed in to change notification settings - Fork 15
/
Requirements2Csv.tcl
166 lines (142 loc) · 6.44 KB
/
Requirements2Csv.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
# File Name: Requirements2Csv.tcl
# Purpose: Create HTML for Requirements
# Revision: OSVVM MODELS STANDARD VERSION
#
# Maintainer: Jim Lewis email: [email protected]
# Contributor(s):
# Jim Lewis email: [email protected]
#
# Description
# Visible externally: Requirements2Csv
#
# 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/2023 2023.07 Initial Revision
#
#
# This file is part of OSVVM.
#
# Copyright (c) 2023 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
proc Requirements2Csv {RequirementsYamlFile} {
variable ResultsFile
if {[file exists $RequirementsYamlFile]} {
set FileRoot [file rootname $RequirementsYamlFile]
set CsvFileName ${FileRoot}.csv
set ResultsFile [open ${CsvFileName} w]
set ReportName [regsub {_req} [file tail $FileRoot] ""]
set ErrorCode [catch {LocalRequirements2Csv $RequirementsYamlFile $ReportName} errmsg]
close $ResultsFile
if {$ErrorCode} {
CallbackOnError_AnyReport "Requirements2Csv" "RequirementsYamlFile: $RequirementsYamlFile" $errmsg
}
}
}
proc LocalRequirements2Csv {RequirementsYamlFile ReportName} {
variable ResultsFile
set Requirements2Dict [::yaml::yaml2dict -file ${RequirementsYamlFile}]
# CSV only for merged Requirements which are already sorted
# set Requirements2Dict [lsort -index 1 $UnsortedRequirements2Dict]
foreach item $Requirements2Dict {
set Requirement [dict get $item Requirement]
set TestCases [dict get $item TestCases]
set NumTestCases [llength $TestCases]
if {$NumTestCases == 1} {
set TestCase [lindex $TestCases 0]
WriteOneRequirementCsv $TestCase $Requirement
} else {
WriteMergeTestCaseCsv $TestCases $Requirement
}
}
}
proc WriteOneRequirementCsv {TestCase {Requirement ""}} {
variable ResultsFile
set TestName [dict get $TestCase TestName]
set Status [dict get $TestCase Status]
set ResultsDict [dict get $TestCase Results]
set Goal [dict get $ResultsDict Goal]
set Passed [dict get $ResultsDict Passed]
set TotalErrors [dict get $ResultsDict Errors]
set Checked [dict get $ResultsDict Checked]
set AlertCount [dict get $ResultsDict AlertCount]
set AlertFailure [dict get $AlertCount Failure]
set AlertError [dict get $AlertCount Error]
set AlertWarning [dict get $AlertCount Warning]
set DisabledAlertCount [dict get $ResultsDict DisabledAlertCount]
set DisabledAlertFailure [dict get $DisabledAlertCount Failure]
set DisabledAlertError [dict get $DisabledAlertCount Error]
set DisabledAlertWarning [dict get $DisabledAlertCount Warning]
set Failures [expr {$AlertFailure + $DisabledAlertFailure}]
set Errors [expr {$AlertError + $DisabledAlertError }]
set Warnings [expr {$AlertWarning + $DisabledAlertWarning}]
puts $ResultsFile "$Requirement, $Goal, $Passed, $TotalErrors, $Failures, $Errors, $Warnings, $Checked"
}
proc WriteMergeTestCaseCsv { TestCases {Requirement ""}} {
variable ResultsFile
set TestName Merged
set Status PASSED
set Goal 0
set Passed 0
set TotalErrors 0
set Checked 0
set AlertFailure 0
set AlertError 0
set AlertWarning 0
set DisabledAlertFailure 0
set DisabledAlertError 0
set DisabledAlertWarning 0
foreach TestCase $TestCases {
set CurStatus [dict get $TestCase Status]
set ResultsDict [dict get $TestCase Results]
set CurGoal [dict get $ResultsDict Goal]
set DictPassed [dict get $ResultsDict Passed]
set CurPassed [expr {$DictPassed < $CurGoal ? $DictPassed : $CurGoal}]
set CurErrors [dict get $ResultsDict Errors]
set CurChecked [dict get $ResultsDict Checked]
set AlertCount [dict get $ResultsDict AlertCount]
set CurAlertFailure [dict get $AlertCount Failure]
set CurAlertError [dict get $AlertCount Error]
set CurAlertWarning [dict get $AlertCount Warning]
set DisabledAlertCount [dict get $ResultsDict DisabledAlertCount]
set CurDisabledAlertFailure [dict get $DisabledAlertCount Failure]
set CurDisabledAlertError [dict get $DisabledAlertCount Error]
set CurDisabledAlertWarning [dict get $DisabledAlertCount Warning]
if {$CurStatus eq "FAILED"} {
set Status "FAILED"
}
set Goal [expr {$Goal > $CurGoal ? $Goal : $CurGoal}]
set Passed [expr {$Passed + $CurPassed}]
set TotalErrors [expr {$TotalErrors + $CurErrors}]
set Checked [expr {$Checked + $CurChecked}]
set AlertFailure [expr {$AlertFailure + $CurAlertFailure}]
set AlertError [expr {$AlertError + $CurAlertError}]
set AlertWarning [expr {$AlertWarning + $CurAlertWarning}]
set DisabledAlertFailure [expr {$DisabledAlertFailure + $CurDisabledAlertFailure}]
set DisabledAlertError [expr {$DisabledAlertError + $CurDisabledAlertError}]
set DisabledAlertWarning [expr {$DisabledAlertWarning + $CurDisabledAlertWarning}]
}
set Failures [expr {$AlertFailure + $DisabledAlertFailure}]
set Errors [expr {$AlertError + $DisabledAlertError }]
set Warnings [expr {$AlertWarning + $DisabledAlertWarning}]
puts $ResultsFile "$Requirement, $Goal, $Passed, $TotalErrors, $Failures, $Errors, $Warnings, $Checked"
}