You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/08/15 16:55:45 UTC

[GitHub] [incubator-nuttx-apps] FASTSHIFT opened a new pull request, #1273: testing: add monkey test

FASTSHIFT opened a new pull request, #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273

   ## Summary
   A UI stress test program based on uinput.
   The currently implemented functions are:
   1. Support random click and swipe
   2. Support recording user operations and playback
   3. Support multiple instances, you can start multiple monkey processes to run independently at the same time
   4. Support simultaneous monitoring and operation of multiple devices
   
   ## Impact
   Add new features.
   
   ## Testing
   daily test.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] pkarashchenko commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946992895


##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,325 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)

Review Comment:
   ```suggestion
     if (ret != sizeof(buttonset))
   ```



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,325 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = calloc(1, sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+    }
+
+  free(dev);
+}
+
+/****************************************************************************
+ * Name: monkey_dev_set_state
+ ****************************************************************************/
+
+void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
+                          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_BUTTON:
+        ubutton_write(dev->fd, state->data.button.value);
+        break;
+
+      default:
+        break;
+    }
+}
+
+/****************************************************************************
+ * Name: monkey_dev_get_state
+ ****************************************************************************/
+
+bool monkey_dev_get_state(FAR struct monkey_dev_s *dev,
+                          FAR struct monkey_dev_state_s *state)
+{
+  bool retval;
+  MONKEY_ASSERT_NULL(dev);
+
+  retval = false;
+
+  state->type = dev->type;
+
+  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_BUTTON:
+        retval = button_read(dev->fd, &state->data.button.value);
+        break;
+
+      default:
+        break;
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_get_state
+ ****************************************************************************/
+
+enum monkey_dev_type_e monkey_dev_get_type(
+                       FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+  return dev->type;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_get_available
+ ****************************************************************************/
+
+int monkey_dev_get_available(FAR struct monkey_dev_s *devs[], int dev_num)
+{
+  int i;
+  int available = 0;
+  struct pollfd fds[MONKEY_DEV_MAX_NUM];

Review Comment:
   Do we need `memset(&fds, 0, sizeof(fds));`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946974453


##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+      dev->fd = -1;
+    }
+
+  free(dev);
+}
+
+/****************************************************************************
+ * Name: monkey_dev_set_state
+ ****************************************************************************/
+
+void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
+                           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_BUTTON:
+      ubutton_write(dev->fd, state->data.button.value);
+      break;
+
+    default:
+      break;
+    }
+}
+
+/****************************************************************************
+ * Name: monkey_dev_get_state
+ ****************************************************************************/
+
+bool monkey_dev_get_state(FAR struct monkey_dev_s *dev,
+                          FAR struct monkey_dev_state_s *state)
+{
+  bool retval;
+  MONKEY_ASSERT_NULL(dev);
+
+  retval = false;
+
+  state->type = dev->type;
+
+  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_BUTTON:
+      retval = button_read(dev->fd, &state->data.button.value);
+      break;
+
+    default:
+      break;
+    }

Review Comment:
   done



##########
testing/monkey/monkey_dev.h:
##########
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_DEV_H__
+#define __MONKEY_DEV_H__

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] pkarashchenko commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946547813


##########
testing/monkey/monkey.c:
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "monkey.h"
+#include "monkey_recorder.h"
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type)                  \
+do {                                                                      \
+  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,      \
+                              MONKEY_DEV_TYPE_##type);                    \
+      if (!dev)                                                           \
+        {                                                                 \
+          goto failed;                                                    \
+        }                                                                 \
+      monkey->devs[monkey->dev_num] = dev;                                \
+      monkey->dev_num++;                                                  \

Review Comment:
   ```suggestion
         (monkey)->devs[(monkey)->dev_num] = dev;                            \
         (monkey)->dev_num++;                                                \
   ```



##########
testing/monkey/monkey.c:
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "monkey.h"
+#include "monkey_recorder.h"
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type)                  \
+do {                                                                      \
+  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,      \
+                              MONKEY_DEV_TYPE_##type);                    \
+      if (!dev)                                                           \
+        {                                                                 \
+          goto failed;                                                    \
+        }                                                                 \
+      monkey->devs[monkey->dev_num] = dev;                                \
+      monkey->dev_num++;                                                  \
+    }                                                                     \
+} while (0)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_create
+ ****************************************************************************/
+
+FAR struct monkey_s *monkey_create(int dev_type_mask)
+{
+  FAR struct monkey_s *monkey = malloc(sizeof(struct monkey_s));
+  MONKEY_ASSERT_NULL(monkey);
+  memset(monkey, 0, sizeof(struct monkey_s));

Review Comment:
   Optional: `zalloc` or `calloc` can used to remove `memset`



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));

Review Comment:
   Optional: `zalloc` or `calloc`



##########
testing/monkey/monkey.c:
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "monkey.h"
+#include "monkey_recorder.h"
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type)                  \
+do {                                                                      \
+  if ((type_mask & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type)     \

Review Comment:
   ```suggestion
     if (((type_mask) & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type)   \
   ```



##########
testing/monkey/monkey_assert.h:
##########
@@ -0,0 +1,37 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_assert.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_ASSERT_H__
+#define __MONKEY_ASSERT_H__

Review Comment:
   Please include path part



##########
testing/monkey/monkey.c:
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "monkey.h"
+#include "monkey_recorder.h"
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type)                  \
+do {                                                                      \
+  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,      \
+                              MONKEY_DEV_TYPE_##type);                    \
+      if (!dev)                                                           \
+        {                                                                 \
+          goto failed;                                                    \
+        }                                                                 \
+      monkey->devs[monkey->dev_num] = dev;                                \
+      monkey->dev_num++;                                                  \
+    }                                                                     \
+} while (0)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_create
+ ****************************************************************************/
+
+FAR struct monkey_s *monkey_create(int dev_type_mask)
+{
+  FAR struct monkey_s *monkey = malloc(sizeof(struct monkey_s));
+  MONKEY_ASSERT_NULL(monkey);
+  memset(monkey, 0, sizeof(struct monkey_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(dev_type_mask))
+    {
+      MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, UTOUCH);
+      MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, UBUTTON);
+    }
+  else
+    {
+      MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, TOUCH);
+      MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, BUTTON);
+    }
+
+  if (monkey->dev_num == 0)
+    {
+      MONKEY_LOG_ERROR("NO enabled device detected");
+      goto failed;
+    }
+
+  MONKEY_ASSERT(monkey->dev_num <= MONKEY_DEV_MAX_NUM);
+
+  MONKEY_LOG_NOTICE("OK");
+
+  return monkey;
+
+failed:
+  monkey_delete(monkey);
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: monkey_delete
+ ****************************************************************************/
+
+void monkey_delete(FAR struct monkey_s *monkey)
+{
+  int i;
+  MONKEY_ASSERT_NULL(monkey);
+
+  for (i = 0; i < monkey->dev_num; i++)
+    {
+        monkey_dev_delete(monkey->devs[i]);

Review Comment:
   ```suggestion
         monkey_dev_delete(monkey->devs[i]);
   ```



##########
testing/monkey/monkey.h:
##########
@@ -0,0 +1,98 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_H__
+#define __MONKEY_H__

Review Comment:
   please include path part



##########
testing/monkey/monkey_log.h:
##########
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_log.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_LOG_H__
+#define __MONKEY_LOG_H__

Review Comment:
   ditto



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+      dev->fd = -1;

Review Comment:
   not needed since is followed by `free` unconditionally



##########
testing/monkey/monkey_log.c:
##########
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_log.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <syslog.h>
+#include "monkey_log.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_TESTING_MONKEY_LOG_ENABLE
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static enum monkey_log_level_type_e g_log_level =
+                               CONFIG_TESTING_MONKEY_LOG_LEVEL_DEFAULT;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_log_printf
+ ****************************************************************************/
+
+void monkey_log_printf(enum monkey_log_level_type_e level,
+                       FAR const char *func,
+                       FAR const char *fmt,
+                       ...)
+{
+  struct va_format vaf;
+  va_list ap;
+
+  static const int priority[_MONKEY_LOG_LEVEL_LAST] = {
+    LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR
+  };

Review Comment:
   ```suggestion
     static const int priority[_MONKEY_LOG_LEVEL_LAST] =
       {
         LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR
       };
   ```



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+      dev->fd = -1;
+    }
+
+  free(dev);
+}
+
+/****************************************************************************
+ * Name: monkey_dev_set_state
+ ****************************************************************************/
+
+void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
+                           FAR const struct monkey_dev_state_s *state)

Review Comment:
   ```suggestion
                             FAR const struct monkey_dev_state_s *state)
   ```



##########
testing/monkey/monkey_dev.h:
##########
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_DEV_H__
+#define __MONKEY_DEV_H__

Review Comment:
   ditto



##########
testing/monkey/monkey_recorder.c:
##########
@@ -0,0 +1,344 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_recorder.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_recorder.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_REC_HEAD_FMT  "T%" PRIu32 ",D%X,"
+#define MONKEY_REC_TOUCH_FMT MONKEY_REC_HEAD_FMT "X%d,Y%d,PR%d\n"
+#define MONKEY_REC_BTN_FMT   MONKEY_REC_HEAD_FMT "V%" PRIu32 "\n"
+#define MONKEY_REC_FILE_EXT  ".csv"
+#define MONKEY_REC_FILE_HEAD "rec_"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_recorder_gen_file_path
+ ****************************************************************************/
+
+static void monkey_recorder_gen_file_path(FAR char *path_buf,
+                                          size_t buf_size,
+                                          FAR const char *dir_path)
+{
+  char localtime_str_buf[64];
+
+  monkey_get_localtime_str(localtime_str_buf, sizeof(localtime_str_buf));
+
+  snprintf(path_buf, buf_size,
+           "%s/" MONKEY_REC_FILE_HEAD "%s" MONKEY_REC_FILE_EXT,
+           dir_path,
+           localtime_str_buf);
+}
+
+/****************************************************************************
+ * Name: monkey_readline
+ ****************************************************************************/
+
+static int monkey_readline(int fd, FAR char *ptr, int maxlen)
+{
+  int n;
+  int rc;
+  char c;
+  for (n = 1; n < maxlen; n++)
+    {
+      if ((rc = read(fd, &c, 1)) == 1)
+        {
+          *ptr++ = c;
+          if (c == '\n')
+            {
+              break;
+            }
+        }
+      else if (rc == 0)
+        {
+          if (n == 1)
+            {
+              /* EOF no data read */
+
+              return 0;
+            }
+          else
+            {
+              /* EOF, some data read */
+
+              break;
+            }
+        }
+      else
+        {
+          /* error */
+
+          return -1;
+        }
+    }
+
+  *ptr = 0;
+  return n;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_recorder_create
+ ****************************************************************************/
+
+FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path,
+                                            enum monkey_recorder_mode_e mode)
+{
+  char file_path[PATH_MAX];
+  FAR const char *path_ptr;
+  int oflag;
+  int fd;
+  FAR struct monkey_recorder_s *recorder;
+
+  MONKEY_ASSERT_NULL(path);
+
+  recorder = malloc(sizeof(struct monkey_recorder_s));
+  MONKEY_ASSERT_NULL(recorder);
+  memset(recorder, 0, sizeof(struct monkey_recorder_s));
+
+  if (mode == MONKEY_RECORDER_MODE_RECORD)
+    {
+      if (!monkey_dir_check(path))
+        {
+          goto failed;
+        }
+
+      monkey_recorder_gen_file_path(file_path,
+                                    sizeof(file_path),
+                                    path);
+      path_ptr = file_path;
+      oflag = O_WRONLY | O_CREAT;
+    }
+  else
+    {
+      path_ptr = path;
+      oflag = O_RDONLY;
+    }
+
+  fd = open(path_ptr, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", path_ptr, errno);
+      goto failed;
+    }
+
+  recorder->fd = fd;
+  recorder->mode = mode;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, mode = %d",
+                    path_ptr, fd, mode);
+
+  return recorder;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (recorder)
+    {
+      free(recorder);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: monkey_recorder_delete
+ ****************************************************************************/
+
+void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder)
+{
+  MONKEY_ASSERT_NULL(recorder);
+  if (recorder->fd > 0)
+    {
+      MONKEY_LOG_NOTICE("close fd: %d", recorder->fd);
+      close(recorder->fd);
+      recorder->fd = -1;
+    }
+
+  free(recorder);
+}
+
+/****************************************************************************
+ * Name: monkey_recorder_write
+ ****************************************************************************/
+
+enum monkey_recorder_res_e monkey_recorder_write(
+                                  FAR struct monkey_recorder_s *recorder,
+                                  FAR const struct monkey_dev_state_s *state)
+{
+  char buffer[128];
+  int len = -1;
+  int ret;
+  uint32_t cur_tick;
+
+  MONKEY_ASSERT_NULL(recorder);
+  MONKEY_ASSERT(recorder->mode == MONKEY_RECORDER_MODE_RECORD);
+
+  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;
+  }
+
+  if (len <= 0)
+    {
+      return MONKEY_RECORDER_RES_PARSER_ERROR;
+    }
+
+  ret = write(recorder->fd, buffer, len);
+  if (ret < 0)
+    {
+      return MONKEY_RECORDER_RES_WRITE_ERROR;
+    }
+
+  return MONKEY_RECORDER_RES_OK;
+}
+
+/****************************************************************************
+ * Name: monkey_recorder_read
+ ****************************************************************************/
+
+enum monkey_recorder_res_e monkey_recorder_read(
+                                      FAR struct monkey_recorder_s *recorder,
+                                      FAR struct monkey_dev_state_s *state,
+                                      FAR uint32_t *time_stamp)
+{
+  char buffer[128];
+  int dev_type;
+  int converted;
+  int ret;
+
+  MONKEY_ASSERT_NULL(recorder);
+  MONKEY_ASSERT(recorder->mode == MONKEY_RECORDER_MODE_PLAYBACK);
+
+  ret = monkey_readline(recorder->fd, buffer, sizeof(buffer));
+
+  if (ret < 0)
+    {
+      return MONKEY_RECORDER_RES_READ_ERROR;
+    }
+
+  if (ret == 0)
+    {
+      return MONKEY_RECORDER_RES_END_OF_FILE;
+    }
+
+  /* Read head to get device type */
+
+  converted = sscanf(buffer, MONKEY_REC_HEAD_FMT, time_stamp, &dev_type);
+
+  if (converted != 2)
+    {
+      return MONKEY_RECORDER_RES_PARSER_ERROR;
+    }
+
+  state->type = dev_type;
+
+  /* Get data */
+
+  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,

Review Comment:
   2 more spaces for case block



##########
testing/monkey/monkey_type.h:
##########
@@ -0,0 +1,118 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_type.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_TYPE_H__
+#define __MONKEY_TYPE_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#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)

Review Comment:
   ```suggestion
   #define MONKEY_GET_DEV_TYPE(type)   ((type) & ~MONKEY_UINPUT_TYPE_MASK)
   ```



##########
testing/monkey/monkey_type.h:
##########
@@ -0,0 +1,118 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_type.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_TYPE_H__
+#define __MONKEY_TYPE_H__

Review Comment:
   ditto



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/

Review Comment:
   `monkey_dev_create` also seems to be `Public`



##########
testing/monkey/monkey_type.h:
##########
@@ -0,0 +1,118 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_type.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_TYPE_H__
+#define __MONKEY_TYPE_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#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_DEV_MAX_NUM          2
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct monkey_dev_s;
+struct monkey_recorder_s;
+
+enum monkey_screen_type_e
+{
+  MONKEY_SCREEN_TYPE_RECT,
+  MONKEY_SCREEN_TYPE_ROUND
+};
+
+enum monkey_mode_e
+{
+  MONKEY_MODE_RANDOM,
+  MONKEY_MODE_RECORD,
+  MONKEY_MODE_PLAYBACK,
+};
+
+enum monkey_dev_type_e
+{
+  MONKEY_DEV_TYPE_UNKNOW  = 0x00,
+  MONKEY_DEV_TYPE_TOUCH   = 0x01,
+  MONKEY_DEV_TYPE_BUTTON  = 0x02,
+  MONKEY_DEV_TYPE_UTOUCH  = MONKEY_UINPUT_TYPE_MASK | MONKEY_DEV_TYPE_TOUCH,
+  MONKEY_DEV_TYPE_UBUTTON = MONKEY_UINPUT_TYPE_MASK | MONKEY_DEV_TYPE_BUTTON,
+};
+
+struct monkey_dev_state_s
+{
+  enum monkey_dev_type_e type;
+  union
+  {
+    struct
+    {
+      int x;
+      int y;
+      int is_pressed;
+    } touch;
+
+    struct
+    {
+      uint32_t value;
+    } button;
+  } data;
+};
+
+struct monkey_config_s
+{
+  struct
+  {
+    enum monkey_screen_type_e type;
+    int hor_res;
+    int ver_res;
+  } screen;
+
+  struct
+  {
+    uint32_t min;
+    uint32_t max;
+  } period;
+};
+
+struct monkey_s
+{
+  struct monkey_config_s config;
+  enum monkey_mode_e mode;
+  FAR struct monkey_dev_s *devs[MONKEY_DEV_MAX_NUM];
+  int dev_num;
+  FAR struct monkey_recorder_s *recorder;
+  struct
+  {
+      struct monkey_dev_state_s state;
+      uint32_t time_stamp;

Review Comment:
   ```suggestion
       struct monkey_dev_state_s state;
       uint32_t time_stamp;
   ```



##########
testing/monkey/monkey_utils.h:
##########
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_utils.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_UTILS_H__
+#define __MONKEY_UTILS_H__

Review Comment:
   ditto



##########
testing/monkey/monkey_recorder.h:
##########
@@ -0,0 +1,110 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_recorder.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_RECORDER_H__
+#define __MONKEY_RECORDER_H__

Review Comment:
   ditto



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+      dev->fd = -1;
+    }
+
+  free(dev);
+}
+
+/****************************************************************************
+ * Name: monkey_dev_set_state
+ ****************************************************************************/
+
+void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
+                           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_BUTTON:
+      ubutton_write(dev->fd, state->data.button.value);
+      break;
+
+    default:
+      break;
+    }
+}
+
+/****************************************************************************
+ * Name: monkey_dev_get_state
+ ****************************************************************************/
+
+bool monkey_dev_get_state(FAR struct monkey_dev_s *dev,
+                          FAR struct monkey_dev_state_s *state)
+{
+  bool retval;
+  MONKEY_ASSERT_NULL(dev);
+
+  retval = false;
+
+  state->type = dev->type;
+
+  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_BUTTON:
+      retval = button_read(dev->fd, &state->data.button.value);
+      break;
+
+    default:
+      break;
+    }

Review Comment:
   ditto



##########
testing/monkey/monkey_recorder.c:
##########
@@ -0,0 +1,344 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_recorder.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_recorder.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_REC_HEAD_FMT  "T%" PRIu32 ",D%X,"
+#define MONKEY_REC_TOUCH_FMT MONKEY_REC_HEAD_FMT "X%d,Y%d,PR%d\n"
+#define MONKEY_REC_BTN_FMT   MONKEY_REC_HEAD_FMT "V%" PRIu32 "\n"
+#define MONKEY_REC_FILE_EXT  ".csv"
+#define MONKEY_REC_FILE_HEAD "rec_"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_recorder_gen_file_path
+ ****************************************************************************/
+
+static void monkey_recorder_gen_file_path(FAR char *path_buf,
+                                          size_t buf_size,
+                                          FAR const char *dir_path)
+{
+  char localtime_str_buf[64];
+
+  monkey_get_localtime_str(localtime_str_buf, sizeof(localtime_str_buf));
+
+  snprintf(path_buf, buf_size,
+           "%s/" MONKEY_REC_FILE_HEAD "%s" MONKEY_REC_FILE_EXT,
+           dir_path,
+           localtime_str_buf);
+}
+
+/****************************************************************************
+ * Name: monkey_readline
+ ****************************************************************************/
+
+static int monkey_readline(int fd, FAR char *ptr, int maxlen)
+{
+  int n;
+  int rc;
+  char c;
+  for (n = 1; n < maxlen; n++)
+    {
+      if ((rc = read(fd, &c, 1)) == 1)
+        {
+          *ptr++ = c;
+          if (c == '\n')
+            {
+              break;
+            }
+        }
+      else if (rc == 0)
+        {
+          if (n == 1)
+            {
+              /* EOF no data read */
+
+              return 0;
+            }
+          else
+            {
+              /* EOF, some data read */
+
+              break;
+            }
+        }
+      else
+        {
+          /* error */
+
+          return -1;
+        }
+    }
+
+  *ptr = 0;
+  return n;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_recorder_create
+ ****************************************************************************/
+
+FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path,
+                                            enum monkey_recorder_mode_e mode)
+{
+  char file_path[PATH_MAX];
+  FAR const char *path_ptr;
+  int oflag;
+  int fd;
+  FAR struct monkey_recorder_s *recorder;
+
+  MONKEY_ASSERT_NULL(path);
+
+  recorder = malloc(sizeof(struct monkey_recorder_s));
+  MONKEY_ASSERT_NULL(recorder);
+  memset(recorder, 0, sizeof(struct monkey_recorder_s));
+
+  if (mode == MONKEY_RECORDER_MODE_RECORD)
+    {
+      if (!monkey_dir_check(path))
+        {
+          goto failed;
+        }
+
+      monkey_recorder_gen_file_path(file_path,
+                                    sizeof(file_path),
+                                    path);
+      path_ptr = file_path;
+      oflag = O_WRONLY | O_CREAT;
+    }
+  else
+    {
+      path_ptr = path;
+      oflag = O_RDONLY;
+    }
+
+  fd = open(path_ptr, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", path_ptr, errno);
+      goto failed;
+    }
+
+  recorder->fd = fd;
+  recorder->mode = mode;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, mode = %d",
+                    path_ptr, fd, mode);
+
+  return recorder;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (recorder)
+    {
+      free(recorder);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: monkey_recorder_delete
+ ****************************************************************************/
+
+void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder)
+{
+  MONKEY_ASSERT_NULL(recorder);
+  if (recorder->fd > 0)
+    {
+      MONKEY_LOG_NOTICE("close fd: %d", recorder->fd);
+      close(recorder->fd);
+      recorder->fd = -1;

Review Comment:
   ```suggestion
   ```
   ditto



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+      dev->fd = -1;
+    }
+
+  free(dev);
+}
+
+/****************************************************************************
+ * Name: monkey_dev_set_state
+ ****************************************************************************/
+
+void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
+                           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_BUTTON:
+      ubutton_write(dev->fd, state->data.button.value);
+      break;
+
+    default:
+      break;

Review Comment:
   I think 2 more spaces are needed for case block



##########
testing/monkey/monkey_main.c:
##########
@@ -0,0 +1,381 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_main.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include "monkey.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_PREFIX "monkey"
+
+#define OPTARG_TO_VALUE(value, type, base)                             \
+  do                                                                   \
+  {                                                                    \
+    FAR char *ptr;                                                     \
+    value = (type)strtoul(optarg, &ptr, base);                         \

Review Comment:
   ```suggestion
       (value) = (type)strtoul(optarg, &ptr, (base));                     \
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946972850


##########
testing/monkey/monkey.c:
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "monkey.h"
+#include "monkey_recorder.h"
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type)                  \
+do {                                                                      \
+  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,      \
+                              MONKEY_DEV_TYPE_##type);                    \
+      if (!dev)                                                           \
+        {                                                                 \
+          goto failed;                                                    \
+        }                                                                 \
+      monkey->devs[monkey->dev_num] = dev;                                \
+      monkey->dev_num++;                                                  \
+    }                                                                     \
+} while (0)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_create
+ ****************************************************************************/
+
+FAR struct monkey_s *monkey_create(int dev_type_mask)
+{
+  FAR struct monkey_s *monkey = malloc(sizeof(struct monkey_s));
+  MONKEY_ASSERT_NULL(monkey);
+  memset(monkey, 0, sizeof(struct monkey_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(dev_type_mask))
+    {
+      MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, UTOUCH);
+      MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, UBUTTON);
+    }
+  else
+    {
+      MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, TOUCH);
+      MONKEY_DEV_CREATE_MATCH(monkey, dev_type_mask, BUTTON);
+    }
+
+  if (monkey->dev_num == 0)
+    {
+      MONKEY_LOG_ERROR("NO enabled device detected");
+      goto failed;
+    }
+
+  MONKEY_ASSERT(monkey->dev_num <= MONKEY_DEV_MAX_NUM);
+
+  MONKEY_LOG_NOTICE("OK");
+
+  return monkey;
+
+failed:
+  monkey_delete(monkey);
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: monkey_delete
+ ****************************************************************************/
+
+void monkey_delete(FAR struct monkey_s *monkey)
+{
+  int i;
+  MONKEY_ASSERT_NULL(monkey);
+
+  for (i = 0; i < monkey->dev_num; i++)
+    {
+        monkey_dev_delete(monkey->devs[i]);

Review Comment:
   done



##########
testing/monkey/monkey.h:
##########
@@ -0,0 +1,98 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_H__
+#define __MONKEY_H__

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#issuecomment-1215401453

   > @FASTSHIFT please fix the warning report here: https://github.com/apache/incubator-nuttx-apps/runs/7842281876?check_suite_focus=true
   
   done


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946974960


##########
testing/monkey/monkey_log.c:
##########
@@ -0,0 +1,99 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_log.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <syslog.h>
+#include "monkey_log.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_TESTING_MONKEY_LOG_ENABLE
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static enum monkey_log_level_type_e g_log_level =
+                               CONFIG_TESTING_MONKEY_LOG_LEVEL_DEFAULT;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_log_printf
+ ****************************************************************************/
+
+void monkey_log_printf(enum monkey_log_level_type_e level,
+                       FAR const char *func,
+                       FAR const char *fmt,
+                       ...)
+{
+  struct va_format vaf;
+  va_list ap;
+
+  static const int priority[_MONKEY_LOG_LEVEL_LAST] = {
+    LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR
+  };

Review Comment:
   done



##########
testing/monkey/monkey_log.h:
##########
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_log.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_LOG_H__
+#define __MONKEY_LOG_H__

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r947028792


##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,325 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)

Review Comment:
   done



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,325 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = calloc(1, sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+    }
+
+  free(dev);
+}
+
+/****************************************************************************
+ * Name: monkey_dev_set_state
+ ****************************************************************************/
+
+void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
+                          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_BUTTON:
+        ubutton_write(dev->fd, state->data.button.value);
+        break;
+
+      default:
+        break;
+    }
+}
+
+/****************************************************************************
+ * Name: monkey_dev_get_state
+ ****************************************************************************/
+
+bool monkey_dev_get_state(FAR struct monkey_dev_s *dev,
+                          FAR struct monkey_dev_state_s *state)
+{
+  bool retval;
+  MONKEY_ASSERT_NULL(dev);
+
+  retval = false;
+
+  state->type = dev->type;
+
+  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_BUTTON:
+        retval = button_read(dev->fd, &state->data.button.value);
+        break;
+
+      default:
+        break;
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_get_state
+ ****************************************************************************/
+
+enum monkey_dev_type_e monkey_dev_get_type(
+                       FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+  return dev->type;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_get_available
+ ****************************************************************************/
+
+int monkey_dev_get_available(FAR struct monkey_dev_s *devs[], int dev_num)
+{
+  int i;
+  int available = 0;
+  struct pollfd fds[MONKEY_DEV_MAX_NUM];

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946977170


##########
testing/monkey/monkey_type.h:
##########
@@ -0,0 +1,118 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_type.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_TYPE_H__
+#define __MONKEY_TYPE_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#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_DEV_MAX_NUM          2
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+struct monkey_dev_s;
+struct monkey_recorder_s;
+
+enum monkey_screen_type_e
+{
+  MONKEY_SCREEN_TYPE_RECT,
+  MONKEY_SCREEN_TYPE_ROUND
+};
+
+enum monkey_mode_e
+{
+  MONKEY_MODE_RANDOM,
+  MONKEY_MODE_RECORD,
+  MONKEY_MODE_PLAYBACK,
+};
+
+enum monkey_dev_type_e
+{
+  MONKEY_DEV_TYPE_UNKNOW  = 0x00,
+  MONKEY_DEV_TYPE_TOUCH   = 0x01,
+  MONKEY_DEV_TYPE_BUTTON  = 0x02,
+  MONKEY_DEV_TYPE_UTOUCH  = MONKEY_UINPUT_TYPE_MASK | MONKEY_DEV_TYPE_TOUCH,
+  MONKEY_DEV_TYPE_UBUTTON = MONKEY_UINPUT_TYPE_MASK | MONKEY_DEV_TYPE_BUTTON,
+};
+
+struct monkey_dev_state_s
+{
+  enum monkey_dev_type_e type;
+  union
+  {
+    struct
+    {
+      int x;
+      int y;
+      int is_pressed;
+    } touch;
+
+    struct
+    {
+      uint32_t value;
+    } button;
+  } data;
+};
+
+struct monkey_config_s
+{
+  struct
+  {
+    enum monkey_screen_type_e type;
+    int hor_res;
+    int ver_res;
+  } screen;
+
+  struct
+  {
+    uint32_t min;
+    uint32_t max;
+  } period;
+};
+
+struct monkey_s
+{
+  struct monkey_config_s config;
+  enum monkey_mode_e mode;
+  FAR struct monkey_dev_s *devs[MONKEY_DEV_MAX_NUM];
+  int dev_num;
+  FAR struct monkey_recorder_s *recorder;
+  struct
+  {
+      struct monkey_dev_state_s state;
+      uint32_t time_stamp;

Review Comment:
   done



##########
testing/monkey/monkey_utils.h:
##########
@@ -0,0 +1,94 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_utils.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_UTILS_H__
+#define __MONKEY_UTILS_H__

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] xiaoxiang781216 merged pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 merged PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946973541


##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/

Review Comment:
   done



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+      dev->fd = -1;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946976717


##########
testing/monkey/monkey_type.h:
##########
@@ -0,0 +1,118 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_type.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_TYPE_H__
+#define __MONKEY_TYPE_H__

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] xiaoxiang781216 commented on pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#issuecomment-1215386978

   @FASTSHIFT please fix the warning report here: 
   https://github.com/apache/incubator-nuttx-apps/runs/7842281876?check_suite_focus=true


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946973281


##########
testing/monkey/monkey_assert.h:
##########
@@ -0,0 +1,37 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_assert.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_ASSERT_H__
+#define __MONKEY_ASSERT_H__

Review Comment:
   done



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946974113


##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+      dev->fd = -1;
+    }
+
+  free(dev);
+}
+
+/****************************************************************************
+ * Name: monkey_dev_set_state
+ ****************************************************************************/
+
+void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
+                           FAR const struct monkey_dev_state_s *state)

Review Comment:
   done



##########
testing/monkey/monkey_dev.c:
##########
@@ -0,0 +1,327 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_dev.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <nuttx/input/buttons.h>
+#include <nuttx/input/touchscreen.h>
+#include <poll.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: utouch_write
+ ****************************************************************************/
+
+static void utouch_write(int fd, int x, int y, int touch_down)
+{
+  struct touch_sample_s sample;
+
+  if (touch_down)
+    {
+      sample.point[0].x        = x;
+      sample.point[0].y        = y;
+      sample.point[0].pressure = 42;
+      sample.point[0].flags    = TOUCH_DOWN | TOUCH_ID_VALID |
+                                 TOUCH_POS_VALID | TOUCH_PRESSURE_VALID;
+    }
+  else
+    {
+      sample.point[0].flags = TOUCH_UP | TOUCH_ID_VALID;
+    }
+
+  sample.npoints    = 1;
+  sample.point[0].h = 1;
+  sample.point[0].w = 1;
+
+  write(fd, &sample, sizeof(struct touch_sample_s));
+  MONKEY_LOG_INFO("%s at x = %d, y = %d",
+                  touch_down ? "PRESS  " : "RELEASE", x, y);
+}
+
+/****************************************************************************
+ * Name: ubutton_write
+ ****************************************************************************/
+
+static void ubutton_write(int fd, uint32_t btn_bits)
+{
+  btn_buttonset_t buttonset = btn_bits;
+  write(fd, &buttonset, sizeof(buttonset));
+  MONKEY_LOG_INFO("btn = 0x%08X", btn_bits);
+}
+
+/****************************************************************************
+ * Name: touch_read
+ ****************************************************************************/
+
+static bool touch_read(int fd, FAR int *x, FAR int *y, FAR int *touch_down)
+{
+  bool retval = false;
+  struct touch_sample_s sample;
+
+  int nbytes = read(fd, &sample, sizeof(sample));
+
+  if (nbytes == sizeof(sample))
+    {
+      retval = true;
+      uint8_t touch_flags = sample.point[0].flags;
+
+      if (touch_flags & TOUCH_DOWN || touch_flags & TOUCH_MOVE)
+        {
+          *x = sample.point[0].x;
+          *y = sample.point[0].y;
+          *touch_down = true;
+        }
+      else if (touch_flags & TOUCH_UP)
+        {
+          *x = 0;
+          *y = 0;
+          *touch_down = false;
+        }
+    }
+
+  return retval;
+}
+
+/****************************************************************************
+ * Name: button_read
+ ****************************************************************************/
+
+static bool button_read(int fd, FAR uint32_t *value)
+{
+  btn_buttonset_t buttonset;
+
+  int ret = read(fd, &buttonset, sizeof(buttonset));
+  if (ret < 0)
+    {
+      return false;
+    }
+
+  *value = buttonset;
+  return true;
+}
+
+/****************************************************************************
+ * Name: monkey_dev_create
+ ****************************************************************************/
+
+FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
+                                           enum monkey_dev_type_e type)
+{
+  FAR struct monkey_dev_s *dev;
+  int oflag;
+  int fd;
+
+  MONKEY_ASSERT_NULL(dev_path);
+
+  dev = malloc(sizeof(struct monkey_dev_s));
+  MONKEY_ASSERT_NULL(dev);
+  memset(dev, 0, sizeof(struct monkey_dev_s));
+
+  if (MONKEY_IS_UINPUT_TYPE(type))
+    {
+      oflag = O_RDWR | O_NONBLOCK;
+    }
+  else
+    {
+      oflag = O_RDONLY | O_NONBLOCK;
+    }
+
+  fd = open(dev_path, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", dev_path, errno);
+      goto failed;
+    }
+
+  dev->type = type;
+  dev->fd = fd;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, type: %s",
+                    dev_path, fd, monkey_dev_type2name(type));
+
+  return dev;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (dev)
+    {
+      free(dev);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_dev_delete
+ ****************************************************************************/
+
+void monkey_dev_delete(FAR struct monkey_dev_s *dev)
+{
+  MONKEY_ASSERT_NULL(dev);
+
+  if (dev->fd > 0)
+    {
+      /* Reset input state */
+
+      struct monkey_dev_state_s state;
+      memset(&state, 0, sizeof(state));
+      state.type = dev->type;
+      monkey_dev_set_state(dev, &state);
+
+      MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
+      close(dev->fd);
+      dev->fd = -1;
+    }
+
+  free(dev);
+}
+
+/****************************************************************************
+ * Name: monkey_dev_set_state
+ ****************************************************************************/
+
+void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
+                           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_BUTTON:
+      ubutton_write(dev->fd, state->data.button.value);
+      break;
+
+    default:
+      break;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946975647


##########
testing/monkey/monkey_main.c:
##########
@@ -0,0 +1,381 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_main.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include "monkey.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_PREFIX "monkey"
+
+#define OPTARG_TO_VALUE(value, type, base)                             \
+  do                                                                   \
+  {                                                                    \
+    FAR char *ptr;                                                     \
+    value = (type)strtoul(optarg, &ptr, base);                         \

Review Comment:
   done



##########
testing/monkey/monkey_recorder.c:
##########
@@ -0,0 +1,344 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_recorder.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_recorder.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_REC_HEAD_FMT  "T%" PRIu32 ",D%X,"
+#define MONKEY_REC_TOUCH_FMT MONKEY_REC_HEAD_FMT "X%d,Y%d,PR%d\n"
+#define MONKEY_REC_BTN_FMT   MONKEY_REC_HEAD_FMT "V%" PRIu32 "\n"
+#define MONKEY_REC_FILE_EXT  ".csv"
+#define MONKEY_REC_FILE_HEAD "rec_"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_recorder_gen_file_path
+ ****************************************************************************/
+
+static void monkey_recorder_gen_file_path(FAR char *path_buf,
+                                          size_t buf_size,
+                                          FAR const char *dir_path)
+{
+  char localtime_str_buf[64];
+
+  monkey_get_localtime_str(localtime_str_buf, sizeof(localtime_str_buf));
+
+  snprintf(path_buf, buf_size,
+           "%s/" MONKEY_REC_FILE_HEAD "%s" MONKEY_REC_FILE_EXT,
+           dir_path,
+           localtime_str_buf);
+}
+
+/****************************************************************************
+ * Name: monkey_readline
+ ****************************************************************************/
+
+static int monkey_readline(int fd, FAR char *ptr, int maxlen)
+{
+  int n;
+  int rc;
+  char c;
+  for (n = 1; n < maxlen; n++)
+    {
+      if ((rc = read(fd, &c, 1)) == 1)
+        {
+          *ptr++ = c;
+          if (c == '\n')
+            {
+              break;
+            }
+        }
+      else if (rc == 0)
+        {
+          if (n == 1)
+            {
+              /* EOF no data read */
+
+              return 0;
+            }
+          else
+            {
+              /* EOF, some data read */
+
+              break;
+            }
+        }
+      else
+        {
+          /* error */
+
+          return -1;
+        }
+    }
+
+  *ptr = 0;
+  return n;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_recorder_create
+ ****************************************************************************/
+
+FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path,
+                                            enum monkey_recorder_mode_e mode)
+{
+  char file_path[PATH_MAX];
+  FAR const char *path_ptr;
+  int oflag;
+  int fd;
+  FAR struct monkey_recorder_s *recorder;
+
+  MONKEY_ASSERT_NULL(path);
+
+  recorder = malloc(sizeof(struct monkey_recorder_s));
+  MONKEY_ASSERT_NULL(recorder);
+  memset(recorder, 0, sizeof(struct monkey_recorder_s));
+
+  if (mode == MONKEY_RECORDER_MODE_RECORD)
+    {
+      if (!monkey_dir_check(path))
+        {
+          goto failed;
+        }
+
+      monkey_recorder_gen_file_path(file_path,
+                                    sizeof(file_path),
+                                    path);
+      path_ptr = file_path;
+      oflag = O_WRONLY | O_CREAT;
+    }
+  else
+    {
+      path_ptr = path;
+      oflag = O_RDONLY;
+    }
+
+  fd = open(path_ptr, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", path_ptr, errno);
+      goto failed;
+    }
+
+  recorder->fd = fd;
+  recorder->mode = mode;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, mode = %d",
+                    path_ptr, fd, mode);
+
+  return recorder;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (recorder)
+    {
+      free(recorder);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: monkey_recorder_delete
+ ****************************************************************************/
+
+void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder)
+{
+  MONKEY_ASSERT_NULL(recorder);
+  if (recorder->fd > 0)
+    {
+      MONKEY_LOG_NOTICE("close fd: %d", recorder->fd);
+      close(recorder->fd);
+      recorder->fd = -1;

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946975943


##########
testing/monkey/monkey_recorder.c:
##########
@@ -0,0 +1,344 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_recorder.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_recorder.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_REC_HEAD_FMT  "T%" PRIu32 ",D%X,"
+#define MONKEY_REC_TOUCH_FMT MONKEY_REC_HEAD_FMT "X%d,Y%d,PR%d\n"
+#define MONKEY_REC_BTN_FMT   MONKEY_REC_HEAD_FMT "V%" PRIu32 "\n"
+#define MONKEY_REC_FILE_EXT  ".csv"
+#define MONKEY_REC_FILE_HEAD "rec_"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_recorder_gen_file_path
+ ****************************************************************************/
+
+static void monkey_recorder_gen_file_path(FAR char *path_buf,
+                                          size_t buf_size,
+                                          FAR const char *dir_path)
+{
+  char localtime_str_buf[64];
+
+  monkey_get_localtime_str(localtime_str_buf, sizeof(localtime_str_buf));
+
+  snprintf(path_buf, buf_size,
+           "%s/" MONKEY_REC_FILE_HEAD "%s" MONKEY_REC_FILE_EXT,
+           dir_path,
+           localtime_str_buf);
+}
+
+/****************************************************************************
+ * Name: monkey_readline
+ ****************************************************************************/
+
+static int monkey_readline(int fd, FAR char *ptr, int maxlen)
+{
+  int n;
+  int rc;
+  char c;
+  for (n = 1; n < maxlen; n++)
+    {
+      if ((rc = read(fd, &c, 1)) == 1)
+        {
+          *ptr++ = c;
+          if (c == '\n')
+            {
+              break;
+            }
+        }
+      else if (rc == 0)
+        {
+          if (n == 1)
+            {
+              /* EOF no data read */
+
+              return 0;
+            }
+          else
+            {
+              /* EOF, some data read */
+
+              break;
+            }
+        }
+      else
+        {
+          /* error */
+
+          return -1;
+        }
+    }
+
+  *ptr = 0;
+  return n;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_recorder_create
+ ****************************************************************************/
+
+FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path,
+                                            enum monkey_recorder_mode_e mode)
+{
+  char file_path[PATH_MAX];
+  FAR const char *path_ptr;
+  int oflag;
+  int fd;
+  FAR struct monkey_recorder_s *recorder;
+
+  MONKEY_ASSERT_NULL(path);
+
+  recorder = malloc(sizeof(struct monkey_recorder_s));
+  MONKEY_ASSERT_NULL(recorder);
+  memset(recorder, 0, sizeof(struct monkey_recorder_s));
+
+  if (mode == MONKEY_RECORDER_MODE_RECORD)
+    {
+      if (!monkey_dir_check(path))
+        {
+          goto failed;
+        }
+
+      monkey_recorder_gen_file_path(file_path,
+                                    sizeof(file_path),
+                                    path);
+      path_ptr = file_path;
+      oflag = O_WRONLY | O_CREAT;
+    }
+  else
+    {
+      path_ptr = path;
+      oflag = O_RDONLY;
+    }
+
+  fd = open(path_ptr, oflag);
+  if (fd < 0)
+    {
+      MONKEY_LOG_ERROR("open %s failed: %d", path_ptr, errno);
+      goto failed;
+    }
+
+  recorder->fd = fd;
+  recorder->mode = mode;
+
+  MONKEY_LOG_NOTICE("open %s success, fd = %d, mode = %d",
+                    path_ptr, fd, mode);
+
+  return recorder;
+
+failed:
+  if (fd > 0)
+    {
+      close(fd);
+    }
+
+  if (recorder)
+    {
+      free(recorder);
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: monkey_recorder_delete
+ ****************************************************************************/
+
+void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder)
+{
+  MONKEY_ASSERT_NULL(recorder);
+  if (recorder->fd > 0)
+    {
+      MONKEY_LOG_NOTICE("close fd: %d", recorder->fd);
+      close(recorder->fd);
+      recorder->fd = -1;
+    }
+
+  free(recorder);
+}
+
+/****************************************************************************
+ * Name: monkey_recorder_write
+ ****************************************************************************/
+
+enum monkey_recorder_res_e monkey_recorder_write(
+                                  FAR struct monkey_recorder_s *recorder,
+                                  FAR const struct monkey_dev_state_s *state)
+{
+  char buffer[128];
+  int len = -1;
+  int ret;
+  uint32_t cur_tick;
+
+  MONKEY_ASSERT_NULL(recorder);
+  MONKEY_ASSERT(recorder->mode == MONKEY_RECORDER_MODE_RECORD);
+
+  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;
+  }
+
+  if (len <= 0)
+    {
+      return MONKEY_RECORDER_RES_PARSER_ERROR;
+    }
+
+  ret = write(recorder->fd, buffer, len);
+  if (ret < 0)
+    {
+      return MONKEY_RECORDER_RES_WRITE_ERROR;
+    }
+
+  return MONKEY_RECORDER_RES_OK;
+}
+
+/****************************************************************************
+ * Name: monkey_recorder_read
+ ****************************************************************************/
+
+enum monkey_recorder_res_e monkey_recorder_read(
+                                      FAR struct monkey_recorder_s *recorder,
+                                      FAR struct monkey_dev_state_s *state,
+                                      FAR uint32_t *time_stamp)
+{
+  char buffer[128];
+  int dev_type;
+  int converted;
+  int ret;
+
+  MONKEY_ASSERT_NULL(recorder);
+  MONKEY_ASSERT(recorder->mode == MONKEY_RECORDER_MODE_PLAYBACK);
+
+  ret = monkey_readline(recorder->fd, buffer, sizeof(buffer));
+
+  if (ret < 0)
+    {
+      return MONKEY_RECORDER_RES_READ_ERROR;
+    }
+
+  if (ret == 0)
+    {
+      return MONKEY_RECORDER_RES_END_OF_FILE;
+    }
+
+  /* Read head to get device type */
+
+  converted = sscanf(buffer, MONKEY_REC_HEAD_FMT, time_stamp, &dev_type);
+
+  if (converted != 2)
+    {
+      return MONKEY_RECORDER_RES_PARSER_ERROR;
+    }
+
+  state->type = dev_type;
+
+  /* Get data */
+
+  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,

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946976467


##########
testing/monkey/monkey_recorder.h:
##########
@@ -0,0 +1,110 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_recorder.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_RECORDER_H__
+#define __MONKEY_RECORDER_H__

Review Comment:
   done



##########
testing/monkey/monkey_type.h:
##########
@@ -0,0 +1,118 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey_type.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __MONKEY_TYPE_H__
+#define __MONKEY_TYPE_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+#include <stdbool.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#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)

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946972377


##########
testing/monkey/monkey.c:
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "monkey.h"
+#include "monkey_recorder.h"
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type)                  \
+do {                                                                      \
+  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,      \
+                              MONKEY_DEV_TYPE_##type);                    \
+      if (!dev)                                                           \
+        {                                                                 \
+          goto failed;                                                    \
+        }                                                                 \
+      monkey->devs[monkey->dev_num] = dev;                                \
+      monkey->dev_num++;                                                  \
+    }                                                                     \
+} while (0)
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: monkey_create
+ ****************************************************************************/
+
+FAR struct monkey_s *monkey_create(int dev_type_mask)
+{
+  FAR struct monkey_s *monkey = malloc(sizeof(struct monkey_s));
+  MONKEY_ASSERT_NULL(monkey);
+  memset(monkey, 0, sizeof(struct monkey_s));

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946972209


##########
testing/monkey/monkey.c:
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "monkey.h"
+#include "monkey_recorder.h"
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type)                  \
+do {                                                                      \
+  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,      \
+                              MONKEY_DEV_TYPE_##type);                    \
+      if (!dev)                                                           \
+        {                                                                 \
+          goto failed;                                                    \
+        }                                                                 \
+      monkey->devs[monkey->dev_num] = dev;                                \
+      monkey->dev_num++;                                                  \

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] FASTSHIFT commented on a diff in pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
FASTSHIFT commented on code in PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#discussion_r946971939


##########
testing/monkey/monkey.c:
##########
@@ -0,0 +1,196 @@
+/****************************************************************************
+ * apps/testing/monkey/monkey.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include "monkey.h"
+#include "monkey_recorder.h"
+#include "monkey_assert.h"
+#include "monkey_log.h"
+#include "monkey_dev.h"
+#include "monkey_utils.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type)                  \
+do {                                                                      \
+  if ((type_mask & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type)     \

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-nuttx-apps] pkarashchenko commented on pull request #1273: testing: add monkey test

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on PR #1273:
URL: https://github.com/apache/incubator-nuttx-apps/pull/1273#issuecomment-1216865018

   In general looks good


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org