diff options
| author | armink <[email protected]> | 2019-02-19 11:50:16 +0800 |
|---|---|---|
| committer | armink <[email protected]> | 2019-02-19 11:50:16 +0800 |
| commit | c231565610fed352558c913ea0afd6faeca08824 (patch) | |
| tree | af662f13d4064fe9df4da8ab3202a453cd47dfe3 /components/utilities | |
| parent | 8ace8be30e014ed67887fcba893624400c8a1154 (diff) | |
Sync from master (6a150c0963d4db931f71c5716c1811b672a19af3)
Diffstat (limited to 'components/utilities')
| -rw-r--r-- | components/utilities/Kconfig | 9 | ||||
| -rw-r--r-- | components/utilities/utest/utest.c | 178 | ||||
| -rw-r--r-- | components/utilities/ymodem/ymodem.c | 38 |
3 files changed, 178 insertions, 47 deletions
diff --git a/components/utilities/Kconfig b/components/utilities/Kconfig index 8e43cfa0a0..1175006a58 100644 --- a/components/utilities/Kconfig +++ b/components/utilities/Kconfig @@ -234,4 +234,13 @@ config RT_USING_UTEST bool "Enable utest (RT-Thread test framework)" default n + if RT_USING_UTEST + config UTEST_THR_STACK_SIZE + int "The utest thread stack size" + default 4096 + config UTEST_THR_PRIORITY + int "The utest thread priority" + default 20 + endif + endmenu diff --git a/components/utilities/utest/utest.c b/components/utilities/utest/utest.c index a0a42d7438..f7348b3be4 100644 --- a/components/utilities/utest/utest.c +++ b/components/utilities/utest/utest.c @@ -10,6 +10,8 @@ #include <rtthread.h> #include <string.h> +#include <stdlib.h> + #include "utest.h" #include <utest_log.h> @@ -32,9 +34,22 @@ #error "RT_CONSOLEBUF_SIZE is less than 256!" #endif +#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 + static rt_uint8_t utest_log_lv = UTEST_LOG_ALL; static utest_tc_export_t tc_table = RT_NULL; static rt_size_t tc_num; +static rt_uint32_t tc_loop; static struct utest local_utest = {UTEST_PASSED, 0, 0}; #if defined(__ICCARM__) || defined(__ICCRX__) /* for IAR compiler */ @@ -104,83 +119,168 @@ static const char *file_basename(const char *file) return (const char *)rst; } +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; +} + static void utest_run(const char *utest_name) { - rt_size_t i = 0; + rt_size_t i; + rt_uint32_t index; + rt_bool_t is_find; + + rt_thread_mdelay(1000); - LOG_I("[==========] [ utest ] started"); - while(i < tc_num) + for (index = 0; index < tc_loop; index ++) { - if (utest_name && rt_strcmp(utest_name, tc_table[i].name)) + i = 0; + is_find = RT_FALSE; + LOG_I("[==========] [ utest ] started"); + while(i < tc_num) { - i++; - continue; - } + 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; + } + } + is_find = RT_TRUE; - LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name); - if (tc_table[i].init != RT_NULL) - { - if (tc_table[i].init() != RT_EOK) + LOG_I("[----------] [ testcase ] (%s) started", tc_table[i].name); + if (tc_table[i].init != RT_NULL) { - LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); - goto __tc_continue; + if (tc_table[i].init() != RT_EOK) + { + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + goto __tc_continue; + } } - } - if (tc_table[i].tc != RT_NULL) - { - 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_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + } } else { LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); } - } - else - { - LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); - } - if (tc_table[i].cleanup != RT_NULL) - { - if (tc_table[i].cleanup() != RT_EOK) + if (tc_table[i].cleanup != RT_NULL) { - LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); - goto __tc_continue; + if (tc_table[i].cleanup() != RT_EOK) + { + LOG_E("[ FAILED ] [ result ] testcase (%s)", tc_table[i].name); + goto __tc_continue; + } } + + __tc_continue: + LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name); + + i++; } -__tc_continue: - LOG_I("[----------] [ testcase ] (%s) finished", tc_table[i].name); + if (i == tc_num && is_find == RT_FALSE) + { + LOG_I("[==========] [ utest ] Not find (%s)", utest_name); + LOG_I("[==========] [ utest ] finished"); + break; + } - i++; + LOG_I("[==========] [ utest ] finished"); } - LOG_I("[==========] [ utest ] finished"); } static void utest_testcase_run(int argc, char** argv) { - char utest_name[UTEST_NAME_MAX_LEN]; + void *thr_param = RT_NULL; + + static char utest_name[UTEST_NAME_MAX_LEN]; + rt_memset(utest_name, 0x0, sizeof(utest_name)); + + tc_loop = 1; if (argc == 1) { utest_run(RT_NULL); + return; } - else if (argc == 2) + else if (argc == 2 || argc == 3 || argc == 4) { - rt_memset(utest_name, 0x0, sizeof(utest_name)); - rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1); - utest_run(utest_name); + 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); + thr_param = (void*)utest_name; + + if (argc == 4) tc_loop = atoi(argv[3]); + } + 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); + } + } + else if (rt_strcmp(argv[1], "-help") == 0) + { + utest_help(); + } + else + { + rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1); + if (argc == 3) tc_loop = atoi(argv[2]); + utest_run(utest_name); + } } else { LOG_E("[ error ] at (%s:%d), in param error.", __func__, __LINE__); + utest_help(); } } -MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [testcase name]); +MSH_CMD_EXPORT_ALIAS(utest_testcase_run, utest_run, utest_run [-thread or -help] [testcase name] [loop num]); utest_t utest_handle_get(void) { diff --git a/components/utilities/ymodem/ymodem.c b/components/utilities/ymodem/ymodem.c index 899ee56ac8..c98c7f6cb6 100644 --- a/components/utilities/ymodem/ymodem.c +++ b/components/utilities/ymodem/ymodem.c @@ -266,6 +266,7 @@ static rt_err_t _rym_do_fin(struct rym_ctx *ctx) enum rym_code code; rt_uint16_t recv_crc; rt_size_t i; + rt_size_t data_sz; ctx->stage = RYM_STAGE_FINISHING; /* we already got one EOT in the caller. invoke the callback if there is @@ -282,7 +283,15 @@ static rt_err_t _rym_do_fin(struct rym_ctx *ctx) _rym_putchar(ctx, RYM_CODE_C); code = _rym_read_code(ctx, RYM_WAIT_PKG_TICK); - if (code != RYM_CODE_SOH) + if (code == RYM_CODE_SOH) + { + data_sz = _RYM_SOH_PKG_SZ; + } + else if(code == RYM_CODE_STX) + { + data_sz = _RYM_STX_PKG_SZ; + } + else return -RYM_ERR_CODE; i = _rym_read_data(ctx, _RYM_SOH_PKG_SZ-1); @@ -290,8 +299,6 @@ static rt_err_t _rym_do_fin(struct rym_ctx *ctx) return -RYM_ERR_DSZ; /* sanity check - * - * TODO: multiple files transmission */ if (ctx->buf[1] != 0 || ctx->buf[2] != 0xFF) return -RYM_ERR_SEQ; @@ -300,6 +307,14 @@ static rt_err_t _rym_do_fin(struct rym_ctx *ctx) if (recv_crc != CRC16(ctx->buf+3, _RYM_SOH_PKG_SZ-5)) return -RYM_ERR_CRC; + /*next file transmission*/ + if (ctx->buf[3] != 0) + { + if (ctx->on_begin && ctx->on_begin(ctx, ctx->buf+3, data_sz-5) != RYM_CODE_ACK) + return -RYM_ERR_CAN; + return RT_EOK; + } + /* congratulations, check passed. */ ctx->stage = RYM_STAGE_FINISHED; @@ -324,12 +339,19 @@ static rt_err_t _rym_do_recv( err = _rym_do_handshake(ctx, handshake_timeout); if (err != RT_EOK) return err; + while (1) + { + err = _rym_do_trans(ctx); + if (err != RT_EOK) + return err; - err = _rym_do_trans(ctx); - if (err != RT_EOK) - return err; - - return _rym_do_fin(ctx); + err = _rym_do_fin(ctx); + if (err != RT_EOK) + return err; + if (ctx->stage == RYM_STAGE_FINISHED) + break; + } + return err; } rt_err_t rym_recv_on_device( |
