From 1a4419059d90d9010320f343e56bb0b2e38df980 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 3 May 2022 18:11:23 +0300 Subject: [PATCH] Added support for "socket://" and "rfc2217://" protocols using "test_port" option // Resolve #4229 --- HISTORY.rst | 3 ++- docs | 2 +- platformio/test/runners/base.py | 9 ++++++++- platformio/test/runners/readers/serial.py | 20 ++++++-------------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index c5aa1c00..472d1b20 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -44,10 +44,11 @@ Please check `Migration guide from 5.x to 6.0 `_ solution and documentation + - Refactored from scratch `Unit Testing `_ solution and its documentation - New `Test Hierarchies `_ (`issue #4135 `_) - New `Custom Testing Framework `_ - New "test" `build configuration `__ + - Added support for ``socket://`` and ``rfc2217://`` protocols using `test_port `__ option (`issue #4229 `_) - Generate reports in JUnit and JSON formats using the `pio test --output-format `__ option (`issue #2891 `_) - Provide more information when the native program crashed on a host (errored with a negative return code) (`issue #3429 `_) - Fixed an issue when command line parameters (``--ignore``, ``--filter``) do not override values defined in the |PIOCONF| (`issue #3845 `_) diff --git a/docs b/docs index 7133d092..37f04cb5 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 7133d092725e4768ee99a1a24729b75b93c9b70e +Subproject commit 37f04cb5e6e57f64174d0dc5c7435c6581f1a3ce diff --git a/platformio/test/runners/base.py b/platformio/test/runners/base.py index 5d4a19d5..e828e3af 100644 --- a/platformio/test/runners/base.py +++ b/platformio/test/runners/base.py @@ -76,6 +76,11 @@ class TestRunnerBase: self.project_config.get(f"env:{self.test_suite.env_name}", "test_speed") ) + def get_test_port(self): + return self.options.test_port or self.project_config.get( + f"env:{self.test_suite.env_name}", "test_port" + ) + def start(self, cmd_ctx): # setup command context self.cmd_ctx = cmd_ctx @@ -138,9 +143,11 @@ class TestRunnerBase: if self.options.without_testing: return None click.secho("Testing...", bold=self.options.verbose) + test_port = self.get_test_port() + serial_conds = [self.platform.is_embedded(), test_port and "://" in test_port] reader = ( SerialTestOutputReader(self) - if self.platform.is_embedded() + if any(serial_conds) else ProgramTestOutputReader(self) ) return reader.begin() diff --git a/platformio/test/runners/readers/serial.py b/platformio/test/runners/readers/serial.py index 4813c76d..5371eb04 100644 --- a/platformio/test/runners/readers/serial.py +++ b/platformio/test/runners/readers/serial.py @@ -36,10 +36,12 @@ class SerialTestOutputReader: click.echo() try: - ser = serial.Serial( - baudrate=self.test_runner.get_test_speed(), timeout=self.SERIAL_TIMEOUT + ser = serial.serial_for_url( + self.test_runner.get_test_port() or self.autodetect_test_port(), + do_not_open=True, + baudrate=self.test_runner.get_test_speed(), + timeout=self.SERIAL_TIMEOUT, ) - ser.port = self.get_test_port() ser.rts = self.test_runner.options.monitor_rts ser.dtr = self.test_runner.options.monitor_dtr ser.open() @@ -74,17 +76,7 @@ class SerialTestOutputReader: self.test_runner.on_test_output(line) ser.close() - def get_test_port(self): - # if test port is specified manually or in config - port = ( - self.test_runner.options.test_port - or self.test_runner.project_config.get( - f"env:{self.test_runner.test_suite.env_name}", "test_port" - ) - ) - if port: - return port - + def autodetect_test_port(self): board = self.test_runner.project_config.get( f"env:{self.test_runner.test_suite.env_name}", "board" )