22import unittest
33
44from chipflow_lib .platforms .utils import (
5- BareDiePackageDef , QuadPackageDef , Package
5+ BareDiePackageDef , QuadPackageDef , Package , GAPackageDef , GALayout , GAPin
66)
77
88
@@ -97,4 +97,160 @@ def test_package_type_access(self):
9797 self .assertEqual (self .package .package_type .type , "BareDiePackageDef" )
9898
9999 # Basic test of Package structure
100- self .assertIsInstance (self .package .package_type , BareDiePackageDef )
100+ self .assertIsInstance (self .package .package_type , BareDiePackageDef )
101+
102+
103+ class TestGAPackage (unittest .TestCase ):
104+ def test_gapin_creation (self ):
105+ """Test GAPin creation and equality"""
106+ pin1 = GAPin (h = "A" , w = 1 )
107+ pin2 = GAPin (h = "A" , w = 1 )
108+ pin3 = GAPin (h = "B" , w = 2 )
109+
110+ # Test equality
111+ self .assertEqual (pin1 , pin2 )
112+ self .assertNotEqual (pin1 , pin3 )
113+
114+ # Test attributes
115+ self .assertEqual (pin1 .h , "A" )
116+ self .assertEqual (pin1 .w , 1 )
117+ self .assertEqual (pin3 .h , "B" )
118+ self .assertEqual (pin3 .w , 2 )
119+
120+ def test_galayout_enum_values (self ):
121+ """Test GALayout enum values"""
122+ self .assertEqual (GALayout .FULL , "full" )
123+ self .assertEqual (GALayout .PERIMETER , "perimeter" )
124+ self .assertEqual (GALayout .CHANNEL , "channel" )
125+ self .assertEqual (GALayout .ISLAND , "island" )
126+
127+ def test_gapackagedef_class_structure (self ):
128+ """Test GAPackageDef class structure and type"""
129+ # Test that we can import and access the class
130+ from chipflow_lib .platforms .utils import BasePackageDef
131+
132+ # Test that GAPackageDef inherits from BasePackageDef
133+ self .assertTrue (issubclass (GAPackageDef , BasePackageDef ))
134+
135+ # Test that it has the correct type discriminator
136+ self .assertEqual (GAPackageDef .model_fields ['type' ].default , 'GAPackageDef' )
137+
138+ def test_gapackagedef_field_types (self ):
139+ """Test GAPackageDef field definitions"""
140+
141+ # Test that fields exist
142+ fields = GAPackageDef .model_fields
143+ self .assertIn ('name' , fields )
144+ self .assertIn ('width' , fields )
145+ self .assertIn ('height' , fields )
146+ self .assertIn ('layout_type' , fields )
147+ self .assertIn ('channel_width' , fields )
148+ self .assertIn ('island_width' , fields )
149+ self .assertIn ('missing_pins' , fields )
150+ self .assertIn ('additional_pins' , fields )
151+
152+ def test_gapackagedef_pydantic_model (self ):
153+ """Test GAPackageDef as a Pydantic model"""
154+
155+ # Test that it's a Pydantic model
156+ import pydantic
157+ self .assertTrue (issubclass (GAPackageDef , pydantic .BaseModel ))
158+
159+ # Test that it has the expected type field in model_fields
160+ self .assertIn ('type' , GAPackageDef .model_fields )
161+
162+ def test_missing_pins_configuration (self ):
163+ """Test missing pins configuration"""
164+ # Since GAPin is not hashable, test individual pins
165+ pin1 = GAPin (h = "A" , w = 1 )
166+ pin2 = GAPin (h = "B" , w = 2 )
167+ pin3 = GAPin (h = "C" , w = 3 )
168+
169+ # Test that pins can be created correctly
170+ self .assertEqual (pin1 .h , "A" )
171+ self .assertEqual (pin1 .w , 1 )
172+ self .assertEqual (pin2 .h , "B" )
173+ self .assertEqual (pin2 .w , 2 )
174+ self .assertEqual (pin3 .h , "C" )
175+ self .assertEqual (pin3 .w , 3 )
176+
177+ # Test that pins are equal to themselves
178+ self .assertEqual (pin1 , GAPin (h = "A" , w = 1 ))
179+ self .assertEqual (pin2 , GAPin (h = "B" , w = 2 ))
180+
181+ def test_additional_pins_configuration (self ):
182+ """Test additional pins configuration"""
183+ # Since GAPin is not hashable, test individual pins
184+ pin1 = GAPin (h = "D" , w = 4 )
185+ pin2 = GAPin (h = "E" , w = 5 )
186+
187+ # Test that additional pins can be created correctly
188+ self .assertEqual (pin1 .h , "D" )
189+ self .assertEqual (pin1 .w , 4 )
190+ self .assertEqual (pin2 .h , "E" )
191+ self .assertEqual (pin2 .w , 5 )
192+
193+ # Test equality
194+ self .assertEqual (pin1 , GAPin (h = "D" , w = 4 ))
195+ self .assertEqual (pin2 , GAPin (h = "E" , w = 5 ))
196+
197+ def test_layout_type_values (self ):
198+ """Test different layout type values"""
199+ # Test that GALayout values are correct
200+ self .assertEqual (GALayout .FULL .value , "full" )
201+ self .assertEqual (GALayout .PERIMETER .value , "perimeter" )
202+ self .assertEqual (GALayout .CHANNEL .value , "channel" )
203+ self .assertEqual (GALayout .ISLAND .value , "island" )
204+
205+ def test_package_public_api_methods (self ):
206+ """Test that expected public API methods exist"""
207+
208+ # Test that expected methods exist
209+ self .assertTrue (hasattr (GAPackageDef , 'allocate_pins' ))
210+ self .assertTrue (hasattr (GAPackageDef , 'bringup_pins' ))
211+ self .assertTrue (hasattr (GAPackageDef , 'heartbeat' ))
212+ self .assertTrue (hasattr (GAPackageDef , '_power' ))
213+ self .assertTrue (hasattr (GAPackageDef , '_jtag' ))
214+
215+ # Test that these are callable or properties
216+ self .assertTrue (callable (GAPackageDef .allocate_pins ))
217+ # bringup_pins, heartbeat, _power, _jtag are properties
218+
219+ def test_gapin_equality_operations (self ):
220+ """Test that GAPin equality works correctly"""
221+ pin1 = GAPin (h = "A" , w = 1 )
222+ pin2 = GAPin (h = "A" , w = 1 ) # Duplicate
223+ pin3 = GAPin (h = "B" , w = 2 )
224+
225+ # Test that GAPin equality works correctly
226+ self .assertEqual (pin1 , pin2 ) # pin1 and pin2 are equal
227+ self .assertNotEqual (pin1 , pin3 ) # pin1 and pin3 are different
228+ self .assertNotEqual (pin2 , pin3 ) # pin2 and pin3 are different
229+
230+ # Test that different coordinates create different pins
231+ self .assertNotEqual (GAPin (h = "A" , w = 1 ), GAPin (h = "A" , w = 2 ))
232+ self .assertNotEqual (GAPin (h = "A" , w = 1 ), GAPin (h = "B" , w = 1 ))
233+
234+ def test_gapin_string_representation (self ):
235+ """Test GAPin string representation"""
236+ pin = GAPin (h = "A" , w = 1 )
237+
238+ # Test that pin has reasonable string representation
239+ str_repr = str (pin )
240+ self .assertIn ("A" , str_repr )
241+ self .assertIn ("1" , str_repr )
242+
243+ def test_inheritance_from_basepackagedef (self ):
244+ """Test that GAPackageDef properly inherits from BasePackageDef"""
245+ from chipflow_lib .platforms .utils import BasePackageDef
246+
247+ # Test inheritance
248+ self .assertTrue (issubclass (GAPackageDef , BasePackageDef ))
249+
250+ # Test that abstract methods are implemented
251+ base_methods = [method for method in dir (BasePackageDef )
252+ if not method .startswith ('_' ) and callable (getattr (BasePackageDef , method , None ))]
253+
254+ for method in base_methods :
255+ self .assertTrue (hasattr (GAPackageDef , method ),
256+ f"GAPackageDef should implement { method } from BasePackageDef" )
0 commit comments