mciepluc / cocotb-coverage

Functional Coverage and Constrained Randomization Extensions for Cocotb
BSD 2-Clause "Simplified" License
100 stars 15 forks source link

Various improvements suggestions #11

Closed mciepluc closed 5 years ago

mciepluc commented 5 years ago

I do have a little bit feedback.

Coverage

CRV

I hacked together something like this in my base transaction class:

from random import choice
from cocotb.crv import Randomized

class MyRandomized(Randomized):
    def __init__(self):
        super().__init__()
        self._rand_lists = {}

    def add_rand_list(self, name, lengths, values, pre_randomize=True):
        self._rand_lists[name] = (lengths, values, pre_randomize)
        setattr(self, name, [])

    def build_rand_lists(self, pre_randomize):
        for name, (lengths, values, pr) in self._rand_lists.items():
            if pre_randomize == pr:
                setattr(self, name, [choice(values) for x in range(choice(lengths))])

    def pre_randomize(self):
        self.build_rand_lists(pre_randomize=True)

    def post_randomize(self):
        self.build_rand_lists(pre_randomize=False)

Keep up the good work!

Originally posted by @jrpetrus in https://github.com/potentialventures/cocotb/pull/490#issuecomment-358652919

mciepluc commented 5 years ago

Most of the suggested enhancements have been added. Regarding building random dataset options, I don't see a need to do this, as there are different ways, depending on particular requirements.