Skip to content

Commit

Permalink
Merge pull request #21 from apaiva/master
Browse files Browse the repository at this point in the history
Unit test to reproduce issue #20
  • Loading branch information
mballance authored Sep 28, 2024
2 parents a10e09e + 0723c21 commit e5f9c59
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/ucis/merge/db_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ def _merge_covergroup(self, dst_cg, src_cg_l):
self._merge_crosses(dst_cg, dst_cp_m, src_cg_l)

self._merge_coverinsts(dst_cg, src_cg_l)

pass


def _merge_coverinsts(self, dst_cg, src_cg_l):

cg_i_m = {}
Expand Down
14 changes: 10 additions & 4 deletions src/ucis/xml/xml_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from datetime import datetime
import logging
from io import StringIO
from logging import _srcfile
import sys
from typing import Dict
Expand All @@ -47,7 +48,12 @@ def __init__(self):
self.module_scope_m : Dict[str, MemScope] = {}
self.inst_scope_m : Dict[str, MemScope] = {}
pass


def loads(self, s) -> UCIS:
fp = StringIO(s)
return self.read(fp)


def read(self, file) -> UCIS:
tree = etree.parse(file)
root = tree.getroot()
Expand Down Expand Up @@ -337,16 +343,16 @@ def populateCoverpointType(self, cp_t, cp_bin_m):
kind)

def readCrossInst(self, cg_i, cr_e, cr_type_i, cp_m):
crossExpr = next(cr_e.iter("crossExpr"))
name = self.getAttr(cr_e, "name", "<unknown>")

cp_l = []
for cp_n in crossExpr.text.split(','):
for crossExpr in cr_e.iter("crossExpr"):
cp_n = crossExpr.text.strip()
logging.debug("cp_n=\"" + cp_n + "\"")
if cp_n in cp_m.keys():
cp_l.append(cp_m[cp_n])
else:
raise Exception("Cross " + name + " references missing coverpoint " + cp_n)
raise Exception("Cross " + cp_n + " references missing coverpoint " + cp_n)

srcinfo = None

Expand Down
122 changes: 122 additions & 0 deletions ve/unit/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ucis.report.coverage_report_builder import CoverageReportBuilder
from ucis.report.text_coverage_report_formatter import TextCoverageReportFormatter
from ucis.yaml.yaml_reader import YamlReader
from ucis.xml.xml_reader import XmlReader
from ucis.merge.db_merger import DbMerger


Expand Down Expand Up @@ -527,6 +528,127 @@ def test_1db_2ci_2cp_1cr(self):
self.assertEqual(rpt.covergroups[0].covergroups[1].coverpoints[0].coverage, 50.0)


def test_2db_2ci_2cp_1cr_xml(self):
db1_src = """
<UCIS xmlns:ucis="http://www.w3.org/2001/XMLSchema-instance" writtenBy="apaiva" writtenTime="2024-09-20T00:00:00" ucisVersion="1.0">
<sourceFiles fileName="__null__file__" id="1"/>
<sourceFiles fileName="&lt;unknown&gt;" id="2"/>
<sourceFiles fileName="/xxx/agents/l1_client_fcov.py" id="3"/>
<sourceFiles fileName="/xxx/agents/fpu/fpu_fcov.py" id="4"/>
<sourceFiles fileName="/xxx/instrn/instrn_fcov/instrn_fcov.py" id="5"/>
<sourceFiles fileName="/xxx/agents/unpack/unpack_fcov.py" id="6"/>
<sourceFiles fileName="/xxx/agents/pack/pack_fcov.py" id="7"/>
<historyNodes historyNodeId="0" logicalName="logicalName" physicalName="foo.ucis" kind="HistoryNodeKind.TEST" testStatus="true" simtime="0.0" timeunit="ns" runCwd="." cpuTime="0.0" seed="0" cmd="" args="" compulsory="0" date="2024-09-20T22:19:22" userName="user" cost="0.0" toolCategory="UCIS:simulator" ucisVersion="1.0" vendorId="unknown" vendorTool="unknown" vendorToolVersion="unknown"/>
<instanceCoverages name="cg_inst" key="0">
<id file="1" line="1" inlineCount="1"/>
<covergroupCoverage>
<cgInstance name="L1ClientOp" key="0">
<options/>
<coverpoint name="cp_101_in_fmt" key="0">
<options/>
<coverpointBin name="T6TensorStorageType.Float32" type="bins" key="0">
<range from="-1" to="-1">
<contents coverageCount="0"/>
</range>
</coverpointBin>
</coverpoint>
<coverpoint name="cp_blk_id" key="0">
<options/>
<coverpointBin name="cp_blk_id[0]" type="bins" key="0">
<range from="-1" to="-1">
<contents coverageCount="5"/>
</range>
</coverpointBin>
</coverpoint>
<cross name="cc_101_in_fmt_X_upk_id" key="0">
<options/>
<crossExpr>cp_101_in_fmt</crossExpr>
<crossExpr>cp_blk_id</crossExpr>
<crossBin name="&lt;T6TensorStorageType.Float32,cp_blk_id[0]&gt;" key="0" type="default">
<index>-1</index>
<contents coverageCount="0"/>
</crossBin>
<crossBin name="&lt;T6TensorStorageType.Float32,cp_blk_id[1]&gt;" key="0" type="default">
<index>-1</index>
<contents coverageCount="0"/>
</crossBin>
</cross>
</cgInstance>
</covergroupCoverage>
</instanceCoverages>
</UCIS>
"""
db2_src = """
<UCIS xmlns:ucis="http://www.w3.org/2001/XMLSchema-instance" writtenBy="apaiva" writtenTime="2024-09-20T00:00:00" ucisVersion="1.0">
<sourceFiles fileName="__null__file__" id="1"/>
<sourceFiles fileName="&lt;unknown&gt;" id="2"/>
<sourceFiles fileName="/xxx/agents/l1_client_fcov.py" id="3"/>
<sourceFiles fileName="/xxx/agents/fpu/fpu_fcov.py" id="4"/>
<sourceFiles fileName="/xxx/instrn/instrn_fcov/instrn_fcov.py" id="5"/>
<sourceFiles fileName="/xxx/agents/unpack/unpack_fcov.py" id="6"/>
<sourceFiles fileName="/xxx/agents/pack/pack_fcov.py" id="7"/>
<historyNodes historyNodeId="0" logicalName="logicalName" physicalName="foo.ucis" kind="HistoryNodeKind.TEST" testStatus="true" simtime="0.0" timeunit="ns" runCwd="." cpuTime="0.0" seed="0" cmd="" args="" compulsory="0" date="2024-09-20T22:19:22" userName="user" cost="0.0" toolCategory="UCIS:simulator" ucisVersion="1.0" vendorId="unknown" vendorTool="unknown" vendorToolVersion="unknown"/>
<instanceCoverages name="cg_inst" key="0">
<id file="1" line="1" inlineCount="1"/>
<covergroupCoverage>
<cgInstance name="L1ClientOp" key="0">
<options/>
<coverpoint name="cp_101_in_fmt" key="0">
<options/>
<coverpointBin name="T6TensorStorageType.Float32" type="bins" key="0">
<range from="-1" to="-1">
<contents coverageCount="0"/>
</range>
</coverpointBin>
</coverpoint>
<coverpoint name="cp_blk_id" key="0">
<options/>
<coverpointBin name="cp_blk_id[0]" type="bins" key="0">
<range from="-1" to="-1">
<contents coverageCount="5"/>
</range>
</coverpointBin>
<coverpointBin name="cp_blk_id[1]" type="bins" key="0">
<range from="-1" to="-1">
<contents coverageCount="5"/>
</range>
</coverpointBin>
</coverpoint>
<cross name="cc_101_in_fmt_X_upk_id" key="0">
<options/>
<crossExpr>cp_101_in_fmt</crossExpr>
<crossExpr>cp_blk_id</crossExpr>
<crossBin name="&lt;T6TensorStorageType.Float32,cp_blk_id[0]&gt;" key="0" type="default">
<index>-1</index>
<contents coverageCount="0"/>
</crossBin>
<crossBin name="&lt;T6TensorStorageType.Float32,cp_blk_id[1]&gt;" key="0" type="default">
<index>-1</index>
<contents coverageCount="0"/>
</crossBin>
</cross>
</cgInstance>
</covergroupCoverage>
</instanceCoverages>
</UCIS>
"""

src_db = []
src_db.append(XmlReader().loads(db1_src))
src_db.append(XmlReader().loads(db2_src))

rpt = CoverageReportBuilder.build(src_db[0])

dst_db = MemFactory.create()

merger = DbMerger()
merger.merge(dst_db, src_db)

self.assertEqual(len(dst_db.m_children), 2)
self.assertEqual(len(dst_db.m_children[1].m_children[0].m_children), 4)
self.assertEqual(len(dst_db.m_children[1].m_children[0].m_children[2].coverpoints), 2)
self.assertEqual(len(dst_db.m_children[1].m_children[0].m_children[3].m_children[2].coverpoints), 2)

def test_2db_2ci_2cp_1cr(self):
db1_src = """
coverage:
Expand Down

0 comments on commit e5f9c59

Please sign in to comment.