Skip to content

Unified logging - String Based #5965

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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
66d1de0
Unified logging system: String based only support
Feb 13, 2018
ee159ed
Code cleanup and addressed review comments
Feb 15, 2018
e7fe803
Deprecate debug/error/MBED_ASSERT API, added non variadic function
Feb 22, 2018
ecd986b
Added trace level for OS/Lib and API description
Mar 2, 2018
07626b3
Design change: shared event queue+circular buffer overflow handling
Mar 13, 2018
8872700
Added test to verify logging module
Mar 19, 2018
3f2e9b7
Corrected the deprecate messages
Mar 29, 2018
ca3b8bb
Added function to enable timing prints
Mar 29, 2018
3c2b4d1
Removed buffering for user prints and addressed review comments
Apr 10, 2018
0b7c5d9
Moved static functions out of extern C define
Apr 11, 2018
f923347
Added mbed_trace mutex function pointers
Apr 11, 2018
22267ad
Code cleanup
Apr 11, 2018
b0cd563
Cleanup - helper functions
Apr 11, 2018
82b2012
Addressed review comments
Apr 13, 2018
3aa4f25
Do not over-write ISR data when print is in progress
Apr 16, 2018
0ddb5a5
Append * at the end in case of incomplete message
Apr 16, 2018
b0bad57
Add note for expression evaluation not supported
Apr 16, 2018
d3cb837
Added overflow test case, and assert for min string length
Apr 16, 2018
3cb4b3d
Attribute for printf format not supported in IAR
Apr 18, 2018
e3cd85c
Corrected ISR + ID based buffering logic
Apr 19, 2018
c99cff5
RAM Space limitation - logging
Apr 23, 2018
bff7a98
Option to disable ISR logging
Apr 23, 2018
7f98dc0
Corrected NDEBUG guard for logging
Apr 23, 2018
281ea41
API document + Config options
Apr 25, 2018
58388d5
Addressed review comments
Apr 26, 2018
c577eb9
Circular buffer memory creation using malloc instead new
Apr 26, 2018
54ca3bb
HEAP memory for stack creation and no disable option
Apr 26, 2018
7319abc
Added eventflags for synchronization
Apr 26, 2018
820ff14
Corrected the scope of critical section
Apr 27, 2018
84ef718
Correcting wrong macro removal
Apr 27, 2018
136923c
Updated the example as newline char is needed now
Apr 27, 2018
a4e1bda
Removed trace level and set info as default log level
May 11, 2018
65d00d0
Default Mbed_trace enabled
May 11, 2018
1bfb5b1
Mbed trace enabled as default
May 11, 2018
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
311 changes: 311 additions & 0 deletions TESTS/mbed_platform/logging/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,311 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "platform/mbed_trace_internal.h"
#include "greentea-client/test_env.h"
#include "utest/utest.h"
#include "unity/unity.h"

using utest::v1::Case;

#if !defined(MBED_CONF_MBED_TRACE_FEA_IPV6) || !defined(MBED_CONF_MBED_TRACE_ENABLE)
#warning "Helper functions will not be tested, as MBED_CONF_MBED_TRACE_FEA_IPV6/MBED_CONF_MBED_TRACE_ENABLE is not set"
#endif

LOG_DATA_TYPE_ *buf = NULL;

static void test_log_reset()
{
log_reset();
if (NULL == buf) {
buf = new LOG_DATA_TYPE_[MBED_CONF_PLATFORM_LOG_MAX_BUFFER_SIZE];
}
memset(buf, 0x0, MBED_CONF_PLATFORM_LOG_MAX_BUFFER_SIZE);
log_buffer_data(buf);
log_disable_time_capture();
return;
}

static void test_log_clean()
{
delete[] buf;
}

static void test_log_levels()
{
test_log_reset();
MBED_ERR("TEST", "Error performing XYZ operation, errno = %d", -10);
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[ERR ][TEST]: Error performing XYZ operation, errno = -10", buf);

test_log_reset();
MBED_WARN("TEST", "This is warning message");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[WARN][TEST]: This is warning message", buf);

test_log_reset();
MBED_DBG_IF("TEST", false, "This should not be printed");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("", buf);

test_log_reset();
MBED_DBG_IF("TEST", (1 == 1), "Cool 1 is 1");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[DBG ][TEST]: Cool 1 is 1", buf);

test_log_reset();
MBED_DBG("TEST", "%s %s %d", "Hello World!", "Count is:", 20);
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[DBG ][TEST]: Hello World! Count is: 20", buf);

test_log_reset();
MBED_INFO_IF("TEST", (1 == 0) , "Really ???");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("", buf);

test_log_reset();
MBED_INFO_IF("TEST", (1 != 0), "Correct %s", "Always");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[INFO][TEST]: Correct Always", buf);

test_log_reset();
MBED_INFO("TEST", "Again here!! Entry is: %d Exit is: %d", 120, 121);
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[INFO][TEST]: Again here!! Entry is: 120 Exit is: 121", buf);

test_log_reset();
MBED_TRACE_IF("TEST", 0 , "No trace");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("", buf);

test_log_reset();
MBED_TRACE_IF("TEST", (1 != 0), "Trace level not enabled by default");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("", buf);

test_log_reset();
MBED_TRACE("TEST", "No trace - disabled");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("", buf);
return;
}

static void test_gen_log_api()
{
test_log_reset();
MBED_LOG(2, "GENx", "Error performing XYZ operation, errno = %d", -10);
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[ERR ][GENx]: Error performing XYZ operation, errno = -10", buf);

test_log_reset();
MBED_LOG(4, "GENx", "This is warning message");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[WARN][GENx]: This is warning message", buf);

test_log_reset();
MBED_LOG(10, "GENx", "%s %s %d", "Hello World!", "Count is:", 20);
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[DBG ][GENx]: Hello World! Count is: 20", buf);

test_log_reset();
MBED_LOG(8, "GENx", "Again here!! Entry is: %d Exit is: %d", 120, 121);
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[INFO][GENx]: Again here!! Entry is: 120 Exit is: 121", buf);

test_log_reset();
MBED_LOG(20, "GENx", "MBED_LOG prints all levels");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[TRAC][GENx]: MBED_LOG prints all levels", buf);
return;
}

static void test_log_helper_arrays()
{
static uint8_t longStr[5];

longStr[0] = 0x23;
longStr[1] = 0x45;
test_log_reset();
MBED_INFO("TEST", "%s", mbed_trace_array(longStr, 2));
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[INFO][TEST]: 23:45", buf);

test_log_reset();
MBED_DBG("TEST", "%s", mbed_trace_array(longStr, 0));
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[DBG ][TEST]: ", buf);

test_log_reset();
MBED_WARN("Testing", "%s", mbed_trace_array(NULL, 0));
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[WARN][Test]: ", buf);

test_log_reset();
MBED_ERR("TEST", "%s", mbed_trace_array(NULL, 2));
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[ERR ][TEST]: <null>", buf);
return;
}

static void test_log_helper_ipv6()
{
uint8_t prefix[] = { 0x14, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00 };
int prefix_len = 64;

test_log_reset();
MBED_INFO("IPv6", "%s", mbed_trace_ipv6_prefix(prefix, prefix_len));
wait_us(1000);
#if defined(MBED_CONF_MBED_TRACE_FEA_IPV6)
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: 146e:a00::/64", buf);
#else
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: ", buf);
#endif

test_log_reset();
MBED_INFO("IPv6", "%s", mbed_trace_ipv6_prefix(NULL, 0));
wait_us(1000);
#if defined(MBED_CONF_MBED_TRACE_FEA_IPV6)
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: ::/0", buf);
#else
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: ", buf);
#endif

test_log_reset();
MBED_INFO("IPv6", "%s", mbed_trace_ipv6_prefix(NULL, 1));
wait_us(1000);
#if defined(MBED_CONF_MBED_TRACE_FEA_IPV6)
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: <err>", buf);
#else
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: ", buf);
#endif

test_log_reset();
MBED_INFO("IPv6", "%s", mbed_trace_ipv6_prefix(prefix, 200));
wait_us(1000);
#if defined(MBED_CONF_MBED_TRACE_FEA_IPV6)
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: <err>", buf);
#else
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: ", buf);
#endif

uint8_t arr[] = { 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 };
test_log_reset();
MBED_INFO("IPv6", "%s", mbed_trace_ipv6(arr));
wait_us(1000);
#if defined(MBED_CONF_MBED_TRACE_FEA_IPV6)
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: 2001:db8::1:0:0:1", buf);
#else
TEST_ASSERT_EQUAL_STRING("[INFO][IPv6]: ", buf);
#endif
return;
}

void LogCallback(void)
{
MBED_WARN("LOG", "Inside ISR");
}

static void test_log_isr()
{
Ticker t1;
test_log_reset();
t1.attach_us(LogCallback, 100000);
wait_us(101000);
TEST_ASSERT_EQUAL_STRING("[WARN][LOG ]: Inside ISR", buf);
return;
}

static void test_log_interleave()
{
Ticker t1;
test_log_reset();
t1.attach(LogCallback, 1);
uint32_t count = 0;

while(count++ < 3) {
wait_us(200000);
MBED_DBG_IF("TEST", (0 == (count%2)), "Even");
wait_us(200000);
MBED_INFO_IF("TEST", (0 != (count%2)), "Odd");
}
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[INFO][TEST]: Odd"
"[DBG ][TEST]: Even"
"[WARN][LOG ]: Inside ISR"
"[INFO][TEST]: Odd", buf);
return;
}

static void test_log_overflow()
{
static uint8_t longStr[100];
for(int i = 0; i < 100; i++)
{
longStr[i] = 0x88;
}

test_log_reset();
MBED_WARN("TEST", "%s", mbed_trace_array(longStr, 100));
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[WARN][TEST]: 88:88:88:88:88:88:88:88:88:88:88:88:88:"
"88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:"
"88:88:88:88:88:88:88:88:88:88:88:*", buf);

test_log_reset();
MBED_WARN("TEST", "01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:"
"31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:"
"61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80:81:82:83:84:85:86:87:88:89:90:");
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[WARN][TEST]: 01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:"
"31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60:"
"61:62:63:64:65:66:67:68:69:70:71:72:73:74:75:76:77:78:79:80*\n", buf);

test_log_reset();
MBED_WARN("TEST", "01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:"
"31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60: %s",
mbed_trace_array(longStr, 100));
wait_us(1000);
TEST_ASSERT_EQUAL_STRING("[WARN][TEST]: 01:02:03:04:05:06:07:08:09:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:"
"31:32:33:34:35:36:37:38:39:40:41:42:43:44:45:46:47:48:49:50:51:52:53:54:55:56:57:58:59:60: "
"88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:8*\n", buf);

return;
}

// Test cases
Case cases[] = {
Case("Test all log levels", test_log_levels),
Case("Test generic log API", test_gen_log_api),
Case("Test helper array function", test_log_helper_arrays),
Case("Test helper ipv6 functions", test_log_helper_ipv6),
Case("Test log in ISR context", test_log_isr),
Case("Test log interleave test", test_log_interleave),
Case("Test overflow test", test_log_overflow),
Case("Cleanup buffers", test_log_clean)
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(15, "default_auto");
return utest::v1::greentea_test_setup_handler(number_of_cases);
}

utest::v1::Specification specification(greentea_test_setup, cases, utest::v1::greentea_test_teardown_handler);

int main()
{
utest::v1::Harness::run(specification);
}
9 changes: 9 additions & 0 deletions features/frameworks/mbed-trace/mbed-trace/mbed_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ extern "C" {
/** special level for cmdline. Behaviours like "plain mode" */
#define TRACE_LEVEL_CMD 0x01

#if defined(MBED_CONF_PLATFORM_LOGGING_ENABLE) && (MBED_CONF_PLATFORM_LOGGING_ENABLE)
#include "platform/mbed_trace_internal.h"
#else

#ifndef MBED_TRACE_MAX_LEVEL
#define MBED_TRACE_MAX_LEVEL TRACE_LEVEL_DEBUG
#endif
Expand Down Expand Up @@ -366,12 +370,15 @@ char* mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
*/
char* mbed_trace_array(const uint8_t* buf, uint16_t len);

#endif

#ifdef __cplusplus
}
#endif

#endif /* MBED_TRACE_H_ */

#if !defined(MBED_CONF_PLATFORM_LOGGING_ENABLE) || !(MBED_CONF_PLATFORM_LOGGING_ENABLE)
/* These macros are outside the inclusion guard so they will be re-evaluated for every inclusion of the header.
* If tracing is disabled, the dummies will hide the real functions. The real functions can still be reached by
* surrounding the name of the function with brackets, e.g. "(mbed_tracef)(dlevel, grp, "like so");"
Expand Down Expand Up @@ -435,3 +442,5 @@ char* mbed_trace_array(const uint8_t* buf, uint16_t len);
#define mbed_trace_array(...) dont_use_trace_helpers_outside_trace_calls

#endif /* FEA_TRACE_SUPPORT */

#endif
2 changes: 1 addition & 1 deletion features/frameworks/mbed-trace/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"config": {
"enable": {
"help": "Used to globally enable traces.",
"value": null
"value": true
},
"fea-ipv6": {
"help": "Used to globally disable ipv6 tracing features.",
Expand Down
8 changes: 6 additions & 2 deletions features/frameworks/mbed-trace/source/mbed_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include <string.h>
#include <stdarg.h>

#if !defined(MBED_CONF_PLATFORM_LOGGING_ENABLE) || !(MBED_CONF_PLATFORM_LOGGING_ENABLE)

#ifdef MBED_CONF_MBED_TRACE_ENABLE
#undef MBED_CONF_MBED_TRACE_ENABLE
#endif
#define MBED_CONF_MBED_TRACE_ENABLE 1
#define MBED_CONF_MBED_TRACE_ENABLE 1
#ifndef MBED_CONF_MBED_TRACE_FEA_IPV6
#define MBED_CONF_MBED_TRACE_FEA_IPV6 1
#define MBED_CONF_MBED_TRACE_FEA_IPV6 1
#endif

#include "mbed-trace/mbed_trace.h"
Expand Down Expand Up @@ -593,3 +595,5 @@ char *mbed_trace_array(const uint8_t *buf, uint16_t len)
m_trace.tmp_data_ptr = wptr;
return str;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,11 @@ static uint8_t nd_router_bootstrap_timer(nd_router_t *cur, protocol_interface_in
cur->nd_timer = nd_params.rs_retry_interval_min;
cur->nd_timer += randLIB_get_16bit() & nd_params.timer_random_max;
cur->ns_retry--;
tr_debug(cur->nd_state == ND_RS_UNCAST ? "RS" : "RS+");
if (cur->nd_state == ND_RS_UNCAST) {
tr_debug("RS");
} else {
tr_debug("RS+");
}
} else {
cur->nd_timer = 2;
}
Expand Down
1 change: 1 addition & 0 deletions mbed.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "platform/mbed_interface.h"
#include "platform/mbed_assert.h"
#include "platform/mbed_debug.h"
#include "platform/mbed_log_trace.h"

// mbed Peripheral components
#include "drivers/DigitalIn.h"
Expand Down
Loading