11import unittest
2+ import os
23
34from systemrdl import RDLCompiler , FieldNode , AddressableNode
45from systemrdl .importer import RDLImporter
56
7+ #-------------------------------------------------------------------------------
68class MyImporter (RDLImporter ):
7-
89 def import_file (self , path : str ) -> None :
910 super ().import_file (path )
1011
@@ -79,6 +80,7 @@ def import_file(self, path: str) -> None:
7980 "reg1.some_signal" , 0 )
8081 self .add_child (my_rf , reg1 )
8182
83+
8284class TypeNameErrorTestcaseImporter (RDLImporter ):
8385
8486 def import_file (self , path : str ) -> None :
@@ -90,6 +92,42 @@ def import_file(self, path: str) -> None:
9092 # Creates a register instance with an illegal name.
9193 reg_t = self .create_reg_definition ("illegal.type.name" )
9294
95+ #-------------------------------------------------------------------------------
96+ class TypeTestImporter (RDLImporter ):
97+ def import_file (self , path : str ) -> None :
98+ super ().import_file (path )
99+
100+ top = self .create_addrmap_definition ("top" )
101+ self .register_root_component (top )
102+
103+ reg = self .instantiate_reg (
104+ self .create_reg_definition (),
105+ "r" ,
106+ 0x0 ,
107+ )
108+ self .add_child (top , reg )
109+
110+ field = self .instantiate_field (
111+ self .create_field_definition (),
112+ "f" ,
113+ 0 ,
114+ 32 ,
115+ )
116+ self .add_child (reg , field )
117+
118+ self .assign_property (top , "udp_string" , "my string" )
119+ self .assign_property (top , "udp_string_array" , ["str1" , "str2" , "str3" ])
120+ self .assign_property (top , "udp_boolean" , True )
121+ self .assign_property (top , "udp_boolean_array" , [True , False , True ])
122+ self .assign_property (top , "udp_longint" , 123 )
123+ self .assign_property (top , "udp_longint_array" , [12 , 34 , 56 ])
124+
125+ self .assign_property (reg , "udp_string_array" , [])
126+ self .assign_property (reg , "udp_boolean_array" , [])
127+ self .assign_property (reg , "udp_longint_array" , [])
128+
129+ #-------------------------------------------------------------------------------
130+
93131class TestImporter (unittest .TestCase ):
94132 def test_importer (self ):
95133 rdlc = RDLCompiler ()
@@ -141,3 +179,28 @@ def test_illegal_type_name_import_raises_error(self):
141179 i = TypeNameErrorTestcaseImporter (rdlc )
142180 with self .assertRaisesRegex (ValueError , "Type name has invalid characters: 'illegal.type.name'" ):
143181 i .import_file ("asdf" )
182+
183+
184+ def test_importer_types (self ):
185+ rdlc = RDLCompiler ()
186+
187+ this_dir = os .path .dirname (os .path .realpath (__file__ ))
188+ rdlc .compile_file (os .path .join (this_dir , "rdl_src/incdir/importer_udps.rdl" ))
189+
190+ i = TypeTestImporter (rdlc )
191+ i .import_file ("asdf" )
192+
193+ root = rdlc .elaborate ()
194+
195+ top = root .top
196+ self .assertEqual (top .get_property ("udp_string" ), "my string" )
197+ self .assertListEqual (top .get_property ("udp_string_array" ), ["str1" , "str2" , "str3" ])
198+ self .assertIs (top .get_property ("udp_boolean" ), True )
199+ self .assertListEqual (top .get_property ("udp_boolean_array" ), [True , False , True ])
200+ self .assertEqual (top .get_property ("udp_longint" ), 123 )
201+ self .assertListEqual (top .get_property ("udp_longint_array" ), [12 , 34 , 56 ])
202+
203+ reg = top .get_child_by_name ("r" )
204+ self .assertListEqual (reg .get_property ("udp_string_array" ), [])
205+ self .assertListEqual (reg .get_property ("udp_boolean_array" ), [])
206+ self .assertListEqual (reg .get_property ("udp_longint_array" ), [])
0 commit comments