xiaoxiang781216 commented on code in PR #1662:
URL: https://github.com/apache/nuttx-apps/pull/1662#discussion_r1138001565


##########
testing/arch_libc/Make.defs:
##########
@@ -0,0 +1,23 @@
+############################################################################
+# apps/testing/mtd_config_fs/Make.defs

Review Comment:
   ```suggestion
   # apps/testing/arch_libc/Make.defs
   ```



##########
testing/arch_libc/arch_libc_test_main.c:
##########
@@ -0,0 +1,251 @@
+/****************************************************************************
+ * apps/testing/arch_libc/arch_libc_test_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 <nuttx/arch.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <debug.h>
+#include <assert.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Configuration ************************************************************/
+
+#ifdef CONFIG_TESTING_ARCH_LIBC_STRCPY
+#  define TEST_MAX_STRING_LEN    128
+#  define TEST_SHORT_SRC_LEN     50
+#  define TEST_LONG_SRC_LEN      128
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_TESTING_ARCH_LIBC_STRCPY
+static char g_test_src_str[TEST_MAX_STRING_LEN];
+static char g_test_dst_str[TEST_MAX_STRING_LEN];
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+#ifdef CONFIG_TESTING_ARCH_LIBC_STRCPY
+
+/****************************************************************************
+ * Name: arch_libc_test_strcpy
+ ****************************************************************************/
+
+void init_short_test_str(int dst_offset, int src_offset)
+{
+  int off;
+
+  memset(g_test_src_str, '\0', sizeof(g_test_src_str));
+  memset(g_test_dst_str, '\0', sizeof(g_test_dst_str));
+
+  for (off = 0; off < TEST_SHORT_SRC_LEN; off++)
+    {
+      g_test_src_str[off + src_offset] = '0' + off % 10;
+    }
+}
+
+/****************************************************************************
+ * Name: arch_libc_test_strcpy_offset
+ ****************************************************************************/
+
+int arch_libc_test_strcpy_offset(int dst_offset, int src_offset)
+{
+  int off;
+  FAR char *dest;
+  FAR char *src;
+  FAR char *result_str;
+  bool pass = true;
+
+  init_short_test_str(dst_offset, src_offset);
+  dest = g_test_dst_str + dst_offset;
+  src = g_test_src_str + src_offset;
+  result_str = strcpy(dest, src);
+
+  /* check strcpy data */
+
+  for (off = 0; off < TEST_SHORT_SRC_LEN; off++)
+    {
+      if (result_str[off] != '0' + off % 10)
+        {
+          pass = false;
+          printf("dest copied data error, index %d\n", off);
+        }
+
+      if (src[off] != '0' + off % 10)
+        {
+          pass = false;
+          printf("src data error, index %d\n", off);
+        }
+    }
+
+  for (off = TEST_SHORT_SRC_LEN; off < TEST_MAX_STRING_LEN - dst_offset;
+       off++)
+    {
+      if (result_str[off] != '\0')
+        {
+          pass = false;
+          printf("dest tailing zero error, index %d\n", off);
+        }
+    }
+
+  for (off = TEST_SHORT_SRC_LEN; off < TEST_MAX_STRING_LEN - src_offset;
+       off++)
+    {
+      if (src[off] != '\0')
+        {
+          pass = false;
+          printf("src tailing zero error, index %d\n", off);
+        }
+    }
+
+  /* strcpy shouln't change arch_libc_test_strcpy's local variable */
+
+  if (dest != (g_test_dst_str + dst_offset) ||
+      src != (g_test_src_str + src_offset))
+    {
+      pass = false;
+      printf("local var changed after calling strcpy\n");
+    }
+
+  if (!pass)
+    {
+      printf("Test Failed at dst/src offset [%d, %d]\n", dst_offset,
+             src_offset);
+      return -1;
+    }
+
+  return 0;
+}
+
+/****************************************************************************
+ * Name: arch_libc_test_strcpy
+ ****************************************************************************/
+
+int arch_libc_test_strcpy(void)
+{
+  int dest_off;
+  int src_off;
+  int ret = 0;
+
+  for (dest_off = 0; dest_off <= 4; dest_off++)
+    {
+      for (src_off = 0; src_off <= 4; src_off++)
+        {
+          if (arch_libc_test_strcpy_offset(dest_off, src_off) != 0)
+            {
+              ret = -1;
+            }
+        }
+    }
+
+  if (ret != 0)
+    {
+      printf("arch_libc_test_strcpy Test Failed\n");
+    }
+  else
+    {
+      printf("arch_libc_test_strcpy Test Passed\n");
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: arch_libc_strcpy_speed_offset
+ ****************************************************************************/
+
+uint32_t arch_libc_strcpy_speed_offset(int dst_offset, int src_offset)
+{
+  FAR char *dest;
+  FAR char *src;
+  uint32_t start;
+  uint32_t end;
+
+  init_short_test_str(dst_offset, src_offset);
+  dest = g_test_dst_str + dst_offset;
+  src = g_test_src_str + src_offset;
+  start = up_perf_gettime();
+  strcpy(dest, src);
+  end = up_perf_gettime();
+
+  return end - start;
+}
+
+/****************************************************************************
+ * Name: arch_libc_strcpy_speed
+ ****************************************************************************/
+
+int arch_libc_strcpy_speed(void)
+{
+  int dest_off;
+  int src_off;
+  uint32_t cycles = 0;
+
+  up_perf_init(NULL);

Review Comment:
   up_perf_init should be called by board file, not application.



##########
testing/arch_libc/Kconfig:
##########
@@ -0,0 +1,38 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config TESTING_ARCH_LIBC
+       tristate "arch-specific libc function test"
+       default n
+       depends on ARCH_TOOLCHAIN_GNU
+       ---help---
+               Enable the arch libc test
+
+if TESTING_ARCH_LIBC
+
+config TESTING_ARCH_LIBC_STRCPY
+       bool "test strcpy"
+       default n
+
+config TESTING_ARCH_LIBC_PROGNAME
+       string "Program name"
+       default "arch_libctest"
+       ---help---
+               This is the name of the program that will be used when the NSH 
ELF
+               program is installed.
+
+config TESTING_ARCH_LIBC_PRIORITY
+       int "arch libc test priority"
+       default 100
+
+config TESTING_ARCH_LIBC_STACKSIZE
+       int "arch libc test stack size"
+       default 4096

Review Comment:
   why not use the default stack size



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to