Skip to content

Commit 46304c0

Browse files
mballanceCopilot
andcommitted
Fix XML writer: element ordering and missing coverpoint bins
Two bugs found by converting merged_ncdb.cdb to UCIS XML and validating against the UCIS XSD schema (ucis.xsd): 1. Wrong element order in instanceCoverages: covergroupCoverage was emitted first and conditionCoverage came after branchCoverage, both violating the schema sequence (toggle→block→condition→branch→fsm→ assertion→covergroup→userAttr). Reorder write_instance_coverages() to match the XSD. 2. Missing coverpointBin children: write_coverpoint() queried bins only as direct coverItems on the coverpoint scope, but the NCDB (and any DB produced by ncdb_writer) stores bins in child CVGBINSCOPE / IGNOREBINSCOPE / ILLEGALBINSCOPE scopes. Fix by falling back to collecting bins from those child scopes when no direct bins exist. After these fixes 'python -m ucis convert --input-format ncdb ...' produces XML that passes lxml XMLSchema validation against ucis.xsd. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 11f172d commit 46304c0

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/ucis/xml/xml_writer.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,16 @@ def write_instance_coverages(self, s, parent_instance_id=None):
202202

203203
self.addId(inst, s.getSourceInfo())
204204

205-
self.write_covergroups(inst, s)
205+
# Write coverage children in schema-required order (UCIS XSD §INSTANCE_COVERAGE):
206+
# toggleCoverage, blockCoverage, conditionCoverage, branchCoverage,
207+
# fsmCoverage, assertionCoverage, covergroupCoverage, userAttr
206208
self.write_toggle_coverage(inst, s)
207209
self.write_block_coverage(inst, s)
210+
self.write_condition_coverage(inst, s)
208211
self.write_branch_coverage(inst, s)
209212
self.write_fsm_coverage(inst, s)
210213
self.write_assertion_coverage(inst, s)
211-
self.write_condition_coverage(inst, s)
214+
self.write_covergroups(inst, s)
212215
self.write_user_attrs(inst, s)
213216

214217
# Recursively write child instances
@@ -450,9 +453,19 @@ def write_coverpoint(self, cgInstElem, cp : Coverpoint):
450453
self.setAttr(cpElem, "key", "0")
451454

452455
self.write_options(cpElem, cp, is_coverpoint=True)
453-
454-
self.write_coverpoint_bins(cpElem, cp.coverItems(
455-
CoverTypeT.CVGBIN|CoverTypeT.IGNOREBIN|CoverTypeT.ILLEGALBIN))
456+
457+
_BIN_MASK = CoverTypeT.CVGBIN | CoverTypeT.IGNOREBIN | CoverTypeT.ILLEGALBIN
458+
# Bins may live directly on the coverpoint or in child CVGBINSCOPE /
459+
# IGNOREBINSCOPE / ILLEGALBINSCOPE scopes (depends on how the DB was
460+
# written). Collect from both places and emit them together.
461+
bins = list(cp.coverItems(_BIN_MASK))
462+
if not bins:
463+
_BINSCOPE_MASK = (ScopeTypeT.CVGBINSCOPE
464+
| ScopeTypeT.IGNOREBINSCOPE
465+
| ScopeTypeT.ILLEGALBINSCOPE)
466+
for cs in cp.scopes(_BINSCOPE_MASK):
467+
bins.extend(cs.coverItems(_BIN_MASK))
468+
self.write_coverpoint_bins(cpElem, iter(bins))
456469

457470
def write_coverpoint_bins(self, cpElem, coveritems : Iterator[CoverIndex]):
458471
# TODO: should probably organize bins into a structure that fits more nicely into the interchage format

0 commit comments

Comments
 (0)