Coverage for pyEDAA/OSVVM/Procedures.py: 95%

116 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-03-10 07:04 +0000

1# ==================================================================================================================== # 

2# _____ ____ _ _ ___ ______ ____ ____ __ # 

3# _ __ _ _| ____| _ \ / \ / \ / _ \/ ___\ \ / /\ \ / / \/ | # 

4# | '_ \| | | | _| | | | |/ _ \ / _ \ | | | \___ \\ \ / / \ \ / /| |\/| | # 

5# | |_) | |_| | |___| |_| / ___ \ / ___ \ | |_| |___) |\ V / \ V / | | | | # 

6# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)___/|____/ \_/ \_/ |_| |_| # 

7# |_| |___/ # 

8# ==================================================================================================================== # 

9# Authors: # 

10# Patrick Lehmann # 

11# # 

12# License: # 

13# ==================================================================================================================== # 

14# Copyright 2025-2025 Patrick Lehmann - Boetzingen, Germany # 

15# # 

16# Licensed under the Apache License, Version 2.0 (the "License"); # 

17# you may not use this file except in compliance with the License. # 

18# You may obtain a copy of the License at # 

19# # 

20# http://www.apache.org/licenses/LICENSE-2.0 # 

21# # 

22# Unless required by applicable law or agreed to in writing, software # 

23# distributed under the License is distributed on an "AS IS" BASIS, # 

24# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 

25# See the License for the specific language governing permissions and # 

26# limitations under the License. # 

27# # 

28# SPDX-License-Identifier: Apache-2.0 # 

29# ==================================================================================================================== # 

30# 

31from pathlib import Path 

32from typing import Optional as Nullable, Tuple 

33 

34from pyTooling.Decorators import export 

35from pyVHDLModel import VHDLVersion 

36 

37from pyEDAA.OSVVM import OSVVMException 

38from pyEDAA.OSVVM.Environment import osvvmContext, VHDLSourceFile, GenericValue 

39 

40 

41@export 

42def build(file: str) -> None: 

43 include(file) 

44 

45 

46@export 

47def include(file: str) -> None: 

48 currentDirectory = osvvmContext._currentDirectory 

49 

50 includeFile = osvvmContext.IncludeFile(Path(file)) 

51 osvvmContext.EvaluateFile(includeFile) 

52 

53 osvvmContext._currentDirectory = currentDirectory 

54 

55 

56@export 

57def library(libraryName: str, libraryPath: Nullable[str] = None) -> None: 

58 osvvmContext.SetLibrary(libraryName) 

59 

60 

61@export 

62def analyze(file: str) -> None: 

63 file = Path(file) 

64 fullPath = (osvvmContext._currentDirectory / file).resolve() 

65 

66 if not fullPath.exists(): # pragma: no cover 

67 ex = OSVVMException(f"Path '{fullPath}' can't be analyzed.") 

68 ex.__cause__ = FileNotFoundError(fullPath) 

69 osvvmContext.LastException = ex 

70 raise ex 

71 

72 if fullPath.suffix in (".vhd", ".vhdl"): 

73 vhdlFile = VHDLSourceFile(fullPath.relative_to(osvvmContext._workingDirectory, walk_up=True)) 

74 osvvmContext.AddVHDLFile(vhdlFile) 

75 else: # pragma: no cover 

76 ex = OSVVMException(f"Path '{fullPath}' is no VHDL file.") 

77 osvvmContext.LastException = ex 

78 raise ex 

79 

80 

81@export 

82def simulate(toplevelName: str, *options: Tuple[int]) -> None: 

83 testcase = osvvmContext.SetTestcaseToplevel(toplevelName) 

84 for optionID in options: 

85 try: 

86 option = osvvmContext._options[int(optionID)] 

87 except KeyError as e: # pragma: no cover 

88 ex = OSVVMException(f"Option {optionID} not found in option dictionary.") 

89 ex.__cause__ = e 

90 osvvmContext.LastException = ex 

91 raise ex 

92 

93 if isinstance(option, GenericValue): 

94 testcase.AddGeneric(option) 

95 else: # pragma: no cover 

96 ex = OSVVMException(f"Option {optionID} is not a GenericValue.") 

97 ex.__cause__ = TypeError() 

98 osvvmContext.LastException = ex 

99 raise ex 

100 

101 # osvvmContext._testcase = None 

102 

103 

104@export 

105def generic(name: str, value: str) -> GenericValue: 

106 genericValue = GenericValue(name, value) 

107 optionID = osvvmContext.AddOption(genericValue) 

108 

109 return optionID 

110 

111 

112@export 

113def TestSuite(name: str) -> None: 

114 osvvmContext.SetTestsuite(name) 

115 

116 

117@export 

118def TestName(name: str) -> None: 

119 osvvmContext.AddTestcase(name) 

120 

121 

122@export 

123def RunTest(file: str, *options: Tuple[int]) -> None: 

124 file = Path(file) 

125 testName = file.stem 

126 

127 # Analyze file 

128 fullPath = (osvvmContext._currentDirectory / file).resolve() 

129 if not fullPath.exists(): # pragma: no cover 

130 ex = OSVVMException(f"Path '{fullPath}' can't be analyzed.") 

131 ex.__cause__ = FileNotFoundError(fullPath) 

132 osvvmContext.LastException = ex 

133 raise ex 

134 

135 if fullPath.suffix in (".vhd", ".vhdl"): 

136 vhdlFile = VHDLSourceFile(fullPath.relative_to(osvvmContext._workingDirectory, walk_up=True)) 

137 osvvmContext.AddVHDLFile(vhdlFile) 

138 else: # pragma: no cover 

139 ex = OSVVMException(f"Path '{fullPath}' is no VHDL file.") 

140 osvvmContext.LastException = ex 

141 raise ex 

142 

143 # Add testcase 

144 testcase = osvvmContext.AddTestcase(testName) 

145 testcase.SetToplevel(testName) 

146 for optionID in options: 

147 try: 

148 option = osvvmContext._options[int(optionID)] 

149 except KeyError as e: # pragma: no cover 

150 ex = OSVVMException(f"Option {optionID} not found in option dictionary.") 

151 ex.__cause__ = e 

152 osvvmContext.LastException = ex 

153 raise ex 

154 

155 if isinstance(option, GenericValue): 

156 testcase.AddGeneric(option) 

157 else: # pragma: no cover 

158 ex = OSVVMException(f"Option {optionID} is not a GenericValue.") 

159 ex.__cause__ = TypeError() 

160 osvvmContext.LastException = ex 

161 raise ex 

162 

163 # osvvmContext._testcase = None 

164 

165 

166@export 

167def LinkLibrary(libraryName: str, libraryPath: Nullable[str] = None): 

168 print(f"[LinkLibrary] {libraryPath}") 

169 

170 

171@export 

172def LinkLibraryDirectory(libraryDirectory: str): 

173 print(f"[LinkLibraryDirectory] {libraryDirectory}") 

174 

175 

176@export 

177def SetVHDLVersion(value: str) -> None: 

178 try: 

179 value = int(value) 

180 except ValueError as e: # pragma: no cover 

181 ex = OSVVMException(f"Unsupported VHDL version '{value}'.") 

182 ex.__cause__ = e 

183 osvvmContext.LastException = ex 

184 raise ex 

185 

186 match value: 

187 case 1987: 

188 osvvmContext.VHDLVersion = VHDLVersion.VHDL87 

189 case 1993: 

190 osvvmContext.VHDLVersion = VHDLVersion.VHDL93 

191 case 2002: 

192 osvvmContext.VHDLVersion = VHDLVersion.VHDL2002 

193 case 2008: 

194 osvvmContext.VHDLVersion = VHDLVersion.VHDL2008 

195 case 2019: 

196 osvvmContext.VHDLVersion = VHDLVersion.VHDL2019 

197 case _: # pragma: no cover 

198 ex = OSVVMException(f"Unsupported VHDL version '{value}'.") 

199 osvvmContext.LastException = ex 

200 raise ex 

201 

202 

203@export 

204def GetVHDLVersion() -> int: 

205 if osvvmContext.VHDLVersion is VHDLVersion.VHDL87: 

206 return 1987 

207 elif osvvmContext.VHDLVersion is VHDLVersion.VHDL93: 

208 return 1993 

209 elif osvvmContext.VHDLVersion is VHDLVersion.VHDL2002: 

210 return 2002 

211 elif osvvmContext.VHDLVersion is VHDLVersion.VHDL2008: 

212 return 2008 

213 elif osvvmContext.VHDLVersion is VHDLVersion.VHDL2019: 

214 return 2019 

215 else: # pragma: no cover 

216 ex = OSVVMException(f"Unsupported VHDL version '{osvvmContext.VHDLVersion}'.") 

217 osvvmContext.LastException = ex 

218 raise ex 

219 

220 

221@export 

222def SetCoverageAnalyzeEnable(value: bool) -> None: 

223 print(f"[SetCoverageAnalyzeEnable] {value}:{value.__class__.__name__}") 

224 

225 

226@export 

227def SetCoverageSimulateEnable(value: bool) -> None: 

228 print(f"[SetCoverageSimulateEnable] {value}") 

229 

230 

231@export 

232def FileExists(file: str) -> bool: 

233 return (osvvmContext._currentDirectory / file).is_file() 

234 

235 

236@export 

237def DirectoryExists(directory: str) -> bool: 

238 return (osvvmContext._currentDirectory / directory).is_dir() 

239 

240 

241@export 

242def ChangeWorkingDirectory(directory: str) -> None: 

243 osvvmContext._currentDirectory = (newDirectory := osvvmContext._currentDirectory / directory) 

244 if not newDirectory.is_dir(): # pragma: no cover 

245 ex = OSVVMException(f"Directory '{newDirectory}' doesn't exist.") 

246 ex.__cause__ = NotADirectoryError(newDirectory) 

247 osvvmContext.LastException = ex 

248 raise ex 

249 

250 

251@export 

252def FindOsvvmSettingsDirectory(*args): 

253 pass 

254 

255 

256@export 

257def CreateOsvvmScriptSettingsPkg(*args): 

258 pass 

259 

260 

261@export 

262def noop(*args): 

263 pass