fixed non-standard naming and usage

This commit is contained in:
pengyiqiang 2022-08-16 23:56:40 +08:00 committed by Xiang Xiao
parent 2af0fb3815
commit d3232585b0
12 changed files with 115 additions and 111 deletions

View File

@ -39,7 +39,7 @@
#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type) \ #define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type) \
do { \ do { \
if ((type_mask & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type) \ if (((type_mask) & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type) \
{ \ { \
FAR struct monkey_dev_s *dev; \ FAR struct monkey_dev_s *dev; \
dev = monkey_dev_create(CONFIG_TESTING_MONKEY_DEV_PATH_##type, \ dev = monkey_dev_create(CONFIG_TESTING_MONKEY_DEV_PATH_##type, \
@ -48,8 +48,8 @@ do { \
{ \ { \
goto failed; \ goto failed; \
} \ } \
monkey->devs[monkey->dev_num] = dev; \ (monkey)->devs[(monkey)->dev_num] = dev; \
monkey->dev_num++; \ (monkey)->dev_num++; \
} \ } \
} while (0) } while (0)
@ -63,9 +63,8 @@ do { \
FAR struct monkey_s *monkey_create(int dev_type_mask) FAR struct monkey_s *monkey_create(int dev_type_mask)
{ {
FAR struct monkey_s *monkey = malloc(sizeof(struct monkey_s)); FAR struct monkey_s *monkey = calloc(1, sizeof(struct monkey_s));
MONKEY_ASSERT_NULL(monkey); MONKEY_ASSERT_NULL(monkey);
memset(monkey, 0, sizeof(struct monkey_s));
if (MONKEY_IS_UINPUT_TYPE(dev_type_mask)) if (MONKEY_IS_UINPUT_TYPE(dev_type_mask))
{ {

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_H
#define __MONKEY_H__ #define __APPS_TESTING_MONKEY_MONKEY_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -95,4 +95,4 @@ bool monkey_set_recorder_path(FAR struct monkey_s *monkey,
} }
#endif #endif
#endif /* __MONKEY_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_H */

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_ASSERT_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_ASSERT_H
#define __MONKEY_ASSERT_H__ #define __APPS_TESTING_MONKEY_MONKEY_ASSERT_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -34,4 +34,4 @@
#define MONKEY_ASSERT(expr) DEBUGASSERT(expr) #define MONKEY_ASSERT(expr) DEBUGASSERT(expr)
#define MONKEY_ASSERT_NULL(ptr) MONKEY_ASSERT(ptr != NULL) #define MONKEY_ASSERT_NULL(ptr) MONKEY_ASSERT(ptr != NULL)
#endif /* __MONKEY_ASSERT_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_ASSERT_H */

View File

@ -134,6 +134,10 @@ static bool button_read(int fd, FAR uint32_t *value)
return true; return true;
} }
/****************************************************************************
* Public Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: monkey_dev_create * Name: monkey_dev_create
****************************************************************************/ ****************************************************************************/
@ -147,9 +151,8 @@ FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
MONKEY_ASSERT_NULL(dev_path); MONKEY_ASSERT_NULL(dev_path);
dev = malloc(sizeof(struct monkey_dev_s)); dev = calloc(1, sizeof(struct monkey_dev_s));
MONKEY_ASSERT_NULL(dev); MONKEY_ASSERT_NULL(dev);
memset(dev, 0, sizeof(struct monkey_dev_s));
if (MONKEY_IS_UINPUT_TYPE(type)) if (MONKEY_IS_UINPUT_TYPE(type))
{ {
@ -189,10 +192,6 @@ failed:
return NULL; return NULL;
} }
/****************************************************************************
* Public Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: monkey_dev_delete * Name: monkey_dev_delete
****************************************************************************/ ****************************************************************************/
@ -212,7 +211,6 @@ void monkey_dev_delete(FAR struct monkey_dev_s *dev)
MONKEY_LOG_NOTICE("close fd: %d", dev->fd); MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
close(dev->fd); close(dev->fd);
dev->fd = -1;
} }
free(dev); free(dev);

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_DEV_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_DEV_H
#define __MONKEY_DEV_H__ #define __APPS_TESTING_MONKEY_MONKEY_DEV_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -94,4 +94,4 @@ int monkey_dev_get_available(FAR struct monkey_dev_s *devs[], int dev_num);
} }
#endif #endif
#endif /* __MONKEY_DEV_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_DEV_H */

View File

@ -56,7 +56,8 @@ void monkey_log_printf(enum monkey_log_level_type_e level,
struct va_format vaf; struct va_format vaf;
va_list ap; va_list ap;
static const int priority[_MONKEY_LOG_LEVEL_LAST] = { static const int priority[_MONKEY_LOG_LEVEL_LAST] =
{
LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR
}; };

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_LOG_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_LOG_H
#define __MONKEY_LOG_H__ #define __APPS_TESTING_MONKEY_MONKEY_LOG_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -114,4 +114,4 @@ enum monkey_log_level_type_e monkey_log_get_level(void);
} }
#endif #endif
#endif /* __MONKEY_LOG_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_LOG_H */

View File

@ -43,7 +43,7 @@
do \ do \
{ \ { \
FAR char *ptr; \ FAR char *ptr; \
value = (type)strtoul(optarg, &ptr, base); \ (value) = (type)strtoul(optarg, &ptr, (base)); \
if (*ptr != '\0') \ if (*ptr != '\0') \
{ \ { \
printf(MONKEY_PREFIX "Parameter error: -%c %s\n", ch, optarg); \ printf(MONKEY_PREFIX "Parameter error: -%c %s\n", ch, optarg); \
@ -208,9 +208,11 @@ static void parse_commandline(int argc, FAR char **argv,
case 't': case 't':
OPTARG_TO_VALUE(param->dev_type_mask, int, 16); OPTARG_TO_VALUE(param->dev_type_mask, int, 16);
break; break;
case 'f': case 'f':
param->file_path = optarg; param->file_path = optarg;
break; break;
case 'p': case 'p':
converted = sscanf(optarg, "%d-%d", &period_min, &period_max); converted = sscanf(optarg, "%d-%d", &period_min, &period_max);
if (converted == 2 && period_min >= 0 && period_max >= 0) if (converted == 2 && period_min >= 0 && period_max >= 0)
@ -224,6 +226,7 @@ static void parse_commandline(int argc, FAR char **argv,
show_usage(argv[0], EXIT_FAILURE); show_usage(argv[0], EXIT_FAILURE);
} }
break; break;
case 's': case 's':
converted = sscanf(optarg, "%dx%d", &hor_res, &ver_res); converted = sscanf(optarg, "%dx%d", &hor_res, &ver_res);
if (converted == 2 && hor_res > 0 && ver_res > 0) if (converted == 2 && hor_res > 0 && ver_res > 0)
@ -238,6 +241,7 @@ static void parse_commandline(int argc, FAR char **argv,
show_usage(argv[0], EXIT_FAILURE); show_usage(argv[0], EXIT_FAILURE);
} }
break; break;
case '?': case '?':
printf(MONKEY_PREFIX ": Unknown option: %c\n", optopt); printf(MONKEY_PREFIX ": Unknown option: %c\n", optopt);
show_usage(argv[0], EXIT_FAILURE); show_usage(argv[0], EXIT_FAILURE);

View File

@ -135,9 +135,8 @@ FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path,
MONKEY_ASSERT_NULL(path); MONKEY_ASSERT_NULL(path);
recorder = malloc(sizeof(struct monkey_recorder_s)); recorder = calloc(1, sizeof(struct monkey_recorder_s));
MONKEY_ASSERT_NULL(recorder); MONKEY_ASSERT_NULL(recorder);
memset(recorder, 0, sizeof(struct monkey_recorder_s));
if (mode == MONKEY_RECORDER_MODE_RECORD) if (mode == MONKEY_RECORDER_MODE_RECORD)
{ {
@ -198,7 +197,6 @@ void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder)
{ {
MONKEY_LOG_NOTICE("close fd: %d", recorder->fd); MONKEY_LOG_NOTICE("close fd: %d", recorder->fd);
close(recorder->fd); close(recorder->fd);
recorder->fd = -1;
} }
free(recorder); free(recorder);
@ -232,12 +230,14 @@ enum monkey_recorder_res_e monkey_recorder_write(
state->data.touch.y, state->data.touch.y,
state->data.touch.is_pressed); state->data.touch.is_pressed);
break; break;
case MONKEY_DEV_TYPE_BUTTON: case MONKEY_DEV_TYPE_BUTTON:
len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT, len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT,
cur_tick, cur_tick,
state->type, state->type,
state->data.button.value); state->data.button.value);
break; break;
default: default:
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR; return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
} }
@ -313,6 +313,7 @@ enum monkey_recorder_res_e monkey_recorder_read(
return MONKEY_RECORDER_RES_PARSER_ERROR; return MONKEY_RECORDER_RES_PARSER_ERROR;
} }
break; break;
case MONKEY_DEV_TYPE_BUTTON: case MONKEY_DEV_TYPE_BUTTON:
converted = sscanf(buffer, converted = sscanf(buffer,
MONKEY_REC_BTN_FMT, MONKEY_REC_BTN_FMT,
@ -324,6 +325,7 @@ enum monkey_recorder_res_e monkey_recorder_read(
return MONKEY_RECORDER_RES_PARSER_ERROR; return MONKEY_RECORDER_RES_PARSER_ERROR;
} }
break; break;
default: default:
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR; return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
} }

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_RECORDER_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_RECORDER_H
#define __MONKEY_RECORDER_H__ #define __APPS_TESTING_MONKEY_MONKEY_RECORDER_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -107,4 +107,4 @@ enum monkey_recorder_res_e monkey_recorder_reset(
} }
#endif #endif
#endif /* __MONKEY_RECORDER_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_RECORDER_H */

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_TYPE_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_TYPE_H
#define __MONKEY_TYPE_H__ #define __APPS_TESTING_MONKEY_MONKEY_TYPE_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -34,7 +34,7 @@
#define MONKEY_UINPUT_TYPE_MASK (0x10) #define MONKEY_UINPUT_TYPE_MASK (0x10)
#define MONKEY_IS_UINPUT_TYPE(type) (!!((type) & MONKEY_UINPUT_TYPE_MASK)) #define MONKEY_IS_UINPUT_TYPE(type) (!!((type) & MONKEY_UINPUT_TYPE_MASK))
#define MONKEY_GET_DEV_TYPE(type) (type & ~MONKEY_UINPUT_TYPE_MASK) #define MONKEY_GET_DEV_TYPE(type) ((type) & ~MONKEY_UINPUT_TYPE_MASK)
#define MONKEY_DEV_MAX_NUM 2 #define MONKEY_DEV_MAX_NUM 2
/**************************************************************************** /****************************************************************************
@ -115,4 +115,4 @@ struct monkey_s
} playback_ctx; } playback_ctx;
}; };
#endif /* __MONKEY_TYPE_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_TYPE_H */

View File

@ -18,8 +18,8 @@
* *
****************************************************************************/ ****************************************************************************/
#ifndef __MONKEY_UTILS_H__ #ifndef __APPS_TESTING_MONKEY_MONKEY_UTILS_H
#define __MONKEY_UTILS_H__ #define __APPS_TESTING_MONKEY_MONKEY_UTILS_H
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
@ -91,4 +91,4 @@ enum monkey_dev_type_e monkey_dev_name2type(FAR const char *name);
} }
#endif #endif
#endif /* __MONKEY_UTILS_H__ */ #endif /* __APPS_TESTING_MONKEY_MONKEY_UTILS_H */