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
|
# ==================================================================================================================== #
# _____ ____ _ _ ____ _ #
# _ __ _ _| ____| _ \ / \ / \ | _ \ ___ _ __ ___ _ __| |_ ___ #
# | '_ \| | | | _| | | | |/ _ \ / _ \ | |_) / _ \ '_ \ / _ \| '__| __/ __| #
# | |_) | |_| | |___| |_| / ___ \ / ___ \ _| _ < __/ |_) | (_) | | | |_\__ \ #
# | .__/ \__, |_____|____/_/ \_\/_/ \_(_)_| \_\___| .__/ \___/|_| \__|___/ #
# |_| |___/ |_| #
# ==================================================================================================================== #
# Authors: #
# Patrick Lehmann #
# #
# License: #
# ==================================================================================================================== #
# Copyright 2026-2026 Electronic Design Automation Abstraction (EDA²) #
# #
# 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 #
# #
# http://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. #
# #
# SPDX-License-Identifier: Apache-2.0 #
# ==================================================================================================================== #
#
"""
The options of the covergroup coverage of the UCIS XML interchange format: the ``<options>`` of a covergroup instance,
a coverpoint or a cross, as SystemVerilog declares them.
"""
from __future__ import annotations
from typing import Self
from lxml.etree import _Element
from pyTooling.Common import getFullyQualifiedName
from pyTooling.Decorators import export, readonly
from pyTooling.MetaClasses import ExtendedType, abstractclass
from pyEDAA.Reports.CodeCoverage.UCIS.Elements import Base
@export
@abstractclass
class Options(metaclass=ExtendedType, slots=True):
"""
Base-class of the ``<options>`` of a covergroup instance, a coverpoint or a cross: the options SystemVerilog declares
for all three.
It is a value, as a path is: it names no parent.
"""
_weight: int #: Weight in computing the coverage.
_goal: int #: Coverage goal, in percent.
_comment: str #: A comment.
_atLeast: int #: How often a bin must be hit to be covered.
def __init__(self, weight: int = 1, goal: int = 100, comment: str = "", atLeast: int = 1) -> None:
"""
Initialize the options.
:param weight: Optional, weight in computing the coverage. Default: ``1``.
:param goal: Optional, coverage goal, in percent. Default: ``100``.
:param comment: Optional, a comment. Default: ``""``.
:param atLeast: Optional, how often a bin must be hit to be covered. Default: ``1``.
:raises ValueError: If parameter ``weight``, ``goal`` or ``atLeast`` is ``None``.
:raises TypeError: If parameter ``weight``, ``goal`` or ``atLeast`` isn't of type :class:`int`.
:raises ValueError: If parameter ``weight``, ``goal`` or ``atLeast`` is negative.
:raises ValueError: If parameter ``comment`` is ``None``.
:raises TypeError: If parameter ``comment`` isn't of type :class:`str`.
"""
for parameterName, value in (
("weight", weight),
("goal", goal),
("atLeast", atLeast)
):
if value is None:
raise ValueError(f"Parameter '{parameterName}' is None.")
elif not isinstance(value, int) or isinstance(value, bool):
ex = TypeError(f"Parameter '{parameterName}' is not of type 'int'.")
ex.add_note(f"Got type '{getFullyQualifiedName(value)}'.")
raise ex
elif value < 0:
ex = ValueError(f"Parameter '{parameterName}' is negative.")
ex.add_note(f"Got value '{value}'.")
raise ex
if comment is None:
raise ValueError("Parameter 'comment' is None.")
elif not isinstance(comment, str):
ex = TypeError("Parameter 'comment' is not of type 'str'.")
ex.add_note(f"Got type '{getFullyQualifiedName(comment)}'.")
raise ex
self._weight = weight
self._goal = goal
self._comment = comment
self._atLeast = atLeast
@readonly
def Weight(self) -> int:
"""
Read-only property to access the weight in computing the coverage (:attr:`_weight`).
:returns: The weight; ``1``, if the report states none.
"""
return self._weight
@readonly
def Goal(self) -> int:
"""
Read-only property to access the coverage goal (:attr:`_goal`).
:returns: The goal, in percent; ``100``, if the report states none.
"""
return self._goal
@readonly
def Comment(self) -> str:
"""
Read-only property to access the comment (:attr:`_comment`).
:returns: The comment; empty, if the report states none.
"""
return self._comment
@readonly
def AtLeast(self) -> int:
"""
Read-only property to access how often a bin must be hit to be covered (:attr:`_atLeast`).
:returns: The count; ``1``, if the report states none.
"""
return self._atLeast
@export
class CoverpointOptions(Options):
"""
The ``<options>`` of a coverpoint.
"""
_detectOverlap: bool #: Whether to warn about overlapping bins.
_autoBinMax: int #: Maximum number of bins created automatically.
def __init__(
self,
weight: int = 1,
goal: int = 100,
comment: str = "",
atLeast: int = 1,
detectOverlap: bool = False,
autoBinMax: int = 64
) -> None:
"""
Initialize the options of a coverpoint.
:param weight: Optional, weight in computing the coverage. Default: ``1``.
:param goal: Optional, coverage goal, in percent. Default: ``100``.
:param comment: Optional, a comment. Default: ``""``.
:param atLeast: Optional, how often a bin must be hit to be covered. Default: ``1``.
:param detectOverlap: Optional, whether to warn about overlapping bins. Default: ``False``.
:param autoBinMax: Optional, maximum number of bins created automatically. Default: ``64``.
:raises ValueError: If parameter ``weight``, ``goal`` or ``atLeast`` is ``None``.
:raises TypeError: If parameter ``weight``, ``goal`` or ``atLeast`` isn't of type :class:`int`.
:raises ValueError: If parameter ``weight``, ``goal`` or ``atLeast`` is negative.
:raises ValueError: If parameter ``comment`` is ``None``.
:raises TypeError: If parameter ``comment`` isn't of type :class:`str`.
:raises ValueError: If parameter ``detectOverlap`` is ``None``.
:raises TypeError: If parameter ``detectOverlap`` isn't of type :class:`bool`.
:raises ValueError: If parameter ``autoBinMax`` is ``None``.
:raises TypeError: If parameter ``autoBinMax`` isn't of type :class:`int`.
:raises ValueError: If parameter ``autoBinMax`` is negative.
"""
super().__init__(weight, goal, comment, atLeast)
if detectOverlap is None:
raise ValueError("Parameter 'detectOverlap' is None.")
elif not isinstance(detectOverlap, bool):
ex = TypeError("Parameter 'detectOverlap' is not of type 'bool'.")
ex.add_note(f"Got type '{getFullyQualifiedName(detectOverlap)}'.")
raise ex
if autoBinMax is None:
raise ValueError("Parameter 'autoBinMax' is None.")
elif not isinstance(autoBinMax, int) or isinstance(autoBinMax, bool):
ex = TypeError("Parameter 'autoBinMax' is not of type 'int'.")
ex.add_note(f"Got type '{getFullyQualifiedName(autoBinMax)}'.")
raise ex
elif autoBinMax < 0:
ex = ValueError("Parameter 'autoBinMax' is negative.")
ex.add_note(f"Got value '{autoBinMax}'.")
raise ex
self._detectOverlap = detectOverlap
self._autoBinMax = autoBinMax
@classmethod
def Parse(cls, element: _Element) -> Self:
"""
Parse the options of a coverpoint from its ``<options>`` element; an option it doesn't state has its default.
:param element: The ``<options>`` element.
:returns: The options.
"""
attributes = element.attrib
return cls(
int(attributes.get("weight", "1")),
int(attributes.get("goal", "100")),
attributes.get("comment", ""),
int(attributes.get("at_least", "1")),
Base._ParseBoolean(attributes.get("detect_overlap", "false")),
int(attributes.get("auto_bin_max", "64"))
)
@readonly
def DetectOverlap(self) -> bool:
"""
Read-only property to access whether to warn about overlapping bins (:attr:`_detectOverlap`).
:returns: ``True``, if overlapping bins are reported.
"""
return self._detectOverlap
@readonly
def AutoBinMax(self) -> int:
"""
Read-only property to access the maximum number of bins created automatically (:attr:`_autoBinMax`).
:returns: The maximum; ``64``, if the report states none.
"""
return self._autoBinMax
@export
class CrossOptions(Options):
"""
The ``<options>`` of a cross.
"""
_crossNumPrintMissing: int #: Number of uncovered cross bins to save and report.
def __init__(
self,
weight: int = 1,
goal: int = 100,
comment: str = "",
atLeast: int = 1,
crossNumPrintMissing: int = 0
) -> None:
"""
Initialize the options of a cross.
:param weight: Optional, weight in computing the coverage. Default: ``1``.
:param goal: Optional, coverage goal, in percent. Default: ``100``.
:param comment: Optional, a comment. Default: ``""``.
:param atLeast: Optional, how often a bin must be hit to be covered. Default: ``1``.
:param crossNumPrintMissing: Optional, number of uncovered cross bins to save and report. Default: ``0``.
:raises ValueError: If parameter ``weight``, ``goal`` or ``atLeast`` is ``None``.
:raises TypeError: If parameter ``weight``, ``goal`` or ``atLeast`` isn't of type :class:`int`.
:raises ValueError: If parameter ``weight``, ``goal`` or ``atLeast`` is negative.
:raises ValueError: If parameter ``comment`` is ``None``.
:raises TypeError: If parameter ``comment`` isn't of type :class:`str`.
:raises ValueError: If parameter ``crossNumPrintMissing`` is ``None``.
:raises TypeError: If parameter ``crossNumPrintMissing`` isn't of type :class:`int`.
:raises ValueError: If parameter ``crossNumPrintMissing`` is negative.
"""
super().__init__(weight, goal, comment, atLeast)
if crossNumPrintMissing is None:
raise ValueError("Parameter 'crossNumPrintMissing' is None.")
elif not isinstance(crossNumPrintMissing, int) or isinstance(crossNumPrintMissing, bool):
ex = TypeError("Parameter 'crossNumPrintMissing' is not of type 'int'.")
ex.add_note(f"Got type '{getFullyQualifiedName(crossNumPrintMissing)}'.")
raise ex
elif crossNumPrintMissing < 0:
ex = ValueError("Parameter 'crossNumPrintMissing' is negative.")
ex.add_note(f"Got value '{crossNumPrintMissing}'.")
raise ex
self._crossNumPrintMissing = crossNumPrintMissing
@classmethod
def Parse(cls, element: _Element) -> Self:
"""
Parse the options of a cross from its ``<options>`` element; an option it doesn't state has its default.
:param element: The ``<options>`` element.
:returns: The options.
"""
attributes = element.attrib
return cls(
int(attributes.get("weight", "1")),
int(attributes.get("goal", "100")),
attributes.get("comment", ""),
int(attributes.get("at_least", "1")),
int(attributes.get("cross_num_print_missing", "0"))
)
@readonly
def CrossNumPrintMissing(self) -> int:
"""
Read-only property to access the number of uncovered cross bins to save and report (:attr:`_crossNumPrintMissing`).
:returns: The number; ``0``, if the report states none.
"""
return self._crossNumPrintMissing
@export
class CovergroupOptions(CoverpointOptions):
"""
The ``<options>`` of a covergroup instance.
"""
_crossNumPrintMissing: int #: Number of uncovered cross bins to save and report.
_perInstance: bool #: Whether the instance's coverage is kept on its own.
_mergeInstances: bool #: Whether the covergroup's coverage merges its instances.
def __init__(
self,
weight: int = 1,
goal: int = 100,
comment: str = "",
atLeast: int = 1,
detectOverlap: bool = False,
autoBinMax: int = 64,
crossNumPrintMissing: int = 0,
perInstance: bool = False,
mergeInstances: bool = False
) -> None:
"""
Initialize the options of a covergroup instance.
:param weight: Optional, weight in computing the coverage. Default: ``1``.
:param goal: Optional, coverage goal, in percent. Default: ``100``.
:param comment: Optional, a comment. Default: ``""``.
:param atLeast: Optional, how often a bin must be hit to be covered. Default: ``1``.
:param detectOverlap: Optional, whether to warn about overlapping bins. Default: ``False``.
:param autoBinMax: Optional, maximum number of bins created automatically. Default: ``64``.
:param crossNumPrintMissing: Optional, number of uncovered cross bins to save and report. Default: ``0``.
:param perInstance: Optional, whether the instance's coverage is kept on its own. Default: ``False``.
:param mergeInstances: Optional, whether the covergroup's coverage merges its instances. Default:
``False``.
:raises ValueError: If parameter ``weight``, ``goal`` or ``atLeast`` is ``None``.
:raises TypeError: If parameter ``weight``, ``goal`` or ``atLeast`` isn't of type :class:`int`.
:raises ValueError: If parameter ``weight``, ``goal`` or ``atLeast`` is negative.
:raises ValueError: If parameter ``comment`` is ``None``.
:raises TypeError: If parameter ``comment`` isn't of type :class:`str`.
:raises ValueError: If parameter ``detectOverlap`` is ``None``.
:raises TypeError: If parameter ``detectOverlap`` isn't of type :class:`bool`.
:raises ValueError: If parameter ``autoBinMax`` is ``None``.
:raises TypeError: If parameter ``autoBinMax`` isn't of type :class:`int`.
:raises ValueError: If parameter ``autoBinMax`` is negative.
:raises ValueError: If parameter ``crossNumPrintMissing`` is ``None``.
:raises TypeError: If parameter ``crossNumPrintMissing`` isn't of type :class:`int`.
:raises ValueError: If parameter ``crossNumPrintMissing`` is negative.
:raises ValueError: If parameter ``perInstance`` or ``mergeInstances`` is ``None``.
:raises TypeError: If parameter ``perInstance`` or ``mergeInstances`` isn't of type :class:`bool`.
"""
super().__init__(weight, goal, comment, atLeast, detectOverlap, autoBinMax)
if crossNumPrintMissing is None:
raise ValueError("Parameter 'crossNumPrintMissing' is None.")
elif not isinstance(crossNumPrintMissing, int) or isinstance(crossNumPrintMissing, bool):
ex = TypeError("Parameter 'crossNumPrintMissing' is not of type 'int'.")
ex.add_note(f"Got type '{getFullyQualifiedName(crossNumPrintMissing)}'.")
raise ex
elif crossNumPrintMissing < 0:
ex = ValueError("Parameter 'crossNumPrintMissing' is negative.")
ex.add_note(f"Got value '{crossNumPrintMissing}'.")
raise ex
if perInstance is None:
raise ValueError("Parameter 'perInstance' is None.")
elif not isinstance(perInstance, bool):
ex = TypeError("Parameter 'perInstance' is not of type 'bool'.")
ex.add_note(f"Got type '{getFullyQualifiedName(perInstance)}'.")
raise ex
if mergeInstances is None:
raise ValueError("Parameter 'mergeInstances' is None.")
elif not isinstance(mergeInstances, bool):
ex = TypeError("Parameter 'mergeInstances' is not of type 'bool'.")
ex.add_note(f"Got type '{getFullyQualifiedName(mergeInstances)}'.")
raise ex
self._crossNumPrintMissing = crossNumPrintMissing
self._perInstance = perInstance
self._mergeInstances = mergeInstances
@classmethod
def Parse(cls, element: _Element) -> Self:
"""
Parse the options of a covergroup instance from its ``<options>`` element; an option it doesn't state has its
default.
:param element: The ``<options>`` element.
:returns: The options.
"""
attributes = element.attrib
return cls(
int(attributes.get("weight", "1")),
int(attributes.get("goal", "100")),
attributes.get("comment", ""),
int(attributes.get("at_least", "1")),
Base._ParseBoolean(attributes.get("detect_overlap", "false")),
int(attributes.get("auto_bin_max", "64")),
int(attributes.get("cross_num_print_missing", "0")),
Base._ParseBoolean(attributes.get("per_instance", "false")),
Base._ParseBoolean(attributes.get("merge_instances", "false"))
)
@readonly
def CrossNumPrintMissing(self) -> int:
"""
Read-only property to access the number of uncovered cross bins to save and report (:attr:`_crossNumPrintMissing`).
:returns: The number; ``0``, if the report states none.
"""
return self._crossNumPrintMissing
@readonly
def PerInstance(self) -> bool:
"""
Read-only property to access whether the instance's coverage is kept on its own (:attr:`_perInstance`).
:returns: ``True``, if kept per instance.
"""
return self._perInstance
@readonly
def MergeInstances(self) -> bool:
"""
Read-only property to access whether the covergroup's coverage merges its instances (:attr:`_mergeInstances`).
:returns: ``True``, if the instances are merged; otherwise, it is their weighted average.
"""
return self._mergeInstances
|