diff options
| author | CYFS3 <CYFS3+github[bot]@noreply.github.com> | 2026-07-23 07:22:58 +0000 |
|---|---|---|
| committer | Rbb666 <[email protected]> | 2026-10-28 14:44:20 +0800 |
| commit | ff82e23d1376de8adf1e92fabe4f939cfcec069f (patch) | |
| tree | fefe040022c425f1e3ba6be3cc8b36d34553571b /components/utilities | |
| parent | 25dcad752cc8d0b06942cbfec94e1a8a1d0b2d50 (diff) | |
style: format code with clang-format [skip ci]
Diffstat (limited to 'components/utilities')
| -rw-r--r-- | components/utilities/utest/utest.c | 64 |
1 files changed, 31 insertions, 33 deletions
diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index e4a4983372..f9f80fdff9 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -14,11 +14,11 @@ #include "utest.h" #include "utest_log.h" -#define DBG_TAG "utest" +#define DBG_TAG "utest" #ifdef UTEST_DEBUG -#define DBG_LVL DBG_LOG +#define DBG_LVL DBG_LOG #else -#define DBG_LVL DBG_INFO +#define DBG_LVL DBG_INFO #endif #include <rtdbg.h> @@ -33,9 +33,9 @@ #endif #ifdef UTEST_THR_PRIORITY -#define UTEST_THREAD_PRIORITY UTEST_THR_PRIORITY +#define UTEST_THREAD_PRIORITY UTEST_THR_PRIORITY #else -#define UTEST_THREAD_PRIORITY FINSH_THREAD_PRIORITY +#define UTEST_THREAD_PRIORITY FINSH_THREAD_PRIORITY #endif static rt_uint8_t utest_log_lv = UTEST_LOG_ALL; @@ -43,27 +43,25 @@ static utest_tc_export_t tc_table = RT_NULL; static rt_size_t tc_num; static rt_uint32_t tc_loop; static rt_uint8_t *tc_fail_list; -static struct utest local_utest = {UTEST_PASSED, 0, 0}; +static struct utest local_utest = { UTEST_PASSED, 0, 0 }; #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ -#pragma section="UtestTcTab" +#pragma section = "UtestTcTab" #elif defined(_MSC_VER) #pragma section("UtestTcTab$a", read) -__declspec(allocate("UtestTcTab$a")) const struct utest_tc_export __tc_export_begin = -{ +__declspec(allocate("UtestTcTab$a")) const struct utest_tc_export __tc_export_begin = { "__start", }; #pragma section("UtestTcTab$z", read) -__declspec(allocate("UtestTcTab$z")) const struct utest_tc_export __tc_export_end = -{ +__declspec(allocate("UtestTcTab$z")) const struct utest_tc_export __tc_export_end = { "__end", }; #endif -#define TC_FAIL_LIST_SIZE (RT_ALIGN(tc_num, 8) / 8) -#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))) +#define TC_FAIL_LIST_SIZE (RT_ALIGN(tc_num, 8) / 8) +#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))) void utest_log_lv_set(rt_uint8_t lv) { @@ -152,7 +150,7 @@ int utest_init(void) if (tc_num > 0) { tc_fail_list = rt_malloc(TC_FAIL_LIST_SIZE); - if(!tc_fail_list) + if (!tc_fail_list) { LOG_E("no memory, tc_fail_list init failed!"); } @@ -184,8 +182,8 @@ static const char *file_basename(const char *file) char *end_ptr = RT_NULL; char *rst = RT_NULL; - if (!((end_ptr = strrchr(file, '\\')) != RT_NULL || \ - (end_ptr = strrchr(file, '/')) != RT_NULL) || \ + if (!((end_ptr = strrchr(file, '\\')) != RT_NULL || + (end_ptr = strrchr(file, '/')) != RT_NULL) || (rt_strlen(file) < 2)) { rst = (char *)file; @@ -232,7 +230,7 @@ static void utest_do_run(const char *utest_name) rt_uint32_t tc_fail_num = 0; rt_uint32_t tc_run_num = 0; - for (index = 0; index < tc_loop; index ++) + for (index = 0; index < tc_loop; index++) { i = 0; is_find = RT_FALSE; @@ -246,7 +244,7 @@ static void utest_do_run(const char *utest_name) LOG_I("[==========] [ utest ] loop %d/%d", index + 1, tc_loop); LOG_I("[==========] [ utest ] started"); - while(i < tc_num) + while (i < tc_num) { if (utest_name) { @@ -276,7 +274,7 @@ static void utest_do_run(const char *utest_name) if (tc_table[i].init() != RT_EOK) { TC_FAIL_LIST_MARK_FAILED(i); - tc_fail_num ++; + tc_fail_num++; tc_failed = RT_TRUE; LOG_E("[ FAILED ] [ result ] testcase init (%s)", tc_table[i].name); goto __tc_continue; @@ -297,7 +295,7 @@ static void utest_do_run(const char *utest_name) else { TC_FAIL_LIST_MARK_FAILED(i); - tc_fail_num ++; + tc_fail_num++; tc_failed = RT_TRUE; LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); } @@ -305,7 +303,7 @@ static void utest_do_run(const char *utest_name) else { TC_FAIL_LIST_MARK_FAILED(i); - tc_fail_num ++; + tc_fail_num++; tc_failed = RT_TRUE; LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); } @@ -317,17 +315,17 @@ static void utest_do_run(const char *utest_name) if (tc_failed == RT_FALSE) { TC_FAIL_LIST_MARK_FAILED(i); - tc_fail_num ++; + tc_fail_num++; } LOG_E("[ FAILED ] [ result ] testcase cleanup (%s)", tc_table[i].name); goto __tc_continue; } } - __tc_continue: + __tc_continue: LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name); - tc_run_num ++; + tc_run_num++; i++; } @@ -341,10 +339,10 @@ static void utest_do_run(const char *utest_name) 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)) + 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 ++) + for (i = 0; i < tc_num; i++) { if (TC_FAIL_LIST_IS_FAILED(i)) { @@ -387,7 +385,7 @@ static int utest_auto_run(void) INIT_APP_EXPORT(utest_auto_run); #endif /* RT_UTEST_USING_AUTO_RUN */ -int utest_testcase_run(int argc, char** argv) +int utest_testcase_run(int argc, char **argv) { static char utest_name[UTEST_NAME_MAX_LEN]; rt_memset(utest_name, 0x0, sizeof(utest_name)); @@ -404,7 +402,7 @@ int utest_testcase_run(int argc, char** argv) { if (argc == 3 || argc == 4) { - rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1); + rt_strncpy(utest_name, argv[2], sizeof(utest_name) - 1); if (argc == 4) { tc_loop = atoi(argv[3]); @@ -418,7 +416,7 @@ int utest_testcase_run(int argc, char** argv) } else { - rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1); + rt_strncpy(utest_name, argv[1], sizeof(utest_name) - 1); if (argc == 3) { tc_loop = atoi(argv[2]); @@ -434,7 +432,7 @@ int utest_testcase_run(int argc, char** argv) return RT_EOK; } -MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num], optenable); +MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run[-thread or -help][testcase name][loop num], optenable); utest_t utest_handle_get(void) { @@ -485,7 +483,7 @@ rt_bool_t utest_assert(int value, const char *file, int line, const char *func, if (!(value)) { local_utest.error = UTEST_FAILED; - local_utest.failed_num ++; + local_utest.failed_num++; LOG_E("[ ASSERT ] [ unit ] at (%s); func: (%s:%d); msg: (%s)", file_basename(file), func, line, msg); rst = RT_FALSE; } @@ -496,7 +494,7 @@ rt_bool_t utest_assert(int value, const char *file, int line, const char *func, LOG_D("[ OK ] [ unit ] (%s:%d) is passed", func, line); } local_utest.error = UTEST_PASSED; - local_utest.passed_num ++; + local_utest.passed_num++; rst = RT_TRUE; } |
