Skip to content

Fix inconsistent mbed-trace dummy defines and original function declarations #4706

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

Merged
merged 1 commit into from
Jul 24, 2017
Merged
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
4 changes: 4 additions & 0 deletions features/FEATURE_COMMON_PAL/mbed-trace/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ build/
test_coverage/
**/*.info
**/*~
output/*

# Yotta files
.yotta.json
1 change: 1 addition & 0 deletions features/FEATURE_COMMON_PAL/mbed-trace/CMakeLists.txt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ project(mbedTrace)


include_directories(${CMAKE_CURRENT_SOURCE_DIR}/mbed-trace/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../nanostack-libservice/mbed-client-libservice/)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../nanostack-libservice/)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ char* mbed_trace_array(const uint8_t* buf, uint16_t len);
#elif !defined(MBED_TRACE_DUMMIES_DEFINED)
// define dummies, hiding the real functions
#define MBED_TRACE_DUMMIES_DEFINED
#define mbed_trace_init(...) ((void) 0)
#define mbed_trace_init(...) ((int) 0)
#define mbed_trace_free(...) ((void) 0)
#define mbed_trace_buffer_sizes(...) ((void) 0)
#define mbed_trace_config_set(...) ((void) 0)
Expand Down
2 changes: 1 addition & 1 deletion features/FEATURE_COMMON_PAL/mbed-trace/module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mbed-trace",
"version": "1.2.1",
"version": "1.3.0",
"description": "Trace library for mbed devices",
"keywords": [
"trace",
Expand Down
13 changes: 1 addition & 12 deletions features/FEATURE_COMMON_PAL/mbed-trace/source/mbed_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,6 @@ void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap)
if (plain == true || dlevel == TRACE_LEVEL_CMD) {
//add trace data
retval = vsnprintf(ptr, bLeft, fmt, ap);
//convenience - trim off one trailing \n. Useful if trying to directly
//connect debug layers that do expect callers to pass \n to mbed_trace.
if (retval > 0 && retval < bLeft && ptr[retval - 1] == '\n') {
ptr[--retval] = '\0';
}
if (dlevel == TRACE_LEVEL_CMD && m_trace.cmd_printf) {
m_trace.cmd_printf(m_trace.line);
m_trace.cmd_printf("\n");
Expand Down Expand Up @@ -446,12 +441,6 @@ void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap)
if (retval > 0) {
ptr += retval;
bLeft -= retval;
//convenience - trim off one trailing \n. Useful if trying to directly
//connect debug layers that do expect callers to pass \n to mbed_trace.
if (ptr[-1] == '\n') {
*--ptr = '\0';
++bLeft;
}
}
}

Expand Down Expand Up @@ -569,7 +558,7 @@ char *mbed_trace_array(const uint8_t *buf, uint16_t len)
int i, bLeft = tmp_data_left();
char *str, *wptr;
str = m_trace.tmp_data_ptr;
if (str == NULL || bLeft == 0) {
if (len == 0 || str == NULL || bLeft == 0) {
return "";
}
if (buf == NULL) {
Expand Down
13 changes: 13 additions & 0 deletions features/FEATURE_COMMON_PAL/mbed-trace/test/Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ TEST(trace, Array)
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(longStr, 200) );
}

TEST(trace, Null0Array)
{
static const unsigned char array[2] = { 0x23, 0x45 };
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(array, 2));
STRCMP_EQUAL("23:45", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(array, 0));
STRCMP_EQUAL("", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(NULL, 0));
STRCMP_EQUAL("", buf);
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(NULL, 2));
STRCMP_EQUAL("<null>", buf);
}

TEST(trace, LongString)
{
char longStr[1000] = {0x36};
Expand Down