Exemplo n.º 1
0
    def read(file_or_filename) -> UCIS:
        """Reads the specified XML file and returns a UCIS representation"""

        # First, validate the incoming XML
        if type(file_or_filename) == str:
            fp = open(file_or_filename)
        else:
            fp = file_or_filename

        try:
            validate_ucis_xml(fp)
        except:
            if type(file_or_filename) == str:
                fp.close()

        fp.seek(0)

        reader = XmlReader()

        try:
            ret = reader.read(fp)
        finally:
            if type(file_or_filename) == str:
                fp.close()

        return ret
Exemplo n.º 2
0
    def test_simplest_create(self):
        print("-- test_simplest_create")

        ucisdb = "file.ucis"
        db = MemFactory.create()

        testnode = db.createHistoryNode(None, "logicalName", ucisdb,
                                        UCIS_HISTORYNODE_TEST)
        td = TestData(teststatus=UCIS_TESTSTATUS_OK,
                      toolcategory="UCIS:simulator",
                      date="20200202020")
        testnode.setTestData(td)

        file = db.createFileHandle("dummy", os.getcwd())

        srcinfo = SourceInfo(file, 0, 0)
        du = db.createScope(
            "foo.bar",
            srcinfo,
            1,  # weight
            UCIS_OTHER,
            UCIS_DU_MODULE,
            UCIS_ENABLED_STMT | UCIS_ENABLED_BRANCH
            | UCIS_ENABLED_COND | UCIS_ENABLED_EXPR
            | UCIS_ENABLED_FSM | UCIS_ENABLED_TOGGLE
            | UCIS_INST_ONCE | UCIS_SCOPE_UNDER_DU)

        instance = db.createInstance(
            "dummy",
            None,  # sourceinfo
            1,  # weight
            UCIS_OTHER,
            UCIS_INSTANCE,
            du,
            UCIS_INST_ONCE)

        cg = instance.createCovergroup(
            "cg",
            SourceInfo(file, 3, 0),
            1,  # weight
            UCIS_OTHER)

        cp = cg.createCoverpoint(
            "t",
            SourceInfo(file, 4, 0),
            1,  # weight
            UCIS_VLOG)
        cp.setComment("Hello There")

        cp.createBin("auto[a]", SourceInfo(file, 4, 0), 1, 4, "a")

        out = StringIO()
        writer = XmlWriter()
        writer.write(out, db)

        print("XML Output:\n" + out.getvalue())
        input = StringIO(out.getvalue())
        validate_ucis_xml(input)
Exemplo n.º 3
0
    def disabled_test_smoke(self):
        db = MemFactory.create()

        srcF = db.createFileHandle("/home/foobar", None)
        histN = db.createHistoryNode(None, "abc")
        coverI = db.createCoverInstance("my_cg", StatementId(srcF, 1, 1))
        out = io.StringIO()
        XmlFactory.write(db, out)

        print("output:\n" + out.getvalue())

        xml_in = io.StringIO(out.getvalue())
        validate_ucis_xml(xml_in)

        xml_in = io.StringIO(out.getvalue())
        db2 = XmlFactory.read(xml_in)

        out2 = io.StringIO()
        XmlFactory.write(db2, out2)
        print("output2:\n" + out2.getvalue())
Exemplo n.º 4
0
    def disabled_test_validate(self):
        document = """
<ucis:UCIS xmlns:ucis="UCIS" ucisVersion="1.0"  writtenBy="$USER"
 writtenTime="2008-09-29T03:49:45">
<ucis:sourceFiles  fileName="string" id="201" />
</ucis:UCIS>        
        """
        #        document = """
        #<ucis:UCIS xmlns:ucis="UCIS" ucisVersion="1.0" writtenBy="foo" writtenTime="20200101">
        #  <ucis:sourceFiles fileName="/home/foobar" id="0"/>
        #  <ucis:historyNodes historyNodeId="0" logicalName="abc" testStatus="False"/>
        #  <ucis:instanceCoverages name="my_cg" key="0">
        #    <ucis:id file="0" line="1" inlineCount="1"/>
        #  </ucis:instanceCoverages>
        #</ucis:UCIS>
        #        """

        file_i = io.StringIO(document)

        print("Document: " + file_i.getvalue())

        validate_ucis_xml(file_i)
Exemplo n.º 5
0
    def test_smoke(self):
        print("-- test_simplest_create")

        ucisdb = "file.ucis"
        db = MemFactory.create()

        testnode = db.createHistoryNode(None, "logicalName", ucisdb,
                                        UCIS_HISTORYNODE_TEST)
        td = TestData(teststatus=UCIS_TESTSTATUS_OK,
                      toolcategory="UCIS:simulator",
                      date="20200202020")
        testnode.setTestData(td)

        file = db.createFileHandle("dummy", os.getcwd())

        srcinfo = SourceInfo(file, 0, 0)
        du = db.createScope(
            "foo.bar",
            srcinfo,
            1,  # weight
            UCIS_OTHER,
            UCIS_DU_MODULE,
            UCIS_ENABLED_STMT | UCIS_ENABLED_BRANCH
            | UCIS_ENABLED_COND | UCIS_ENABLED_EXPR
            | UCIS_ENABLED_FSM | UCIS_ENABLED_TOGGLE
            | UCIS_INST_ONCE | UCIS_SCOPE_UNDER_DU)

        instance = db.createInstance(
            "my_inst_scope",
            None,  # sourceinfo
            1,  # weight
            UCIS_OTHER,
            UCIS_INSTANCE,
            du,
            UCIS_INST_ONCE)

        cg = instance.createCovergroup(
            "cg",
            SourceInfo(file, 3, 0),
            1,  # weight
            UCIS_OTHER)

        cp1 = cg.createCoverpoint(
            "cp1",
            SourceInfo(file, 4, 0),
            1,  # weight
            UCIS_VLOG)

        cp1.createBin("v[1]", SourceInfo(file, 4, 0), 1, 4, "v")
        cp1.createBin("v[2]", SourceInfo(file, 4, 0), 1, 4, "v")

        cp2 = cg.createCoverpoint(
            "cp2",
            SourceInfo(file, 4, 0),
            1,  # weight
            UCIS_VLOG)

        cp2.createBin("v2[1]", SourceInfo(file, 4, 0), 1, 4, "v2")
        cp2.createBin("v2[2]", SourceInfo(file, 4, 0), 1, 4, "v2")

        cr = cg.createCross("cr", SourceInfo(file, 4, 0), 1, UCIS_VLOG,
                            [cp1, cp2])

        cr.createBin("<v1[1],v2[1]>", SourceInfo(file, 4, 0), 1, 4, "v1,v2")

        cr.createBin("<v1[2],v2[1]>", SourceInfo(file, 4, 0), 1, 4, "v1,v2")

        cr.createBin("<v1[1],v2[2]>", SourceInfo(file, 4, 0), 1, 4, "v1,v2")

        cr.createBin("<v1[2],v2[2]>", SourceInfo(file, 4, 0), 1, 4, "v1,v2")

        out = StringIO()
        writer = XmlWriter()
        writer.write(out, db)

        print("XML Output:\n" + out.getvalue())
        input = StringIO(out.getvalue())
        validate_ucis_xml(input)

        input = StringIO(out.getvalue())
        reader = XmlReader()
        db2 = reader.read(input)

        out2 = StringIO()
        writer = XmlWriter()
        writer.write(out2, db2)
        print("XML Output2:\n" + out2.getvalue())
        input = StringIO(out2.getvalue())
        validate_ucis_xml(input)
Exemplo n.º 6
0
 def validate(file_or_filename):
     validate_ucis_xml(file_or_filename)