pkarashchenko commented on code in PR #1446:
URL: https://github.com/apache/nuttx-apps/pull/1446#discussion_r1051610975


##########
testing/himem_test/himem_chardev_test.c:
##########
@@ -0,0 +1,437 @@
+/****************************************************************************
+ * apps/testing/himem_test/himem_chardev_test.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 <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <nuttx/himem/himem.h>
+#include <math.h>
+
+#include <nuttx/config.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <arch/esp32/esp32_himem_chardev.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+#define HIMEM_DEV1 "/dev/chardev1"
+#define HIMEM_DEV2 "/dev/chardev2"
+#define DATA_OUTPUT 0
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Data check function
+ ****************************************************************************/
+
+static void himem_data_check(uint8_t *data1, uint8_t *data2,
+                     uint32_t len, uint32_t offset)
+{

Review Comment:
   ```suggestion
   static void himem_data_check(uint8_t *data1, uint8_t *data2,
                                uint32_t len, uint32_t offset)
   {
   ```



##########
testing/himem_test/himem_chardev_test.c:
##########
@@ -0,0 +1,437 @@
+/****************************************************************************
+ * apps/testing/himem_test/himem_chardev_test.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 <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <nuttx/himem/himem.h>
+#include <math.h>
+
+#include <nuttx/config.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <arch/esp32/esp32_himem_chardev.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+#define HIMEM_DEV1 "/dev/chardev1"
+#define HIMEM_DEV2 "/dev/chardev2"
+#define DATA_OUTPUT 0
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Data check function
+ ****************************************************************************/
+
+static void himem_data_check(uint8_t *data1, uint8_t *data2,
+                     uint32_t len, uint32_t offset)
+{
+  uint32_t ok = 0;
+  uint32_t ng = 0;
+
+  for (int i = 0; i < len; i++)
+    {
+      if (data1[i] == data2[i])
+        {
+           ok++;
+        }
+        else
+        {
+          ng++;
+        }
+    }
+
+  if (ng == 0)
+    {
+      printf("Data check OK=%d KB\n", ok / 1024);
+    }
+    else
+    {
+      printf("Data check NG=%d OK=%d\n", ng, ok);
+    }
+}
+
+/****************************************************************************
+ * Alternate access verification for multiple devices
+ ****************************************************************************/
+
+static void himem_multi_dev_check(uint32_t size, uint32_t offset)
+{
+  int fd1;
+  int fd2;
+  uint8_t *work_buffer1 = NULL;
+  uint8_t *work_buffer2 = NULL;
+  uint8_t *work_buffer3 = NULL;
+
+  if (himem_chardev_register(HIMEM_DEV1, size + offset) != 0)
+    {
+      printf("HIMEM_DEV1 Create failed. \n");
+      goto common_exit3;
+    }
+
+  if (himem_chardev_register(HIMEM_DEV2, size + offset) != 0)
+    {
+      printf("HIMEM_DEV2 Create failed. \n");
+      goto common_exit3;
+    }
+
+  if ((fd1 = open(HIMEM_DEV1, O_RDWR)) < 0)
+    {
+      printf("HIMEM_DEV1 Open failed. \n");
+      goto common_exit2;
+    }
+
+  if ((fd2 = open(HIMEM_DEV2, O_RDWR)) < 0)
+    {
+      printf("HIMEM_DEV1 Open failed. \n");
+      goto common_exit1;
+    }
+
+  if ((work_buffer1 = malloc(size)) == NULL)
+    {
+      printf("Allocate failed1");
+      goto common_exit;
+    }
+
+  if ((work_buffer2 = malloc(size)) == NULL)
+    {
+      printf("Allocate failed2");
+      goto common_exit;
+    }
+
+  if ((work_buffer3 = malloc(size)) == NULL)
+    {
+      printf("Allocate failed2");
+      goto common_exit;
+    }
+
+  memset(work_buffer1, 0, size);
+  memset(work_buffer2, 0, size);
+  memset(work_buffer3, 0, size);
+
+  if (size + offset < 1048576)
+    {
+      printf("Memory Size: %d KB\nHimemSizeTest=%d\n",
+                (size + offset) / 1024, size + offset);

Review Comment:
   ```suggestion
         printf("Memory Size: %d KB\nHimemSizeTest=%d\n",
                (size + offset) / 1024, size + offset);
   ```



##########
testing/himem_test/himem_chardev_test.c:
##########
@@ -0,0 +1,437 @@
+/****************************************************************************
+ * apps/testing/himem_test/himem_chardev_test.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 <stdio.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <nuttx/himem/himem.h>
+#include <math.h>
+
+#include <nuttx/config.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <assert.h>
+#include <arch/esp32/esp32_himem_chardev.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+#define HIMEM_DEV1 "/dev/chardev1"
+#define HIMEM_DEV2 "/dev/chardev2"
+#define DATA_OUTPUT 0
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Data check function
+ ****************************************************************************/
+
+static void himem_data_check(uint8_t *data1, uint8_t *data2,
+                     uint32_t len, uint32_t offset)
+{
+  uint32_t ok = 0;
+  uint32_t ng = 0;
+
+  for (int i = 0; i < len; i++)
+    {
+      if (data1[i] == data2[i])
+        {
+           ok++;
+        }
+        else
+        {
+          ng++;
+        }
+    }
+
+  if (ng == 0)
+    {
+      printf("Data check OK=%d KB\n", ok / 1024);
+    }
+    else
+    {
+      printf("Data check NG=%d OK=%d\n", ng, ok);
+    }
+}
+
+/****************************************************************************
+ * Alternate access verification for multiple devices
+ ****************************************************************************/
+
+static void himem_multi_dev_check(uint32_t size, uint32_t offset)
+{
+  int fd1;
+  int fd2;
+  uint8_t *work_buffer1 = NULL;
+  uint8_t *work_buffer2 = NULL;
+  uint8_t *work_buffer3 = NULL;
+
+  if (himem_chardev_register(HIMEM_DEV1, size + offset) != 0)
+    {
+      printf("HIMEM_DEV1 Create failed. \n");
+      goto common_exit3;
+    }
+
+  if (himem_chardev_register(HIMEM_DEV2, size + offset) != 0)
+    {
+      printf("HIMEM_DEV2 Create failed. \n");
+      goto common_exit3;
+    }
+
+  if ((fd1 = open(HIMEM_DEV1, O_RDWR)) < 0)
+    {
+      printf("HIMEM_DEV1 Open failed. \n");
+      goto common_exit2;
+    }
+
+  if ((fd2 = open(HIMEM_DEV2, O_RDWR)) < 0)
+    {
+      printf("HIMEM_DEV1 Open failed. \n");
+      goto common_exit1;
+    }
+
+  if ((work_buffer1 = malloc(size)) == NULL)
+    {
+      printf("Allocate failed1");
+      goto common_exit;
+    }
+
+  if ((work_buffer2 = malloc(size)) == NULL)
+    {
+      printf("Allocate failed2");
+      goto common_exit;
+    }
+
+  if ((work_buffer3 = malloc(size)) == NULL)
+    {
+      printf("Allocate failed2");
+      goto common_exit;
+    }
+
+  memset(work_buffer1, 0, size);
+  memset(work_buffer2, 0, size);
+  memset(work_buffer3, 0, size);
+
+  if (size + offset < 1048576)
+    {
+      printf("Memory Size: %d KB\nHimemSizeTest=%d\n",
+                (size + offset) / 1024, size + offset);
+    }
+  else
+    {
+      printf("Memory Size: %d MB\nHimemSizeTest=%d\n",
+                (size + offset) / (1024 * 1024), size + offset);

Review Comment:
   ```suggestion
         printf("Memory Size: %d MB\nHimemSizeTest=%d\n",
                (size + offset) / (1024 * 1024), size + offset);
   ```



-- 
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-unsubscr...@nuttx.apache.org

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

Reply via email to