[PATCH] Add Testsuite for PSXINTTYPES01
Aditya Upadhyay
aadit0402 at gmail.com
Wed Jun 12 16:40:27 UTC 2019
Hi Vaibhav,
RTEMS does not use // for comment. Just make this little change and send the
next version of this patch.
On Wed, Jun 12, 2019 at 3:09 PM Vaibhav Gupta <vaibhavgupta40 at gmail.com> wrote:
>
> ---
> testsuites/psxtests/Makefile.am | 7 +
> testsuites/psxtests/configure.ac | 1 +
> testsuites/psxtests/psxinttypes01/init.c | 233 ++++++++++++++++++
> .../psxtests/psxinttypes01/psxinttypes01.doc | 70 ++++++
> .../psxtests/psxinttypes01/psxinttypes01.scn | 44 ++++
> 5 files changed, 355 insertions(+)
> create mode 100644 testsuites/psxtests/psxinttypes01/init.c
> create mode 100644 testsuites/psxtests/psxinttypes01/psxinttypes01.docs
> create mode 100644 testsuites/psxtests/psxinttypes01/psxinttypes01.scn
>
> diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
> index 1e354c0df7..59c9f2085b 100755
> --- a/testsuites/psxtests/Makefile.am
> +++ b/testsuites/psxtests/Makefile.am
> @@ -523,6 +523,13 @@ psxintrcritical01_CPPFLAGS = $(AM_CPPFLAGS) \
> endif
> endif
>
> +if TEST_psxinttypes01
> +psx_tests += psxinttypes01
> +psxinttypes01_SOURCES = psxinttypes01/init.c
> +psxinttypes01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxinttypes01) \
> + $(support_includes)
> +endif
> +
> if HAS_POSIX
> if TEST_psxitimer
> psx_tests += psxitimer
> diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
> index cdd6ee7e4e..85559e4aa5 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 0000000000..8eafae11ac
> --- /dev/null
> +++ b/testsuites/psxtests/psxinttypes01/init.c
> @@ -0,0 +1,233 @@
> +/**
> + * @file
> + * @brief Test suite for inttypes.h methods
> + */
> +
> +/*
> + * SPDX-License-Identifier: BSD-2-Clause
> + *
> + * Copyright (C) 2019, Aditya Upadhyay and Vaibhav Gupta
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + * notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + * notice, this list of conditions and the following disclaimer in the
> + * documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +#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;
> + int invalid_base = 40;
> +
> + char *nptr1_p = "123abc"; //char* pointing to string with positive number
> + char *nptr1_p_errange = "9999999999999999999999"; //char* pointing to string with positive number that is out of range
> + char *nptr1_n = "-123abc"; //char* pointing to string with negative number
> + char *nptr1_n_errange = "-9999999999999999999999"; //char* pointing to string with negative number that is out of range
> + char *endptr1 = NULL;
> +
> + wchar_t *nptr2_p = L"123junk"; //wchar_t* pointing to string with positive number
> + wchar_t *nptr2_p_errange = L"9999999999999999999999"; //wchar_t* pointing to string with positive number that is out of range
> + wchar_t *nptr2_n = L"-123junk"; //wchar_t* pointing to string with negative number
> + wchar_t *nptr2_n_errange = L"-9999999999999999999999"; //wchar_t* pointing to string with negative number that is out of range
> + wchar_t *endptr2 = NULL;
> +
> + intmax_t result_strtoimax;
> + uintmax_t result_strtoumax;
> +
> + TEST_BEGIN();
> +
> + /*Test for strtoimax */
> + puts( "\nstrtoimax Testcases...." );
> + puts( "Valid Inputs - Positive Number" );
> + result_strtoimax = strtoimax( nptr1_p, &endptr1, base );
> + rtems_test_assert( result_strtoimax == 123 );
> +
> + puts( "Final string pointed by endptr" );
> + rtems_test_assert( endptr1 == ( nptr1_p + 3 ) );
> +
> + puts( "Valid Inputs - Negative Number" );
> + result_strtoimax = strtoimax( nptr1_n, &endptr1, base );
> + rtems_test_assert( result_strtoimax == -123 );
> +
> + puts( "Final string pointed by endptr" );
> + rtems_test_assert( endptr1 == ( nptr1_n + 4 ) );
> +
> + puts( "Valid Input - Positive Number - Number out of Range" );
> + result_strtoimax = strtoimax( nptr1_p_errange, &endptr1, base );
> + rtems_test_assert( result_strtoimax == INTMAX_MAX );
> + rtems_test_assert( errno == ERANGE );
> +
> + puts( "Valid Input - Negative Number - Number out of Range" );
> + result_strtoimax = strtoimax( nptr1_n_errange, &endptr1, base );
> + rtems_test_assert( result_strtoimax == INTMAX_MIN );
> + rtems_test_assert( errno == ERANGE );
> +
> + puts( "Invalid Input - Send NULL Pointer" );
> + result_strtoimax = strtoimax( NULL, &endptr1, base );
> + rtems_test_assert( result_strtoimax == 0 );
> + rtems_test_assert( errno == EINVAL );
> +
> + puts( "Invalid Input - Invalid base - Use base = 40" );
> + result_strtoimax = strtoimax( nptr1_p, &endptr1, invalid_base );
> + rtems_test_assert( result_strtoimax == 0 );
> + rtems_test_assert( errno == EINVAL );
> +
> + /*Test for strtoumax */
> + puts( "\nstrtoumax Testcases...." );
> + puts( "Valid Inputs - Positive Number" );
> + result_strtoumax = strtoumax( nptr1_p, &endptr1, base );
> + rtems_test_assert( result_strtoumax ==123 );
> +
> + puts( "Final string pointed by endptr" );
> + rtems_test_assert( endptr1 == ( nptr1_p + 3 ) );
> +
> + puts( "Valid Inputs - Negative Number" );
> + result_strtoumax = strtoumax( nptr1_n, &endptr1, base );
> + rtems_test_assert( result_strtoumax != 0 );
> +
> + puts( "Final string pointed by endptr" );
> + rtems_test_assert( endptr1 == ( nptr1_n + 4 ) );
> +
> + puts( "Valid Input - Positive Number - Number out of Range" );
> + result_strtoumax = strtoumax( nptr1_p_errange, &endptr1, base );
> + rtems_test_assert( result_strtoumax == UINTMAX_MAX );
> + rtems_test_assert( errno == ERANGE );
> +
> + puts( "Valid Input - Negative Number - Number out of Range" );
> + result_strtoumax = strtoumax( nptr1_n_errange, &endptr1, base );
> + rtems_test_assert( result_strtoumax != 0 );
> + rtems_test_assert( errno == ERANGE );
> +
> + puts( "Invalid Input - Send NULL Pointer" );
> + result_strtoumax = strtoumax( NULL, &endptr1, base );
> + rtems_test_assert( result_strtoumax == 0 );
> + rtems_test_assert( errno == EINVAL );
> +
> + puts( "Invalid Input - Invalid base - Use base = 40" );
> + result_strtoumax = strtoumax( nptr1_p, &endptr1, invalid_base );
> + rtems_test_assert( result_strtoumax == 0 );
> + rtems_test_assert( errno == EINVAL );
> +
> + /*Test for wcstoimax */
> + puts( "\nwcstoimax Testcases...." );
> + puts( "Valid Inputs - Positive Number" );
> + result_strtoimax = wcstoimax( nptr2_p, &endptr2, base );
> + rtems_test_assert( result_strtoimax == 123 );
> +
> + puts( "Final string pointed by endptr" );
> + rtems_test_assert( endptr2 == ( nptr2_p + 3 ) );
> +
> + puts( "Valid Inputs - Negative Number" );
> + result_strtoimax = wcstoimax( nptr2_n, &endptr2, base );
> + rtems_test_assert( result_strtoimax == -123 );
> +
This should be like result_strtoimax == -123. ( one space between
operator and and value)
> + puts( "Final string pointed by endptr" );
> + rtems_test_assert( endptr2 == ( nptr2_n + 4 ) );
> +
> + puts( "Valid Input - Positive Number - Number out of Range" );
> + result_strtoimax = wcstoimax( nptr2_p_errange, &endptr2, base );
> + rtems_test_assert( result_strtoimax == INTMAX_MAX );
> + rtems_test_assert( errno == ERANGE );
> +
> + puts( "Valid Input - Negative Number - Number out of Range" );
> + result_strtoimax = wcstoimax( nptr2_n_errange, &endptr2, base );
> + rtems_test_assert( result_strtoimax != 0 );
> + rtems_test_assert( errno == ERANGE );
> +
> + puts( "Invalid Input - Send NULL Pointer" );
> + result_strtoimax = wcstoimax( NULL, &endptr2, base );
> + rtems_test_assert( result_strtoimax == 0 );
> + rtems_test_assert( errno == EINVAL );
> +
> + puts( "Invalid Input - Invalid base - Use base = 40" );
> + result_strtoimax = wcstoimax( nptr2_p, &endptr2, invalid_base );
> + rtems_test_assert( result_strtoimax == 0 );
> + rtems_test_assert( errno == EINVAL );
> +
> + /*Test for wcstoumax */
> + puts( "\nwcstoumax Testcases...." );
> + puts( "Valid Inputs - Positive Number" );
> + result_strtoumax = wcstoumax( nptr2_p, &endptr2, base );
> + rtems_test_assert( result_strtoumax == 123 );
> +
> + puts( "Final string pointed by endptr" );
> + rtems_test_assert( endptr2 == ( nptr2_p + 3 ) );
> +
> + puts( "Valid Inputs - Negative Number" );
> + result_strtoumax = wcstoumax( nptr2_n, &endptr2, base );
> + rtems_test_assert( result_strtoumax != 0 );
> +
> + puts( "Final string pointed by endptr" );
> + rtems_test_assert( endptr2 == ( nptr2_n + 4 ) );
> +
> + puts( "Valid Input - Positive Number - Number out of Range" );
> + result_strtoumax = wcstoumax( nptr2_p_errange, &endptr2, base );
> + rtems_test_assert( result_strtoumax == UINTMAX_MAX );
> + rtems_test_assert( errno == ERANGE );
> +
> + puts( "Valid Input - Negative Number - Number out of Range" );
> + result_strtoumax = wcstoumax( nptr2_n_errange, &endptr2, base );
> + rtems_test_assert( result_strtoumax != 0 );
> + rtems_test_assert( errno == ERANGE );
> +
> + puts( "Invalid Input - Send NULL Pointer" );
> + result_strtoumax = wcstoumax( NULL, &endptr2, base );
> + rtems_test_assert( result_strtoumax == 0 );
> + rtems_test_assert( errno == EINVAL );
> +
> + puts( "Invalid Input - Invalid base - Use base = 40" );
> + result_strtoumax = wcstoumax( nptr2_p, &endptr2, invalid_base );
> + rtems_test_assert( result_strtoumax == 0 );
> + rtems_test_assert( errno == EINVAL );
> +
> + 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.doc b/testsuites/psxtests/psxinttypes01/psxinttypes01.doc
> new file mode 100644
> index 0000000000..b5fd8e6d0e
> --- /dev/null
> +++ b/testsuites/psxtests/psxinttypes01/psxinttypes01.doc
> @@ -0,0 +1,70 @@
> +/*
> + * SPDX-License-Identifier: BSD-2-Clause
> + *
> + * Copyright (C) 2019, Vaibhav Gupta
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + * 1. Redistributions of source code must retain the above copyright
> + * notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + * notice, this list of conditions and the following disclaimer in the
> + * documentation and/or other materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + */
> +
> +This File describes the concepts tested by this test suite.
> +
> +inttypes.h - fixed size integer types
> +
> +test suite name: PSXINTTYPE 01
> +
> +- Checks for invalid base value
> +
> +- Checks for Strtoimax Testcases
> + - checks for output for string having a positive number
> + - checks for output for string having a negative number
> + - checks for output for string having a positive number - Number Out of Range
> + - checks for output for string having a negative number - Number Out of Range
> + - checks for final string pointed by endptr
> + - checks for output for invalid argument - NULL Pointer
> + - checks for output for invalid argument - Invalid Base
> +
> +- Checks for Strtoumax Test Cases
> + - checks for output for string having a positive number
> + - checks for output for string having a negative number
> + - checks for output for string having a positive number - Number Out of Range
> + - checks for output for string having a negative number - Number Out of Range
> + - checks for final string pointed by endptr
> + - checks for output for invalid argument - NULL Pointer
> + - checks for output for invalid argument - Invalid Base
> +
> +- Checks for Wcstoimax Testcases
> + - checks for output for string having a positive number
> + - checks for output for string having a negative number
> + - checks for output for string having a positive number - Number Out of Range
> + - checks for output for string having a negative number - Number Out of Range
> + - checks for final string pointed by endptr
> + - checks for output for invalid argument - NULL Pointer
> + - checks for output for invalid argument - Invalid Base
> +
> +- Checks for Wcstoumax Testcases
> + - checks for output for string having a positive number
> + - checks for output for string having a negative number
> + - checks for output for string having a positive number - Number Out of Range
> + - checks for output for string having a negative number - Number Out of Range
> + - checks for final string pointed by endptr
> + - checks for output for invalid argument - NULL Pointer
> + - checks for output for invalid argument - Invalid Base
> diff --git a/testsuites/psxtests/psxinttypes01/psxinttypes01.scn b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn
> new file mode 100644
> index 0000000000..33e82428f1
> --- /dev/null
> +++ b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn
> @@ -0,0 +1,44 @@
> +*** PSXINTTYPE 01 TEST ***
> +
> +strtoimax Testcases....
> +Valid Inputs - Positive Number
> +Final string pointed by endptr
> +Valid Inputs - Negative Number
> +Final string pointed by endptr
> +Valid Input - Positive Number - Number out of Range
> +Valid Input - Negative Number - Number out of Range
> +Invalid Input - Send NULL Pointer
> +Invalid Input - Invalid base - Use base = 40
> +
> +strtoumax Testcases....
> +Valid Inputs - Positive Number
> +Final string pointed by endptr
> +Valid Inputs - Negative Number
> +Final string pointed by endptr
> +Valid Input - Positive Number - Number out of Range
> +Valid Input - Negative Number - Number out of Range
> +Invalid Input - Send NULL Pointer
> +Invalid Input - Invalid base - Use base = 40
> +
> +wcstoimax Testcases....
> +Valid Inputs - Positive Number
> +Final string pointed by endptr
> +Valid Inputs - Negative Number
> +Final string pointed by endptr
> +Valid Input - Positive Number - Number out of Range
> +Valid Input - Negative Number - Number out of Range
> +Invalid Input - Send NULL Pointer
> +Invalid Input - Invalid base - Use base = 40
> +
> +wcstoumax Testcases....
> +Valid Inputs - Positive Number
> +Final string pointed by endptr
> +Valid Inputs - Negative Number
> +Final string pointed by endptr
> +Valid Input - Positive Number - Number out of Range
> +Valid Input - Negative Number - Number out of Range
> +Invalid Input - Send NULL Pointer
> +Invalid Input - Invalid base - Use base = 40
> +
> +*** END OF PSXINTTYPE 01 TEST ***
> +
> --
> 2.21.0
>
You can also look into this: http://man7.org/linux/man-pages/man3/strtol.3.html
Thanks,
More information about the devel
mailing list