def test_all(): # Bit type. assert make_value(type(Foo.a), BitVector[1](0)) == BitVector[1](0) assert make_value(type(Foo.a), 0) == BitVector[1](0) assert make_value(type(Foo.a), 1) == BitVector[1](1) assert make_value(type(Foo.a), AnyValue) == AnyValue assert make_value(type(Foo.a), UnknownValue) == UnknownValue with pytest.raises(NotImplementedError) as pytest_e: make_value(type(Foo.a), 2) assert False assert pytest_e.type == NotImplementedError # NOTE(rsetaluri): For the following 3 tests we use arbitray values as input # into the bit-vectors. The tests should pass for any number. # Bits type. assert make_value(type(Foo.b), BitVector[8](5)) == BitVector[8](5) assert make_value(type(Foo.b), 17) == BitVector[8](17) assert make_value(type(Foo.b), AnyValue) == AnyValue assert make_value(type(Foo.b), UnknownValue) == UnknownValue # Array(Bit) type. Should be the same as above. assert make_value(type(Foo.c), BitVector[12](83)) == BitVector[12](83) assert make_value(type(Foo.c), 23) == BitVector[12](23) assert make_value(type(Foo.c), AnyValue) == AnyValue assert make_value(type(Foo.c), UnknownValue) == UnknownValue # Array(Array(Bit)) type. assert make_value(type(Foo.d), 894) == Array([BitVector[20](894)] * 16, 16) assert make_value(type(Foo.d), AnyValue) == Array([AnyValue] * 16, 16) assert make_value(type(Foo.d), UnknownValue) == \ Array([UnknownValue] * 16, 16)
def test_all(): # Bit type. assert make_value(Foo.a, BitVector(0, 1)) == BitVector(0, 1) assert make_value(Foo.a, 0) == BitVector(0, 1) assert make_value(Foo.a, 1) == BitVector(1, 1) assert make_value(Foo.a, AnyValue) == AnyValue assert make_value(Foo.a, UnknownValue) == UnknownValue with pytest.raises(NotImplementedError) as pytest_e: make_value(Foo.a, 2) assert False assert pytest_e.type == NotImplementedError # NOTE(rsetaluri): For the following 3 tests we use arbitray values as input # into the bit-vectors. The tests should pass for any number. # Bits type. assert make_value(Foo.b, BitVector(5, 8)) == BitVector(5, 8) assert make_value(Foo.b, 17) == BitVector(17, 8) assert make_value(Foo.b, AnyValue) == AnyValue assert make_value(Foo.b, UnknownValue) == UnknownValue # Array(Bit) type. Should be the same as above. assert make_value(Foo.c, BitVector(83, 12)) == BitVector(83, 12) assert make_value(Foo.c, 23) == BitVector(23, 12) assert make_value(Foo.c, AnyValue) == AnyValue assert make_value(Foo.c, UnknownValue) == UnknownValue # Array(Array(Bit)) type. assert make_value(Foo.d, 894) == Array([BitVector(894, 20)] * 16, 16) assert make_value(Foo.d, AnyValue) == Array([AnyValue] * 16, 16) assert make_value(Foo.d, UnknownValue) == Array([UnknownValue] * 16, 16)
def make_array(T, N, value): assert isinstance(N, int) if isinstance(T, magma._BitKind): return make_bit_vector(N, value) if isinstance(T, magma.ArrayKind): if isinstance(value, list): return Array([make_array(T.T, T.N, value[i]) for i in range(N)], N) else: return Array([make_array(T.T, T.N, value) for _ in range(N)], N) raise NotImplementedError(T, N, value)
def test_tester_nested_arrays(): circ = TestNestedArraysCircuit builder = VectorBuilder(circ) expected = [] for i in range(3): val = random.randint(0, (1 << 4) - 1) builder.process(Poke(circ.I[i], BitVector[4](val))) builder.process(Expect(circ.O[i], BitVector[4](val))) expected.append(val) assert builder.vectors == [[Array(expected, 3), Array(expected, 3)]]