[PATCH] Add testsuite for psxinttypes01
Vaibhav Gupta
vaibhavgupta40 at gmail.com
Tue Jun 11 04:37:38 UTC 2019
On Mon, Jun 10, 2019 at 10:01 PM Gedare Bloom <gedare at rtems.org> wrote:
> Hi Vaibhav,
>
> This is getting better, see below for review comments.
>
> On Mon, Jun 10, 2019 at 4:48 AM Vaibhav Gupta <vaibhavgupta40 at gmail.com>
> wrote:
> >
> > ---
> > testsuites/psxtests/Makefile.am | 7 +
> > testsuites/psxtests/configure.ac | 1 +
> > testsuites/psxtests/psxinttypes01/init.c | 220 ++++++++++++++++++
> > .../psxtests/psxinttypes01/psxinttypes01.doc | 67 ++++++
> > .../psxtests/psxinttypes01/psxinttypes01.scn | 75 ++++++
> > 5 files changed, 370 insertions(+)
> > create mode 100644 testsuites/psxtests/psxinttypes01/init.c
> > create mode 100644 testsuites/psxtests/psxinttypes01/psxinttypes01.doc
> > 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..7627e28195
> > --- /dev/null
> > +++ b/testsuites/psxtests/psxinttypes01/init.c
> > @@ -0,0 +1,220 @@
> > +/**
> > + * @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_n = "-123abc";
> //char* pointing to string with negative number
> > + char *endptr1 = NULL;
> > + wchar_t *nptr2_p = L"123junk";
> //wchar_t* pointing to string with positive number
> > + wchar_t *nptr2_n = L"-123junk";
> //wchar_t* pointing to string with negative number
> > + wchar_t *endptr2 = NULL;
> > + intmax_t result_strtoimax;
> > + uintmax_t result_strtoumax;
> > +
> > +
> Only one blank line is needed.
> > + TEST_BEGIN();
> > +
> > + puts( "\nChecking invalid base value" );
> > + rtems_test_assert( base >=2 && base <= 36 );
> This is an unnecessary print statement and assert.
>
> > +
> > + /*Test for strtoimax */
> > + puts( "\nStrtoimax Testcases...." );
> Don't capitalize the S. Same below in other testcases.
> > + puts( "Generating Results" );
> > + puts( "1 - Valid Inputs - Positive Number" );
> This is very "chatty" I think you can remove some print statements. At
> least, "Generating Results" is unnecessary here, more below. You might
> also consider removing the sequence numbers "1 - " and others below,
> they're not really needed.
>
> > + result_strtoimax = strtoimax( nptr1_p, &endptr1, base );
> > + puts( "Checking Results" );
> And "Checking Results" is not needed.
>
> > + rtems_test_assert( result_strtoimax == 123 );
> > + puts( "PASS" );
> And "PASS" is not needed, it is implied by reaching the next print
> statement.
>
> > +
> > + puts( "2 - Valid Inputs - Negative Number" );
> > + result_strtoimax = strtoimax( nptr1_n, &endptr1, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoimax == -123 );
> > + puts( "PASS" );
> Again get rid of "Checking Results" and "PASS" print statements.
> Repeat as needed below.
>
> > +
> > + puts( "Checking Garbage end of endptr" );
> I'd suggest you use the language from POSIX strtol, and say 'final
> string' instead of 'Garbage'.
>
> > + rtems_test_assert( *endptr1 != '\0' );
> Would it be more correct to check that *endptr1 == 'a', or that
> (endptr1 == nptr1_n+4)?
>
> > + puts( "PASS" );
> > +
> > + puts( "3 - Invalid Input - Send NULL Pointer" );
> > + result_strtoimax = strtoimax( NULL, &endptr1, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoimax == 0 );
> > + rtems_test_assert( errno == EINVAL );
> > + puts( "PASS" );
> > +
> > + puts( "4 - Invalid Input - Invalid base - Use base = 40" );
> > + result_strtoimax = strtoimax( nptr1_p, &endptr1, invalid_base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoimax == 0 );
> > + rtems_test_assert( errno == EINVAL );
> > + puts( "PASS" );
> > +
>
> There should be tests for out-of-range. Pass a string with a larger
> magnitude (positive and then negative) and check the return/errno.
>
> > + /*Test for strtoumax */
> > + puts( "\nStrtoumax Testcases...." );
> > + puts( "Generating Results" );
> > + puts( "1 - Valid Inputs - Positive Number" );
> > + result_strtoumax = strtoumax( nptr1_p, &endptr1, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoumax ==123 );
> > + puts( "PASS" );
> > +
> > + puts( "2 - Valid Inputs - Negative Number" );
> > + result_strtoumax = strtoumax( nptr1_n, &endptr1, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoumax == ( UINTMAX_MAX - 123 + 1 ) );
> > + puts( "PASS" );
> Is it expected to convert the negative number correctly like this?
>
In previous code, the test was rtems_test_assert( result_strtoumax != 0
);
On suggestion, I converted it to assert it with the output instead of zero.
.
I matched it with output, ( UINTMAX_MAX - 123 + 1 ) is giving correct
result.
Can you brief, how else I should convert this negative number?
>
> > +
> > + puts( "Checking Garbage end of endptr" );
> > + rtems_test_assert( *endptr1 != '\0' );
> > + puts( "PASS" );
> > +
> > + puts( "3 - Invalid Input - Send NULL Pointer" );
> > + result_strtoumax = strtoumax( NULL, &endptr1, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoumax == 0 );
> > + rtems_test_assert( errno == EINVAL );
> > + puts( "PASS" );
> > +
> > + puts( "4 - Invalid Input - Invalid base - Use base = 40" );
> > + result_strtoumax = strtoumax( nptr1_p, &endptr1, invalid_base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoumax == 0 );
> > + rtems_test_assert( errno == EINVAL );
> > + puts( "PASS" );
> > +
> > + /*Test for wcstoimax */
> > + puts( "\nWcstoimax Testcases...." );
> > + puts( "Generating Results" );
> > + puts( "1 - Valid Inputs - Positive Number" );
> > + result_strtoimax = wcstoimax( nptr2_p, &endptr2, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoimax == 123 );
> > + puts( "PASS" );
> > +
> > + puts( "2 - Valid Inputs - Negative Number" );
> > + result_strtoimax = wcstoimax( nptr2_n, &endptr2, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoimax == -123 );
> > + puts( "PASS" );
> > +
> > + puts( "Checking Garbage end of endptr" );
> > + rtems_test_assert( *endptr2 != '\0' );
> > + puts( "PASS" );
> > +
> > + puts( "3 - Invalid Input - Send NULL Pointer" );
> > + result_strtoimax = wcstoimax( NULL, &endptr2, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoimax == 0 );
> > + rtems_test_assert( errno == EINVAL );
> > + puts( "PASS" );
> > +
> > + puts( "4 - Invalid Input - Invalid base - Use base = 40" );
> > + result_strtoimax = wcstoimax( nptr2_p, &endptr2, invalid_base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoimax == 0 );
> > + rtems_test_assert( errno == EINVAL );
> > + puts( "PASS" );
> > +
> > + /*Test for wcstoumax */
> > + puts( "\nWcstoumax Testcases...." );
> > + puts( "Generating Results" );
> > + puts( "1 - Valid Inputs - Positive Number" );
> > + result_strtoumax = wcstoumax( nptr2_p, &endptr2, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoumax == 123 );
> > + puts( "PASS" );
> > +
> > + puts( "2 - Valid Inputs - Negative Number" );
> > + result_strtoumax = wcstoumax( nptr2_n, &endptr2, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoumax == ( UINTMAX_MAX - 123 + 1 ) );
> > + puts( "PASS" );
> > +
> > + puts( "Checking Garbage end of endptr" );
> > + rtems_test_assert( *endptr2 != '\0' );
> > + puts( "PASS" );
> > +
> > + puts( "3 - Invalid Input - Send NULL Pointer" );
> > + result_strtoumax = wcstoumax( NULL, &endptr2, base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoumax == 0 );
> > + rtems_test_assert( errno == EINVAL );
> > + puts( "PASS" );
> > +
> > + puts( "4 - Invalid Input - Invalid base - Use base = 40" );
> > + result_strtoumax = wcstoumax( nptr2_p, &endptr2, invalid_base );
> > + puts( "Checking Results" );
> > + rtems_test_assert( result_strtoumax == 0 );
> > + rtems_test_assert( errno == EINVAL );
> > + puts( "PASS" );
> > +
> > +
> > +
> Excess whitespace
>
> > + 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..50962dd930
> > --- /dev/null
> > +++ b/testsuites/psxtests/psxinttypes01/psxinttypes01.doc
> > @@ -0,0 +1,67 @@
> > +/**
> > + * @file
> > + * @brief Doc for Test suite for inttypes.h methods
> > + */
> Don't put in .doc file
>
> > +
> > +/*
> > + * 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.
> > + */
> ditto
> > +
> > +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
> Delete this line
> > +
> > +- Checks for Strtoimax Testcases
> > + - checks for output for string having a positive number
> > + - checks for output for string having a negative number
> > + - checks for Garbage end of 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 Garbage end of 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 Garbage end of 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 Garbage end of 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..6d50e64672
> > --- /dev/null
> > +++ b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn
> > @@ -0,0 +1,75 @@
> > +*** PSXINTTYPE 01 TEST ***
> > +
> > +Checking invalid base value
> > +
> > +Strtoimax Testcases....
> > +Generating Results
> > +1 - Valid Inputs - Positive Number
> > +Checking Results
> > +PASS
> > +2 - Valid Inputs - Negative Number
> > +Checking Results
> > +PASS
> > +Checking Garbage end of endptr
> > +PASS
> > +3 - Invalid Input - Send NULL Pointer
> > +Checking Results
> > +PASS
> > +4 - Invalid Input - Invalid base - Use base = 40
> > +Checking Results
> > +PASS
> > +
> > +Strtoumax Testcases....
> > +Generating Results
> > +1 - Valid Inputs - Positive Number
> > +Checking Results
> > +PASS
> > +2 - Valid Inputs - Negative Number
> > +Checking Results
> > +PASS
> > +Checking Garbage end of endptr
> > +PASS
> > +3 - Invalid Input - Send NULL Pointer
> > +Checking Results
> > +PASS
> > +4 - Invalid Input - Invalid base - Use base = 40
> > +Checking Results
> > +PASS
> > +
> > +Wcstoimax Testcases....
> > +Generating Results
> > +1 - Valid Inputs - Positive Number
> > +Checking Results
> > +PASS
> > +2 - Valid Inputs - Negative Number
> > +Checking Results
> > +PASS
> > +Checking Garbage end of endptr
> > +PASS
> > +3 - Invalid Input - Send NULL Pointer
> > +Checking Results
> > +PASS
> > +4 - Invalid Input - Invalid base - Use base = 40
> > +Checking Results
> > +PASS
> > +
> > +Wcstoumax Testcases....
> > +Generating Results
> > +1 - Valid Inputs - Positive Number
> > +Checking Results
> > +PASS
> > +2 - Valid Inputs - Negative Number
> > +Checking Results
> > +PASS
> > +Checking Garbage end of endptr
> > +PASS
> > +3 - Invalid Input - Send NULL Pointer
> > +Checking Results
> > +PASS
> > +4 - Invalid Input - Invalid base - Use base = 40
> > +Checking Results
> > +PASS
> > +
> > +
> > +*** END OF PSXINTTYPE 01 TEST ***
> > +
> Regenerate
>
> > --
> > 2.21.0
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20190611/07f65fbd/attachment-0002.html>
More information about the devel
mailing list