Skip to content

Commit e4054a2

Browse files
committed
[utest] optimize the utest
1 parent c6e447a commit e4054a2

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

components/utilities/utest/utest.c

+30-16
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static int utest_help(void)
191191
return 0;
192192
}
193193

194-
static void utest_run(const char *utest_name)
194+
static void utest_do_run(const char *utest_name)
195195
{
196196
rt_size_t i;
197197
rt_uint32_t index;
@@ -304,41 +304,55 @@ static void utest_thr_entry(const char *utest_name)
304304
{
305305
/* see commit:0dc7b9a for details */
306306
rt_thread_mdelay(1000);
307+
utest_do_run(utest_name);
308+
}
307309

308-
utest_run(utest_name);
310+
static void utest_thread_create(const char *utest_name)
311+
{
312+
rt_thread_t tid = RT_NULL;
313+
tid = rt_thread_create("utest",
314+
(void (*)(void *))utest_thr_entry, RT_NULL /*utest_name*/,
315+
UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10);
316+
if (tid != RT_NULL)
317+
{
318+
rt_thread_startup(tid);
319+
}
309320
}
310321

311-
long utest_testcase_run(int argc, char** argv)
322+
#ifdef RT_USING_CI_ACTION
323+
static int utest_ci_action(void)
312324
{
325+
tc_loop = 1;
326+
utest_thread_create(RT_NULL);
327+
return RT_EOK;
328+
}
329+
INIT_APP_EXPORT(utest_ci_action);
330+
#endif /* RT_USING_CI_ACTION */
313331

332+
long utest_testcase_run(int argc, char** argv)
333+
{
314334
static char utest_name[UTEST_NAME_MAX_LEN];
315335
rt_memset(utest_name, 0x0, sizeof(utest_name));
316336

317337
tc_loop = 1;
318338

319339
if (argc == 1)
320340
{
321-
utest_run(RT_NULL);
322-
return 0;
341+
utest_thread_create(RT_NULL);
323342
}
324343
else if (argc == 2 || argc == 3 || argc == 4)
325344
{
326345
if (rt_strcmp(argv[1], "-thread") == 0)
327346
{
328-
rt_thread_t tid = RT_NULL;
329347
if (argc == 3 || argc == 4)
330348
{
331349
rt_strncpy(utest_name, argv[2], sizeof(utest_name) -1);
332-
333-
if (argc == 4) tc_loop = atoi(argv[3]);
334-
}
335-
tid = rt_thread_create("utest",
336-
(void (*)(void *))utest_thr_entry, utest_name,
337-
UTEST_THREAD_STACK_SIZE, UTEST_THREAD_PRIORITY, 10);
338-
if (tid != NULL)
339-
{
340-
rt_thread_startup(tid);
350+
if (argc == 4)
351+
{
352+
tc_loop = atoi(argv[3]);
353+
}
341354
}
355+
utest_thread_create(utest_name);
342356
}
343357
else if (rt_strcmp(argv[1], "-help") == 0)
344358
{
@@ -348,7 +362,7 @@ long utest_testcase_run(int argc, char** argv)
348362
{
349363
rt_strncpy(utest_name, argv[1], sizeof(utest_name) -1);
350364
if (argc == 3) tc_loop = atoi(argv[2]);
351-
utest_run(utest_name);
365+
utest_do_run(utest_name);
352366
}
353367
}
354368
else

0 commit comments

Comments
 (0)