diff --git a/testing/monkey/monkey.c b/testing/monkey/monkey.c index 855e8be6c..e725c69ec 100644 --- a/testing/monkey/monkey.c +++ b/testing/monkey/monkey.c @@ -39,7 +39,7 @@ #define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type) \ 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; \ dev = monkey_dev_create(CONFIG_TESTING_MONKEY_DEV_PATH_##type, \ @@ -48,8 +48,8 @@ do { \ { \ goto failed; \ } \ - monkey->devs[monkey->dev_num] = dev; \ - monkey->dev_num++; \ + (monkey)->devs[(monkey)->dev_num] = dev; \ + (monkey)->dev_num++; \ } \ } while (0) @@ -63,9 +63,8 @@ do { \ 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); - memset(monkey, 0, sizeof(struct monkey_s)); if (MONKEY_IS_UINPUT_TYPE(dev_type_mask)) { @@ -106,7 +105,7 @@ void monkey_delete(FAR struct monkey_s *monkey) for (i = 0; i < monkey->dev_num; i++) { - monkey_dev_delete(monkey->devs[i]); + monkey_dev_delete(monkey->devs[i]); } if (monkey->recorder) diff --git a/testing/monkey/monkey.h b/testing/monkey/monkey.h index 9e8238034..39139f19a 100644 --- a/testing/monkey/monkey.h +++ b/testing/monkey/monkey.h @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __MONKEY_H__ -#define __MONKEY_H__ +#ifndef __APPS_TESTING_MONKEY_MONKEY_H +#define __APPS_TESTING_MONKEY_MONKEY_H /**************************************************************************** * Included Files @@ -95,4 +95,4 @@ bool monkey_set_recorder_path(FAR struct monkey_s *monkey, } #endif -#endif /* __MONKEY_H__ */ +#endif /* __APPS_TESTING_MONKEY_MONKEY_H */ diff --git a/testing/monkey/monkey_assert.h b/testing/monkey/monkey_assert.h index 3ade09527..50e5ae4b9 100644 --- a/testing/monkey/monkey_assert.h +++ b/testing/monkey/monkey_assert.h @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __MONKEY_ASSERT_H__ -#define __MONKEY_ASSERT_H__ +#ifndef __APPS_TESTING_MONKEY_MONKEY_ASSERT_H +#define __APPS_TESTING_MONKEY_MONKEY_ASSERT_H /**************************************************************************** * Included Files @@ -34,4 +34,4 @@ #define MONKEY_ASSERT(expr) DEBUGASSERT(expr) #define MONKEY_ASSERT_NULL(ptr) MONKEY_ASSERT(ptr != NULL) -#endif /* __MONKEY_ASSERT_H__ */ +#endif /* __APPS_TESTING_MONKEY_MONKEY_ASSERT_H */ diff --git a/testing/monkey/monkey_dev.c b/testing/monkey/monkey_dev.c index 11409741b..d87780406 100644 --- a/testing/monkey/monkey_dev.c +++ b/testing/monkey/monkey_dev.c @@ -134,6 +134,10 @@ static bool button_read(int fd, FAR uint32_t *value) return true; } +/**************************************************************************** + * Public Functions + ****************************************************************************/ + /**************************************************************************** * 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); - dev = malloc(sizeof(struct monkey_dev_s)); + dev = calloc(1, sizeof(struct monkey_dev_s)); MONKEY_ASSERT_NULL(dev); - memset(dev, 0, sizeof(struct monkey_dev_s)); if (MONKEY_IS_UINPUT_TYPE(type)) { @@ -189,10 +192,6 @@ failed: return NULL; } -/**************************************************************************** - * Public Functions - ****************************************************************************/ - /**************************************************************************** * 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); close(dev->fd); - dev->fd = -1; } free(dev); @@ -223,25 +221,25 @@ void monkey_dev_delete(FAR struct monkey_dev_s *dev) ****************************************************************************/ void monkey_dev_set_state(FAR struct monkey_dev_s *dev, - FAR const struct monkey_dev_state_s *state) + FAR const struct monkey_dev_state_s *state) { MONKEY_ASSERT_NULL(dev); switch (MONKEY_GET_DEV_TYPE(dev->type)) { - case MONKEY_DEV_TYPE_TOUCH: - utouch_write(dev->fd, - state->data.touch.x, - state->data.touch.y, - state->data.touch.is_pressed); - break; + case MONKEY_DEV_TYPE_TOUCH: + utouch_write(dev->fd, + state->data.touch.x, + state->data.touch.y, + state->data.touch.is_pressed); + break; - case MONKEY_DEV_TYPE_BUTTON: - ubutton_write(dev->fd, state->data.button.value); - break; + case MONKEY_DEV_TYPE_BUTTON: + ubutton_write(dev->fd, state->data.button.value); + break; - default: - break; + default: + break; } } @@ -261,19 +259,19 @@ bool monkey_dev_get_state(FAR struct monkey_dev_s *dev, switch (dev->type) { - case MONKEY_DEV_TYPE_TOUCH: - retval = touch_read(dev->fd, - &state->data.touch.x, - &state->data.touch.y, - &state->data.touch.is_pressed); - break; + case MONKEY_DEV_TYPE_TOUCH: + retval = touch_read(dev->fd, + &state->data.touch.x, + &state->data.touch.y, + &state->data.touch.is_pressed); + break; - case MONKEY_DEV_TYPE_BUTTON: - retval = button_read(dev->fd, &state->data.button.value); - break; + case MONKEY_DEV_TYPE_BUTTON: + retval = button_read(dev->fd, &state->data.button.value); + break; - default: - break; + default: + break; } return retval; diff --git a/testing/monkey/monkey_dev.h b/testing/monkey/monkey_dev.h index 61de011b7..87c1c80dd 100644 --- a/testing/monkey/monkey_dev.h +++ b/testing/monkey/monkey_dev.h @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __MONKEY_DEV_H__ -#define __MONKEY_DEV_H__ +#ifndef __APPS_TESTING_MONKEY_MONKEY_DEV_H +#define __APPS_TESTING_MONKEY_MONKEY_DEV_H /**************************************************************************** * Included Files @@ -94,4 +94,4 @@ int monkey_dev_get_available(FAR struct monkey_dev_s *devs[], int dev_num); } #endif -#endif /* __MONKEY_DEV_H__ */ +#endif /* __APPS_TESTING_MONKEY_MONKEY_DEV_H */ diff --git a/testing/monkey/monkey_log.c b/testing/monkey/monkey_log.c index 373571cc9..01ae013bb 100644 --- a/testing/monkey/monkey_log.c +++ b/testing/monkey/monkey_log.c @@ -56,9 +56,10 @@ void monkey_log_printf(enum monkey_log_level_type_e level, struct va_format vaf; va_list ap; - static const int priority[_MONKEY_LOG_LEVEL_LAST] = { - LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR - }; + static const int priority[_MONKEY_LOG_LEVEL_LAST] = + { + LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR + }; if (level < g_log_level) { diff --git a/testing/monkey/monkey_log.h b/testing/monkey/monkey_log.h index 0a6a4d7d7..dbe7cf6d5 100644 --- a/testing/monkey/monkey_log.h +++ b/testing/monkey/monkey_log.h @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __MONKEY_LOG_H__ -#define __MONKEY_LOG_H__ +#ifndef __APPS_TESTING_MONKEY_MONKEY_LOG_H +#define __APPS_TESTING_MONKEY_MONKEY_LOG_H /**************************************************************************** * Included Files @@ -114,4 +114,4 @@ enum monkey_log_level_type_e monkey_log_get_level(void); } #endif -#endif /* __MONKEY_LOG_H__ */ +#endif /* __APPS_TESTING_MONKEY_MONKEY_LOG_H */ diff --git a/testing/monkey/monkey_main.c b/testing/monkey/monkey_main.c index 6b7bed939..1004e2b5c 100644 --- a/testing/monkey/monkey_main.c +++ b/testing/monkey/monkey_main.c @@ -43,7 +43,7 @@ do \ { \ FAR char *ptr; \ - value = (type)strtoul(optarg, &ptr, base); \ + (value) = (type)strtoul(optarg, &ptr, (base)); \ if (*ptr != '\0') \ { \ 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': OPTARG_TO_VALUE(param->dev_type_mask, int, 16); break; + case 'f': param->file_path = optarg; break; + case 'p': converted = sscanf(optarg, "%d-%d", &period_min, &period_max); 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); } break; + case 's': converted = sscanf(optarg, "%dx%d", &hor_res, &ver_res); 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); } break; + case '?': printf(MONKEY_PREFIX ": Unknown option: %c\n", optopt); show_usage(argv[0], EXIT_FAILURE); diff --git a/testing/monkey/monkey_recorder.c b/testing/monkey/monkey_recorder.c index ad0ca4d4a..228988204 100644 --- a/testing/monkey/monkey_recorder.c +++ b/testing/monkey/monkey_recorder.c @@ -135,9 +135,8 @@ FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path, MONKEY_ASSERT_NULL(path); - recorder = malloc(sizeof(struct monkey_recorder_s)); + recorder = calloc(1, sizeof(struct monkey_recorder_s)); MONKEY_ASSERT_NULL(recorder); - memset(recorder, 0, sizeof(struct monkey_recorder_s)); 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); close(recorder->fd); - recorder->fd = -1; } free(recorder); @@ -223,24 +221,26 @@ enum monkey_recorder_res_e monkey_recorder_write( cur_tick = monkey_tick_get(); switch (MONKEY_GET_DEV_TYPE(state->type)) - { - case MONKEY_DEV_TYPE_TOUCH: - len = snprintf(buffer, sizeof(buffer), MONKEY_REC_TOUCH_FMT, - cur_tick, - state->type, - state->data.touch.x, - state->data.touch.y, - state->data.touch.is_pressed); - break; - case MONKEY_DEV_TYPE_BUTTON: - len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT, - cur_tick, - state->type, - state->data.button.value); - break; - default: - return MONKEY_RECORDER_RES_DEV_TYPE_ERROR; - } + { + case MONKEY_DEV_TYPE_TOUCH: + len = snprintf(buffer, sizeof(buffer), MONKEY_REC_TOUCH_FMT, + cur_tick, + state->type, + state->data.touch.x, + state->data.touch.y, + state->data.touch.is_pressed); + break; + + case MONKEY_DEV_TYPE_BUTTON: + len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT, + cur_tick, + state->type, + state->data.button.value); + break; + + default: + return MONKEY_RECORDER_RES_DEV_TYPE_ERROR; + } if (len <= 0) { @@ -300,32 +300,34 @@ enum monkey_recorder_res_e monkey_recorder_read( switch (MONKEY_GET_DEV_TYPE(state->type)) { - case MONKEY_DEV_TYPE_TOUCH: - converted = sscanf(buffer, - MONKEY_REC_TOUCH_FMT, - time_stamp, - &dev_type, - &state->data.touch.x, - &state->data.touch.y, - &state->data.touch.is_pressed); - if (converted != 5) - { - return MONKEY_RECORDER_RES_PARSER_ERROR; - } - break; - case MONKEY_DEV_TYPE_BUTTON: - converted = sscanf(buffer, - MONKEY_REC_BTN_FMT, - time_stamp, - &dev_type, - &state->data.button.value); - if (converted != 3) - { - return MONKEY_RECORDER_RES_PARSER_ERROR; - } - break; - default: - return MONKEY_RECORDER_RES_DEV_TYPE_ERROR; + case MONKEY_DEV_TYPE_TOUCH: + converted = sscanf(buffer, + MONKEY_REC_TOUCH_FMT, + time_stamp, + &dev_type, + &state->data.touch.x, + &state->data.touch.y, + &state->data.touch.is_pressed); + if (converted != 5) + { + return MONKEY_RECORDER_RES_PARSER_ERROR; + } + break; + + case MONKEY_DEV_TYPE_BUTTON: + converted = sscanf(buffer, + MONKEY_REC_BTN_FMT, + time_stamp, + &dev_type, + &state->data.button.value); + if (converted != 3) + { + return MONKEY_RECORDER_RES_PARSER_ERROR; + } + break; + + default: + return MONKEY_RECORDER_RES_DEV_TYPE_ERROR; } return MONKEY_RECORDER_RES_OK; diff --git a/testing/monkey/monkey_recorder.h b/testing/monkey/monkey_recorder.h index 075882084..0d69bd193 100644 --- a/testing/monkey/monkey_recorder.h +++ b/testing/monkey/monkey_recorder.h @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __MONKEY_RECORDER_H__ -#define __MONKEY_RECORDER_H__ +#ifndef __APPS_TESTING_MONKEY_MONKEY_RECORDER_H +#define __APPS_TESTING_MONKEY_MONKEY_RECORDER_H /**************************************************************************** * Included Files @@ -107,4 +107,4 @@ enum monkey_recorder_res_e monkey_recorder_reset( } #endif -#endif /* __MONKEY_RECORDER_H__ */ +#endif /* __APPS_TESTING_MONKEY_MONKEY_RECORDER_H */ diff --git a/testing/monkey/monkey_type.h b/testing/monkey/monkey_type.h index 16930675b..5708836cb 100644 --- a/testing/monkey/monkey_type.h +++ b/testing/monkey/monkey_type.h @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __MONKEY_TYPE_H__ -#define __MONKEY_TYPE_H__ +#ifndef __APPS_TESTING_MONKEY_MONKEY_TYPE_H +#define __APPS_TESTING_MONKEY_MONKEY_TYPE_H /**************************************************************************** * Included Files @@ -34,7 +34,7 @@ #define MONKEY_UINPUT_TYPE_MASK (0x10) #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 /**************************************************************************** @@ -110,9 +110,9 @@ struct monkey_s FAR struct monkey_recorder_s *recorder; struct { - struct monkey_dev_state_s state; - uint32_t time_stamp; + struct monkey_dev_state_s state; + uint32_t time_stamp; } playback_ctx; }; -#endif /* __MONKEY_TYPE_H__ */ +#endif /* __APPS_TESTING_MONKEY_MONKEY_TYPE_H */ diff --git a/testing/monkey/monkey_utils.h b/testing/monkey/monkey_utils.h index 6711dc0e1..487665f21 100644 --- a/testing/monkey/monkey_utils.h +++ b/testing/monkey/monkey_utils.h @@ -18,8 +18,8 @@ * ****************************************************************************/ -#ifndef __MONKEY_UTILS_H__ -#define __MONKEY_UTILS_H__ +#ifndef __APPS_TESTING_MONKEY_MONKEY_UTILS_H +#define __APPS_TESTING_MONKEY_MONKEY_UTILS_H /**************************************************************************** * Included Files @@ -91,4 +91,4 @@ enum monkey_dev_type_e monkey_dev_name2type(FAR const char *name); } #endif -#endif /* __MONKEY_UTILS_H__ */ +#endif /* __APPS_TESTING_MONKEY_MONKEY_UTILS_H */