twister: add simulation handler

Simplify the code a bit by introducing a simulator handler class.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2022-11-21 14:04:11 -05:00
commit a90d711c7d
3 changed files with 40 additions and 34 deletions

View file

@ -38,6 +38,7 @@ except ImportError as capture_error:
logger = logging.getLogger('twister')
logger.setLevel(logging.DEBUG)
SUPPORTED_SIMS = ["mdb-nsim", "nsim", "renode", "qemu", "tsim", "armfvp", "xt-sim", "native"]
class HarnessImporter:
@ -76,6 +77,7 @@ class Handler:
self.generator = None
self.generator_cmd = None
self.suite_name_check = True
self.ready = False
self.args = []
self.terminated = False
@ -311,6 +313,21 @@ class BinaryHandler(Handler):
self._final_handle_actions(harness, handler_time)
class SimulationHandler(BinaryHandler):
def __init__(self, instance, type_str):
"""Constructor
@param instance Test Instance
"""
super().__init__(instance, type_str)
if type_str == 'renode':
self.pid_fn = os.path.join(instance.build_dir, "renode.pid")
elif type_str == 'native':
self.call_make_run = False
self.binary = os.path.join(instance.build_dir, "zephyr", "zephyr.exe")
self.ready = True
class DeviceHandler(Handler):
def __init__(self, instance, type_str):

View file

@ -545,7 +545,7 @@ class ProjectBuilder(FilterBuilder):
elif op == "gather_metrics":
self.gather_metrics(self.instance)
if self.instance.run and self.instance.handler:
if self.instance.run and self.instance.handler.ready:
pipeline.put({"op": "run", "test": self.instance})
else:
pipeline.put({"op": "report", "test": self.instance})
@ -739,7 +739,7 @@ class ProjectBuilder(FilterBuilder):
elif instance.status in ["skipped", "filtered"]:
more_info = instance.reason
else:
if instance.handler and instance.run:
if instance.handler.ready and instance.run:
more_info = instance.handler.type_str
htime = instance.execution_time
if htime:
@ -784,7 +784,7 @@ class ProjectBuilder(FilterBuilder):
instance = self.instance
args = self.testsuite.extra_args[:]
if instance.handler:
if instance.handler.ready:
args += instance.handler.args
# merge overlay files into one variable
@ -826,7 +826,7 @@ class ProjectBuilder(FilterBuilder):
instance = self.instance
if instance.handler:
if instance.handler.ready:
if instance.handler.type_str == "device":
instance.handler.duts = self.duts

View file

@ -14,7 +14,7 @@ import glob
from twisterlib.testsuite import TestCase
from twisterlib.error import BuildError
from twisterlib.size_calc import SizeCalculator
from twisterlib.handlers import BinaryHandler, QEMUHandler, DeviceHandler
from twisterlib.handlers import Handler, SimulationHandler, BinaryHandler, QEMUHandler, DeviceHandler, SUPPORTED_SIMS
logger = logging.getLogger('twister')
@ -139,43 +139,30 @@ class TestInstance:
return
options = env.options
args = []
handler = None
if self.platform.simulation == "qemu":
handler = QEMUHandler(self, "qemu")
args.append(f"QEMU_PIPE={handler.get_fifo()}")
handler = Handler(self, "")
if self.platform.simulation:
if self.platform.simulation == "qemu":
handler = QEMUHandler(self, "qemu")
handler.args.append(f"QEMU_PIPE={handler.get_fifo()}")
handler.ready = True
else:
handler = SimulationHandler(self, self.platform.simulation)
if self.platform.simulation_exec and shutil.which(self.platform.simulation_exec):
handler.ready = True
elif self.testsuite.type == "unit":
handler = BinaryHandler(self, "unit")
handler.binary = os.path.join(self.build_dir, "testbinary")
if options.enable_coverage:
args.append("COVERAGE=1")
handler.args.append("COVERAGE=1")
handler.call_make_run = False
elif self.platform.type == "native":
handler = BinaryHandler(self, "native")
handler.call_make_run = False
handler.binary = os.path.join(self.build_dir, "zephyr", "zephyr.exe")
elif self.platform.simulation == "renode":
if shutil.which("renode"):
handler = BinaryHandler(self, "renode")
handler.pid_fn = os.path.join(self.build_dir, "renode.pid")
elif self.platform.simulation == "tsim":
handler = BinaryHandler(self, "tsim")
handler.ready = True
elif options.device_testing:
handler = DeviceHandler(self, "device")
handler.call_make_run = False
elif self.platform.simulation == "nsim":
if shutil.which("nsimdrv"):
handler = BinaryHandler(self, "nsim")
elif self.platform.simulation == "mdb-nsim":
if shutil.which("mdb"):
handler = BinaryHandler(self, "nsim")
elif self.platform.simulation == "armfvp":
handler = BinaryHandler(self, "armfvp")
elif self.platform.simulation == "xt-sim":
handler = BinaryHandler(self, "xt-sim")
handler.ready = True
if handler:
handler.args = args
handler.options = options
handler.generator_cmd = env.generator_cmd
handler.generator = env.generator
@ -200,14 +187,16 @@ class TestInstance:
target_ready = bool(self.testsuite.type == "unit" or \
self.platform.type == "native" or \
self.platform.simulation in ["mdb-nsim", "nsim", "renode", "qemu", "tsim", "armfvp", "xt-sim"] or \
self.platform.simulation in SUPPORTED_SIMS or \
filter == 'runnable')
for sim in ['nsim', 'mdb-nsim', 'renode', 'tsim']:
for sim in ['nsim', 'mdb-nsim', 'renode', 'tsim', 'native']:
if self.platform.simulation == sim and self.platform.simulation_exec:
if not shutil.which(self.platform.simulation_exec):
target_ready = False
break
else:
target_ready = True
testsuite_runnable = self.testsuite_runnable(self.testsuite, fixtures)