From f9e5d87c98c135426f2768bc6c0e44da25e6a92a Mon Sep 17 00:00:00 2001 From: MurphyZhao Date: Tue, 22 Jan 2019 15:42:55 +0800 Subject: [PATCH] =?UTF-8?q?[components][utest]=20=E5=B0=86=20utest=5Fasser?= =?UTF-8?q?t.h=20=E5=8A=A0=E5=85=A5=20utest.h=EF=BC=8C=E4=BB=A5=E5=90=8E?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E4=BB=85=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E5=8C=85=E5=90=AB=20utest.h=20[components][utest]=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=20buf=20=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=AD=97=E8=8A=82?= =?UTF-8?q?=E6=AF=94=E8=BE=83=20assert=20=E5=AE=8F=20[components][utest]?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E7=9A=84=E8=BE=93=E5=87=BA=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E4=B8=BA=20ERR=20=E7=BA=A7=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MurphyZhao --- components/utilities/utest/utest.c | 39 ++++++++++++++++++++--- components/utilities/utest/utest.h | 5 +-- components/utilities/utest/utest_assert.h | 6 ++++ 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index 0f5a206d3c..0ee0b94bf5 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -112,7 +112,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 +126,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; } } @@ -236,3 +236,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); + } + } +} diff --git a/components/utilities/utest/utest.h b/components/utilities/utest/utest.h index 5a7e8af721..386d177a77 100644 --- a/components/utilities/utest/utest.h +++ b/components/utilities/utest/utest.h @@ -13,6 +13,7 @@ #include #include "utest_log.h" +#include "utest_assert.h" /** * utest_error @@ -57,7 +58,7 @@ typedef struct utest *utest_t; * Will export the data to `UtestTcTab` section in flash. * * @member name Testcase name. - * @member run_timeout Testcase maximum test time. + * @member run_timeout Testcase maximum test time (Time unit: seconds). * @member init Necessary initialization before executing the test case function. * @member tc Total number of tests failed. * @member cleanup Total number of tests failed. @@ -125,7 +126,7 @@ utest_t utest_handle_get(void); * @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. + * @param timeout Testcase maximum test time (Time unit: seconds). * * @return None * diff --git a/components/utilities/utest/utest_assert.h b/components/utilities/utest/utest_assert.h index 997e8ae7f3..9c620c689d 100644 --- a/components/utilities/utest/utest_assert.h +++ b/components/utilities/utest/utest_assert.h @@ -19,6 +19,7 @@ void utest_assert(int value, const char *file, int line, const char *func, const /* 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); +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); /* No need for the user to use this macro directly */ #define __utest_assert(value, msg) utest_assert(value, __FILE__, __LINE__, __func__, msg) @@ -37,6 +38,8 @@ void utest_assert_string(const char *a, const char *b, rt_bool_t equal, const ch * @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_buf_equal if @a equal to @b, not assert, means passing. buf type test. + * @macro uassert_buf_not_equal if @a not equal to @b, not assert, means passing. buf 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. * @@ -52,6 +55,9 @@ void utest_assert_string(const char *a, const char *b, rt_bool_t equal, const ch #define uassert_str_equal(a, b) utest_assert_string((const char*)(a), (const char*)(b), RT_TRUE, __FILE__, __LINE__, __func__, "string not equal") #define uassert_str_not_equal(a, b) utest_assert_string((const char*)(a), (const char*)(b), RT_FALSE, __FILE__, __LINE__, __func__, "string equal") +#define uassert_buf_equal(a, b, sz) utest_assert_buf((const char*)(a), (const char*)(b), (sz), RT_TRUE, __FILE__, __LINE__, __func__, "buf not equal") +#define uassert_buf_not_equal(a, b, sz) utest_assert_buf((const char*)(a), (const char*)(b), (sz), RT_FALSE, __FILE__, __LINE__, __func__, "buf equal") + #define uassert_in_range(value, min, max) __utest_assert(((value >= min) && (value <= max)), "(" #value ") not in range("#min","#max")") #define uassert_not_in_range(value, min, max) __utest_assert(!((value >= min) && (value <= max)), "(" #value ") in range("#min","#max")")