#include #if defined(TEST_TARGET_init) #include #include #include #else #include "init.h" #include "command.h" #include "unitt.h" #include "kern.h" #include "init.h" #endif /************************************************************************************/ /************************************* Unit Test ************************************/ /************************************************************************************/ // #define EXIT_TEST extern uint64_t unitt_clock(void); static int test_0(void) { for (int i = 0; i < 100; i++) { if (0) { #if defined (EXIT_TEST) exit(0); #endif return UNITT_E_FAIL; } } return UNITT_E_OK; } static void unitt_task(void) { static UNITT_TCASE rand_tests[] = { UNITT_TCASE(test_0), // UNITT_TCASE(test_1), // UNITT_TCASE(test_2), }; static UNITT suites[] = { { "xxx suite", rand_tests, sizeof(rand_tests) / sizeof(rand_tests[0]) , unitt_clock }, }; UNITT_EXE(suites); } /************************************************************************************/ /************************************* Base Test ************************************/ /************************************************************************************/ void test_init_hardware(void) { printf("hardware init!\r\n"); } init_export_hardware(test_init_hardware); void test_init_driver(void) { printf("driver init!\r\n"); } init_export_driver(test_init_driver); void test_init_system(void) { printf("system init!\r\n"); } init_export_system(test_init_system); void test_init_module(void) { printf("module init!\r\n"); } init_export_module(test_init_module); void test_init_app(void) { printf("app init!\r\n"); } init_export_app(test_init_app); void test_init_system1(void) { printf("system1 init!\r\n"); } init_export_system(test_init_system1); static void usage(void) { printf( "Usage: init [opt] [arg] ...\n" "\n" "options:\n" " -e Specifies the function to execute, the default is the test\n" " Test base function\n" " Unit test\n" " -h Print help\n" " -v Print version\n" " -u [] Unit test period, unit ms, the default is 1000ms\n" "\n" ); } static int test(int argc, char *argv[]) { char *execute = NULL; int ut_period = 1000; /* reset getopt */ command_opt_init(); while (1) { int opt = command_getopt(argc, argv, "e:hvu::"); if (opt == -1) break; switch (opt) { case 'u' : if (command_optarg) ut_period = atoi(command_optarg); break; case 'e' : execute = command_optarg; break; case 'v' : printf("init version %d.%d.%d\r\n", INIT_V_MAJOR, INIT_V_MINOR, INIT_V_PATCH); return 0; case '?': printf("Unknown option `%c`\r\n", command_optopt); return -1; case 'h' : default: usage(); return 0; } } return 0; } /************************************************************************************/ /************************************ Test entry ************************************/ /************************************************************************************/ #if defined(TEST_TARGET_init) int main(int argc, char *argv[]) { return test(argc, argv); } #else void test_init(void) { command_export("init", test); } init_export_app(test_init); #endif