2222from vunit .vhdl_standard import VHDL
2323
2424
25+ def _get_test_path ():
26+ return Path (__file__ ).parent / "test_modelsim_out"
27+
28+
29+ def _get_prefix_path ():
30+ return _get_test_path () / "prefix" / "bin"
31+
32+
33+ def _get_installed_modelsim_ini ():
34+ return (_get_prefix_path () / ".." / "modelsim.ini" ).resolve ()
35+
36+
2537class TestModelSimInterface (unittest .TestCase ):
2638 """
2739 Test the ModelSim interface
2840 """
2941
42+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
3043 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
3144 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
32- def test_compile_project_vhdl_2008 (self , process , check_output ):
45+ def test_compile_project_vhdl_2008 (self , process , check_output , get_modelsim_ini ):
3346 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
3447 project = Project ()
3548 project .add_library ("lib" , "lib_path" )
@@ -50,9 +63,10 @@ def test_compile_project_vhdl_2008(self, process, check_output):
5063 ]
5164 check_output .assert_called_once_with (check_args , env = simif .get_env ())
5265
66+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
5367 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
5468 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
55- def test_compile_project_vhdl_2002 (self , process , check_output ):
69+ def test_compile_project_vhdl_2002 (self , process , check_output , get_modelsim_ini ):
5670 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
5771 project = Project ()
5872 project .add_library ("lib" , "lib_path" )
@@ -73,9 +87,10 @@ def test_compile_project_vhdl_2002(self, process, check_output):
7387 ]
7488 check_output .assert_called_once_with (check_args , env = simif .get_env ())
7589
90+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
7691 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
7792 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
78- def test_compile_project_vhdl_93 (self , process , check_output ):
93+ def test_compile_project_vhdl_93 (self , process , check_output , get_modelsim_ini ):
7994 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
8095 project = Project ()
8196 project .add_library ("lib" , "lib_path" )
@@ -96,9 +111,10 @@ def test_compile_project_vhdl_93(self, process, check_output):
96111 ]
97112 check_output .assert_called_once_with (check_args , env = simif .get_env ())
98113
114+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
99115 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
100116 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
101- def test_compile_project_vhdl_extra_flags (self , process , check_output ):
117+ def test_compile_project_vhdl_extra_flags (self , process , check_output , get_modelsim_ini ):
102118 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
103119 project = Project ()
104120 project .add_library ("lib" , "lib_path" )
@@ -122,9 +138,10 @@ def test_compile_project_vhdl_extra_flags(self, process, check_output):
122138 ]
123139 check_output .assert_called_once_with (check_args , env = simif .get_env ())
124140
141+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
125142 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
126143 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
127- def test_compile_project_verilog (self , process , check_output ):
144+ def test_compile_project_verilog (self , process , check_output , get_modelsim_ini ):
128145 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
129146 project = Project ()
130147 project .add_library ("lib" , "lib_path" )
@@ -146,9 +163,10 @@ def test_compile_project_verilog(self, process, check_output):
146163 ]
147164 check_output .assert_called_once_with (check_args , env = simif .get_env ())
148165
166+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
149167 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
150168 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
151- def test_compile_project_system_verilog (self , process , check_output ):
169+ def test_compile_project_system_verilog (self , process , check_output , get_modelsim_ini ):
152170 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
153171 project = Project ()
154172 project .add_library ("lib" , "lib_path" )
@@ -171,9 +189,10 @@ def test_compile_project_system_verilog(self, process, check_output):
171189 ]
172190 check_output .assert_called_once_with (check_args , env = simif .get_env ())
173191
192+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
174193 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
175194 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
176- def test_compile_project_verilog_extra_flags (self , process , check_output ):
195+ def test_compile_project_verilog_extra_flags (self , process , check_output , get_modelsim_ini ):
177196 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
178197 project = Project ()
179198 project .add_library ("lib" , "lib_path" )
@@ -198,9 +217,10 @@ def test_compile_project_verilog_extra_flags(self, process, check_output):
198217 ]
199218 check_output .assert_called_once_with (check_args , env = simif .get_env ())
200219
220+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
201221 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
202222 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
203- def test_compile_project_verilog_include (self , process , check_output ):
223+ def test_compile_project_verilog_include (self , process , check_output , get_modelsim_ini ):
204224 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
205225 project = Project ()
206226 project .add_library ("lib" , "lib_path" )
@@ -223,9 +243,10 @@ def test_compile_project_verilog_include(self, process, check_output):
223243 ]
224244 check_output .assert_called_once_with (check_args , env = simif .get_env ())
225245
246+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
226247 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
227248 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
228- def test_compile_project_verilog_define (self , process , check_output ):
249+ def test_compile_project_verilog_define (self , process , check_output , get_modelsim_ini ):
229250 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
230251 project = Project ()
231252 project .add_library ("lib" , "lib_path" )
@@ -251,11 +272,12 @@ def test_compile_project_verilog_define(self, process, check_output):
251272 def _get_inis (self ):
252273 return (
253274 str (Path (self .output_path ) / "modelsim.ini" ),
254- str (Path ( self . prefix_path ) / ".." / "modelsim.ini" ),
275+ str (_get_installed_modelsim_ini () ),
255276 str (Path (self .test_path ) / "my_modelsim.ini" ),
256277 )
257278
258- def test_copies_modelsim_ini_file_from_install (self ):
279+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
280+ def test_copies_modelsim_ini_file_from_install (self , get_modelsim_ini ):
259281 (modelsim_ini , installed_modelsim_ini , user_modelsim_ini ) = self ._get_inis ()
260282
261283 with open (installed_modelsim_ini , "w" ) as fptr :
@@ -268,7 +290,8 @@ def test_copies_modelsim_ini_file_from_install(self):
268290 with open (modelsim_ini , "r" ) as fptr :
269291 self .assertEqual (fptr .read (), "installed" )
270292
271- def test_copies_modelsim_ini_file_from_user (self ):
293+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
294+ def test_copies_modelsim_ini_file_from_user (self , get_modelsim_ini ):
272295 (modelsim_ini , installed_modelsim_ini , user_modelsim_ini ) = self ._get_inis ()
273296
274297 with open (installed_modelsim_ini , "w" ) as fptr :
@@ -283,7 +306,8 @@ def test_copies_modelsim_ini_file_from_user(self):
283306 with open (modelsim_ini , "r" ) as fptr :
284307 self .assertEqual (fptr .read (), "user" )
285308
286- def test_overwrites_modelsim_ini_file_from_install (self ):
309+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
310+ def test_overwrites_modelsim_ini_file_from_install (self , get_modelsim_ini ):
287311 (modelsim_ini , installed_modelsim_ini , user_modelsim_ini ) = self ._get_inis ()
288312
289313 with open (modelsim_ini , "w" ) as fptr :
@@ -299,7 +323,8 @@ def test_overwrites_modelsim_ini_file_from_install(self):
299323 with open (modelsim_ini , "r" ) as fptr :
300324 self .assertEqual (fptr .read (), "installed" )
301325
302- def test_overwrites_modelsim_ini_file_from_user (self ):
326+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
327+ def test_overwrites_modelsim_ini_file_from_user (self , get_modelsim_ini ):
303328 (modelsim_ini , installed_modelsim_ini , user_modelsim_ini ) = self ._get_inis ()
304329
305330 with open (modelsim_ini , "w" ) as fptr :
@@ -318,10 +343,11 @@ def test_overwrites_modelsim_ini_file_from_user(self):
318343 self .assertEqual (fptr .read (), "user" )
319344
320345 @mock .patch ("vunit.sim_if.modelsim.LOGGER" , autospec = True )
346+ @mock .patch ("vunit.sim_if.modelsim.ModelSimInterface._get_modelsim_ini_from_vmap" , return_value = _get_installed_modelsim_ini ())
321347 @mock .patch ("vunit.sim_if.check_output" , autospec = True , return_value = "" )
322348 @mock .patch ("vunit.sim_if.modelsim.Process" , autospec = True )
323349 @mock .patch ("vunit.sim_if.vsim_simulator_mixin.Process" , autospec = True )
324- def test_optimize (self , vsim_simulator_mixin_process , modelsim_process , check_output , LOGGER ):
350+ def test_optimize (self , vsim_simulator_mixin_process , modelsim_process , check_output , get_modelsim_ini , LOGGER ):
325351 simif = ModelSimInterface (prefix = self .prefix_path , output_path = self .output_path , persistent = False )
326352 project = Project ()
327353 project .add_library ("lib" , str (Path (self .libraries_path ) / "lib" ))
@@ -361,18 +387,18 @@ def test_optimize(self, vsim_simulator_mixin_process, modelsim_process, check_ou
361387 LOGGER .error .assert_has_calls (expected_error_calls )
362388
363389 def setUp (self ):
364- self .test_path = str (Path ( __file__ ). parent / "test_modelsim_out" )
390+ self .test_path = str (_get_test_path () )
365391
366392 self .output_path = str (Path (self .test_path ) / "modelsim" )
367- self .prefix_path = str (Path ( self . test_path ) / "prefix" / "bin" )
393+ self .prefix_path = str (_get_prefix_path )
368394 self .libraries_path = str (Path (self .output_path ) / "libraries" )
369395 self .simulation_output_path = str (Path (self .test_path ) / "test_output" / "lib.tb" )
370396 renew_path (self .test_path )
371397 renew_path (self .output_path )
372398 renew_path (self .prefix_path )
373399 renew_path (self .libraries_path )
374400 renew_path (self .simulation_output_path )
375- installed_modelsim_ini = str (Path ( self . prefix_path ) / ".." / "modelsim.ini" )
401+ installed_modelsim_ini = str (_get_installed_modelsim_ini () )
376402 write_file (installed_modelsim_ini , "[Library]" )
377403 self .project = Project ()
378404 self .cwd = os .getcwd ()
0 commit comments