This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 46e148db0 testing/ostest: add strto base tests
46e148db0 is described below
commit 46e148db093d091fae102c4a4a2294f36dbe24c6
Author: hanzhijian <[email protected]>
AuthorDate: Sat Aug 1 17:45:02 2026 +0800
testing/ostest: add strto base tests
Add regression coverage for integer conversions with explicit bases from 2
through 36. Exercise lower- and upper-case digits, positional values, all six
strto* interfaces, end pointers, errno, and the invalid range boundaries.
The tests fail at base 27 without apache/nuttx#19594 and pass with the
corresponding libc fix.
Signed-off-by: hanzhijian <[email protected]>
---
testing/ostest/CMakeLists.txt | 2 +-
testing/ostest/Makefile | 2 +-
testing/ostest/libc_strto.c | 122 ++++++++++++++++++++++++++++++++++++++++++
testing/ostest/ostest.h | 4 ++
testing/ostest/ostest_main.c | 1 +
5 files changed, 129 insertions(+), 2 deletions(-)
diff --git a/testing/ostest/CMakeLists.txt b/testing/ostest/CMakeLists.txt
index c52256105..2ec79d11c 100644
--- a/testing/ostest/CMakeLists.txt
+++ b/testing/ostest/CMakeLists.txt
@@ -22,7 +22,7 @@
if(CONFIG_TESTING_OSTEST)
- set(SRCS getopt.c libc_memmem.c restart.c sighelper.c)
+ set(SRCS getopt.c libc_memmem.c libc_strto.c restart.c sighelper.c)
if(CONFIG_ENABLE_ALL_SIGNALS)
list(APPEND SRCS sighand.c signest.c)
diff --git a/testing/ostest/Makefile b/testing/ostest/Makefile
index 12afab653..d79b9d87d 100644
--- a/testing/ostest/Makefile
+++ b/testing/ostest/Makefile
@@ -31,7 +31,7 @@ MODULE = $(CONFIG_TESTING_OSTEST)
# NuttX OS Test
-CSRCS = getopt.c libc_memmem.c restart.c sighelper.c
+CSRCS = getopt.c libc_memmem.c libc_strto.c restart.c sighelper.c
ifeq ($(CONFIG_ENABLE_ALL_SIGNALS),y)
CSRCS += sighand.c signest.c
diff --git a/testing/ostest/libc_strto.c b/testing/ostest/libc_strto.c
new file mode 100644
index 000000000..12d8dd477
--- /dev/null
+++ b/testing/ostest/libc_strto.c
@@ -0,0 +1,122 @@
+/****************************************************************************
+ * apps/testing/ostest/libc_strto.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+
+#include "ostest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int strto_test(void)
+{
+ unsigned long value;
+ char input[3];
+ char *endptr;
+ int base;
+
+ /* Verify the largest lower- and upper-case digit and a positional value
+ * in every supported explicit base.
+ */
+
+ input[1] = '!';
+ input[2] = '\0';
+ for (base = 2; base <= 36; base++)
+ {
+ input[0] = base <= 10 ? '0' + base - 1 : 'a' + base - 11;
+ errno = 0;
+ value = strtoul(input, &endptr, base);
+ ASSERT(value == (unsigned long)base - 1);
+ ASSERT(endptr == input + 1);
+ ASSERT(errno == 0);
+
+ if (base > 10)
+ {
+ input[0] = 'A' + base - 11;
+ errno = 0;
+ value = strtoul(input, &endptr, base);
+ ASSERT(value == (unsigned long)base - 1);
+ ASSERT(endptr == input + 1);
+ ASSERT(errno == 0);
+ }
+
+ errno = 0;
+ value = strtoul("10!", &endptr, base);
+ ASSERT(value == (unsigned long)base);
+ ASSERT(*endptr == '!');
+ ASSERT(errno == 0);
+ }
+
+ /* All public integer conversion interfaces share this base validation. */
+
+ errno = 0;
+ ASSERT(strtol("z!", &endptr, 36) == 35);
+ ASSERT(*endptr == '!');
+ ASSERT(errno == 0);
+
+ errno = 0;
+ ASSERT(strtoul("z!", &endptr, 36) == 35);
+ ASSERT(*endptr == '!');
+ ASSERT(errno == 0);
+
+ errno = 0;
+ ASSERT(strtoll("z!", &endptr, 36) == 35);
+ ASSERT(*endptr == '!');
+ ASSERT(errno == 0);
+
+ errno = 0;
+ ASSERT(strtoull("z!", &endptr, 36) == 35);
+ ASSERT(*endptr == '!');
+ ASSERT(errno == 0);
+
+ errno = 0;
+ ASSERT(strtoimax("z!", &endptr, 36) == 35);
+ ASSERT(*endptr == '!');
+ ASSERT(errno == 0);
+
+ errno = 0;
+ ASSERT(strtoumax("z!", &endptr, 36) == 35);
+ ASSERT(*endptr == '!');
+ ASSERT(errno == 0);
+
+ /* Bases outside the supported range remain invalid. */
+
+ errno = 0;
+ ASSERT(strtoul("10", &endptr, 1) == 0);
+ ASSERT(errno == EINVAL);
+
+ errno = 0;
+ ASSERT(strtoul("10", &endptr, 37) == 0);
+ ASSERT(errno == EINVAL);
+
+ return OK;
+}
diff --git a/testing/ostest/ostest.h b/testing/ostest/ostest.h
index 38e95d1fb..c889a4354 100644
--- a/testing/ostest/ostest.h
+++ b/testing/ostest/ostest.h
@@ -97,6 +97,10 @@ int getopt_test(void);
int memmem_test(void);
+/* libc_strto.c *************************************************************/
+
+int strto_test(void);
+
/* setvbuf.c ****************************************************************/
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
diff --git a/testing/ostest/ostest_main.c b/testing/ostest/ostest_main.c
index 095b63c02..cd53d1a29 100644
--- a/testing/ostest/ostest_main.c
+++ b/testing/ostest/ostest_main.c
@@ -289,6 +289,7 @@ static int user_main(int argc, char *argv[])
printf("\nuser_main: libc tests\n");
memmem_test();
+ strto_test();
check_test_memory_usage();
/* If retention of child status is enable, then suppress it for this task.