varch/test/test_init.c
2024-11-16 13:36:54 +08:00

102 lines
1.8 KiB
C

#include <stdio.h>
#if defined(TEST_TARGET_init)
#include <varch/command.h>
#include <varch/init.h>
#else
#include "init.h"
#include "command.h"
#include "init.h"
#endif
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"
" -h Print help\n"
" -v Print version\n"
"\n"
"argument:\n"
" <read> Test default read function\n"
" <write> Test default write function\n"
);
}
static int test(int argc, char *argv[])
{
/* reset getopt */
command_opt_init();
while (1)
{
int opt = command_getopt(argc, argv, "hv");
if (opt == -1) break;
switch (opt)
{
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;
}
#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