From 13447a9298fc7bc30e5fce5f111798367ca181e6 Mon Sep 17 00:00:00 2001 From: Armond Paiva Date: Mon, 23 Sep 2024 15:45:56 +0000 Subject: [PATCH 1/3] Adds string based XML load --- src/ucis/xml/xml_reader.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ucis/xml/xml_reader.py b/src/ucis/xml/xml_reader.py index 102cc1e..e3d181a 100644 --- a/src/ucis/xml/xml_reader.py +++ b/src/ucis/xml/xml_reader.py @@ -22,6 +22,7 @@ from datetime import datetime import logging +from io import StringIO from logging import _srcfile import sys from typing import Dict @@ -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() From da86ebb2e093ace4e5d9a45ec387a5e9ae014d7d Mon Sep 17 00:00:00 2001 From: Armond Paiva Date: Mon, 23 Sep 2024 15:46:36 +0000 Subject: [PATCH 2/3] Adds unit test test_2db_2ci_2cp_1cr_xml --- ve/unit/test_merge.py | 122 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/ve/unit/test_merge.py b/ve/unit/test_merge.py index 009fdf5..4415698 100644 --- a/ve/unit/test_merge.py +++ b/ve/unit/test_merge.py @@ -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 @@ -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 = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + cp_101_in_fmt + cp_blk_id + + -1 + + + + -1 + + + + + + + + """ + db2_src = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + cp_101_in_fmt + cp_blk_id + + -1 + + + + -1 + + + + + + + + """ + + 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: From 0723c219951acc480335f88a5c40f4606a66d18c Mon Sep 17 00:00:00 2001 From: Armond Paiva Date: Sat, 28 Sep 2024 20:39:23 +0000 Subject: [PATCH 3/3] Second fix re issue #20 in xml_reader --- src/ucis/merge/db_merger.py | 4 +--- src/ucis/xml/xml_reader.py | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/ucis/merge/db_merger.py b/src/ucis/merge/db_merger.py index 57cf7fd..1b9ee9b 100644 --- a/src/ucis/merge/db_merger.py +++ b/src/ucis/merge/db_merger.py @@ -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 = {} diff --git a/src/ucis/xml/xml_reader.py b/src/ucis/xml/xml_reader.py index e3d181a..c51da9a 100644 --- a/src/ucis/xml/xml_reader.py +++ b/src/ucis/xml/xml_reader.py @@ -343,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", "") 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