initial commit
This commit is contained in:
2
mw/unittest/config.mk
Executable file
2
mw/unittest/config.mk
Executable file
@@ -0,0 +1,2 @@
|
||||
CORE_SRCDIRS += $(MW_DIR)/unittest
|
||||
HEADERS += $(MW_DIR)/unittest/*.h
|
||||
99
mw/unittest/mw_unittest.c
Executable file
99
mw/unittest/mw_unittest.c
Executable file
@@ -0,0 +1,99 @@
|
||||
/*************************************************
|
||||
File name : mw_unittest.c
|
||||
Module :
|
||||
Author : amir
|
||||
Version : 0.1
|
||||
Created on : 2023-02-07
|
||||
Description :
|
||||
Data structure and function definitions required by the socket interface
|
||||
|
||||
Modify History:
|
||||
1. Date: Author: Modification:
|
||||
*************************************************/
|
||||
#include "mw_mmc.h"
|
||||
#include "mw_unittest.h"
|
||||
#include "hlog.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
#define INSUT_UNITTEST_SHOWHOW -2
|
||||
|
||||
static int32_t unittest_help(unittest_cmd *cmd_info, uint8_t cmd_cnt)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
if(cmd_info == NULL)
|
||||
{
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
hlogi("Command List:");
|
||||
for(i=0; i<cmd_cnt; i++)
|
||||
{
|
||||
hlogi(" %s - %s", cmd_info[i].cmd_name, cmd_info[i].cmd_help);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t unittest_run_cmd(unittest_cmd *cmd_info, uint8_t cmd_cnt, int32_t argc, char **argv)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
int32_t rval = 0;
|
||||
if(argc > 0 && argv != NULL)
|
||||
{
|
||||
for(i=0; i<cmd_cnt; i++)
|
||||
{
|
||||
if(strcmp(argv[0], cmd_info[i].cmd_name) == 0)
|
||||
{
|
||||
if(cmd_info[i].exec_func != NULL)
|
||||
{
|
||||
rval = cmd_info[i].exec_func(argc-1, &argv[1]);
|
||||
if(rval == INSUT_UNITTEST_SHOWHOW)
|
||||
{
|
||||
unittest_help(cmd_info, cmd_cnt);
|
||||
}
|
||||
else if(rval != 0)
|
||||
{
|
||||
hloge("Rum cmd fail [ %s ] (0x%x)", argv[0], rval);
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
else if(cmd_info[i].next_cmd != NULL)
|
||||
{
|
||||
return unittest_run_cmd(cmd_info[i].next_cmd, cmd_info[i].next_cmd_cnt, argc-1, &argv[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unittest_help(cmd_info, cmd_cnt);
|
||||
return INSUT_UNITTEST_SHOWHOW;
|
||||
}
|
||||
|
||||
int32_t unittest_shell_entry(int32_t argc, char **argv)
|
||||
{
|
||||
unittest_cmd *cmds;
|
||||
uint32_t cnt = unittest_get(&cmds);
|
||||
return unittest_run_cmd(cmds, cnt, argc, argv);
|
||||
}
|
||||
|
||||
void unittest(uint32_t argc, char **argv)
|
||||
{
|
||||
unittest_shell_entry(argc, argv);
|
||||
}
|
||||
|
||||
int32_t unittest_test()
|
||||
{
|
||||
char *args0[]={}; /* print all */
|
||||
unittest_shell_entry(sizeof(args0)/sizeof(char *), args0);
|
||||
|
||||
char *args[]={"device", "gpio", "output", "88", "0"};
|
||||
//char *args[]={"device", "gpio"}; 提示help
|
||||
unittest_shell_entry(sizeof(args)/sizeof(char *), args);
|
||||
|
||||
char *args2[]={"media", "debug"};
|
||||
// char *args2[]={"media"}; 提示help
|
||||
unittest_shell_entry(sizeof(args2)/sizeof(char *), args2);
|
||||
|
||||
char *args3[]={"main", "main"};
|
||||
unittest_shell_entry(sizeof(args3)/sizeof(char *), args3);
|
||||
}
|
||||
|
||||
33
mw/unittest/mw_unittest.h
Executable file
33
mw/unittest/mw_unittest.h
Executable file
@@ -0,0 +1,33 @@
|
||||
#ifndef __MW_UNITTES_H__
|
||||
#define __MW_UNITTES_H__
|
||||
#include <stdint.h>
|
||||
#include "hal.h"
|
||||
|
||||
|
||||
//int32_t unittest_register(AMBA_SHELL_COMMAND_s *pNewCmd);
|
||||
/* unittest_shell_entry
|
||||
** 执行命令行
|
||||
** 将这个函数插到shell回调中
|
||||
*/
|
||||
int32_t unittest_shell_entry(int32_t argc, char **argv);
|
||||
|
||||
/* unittest_file_entry
|
||||
** 执行脚本文件
|
||||
*/
|
||||
int32_t unittest_file_entry(uint8_t file_cnt, char *file_list[]);
|
||||
|
||||
/* unittest_get
|
||||
** 需要由外部的project的unittest_list实现
|
||||
*/
|
||||
int32_t unittest_get(unittest_cmd **cmds);
|
||||
//{
|
||||
// *cmds = unittest_list;
|
||||
// return sizeof(unittest_list)/sizeof(unittest_cmd);
|
||||
//}
|
||||
|
||||
|
||||
void unittest(uint32_t argc, char **argv);
|
||||
|
||||
int32_t unittest_test();
|
||||
|
||||
#endif /* __MW_UNITTES_H__ */
|
||||
Reference in New Issue
Block a user