Exemplo n.º 1
0
 def pre_randomize(self):
     # Set the size field for arrays that don't
     # have a random size
     if not self.is_rand_sz:
         self._set_size(len(self.field_l))
     else:
         self.size.set_used_rand(True)
     FieldCompositeModel.pre_randomize(self)
Exemplo n.º 2
0
    def test_smoke(self):
        obj = FieldCompositeModel("obj")
        a = obj.add_field(FieldScalarModel("a", 8, False, True))
        b = obj.add_field(FieldScalarModel("a", 8, False, True))
        obj.add_constraint(
            ConstraintBlockModel("c", [
                ConstraintExprModel(
                    ExprBinModel(a.expr(), BinExprType.Lt, b.expr()))
            ]))

        rand = Randomizer(RandState(0))
        randstate = RandState(0)

        rand.do_randomize(randstate, SourceInfo("", -1), [obj])

        self.assertLess(a.val, b.val)
Exemplo n.º 3
0
    def test_wide_var(self):
        obj = FieldCompositeModel("obj")
        a = obj.add_field(FieldScalarModel("a", 1024, False, True))
        obj.add_constraint(
            ConstraintBlockModel("c", [
                ConstraintExprModel(
                    ExprBinModel(
                        a.expr(), BinExprType.Gt,
                        ExprLiteralModel(0x80000000000000000, False, 72)))
            ]))

        randstate = RandState(0)
        rand = Randomizer(randstate)

        rand.do_randomize(randstate, SourceInfo("", -1), [obj])

        print("a=" + hex(int(a.val)))
        self.assertGreater(a.val, ValueScalar(0x80000000000000000))
Exemplo n.º 4
0
    def test_incr(self):
        obj = FieldCompositeModel("obj")
        arr = obj.add_field(
            FieldArrayModel(
                "arr",
                None,  # type_t
                True,  # is_scalar
                None,  # not an enum-type list
                32,
                False,
                True,
                False))
        for i in range(10):
            arr.add_field()
        obj.add_constraint(
            ConstraintBlockModel("XX", [
                ConstraintExprModel(
                    ExprBinModel(ExprFieldRefModel(arr.size), BinExprType.Eq,
                                 ExprLiteralModel(10, False, 32)))
            ]))
        foreach = ConstraintForeachModel(ExprFieldRefModel(arr))
        foreach.addConstraint(
            ConstraintImpliesModel(
                ExprBinModel(ExprFieldRefModel(foreach.index), BinExprType.Gt,
                             ExprLiteralModel(0, False, 32)),
                [
                    ConstraintExprModel(
                        ExprBinModel(
                            ExprArraySubscriptModel(
                                ExprFieldRefModel(arr),
                                ExprFieldRefModel(foreach.index)),
                            BinExprType.Eq,
                            ExprBinModel(
                                ExprArraySubscriptModel(
                                    ExprFieldRefModel(arr),
                                    ExprBinModel(
                                        ExprFieldRefModel(foreach.index),
                                        BinExprType.Sub,
                                        ExprLiteralModel(1, False, 32))),
                                BinExprType.Add, ExprLiteralModel(
                                    1, False, 32))))
                ]))

        obj.add_constraint(ConstraintBlockModel("c", [foreach]))

        #         print("Object: " + ModelPrettyPrinter.print(obj))
        #
        #         constraints = ArrayConstraintBuilder.build(obj)
        #         for c in constraints:
        #             print("Constraint: " + ModelPrettyPrinter.print(c))
        #         print("Object(1): " + ModelPrettyPrinter.print(obj))
        #
        #         ConstraintOverrideRollbackVisitor.rollback(obj)
        #         print("Object(2): " + ModelPrettyPrinter.print(obj))

        Randomizer.do_randomize([obj])

        for f in arr.field_l:
            print("" + f.name + ": " + str(int(f.get_val())))
Exemplo n.º 5
0
    def test_smoke(self):
        obj = FieldCompositeModel("obj")
        arr = obj.add_field(
            FieldArrayModel(
                "arr",
                None,  # type_t
                True,
                None,  # not an enum-type 
                32,
                False,
                True,
                True))
        #         for i in range(10):
        #             arr.add_field()
        obj.add_constraint(
            ConstraintBlockModel("XX", [
                ConstraintExprModel(
                    ExprBinModel(ExprFieldRefModel(arr.size), BinExprType.Eq,
                                 ExprLiteralModel(10, False, 32)))
            ]))

        foreach = ConstraintForeachModel(ExprFieldRefModel(arr))
        foreach.addConstraint(
            ConstraintExprModel(
                ExprBinModel(
                    ExprArraySubscriptModel(ExprFieldRefModel(arr),
                                            ExprFieldRefModel(foreach.index)),
                    BinExprType.Lt, ExprLiteralModel(10, False, 32))))

        obj.add_constraint(ConstraintBlockModel("c", [foreach]))

        #         print("Object: " + ModelPrettyPrinter.print(obj))
        #
        #         constraints = ArrayConstraintBuilder.build(obj)
        #         for c in constraints:
        #             print("Constraint: " + ModelPrettyPrinter.print(c))
        #         print("Object(1): " + ModelPrettyPrinter.print(obj))
        #
        #         ConstraintOverrideRollbackVisitor.rollback(obj)
        #         print("Object(2): " + ModelPrettyPrinter.print(obj))
        randstate = RandState(0)
        Randomizer.do_randomize(randstate, SourceInfo("", -1), [obj])

        for f in arr.field_l:
            print("" + f.name + ": " + str(int(f.get_val())))
Exemplo n.º 6
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))
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
 def post_randomize(self):
     FieldCompositeModel.post_randomize(self)
     self.sum_expr = None
     self.sum_expr_btor = None
Exemplo n.º 10
0
 def pre_randomize(self):
     # Set the size field for arrays that don't
     # have a random size
     if not self.is_rand_sz:
         self.size.set_val(len(self.field_l))
     FieldCompositeModel.pre_randomize(self)