Ejemplo n.º 1
0
    def testSeeded(self):
        cls = self.__class__

        seeds = [
            {
                'a': 2
            },
            {
                'b': 4
            },
            ttypes.IntUnion(a=2),
            ttypes.IntUnion(b=4),
        ]

        constraints = {'seeds': seeds, 'p_random': 0, 'p_fuzz': 0}

        gen = self.struct_randomizer(constraints=constraints)

        def is_seed(val):
            if val.field == 1:
                return val.value == 2
            elif val.field == 2:
                return val.value == 4
            return False

        for _ in sm.xrange(cls.iterations):
            val = gen.generate()
            self.assertTrue(is_seed(val),
                            msg="Not a seed: %s (%s)" % (val, val.__dict__))
Ejemplo n.º 2
0
 def testSeededFuzz(self):
     cls = self.__class__
     seeds = [ttypes.IntUnion(a=20), ttypes.IntUnion(b=40)]
     constraints = {"seeds": seeds, "p_random": 0}
     gen = self.struct_randomizer(constraints=constraints)
     for _ in sm.xrange(cls.iterations):
         val = gen.generate()
         self.assertIsNotNone(
             val,
             ("The union should always be created. "
              "We don't know the expected values, "
              "just that they exist"),
         )