2018-11-30 16:12:35 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2018-11-30 16:12:35 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018-11-19 MurphyZhao the first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2019-01-25 17:24:01 +08:00
|
|
|
#include <string.h>
|
2019-02-14 15:23:07 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2019-01-25 17:24:01 +08:00
|
|
|
#include "utest.h"
|
|
|
|
#include <utest_log.h>
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2019-04-12 10:18:57 +08:00
|
|
|
#undef DBG_TAG
|
|
|
|
#undef DBG_LVL
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2019-04-12 10:18:57 +08:00
|
|
|
#define DBG_TAG "utest"
|
2018-11-30 16:12:35 +08:00
|
|
|
#ifdef UTEST_DEBUG
|
2019-04-12 10:18:57 +08:00
|
|
|
#define DBG_LVL DBG_LOG
|
2018-11-30 16:12:35 +08:00
|
|
|
#else
|
2019-04-12 10:18:57 +08:00
|
|
|
#define DBG_LVL DBG_INFO
|
2018-11-30 16:12:35 +08:00
|
|
|
#endif
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
|
|
|
#if RT_CONSOLEBUF_SIZE < 256
|
|
|
|
#error "RT_CONSOLEBUF_SIZE is less than 256!"
|
|
|
|
#endif
|
|
|
|
|
2019-02-13 09:37:26 +08:00
|
|
|
#ifdef UTEST_THR_STACK_SIZE
|
|
|
|
#define UTEST_THREAD_STACK_SIZE UTEST_THR_STACK_SIZE
|
|
|
|
#else
|
|
|
|
#define UTEST_THREAD_STACK_SIZE (4096)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef UTEST_THR_PRIORITY
|
|
|
|
#define UTEST_THREAD_PRIORITY UTEST_THR_PRIORITY
|
|
|
|
#else
|
|
|
|
#define UTEST_THREAD_PRIORITY FINSH_THREAD_PRIORITY
|
|
|
|
#endif
|
|
|
|
|
2019-01-25 17:24:01 +08:00
|
|
|
static rt_uint8_t utest_log_lv = UTEST_LOG_ALL;
|
2018-11-30 16:12:35 +08:00
|
|
|
static utest_tc_export_t tc_table = RT_NULL;
|
|
|
|
static rt_size_t tc_num;
|
2019-02-14 15:23:07 +08:00
|
|
|
static rt_uint32_t tc_loop;
|
2021-08-17 21:26:11 +08:00
|
|
|
static rt_uint8_t *tc_fail_list;
|
2018-11-30 16:12:35 +08:00
|
|
|
static struct utest local_utest = {UTEST_PASSED, 0, 0};
|
|
|
|
|
|
|
|
#if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */
|
|
|
|
#pragma section="UtestTcTab"
|
|
|
|
#endif
|
|
|
|
|
2021-08-17 21:26:11 +08:00
|
|
|
#define TC_FAIL_LIST_SIZE (RT_ALIGN(tc_num, 8) / 8)
|
2021-08-24 17:05:56 +08:00
|
|
|
#define TC_FAIL_LIST_MARK_FAILED(index) (tc_fail_list[index / 8] |= (1UL << (index % 8)))
|
|
|
|
#define TC_FAIL_LIST_IS_FAILED(index) (tc_fail_list[index / 8] & (1UL << (index % 8)))
|
2021-08-17 21:26:11 +08:00
|
|
|
|
2019-01-25 17:24:01 +08:00
|
|
|
void utest_log_lv_set(rt_uint8_t lv)
|
|
|
|
{
|
|
|
|
if (lv == UTEST_LOG_ALL || lv == UTEST_LOG_ASSERT)
|
|
|
|
{
|
|
|
|
utest_log_lv = lv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 16:12:35 +08:00
|
|
|
int utest_init(void)
|
|
|
|
{
|
|
|
|
/* initialize the utest commands table.*/
|
2021-12-30 03:14:07 +08:00
|
|
|
#if defined(__ARMCC_VERSION) /* ARM C Compiler */
|
2018-11-30 16:12:35 +08:00
|
|
|
extern const int UtestTcTab$$Base;
|
|
|
|
extern const int UtestTcTab$$Limit;
|
|
|
|
tc_table = (utest_tc_export_t)&UtestTcTab$$Base;
|
|
|
|
tc_num = (utest_tc_export_t)&UtestTcTab$$Limit - tc_table;
|
2019-09-14 22:44:44 +08:00
|
|
|
#elif defined (__ICCARM__) || defined(__ICCRX__) /* for IAR Compiler */
|
2018-11-30 16:12:35 +08:00
|
|
|
tc_table = (utest_tc_export_t)__section_begin("UtestTcTab");
|
|
|
|
tc_num = (utest_tc_export_t)__section_end("UtestTcTab") - tc_table;
|
2019-09-14 22:44:44 +08:00
|
|
|
#elif defined (__GNUC__) /* for GCC Compiler */
|
2018-12-05 14:53:13 +08:00
|
|
|
extern const int __rt_utest_tc_tab_start;
|
|
|
|
extern const int __rt_utest_tc_tab_end;
|
|
|
|
tc_table = (utest_tc_export_t)&__rt_utest_tc_tab_start;
|
|
|
|
tc_num = (utest_tc_export_t) &__rt_utest_tc_tab_end - tc_table;
|
2019-09-14 22:44:44 +08:00
|
|
|
#endif
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2018-12-06 17:11:27 +08:00
|
|
|
LOG_I("utest is initialize success.");
|
|
|
|
LOG_I("total utest testcase num: (%d)", tc_num);
|
2021-08-19 11:20:10 +08:00
|
|
|
if (tc_num > 0)
|
|
|
|
{
|
|
|
|
tc_fail_list = rt_malloc(TC_FAIL_LIST_SIZE);
|
|
|
|
if(!tc_fail_list)
|
|
|
|
{
|
|
|
|
LOG_E("no memory, tc_fail_list init failed!");
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 16:12:35 +08:00
|
|
|
return tc_num;
|
|
|
|
}
|
|
|
|
INIT_COMPONENT_EXPORT(utest_init);
|
|
|
|
|
|
|
|
static void utest_tc_list(void)
|
|
|
|
{
|
|
|
|
rt_size_t i = 0;
|
|
|
|
|
2018-12-06 17:11:27 +08:00
|
|
|
LOG_I("Commands list : ");
|
2018-11-30 16:12:35 +08:00
|
|
|
|
|
|
|
for (i = 0; i < tc_num; i++)
|
|
|
|
{
|
2018-12-06 17:11:27 +08:00
|
|
|
LOG_I("[testcase name]:%s; [run timeout]:%d", tc_table[i].name, tc_table[i].run_timeout);
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 14:46:38 +08:00
|
|
|
MSH_CMD_EXPORT_ALIAS(utest_tc_list, utest_list, output all utest testcase);
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2018-12-08 14:46:38 +08:00
|
|
|
static const char *file_basename(const char *file)
|
2018-11-30 16:12:35 +08:00
|
|
|
{
|
2018-12-08 14:46:38 +08:00
|
|
|
char *end_ptr = RT_NULL;
|
2018-11-30 16:12:35 +08:00
|
|
|
char *rst = RT_NULL;
|
2018-12-08 14:46:38 +08:00
|
|
|
|
|
|
|
if (!((end_ptr = strrchr(file, '\\')) != RT_NULL || \
|
|
|
|
(end_ptr = strrchr(file, '/')) != RT_NULL) || \
|
|
|
|
(rt_strlen(file) < 2))
|
2018-11-30 16:12:35 +08:00
|
|
|
{
|
2018-12-08 14:46:38 +08:00
|
|
|
rst = (char *)file;
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-08 14:46:38 +08:00
|
|
|
rst = (char *)(end_ptr + 1);
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
2018-12-08 14:46:38 +08:00
|
|
|
return (const char *)rst;
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
|
|
|
|
2019-02-15 11:47:21 +08:00
|
|
|
static int utest_help(void)
|
|
|
|
{
|
|
|
|
rt_kprintf("\n");
|
|
|
|
rt_kprintf("Command: utest_run\n");
|
|
|
|
rt_kprintf(" info: Execute test cases.\n");
|
|
|
|
rt_kprintf(" format: utest_run [-thread or -help] [testcase name] [loop num]\n");
|
|
|
|
rt_kprintf(" usage:\n");
|
|
|
|
rt_kprintf(" 1. utest_run\n");
|
|
|
|
rt_kprintf(" Do not specify a test case name. Run all test cases.\n");
|
|
|
|
rt_kprintf(" 2. utest_run -thread\n");
|
|
|
|
rt_kprintf(" Do not specify a test case name. Run all test cases in threaded mode.\n");
|
|
|
|
rt_kprintf(" 3. utest_run testcaseA\n");
|
|
|
|
rt_kprintf(" Run 'testcaseA'.\n");
|
|
|
|
rt_kprintf(" 4. utest_run testcaseA 10\n");
|
|
|
|
rt_kprintf(" Run 'testcaseA' ten times.\n");
|
|
|
|
rt_kprintf(" 5. utest_run -thread testcaseA\n");
|
|
|
|
rt_kprintf(" Run 'testcaseA' in threaded mode.\n");
|
|
|
|
rt_kprintf(" 6. utest_run -thread testcaseA 10\n");
|
|
|
|
rt_kprintf(" Run 'testcaseA' ten times in threaded mode.\n");
|
|
|
|
rt_kprintf(" 7. utest_run test*\n");
|
|
|
|
rt_kprintf(" support '*' wildcard. Run all test cases starting with 'test'.\n");
|
|
|
|
rt_kprintf(" 8. utest_run -help\n");
|
|
|
|
rt_kprintf(" Show utest help information\n");
|
|
|
|
rt_kprintf("\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-30 16:12:35 +08:00
|
|
|
static void utest_run(const char *utest_name)
|
|
|
|
{
|
2019-02-14 15:23:07 +08:00
|
|
|
rt_size_t i;
|
|
|
|
rt_uint32_t index;
|
2019-02-15 11:47:21 +08:00
|
|
|
rt_bool_t is_find;
|
2021-08-17 21:26:11 +08:00
|
|
|
rt_uint32_t tc_fail_num = 0;
|
|
|
|
rt_uint32_t tc_run_num = 0;
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2019-02-14 12:00:58 +08:00
|
|
|
rt_thread_mdelay(1000);
|
|
|
|
|
2019-02-14 15:23:07 +08:00
|
|
|
for (index = 0; index < tc_loop; index ++)
|
2018-11-30 16:12:35 +08:00
|
|
|
{
|
2019-02-14 15:23:07 +08:00
|
|
|
i = 0;
|
2019-02-15 11:47:21 +08:00
|
|
|
is_find = RT_FALSE;
|
2021-08-17 21:26:11 +08:00
|
|
|
|
|
|
|
tc_fail_num = 0;
|
|
|
|
tc_run_num = 0;
|
|
|
|
if (tc_fail_list)
|
|
|
|
{
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memset(tc_fail_list, 0, TC_FAIL_LIST_SIZE);
|
2021-08-17 21:26:11 +08:00
|
|
|
}
|
|
|
|
|
2019-03-19 14:26:04 +08:00
|
|
|
LOG_I("[==========] [ utest ] loop %d/%d", index + 1, tc_loop);
|
2019-02-14 15:23:07 +08:00
|
|
|
LOG_I("[==========] [ utest ] started");
|
|
|
|
while(i < tc_num)
|
2018-11-30 16:12:35 +08:00
|
|
|
{
|
2019-02-14 15:23:07 +08:00
|
|
|
if (utest_name)
|
|
|
|
{
|
|
|
|
int len = strlen(utest_name);
|
|
|
|
if (utest_name[len - 1] == '*')
|
|
|
|
{
|
|
|
|
len -= 1;
|
|
|
|
}
|
|
|
|
if (rt_memcmp(tc_table[i].name, utest_name, len) != 0)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 11:47:21 +08:00
|
|
|
is_find = RT_TRUE;
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2019-02-14 15:23:07 +08:00
|
|
|
LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name);
|
|
|
|
if (tc_table[i].init != RT_NULL)
|
2018-12-06 18:58:23 +08:00
|
|
|
{
|
2019-02-14 15:23:07 +08:00
|
|
|
if (tc_table[i].init() != RT_EOK)
|
|
|
|
{
|
|
|
|
LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
|
|
|
|
goto __tc_continue;
|
|
|
|
}
|
2018-12-06 18:58:23 +08:00
|
|
|
}
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2019-02-14 15:23:07 +08:00
|
|
|
if (tc_table[i].tc != RT_NULL)
|
2018-12-06 18:58:23 +08:00
|
|
|
{
|
2019-02-14 15:23:07 +08:00
|
|
|
tc_table[i].tc();
|
|
|
|
if (local_utest.failed_num == 0)
|
|
|
|
{
|
|
|
|
LOG_I("[ PASSED ] [ result ] testcase (%s)", tc_table[i].name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-17 21:26:11 +08:00
|
|
|
TC_FAIL_LIST_MARK_FAILED(i);
|
|
|
|
tc_fail_num ++;
|
2019-02-14 15:23:07 +08:00
|
|
|
LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
|
|
|
|
}
|
2018-12-06 18:58:23 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-22 15:42:55 +08:00
|
|
|
LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
|
2018-12-06 18:58:23 +08:00
|
|
|
}
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2019-02-14 15:23:07 +08:00
|
|
|
if (tc_table[i].cleanup != RT_NULL)
|
2018-12-06 18:58:23 +08:00
|
|
|
{
|
2019-02-14 15:23:07 +08:00
|
|
|
if (tc_table[i].cleanup() != RT_EOK)
|
|
|
|
{
|
|
|
|
LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
|
|
|
|
goto __tc_continue;
|
|
|
|
}
|
2018-12-06 18:58:23 +08:00
|
|
|
}
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2019-02-14 15:23:07 +08:00
|
|
|
__tc_continue:
|
|
|
|
LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name);
|
2018-12-06 18:58:23 +08:00
|
|
|
|
2021-08-17 21:26:11 +08:00
|
|
|
tc_run_num ++;
|
2019-02-14 15:23:07 +08:00
|
|
|
i++;
|
|
|
|
}
|
2019-02-15 11:47:21 +08:00
|
|
|
|
2019-09-14 22:44:44 +08:00
|
|
|
if (i == tc_num && is_find == RT_FALSE && utest_name != RT_NULL)
|
2019-02-15 11:47:21 +08:00
|
|
|
{
|
|
|
|
LOG_I("[==========] [ utest ] Not find (%s)", utest_name);
|
|
|
|
LOG_I("[==========] [ utest ] finished");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-02-14 15:23:07 +08:00
|
|
|
LOG_I("[==========] [ utest ] finished");
|
2021-08-17 21:26:11 +08:00
|
|
|
LOG_I("[==========] [ utest ] %d tests from %d testcase ran.", tc_run_num, tc_num);
|
|
|
|
LOG_I("[ PASSED ] [ result ] %d tests.", tc_run_num - tc_fail_num);
|
|
|
|
|
|
|
|
if(tc_fail_list && (tc_fail_num > 0))
|
|
|
|
{
|
|
|
|
LOG_E("[ FAILED ] [ result ] %d tests, listed below:", tc_fail_num);
|
|
|
|
for(i = 0; i < tc_num; i ++)
|
|
|
|
{
|
|
|
|
if (TC_FAIL_LIST_IS_FAILED(i))
|
|
|
|
{
|
|
|
|
LOG_E("[ FAILED ] [ result ] %s", tc_table[i].name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void utest_testcase_run(int argc, char** argv)
|
|
|
|
{
|
2019-02-13 09:37:26 +08:00
|
|
|
void *thr_param = RT_NULL;
|
|
|
|
|
|
|
|
static char utest_name[UTEST_NAME_MAX_LEN];
|
|
|
|
rt_memset(utest_name, 0x0, sizeof(utest_name));
|
2018-11-30 16:12:35 +08:00
|
|
|
|
2019-02-14 15:23:07 +08:00
|
|
|
tc_loop = 1;
|
|
|
|
|
2018-11-30 16:12:35 +08:00
|
|
|
if (argc == 1)
|
|
|
|
{
|
|
|
|
utest_run(RT_NULL);
|
2019-02-13 09:37:26 +08:00
|
|
|
return;
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
2019-02-14 15:23:07 +08:00
|
|
|
else if (argc == 2 || argc == 3 || argc == 4)
|
2018-11-30 16:12:35 +08:00
|
|
|
{
|
2019-02-13 09:37:26 +08:00
|
|
|
if (rt_strcmp(argv[1], "-thread") == 0)
|
|
|
|
{
|
|
|
|
rt_thread_t tid = RT_NULL;
|
2019-02-14 15:23:07 +08:00
|
|
|
if (argc == 3 || argc == 4)
|
2019-02-13 09:37:26 +08:00
|
|
|
{
|
|
|
|
rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1);
|
|
|
|
thr_param = (void*)utest_name;
|
2019-02-14 15:23:07 +08:00
|
|
|
|
|
|
|
if (argc == 4) tc_loop = atoi(argv[3]);
|
2019-02-13 09:37:26 +08:00
|
|
|
}
|
|
|
|
tid = rt_thread_create("utest",
|
|
|
|
(void (*)(void *))utest_run, thr_param,
|
|
|
|
UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10);
|
|
|
|
if (tid != NULL)
|
|
|
|
{
|
|
|
|
rt_thread_startup(tid);
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 11:47:21 +08:00
|
|
|
else if (rt_strcmp(argv[1], "-help") == 0)
|
|
|
|
{
|
|
|
|
utest_help();
|
|
|
|
}
|
2019-02-13 09:37:26 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1);
|
2019-02-14 15:23:07 +08:00
|
|
|
if (argc == 3) tc_loop = atoi(argv[2]);
|
2019-02-13 09:37:26 +08:00
|
|
|
utest_run(utest_name);
|
|
|
|
}
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_E("[ error ] at (%s:%d), in param error.", __func__, __LINE__);
|
2019-02-15 11:47:21 +08:00
|
|
|
utest_help();
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-15 11:47:21 +08:00
|
|
|
MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num]);
|
2018-11-30 16:12:35 +08:00
|
|
|
|
|
|
|
utest_t utest_handle_get(void)
|
|
|
|
{
|
|
|
|
return (utest_t)&local_utest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void utest_unit_run(test_unit_func func, const char *unit_func_name)
|
|
|
|
{
|
|
|
|
// LOG_I("[==========] utest unit name: (%s)", unit_func_name);
|
|
|
|
local_utest.error = UTEST_PASSED;
|
|
|
|
local_utest.passed_num = 0;
|
|
|
|
local_utest.failed_num = 0;
|
2018-12-06 18:58:23 +08:00
|
|
|
|
|
|
|
if (func != RT_NULL)
|
|
|
|
{
|
|
|
|
func();
|
|
|
|
}
|
2018-11-30 16:12:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void utest_assert(int value, const char *file, int line, const char *func, const char *msg)
|
|
|
|
{
|
|
|
|
if (!(value))
|
|
|
|
{
|
|
|
|
local_utest.error = UTEST_FAILED;
|
|
|
|
local_utest.failed_num ++;
|
|
|
|
LOG_E("[ ASSERT ] [ unit ] at (%s); func: (%s:%d); msg: (%s)", file_basename(file), func, line, msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-25 17:24:01 +08:00
|
|
|
if (utest_log_lv == UTEST_LOG_ALL)
|
|
|
|
{
|
|
|
|
LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line);
|
|
|
|
}
|
2018-11-30 16:12:35 +08:00
|
|
|
local_utest.error = UTEST_PASSED;
|
|
|
|
local_utest.passed_num ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (a == RT_NULL || b == RT_NULL)
|
|
|
|
{
|
|
|
|
utest_assert(0, file, line, func, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (equal)
|
|
|
|
{
|
|
|
|
if (rt_strcmp(a, b) == 0)
|
|
|
|
{
|
|
|
|
utest_assert(1, file, line, func, msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utest_assert(0, file, line, func, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (rt_strcmp(a, b) == 0)
|
|
|
|
{
|
|
|
|
utest_assert(0, file, line, func, msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
utest_assert(1, file, line, func, msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-22 15:42:55 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|