Skip to content

Commit 500d43b

Browse files
authored
Merge pull request #2269 from zhaojuntao/fix-utest-0125
[component][utest] 增加 utest 日志输出级别配置
2 parents b3c4f3b + 655c4ad commit 500d43b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

components/utilities/utest/utest.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
* 2018-11-19 MurphyZhao the first version
99
*/
1010

11-
#include "utest.h"
1211
#include <rtthread.h>
13-
#include <finsh.h>
12+
#include <string.h>
13+
#include "utest.h"
14+
#include <utest_log.h>
1415

1516
#undef DBG_SECTION_NAME
1617
#undef DBG_LEVEL
@@ -31,6 +32,7 @@
3132
#error "RT_CONSOLEBUF_SIZE is less than 256!"
3233
#endif
3334

35+
static rt_uint8_t utest_log_lv = UTEST_LOG_ALL;
3436
static utest_tc_export_t tc_table = RT_NULL;
3537
static rt_size_t tc_num;
3638
static struct utest local_utest = {UTEST_PASSED, 0, 0};
@@ -39,6 +41,14 @@ static struct utest local_utest = {UTEST_PASSED, 0, 0};
3941
#pragma section="UtestTcTab"
4042
#endif
4143

44+
void utest_log_lv_set(rt_uint8_t lv)
45+
{
46+
if (lv == UTEST_LOG_ALL || lv == UTEST_LOG_ASSERT)
47+
{
48+
utest_log_lv = lv;
49+
}
50+
}
51+
4252
int utest_init(void)
4353
{
4454
/* initialize the utest commands table.*/
@@ -200,7 +210,10 @@ void utest_assert(int value, const char *file, int line, const char *func, const
200210
}
201211
else
202212
{
203-
LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line);
213+
if (utest_log_lv == UTEST_LOG_ALL)
214+
{
215+
LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line);
216+
}
204217
local_utest.error = UTEST_PASSED;
205218
local_utest.passed_num ++;
206219
}

components/utilities/utest/utest_log.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#ifndef __UTEST_LOG_H__
1212
#define __UTEST_LOG_H__
1313

14+
#include <rtthread.h>
15+
1416
#define UTEST_DEBUG
1517

1618
#undef DBG_SECTION_NAME
@@ -28,4 +30,9 @@
2830
#define DBG_COLOR
2931
#include <rtdbg.h>
3032

33+
#define UTEST_LOG_ALL (1u)
34+
#define UTEST_LOG_ASSERT (2u)
35+
36+
void utest_log_lv_set(rt_uint8_t lv);
37+
3138
#endif /* __UTEST_LOG_H__ */

0 commit comments

Comments
 (0)