diff options
| author | Bernard Xiong <[email protected]> | 2019-01-29 04:28:40 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-01-29 04:28:40 +0800 |
| commit | b2c2958964d429775e3da335a4f6ca5b4f9e1671 (patch) | |
| tree | 25a2209ba4814d41b19e624a136ca1c7c894918f /components/utilities/utest/utest.c | |
| parent | dfebb30c91875c52f16fd4e7bb9e5981fd0512b4 (diff) | |
| parent | 8ff9b7795f0423eee36a19b2a36cec4e00c1e831 (diff) | |
Merge pull request #2289 from armink/lts-v3.1.xv3.1.2
Lts v3.1.x
Diffstat (limited to 'components/utilities/utest/utest.c')
| -rw-r--r-- | components/utilities/utest/utest.c | 58 |
1 files changed, 51 insertions, 7 deletions
diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 0f5a206d3c..a0a42d7438 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -8,9 +8,10 @@ * 2018-11-19 MurphyZhao the first version */ -#include "utest.h" #include <rtthread.h> -#include <finsh.h> +#include <string.h> +#include "utest.h" +#include <utest_log.h> #undef DBG_SECTION_NAME #undef DBG_LEVEL @@ -31,6 +32,7 @@ #error "RT_CONSOLEBUF_SIZE is less than 256!" #endif +static rt_uint8_t utest_log_lv = UTEST_LOG_ALL; static utest_tc_export_t tc_table = RT_NULL; static rt_size_t tc_num; static struct utest local_utest = {UTEST_PASSED, 0, 0}; @@ -39,6 +41,14 @@ static struct utest local_utest = {UTEST_PASSED, 0, 0}; #pragma section="UtestTcTab" #endif +void utest_log_lv_set(rt_uint8_t lv) +{ + if (lv == UTEST_LOG_ALL || lv == UTEST_LOG_ASSERT) + { + utest_log_lv = lv; + } +} + int utest_init(void) { /* initialize the utest commands table.*/ @@ -112,7 +122,7 @@ static void utest_run(const char *utest_name) { if (tc_table[i].init() != RT_EOK) { - LOG_I("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); goto __tc_continue; } } @@ -126,19 +136,19 @@ static void utest_run(const char *utest_name) } else { - LOG_I("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); } } else { - LOG_I("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); } if (tc_table[i].cleanup != RT_NULL) { if (tc_table[i].cleanup() != RT_EOK) { - LOG_I("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); goto __tc_continue; } } @@ -200,7 +210,10 @@ void utest_assert(int value, const char *file, int line, const char *func, const } else { - LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line); + if (utest_log_lv == UTEST_LOG_ALL) + { + LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line); + } local_utest.error = UTEST_PASSED; local_utest.passed_num ++; } @@ -236,3 +249,34 @@ void utest_assert_string(const char *a, const char *b, rt_bool_t equal, const ch } } } + +void utest_assert_buf(const char *a, const char *b, rt_size_t sz, rt_bool_t equal, const char *file, int line, const char *func, const char *msg) +{ + if (a == RT_NULL || b == RT_NULL) + { + utest_assert(0, file, line, func, msg); + } + + if (equal) + { + if (rt_memcmp(a, b, sz) == 0) + { + utest_assert(1, file, line, func, msg); + } + else + { + utest_assert(0, file, line, func, msg); + } + } + else + { + if (rt_memcmp(a, b, sz) == 0) + { + utest_assert(0, file, line, func, msg); + } + else + { + utest_assert(1, file, line, func, msg); + } + } +} |
