Skip to content

Add Mbed trace support #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ble-cliapp/mbed_app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why null?

},
"K64F": {
"target.features_add": ["BLE"],
Expand Down
17 changes: 17 additions & 0 deletions ble-cliapp/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Comment on lines +189 to +205

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be in #if MBED_CONF_MBED_TRACE_ENABLE

cmd_init( &custom_cmd_response_out );
cmd_set_ready_cb( cmd_ready_cb );
cmd_history_size(1);
Expand Down
11 changes: 7 additions & 4 deletions test_suite/common/ble_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
5 changes: 3 additions & 2 deletions test_suite/common/serial_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ def _input_thread(self):
log.warning('{}: Invalid bytes read: {}'.format(self.name, line))
continue
plain_line.rstrip()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that looks like a nop

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

Expand Down