twister: move device testing code

Move device handling code into hardware map class.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2022-06-12 11:22:10 -04:00
commit 806722cdbf
2 changed files with 36 additions and 37 deletions

View file

@ -144,16 +144,46 @@ class HardwareMap:
self.options = env.options
def discover(self):
if self.options.generate_hardware_map:
self.scan(persistent=self.options.persistent_hardware_map)
self.save(self.options.generate_hardware_map)
return 0
if not self.options.device_testing and self.options.hardware_map:
self.load(self.options.hardware_map)
logger.info("Available devices:")
table = []
self.dump(connected_only=True)
return 0
if self.options.device_testing:
if self.options.hardware_map:
self.load(self.options.hardware_map)
if not self.options.platform:
self.options.platform = []
for d in self.duts:
if d.connected:
self.options.platform.append(d.platform)
elif self.options.device_serial or self.options.device_serial_pty:
if self.options.device_serial:
self.add_device(self.options.device_serial,
self.options.platform[0],
self.options.pre_script,
False,
baud=self.options.device_serial_baud
)
else:
self.add_device(self.options.device_serial_pty,
self.options.platform[0],
self.options.pre_script,
True)
# the fixtures given by twister command explicitly should be assigned to each DUT
if self.options.fixture:
for d in self.duts:
d.fixtures.extend(self.options.fixture)
return 1
def add_device(self, serial, platform, pre_script, is_pty, baud=None):

View file

@ -803,6 +803,12 @@ structure in the main Zephyr tree: boards/<arch>/<board_name>/""")
logger.error("valgrind enabled but valgrind executable not found")
sys.exit(1)
if options.device_testing and (options.device_serial or options.device_serial_pty) and len(options.platform) > 1:
logger.error("""When --device-testing is used with
--device-serial or --device-serial-pty,
only one platform is allowed""")
sys.exit(1)
return options
def setup_logging(outdir, log_file, verbose, timestamps):
@ -837,12 +843,9 @@ def setup_logging(outdir, log_file, verbose, timestamps):
logger.addHandler(fh)
def init_color(colorama_strip):
colorama.init(strip=colorama_strip)
def main():
start_time = time.time()
@ -911,40 +914,6 @@ def main():
logger.error(f"{e}")
sys.exit(1)
if options.device_testing:
if options.hardware_map:
hwm.load(options.hardware_map)
if not options.platform:
options.platform = []
for d in hwm.duts:
if d.connected:
options.platform.append(d.platform)
elif options.device_serial or options.device_serial_pty:
if options.platform and len(options.platform) == 1:
if options.device_serial:
hwm.add_device(options.device_serial,
options.platform[0],
options.pre_script,
False,
baud=options.device_serial_baud
)
else:
hwm.add_device(options.device_serial_pty,
options.platform[0],
options.pre_script,
True)
else:
logger.error("""When --device-testing is used with
--device-serial or --device-serial-pty,
only one platform is allowed""")
# the fixtures given by twister command explicitly should be assigned to each DUT
if options.fixture:
for d in tplan.hwm.duts:
d.fixtures.extend(options.fixture)
if tplan.report() == 0:
return