@@ -73,6 +73,36 @@ void utest_log_lv_set(rt_uint8_t lv)
7373 }
7474}
7575
76+ static struct msh_cmd_opt utest_testcase_run_msh_options [MAX_UTEST_OPTIONS ];
77+
78+ static void utest_build_options (void )
79+ {
80+ rt_size_t i ;
81+ rt_size_t option_index = 0 ;
82+
83+ if (tc_num >= MAX_UTEST_OPTIONS - 1 )
84+ {
85+ LOG_W ("Too many test cases (%d), only first %d will have completion" , tc_num , MAX_UTEST_OPTIONS - 1 );
86+ }
87+
88+ rt_memset (utest_testcase_run_msh_options , 0 , sizeof (utest_testcase_run_msh_options ));
89+
90+ rt_size_t max_cases = (tc_num < MAX_UTEST_OPTIONS - 1 ) ? tc_num : MAX_UTEST_OPTIONS - 1 ;
91+ for (i = 0 ; i < max_cases ; i ++ )
92+ {
93+ utest_testcase_run_msh_options [option_index ].id = i + 1 ;
94+ utest_testcase_run_msh_options [option_index ].name = tc_table [i ].name ;
95+ utest_testcase_run_msh_options [option_index ].des = RT_NULL ;
96+ option_index ++ ;
97+ }
98+
99+ utest_testcase_run_msh_options [option_index ].id = 0 ;
100+ utest_testcase_run_msh_options [option_index ].name = RT_NULL ;
101+ utest_testcase_run_msh_options [option_index ].des = RT_NULL ;
102+ }
103+
104+ static void utest_build_options (void );
105+
76106int utest_init (void )
77107{
78108 /* initialize the utest commands table.*/
@@ -123,6 +153,9 @@ int utest_init(void)
123153 LOG_E ("no memory, tc_fail_list init failed!" );
124154 }
125155 }
156+
157+ utest_build_options ();
158+
126159 return tc_num ;
127160}
128161INIT_COMPONENT_EXPORT (utest_init );
@@ -335,6 +368,7 @@ INIT_APP_EXPORT(utest_auto_run);
335368int utest_testcase_run (int argc , char * * argv )
336369{
337370 static char utest_name [UTEST_NAME_MAX_LEN ];
371+ int opt_id ;
338372 rt_memset (utest_name , 0x0 , sizeof (utest_name ));
339373
340374 tc_loop = 1 ;
@@ -343,32 +377,47 @@ int utest_testcase_run(int argc, char** argv)
343377 {
344378 utest_thread_create (RT_NULL );
345379 }
346- else if (argc == 2 || argc == 3 || argc == 4 )
380+ else if (argc >= 2 )
347381 {
348- if (rt_strcmp (argv [1 ], "-thread" ) == 0 )
382+ opt_id = msh_cmd_opt_id_get (argc , argv , (void * )utest_testcase_run_msh_options );
383+
384+ if (opt_id >= 1 && opt_id <= tc_num )
349385 {
350- if (argc == 3 || argc == 4 )
386+ rt_size_t test_index = opt_id - 1 ;
387+ rt_strncpy (utest_name , tc_table [test_index ].name , sizeof (utest_name ) - 1 );
388+ if (argc == 3 )
351389 {
352- rt_strncpy (utest_name , argv [2 ], sizeof (utest_name ) - 1 );
353- if (argc == 4 )
354- {
355- tc_loop = atoi (argv [3 ]);
356- }
390+ tc_loop = atoi (argv [2 ]);
357391 }
358- utest_thread_create (utest_name );
359- }
360- else if (rt_strcmp (argv [1 ], "-help" ) == 0 )
361- {
362- utest_help ();
392+ utest_do_run (utest_name );
363393 }
364394 else
365395 {
366- rt_strncpy (utest_name , argv [1 ], sizeof (utest_name ) - 1 );
367- if (argc == 3 )
396+ if (rt_strcmp (argv [1 ], "-thread" ) == 0 )
368397 {
369- tc_loop = atoi (argv [2 ]);
398+ if (argc == 3 || argc == 4 )
399+ {
400+ rt_strncpy (utest_name , argv [2 ], sizeof (utest_name ) - 1 );
401+ if (argc == 4 )
402+ {
403+ tc_loop = atoi (argv [3 ]);
404+ }
405+ }
406+ utest_thread_create (utest_name );
407+ }
408+ else if (rt_strcmp (argv [1 ], "-help" ) == 0 )
409+ {
410+ utest_help ();
411+ }
412+ else
413+ {
414+ rt_strncpy (utest_name , argv [1 ], sizeof (utest_name ) - 1 );
415+ if (argc == 3 )
416+ {
417+ tc_loop = atoi (argv [2 ]);
418+ }
419+ utest_do_run (utest_name );
370420 }
371- utest_do_run (utest_name );
372421 }
373422 }
374423 else
@@ -379,7 +428,7 @@ int utest_testcase_run(int argc, char** argv)
379428
380429 return RT_EOK ;
381430}
382- MSH_CMD_EXPORT_ALIAS (utest_testcase_run , utest_run , utest_run [- thread or - help ] [testcase name ] [loop num ]);
431+ MSH_CMD_EXPORT_ALIAS (utest_testcase_run , utest_run , utest_run [- thread or - help ] [testcase name ] [loop num ], optenable );
383432
384433utest_t utest_handle_get (void )
385434{
0 commit comments