1111import hashlib
1212import random
1313import logging
14- import shutil
1514import glob
1615import csv
1716
2827 QEMUHandler ,
2928 QEMUWinHandler ,
3029 DeviceHandler ,
30+ )
31+ from twisterlib .constants import (
3132 SUPPORTED_SIMS ,
3233 SUPPORTED_SIMS_IN_PYTEST ,
34+ SUPPORTED_SIMS_WITH_EXEC ,
3335)
3436
3537logger = logging .getLogger ('twister' )
@@ -211,23 +213,23 @@ def setup_handler(self, env: TwisterEnv):
211213
212214 options = env .options
213215 common_args = (options , env .generator_cmd , not options .disable_suite_name_check )
216+ simulator = self .platform .simulator_by_name (options .sim_name )
214217 if options .device_testing :
215218 handler = DeviceHandler (self , "device" , * common_args )
216219 handler .call_make_run = False
217220 handler .ready = True
218- elif self . platform . simulation != "na" :
219- if self . platform . simulation == "qemu" :
221+ elif simulator :
222+ if simulator . name == "qemu" :
220223 if os .name != "nt" :
221224 handler = QEMUHandler (self , "qemu" , * common_args )
222225 else :
223226 handler = QEMUWinHandler (self , "qemu" , * common_args )
224227 handler .args .append (f"QEMU_PIPE={ handler .get_fifo ()} " )
225228 handler .ready = True
226229 else :
227- handler = SimulationHandler (self , self .platform .simulation , * common_args )
230+ handler = SimulationHandler (self , simulator .name , * common_args )
231+ handler .ready = simulator .is_runnable ()
228232
229- if self .platform .simulation_exec and shutil .which (self .platform .simulation_exec ):
230- handler .ready = True
231233 elif self .testsuite .type == "unit" :
232234 handler = BinaryHandler (self , "unit" , * common_args )
233235 handler .binary = os .path .join (self .build_dir , "testbinary" )
@@ -242,21 +244,23 @@ def setup_handler(self, env: TwisterEnv):
242244
243245 # Global testsuite parameters
244246 def check_runnable (self ,
245- options ,
246- hardware_map = None ):
247+ options : TwisterEnv ,
248+ hardware_map = None ):
247249
248250 enable_slow = options .enable_slow
249251 filter = options .filter
250252 fixtures = options .fixture
251253 device_testing = options .device_testing
254+ simulation = options .sim_name
252255
256+ simulator = self .platform .simulator_by_name (simulation )
253257 if os .name == 'nt' :
254258 # running on simulators is currently supported only for QEMU on Windows
255- if self . platform . simulation not in ('na' , 'qemu' ):
259+ if ( not simulator ) or simulator . name not in ('na' , 'qemu' ):
256260 return False
257261
258262 # check presence of QEMU on Windows
259- if self . platform . simulation == 'qemu' and 'QEMU_BIN_PATH' not in os .environ :
263+ if simulator . name == 'qemu' and 'QEMU_BIN_PATH' not in os .environ :
260264 return False
261265
262266 # we asked for build-only on the command line
@@ -269,20 +273,20 @@ def check_runnable(self,
269273 return False
270274
271275 target_ready = bool (self .testsuite .type == "unit" or \
272- self .platform .type == "native" or \
273- (self .platform .simulation in SUPPORTED_SIMS and \
274- self .platform .simulation not in self .testsuite .simulation_exclude ) or device_testing )
276+ self .platform .type == "native" or \
277+ (simulator and simulator .name in SUPPORTED_SIMS and \
278+ simulator .name not in self .testsuite .simulation_exclude ) or \
279+ device_testing )
275280
276281 # check if test is runnable in pytest
277282 if self .testsuite .harness == 'pytest' :
278- target_ready = bool (filter == 'runnable' or self . platform . simulation in SUPPORTED_SIMS_IN_PYTEST )
283+ target_ready = bool (filter == 'runnable' or simulator and simulator . name in SUPPORTED_SIMS_IN_PYTEST )
279284
280- SUPPORTED_SIMS_WITH_EXEC = ['nsim' , 'mdb-nsim' , 'renode' , 'tsim' , 'native' , 'simics' , 'custom' ]
281285 if filter != 'runnable' and \
282- self . platform . simulation in SUPPORTED_SIMS_WITH_EXEC and \
283- self . platform . simulation_exec :
284- if not shutil . which ( self . platform . simulation_exec ):
285- target_ready = False
286+ simulator and \
287+ simulator . name in SUPPORTED_SIMS_WITH_EXEC and \
288+ not simulator . is_runnable ( ):
289+ target_ready = False
286290
287291 testsuite_runnable = self .testsuite_runnable (self .testsuite , fixtures )
288292
0 commit comments