mirror of https://github.com/ARMmbed/mbed-os.git
Squashed 'features/frameworks/mbed-trace/' changes from 9eaf0d1..7a1bd34
7a1bd34 Use Mbed OS coding style (#86) git-subtree-dir: features/frameworks/mbed-trace git-subtree-split: 7a1bd34be547f3aa9badfbeb1c9993ff4a9e1dedpull/8647/head
parent
7fab5abace
commit
1374a5e5e6
|
@ -180,11 +180,11 @@ extern "C" {
|
|||
* Initialize trace functionality
|
||||
* @return 0 when all success, otherwise non zero
|
||||
*/
|
||||
int mbed_trace_init( void );
|
||||
int mbed_trace_init(void);
|
||||
/**
|
||||
* Free trace memory
|
||||
*/
|
||||
void mbed_trace_free( void );
|
||||
void mbed_trace_free(void);
|
||||
/**
|
||||
* Resize buffers (line / tmp ) sizes
|
||||
* @param lineLength new maximum length for trace line (0 = do no resize)
|
||||
|
@ -226,7 +226,7 @@ uint8_t mbed_trace_config_get(void);
|
|||
* char* trace_time(){ return "rtc-time-in-string"; }
|
||||
* mbed_trace_prefix_function_set( &trace_time );
|
||||
*/
|
||||
void mbed_trace_prefix_function_set( char* (*pref_f)(size_t) );
|
||||
void mbed_trace_prefix_function_set(char *(*pref_f)(size_t));
|
||||
/**
|
||||
* Set trace suffix function
|
||||
* suffix -function return string with null terminated
|
||||
|
@ -235,18 +235,18 @@ void mbed_trace_prefix_function_set( char* (*pref_f)(size_t) );
|
|||
* char* trace_suffix(){ return " END"; }
|
||||
* mbed_trace_suffix_function_set( &trace_suffix );
|
||||
*/
|
||||
void mbed_trace_suffix_function_set(char* (*suffix_f)(void) );
|
||||
void mbed_trace_suffix_function_set(char *(*suffix_f)(void));
|
||||
/**
|
||||
* Set trace print function
|
||||
* By default, trace module print using printf() function,
|
||||
* but with this you can write own print function,
|
||||
* for e.g. to other IO device.
|
||||
*/
|
||||
void mbed_trace_print_function_set( void (*print_f)(const char*) );
|
||||
void mbed_trace_print_function_set(void (*print_f)(const char *));
|
||||
/**
|
||||
* Set trace print function for tr_cmdline()
|
||||
*/
|
||||
void mbed_trace_cmdprint_function_set( void (*printf)(const char*) );
|
||||
void mbed_trace_cmdprint_function_set(void (*printf)(const char *));
|
||||
/**
|
||||
* Set trace mutex wait function
|
||||
* By default, trace calls are not thread safe.
|
||||
|
@ -270,10 +270,10 @@ void mbed_trace_mutex_release_function_set(void (*mutex_release_f)(void));
|
|||
* mbed_trace_exclude_filters_set("mygr");
|
||||
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "ougr", "This is not printed");
|
||||
*/
|
||||
void mbed_trace_exclude_filters_set(char* filters);
|
||||
void mbed_trace_exclude_filters_set(char *filters);
|
||||
/** get trace exclude filters
|
||||
*/
|
||||
const char* mbed_trace_exclude_filters_get(void);
|
||||
const char *mbed_trace_exclude_filters_get(void);
|
||||
/**
|
||||
* When trace group contains text in filter,
|
||||
* trace will be printed.
|
||||
|
@ -282,10 +282,10 @@ const char* mbed_trace_exclude_filters_get(void);
|
|||
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "mygr", "Hi There");
|
||||
* mbed_tracef(TRACE_ACTIVE_LEVEL_DEBUG, "grp2", "This is not printed");
|
||||
*/
|
||||
void mbed_trace_include_filters_set(char* filters);
|
||||
void mbed_trace_include_filters_set(char *filters);
|
||||
/** get trace include filters
|
||||
*/
|
||||
const char* mbed_trace_include_filters_get(void);
|
||||
const char *mbed_trace_include_filters_get(void);
|
||||
/**
|
||||
* General trace function
|
||||
* This should be used every time when user want to print out something important thing
|
||||
|
@ -298,9 +298,9 @@ const char* mbed_trace_include_filters_get(void);
|
|||
* @param ... variable arguments related to fmt
|
||||
*/
|
||||
#if defined(__GNUC__) || defined(__CC_ARM)
|
||||
void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...) __attribute__ ((__format__(__printf__, 3, 4)));
|
||||
void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...) __attribute__((__format__(__printf__, 3, 4)));
|
||||
#else
|
||||
void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...);
|
||||
void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...);
|
||||
#endif
|
||||
/**
|
||||
* General trace function
|
||||
|
@ -318,16 +318,16 @@ void mbed_tracef(uint8_t dlevel, const char* grp, const char *fmt, ...);
|
|||
* @param ap variable arguments list (like vprintf)
|
||||
*/
|
||||
#if defined(__GNUC__) || defined(__CC_ARM)
|
||||
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap) __attribute__ ((__format__(__printf__, 3, 0)));
|
||||
void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap) __attribute__((__format__(__printf__, 3, 0)));
|
||||
#else
|
||||
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap);
|
||||
void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap);
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Get last trace from buffer
|
||||
*/
|
||||
const char* mbed_trace_last(void);
|
||||
const char *mbed_trace_last(void);
|
||||
#if MBED_CONF_MBED_TRACE_FEA_IPV6 == 1
|
||||
/**
|
||||
* mbed_tracef helping function for convert ipv6
|
||||
|
@ -339,7 +339,7 @@ const char* mbed_trace_last(void);
|
|||
* @param add_ptr IPv6 Address pointer
|
||||
* @return temporary buffer where ipv6 is in string format
|
||||
*/
|
||||
char* mbed_trace_ipv6(const void *addr_ptr);
|
||||
char *mbed_trace_ipv6(const void *addr_ptr);
|
||||
/**
|
||||
* mbed_tracef helping function for print ipv6 prefix
|
||||
* usage e.g.
|
||||
|
@ -350,7 +350,7 @@ char* mbed_trace_ipv6(const void *addr_ptr);
|
|||
* @param prefix_len prefix length
|
||||
* @return temporary buffer where ipv6 is in string format
|
||||
*/
|
||||
char* mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
|
||||
char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
|
||||
#endif
|
||||
/**
|
||||
* mbed_tracef helping function for convert hex-array to string.
|
||||
|
@ -364,7 +364,7 @@ char* mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len);
|
|||
* if array as string not fit to temp buffer, this function write '*' as last character,
|
||||
* which indicate that buffer is too small for array.
|
||||
*/
|
||||
char* mbed_trace_array(const uint8_t* buf, uint16_t len);
|
||||
char *mbed_trace_array(const uint8_t *buf, uint16_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
#endif
|
||||
|
||||
/** default print function, just redirect str to printf */
|
||||
static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length);
|
||||
static void mbed_trace_realloc(char **buffer, int *length_ptr, int new_length);
|
||||
static void mbed_trace_default_print(const char *str);
|
||||
static void mbed_trace_reset_tmp(void);
|
||||
|
||||
|
@ -209,7 +209,7 @@ void mbed_trace_free(void)
|
|||
m_trace.mutex_release_f = 0;
|
||||
m_trace.mutex_lock_count = 0;
|
||||
}
|
||||
static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length)
|
||||
static void mbed_trace_realloc(char **buffer, int *length_ptr, int new_length)
|
||||
{
|
||||
MBED_TRACE_MEM_FREE(*buffer);
|
||||
*buffer = MBED_TRACE_MEM_ALLOC(new_length);
|
||||
|
@ -217,11 +217,11 @@ static void mbed_trace_realloc( char **buffer, int *length_ptr, int new_length)
|
|||
}
|
||||
void mbed_trace_buffer_sizes(int lineLength, int tmpLength)
|
||||
{
|
||||
if( lineLength > 0 ) {
|
||||
mbed_trace_realloc( &(m_trace.line), &m_trace.line_length, lineLength );
|
||||
if (lineLength > 0) {
|
||||
mbed_trace_realloc(&(m_trace.line), &m_trace.line_length, lineLength);
|
||||
}
|
||||
if( tmpLength > 0 ) {
|
||||
mbed_trace_realloc( &(m_trace.tmp_data), &m_trace.tmp_data_length, tmpLength);
|
||||
if (tmpLength > 0) {
|
||||
mbed_trace_realloc(&(m_trace.tmp_data), &m_trace.tmp_data_length, tmpLength);
|
||||
mbed_trace_reset_tmp();
|
||||
}
|
||||
}
|
||||
|
@ -311,9 +311,9 @@ void mbed_tracef(uint8_t dlevel, const char *grp, const char *fmt, ...)
|
|||
mbed_vtracef(dlevel, grp, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap)
|
||||
void mbed_vtracef(uint8_t dlevel, const char *grp, const char *fmt, va_list ap)
|
||||
{
|
||||
if ( m_trace.mutex_wait_f ) {
|
||||
if (m_trace.mutex_wait_f) {
|
||||
m_trace.mutex_wait_f();
|
||||
m_trace.mutex_lock_count++;
|
||||
}
|
||||
|
@ -476,7 +476,7 @@ void mbed_vtracef(uint8_t dlevel, const char* grp, const char *fmt, va_list ap)
|
|||
}
|
||||
|
||||
end:
|
||||
if ( m_trace.mutex_release_f ) {
|
||||
if (m_trace.mutex_release_f) {
|
||||
// Store the mutex lock count to temp variable so that it won't get
|
||||
// clobbered during last loop iteration when mutex gets released
|
||||
int count = m_trace.mutex_lock_count;
|
||||
|
@ -507,7 +507,7 @@ const char *mbed_trace_last(void)
|
|||
char *mbed_trace_ipv6(const void *addr_ptr)
|
||||
{
|
||||
/** Acquire mutex. It is released before returning from mbed_vtracef. */
|
||||
if ( m_trace.mutex_wait_f ) {
|
||||
if (m_trace.mutex_wait_f) {
|
||||
m_trace.mutex_wait_f();
|
||||
m_trace.mutex_lock_count++;
|
||||
}
|
||||
|
@ -528,7 +528,7 @@ char *mbed_trace_ipv6(const void *addr_ptr)
|
|||
char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
|
||||
{
|
||||
/** Acquire mutex. It is released before returning from mbed_vtracef. */
|
||||
if ( m_trace.mutex_wait_f ) {
|
||||
if (m_trace.mutex_wait_f) {
|
||||
m_trace.mutex_wait_f();
|
||||
m_trace.mutex_lock_count++;
|
||||
}
|
||||
|
@ -551,7 +551,7 @@ char *mbed_trace_ipv6_prefix(const uint8_t *prefix, uint8_t prefix_len)
|
|||
char *mbed_trace_array(const uint8_t *buf, uint16_t len)
|
||||
{
|
||||
/** Acquire mutex. It is released before returning from mbed_vtracef. */
|
||||
if ( m_trace.mutex_wait_f ) {
|
||||
if (m_trace.mutex_wait_f) {
|
||||
m_trace.mutex_wait_f();
|
||||
m_trace.mutex_lock_count++;
|
||||
}
|
||||
|
@ -581,7 +581,7 @@ char *mbed_trace_array(const uint8_t *buf, uint16_t len)
|
|||
wptr += retval;
|
||||
}
|
||||
if (wptr > str) {
|
||||
if( overflow ) {
|
||||
if (overflow) {
|
||||
// replace last character as 'star',
|
||||
// which indicate buffer len is not enough
|
||||
*(wptr - 1) = '*';
|
||||
|
|
123
test/Test.cpp
123
test/Test.cpp
|
@ -39,26 +39,24 @@ void my_mutex_release()
|
|||
|
||||
char buf[1024];
|
||||
#include <stdio.h>
|
||||
void myprint(const char* str)
|
||||
void myprint(const char *str)
|
||||
{
|
||||
if ( check_mutex_lock_status ) {
|
||||
CHECK( (mutex_wait_count - mutex_release_count) > 0 );
|
||||
if (check_mutex_lock_status) {
|
||||
CHECK((mutex_wait_count - mutex_release_count) > 0);
|
||||
}
|
||||
strcpy(buf, str);
|
||||
}
|
||||
TEST_GROUP(trace)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
void setup() {
|
||||
|
||||
mbed_trace_init();
|
||||
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_print_function_set( myprint );
|
||||
mbed_trace_mutex_wait_function_set( my_mutex_wait );
|
||||
mbed_trace_mutex_release_function_set( my_mutex_release );
|
||||
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_print_function_set(myprint);
|
||||
mbed_trace_mutex_wait_function_set(my_mutex_wait);
|
||||
mbed_trace_mutex_release_function_set(my_mutex_release);
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
void teardown() {
|
||||
CHECK(mutex_wait_count == mutex_release_count); // Check the mutex count with every test
|
||||
mbed_trace_free();
|
||||
}
|
||||
|
@ -67,8 +65,8 @@ TEST_GROUP(trace)
|
|||
/* Unity test code starts */
|
||||
TEST(trace, MutexNotSet)
|
||||
{
|
||||
mbed_trace_mutex_wait_function_set( 0 );
|
||||
mbed_trace_mutex_release_function_set( 0 );
|
||||
mbed_trace_mutex_wait_function_set(0);
|
||||
mbed_trace_mutex_release_function_set(0);
|
||||
int mutex_call_count_at_entry = mutex_wait_count;
|
||||
check_mutex_lock_status = false;
|
||||
|
||||
|
@ -76,19 +74,21 @@ TEST(trace, MutexNotSet)
|
|||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "Hello hello!");
|
||||
STRCMP_EQUAL(expectedStr, buf);
|
||||
|
||||
CHECK( mutex_call_count_at_entry == mutex_wait_count );
|
||||
CHECK( mutex_call_count_at_entry == mutex_release_count );
|
||||
CHECK(mutex_call_count_at_entry == mutex_wait_count);
|
||||
CHECK(mutex_call_count_at_entry == mutex_release_count);
|
||||
|
||||
mbed_trace_mutex_wait_function_set( my_mutex_wait );
|
||||
mbed_trace_mutex_release_function_set( my_mutex_release );
|
||||
mbed_trace_mutex_wait_function_set(my_mutex_wait);
|
||||
mbed_trace_mutex_release_function_set(my_mutex_release);
|
||||
check_mutex_lock_status = true;
|
||||
}
|
||||
|
||||
TEST(trace, Array)
|
||||
{
|
||||
unsigned char longStr[200] = {0x66};
|
||||
for(int i=0;i<200;i++) {longStr[i] = 0x66; }
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(longStr, 200) );
|
||||
for (int i = 0; i < 200; i++) {
|
||||
longStr[i] = 0x66;
|
||||
}
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", mbed_trace_array(longStr, 200));
|
||||
}
|
||||
|
||||
TEST(trace, Null0Array)
|
||||
|
@ -107,23 +107,29 @@ TEST(trace, Null0Array)
|
|||
TEST(trace, LongString)
|
||||
{
|
||||
char longStr[1000] = {0x36};
|
||||
for(int i=0;i<999;i++) {longStr[i] = 0x36; }
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr );
|
||||
for (int i = 0; i < 999; i++) {
|
||||
longStr[i] = 0x36;
|
||||
}
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr);
|
||||
}
|
||||
|
||||
TEST(trace, TooLong)
|
||||
{
|
||||
#define TOO_LONG_SIZE 9400
|
||||
#define TRACE_LINE_SIZE 1024
|
||||
#define TOO_LONG_SIZE 9400
|
||||
#define TRACE_LINE_SIZE 1024
|
||||
char longStr[TOO_LONG_SIZE] = {0};
|
||||
for(int i=0;i<TOO_LONG_SIZE;i++) { longStr[i] = 0x36; }
|
||||
for (int i = 0; i < TOO_LONG_SIZE; i++) {
|
||||
longStr[i] = 0x36;
|
||||
}
|
||||
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr );
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "%s", longStr);
|
||||
|
||||
char shouldStr[TRACE_LINE_SIZE] = "[DBG ][mygr]: ";
|
||||
for(int i=14;i<TRACE_LINE_SIZE;i++) { shouldStr[i] = 0x36; }
|
||||
shouldStr[TRACE_LINE_SIZE-1] = 0;
|
||||
for (int i = 14; i < TRACE_LINE_SIZE; i++) {
|
||||
shouldStr[i] = 0x36;
|
||||
}
|
||||
shouldStr[TRACE_LINE_SIZE - 1] = 0;
|
||||
STRCMP_EQUAL(shouldStr, buf);
|
||||
}
|
||||
|
||||
|
@ -139,7 +145,7 @@ TEST(trace, BufferResize)
|
|||
mbed_trace_buffer_sizes(0, 15);
|
||||
STRCMP_EQUAL("30:30:30:30", mbed_trace_array(arr, 4));
|
||||
|
||||
const char * expectedStr = "0123456789";
|
||||
const char *expectedStr = "0123456789";
|
||||
mbed_trace_buffer_sizes(11, 0);
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
|
||||
STRCMP_EQUAL(expectedStr, buf);
|
||||
|
@ -159,16 +165,16 @@ TEST(trace, PreInitConfiguration)
|
|||
memset(arr, '0', 20);
|
||||
|
||||
mbed_trace_free();
|
||||
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_print_function_set( myprint );
|
||||
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_print_function_set(myprint);
|
||||
mbed_trace_buffer_sizes(11, 10);
|
||||
mbed_trace_mutex_wait_function_set( my_mutex_wait );
|
||||
mbed_trace_mutex_release_function_set( my_mutex_release );
|
||||
mbed_trace_mutex_wait_function_set(my_mutex_wait);
|
||||
mbed_trace_mutex_release_function_set(my_mutex_release);
|
||||
mbed_trace_init();
|
||||
|
||||
STRCMP_EQUAL("30:30:30*", mbed_trace_array(arr, 20));
|
||||
|
||||
const char * expectedStr = "0123456789";
|
||||
const char *expectedStr = "0123456789";
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
|
||||
STRCMP_EQUAL(expectedStr, buf);
|
||||
}
|
||||
|
@ -218,7 +224,7 @@ TEST(trace, active_level_all_ipv6)
|
|||
{
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
||||
|
||||
uint8_t arr[] = { 0x20, 0x01, 0xd, 0xb8, 0,0,0,0,0,1,0,0,0,0,0,1 };
|
||||
uint8_t arr[] = { 0x20, 0x01, 0xd, 0xb8, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 };
|
||||
ip6tos_stub.output_string = "2001:db8::1:0:0:1";
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "my addr: %s", mbed_trace_ipv6(arr));
|
||||
CHECK(memcmp(ip6tos_stub.input_array, arr, 16) == 0);
|
||||
|
@ -228,19 +234,19 @@ TEST(trace, active_level_all_ipv6)
|
|||
|
||||
TEST(trace, config_change)
|
||||
{
|
||||
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
|
||||
CHECK(mbed_trace_config_get() == TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_NONE);
|
||||
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_NONE);
|
||||
mbed_trace_config_set(TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
|
||||
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN|TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_config_set(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
|
||||
CHECK(mbed_trace_config_get() == TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_NONE);
|
||||
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_NONE);
|
||||
mbed_trace_config_set(TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
|
||||
CHECK(mbed_trace_config_get() == TRACE_MODE_PLAIN | TRACE_ACTIVE_LEVEL_ALL);
|
||||
}
|
||||
|
||||
TEST(trace, active_level_all_color)
|
||||
{
|
||||
mbed_trace_config_set(TRACE_MODE_COLOR|TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_config_set(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
|
||||
// unknown debug level
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG+1, "mygr", "hep");
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG + 1, "mygr", "hep");
|
||||
STRCMP_EQUAL(" hep", buf);
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
|
||||
STRCMP_EQUAL("\x1b[90m[DBG ][mygr]: hello\x1b[0m", buf);
|
||||
|
@ -258,11 +264,11 @@ TEST(trace, change_levels)
|
|||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
||||
STRCMP_EQUAL("[DBG ][mygr]: hep", buf);
|
||||
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG|TRACE_MODE_PLAIN);
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG | TRACE_MODE_PLAIN);
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
||||
STRCMP_EQUAL("hep", buf);
|
||||
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG|TRACE_MODE_COLOR);
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG | TRACE_MODE_COLOR);
|
||||
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "hep");
|
||||
STRCMP_EQUAL("\x1b[31m[ERR ][mygr]: hep\x1b[0m", buf);
|
||||
|
||||
|
@ -273,7 +279,7 @@ TEST(trace, active_level_debug)
|
|||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);
|
||||
|
||||
// unknown debug level
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG+1, "mygr", "hep");
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG + 1, "mygr", "hep");
|
||||
STRCMP_EQUAL(" hep", buf);
|
||||
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
||||
|
@ -360,7 +366,7 @@ TEST(trace, active_level_none)
|
|||
TEST(trace, active_level_all_1)
|
||||
{
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_exclude_filters_set((char*)"mygr");
|
||||
mbed_trace_exclude_filters_set((char *)"mygr");
|
||||
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
|
||||
STRCMP_EQUAL("[DBG ][mygu]: hep", buf);
|
||||
|
@ -371,7 +377,7 @@ TEST(trace, active_level_all_1)
|
|||
TEST(trace, active_level_all_2)
|
||||
{
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_exclude_filters_set((char*)"mygr,mygu");
|
||||
mbed_trace_exclude_filters_set((char *)"mygr,mygu");
|
||||
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
|
||||
STRCMP_EQUAL("", mbed_trace_last());
|
||||
|
@ -382,7 +388,7 @@ TEST(trace, active_level_all_2)
|
|||
TEST(trace, active_level_all_3)
|
||||
{
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_include_filters_set((char*)"mygr");
|
||||
mbed_trace_include_filters_set((char *)"mygr");
|
||||
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
|
||||
STRCMP_EQUAL("", mbed_trace_last());
|
||||
|
@ -403,36 +409,37 @@ TEST(trace, active_level_all_array)
|
|||
|
||||
size_t time_length;
|
||||
char trace_prefix_str[] = "[<TIME>]";
|
||||
char* trace_prefix(size_t length){
|
||||
char *trace_prefix(size_t length)
|
||||
{
|
||||
time_length = length;
|
||||
return trace_prefix_str;
|
||||
}
|
||||
TEST(trace, prefix)
|
||||
{
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_prefix_function_set( &trace_prefix );
|
||||
mbed_trace_prefix_function_set(&trace_prefix);
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test %d %d", 1, 2);
|
||||
STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test 1 2", buf);
|
||||
//TEST_ASSERT_EQUAL_INT(4, time_length);
|
||||
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL|TRACE_MODE_PLAIN);
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL | TRACE_MODE_PLAIN);
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test");
|
||||
STRCMP_EQUAL("test", buf);
|
||||
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL|TRACE_MODE_COLOR);
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL | TRACE_MODE_COLOR);
|
||||
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "test");
|
||||
STRCMP_EQUAL("\x1b[31m[<TIME>][ERR ][mygr]: test\x1b[0m", buf);
|
||||
}
|
||||
char trace_suffix_str[] = "[END]";
|
||||
char* trace_suffix()
|
||||
char *trace_suffix()
|
||||
{
|
||||
return trace_suffix_str;
|
||||
}
|
||||
TEST(trace, suffix)
|
||||
{
|
||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
||||
mbed_trace_prefix_function_set( &trace_prefix );
|
||||
mbed_trace_suffix_function_set( &trace_suffix );
|
||||
mbed_trace_prefix_function_set(&trace_prefix);
|
||||
mbed_trace_suffix_function_set(&trace_suffix);
|
||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "test");
|
||||
STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test[END]", buf);
|
||||
}
|
||||
|
@ -449,13 +456,13 @@ TEST(trace, formatting)
|
|||
}
|
||||
TEST(trace, filters_control)
|
||||
{
|
||||
mbed_trace_include_filters_set((char*)"hello");
|
||||
mbed_trace_include_filters_set((char *)"hello");
|
||||
STRCMP_EQUAL("hello", mbed_trace_include_filters_get());
|
||||
|
||||
mbed_trace_include_filters_set(0);
|
||||
STRCMP_EQUAL("", mbed_trace_include_filters_get());
|
||||
|
||||
mbed_trace_exclude_filters_set((char*)"hello");
|
||||
mbed_trace_exclude_filters_set((char *)"hello");
|
||||
STRCMP_EQUAL("hello", mbed_trace_exclude_filters_get());
|
||||
|
||||
mbed_trace_exclude_filters_set(0);
|
||||
|
@ -468,7 +475,7 @@ TEST(trace, cmd_printer)
|
|||
mbed_tracef(TRACE_LEVEL_CMD, "mygr", "default printer");
|
||||
STRCMP_EQUAL("default printer", buf);
|
||||
|
||||
mbed_trace_cmdprint_function_set( myprint );
|
||||
mbed_trace_cmdprint_function_set(myprint);
|
||||
mbed_tracef(TRACE_LEVEL_CMD, "mygr", "custom printer");
|
||||
STRCMP_EQUAL("\n", buf); // because there is two print calls, second one add line feeds
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue