[component][utest] 增加 utest 日志输出级别配置,提供 ASSERT 和 ALL 两个级别,便于测试用例控制 log 输出
Signed-off-by: MurphyZhao <d2014zjt@163.com>
This commit is contained in:
parent
7aede1befb
commit
655c4ad36b
|
@ -8,9 +8,10 @@
|
||||||
* 2018-11-19 MurphyZhao the first version
|
* 2018-11-19 MurphyZhao the first version
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "utest.h"
|
|
||||||
#include <rtthread.h>
|
#include <rtthread.h>
|
||||||
#include <finsh.h>
|
#include <string.h>
|
||||||
|
#include "utest.h"
|
||||||
|
#include <utest_log.h>
|
||||||
|
|
||||||
#undef DBG_SECTION_NAME
|
#undef DBG_SECTION_NAME
|
||||||
#undef DBG_LEVEL
|
#undef DBG_LEVEL
|
||||||
|
@ -31,6 +32,7 @@
|
||||||
#error "RT_CONSOLEBUF_SIZE is less than 256!"
|
#error "RT_CONSOLEBUF_SIZE is less than 256!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static rt_uint8_t utest_log_lv = UTEST_LOG_ALL;
|
||||||
static utest_tc_export_t tc_table = RT_NULL;
|
static utest_tc_export_t tc_table = RT_NULL;
|
||||||
static rt_size_t tc_num;
|
static rt_size_t tc_num;
|
||||||
static struct utest local_utest = {UTEST_PASSED, 0, 0};
|
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"
|
#pragma section="UtestTcTab"
|
||||||
#endif
|
#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)
|
int utest_init(void)
|
||||||
{
|
{
|
||||||
/* initialize the utest commands table.*/
|
/* initialize the utest commands table.*/
|
||||||
|
@ -199,8 +209,11 @@ void utest_assert(int value, const char *file, int line, const char *func, const
|
||||||
LOG_E("[ ASSERT ] [ unit ] at (%s); func: (%s:%d); msg: (%s)", file_basename(file), func, line, msg);
|
LOG_E("[ ASSERT ] [ unit ] at (%s); func: (%s:%d); msg: (%s)", file_basename(file), func, line, msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if (utest_log_lv == UTEST_LOG_ALL)
|
||||||
{
|
{
|
||||||
LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line);
|
LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line);
|
||||||
|
}
|
||||||
local_utest.error = UTEST_PASSED;
|
local_utest.error = UTEST_PASSED;
|
||||||
local_utest.passed_num ++;
|
local_utest.passed_num ++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#ifndef __UTEST_LOG_H__
|
#ifndef __UTEST_LOG_H__
|
||||||
#define __UTEST_LOG_H__
|
#define __UTEST_LOG_H__
|
||||||
|
|
||||||
|
#include <rtthread.h>
|
||||||
|
|
||||||
#define UTEST_DEBUG
|
#define UTEST_DEBUG
|
||||||
|
|
||||||
#undef DBG_SECTION_NAME
|
#undef DBG_SECTION_NAME
|
||||||
|
@ -28,4 +30,9 @@
|
||||||
#define DBG_COLOR
|
#define DBG_COLOR
|
||||||
#include <rtdbg.h>
|
#include <rtdbg.h>
|
||||||
|
|
||||||
|
#define UTEST_LOG_ALL (1u)
|
||||||
|
#define UTEST_LOG_ASSERT (2u)
|
||||||
|
|
||||||
|
void utest_log_lv_set(rt_uint8_t lv);
|
||||||
|
|
||||||
#endif /* __UTEST_LOG_H__ */
|
#endif /* __UTEST_LOG_H__ */
|
||||||
|
|
Loading…
Reference in New Issue