def test_partition_mixed_nonconsecutive_values(self): rangelist = RangelistModel( [1, 3, 5, [7, 10], 12, [13, 15], 17, [19, 22]]) bins = CoverpointBinCollectionModel.mk_collection("bin", rangelist, 4) bins.finalize(0) self.assertEqual(4, len(bins.bin_l)) self.assertEqual(4, bins.get_n_bins())
def test_partition_mixed_consecutive_values(self): rangelist = RangelistModel( [1, 2, 3, [4, 7], 8, 11, 13, [9, 13], 14, 15]) bins = CoverpointBinCollectionModel.mk_collection("bin", rangelist, 4) bins.finalize(0) self.assertEqual(4, len(bins.bin_l)) self.assertEqual(4, bins.get_n_bins())
def test_partition_individual_nonconsecutive_values(self): rangelist = RangelistModel( [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) bins = CoverpointBinCollectionModel.mk_collection("bin", rangelist, 4) bins.finalize(0) self.assertEqual(4, len(bins.bin_l)) self.assertEqual(4, bins.get_n_bins()) for b in bins.bin_l: self.assertTrue(isinstance(b, CoverpointBinSingleBagModel))
def test_partition_single_range_odd(self): rangelist = RangelistModel([[1, 18]]) bins = CoverpointBinCollectionModel.mk_collection("bin", rangelist, 4) bins.finalize(0) self.assertEqual(4, len(bins.bin_l)) self.assertEqual(4, bins.get_n_bins()) self.assertTrue(isinstance(bins.bin_l[3], CoverpointBinSingleBagModel)) self.assertEqual(18, bins.bin_l[3].binspec.range_l[-1][1])
def test_partition_single_range_even(self): rangelist = RangelistModel([[1, 16]]) bins = CoverpointBinCollectionModel.mk_collection("bin", rangelist, 4) bins.finalize(0) self.assertEqual(4, len(bins.bin_l)) self.assertEqual(4, bins.get_n_bins()) self.assertTrue( isinstance(bins.bin_l[3], CoverpointBinSingleRangeModel)) self.assertEqual(16, bins.bin_l[3].target_val_high)
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", CoverageOptionsModel()) cg.add_coverpoint(cp) cp.add_bin_model(CoverpointBinArrayModel("bn1", 0, 1, 16)) cp.add_bin_model(CoverpointBinCollectionModel.mk_collection("bn2", RangelistModel([ [17,65535-16-1] ]), 16)) cp.add_bin_model(CoverpointBinArrayModel("bn3", 0, 65535-16, 65535)) cp2 = CoverpointModel(ExprFieldRefModel(f2), "cp2", CoverageOptionsModel()) cg.add_coverpoint(cp2) bn = CoverpointBinArrayModel("cp", 0, 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)