[PATCH] Tests for inttypes methods
Aditya Upadhyay
aadit0402 at gmail.com
Wed Aug 15 12:24:25 UTC 2018
---
testsuites/psxtests/Makefile.am | 12 ++
testsuites/psxtests/configure.ac | 1 +
testsuites/psxtests/psxinttypes01/init.c | 122 +++++++++++++++++++++
.../psxtests/psxinttypes01/psxinttypes01.scn | 27 +++++
4 files changed, 162 insertions(+)
create mode 100644 testsuites/psxtests/psxinttypes01/init.c
create mode 100644 testsuites/psxtests/psxinttypes01/psxinttypes01.scn
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index 2a18d54..274f02a 100644
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -15,6 +15,18 @@ psx_lib =
support_includes = -I$(top_srcdir)/../support/include
if HAS_POSIX
+if TEST_psxinttypes01
+psx_tests += psxinttypes01
+psx_screens += psxinttypes01/psxinttypes01.scn
+psxinttypes01_SOURCES = psxinttypes01/init.c psxinttypes01/inttypes.h
+psxinttypes01_CPPFLAGS = $(AM_CPPFLAGS) \
+ $(TEST_FLAGS_psxinttypes01) \
+ $(support_includes) \
+ -I$(top_srcdir)/include
+endif
+endif
+
+if HAS_POSIX
if TEST_psx01
psx_tests += psx01
psx01_SOURCES = psx01/init.c psx01/task.c psx01/system.h \
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index cdd6ee7..85559e4 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -91,6 +91,7 @@ RTEMS_TEST_CHECK([psxid01])
RTEMS_TEST_CHECK([psximfs01])
RTEMS_TEST_CHECK([psximfs02])
RTEMS_TEST_CHECK([psxintrcritical01])
+RTEMS_TEST_CHECK([psxinttypes01])
RTEMS_TEST_CHECK([psxitimer])
RTEMS_TEST_CHECK([psxkey01])
RTEMS_TEST_CHECK([psxkey02])
diff --git a/testsuites/psxtests/psxinttypes01/init.c b/testsuites/psxtests/psxinttypes01/init.c
new file mode 100644
index 0000000..2af2f71
--- /dev/null
+++ b/testsuites/psxtests/psxinttypes01/init.c
@@ -0,0 +1,122 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/test.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <errno.h>
+#include <tmacros.h>
+#include <stdint.h>
+#include <stddef.h>
+
+const char rtems_test_name[] = "PSXINTTYPE 01";
+
+/* forward declarations to avoid warnings */
+rtems_task Init(rtems_task_argument ignored);
+
+rtems_task Init(rtems_task_argument ignored)
+{
+ int base = 10;
+ char *nptr1 = "123abc";
+ char *endptr1 = NULL;
+ wchar_t *nptr2 = L"-123junk";
+ wchar_t *endptr2 = NULL;
+ intmax_t status1;
+ uintmax_t status2;
+
+
+ TEST_BEGIN();
+
+ puts( "\nChecking invalid base value" );
+ rtems_test_assert(base != 0 || (base >=2 && base <= 36));
+
+ /*Test for strtoimax */
+ puts( "Strtoimax Testcases...." );
+ puts( "Generating Status" );
+ status1 = strtoimax( nptr1, &endptr1, base );
+
+ rtems_test_assert( status1 != 0);
+ rtems_test_assert( base != EINVAL);
+
+ puts( "Checking Garbage end of endptr" );
+ rtems_test_assert( *endptr1 != '\0' );
+
+ puts( "Checking Underflow Case" );
+ rtems_test_assert( status1 >= INTMAX_MIN );
+
+ puts( "Checking Overflow Case" );
+ rtems_test_assert( status1 <= INTMAX_MAX ) ;
+
+ printf( "status = %jd \n" , status1 );
+
+ /*Test for strtoumax */
+ puts( "Strtoumax Testcases...." );
+ puts( "Generating Status" );
+ status2 = strtoumax( nptr1, &endptr1, base );
+
+ rtems_test_assert( status2 != 0);
+ rtems_test_assert( base != EINVAL);
+
+ puts( "Checking Garbage end of endptr" );
+ rtems_test_assert( *endptr1 != '\0' );
+
+ puts( "Checking Overflow Case" );
+ rtems_test_assert( status2 <= UINTMAX_MAX );
+
+ printf( "status = %ju \n", status2 );
+
+ /*Test for wcstoimax */
+ puts( "\nWcstoimax Testcases...." );
+ puts( "Generating Status" );
+ status1 = wcstoimax( nptr2, &endptr2, base );
+
+ rtems_test_assert( status1 != 0);
+ rtems_test_assert( base != EINVAL);
+
+ puts( "Checking Garbage end of endptr" );
+ rtems_test_assert( *endptr2 != '\0' );
+
+ puts( "Checking Underflow Case" );
+ rtems_test_assert( status1 >= INTMAX_MIN );
+
+ puts( "Checking Overflow Case" );
+ rtems_test_assert( status1 <= INTMAX_MAX ) ;
+
+ printf( "status = %jd \n", status1 );
+
+ /*Test for wcstoumax */
+ puts( "\nwcstoumax Testcases...." );
+ puts( "Generating Status" );
+ status2 = wcstoumax( nptr2, &endptr2, base );
+
+ rtems_test_assert( status2 != 0);
+ rtems_test_assert( base != EINVAL);
+
+ puts( "Checking Garbage end of endptr" );
+ rtems_test_assert( *endptr2 != '\0' );
+
+ puts( "Checking Overflow Case" );
+ rtems_test_assert( status2 <= UINTMAX_MAX );
+
+ printf( "status = %" PRIuMAX, status2 );
+
+
+ TEST_END();
+ rtems_test_exit(0);
+
+}
+
+/* NOTICE: the clock driver is explicitly disabled */
+
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
diff --git a/testsuites/psxtests/psxinttypes01/psxinttypes01.scn b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn
new file mode 100644
index 0000000..7b5a1b9
--- /dev/null
+++ b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn
@@ -0,0 +1,27 @@
+*** BEGIN OF TEST PSXINTTYPES 01 ***
+Checking invalid base value
+Strtoimax Testcases....
+Generating Status
+Checking Garbage end of endptr
+Checking Underflow Case
+Checking Overflow Case
+status = 9223372036854775807
+Strtoumax Testcases....
+Generating Status
+Checking Garbage end of endptr
+Checking Overflow Case
+status = 123
+
+Wcstoimax Testcases....
+Generating Status
+Checking Garbage end of endptr
+Checking Underflow Case
+Checking Overflow Case
+status = -123
+
+Wcstoumax Testcases....
+Generating Status
+Checking Garbage end of endptr
+Checking Overflow Case
+status = 18446744073709551493
+*** END OF TEST PSXINTTYPES 01 ***
--
2.7.4
More information about the devel
mailing list