rtt更新
This commit is contained in:
@@ -137,7 +137,7 @@ menuconfig RT_USING_ULOG
|
||||
config ULOG_OUTPUT_FLOAT
|
||||
bool "Enable float number support. It will using more thread stack."
|
||||
default n
|
||||
select PKG_USING_RT_VSNPRINTF_FULL
|
||||
select RT_KLIBC_USING_VSNPRINTF_STANDARD
|
||||
help
|
||||
The default formater is using rt_vsnprint and it not supported float number.
|
||||
When enable this option then it will enable libc. The formater will change to vsnprint on libc.
|
||||
@@ -210,6 +210,19 @@ config RT_USING_UTEST
|
||||
config UTEST_THR_PRIORITY
|
||||
int "The utest thread priority"
|
||||
default 20
|
||||
|
||||
config RT_UTEST_USING_AUTO_RUN
|
||||
bool "Enable auto run test cases"
|
||||
default n
|
||||
help
|
||||
If enable this option, the test cases will be run automatically when board boot up.
|
||||
|
||||
config RT_UTEST_USING_ALL_CASES
|
||||
bool "Enable all selected modules' test cases"
|
||||
default n
|
||||
help
|
||||
If enable this option, all selected modules' test cases will be run.
|
||||
Otherwise, only the test cases that are explicitly enabled will be run.
|
||||
endif
|
||||
|
||||
config RT_USING_VAR_EXPORT
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2022, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@@ -108,6 +108,7 @@ struct rt_ulog
|
||||
#endif /* ULOG_USING_FILTER */
|
||||
};
|
||||
|
||||
#ifdef ULOG_OUTPUT_LEVEL
|
||||
/* level output info */
|
||||
static const char * const level_output_info[] =
|
||||
{
|
||||
@@ -120,6 +121,7 @@ static const char * const level_output_info[] =
|
||||
"I/",
|
||||
"D/",
|
||||
};
|
||||
#endif /* ULOG_OUTPUT_LEVEL */
|
||||
|
||||
#ifdef ULOG_USING_COLOR
|
||||
/* color output info */
|
||||
@@ -1260,6 +1262,24 @@ MSH_CMD_EXPORT(ulog_filter, Show ulog filter settings);
|
||||
#endif /* RT_USING_FINSH */
|
||||
#endif /* ULOG_USING_FILTER */
|
||||
|
||||
/**
|
||||
* @brief register the backend device into the ulog.
|
||||
*
|
||||
* @param backend Backend device handle, a pointer to a "struct ulog_backend" obj.
|
||||
* @param name Backend device name.
|
||||
* @param support_color Whether it supports color logs.
|
||||
* @return rt_err_t - return 0 on success.
|
||||
*
|
||||
* @note - This function is used to register the backend device into the ulog,
|
||||
* ensuring that the function members in the backend device structure are set before registration.
|
||||
* - about struct ulog_backend:
|
||||
* 1. The name and support_color properties can be passed in through the ulog_backend_register() function.
|
||||
* 2. output is the back-end specific output function, and all backends must implement the interface.
|
||||
* 3. init/deinit is optional, init is called at register, and deinit is called at unregister or ulog_deinit.
|
||||
* 4. flush is also optional, and some internal output cached backends need to implement this interface.
|
||||
* For example, some file systems with RAM cache. The flush of the backend is usually called by
|
||||
* ulog_flush in the case of an exception such as assertion or hardfault.
|
||||
*/
|
||||
rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool_t support_color)
|
||||
{
|
||||
rt_base_t level;
|
||||
@@ -1285,6 +1305,13 @@ rt_err_t ulog_backend_register(ulog_backend_t backend, const char *name, rt_bool
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief unregister a backend device that has already been registered.
|
||||
*
|
||||
* @param backend Backend device handle
|
||||
* @return rt_err_t - return 0 on success.
|
||||
* @note deinit function will be called at unregister.
|
||||
*/
|
||||
rt_err_t ulog_backend_unregister(ulog_backend_t backend)
|
||||
{
|
||||
rt_base_t level;
|
||||
@@ -1458,6 +1485,14 @@ void ulog_flush(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ulog initialization
|
||||
*
|
||||
* @return int return 0 on success, return -5 when failed of insufficient memory.
|
||||
*
|
||||
* @note This function must be called to complete ulog initialization before using ulog.
|
||||
* This function will also be called automatically if component auto-initialization is turned on.
|
||||
*/
|
||||
int ulog_init(void)
|
||||
{
|
||||
if (ulog.init_ok)
|
||||
@@ -1516,6 +1551,11 @@ int ulog_async_init(void)
|
||||
INIT_PREV_EXPORT(ulog_async_init);
|
||||
#endif /* ULOG_USING_ASYNC_OUTPUT */
|
||||
|
||||
/**
|
||||
* @brief ulog deinitialization
|
||||
*
|
||||
* @note This deinit release resource can be executed when ulog is no longer used.
|
||||
*/
|
||||
void ulog_deinit(void)
|
||||
{
|
||||
rt_slist_t *node;
|
||||
|
@@ -43,16 +43,10 @@ extern "C" {
|
||||
#undef DBG_WARNING
|
||||
#undef DBG_INFO
|
||||
#undef DBG_LOG
|
||||
#undef dbg_log
|
||||
#define DBG_ERROR LOG_LVL_ERROR
|
||||
#define DBG_WARNING LOG_LVL_WARNING
|
||||
#define DBG_INFO LOG_LVL_INFO
|
||||
#define DBG_LOG LOG_LVL_DBG
|
||||
#define dbg_log(level, ...) \
|
||||
if ((level) <= LOG_LVL) \
|
||||
{ \
|
||||
ulog_output(level, LOG_TAG, RT_FALSE, __VA_ARGS__);\
|
||||
}
|
||||
|
||||
#if !defined(LOG_TAG)
|
||||
/* compatible for rtdbg */
|
||||
|
83
rt-thread/components/utilities/utest/TC_uassert.c
Normal file
83
rt-thread/components/utilities/utest/TC_uassert.c
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <rtthread.h>
|
||||
#include "utest.h"
|
||||
|
||||
static void TC_uassert_true_false(void)
|
||||
{
|
||||
uassert_true(1);
|
||||
uassert_false(0);
|
||||
}
|
||||
|
||||
static void TC_uassert_null_not_null(void)
|
||||
{
|
||||
int *ptr = RT_NULL;
|
||||
int value = 10;
|
||||
int *ptr2 = &value;
|
||||
|
||||
uassert_null(ptr);
|
||||
uassert_not_null(ptr2);
|
||||
}
|
||||
|
||||
static void TC_uassert_int_op(void)
|
||||
{
|
||||
int a = 5;
|
||||
int b = 10;
|
||||
|
||||
uassert_int_equal(a, a);
|
||||
uassert_int_not_equal(a, b);
|
||||
uassert_value_less(a, b);
|
||||
uassert_value_less_equal(a, b);
|
||||
uassert_value_less_equal(a, a);
|
||||
uassert_value_greater(b, a);
|
||||
uassert_value_greater_equal(b, a);
|
||||
uassert_value_greater_equal(b, b);
|
||||
}
|
||||
|
||||
static void TC_uassert_float_op(void)
|
||||
{
|
||||
float a = 5.0;
|
||||
float b = 5.0;
|
||||
|
||||
uassert_float_equal(a, b);
|
||||
uassert_float_not_equal(a, b + 0.0002);
|
||||
}
|
||||
|
||||
static void TC_uassert_ptr_op(void)
|
||||
{
|
||||
int a = 5;
|
||||
int b = 10;
|
||||
int *ptr_a = &a;
|
||||
int *ptr_b = &b;
|
||||
|
||||
uassert_ptr_equal(ptr_a, ptr_a);
|
||||
uassert_ptr_not_equal(ptr_a, ptr_b);
|
||||
}
|
||||
|
||||
static void TC_uassert_str_op(void)
|
||||
{
|
||||
const char *str1 = "Hello";
|
||||
const char *str2 = "Hello";
|
||||
const char *str3 = "World";
|
||||
|
||||
uassert_str_equal(str1, str2);
|
||||
uassert_str_not_equal(str1, str3);
|
||||
}
|
||||
|
||||
static void TC_uassert_in_range(void)
|
||||
{
|
||||
int value = 5;
|
||||
uassert_in_range(value, 1, 10);
|
||||
uassert_not_in_range(value, 10, 20);
|
||||
}
|
||||
|
||||
static void utest_do_tc(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(TC_uassert_true_false);
|
||||
UTEST_UNIT_RUN(TC_uassert_null_not_null);
|
||||
UTEST_UNIT_RUN(TC_uassert_int_op);
|
||||
UTEST_UNIT_RUN(TC_uassert_float_op);
|
||||
UTEST_UNIT_RUN(TC_uassert_ptr_op);
|
||||
UTEST_UNIT_RUN(TC_uassert_str_op);
|
||||
UTEST_UNIT_RUN(TC_uassert_in_range);
|
||||
}
|
||||
|
||||
UTEST_TC_EXPORT(utest_do_tc, "utest.uassert", RT_NULL, RT_NULL, 10);
|
@@ -11,12 +11,8 @@
|
||||
#include <rtthread.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "utest.h"
|
||||
#include <utest_log.h>
|
||||
|
||||
#undef DBG_TAG
|
||||
#undef DBG_LVL
|
||||
#include "utest_log.h"
|
||||
|
||||
#define DBG_TAG "utest"
|
||||
#ifdef UTEST_DEBUG
|
||||
@@ -33,7 +29,7 @@
|
||||
#ifdef UTEST_THR_STACK_SIZE
|
||||
#define UTEST_THREAD_STACK_SIZE UTEST_THR_STACK_SIZE
|
||||
#else
|
||||
#define UTEST_THREAD_STACK_SIZE (4096)
|
||||
#define UTEST_THREAD_STACK_SIZE 4096
|
||||
#endif
|
||||
|
||||
#ifdef UTEST_THR_PRIORITY
|
||||
@@ -191,7 +187,7 @@ static int utest_help(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void utest_run(const char *utest_name)
|
||||
static void utest_do_run(const char *utest_name)
|
||||
{
|
||||
rt_size_t i;
|
||||
rt_uint32_t index;
|
||||
@@ -217,7 +213,7 @@ static void utest_run(const char *utest_name)
|
||||
{
|
||||
if (utest_name)
|
||||
{
|
||||
int len = strlen(utest_name);
|
||||
int len = rt_strlen(utest_name);
|
||||
if (utest_name[len - 1] == '*')
|
||||
{
|
||||
len -= 1;
|
||||
@@ -235,7 +231,7 @@ static void utest_run(const char *utest_name)
|
||||
{
|
||||
if (tc_table[i].init() != RT_EOK)
|
||||
{
|
||||
LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
|
||||
LOG_E("[ FAILED ] [ result ] testcase init (%s)", tc_table[i].name);
|
||||
goto __tc_continue;
|
||||
}
|
||||
}
|
||||
@@ -263,7 +259,7 @@ static void utest_run(const char *utest_name)
|
||||
{
|
||||
if (tc_table[i].cleanup() != RT_EOK)
|
||||
{
|
||||
LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name);
|
||||
LOG_E("[ FAILED ] [ result ] testcase cleanup (%s)", tc_table[i].name);
|
||||
goto __tc_continue;
|
||||
}
|
||||
}
|
||||
@@ -300,17 +296,38 @@ static void utest_run(const char *utest_name)
|
||||
}
|
||||
}
|
||||
|
||||
static void utest_thr_entry(const char *utest_name)
|
||||
static void utest_thr_entry(void *para)
|
||||
{
|
||||
/* see commit:0dc7b9a for details */
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
utest_run(utest_name);
|
||||
char *utest_name = (char *)para;
|
||||
rt_thread_mdelay(1000); /* see commit:0dc7b9a for details */
|
||||
rt_kprintf("\n");
|
||||
utest_do_run(utest_name);
|
||||
}
|
||||
|
||||
long utest_testcase_run(int argc, char** argv)
|
||||
static void utest_thread_create(const char *utest_name)
|
||||
{
|
||||
rt_thread_t tid = RT_NULL;
|
||||
tid = rt_thread_create("utest",
|
||||
utest_thr_entry, (void *)utest_name,
|
||||
UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10);
|
||||
if (tid != RT_NULL)
|
||||
{
|
||||
rt_thread_startup(tid);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef RT_UTEST_USING_AUTO_RUN
|
||||
static int utest_auto_run(void)
|
||||
{
|
||||
tc_loop = 1;
|
||||
utest_thread_create(RT_NULL);
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_APP_EXPORT(utest_auto_run);
|
||||
#endif /* RT_UTEST_USING_AUTO_RUN */
|
||||
|
||||
int utest_testcase_run(int argc, char** argv)
|
||||
{
|
||||
static char utest_name[UTEST_NAME_MAX_LEN];
|
||||
rt_memset(utest_name, 0x0, sizeof(utest_name));
|
||||
|
||||
@@ -318,27 +335,21 @@ long utest_testcase_run(int argc, char** argv)
|
||||
|
||||
if (argc == 1)
|
||||
{
|
||||
utest_run(RT_NULL);
|
||||
return 0;
|
||||
utest_thread_create(RT_NULL);
|
||||
}
|
||||
else if (argc == 2 || argc == 3 || argc == 4)
|
||||
{
|
||||
if (rt_strcmp(argv[1], "-thread") == 0)
|
||||
{
|
||||
rt_thread_t tid = RT_NULL;
|
||||
if (argc == 3 || argc == 4)
|
||||
{
|
||||
rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1);
|
||||
|
||||
if (argc == 4) tc_loop = atoi(argv[3]);
|
||||
}
|
||||
tid = rt_thread_create("utest",
|
||||
(void (*)(void *))utest_thr_entry, utest_name,
|
||||
UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10);
|
||||
if (tid != NULL)
|
||||
{
|
||||
rt_thread_startup(tid);
|
||||
if (argc == 4)
|
||||
{
|
||||
tc_loop = atoi(argv[3]);
|
||||
}
|
||||
}
|
||||
utest_thread_create(utest_name);
|
||||
}
|
||||
else if (rt_strcmp(argv[1], "-help") == 0)
|
||||
{
|
||||
@@ -347,8 +358,11 @@ long utest_testcase_run(int argc, char** argv)
|
||||
else
|
||||
{
|
||||
rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1);
|
||||
if (argc == 3) tc_loop = atoi(argv[2]);
|
||||
utest_run(utest_name);
|
||||
if (argc == 3)
|
||||
{
|
||||
tc_loop = atoi(argv[2]);
|
||||
}
|
||||
utest_do_run(utest_name);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -356,7 +370,8 @@ long utest_testcase_run(int argc, char** argv)
|
||||
LOG_E("[ error ] at (%s:%d), in param error.", __func__, __LINE__);
|
||||
utest_help();
|
||||
}
|
||||
return 0;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num]);
|
||||
|
||||
@@ -367,7 +382,7 @@ utest_t utest_handle_get(void)
|
||||
|
||||
void utest_unit_run(test_unit_func func, const char *unit_func_name)
|
||||
{
|
||||
// LOG_I("[==========] utest unit name: (%s)", 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;
|
||||
@@ -378,13 +393,27 @@ void utest_unit_run(test_unit_func func, const char *unit_func_name)
|
||||
}
|
||||
}
|
||||
|
||||
void utest_assert(int value, const char *file, int line, const char *func, const char *msg)
|
||||
/*
|
||||
* utest_assert - assert function
|
||||
*
|
||||
* @param value - assert value
|
||||
* @param file - file name
|
||||
* @param line - line number
|
||||
* @param func - function name
|
||||
* @param msg - assert message
|
||||
*
|
||||
* @return - RT_TRUE: assert success; RT_FALSE: assert failed
|
||||
*/
|
||||
rt_bool_t utest_assert(int value, const char *file, int line, const char *func, const char *msg)
|
||||
{
|
||||
rt_bool_t rst = RT_FALSE;
|
||||
|
||||
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);
|
||||
rst = RT_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -394,38 +423,50 @@ void utest_assert(int value, const char *file, int line, const char *func, const
|
||||
}
|
||||
local_utest.error = UTEST_PASSED;
|
||||
local_utest.passed_num ++;
|
||||
rst = RT_TRUE;
|
||||
}
|
||||
|
||||
return rst;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
rt_bool_t rst = RT_FALSE;
|
||||
|
||||
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);
|
||||
}
|
||||
rst = utest_assert(0, file, line, func, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rt_strcmp(a, b) == 0)
|
||||
if (equal)
|
||||
{
|
||||
utest_assert(0, file, line, func, msg);
|
||||
if (rt_strcmp(a, b) == 0)
|
||||
{
|
||||
rst = utest_assert(1, file, line, func, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
rst = utest_assert(0, file, line, func, msg);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
utest_assert(1, file, line, func, msg);
|
||||
if (rt_strcmp(a, b) == 0)
|
||||
{
|
||||
rst = utest_assert(0, file, line, func, msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
rst = utest_assert(1, file, line, func, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!rst)
|
||||
{
|
||||
LOG_E("[ ASSERT ] [ unit ] str-a: (%s); str-b: (%s)", a, b);
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@@ -12,7 +12,6 @@
|
||||
#define __UTEST_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <stdint.h>
|
||||
#include "utest_log.h"
|
||||
#include "utest_assert.h"
|
||||
|
||||
@@ -173,9 +172,12 @@ utest_t utest_handle_get(void);
|
||||
* @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;
|
||||
#define _UTEST_UNIT_RUN(test_unit_func) \
|
||||
do { \
|
||||
utest_unit_run(test_unit_func, #test_unit_func); \
|
||||
} while (0)
|
||||
|
||||
#define UTEST_UNIT_RUN(test_unit_func) _UTEST_UNIT_RUN(test_unit_func)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* 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);
|
||||
rt_bool_t 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);
|
||||
@@ -27,6 +27,7 @@ void utest_assert_buf(const char *a, const char *b, rt_size_t sz, rt_bool_t equa
|
||||
|
||||
/* No need for the user to use this macro directly */
|
||||
#define __utest_assert(value, msg) utest_assert(value, __FILE__, __LINE__, __func__, msg)
|
||||
#define __uassert_value_op(a, b, op) __utest_assert((a) op (b), "(" #a ") not " #op " (" #b ")")
|
||||
|
||||
/**
|
||||
* uassert_x macros
|
||||
@@ -46,15 +47,61 @@ void utest_assert_buf(const char *a, const char *b, rt_size_t sz, rt_bool_t equa
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
* @macro uassert_float_equal if @a equal to @b, not assert, means passing. Float type test.
|
||||
* @macro uassert_float_not_equal if @a not equal to @b, not assert, means passing. Float type test.
|
||||
* @macro uassert_value_less if @a less than @b, not assert, means passing.
|
||||
* @macro uassert_value_less_equal if @a less than or equal to @b, not assert, means passing.
|
||||
* @macro uassert_value_greater if @a greater than @b, not assert, means passing.
|
||||
* @macro uassert_value_greater_equal if @a greater than or equal to @b, not assert, means passing.
|
||||
* @macro uassert_ptr_equal if @a equal to @b, not assert, means passing. Pointer type test.
|
||||
* @macro uassert_ptr_not_equal if @a not equal to @b, not assert, means passing. Pointer type test.
|
||||
*/
|
||||
#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((const char *)(value) == RT_NULL, "(" #value ") is not null")
|
||||
#define uassert_not_null(value) __utest_assert((const char *)(value) != RT_NULL, "(" #value ") is null")
|
||||
|
||||
#define uassert_int_equal(a, b) __utest_assert((a) == (b), "(" #a ") not equal to (" #b ")")
|
||||
#define uassert_int_not_equal(a, b) __utest_assert((a) != (b), "(" #a ") equal to (" #b ")")
|
||||
#define uassert_in_range(value, min, max) \
|
||||
do { \
|
||||
double _value = (value); \
|
||||
double _min = (min); \
|
||||
double _max = (max); \
|
||||
__utest_assert((_value >= _min) && (_value <= _max), "(" #value ") not in range("#min","#max")"); \
|
||||
} while(0)
|
||||
|
||||
#define uassert_not_in_range(value, min, max) \
|
||||
do { \
|
||||
double _value = (value); \
|
||||
double _min = (min); \
|
||||
double _max = (max); \
|
||||
__utest_assert((_value < _min) || (_value > _max), "(" #value ") in range("#min","#max")"); \
|
||||
} while(0)
|
||||
|
||||
#define uassert_float_equal(a, b) \
|
||||
do { \
|
||||
double _a = (a); \
|
||||
double _b = (b); \
|
||||
uassert_in_range(_a, ((double)_b - 0.0001), ((double)_b + 0.0001)); \
|
||||
} while(0)
|
||||
|
||||
#define uassert_float_not_equal(a, b) \
|
||||
do { \
|
||||
double _a = (a); \
|
||||
double _b = (b); \
|
||||
uassert_not_in_range(_a, ((double)_b - 0.0001), ((double)_b + 0.0001)); \
|
||||
} while(0)
|
||||
|
||||
#define uassert_int_equal(a, b) __uassert_value_op(a, b, ==)
|
||||
#define uassert_int_not_equal(a, b) __uassert_value_op(a, b, !=)
|
||||
|
||||
#define uassert_value_less(a, b) __uassert_value_op(a, b, <)
|
||||
#define uassert_value_less_equal(a, b) __uassert_value_op(a, b, <=)
|
||||
#define uassert_value_greater(a, b) __uassert_value_op(a, b, >)
|
||||
#define uassert_value_greater_equal(a, b) __uassert_value_op(a, b, >=)
|
||||
|
||||
#define uassert_ptr_equal(a, b) __utest_assert((const void*)(a) == (const void*)(b), "(" #a ") not equal to (" #b ")")
|
||||
#define uassert_ptr_not_equal(a, b) __utest_assert((const void*)(a) != (const void*)(b), "(" #a ") equal to (" #b ")")
|
||||
|
||||
#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")
|
||||
@@ -62,9 +109,6 @@ void utest_assert_buf(const char *a, const char *b, rt_size_t sz, rt_bool_t equa
|
||||
#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")")
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@@ -13,12 +13,12 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define UTEST_DEBUG
|
||||
// #define UTEST_DEBUG
|
||||
|
||||
#undef DBG_TAG
|
||||
#undef DBG_LVL
|
||||
|
||||
#define DBG_TAG "testcase"
|
||||
#define DBG_TAG "utest"
|
||||
#ifdef UTEST_DEBUG
|
||||
#define DBG_LVL DBG_LOG
|
||||
#else
|
||||
|
@@ -46,7 +46,6 @@ static enum rym_code _rym_recv_begin(
|
||||
rt_size_t len)
|
||||
{
|
||||
struct custom_ctx *cctx = (struct custom_ctx *)ctx;
|
||||
struct stat file_buf;
|
||||
char insert_0 = '\0';
|
||||
char *ret;
|
||||
rt_err_t err;
|
||||
@@ -64,7 +63,7 @@ static enum rym_code _rym_recv_begin(
|
||||
cctx->fd = open(cctx->fpath, O_CREAT | O_WRONLY | O_TRUNC, 0);
|
||||
if (cctx->fd < 0)
|
||||
{
|
||||
rt_err_t err = rt_get_errno();
|
||||
err = rt_get_errno();
|
||||
rt_kprintf("error creating file: %d\n", err);
|
||||
return RYM_CODE_CAN;
|
||||
}
|
||||
|
@@ -500,8 +500,8 @@ static rt_err_t _rym_do_fin(struct rym_ctx *ctx)
|
||||
else
|
||||
return -RYM_ERR_CODE;
|
||||
|
||||
i = _rym_read_data(ctx, _RYM_SOH_PKG_SZ - 1);
|
||||
if (i != (_RYM_SOH_PKG_SZ - 1))
|
||||
i = _rym_read_data(ctx, data_sz - 1);
|
||||
if (i != (data_sz - 1))
|
||||
return -RYM_ERR_DSZ;
|
||||
|
||||
/* sanity check
|
||||
@@ -509,8 +509,8 @@ static rt_err_t _rym_do_fin(struct rym_ctx *ctx)
|
||||
if (ctx->buf[1] != 0 || ctx->buf[2] != 0xFF)
|
||||
return -RYM_ERR_SEQ;
|
||||
|
||||
recv_crc = (rt_uint16_t)(*(ctx->buf + _RYM_SOH_PKG_SZ - 2) << 8) | *(ctx->buf + _RYM_SOH_PKG_SZ - 1);
|
||||
if (recv_crc != CRC16(ctx->buf + 3, _RYM_SOH_PKG_SZ - 5))
|
||||
recv_crc = (rt_uint16_t)(*(ctx->buf + data_sz - 2) << 8) | *(ctx->buf + data_sz - 1);
|
||||
if (recv_crc != CRC16(ctx->buf + 3, data_sz - 5))
|
||||
return -RYM_ERR_CRC;
|
||||
|
||||
/*next file transmission*/
|
||||
|
Reference in New Issue
Block a user