Ejemplo n.º 1
0
def test_make_pair():
    dut = wrap_to_cl(translate(PairTestModel()))
    dut.reset()

    thing1 = MyType(10, 20)
    thing1.w1 = 0b1010101010
    thing1.w2 = 0b01010101010101010101
    # sets w3 to 00011
    thing1.w4 = 0b1111100011
    thing2 = MyType(10, 20)
    thing2.w1 = ~Bits(10, 0b1010101010)
    thing2.w2 = ~Bits(20, 0b01010101010101010101)
    # sets w3 to 00011
    thing2.w4 = ~Bits(10, 0b1111100011)

    result = dut.make_pair(a=thing1, b=thing2)
    assert result.pair.first_w1 == thing1.w1
    assert result.pair.first_w2 == thing1.w2
    assert result.pair.first_w3 == thing1.w3
    assert result.pair.first_w4 == thing1.w4
    assert result.pair.first == thing1
    assert result.pair.second_w1 == thing2.w1
    assert result.pair.second_w2 == thing2.w2
    assert result.pair.second_w3 == thing2.w3
    assert result.pair.second_w4 == thing2.w4
    assert result.pair.second == thing2
Ejemplo n.º 2
0
def test_struct_mux():
    mux = wrap_to_cl(translate(Mux(MyType(10, 20), 4)))

    mux.reset()
    result = mux.mux(in_=[0b0001, 0b0010, 0b1000, 0b1000], select=0b00)
    assert result.out == 0b0001
    mux.cycle()
    result = mux.mux(in_=[0b0001, 0b0010, 0b1000, 0b1000], select=0b01)
    assert result.out == 0b0010
Ejemplo n.º 3
0
def test_struct_decompose():
    decomposer = wrap_to_cl(translate(StructTestModel()))

    decomposer.reset()

    thing = MyType(10, 20)
    thing.w1 = 0b1010101010
    thing.w2 = 0b01010101010101010101
    # sets w3 to 00011
    thing.w4 = 0b1111100011

    result = decomposer.decompose(thing)
    assert result.w1 == thing.w1
    assert result.w2 == thing.w2
    assert result.w3 == thing.w3
    assert result.w4 == thing.w4
Ejemplo n.º 4
0
def test_basic():
  rtl_dut = PipelinedCounter()
  rtl_dut.vcd_file = 'bob.vcd'
  dut = wrap_to_cl(translate(rtl_dut))
  # dut = wrap_to_cl(rtl_dut)

  dut.reset()
  assert isinstance(dut.peek(), NotReady)

  dut.cycle()
  assert dut.peek().msg == 2

  dut.cycle()
  assert dut.peek().msg == 2
  dut.take()

  dut.cycle()
  assert dut.peek().msg == 3
Ejemplo n.º 5
0
def TestHarness(target,
                dut,
                translate_model,
                vcd_file='',
                use_cached_verilated=False):
    test_harness_interface = Interface([], bases=[IncludeAll(dut.interface)])
    UseInterface(target, test_harness_interface)

    if translate_model:
        dut.vcd_file = vcd_file
        target.dut = translate(dut, use_cached_verilated=use_cached_verilated)
    else:
        target.dut = dut

    for name in target.interface.methods.keys():
        target.connect_m(getattr(target, name), getattr(target.dut, name))

    target.vcd_file = vcd_file
Ejemplo n.º 6
0
def test_translation():
    translate(ALU(ALUInterface(64)))
Ejemplo n.º 7
0
def test_translate():
    translate(
        DataFlowManager(DataFlowManagerInterface(64, 32, 64, 4, 2, 2, 1, 4,
                                                 1)))
Ejemplo n.º 8
0
    def _create_test_state_machine(rtl_class,
                                   reference_class,
                                   parameters,
                                   argument_strategy={},
                                   translate_model=False,
                                   release_cycle_accuracy=False,
                                   customized_comparators={}):

        if isinstance(parameters, dict):
            parameters_string = "_".join(
                [str(parameter) for parameter in parameters.values()])
            model = rtl_class(**parameters)
            reference = reference_class(**parameters)
        else:
            if not isinstance(parameters, tuple):
                parameters = (parameters, )
            parameters_string = "_".join(
                [str(parameter) for parameter in parameters])
            model = rtl_class(*parameters)
            reference = reference_class(*parameters)
        if translate_model:
            model = translate(model)
        model.vcd_file = "machine.vcd"
        sim = wrap_to_cl(model)

        Test = type(
            type(model).__name__ + "TestStateMachine_" + parameters_string,
            TestModel.__bases__, dict(TestModel.__dict__))

        Test.interface = None
        if type(model.interface) != type(reference.interface):
            raise RunMethodTestError(
                "Model and reference interface don't match!")

        Test.interface = model.interface

        for k, v in inspect.getmembers(reference):

            precondition = getattr(v, REFERENCE_PRECONDITION_MARKER, None)

            if precondition != None:
                Test.add_precondition(method_name_fl,
                                      precondition.precondition)

            if isinstance(v, MethodStrategy):
                for method, strategy in inspect.getmembers(v):
                    if isinstance(strategy, ArgumentStrategy):
                        Test.add_argument_strategy(method, strategy.arguments)

        for method, arguments in argument_strategy.iteritems():
            if isinstance(arguments, ArgumentStrategy):
                arguments = arguments.arguments
            Test.add_argument_strategy(method, arguments)

        if not Test.interface:
            raise RunMethodTestError(
                "Get rtl model with no interface specified! ")
        # make sure that all method arguments have strategy specified
        error_msg = """
    Found argument with no strategy specified!
      - method name : {method_name}
      - arg         : {arg}
  """
        for name, spec in Test.interface.methods.iteritems():
            strategies = Test.argument_strategy(name)
            for arg, dtype in spec.args.iteritems():
                if not strategies.has_key(arg):
                    strategies[arg] = ArgumentStrategy.get_strategy_from_type(
                        dtype)
                    if not strategies[arg]:
                        raise RunMethodTestError(
                            error_msg.format(method_name=name, arg=arg))

        # add rule
        for name, spec in Test.interface.methods.iteritems():
            add_rule(Test, spec)

        Test.sim = sim
        Test.reference = reference
        Test.release_cycle_accuracy = release_cycle_accuracy
        Test.set_comparators(customized_comparators)

        return Test
Ejemplo n.º 9
0
def test_translate():
    translate(Proc(ProcInterface(), MemMsg(8, 2, 64, 8)))
Ejemplo n.º 10
0
def test_translation():
  translate(Comparator(ComparatorInterface(64)))
Ejemplo n.º 11
0
def test_functional_form():
    dut = wrap_to_cl(translate(FunctionalFormTestModel()))

    dut.reset()

    assert dut.add_w4(a=0b00001111, b=0b00001001).sum == 0b11111000