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

View file

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

View file

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

View file

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