22# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33# SPDX-License-Identifier: Apache-2.0
44
5- """This script provides common DV simulation specific utilities."""
5+ """Common DV simulation specific utilities."""
66
77import re
88from collections import OrderedDict
9+ from pathlib import Path
910
1011
11- # Capture the summary results as a list of lists.
12- # The text coverage report is passed as input to the function, in addition to
13- # the tool used. The tool returns a 2D list if the coverage report file was read
14- # and the coverage was extracted successfully. It returns a tuple of:
15- # List of metrics and values
16- # Final coverage total
17- #
18- # Raises the appropriate exception if the coverage summary extraction fails.
19- def get_cov_summary_table (cov_report_txt , tool ):
20- with open (cov_report_txt ) as f :
12+ def get_cov_summary_table (cov_report_txt : Path , tool : str ):
13+ """Capture the summary results as a list of lists.
14+
15+ The text coverage report is passed as input to the function, in addition to
16+ the tool used. The tool returns a 2D list if the coverage report file was read
17+ and the coverage was extracted successfully.
18+
19+ Returns:
20+ tuple of, List of metrics and values, and final coverage total
21+
22+ Raises:
23+ the appropriate exception if the coverage summary extraction fails.
24+
25+ """
26+ with Path (cov_report_txt ).open () as f :
2127 if tool == "xcelium" :
2228 return xcelium_cov_summary_table (f )
29+
2330 if tool == "vcs" :
2431 return vcs_cov_summary_table (f )
32+
2533 msg = f"{ tool } is unsupported for cov extraction."
2634 raise NotImplementedError (msg )
2735
@@ -57,6 +65,7 @@ def xcelium_cov_summary_table(buf):
5765 items [metrics [i ]]["total" ] += int (m .group (2 ))
5866 items ["Score" ]["covered" ] += int (m .group (1 ))
5967 items ["Score" ]["total" ] += int (m .group (2 ))
68+
6069 # Capture the percentages and the aggregate.
6170 values = []
6271 cov_total = None
@@ -69,6 +78,7 @@ def xcelium_cov_summary_table(buf):
6978 values .append (value )
7079 if metric == "Score" :
7180 cov_total = value
81+
7282 return [items .keys (), values ], cov_total
7383
7484 # If we reached here, then we were unable to extract the coverage.
@@ -102,17 +112,23 @@ def vcs_cov_summary_table(buf):
102112
103113
104114def get_job_runtime (log_text : list , tool : str ) -> tuple [float , str ]:
105- """Returns the job runtime (wall clock time) along with its units.
115+ """Return the job runtime (wall clock time) along with its units.
106116
107117 EDA tools indicate how long the job ran in terms of CPU time in the log
108118 file. This method invokes the tool specific method which parses the log
109119 text and returns the runtime as a floating point value followed by its
110120 units as a tuple.
111121
112- `log_text` is the job's log file contents as a list of lines.
113- `tool` is the EDA tool used to run the job.
114- Returns the runtime, units as a tuple.
115- Raises NotImplementedError exception if the EDA tool is not supported.
122+ Args:
123+ log_text: is the job's log file contents as a list of lines.
124+ tool: is the EDA tool used to run the job.
125+
126+ Returns:
127+ the runtime, units as a tuple.
128+
129+ Raises:
130+ NotImplementedError: exception if the EDA tool is not supported.
131+
116132 """
117133 if tool == "xcelium" :
118134 return xcelium_job_runtime (log_text )
@@ -123,15 +139,22 @@ def get_job_runtime(log_text: list, tool: str) -> tuple[float, str]:
123139
124140
125141def vcs_job_runtime (log_text : list ) -> tuple [float , str ]:
126- """Returns the VCS job runtime (wall clock time) along with its units.
142+ """Return the VCS job runtime (wall clock time) along with its units.
127143
128144 Search pattern example:
129145 CPU time: 22.170 seconds to compile + .518 seconds to elab + 1.901 \
130146 seconds to link
131147 CPU Time: 0.610 seconds; Data structure size: 1.6Mb
132148
133- Returns the runtime, units as a tuple.
134- Raises RuntimeError exception if the search pattern is not found.
149+ Args:
150+ log_text: is the job's log file contents as a list of lines.
151+
152+ Returns:
153+ the runtime, units as a tuple.
154+
155+ Raises:
156+ RuntimeError exception if the search pattern is not found.
157+
135158 """
136159 pattern = r"^CPU [tT]ime:\s*(\d+\.?\d*?)\s*(seconds|minutes|hours).*$"
137160 for line in reversed (log_text ):
@@ -143,14 +166,21 @@ def vcs_job_runtime(log_text: list) -> tuple[float, str]:
143166
144167
145168def xcelium_job_runtime (log_text : list ) -> tuple [float , str ]:
146- """Returns the Xcelium job runtime (wall clock time) along with its units.
169+ """Return the Xcelium job runtime (wall clock time) along with its units.
147170
148171 Search pattern example:
149172 TOOL: xrun(64) 21.09-s006: Exiting on Aug 01, 2022 at 00:21:18 PDT \
150173 (total: 00:00:05)
151174
152- Returns the runtime, units as a tuple.
153- Raises RuntimeError exception if the search pattern is not found.
175+ Args:
176+ log_text: is the job's log file contents as a list of lines.
177+
178+ Returns:
179+ the runtime, units as a tuple.
180+
181+ Raises:
182+ RuntimeError: exception if the search pattern is not found.
183+
154184 """
155185 pattern = r"^TOOL:\s*xrun.*: Exiting on .*\(total:\s*(\d+):(\d+):(\d+)\)\s*$"
156186 for line in reversed (log_text ):
@@ -163,17 +193,23 @@ def xcelium_job_runtime(log_text: list) -> tuple[float, str]:
163193
164194
165195def get_simulated_time (log_text : list , tool : str ) -> tuple [float , str ]:
166- """Returns the simulated time along with its units.
196+ """Return the simulated time along with its units.
167197
168198 EDA tools indicate how long the design was simulated for in the log file.
169199 This method invokes the tool specific method which parses the log text and
170200 returns the simulated time as a floating point value followed by its
171201 units (typically, pico|nano|micro|milliseconds) as a tuple.
172202
173- `log_text` is the job's log file contents as a list of lines.
174- `tool` is the EDA tool used to run the job.
175- Returns the simulated, units as a tuple.
176- Raises NotImplementedError exception if the EDA tool is not supported.
203+ Args:
204+ log_text: is the job's log file contents as a list of lines.
205+ tool: is the EDA tool used to run the job.
206+
207+ Returns:
208+ the simulated, units as a tuple.
209+
210+ Raises:
211+ NotImplementedError: exception if the EDA tool is not supported.
212+
177213 """
178214 if tool == "xcelium" :
179215 return xcelium_simulated_time (log_text )
@@ -184,13 +220,20 @@ def get_simulated_time(log_text: list, tool: str) -> tuple[float, str]:
184220
185221
186222def xcelium_simulated_time (log_text : list ) -> tuple [float , str ]:
187- """Returns the Xcelium simulated time along with its units.
223+ """Return the Xcelium simulated time along with its units.
188224
189225 Search pattern example:
190226 Simulation complete via $finish(2) at time 11724965 PS + 13
191227
192- Returns the simulated time, units as a tuple.
193- Raises RuntimeError exception if the search pattern is not found.
228+ Args:
229+ log_text: is the job's log file contents as a list of lines.
230+
231+ Returns:
232+ the simulated time, units as a tuple.
233+
234+ Raises:
235+ RuntimeError: exception if the search pattern is not found.
236+
194237 """
195238 pattern = r"^Simulation complete .* at time (\d+\.?\d*?)\s*(.?[sS]).*$"
196239 for line in reversed (log_text ):
@@ -202,22 +245,32 @@ def xcelium_simulated_time(log_text: list) -> tuple[float, str]:
202245
203246
204247def vcs_simulated_time (log_text : list ) -> tuple [float , str ]:
205- """Returns the VCS simulated time along with its units.
248+ """Return the VCS simulated time along with its units.
206249
207250 Search pattern example:
208251 V C S S i m u l a t i o n R e p o r t
209252 Time: 12241752 ps
210253
211- Returns the simulated time, units as a tuple.
212- Raises RuntimeError exception if the search pattern is not found.
254+ Args:
255+ log_text: is the job's log file contents as a list of lines.
256+
257+ Returns:
258+ the simulated time, units as a tuple.
259+
260+ Raises:
261+ RuntimeError: exception if the search pattern is not found.
262+
213263 """
214264 pattern = r"^Time:\s*(\d+\.?\d*?)\s*(.?[sS])\s*$"
215265 next_line = ""
266+
216267 for line in reversed (log_text ):
217- if "V C S S i m u l a t i o n R e p o r t" in line :
218- m = re .search (pattern , next_line )
219- if m :
220- return float (m .group (1 )), m .group (2 ).lower ()
268+ if "V C S S i m u l a t i o n R e p o r t" in line and (
269+ m := re .search (pattern , next_line )
270+ ):
271+ return float (m .group (1 )), m .group (2 ).lower ()
272+
221273 next_line = line
274+
222275 msg = "Simulated time not found in the log."
223276 raise RuntimeError (msg )
0 commit comments