twister: more cleanup to option passing

Use global options rather than passing them individually.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2022-06-10 10:51:01 -04:00
commit b8735b3300
4 changed files with 40 additions and 32 deletions

View file

@ -56,6 +56,8 @@ class Handler:
"""Constructor
"""
self.options = None
self.state = "waiting"
self.run = False
self.type_str = type_str
@ -325,8 +327,6 @@ class DeviceHandler(Handler):
"""
super().__init__(instance, type_str)
self.testplan = None
def monitor_serial(self, ser, halt_fileno, harness):
if harness.is_pytest:
harness.handle(None)
@ -385,7 +385,7 @@ class DeviceHandler(Handler):
def device_is_available(self, instance):
device = instance.platform.name
fixture = instance.testsuite.harness_config.get("fixture")
for d in self.testplan.duts:
for d in self.duts:
if fixture and fixture not in d.fixtures:
continue
if d.platform != device or (d.serial is None and d.serial_pty is None):
@ -403,7 +403,7 @@ class DeviceHandler(Handler):
return None
def make_device_available(self, serial):
for d in self.testplan.duts:
for d in self.duts:
if serial in [d.serial_pty, d.serial]:
d.available = 1
@ -430,7 +430,7 @@ class DeviceHandler(Handler):
time.sleep(1)
hardware = self.device_is_available(self.instance)
runner = hardware.runner or self.testplan.west_runner
runner = hardware.runner or self.options.west_runner
serial_pty = hardware.serial_pty
ser_pty_process = None
@ -448,7 +448,7 @@ class DeviceHandler(Handler):
logger.debug(f"Using serial device {serial_device} @ {hardware.baud} baud")
if (self.testplan.west_flash is not None) or runner:
if (self.options.west_flash is not None) or runner:
command = ["west", "flash", "--skip-rebuild", "-d", self.build_dir]
command_extra_args = []
@ -459,8 +459,8 @@ class DeviceHandler(Handler):
# This results in options.west_flash == "--board-id=42"
# 3) Multiple values: --west-flash="--board-id=42,--erase"
# This results in options.west_flash == "--board-id=42 --erase"
if self.testplan.west_flash and self.testplan.west_flash != []:
command_extra_args.extend(self.testplan.west_flash.split(','))
if self.options.west_flash and self.options.west_flash != []:
command_extra_args.extend(self.options.west_flash.split(','))
if runner:
command.append("--runner")
@ -493,7 +493,7 @@ class DeviceHandler(Handler):
# Receive parameters from an runner_params field
# of the specified hardware map file.
for d in self.testplan.duts:
for d in self.duts:
if (d.platform == self.instance.platform.name) and d.runner_params:
for param in d.runner_params:
command.append(param)

View file

@ -13,10 +13,13 @@ import logging
import queue
import time
import multiprocessing
import traceback
from colorama import Fore
from multiprocessing import Lock, Process, Value
from multiprocessing.managers import BaseManager
from numpy import trace
from twister.cmakecache import CMakeCache
logger = logging.getLogger('twister')
@ -376,14 +379,15 @@ class FilterBuilder(CMake):
class ProjectBuilder(FilterBuilder):
def __init__(self, tplan, instance, env, **kwargs):
def __init__(self, instance, env, **kwargs):
super().__init__(instance.testsuite, instance.platform, instance.testsuite.source_dir, instance.build_dir)
self.log = "build.log"
self.instance = instance
self.testplan = tplan
self.filtered_tests = 0
self.options = env.options
self.env = env
self.duts = None
self.extra_args = kwargs.get('extra_args', [])
self.verbose = kwargs.get('verbose', None)
@ -434,7 +438,7 @@ class ProjectBuilder(FilterBuilder):
def process(self, pipeline, done, message, lock, results):
op = message.get('op')
self.instance.setup_handler(self.options)
self.instance.setup_handler(self.env)
# The build process, call cmake and build with configured generator
if op == "cmake":
@ -489,10 +493,10 @@ class ProjectBuilder(FilterBuilder):
logger.debug("run test: %s" % self.instance.name)
self.run()
logger.debug(f"run status: {self.instance.name} {self.instance.status}")
try:
# to make it work with pickle
self.instance.handler.thread = None
self.instance.handler.testplan = None
self.instance.handler.duts = None
pipeline.put({
"op": "report",
"test": self.instance,
@ -500,6 +504,9 @@ class ProjectBuilder(FilterBuilder):
"reason": self.instance.reason
}
)
except RuntimeError as e:
logger.error(f"RuntimeError: {e}")
traceback.print_exc()
# Report results and output progress to screen
elif op == "report":
@ -710,7 +717,7 @@ class ProjectBuilder(FilterBuilder):
if instance.handler:
if instance.handler.type_str == "device":
instance.handler.testplan = self.testplan
instance.handler.duts = self.duts
if(self.seed is not None and instance.platform.name.startswith("native_posix")):
self.parse_generated()
@ -755,6 +762,7 @@ class TwisterRunner:
self.env = env
self.instances = instances
self.suites = suites
self.duts = None
self.jobs = 1
self.results = None
@ -819,7 +827,6 @@ class TwisterRunner:
if retries == 0 or (self.results.failed == self.results.error and not self.options.retry_build_errors):
break
def update_counting(self):
for instance in self.instances.values():
self.results.cases += len(instance.testsuite.testcases)
@ -859,7 +866,8 @@ class TwisterRunner:
break
else:
instance = task['test']
pb = ProjectBuilder(self, instance, self.env)
pb = ProjectBuilder(instance, self.env)
pb.duts = self.duts
pb.process(pipeline, done_queue, task, lock, results)
return True

View file

@ -128,10 +128,11 @@ class TestInstance:
return can_run
def setup_handler(self, options):
def setup_handler(self, env):
if self.handler:
return
options = env.options
args = []
handler = None
if self.platform.simulation == "qemu":
@ -161,7 +162,7 @@ class TestInstance:
handler = BinaryHandler(self, "tsim")
elif options.device_testing:
handler = DeviceHandler(self, "device")
handler.coverage = self.enable_coverage
handler.coverage = options.enable_coverage
handler.call_make_run = False
elif self.platform.simulation == "nsim":
if find_executable("nsimdrv"):
@ -176,6 +177,7 @@ class TestInstance:
if handler:
handler.args = args
handler.options = options
handler.suite_name_check = not options.disable_suite_name_check
if options.ninja:
handler.generator_cmd = "ninja"

View file

@ -1229,10 +1229,8 @@ def main():
if options.short_build_path:
tplan.create_build_dir_links()
runner = TwisterRunner(tplan.instances, tplan.testsuites, env)
runner.duts = tplan.duts
runner.run()
# figure out which report to use for size comparison