From 58774ba60f111b3c1fb43021be05ece5cea65f35 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 7 Jan 2021 12:10:45 +0000 Subject: [PATCH 1/3] Serial device: Skip empty lines. --- test_suite/common/serial_device.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test_suite/common/serial_device.py b/test_suite/common/serial_device.py index e509748..c0479bd 100644 --- a/test_suite/common/serial_device.py +++ b/test_suite/common/serial_device.py @@ -95,8 +95,9 @@ def _input_thread(self): log.warning('{}: Invalid bytes read: {}'.format(self.name, line)) continue plain_line.rstrip() - log.info('<--|{}| {}'.format(self.name, plain_line.strip())) - self.iq.put(plain_line) + if plain_line.strip(): + log.info('<--|{}| {}'.format(self.name, plain_line.strip())) + self.iq.put(plain_line) else: pass From d8269f1104b0c8f5f770d508a60e31ee82fc99bd Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 7 Jan 2021 12:23:52 +0000 Subject: [PATCH 2/3] Add Mbed trace support in ble-cliapp. --- ble-cliapp/mbed_app.json | 3 ++- ble-cliapp/source/main.cpp | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ble-cliapp/mbed_app.json b/ble-cliapp/mbed_app.json index 26d5711..16ac1ce 100644 --- a/ble-cliapp/mbed_app.json +++ b/ble-cliapp/mbed_app.json @@ -25,7 +25,8 @@ "target.printf_lib": "std", "platform.stdio-flush-at-exit": false, "platform.stdio-baud-rate": 115200, - "cordio.desired-att-mtu": 80 + "cordio.desired-att-mtu": 80, + "mbed-trace.enable": null }, "K64F": { "target.features_add": ["BLE"], diff --git a/ble-cliapp/source/main.cpp b/ble-cliapp/source/main.cpp index cb1fa65..1a656e2 100644 --- a/ble-cliapp/source/main.cpp +++ b/ble-cliapp/source/main.cpp @@ -186,6 +186,23 @@ void app_start(int, char*[]) get_serial().baud(115200); // This is default baudrate for our test applications. 230400 is also working, but not 460800. At least with k64f. get_serial().attach(whenRxInterrupt); + mbed_trace_init(); + mbed_trace_prefix_function_set([](size_t) { + // This is the prefix added before any trace, the new line is used to + // ensure the trace is not rendered inside a line containing a json + // payload. The test tool filter out traces based on this pattern. + static char prefix[] = "\n~~~"; + return prefix; + }); + mbed_trace_print_function_set([](const char* str) { + get_serial().write(str, strlen(str)); + // Note: line return in mbed_trace somehow doesn't work if color support + // is deactivated. + get_serial().write("\n", 1); + }); + // Disable color support and carriage return support + mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL); + cmd_init( &custom_cmd_response_out ); cmd_set_ready_cb( cmd_ready_cb ); cmd_history_size(1); From 1b4fa914391087b4f8f0bac40483c9eda64d8b4c Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Thu, 7 Jan 2021 12:24:44 +0000 Subject: [PATCH 3/3] Test: Filter logs from device output. --- test_suite/common/ble_device.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test_suite/common/ble_device.py b/test_suite/common/ble_device.py index c5eee12..ca314ab 100644 --- a/test_suite/common/ble_device.py +++ b/test_suite/common/ble_device.py @@ -338,6 +338,7 @@ def __init__(self, device: Device, command_delay=0): self.device = device self.command_delay = command_delay self.events = queue.Queue() + self.log = queue.Queue() def command(self, cmd: str, expected_retcode: int = 0, async_command: bool = False) -> CommandResult: """Send a command to the device and return a CommandResult. @@ -395,23 +396,25 @@ def __getattr__(self, module_name: str) -> BleCommandModule: def send(self, command, expected_output=None, wait_before_read=None, wait_for_response=30, assert_output=True): sleep(self.command_delay) lines = self.device.send(command, expected_output, wait_before_read, wait_for_response, assert_output) - return self._filter_events(lines) + return self._filter_output(lines) def flush(self, timeout: float = 0) -> [str]: lines = self.device.send(timeout) - return self._filter_events(lines) + return self._filter_output(lines) def wait_for_output(self, search: str, timeout: float = 30, assert_timeout: bool = True) -> [str]: lines = self.device.wait_for_output(search, timeout, assert_timeout) - return self._filter_events(lines) + return self._filter_output(lines) - def _filter_events(self, lines: List[str]) -> Optional[List[str]]: + def _filter_output(self, lines: List[str]) -> Optional[List[str]]: if lines is None: return None unfiltered_lines = [] for line in lines: if line.startswith('<<<'): self.events.put(line[len('<<<'):]) + elif line.startswith('~~~'): + self.log.put(line[len('~~~'):]) else: unfiltered_lines.append(line) return unfiltered_lines