def visit_coverpoint(self, cp : CoverpointModel): from ucis.source_info import SourceInfo active_s = self.active_scope_s[-1] cp_name = cp.name decl_location = None if cp.srcinfo_decl is not None: decl_location = SourceInfo( self.get_file_handle(cp.srcinfo_decl.filename), cp.srcinfo_decl.lineno, 0) # Obtain weight from coverpoint # TODO: obtain from .options vs .type_options? weight = cp.options.weight # TODO: obtain at_least from coverpoint and set on cp_scope at_least = cp.options.at_least # TODO: obtain goal from coverpoint and set on cp_scope # TODO: obtain comment from coverpoint and set on cp_scope cp_scope = active_s.createCoverpoint( cp_name, decl_location, weight, # weight UCIS_OTHER) # Source type self.coverpoint_m[cp.name] = cp_scope # TODO: setAtLeast() # cp_scope.set for bi in range(cp.get_n_bins()): decl_location = None bn_name = cp.get_bin_name(bi) cp_bin = cp_scope.createBin( bn_name, decl_location, at_least, # at_least cp.get_bin_hits(bi), bn_name, UCIS_CVGBIN) for bi in range(cp.get_n_ignore_bins()): decl_location = None bn_name = cp.get_ignore_bin_name(bi) cp_bin = cp_scope.createBin( bn_name, decl_location, at_least, # at_least cp.get_ignore_bin_hits(bi), bn_name, UCIS_IGNOREBIN) for bi in range(cp.get_n_illegal_bins()): decl_location = None bn_name = cp.get_illegal_bin_name(bi) cp_bin = cp_scope.createBin( bn_name, decl_location, at_least, # at_least cp.get_illegal_bin_hits(bi), bn_name, UCIS_ILLEGALBIN)
def test_coverpoint_array_bin(self): cg = CovergroupModel("cg") a = 0 a_cp = CoverpointModel(ExprRefModel(lambda: a, 32, False), "a_cp", CoverageOptionsModel()) cg.add_coverpoint(a_cp) bins = a_cp.add_bin_model(CoverpointBinArrayModel("a", 0, 15)) cg.finalize() for i in range(8): a = i cg.sample() for i in range(16): if (i < 8): self.assertEqual(a_cp.get_bin_hits(i), 1) else: self.assertEqual(a_cp.get_bin_hits(i), 0) self.assertEqual(a_cp.get_coverage(), 50.0) self.assertEqual(cg.get_coverage(), 50.0)
def test_cross(self): stim = FieldCompositeModel("stim", True) f = FieldScalarModel("a", 16, False, True) stim.add_field(f) f2 = FieldScalarModel("b", 16, False, True) stim.add_field(f2) cg = CovergroupModel("cg") cp = CoverpointModel(ExprFieldRefModel(f), "cp1", CoverageOptionsModel()) cg.add_coverpoint(cp) bn = CoverpointBinArrayModel("cp", 0, 1, 16) cp.add_bin_model(bn) cp2 = CoverpointModel(ExprFieldRefModel(f2), "cp2", CoverageOptionsModel()) cg.add_coverpoint(cp2) bn = CoverpointBinArrayModel("cp", 0, 1, 16) cp2.add_bin_model(bn) cr = CoverpointCrossModel("aXb", CoverageOptionsModel()) cr.add_coverpoint(cp) cr.add_coverpoint(cp2) cg.add_coverpoint(cr) gen = GeneratorModel("top") gen.add_field(stim) gen.add_covergroup(cg) gen.finalize() # Need a special randomizer to deal with generators r = Randomizer() count = 0 for i in range(1000): r.do_randomize([gen]) cg.sample() count += 1 cov = cg.get_coverage() print("Coverage: (" + str(i) + ") " + str(cov)) if cov == 100: break self.assertEqual(cg.get_coverage(), 100) # Ensure that we converge relatively quickly self.assertLessEqual(count, (256+16+16))
def test_smoke(self): stim = FieldCompositeModel("stim", True) f = FieldScalarModel("a", 16, False, True) stim.add_field(f) f2 = FieldScalarModel("b", 16, False, True) stim.add_field(f2) cg = CovergroupModel("cg") cp = CoverpointModel(ExprFieldRefModel(f), "cp1", CoverageOptionsModel()) cg.add_coverpoint(cp) bn = CoverpointBinArrayModel("cp", 1, 16) cp.add_bin_model(bn) cp2 = CoverpointModel(ExprFieldRefModel(f2), "cp2", CoverageOptionsModel()) cg.add_coverpoint(cp2) bn = CoverpointBinArrayModel("cp", 1, 16) cp2.add_bin_model(bn) gen = GeneratorModel("top") gen.add_field(stim) gen.add_covergroup(cg) gen.finalize() # Need a special randomizer to deal with generators r = Randomizer(RandState(0)) randstate = RandState(0) count = 0 for i in range(1000): r.do_randomize(randstate, SourceInfo("", -1), [gen]) cg.sample() count += 1 cov = cg.get_coverage() if cov == 100: break self.assertEqual(cg.get_coverage(), 100) # Ensure that we converge relatively quickly self.assertLessEqual(count, 32)
def test_coverpoint_bins(self): stim = FieldCompositeModel("stim", True) f = FieldScalarModel("a", 16, False, True) stim.add_field(f) f2 = FieldScalarModel("b", 16, False, True) stim.add_field(f2) cg = CovergroupModel("cg") cp = CoverpointModel(ExprFieldRefModel(f), "cp1") cg.add_coverpoint(cp) cp.add_bin_model(CoverpointBinArrayModel("bn1", 1, 16)) cp.add_bin_model( CoverpointBinCollectionModel.mk_collection( "bn2", RangelistModel([[17, 65535 - 16 - 1]]), 16)) cp.add_bin_model(CoverpointBinArrayModel("bn3", 65535 - 16, 65535)) cp2 = CoverpointModel(ExprFieldRefModel(f2), "cp2") cg.add_coverpoint(cp2) bn = CoverpointBinArrayModel("cp", 1, 16) cp2.add_bin_model(bn) gen = GeneratorModel("top") gen.add_field(stim) gen.add_covergroup(cg) gen.finalize() # Need a special randomizer to deal with generators r = Randomizer() count = 0 for i in range(1000): r.do_randomize([gen]) cg.sample() count += 1 cov = cg.get_coverage() if cov == 100: break self.assertEqual(cg.get_coverage(), 100) # Ensure that we converge relatively quickly self.assertLessEqual(count, 64)