twister: run tests on device with twister on windows
Currently, support for Twister on Windows is only build. The only thing that needs to be ported is that select() cannot wait on file descriptors on Windows. Therefore the serial monitor function needs to be reworked to support both OSes. Signed-off-by: Cong Nguyen Huu <cong.nguyenhuu@nxp.com>
This commit is contained in:
parent
40a6f08d3c
commit
5b2b5dfec0
2 changed files with 18 additions and 21 deletions
|
@ -2,6 +2,7 @@
|
|||
# vim: set syntax=python ts=4 :
|
||||
#
|
||||
# Copyright (c) 20180-2022 Intel Corporation
|
||||
# Copyright 2022 NXP
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import math
|
||||
|
@ -317,16 +318,13 @@ class DeviceHandler(Handler):
|
|||
"""
|
||||
super().__init__(instance, type_str)
|
||||
|
||||
def monitor_serial(self, ser, halt_fileno, harness):
|
||||
def monitor_serial(self, ser, halt_event, harness):
|
||||
if harness.is_pytest:
|
||||
harness.handle(None)
|
||||
return
|
||||
|
||||
log_out_fp = open(self.log, "wt")
|
||||
|
||||
ser_fileno = ser.fileno()
|
||||
readlist = [halt_fileno, ser_fileno]
|
||||
|
||||
if self.options.coverage:
|
||||
# Set capture_coverage to True to indicate that right after
|
||||
# test results we should get coverage data, otherwise we exit
|
||||
|
@ -349,14 +347,16 @@ class DeviceHandler(Handler):
|
|||
ser.timeout = old_timeout
|
||||
|
||||
while ser.isOpen():
|
||||
readable, _, _ = select.select(readlist, [], [], self.timeout)
|
||||
|
||||
if halt_fileno in readable:
|
||||
if halt_event.is_set():
|
||||
logger.debug('halted')
|
||||
ser.close()
|
||||
break
|
||||
if ser_fileno not in readable:
|
||||
continue # Timeout.
|
||||
|
||||
if not ser.in_waiting:
|
||||
# no incoming bytes are waiting to be read from the serial
|
||||
# input buffer, let other threads run
|
||||
time.sleep(0.001)
|
||||
continue
|
||||
|
||||
serial_line = None
|
||||
try:
|
||||
|
@ -542,12 +542,12 @@ class DeviceHandler(Handler):
|
|||
harness_import = HarnessImporter(harness_name)
|
||||
harness = harness_import.instance
|
||||
harness.configure(self.instance)
|
||||
read_pipe, write_pipe = os.pipe()
|
||||
start_time = time.time()
|
||||
halt_monitor_evt = threading.Event()
|
||||
|
||||
t = threading.Thread(target=self.monitor_serial, daemon=True,
|
||||
args=(ser, read_pipe, harness))
|
||||
args=(ser, halt_monitor_evt, harness))
|
||||
t.start()
|
||||
start_time = time.time()
|
||||
|
||||
d_log = "{}/device.log".format(self.instance.build_dir)
|
||||
logger.debug('Flash command: %s', command)
|
||||
|
@ -566,10 +566,10 @@ class DeviceHandler(Handler):
|
|||
flash_error = True
|
||||
with open(d_log, "w") as dlog_fp:
|
||||
dlog_fp.write(stderr.decode())
|
||||
os.write(write_pipe, b'x') # halt the thread
|
||||
halt_monitor_evt.set()
|
||||
except subprocess.TimeoutExpired:
|
||||
logger.warning("Flash operation timed out.")
|
||||
proc.kill()
|
||||
self.terminate(proc)
|
||||
(stdout, stderr) = proc.communicate()
|
||||
self.instance.status = "error"
|
||||
self.instance.reason = "Device issue (Timeout)"
|
||||
|
@ -579,7 +579,7 @@ class DeviceHandler(Handler):
|
|||
dlog_fp.write(stderr.decode())
|
||||
|
||||
except subprocess.CalledProcessError:
|
||||
os.write(write_pipe, b'x') # halt the thread
|
||||
halt_monitor_evt.set()
|
||||
self.instance.status = "error"
|
||||
self.instance.reason = "Device issue (Flash error)"
|
||||
flash_error = True
|
||||
|
@ -608,9 +608,6 @@ class DeviceHandler(Handler):
|
|||
outs, errs = ser_pty_process.communicate()
|
||||
logger.debug("Process {} terminated outs: {} errs {}".format(serial_pty, outs, errs))
|
||||
|
||||
os.close(write_pipe)
|
||||
os.close(read_pipe)
|
||||
|
||||
handler_time = time.time() - start_time
|
||||
|
||||
if harness.is_pytest:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# vim: set syntax=python ts=4 :
|
||||
#
|
||||
# Copyright (c) 2018-2022 Intel Corporation
|
||||
# Copyright 2022 NXP
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import os
|
||||
|
@ -183,9 +184,8 @@ class TestInstance:
|
|||
# Global testsuite parameters
|
||||
def check_runnable(self, enable_slow=False, filter='buildable', fixtures=[]):
|
||||
|
||||
# right now we only support building on windows. running is still work
|
||||
# in progress.
|
||||
if os.name == 'nt':
|
||||
# running on simulators is currently not supported on Windows
|
||||
if os.name == 'nt' and self.platform.simulation != 'na':
|
||||
return False
|
||||
|
||||
# we asked for build-only on the command line
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue