@@ -219,32 +219,49 @@ def test_instantiate_ports(self, mock_load_pinlock):
219219 # Check that pinlock was set
220220 self .assertEqual (platform .pinlock , mock_pinlock )
221221
222- @mock .patch ('chipflow_lib.platforms.silicon.load_pinlock' )
223- def test_instantiate_ports_missing_clock (self , mock_load_pinlock ):
224- """Test instantiate_ports method with missing clock"""
222+ def test_instantiate_ports_missing_clock (self ):
223+ """Test instantiate_ports method with missing clock directly"""
225224 # Import here to avoid issues during test collection
226- from chipflow_lib .platforms .silicon import SiliconPlatform
225+ from chipflow_lib .platforms .silicon import SiliconPlatform , load_pinlock , ChipFlowError
226+ from amaranth import Module
227227
228- # Create mocks
229- mock_pinlock = mock . MagicMock ()
230- mock_load_pinlock . return_value = mock_pinlock
231-
232- # Setup port_map
233- mock_pinlock . port_map = {}
228+ # Create a config with missing clock configuration
229+ # This deliberately causes an error to test error handling
230+ config_copy = self . config . copy ()
231+ config_copy [ "chipflow" ] = config_copy . get ( "chipflow" , {}). copy ()
232+ config_copy [ "chipflow" ][ "clocks" ] = { "default" : "non_existent_clock" }
233+ config_copy [ "chipflow" ][ "resets" ] = {}
234234
235- # Setup clocks and resets - empty
236- mock_pinlock .package .clocks = {}
237- mock_pinlock .package .resets = {"sys_rst_n" : mock .MagicMock ()}
235+ # Create platform with our modified config
236+ platform = SiliconPlatform (config_copy )
238237
239- # Create platform
240- platform = SiliconPlatform (self .config )
238+ # Make sure pinlock is not already set
239+ if hasattr (platform , "pinlock" ):
240+ del platform .pinlock
241241
242- # Create module
242+ # Create a Module
243243 m = Module ()
244244
245- # Call instantiate_ports - should raise ChipFlowError
246- with self .assertRaises (ChipFlowError ):
247- platform .instantiate_ports (m )
245+ # Create a custom TestPinlock with an empty clocks dict
246+ class TestPinlock :
247+ def __init__ (self ):
248+ self .port_map = {}
249+ self .package = mock .MagicMock ()
250+ self .package .clocks = {}
251+ self .package .resets = {}
252+
253+ # Patch the load_pinlock function directly
254+ original_load_pinlock = load_pinlock
255+ try :
256+ # Replace with our custom implementation
257+ load_pinlock .__globals__ ['load_pinlock' ] = lambda : TestPinlock ()
258+
259+ # Call instantiate_ports - should raise ChipFlowError
260+ with self .assertRaises (ChipFlowError ):
261+ platform .instantiate_ports (m )
262+ finally :
263+ # Restore the original function to avoid affecting other tests
264+ load_pinlock .__globals__ ['load_pinlock' ] = original_load_pinlock
248265
249266 def test_get_io_buffer (self ):
250267 """Test get_io_buffer method"""
0 commit comments