mirror of https://github.com/ARMmbed/mbed-os.git
Squashed 'features/frameworks/mbed-trace/' changes from 0a4f6be..642a459
642a459 Cleanup for Mbed OS release git-subtree-dir: features/frameworks/mbed-trace git-subtree-split: 642a459a3932753dbb724cc695fdba5e923231dbpull/9838/head
parent
14ff147a61
commit
12a2437b39
|
@ -1 +0,0 @@
|
||||||
BUILD
|
|
37
.astylerc
37
.astylerc
|
@ -1,37 +0,0 @@
|
||||||
# Mbed OS code style definition file for astyle
|
|
||||||
|
|
||||||
# Don't create backup files, let git handle it
|
|
||||||
suffix=none
|
|
||||||
|
|
||||||
# K&R style
|
|
||||||
style=kr
|
|
||||||
|
|
||||||
# 1 TBS addition to k&r, add braces to one liners
|
|
||||||
# Use -j as it was changed in astyle from brackets to braces, this way it is compatible with older astyle versions
|
|
||||||
-j
|
|
||||||
|
|
||||||
# 4 spaces, convert tabs to spaces
|
|
||||||
indent=spaces=4
|
|
||||||
convert-tabs
|
|
||||||
|
|
||||||
# Indent switches and cases
|
|
||||||
indent-switches
|
|
||||||
|
|
||||||
# Remove spaces in and around parentheses
|
|
||||||
unpad-paren
|
|
||||||
|
|
||||||
# Insert a space after if, while, for, and around operators
|
|
||||||
pad-header
|
|
||||||
pad-oper
|
|
||||||
|
|
||||||
# Pointer/reference operators go next to the name (on the right)
|
|
||||||
align-pointer=name
|
|
||||||
align-reference=name
|
|
||||||
|
|
||||||
# Attach { for classes and namespaces
|
|
||||||
attach-namespaces
|
|
||||||
attach-classes
|
|
||||||
|
|
||||||
# Extend longer lines, define maximum 120 value. This results in aligned code,
|
|
||||||
# otherwise the lines are broken and not consistent
|
|
||||||
max-continuation-indent=120
|
|
|
@ -1 +0,0 @@
|
||||||
/*CMakeLists.txt
|
|
|
@ -1,2 +0,0 @@
|
||||||
all:
|
|
||||||
gcc main.c -g -I ../.. ../../source/mbed_trace.c -DYOTTA_CFG -DMBED_CONF_MBED_TRACE_FEA_IPV6=0 -o app
|
|
|
@ -1,13 +0,0 @@
|
||||||
# linux example application using mbed-trace library
|
|
||||||
|
|
||||||
## build
|
|
||||||
|
|
||||||
```
|
|
||||||
make
|
|
||||||
```
|
|
||||||
|
|
||||||
## run
|
|
||||||
|
|
||||||
```
|
|
||||||
./app
|
|
||||||
```
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 ARM Limited. All rights reserved.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
* 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 <stdio.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "mbed-trace/mbed_trace.h"
|
|
||||||
#define TRACE_GROUP "main"
|
|
||||||
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
mbed_trace_init();
|
|
||||||
tr_debug("debug print");
|
|
||||||
tr_info("info print");
|
|
||||||
tr_warn("warning print");
|
|
||||||
tr_error("error print");
|
|
||||||
mbed_trace_free();
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
valgrind --leak-check=yes --error-exitcode=1 ./app
|
|
|
@ -1,27 +0,0 @@
|
||||||
# mbed-os 5 example application using mbed-trace library
|
|
||||||
|
|
||||||
## define mbed-os.lib
|
|
||||||
|
|
||||||
```
|
|
||||||
echo https://github.com/armmbed/mbed-os/#6a0a86538c0b9b2bfcc4583b1e2b7fea8f4e71e9 > mbed-os.lib
|
|
||||||
```
|
|
||||||
|
|
||||||
## build
|
|
||||||
|
|
||||||
```
|
|
||||||
mbed deploy
|
|
||||||
mbed compile -t GCC_ARM -m K64F
|
|
||||||
```
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
When you flash a target with this application and open a terminal you should see the following traces:
|
|
||||||
|
|
||||||
```
|
|
||||||
[INFO][main] Hello tracers
|
|
||||||
[DBG ][main] Infinite loop..
|
|
||||||
[DBG ][main] Infinite loop..
|
|
||||||
[DBG ][main] Infinite loop..
|
|
||||||
...
|
|
||||||
```
|
|
|
@ -1,32 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2018 ARM Limited. All rights reserved.
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
* 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 <stdio.h>
|
|
||||||
|
|
||||||
#include "mbed.h"
|
|
||||||
#include "mbed_trace.h"
|
|
||||||
|
|
||||||
#define TRACE_GROUP "main"
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
// Initialize trace library
|
|
||||||
mbed_trace_init();
|
|
||||||
// trace Something
|
|
||||||
tr_info("Hello tracers");
|
|
||||||
while(1) {
|
|
||||||
tr_debug("Infinite loop..");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"macros": [
|
|
||||||
"MEM_ALLOC=malloc",
|
|
||||||
"MEM_FREE=free"
|
|
||||||
],
|
|
||||||
"target_overrides": {
|
|
||||||
"*": {
|
|
||||||
"platform.stdio-baud-rate": 115200,
|
|
||||||
"platform.stdio-convert-newlines": true,
|
|
||||||
"platform.stdio-buffered-serial": true,
|
|
||||||
"target.features_add": ["COMMON_PAL"],
|
|
||||||
"mbed-trace.enable": 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
42
module.json
42
module.json
|
@ -1,42 +0,0 @@
|
||||||
{
|
|
||||||
"name": "mbed-trace",
|
|
||||||
"version": "1.3.0",
|
|
||||||
"description": "Trace library for mbed devices",
|
|
||||||
"keywords": [
|
|
||||||
"trace",
|
|
||||||
"debug",
|
|
||||||
"library",
|
|
||||||
"client",
|
|
||||||
"mbedOS",
|
|
||||||
"mbed"
|
|
||||||
],
|
|
||||||
"author": "Jussi Vatjus-Anttila",
|
|
||||||
"repository": {
|
|
||||||
"url": "https://github.com/ARMmbed/mbed-trace.git",
|
|
||||||
"type": "git"
|
|
||||||
},
|
|
||||||
"homepage": "https://github.com/ARMmbed/mbed-trace",
|
|
||||||
"licenses": [
|
|
||||||
{
|
|
||||||
"url": "https://spdx.org/licenses/Apache-2.0",
|
|
||||||
"type": "Apache-2.0"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"testTargetDependencies": {
|
|
||||||
"x86-linux-native": {
|
|
||||||
"cpputest": "ARMmbed/cpputest",
|
|
||||||
"nanostack-libservice": "^3.6.0"
|
|
||||||
},
|
|
||||||
"x86-osx-native": {
|
|
||||||
"cpputest": "ARMmbed/cpputest",
|
|
||||||
"nanostack-libservice": "^3.6.0"
|
|
||||||
},
|
|
||||||
"x86-windows-native": {
|
|
||||||
"cpputest": "ARMmbed/cpputest",
|
|
||||||
"nanostack-libservice": "^3.6.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"nanostack-libservice": "^3.6.0"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
# only build tests on targets that declare they are like posix
|
|
||||||
if(DEFINED TARGET_LIKE_X86_WINDOWS_NATIVE OR DEFINED TARGET_LIKE_X86_LINUX_NATIVE OR DEFINED TARGET_LIKE_X86_OSX_NATIVE)
|
|
||||||
|
|
||||||
# describe the test executable
|
|
||||||
add_executable(mbed_trace_test EXCLUDE_FROM_ALL Test.cpp stubs/ip6tos_stub.c)
|
|
||||||
|
|
||||||
include_directories("../yotta_modules/cpputest" "./stubs")
|
|
||||||
|
|
||||||
# describe what the test executable needs to link with
|
|
||||||
target_link_libraries(mbed_trace_test "mbed-trace" cpputest)
|
|
||||||
|
|
||||||
# describe what is actual test binary
|
|
||||||
if(DEFINED TARGET_LIKE_X86_WINDOWS_NATIVE)
|
|
||||||
add_test(mbed_trace_test "build/x86-windows-native/test/mbed_trace_test")
|
|
||||||
add_dependencies(all_tests mbed_trace_test)
|
|
||||||
elseif(DEFINED TARGET_LIKE_X86_LINUX_NATIVE)
|
|
||||||
SET(TEST_EXECUTABLE "../../../build/x86-linux-native/test/mbed_trace_test")
|
|
||||||
add_test(mbed_trace_test ${TEST_EXECUTABLE})
|
|
||||||
add_dependencies(all_tests mbed_trace_test)
|
|
||||||
elseif(DEFINED TARGET_LIKE_X86_OSX_NATIVE)
|
|
||||||
SET(TEST_EXECUTABLE "../../../build/x86-osx-native/test/mbed_trace_test")
|
|
||||||
add_test(mbed_trace_test ${TEST_EXECUTABLE})
|
|
||||||
add_dependencies(all_tests mbed_trace_test)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
501
test/Test.cpp
501
test/Test.cpp
|
@ -1,501 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2014 ARM. All rights reserved.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* \file \test_libTrace\Test.c
|
|
||||||
*
|
|
||||||
* \brief Unit tests for mbed_trace
|
|
||||||
*/
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#include "mbed-cpputest/CppUTest/TestHarness.h"
|
|
||||||
#include "mbed-cpputest/CppUTest/SimpleString.h"
|
|
||||||
#include "mbed-cpputest/CppUTest/CommandLineTestRunner.h"
|
|
||||||
|
|
||||||
#define MBED_CONF_MBED_TRACE_ENABLE 1
|
|
||||||
#define MBED_CONF_MBED_TRACE_FEA_IPV6 1
|
|
||||||
|
|
||||||
#include "mbed-trace/mbed_trace.h"
|
|
||||||
#include "ip6tos_stub.h"
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
return CommandLineTestRunner::RunAllTests(ac, av);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mutex_wait_count = 0;
|
|
||||||
static int mutex_release_count = 0;
|
|
||||||
static bool check_mutex_lock_status = true;
|
|
||||||
void my_mutex_wait()
|
|
||||||
{
|
|
||||||
mutex_wait_count++;
|
|
||||||
}
|
|
||||||
void my_mutex_release()
|
|
||||||
{
|
|
||||||
mutex_release_count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
char buf[1024];
|
|
||||||
#include <stdio.h>
|
|
||||||
void myprint(const char *str)
|
|
||||||
{
|
|
||||||
if (check_mutex_lock_status) {
|
|
||||||
CHECK((mutex_wait_count - mutex_release_count) > 0);
|
|
||||||
}
|
|
||||||
strcpy(buf, str);
|
|
||||||
}
|
|
||||||
TEST_GROUP(trace)
|
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
void teardown() {
|
|
||||||
CHECK(mutex_wait_count == mutex_release_count); // Check the mutex count with every test
|
|
||||||
mbed_trace_free();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Unity test code starts */
|
|
||||||
TEST(trace, MutexNotSet)
|
|
||||||
{
|
|
||||||
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;
|
|
||||||
|
|
||||||
char expectedStr[] = "Hello hello!";
|
|
||||||
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);
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
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};
|
|
||||||
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
|
|
||||||
char longStr[TOO_LONG_SIZE] = {0};
|
|
||||||
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);
|
|
||||||
|
|
||||||
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;
|
|
||||||
STRCMP_EQUAL(shouldStr, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, BufferResize)
|
|
||||||
{
|
|
||||||
uint8_t arr[20] = {0};
|
|
||||||
memset(arr, '0', 20);
|
|
||||||
|
|
||||||
mbed_trace_buffer_sizes(0, 10);
|
|
||||||
STRCMP_EQUAL("30:30:30*", mbed_trace_array(arr, 20));
|
|
||||||
mbed_trace_buffer_sizes(0, 15);
|
|
||||||
STRCMP_EQUAL("30:30:30:30*", mbed_trace_array(arr, 20));
|
|
||||||
mbed_trace_buffer_sizes(0, 15);
|
|
||||||
STRCMP_EQUAL("30:30:30:30", mbed_trace_array(arr, 4));
|
|
||||||
|
|
||||||
const char *expectedStr = "0123456789";
|
|
||||||
mbed_trace_buffer_sizes(11, 0);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
|
|
||||||
STRCMP_EQUAL(expectedStr, buf);
|
|
||||||
expectedStr = "012345678901234";
|
|
||||||
mbed_trace_buffer_sizes(16, 0);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
|
|
||||||
STRCMP_EQUAL(expectedStr, buf);
|
|
||||||
expectedStr = "012345678901234";
|
|
||||||
mbed_trace_buffer_sizes(16, 0);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "012345678901234");
|
|
||||||
STRCMP_EQUAL(expectedStr, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, PreInitConfiguration)
|
|
||||||
{
|
|
||||||
uint8_t arr[20] = {0};
|
|
||||||
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_buffer_sizes(11, 10);
|
|
||||||
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";
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "01234567890123456789");
|
|
||||||
STRCMP_EQUAL(expectedStr, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if YOTTA_CFG_MBED_TRACE_FEA_IPV6 == 1
|
|
||||||
ip6tos_stub_def_t ip6tos_stub; // extern variable
|
|
||||||
|
|
||||||
TEST(trace, ipv6)
|
|
||||||
{
|
|
||||||
uint8_t prefix[] = { 0x14, 0x6e, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
int prefix_len = 64;
|
|
||||||
|
|
||||||
char expected_str1[] = "146e:a00::/64";
|
|
||||||
ip6tos_stub.output_string = "146e:a00::/64";
|
|
||||||
char *str = mbed_trace_ipv6_prefix(prefix, prefix_len);
|
|
||||||
CHECK(memcmp(ip6tos_stub.input_array, prefix, 8) == 0);
|
|
||||||
STRCMP_EQUAL(expected_str1, str);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "flush buffers and locks");
|
|
||||||
|
|
||||||
char expected_str2[] = "::/0";
|
|
||||||
ip6tos_stub.output_string = "::/0";
|
|
||||||
str = mbed_trace_ipv6_prefix(NULL, 0);
|
|
||||||
STRCMP_EQUAL(expected_str2, str);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "flush buffers and locks");
|
|
||||||
|
|
||||||
char expected_str3[] = "<err>";
|
|
||||||
str = mbed_trace_ipv6_prefix(NULL, 1);
|
|
||||||
STRCMP_EQUAL(expected_str3, str);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "flush buffers and locks");
|
|
||||||
|
|
||||||
char expected_str4[] = "<err>";
|
|
||||||
str = mbed_trace_ipv6_prefix(prefix, 200);
|
|
||||||
STRCMP_EQUAL(expected_str4, str);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "flush buffers and locks");
|
|
||||||
|
|
||||||
char expected_str5[] = "";
|
|
||||||
ip6tos_stub.output_string = "0123456789012345678901234567890123456789";
|
|
||||||
str = mbed_trace_ipv6_prefix(prefix, 64); // Fill the tmp_data buffer
|
|
||||||
str = mbed_trace_ipv6_prefix(prefix, 64);
|
|
||||||
str = mbed_trace_ipv6_prefix(prefix, 64);
|
|
||||||
str = mbed_trace_ipv6_prefix(prefix, 64);
|
|
||||||
STRCMP_EQUAL(expected_str5, str);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "flush buffers and locks");
|
|
||||||
}
|
|
||||||
|
|
||||||
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 };
|
|
||||||
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);
|
|
||||||
STRCMP_EQUAL("[DBG ][mygr]: my addr: 2001:db8::1:0:0:1", buf);
|
|
||||||
}
|
|
||||||
#endif //YOTTA_CFG_MBED_TRACE_FEA_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);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, active_level_all_color)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_MODE_COLOR | TRACE_ACTIVE_LEVEL_ALL);
|
|
||||||
// unknown debug level
|
|
||||||
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);
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "to one");
|
|
||||||
STRCMP_EQUAL("\x1b[39m[INFO][mygr]: to one\x1b[0m", buf);
|
|
||||||
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "and all");
|
|
||||||
STRCMP_EQUAL("\x1b[33m[WARN][mygr]: and all\x1b[0m", buf);
|
|
||||||
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "even you");
|
|
||||||
STRCMP_EQUAL("\x1b[31m[ERR ][mygr]: even you\x1b[0m", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, change_levels)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);
|
|
||||||
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_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
|
||||||
STRCMP_EQUAL("hep", buf);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, active_level_debug)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_DEBUG);
|
|
||||||
|
|
||||||
// unknown debug level
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG + 1, "mygr", "hep");
|
|
||||||
STRCMP_EQUAL(" hep", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
|
||||||
STRCMP_EQUAL("[DBG ][mygr]: hep", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("[INFO][mygr]: test", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
|
|
||||||
STRCMP_EQUAL("[WARN][mygr]: hups", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
|
|
||||||
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, active_level_info)
|
|
||||||
{
|
|
||||||
buf[0] = 0;
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_INFO);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("[INFO][mygr]: test", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
|
|
||||||
STRCMP_EQUAL("[WARN][mygr]: hups", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
|
|
||||||
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, active_level_warn)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_WARN);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
|
|
||||||
STRCMP_EQUAL("[WARN][mygr]: hups", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
|
|
||||||
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, active_level_error)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ERROR);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
|
|
||||||
STRCMP_EQUAL("[ERR ][mygr]: o'ou", buf);
|
|
||||||
}
|
|
||||||
TEST(trace, active_level_none)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_NONE);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hep");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_WARN, "mygr", "hups");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_ERROR, "mygr", "o'ou");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, active_level_all_1)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
|
||||||
mbed_trace_exclude_filters_set((char *)"mygr");
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
|
|
||||||
STRCMP_EQUAL("[DBG ][mygu]: hep", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
}
|
|
||||||
TEST(trace, active_level_all_2)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
|
||||||
mbed_trace_exclude_filters_set((char *)"mygr,mygu");
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
}
|
|
||||||
TEST(trace, active_level_all_3)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
|
||||||
mbed_trace_include_filters_set((char *)"mygr");
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygu", "hep");
|
|
||||||
STRCMP_EQUAL("", mbed_trace_last());
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_INFO, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("[INFO][mygr]: test", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(trace, active_level_all_array)
|
|
||||||
{
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
|
||||||
|
|
||||||
uint8_t arr[] = {0x01, 0x02, 0x03};
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "my addr: %s", mbed_trace_array(arr, 3));
|
|
||||||
STRCMP_EQUAL("[DBG ][mygr]: my addr: 01:02:03", buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
size_t time_length;
|
|
||||||
char trace_prefix_str[] = "[<TIME>]";
|
|
||||||
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_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_tracef(TRACE_LEVEL_DEBUG, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("test", buf);
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
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_tracef(TRACE_LEVEL_DEBUG, "mygr", "test");
|
|
||||||
STRCMP_EQUAL("[<TIME>][DBG ][mygr]: test[END]", buf);
|
|
||||||
}
|
|
||||||
TEST(trace, formatting)
|
|
||||||
{
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello %d %d %.1f", 12, 13, 5.5);
|
|
||||||
STRCMP_EQUAL("hello 12 13 5.5", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello %d %d %d %d %d %d", 12, 13, 5, 6, 8, 9);
|
|
||||||
STRCMP_EQUAL("hello 12 13 5 6 8 9", buf);
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "HOH %d HAH %d %d %d %d %d", 12, 13, 5, 6, 8, 9);
|
|
||||||
STRCMP_EQUAL("HOH 12 HAH 13 5 6 8 9", buf);
|
|
||||||
}
|
|
||||||
TEST(trace, filters_control)
|
|
||||||
{
|
|
||||||
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");
|
|
||||||
STRCMP_EQUAL("hello", mbed_trace_exclude_filters_get());
|
|
||||||
|
|
||||||
mbed_trace_exclude_filters_set(0);
|
|
||||||
STRCMP_EQUAL("", mbed_trace_exclude_filters_get());
|
|
||||||
}
|
|
||||||
TEST(trace, cmd_printer)
|
|
||||||
{
|
|
||||||
buf[0] = 0;
|
|
||||||
mbed_trace_config_set(TRACE_ACTIVE_LEVEL_ALL);
|
|
||||||
mbed_tracef(TRACE_LEVEL_CMD, "mygr", "default printer");
|
|
||||||
STRCMP_EQUAL("default printer", buf);
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
TEST(trace, no_printer)
|
|
||||||
{
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
|
|
||||||
STRCMP_EQUAL("hello", buf);
|
|
||||||
|
|
||||||
mbed_trace_print_function_set(NULL);
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "this shoudnt be printed because printer is missing");
|
|
||||||
STRCMP_EQUAL("hello", buf);
|
|
||||||
}
|
|
||||||
TEST(trace, uninitialized)
|
|
||||||
{
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "hello");
|
|
||||||
STRCMP_EQUAL("hello", buf);
|
|
||||||
|
|
||||||
mbed_trace_free();
|
|
||||||
|
|
||||||
mbed_tracef(TRACE_LEVEL_DEBUG, "mygr", "this shoudnt be printed because mtrace is not initialized");
|
|
||||||
STRCMP_EQUAL("hello", buf);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2016 ARM Limited. All rights reserved.
|
|
||||||
*/
|
|
||||||
#include "ip6string.h"
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "common_functions.h"
|
|
||||||
|
|
||||||
#include "ip6tos_stub.h"
|
|
||||||
|
|
||||||
ip6tos_stub_def_t ip6tos_stub; // extern variable
|
|
||||||
|
|
||||||
uint8_t ip6tos(const void *ip6addr, char *p)
|
|
||||||
{
|
|
||||||
memcpy(ip6tos_stub.input_array, ip6addr, 16);
|
|
||||||
strcpy(p, ip6tos_stub.output_string);
|
|
||||||
return strlen(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint_fast8_t ip6_prefix_tos(const void *prefix, uint_fast8_t prefix_len, char *p)
|
|
||||||
{
|
|
||||||
bitcopy(ip6tos_stub.input_array, prefix, prefix_len);
|
|
||||||
strcpy(p, ip6tos_stub.output_string);
|
|
||||||
return strlen(p);
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2016 ARM Limited. All rights reserved.
|
|
||||||
*/
|
|
||||||
#ifndef MBED_TRACE_TEST_STUBS_IP6STRING_H_
|
|
||||||
#define MBED_TRACE_TEST_STUBS_IP6STRING_H_
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <inttypes.h>
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
const char *output_string;
|
|
||||||
uint8_t input_array[16];
|
|
||||||
} ip6tos_stub_def_t;
|
|
||||||
|
|
||||||
extern ip6tos_stub_def_t ip6tos_stub;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif /* MBED_TRACE_TEST_STUBS_IP6STRING_H_ */
|
|
Loading…
Reference in New Issue