From 655c4ad36b2207c7ddeba6795f235fa7b939cc7d Mon Sep 17 00:00:00 2001 From: MurphyZhao Date: Fri, 25 Jan 2019 17:24:01 +0800 Subject: [PATCH] =?UTF-8?q?[component][utest]=20=E5=A2=9E=E5=8A=A0=20utest?= =?UTF-8?q?=20=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=E7=BA=A7=E5=88=AB?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=8F=90=E4=BE=9B=20ASSERT=20?= =?UTF-8?q?=E5=92=8C=20ALL=20=E4=B8=A4=E4=B8=AA=E7=BA=A7=E5=88=AB=EF=BC=8C?= =?UTF-8?q?=E4=BE=BF=E4=BA=8E=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=20log=20=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MurphyZhao --- components/utilities/utest/utest.c | 19 ++++++++++++++++--- components/utilities/utest/utest_log.h | 7 +++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 0ee0b94bf5..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 -#include +#include +#include "utest.h" +#include #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.*/ @@ -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 ++; } diff --git a/components/utilities/utest/utest_log.h b/components/utilities/utest/utest_log.h index c954046b76..9f38d3f9c8 100644 --- a/components/utilities/utest/utest_log.h +++ b/components/utilities/utest/utest_log.h @@ -11,6 +11,8 @@ #ifndef __UTEST_LOG_H__ #define __UTEST_LOG_H__ +#include + #define UTEST_DEBUG #undef DBG_SECTION_NAME @@ -28,4 +30,9 @@ #define DBG_COLOR #include +#define UTEST_LOG_ALL (1u) +#define UTEST_LOG_ASSERT (2u) + +void utest_log_lv_set(rt_uint8_t lv); + #endif /* __UTEST_LOG_H__ */