Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
天中雨水
rt-thread
提交
51b17a15
R
rt-thread
项目概览
天中雨水
/
rt-thread
该项目与 Fork 源项目分叉
Fork自
RT-Thread / rt-thread
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
51b17a15
编写于
12月 06, 2018
作者:
M
MurphyZhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[components/utilities/utest] 完善代码,增加注释
Signed-off-by:
N
MurphyZhao
<
d2014zjt@163.com
>
上级
8824b2ca
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
158 addition
and
9 deletion
+158
-9
components/utilities/utest/utest.c
components/utilities/utest/utest.c
+29
-8
components/utilities/utest/utest.h
components/utilities/utest/utest.h
+107
-1
components/utilities/utest/utest_assert.h
components/utilities/utest/utest_assert.h
+22
-0
未找到文件。
components/utilities/utest/utest.c
浏览文件 @
51b17a15
...
...
@@ -125,28 +125,45 @@ static void utest_run(const char *utest_name)
continue
;
}
LOG_I
(
"[----------] [ testcase ] (%s) started"
,
tc_table
[
i
].
name
);
if
(
tc_table
[
i
].
init
!=
RT_NULL
)
{
tc_table
[
i
].
init
();
if
(
tc_table
[
i
].
init
()
!=
RT_EOK
)
{
LOG_I
(
"[ FAILED ] [ result ] testcase (%s)"
,
tc_table
[
i
].
name
);
goto
__tc_continue
;
}
}
LOG_I
(
"[----------] [ testcase ] (%s) started"
,
tc_table
[
i
].
name
);
tc_table
[
i
].
tc
();
if
(
local_utest
.
failed_num
==
0
)
if
(
tc_table
[
i
].
tc
!=
RT_NULL
)
{
LOG_I
(
"[ PASSED ] [ result ] testcase (%s)"
,
tc_table
[
i
].
name
);
tc_table
[
i
].
tc
();
if
(
local_utest
.
failed_num
==
0
)
{
LOG_I
(
"[ PASSED ] [ result ] testcase (%s)"
,
tc_table
[
i
].
name
);
}
else
{
LOG_I
(
"[ FAILED ] [ result ] testcase (%s)"
,
tc_table
[
i
].
name
);
}
}
else
{
LOG_I
(
"[ FAILED ] [ result ] testcase (%s)"
,
tc_table
[
i
].
name
);
}
LOG_I
(
"[----------] [ testcase ] (%s) finished"
,
tc_table
[
i
].
name
);
if
(
tc_table
[
i
].
cleanup
!=
RT_NULL
)
{
tc_table
[
i
].
cleanup
();
if
(
tc_table
[
i
].
cleanup
()
!=
RT_EOK
)
{
LOG_I
(
"[ FAILED ] [ result ] testcase (%s)"
,
tc_table
[
i
].
name
);
goto
__tc_continue
;
}
}
__tc_continue:
LOG_I
(
"[----------] [ testcase ] (%s) finished"
,
tc_table
[
i
].
name
);
i
++
;
}
LOG_I
(
"[==========] [ utest ] finished"
);
...
...
@@ -184,7 +201,11 @@ void utest_unit_run(test_unit_func func, const char *unit_func_name)
local_utest
.
error
=
UTEST_PASSED
;
local_utest
.
passed_num
=
0
;
local_utest
.
failed_num
=
0
;
func
();
if
(
func
!=
RT_NULL
)
{
func
();
}
}
void
utest_assert
(
int
value
,
const
char
*
file
,
int
line
,
const
char
*
func
,
const
char
*
msg
)
...
...
components/utilities/utest/utest.h
浏览文件 @
51b17a15
...
...
@@ -16,6 +16,16 @@
#define UTEST_SW_VERSION "0.0.1"
/**
* utest_error
*
* @brief Test result.
*
* @member UTEST_PASSED Test success.
* @member UTEST_FAILED Test failed.
* @member UTEST_PASSED Test skipped.
*
*/
enum
utest_error
{
UTEST_PASSED
=
0
,
...
...
@@ -24,6 +34,16 @@ enum utest_error
};
typedef
enum
utest_error
utest_err_e
;
/**
* utest
*
* @brief utest data structure.
*
* @member error Error number from enum `utest_error`.
* @member passed_num Total number of tests passed.
* @member failed_num Total number of tests failed.
*
*/
struct
utest
{
utest_err_e
error
;
...
...
@@ -32,6 +52,19 @@ struct utest
};
typedef
struct
utest
*
utest_t
;
/**
* utest_tc_export
*
* @brief utest testcase data structure.
* Will export the data to `UtestTcTab` section in flash.
*
* @member name Testcase name.
* @member run_timeout Testcase maximum test time.
* @member init Necessary initialization before executing the test case function.
* @member tc Total number of tests failed.
* @member cleanup Total number of tests failed.
*
*/
struct
utest_tc_export
{
const
char
*
name
;
uint32_t
run_timeout
;
...
...
@@ -41,18 +74,80 @@ struct utest_tc_export {
};
typedef
struct
utest_tc_export
*
utest_tc_export_t
;
/**
* test_unit_func
*
* @brief Unit test handler function pointer.
*
*/
typedef
void
(
*
test_unit_func
)(
void
);
/**
* TC_LOG_x
*
* @brief Log output interface used in test cases.
*
* @type TC_LOG_I Output info level log.
* @type TC_LOG_D Output debug level log.
* @type TC_LOG_E Output error level log.
* @type TC_LOG_W Output warning level log.
*
*/
#define TC_LOG_I(...) LOG_I(__VA_ARGS__)
#define TC_LOG_D(...) LOG_D(__VA_ARGS__)
#define TC_LOG_E(...) LOG_E(__VA_ARGS__)
#define TC_LOG_W(...) LOG_W(__VA_ARGS__)
/**
* utest_unit_run
*
* @brief Unit test function executor.
* No need for the user to call this function directly
*
* @param func Unit test function.
* @param unit_func_name Unit test function name.
*
* @return void
*
*/
void
utest_unit_run
(
test_unit_func
func
,
const
char
*
unit_func_name
);
/**
* utest_handle_get
*
* @brief Get the utest data structure handle.
* No need for the user to call this function directly
*
* @param void
*
* @return utest_t type. (struct utest *)
*
*/
utest_t
utest_handle_get
(
void
);
/**
* UTEST_NAME_MAX_LEN
*
* @brief Testcase name maximum length.
*
*/
#define UTEST_NAME_MAX_LEN (128u)
/**
* UTEST_TC_EXPORT
*
* @brief Export testcase function to `UtestTcTab` section in flash.
* Used in application layer.
*
* @param testcase The testcase function.
* @param name The testcase name.
* @param init The initialization function of the test case.
* @param cleanup The cleanup function of the test case.
* @param timeout Testcase maximum test time.
*
* @return None
*
*/
#define UTEST_TC_EXPORT(testcase, name, init, cleanup, timeout) \
RT_USED static const struct utest_tc_export _utest_testcase \
SECTION("UtestTcTab") = \
...
...
@@ -64,8 +159,19 @@ utest_t utest_handle_get(void);
cleanup \
}
/**
* UTEST_UNIT_RUN
*
* @brief Unit test function executor.
* Used in `testcase` function in application.
*
* @param test_unit_func Unit test function
*
* @return None
*
*/
#define UTEST_UNIT_RUN(test_unit_func) \
utest_unit_run(test_unit_func, #test_unit_func); \
if(utest_handle_get()->failed_num != 0) return;
#endif
#endif
/* __UTEST_H__ */
components/utilities/utest/utest_assert.h
浏览文件 @
51b17a15
...
...
@@ -14,11 +14,33 @@
#include "utest.h"
#include <rtthread.h>
/* No need for the user to use this function directly */
void
utest_assert
(
int
value
,
const
char
*
file
,
int
line
,
const
char
*
func
,
const
char
*
msg
);
/* No need for the user to use this function directly */
void
utest_assert_string
(
const
char
*
a
,
const
char
*
b
,
rt_bool_t
equal
,
const
char
*
file
,
int
line
,
const
char
*
func
,
const
char
*
msg
);
/* No need for the user to use this macro directly */
#define __utest_assert(value, msg) utest_assert(value, __FILE__, __LINE__, __func__, msg)
/**
* uassert_x macros
*
* @brief Get the utest data structure handle.
* No need for the user to call this function directly.
*
* @macro uassert_true if @value is true, not assert, means passing.
* @macro uassert_false if @value is false, not assert, means passing.
* @macro uassert_null if @value is null, not assert, means passing.
* @macro uassert_not_null if @value is not null, not assert, means passing.
* @macro uassert_int_equal if @a equal to @b, not assert, means passing. Integer type test.
* @macro uassert_int_not_equal if @a not equal to @b, not assert, means passing. Integer type test.
* @macro uassert_str_equal if @a equal to @b, not assert, means passing. String type test.
* @macro uassert_str_not_equal if @a not equal to @b, not assert, means passing. String type test.
* @macro uassert_in_range if @value is in range of min and max, not assert, means passing.
* @macro uassert_not_in_range if @value is not in range of min and max, not assert, means passing.
*
*/
#define uassert_true(value) __utest_assert(value, "(" #value ") is false")
#define uassert_false(value) __utest_assert(!(value), "(" #value ") is true")
#define uassert_null(value) __utest_assert((value) == NULL, "(" #value ") is not null")
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录