def test_tuple_unit(): test_ref = """ typedef struct packed { // (u1, ()) logic [0:0] f0; // u1 } data_t; """ svtype = svgen_typedef(Tuple[Uint[1], Unit], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_multiqueue(): test_ref = """ typedef struct packed { // [u16] logic [5:0] eot; // u1 logic [1:0] data; // u16 } data_t; """ svtype = svgen_typedef(Queue[Uint[2], 6], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_tuple(): test_ref = """ typedef struct packed { // (u1, u2) logic [1:0] f1; // u2 logic [0:0] f0; // u1 } data_t; """ svtype = svgen_typedef(Tuple[Uint[1], Uint[2]], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_seq_incompatible_to_t(): drv(t=Uint[2], seq=[(0, 0)]) | shred with pytest.raises(LogException) as excinfo: sim() assert equal_on_nonspace( str(excinfo.value), 'Cannot convert value "(0, 0)" to type "Uint[2]", in the module "/drv"' )
def test_incomplete_argument(): @gear def test(din) -> b'din': pass expected_err_text = """Input argument "din" has unresolved type "Integer"\n - when instantiating "test" """ with pytest.raises(GearArgsNotSpecified) as excinfo: test(Intf(Integer)) assert equal_on_nonspace(str(excinfo.value), expected_err_text)
def test_incomplete_type(): expected_err_text = """Incomplete type: Integer - when resolving return type \"t\"""" params = {'t': Integer, 'return': b't'} args = {} with pytest.raises(TypeMatchError) as excinfo: infer_ftypes(params, args) assert equal_on_nonspace(str(excinfo.value), expected_err_text)
def test_array_subtype(): test_ref = ''' typedef struct packed { // (u1, u3) logic [2:0] f1; // u3 logic [0:0] f0; // u1 } data_data_t; typedef data_data_t [3:0] data_t; // Array[(u1, u3), 4] ''' svtype = svgen_typedef(Array[Tuple[Uint[1], Uint[3]], 4], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_array_subtype(): test_ref = ''' typedef struct packed { // (u1, u3) logic [2:0] f1; // u3 logic [0:0] f0; // u1 } data_data_t; typedef data_data_t [3:0] data_t; // Array[(u1, u3), 4] ''' # TODO: Check why we need this second option sometimes test_ref_1 = ''' typedef struct packed { // (u1, u3) logic [2:0] f1; // u3 logic f0; // u1 } data_data_t; typedef data_data_t [3:0] data_t; // Array[(u1, u3), 4] ''' svtype = svgen_typedef(Array[Tuple[Uint[1], Uint[3]], 4], 'data') assert equal_on_nonspace(svtype, test_ref) or equal_on_nonspace( svtype, test_ref_1)
def test_namedtuple(): test_ref = """ typedef struct packed { // (u1, u2) logic [1:0] field2; // u2 logic [0:0] field1; // u1 } data_t; """ svtype = svgen_typedef(Tuple[{ 'field1': Uint[1], 'field2': Uint[2] }], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_templated_type_deduction_multi_related_templates_fail(): expected_err_text = """Ambiguous match for parameter "T1": Uint[2] and Uint[1] - when matching Tuple[Uint[1], Uint[2], Uint[2]] to Tuple['T1', Uint['T2'], 'T1'] - when deducing type for argument "din" """ params = { 'din': Tuple['T1', Uint['T2'], 'T1'], 'return': Tuple['T1', 'T2'] } args = {'din': Tuple[Uint[1], Uint[2], Uint[2]]} with pytest.raises(TypeMatchError) as excinfo: infer_ftypes(params, args) assert equal_on_nonspace(str(excinfo.value), expected_err_text)
def test_union_shallow(): test_ref = """ typedef struct packed { // u1 | u2 logic [0:0] ctrl; // u1 logic [1:0] data; // u1 | u2 } data_t; """ svtype = svgen_typedef(Union[{ 'alt1': Uint[1], 'alt2': Uint[2] }], 'data', depth=0) assert equal_on_nonspace(svtype, test_ref)
def test_tuple_multilevel(): test_ref = """ typedef struct packed { // (u3, u4) logic [3:0] f1; // u4 logic [2:0] f0; // u3 } data_f1_t; typedef struct packed { // (u1, u2) logic [1:0] f1; // u2 logic [0:0] f0; // u1 } data_f0_t; typedef struct packed { // ((u1, u2), (u3, u4)) data_f1_t f1; // (u3, u4) data_f0_t f0; // (u1, u2) } data_t; """ svtype = svgen_typedef( Tuple[Tuple[Uint[1], Uint[2]], Tuple[Uint[3], Uint[4]]], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_multiarray(): test_ref = "typedef logic [3:0] [1:0] [15:0] data_t; // Array[Array[u16, 2], 4]" svtype = svgen_typedef(Array[Array[Uint[16], 2], 4], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_uint(): test_ref = "typedef logic [15:0] data_t; // u16" svtype = svgen_typedef(Uint[16], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_array_signed(): test_ref = "typedef logic signed [3:0] [15:0] data_t; // Array[i16, 4]" svtype = svgen_typedef(Array[Int[16], 4], 'data') assert equal_on_nonspace(svtype, test_ref)
def test_int(): test_ref = "typedef logic signed [15:0] data_t; // i16" svtype = svgen_typedef(Int[16], 'data') assert equal_on_nonspace(svtype, test_ref)