<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 10, 2019 at 10:01 PM Gedare Bloom <<a href="mailto:gedare@rtems.org">gedare@rtems.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Vaibhav,<br>
<br>
This is getting better, see below for review comments.<br>
<br>
On Mon, Jun 10, 2019 at 4:48 AM Vaibhav Gupta <<a href="mailto:vaibhavgupta40@gmail.com" target="_blank">vaibhavgupta40@gmail.com</a>> wrote:<br>
><br>
> ---<br>
> testsuites/psxtests/Makefile.am | 7 +<br>
> testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> | 1 +<br>
> testsuites/psxtests/psxinttypes01/init.c | 220 ++++++++++++++++++<br>
> .../psxtests/psxinttypes01/psxinttypes01.doc | 67 ++++++<br>
> .../psxtests/psxinttypes01/psxinttypes01.scn | 75 ++++++<br>
> 5 files changed, 370 insertions(+)<br>
> create mode 100644 testsuites/psxtests/psxinttypes01/init.c<br>
> create mode 100644 testsuites/psxtests/psxinttypes01/psxinttypes01.doc<br>
> create mode 100644 testsuites/psxtests/psxinttypes01/psxinttypes01.scn<br>
><br>
> diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am<br>
> index 1e354c0df7..59c9f2085b 100755<br>
> --- a/testsuites/psxtests/Makefile.am<br>
> +++ b/testsuites/psxtests/Makefile.am<br>
> @@ -523,6 +523,13 @@ psxintrcritical01_CPPFLAGS = $(AM_CPPFLAGS) \<br>
> endif<br>
> endif<br>
><br>
> +if TEST_psxinttypes01<br>
> +psx_tests += psxinttypes01<br>
> +psxinttypes01_SOURCES = psxinttypes01/init.c<br>
> +psxinttypes01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxinttypes01) \<br>
> + $(support_includes)<br>
> +endif<br>
> +<br>
> if HAS_POSIX<br>
> if TEST_psxitimer<br>
> psx_tests += psxitimer<br>
> diff --git a/testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a> b/testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> index cdd6ee7e4e..85559e4aa5 100644<br>
> --- a/testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> +++ b/testsuites/psxtests/<a href="http://configure.ac" rel="noreferrer" target="_blank">configure.ac</a><br>
> @@ -91,6 +91,7 @@ RTEMS_TEST_CHECK([psxid01])<br>
> RTEMS_TEST_CHECK([psximfs01])<br>
> RTEMS_TEST_CHECK([psximfs02])<br>
> RTEMS_TEST_CHECK([psxintrcritical01])<br>
> +RTEMS_TEST_CHECK([psxinttypes01])<br>
> RTEMS_TEST_CHECK([psxitimer])<br>
> RTEMS_TEST_CHECK([psxkey01])<br>
> RTEMS_TEST_CHECK([psxkey02])<br>
> diff --git a/testsuites/psxtests/psxinttypes01/init.c b/testsuites/psxtests/psxinttypes01/init.c<br>
> new file mode 100644<br>
> index 0000000000..7627e28195<br>
> --- /dev/null<br>
> +++ b/testsuites/psxtests/psxinttypes01/init.c<br>
> @@ -0,0 +1,220 @@<br>
> +/**<br>
> + * @file<br>
> + * @brief Test suite for inttypes.h methods<br>
> + */<br>
> +<br>
> +/*<br>
> + * SPDX-License-Identifier: BSD-2-Clause<br>
> + *<br>
> + * Copyright (C) 2019, Aditya Upadhyay and Vaibhav Gupta<br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
> + * POSSIBILITY OF SUCH DAMAGE.<br>
> + */<br>
> +<br>
> +#ifdef HAVE_CONFIG_H<br>
> +#include "config.h"<br>
> +#endif<br>
> +<br>
> +#include <rtems/test.h><br>
> +#include <inttypes.h><br>
> +#include <stdio.h><br>
> +#include <errno.h><br>
> +#include <tmacros.h><br>
> +#include <stdint.h><br>
> +#include <stddef.h><br>
> +<br>
> +const char rtems_test_name[] = "PSXINTTYPE 01";<br>
> +<br>
> +/* forward declarations to avoid warnings */<br>
> +rtems_task Init(rtems_task_argument ignored);<br>
> +<br>
> +rtems_task Init(rtems_task_argument ignored)<br>
> +{<br>
> + int base = 10;<br>
> + int invalid_base = 40;<br>
> + char *nptr1_p = "123abc"; //char* pointing to string with positive number<br>
> + char *nptr1_n = "-123abc"; //char* pointing to string with negative number<br>
> + char *endptr1 = NULL;<br>
> + wchar_t *nptr2_p = L"123junk"; //wchar_t* pointing to string with positive number<br>
> + wchar_t *nptr2_n = L"-123junk"; //wchar_t* pointing to string with negative number<br>
> + wchar_t *endptr2 = NULL;<br>
> + intmax_t result_strtoimax;<br>
> + uintmax_t result_strtoumax;<br>
> +<br>
> +<br>
Only one blank line is needed.<br>
> + TEST_BEGIN();<br>
> +<br>
> + puts( "\nChecking invalid base value" );<br>
> + rtems_test_assert( base >=2 && base <= 36 );<br>
This is an unnecessary print statement and assert.<br>
<br>
> +<br>
> + /*Test for strtoimax */<br>
> + puts( "\nStrtoimax Testcases...." );<br>
Don't capitalize the S. Same below in other testcases.<br>
> + puts( "Generating Results" );<br>
> + puts( "1 - Valid Inputs - Positive Number" );<br>
This is very "chatty" I think you can remove some print statements. At<br>
least, "Generating Results" is unnecessary here, more below. You might<br>
also consider removing the sequence numbers "1 - " and others below,<br>
they're not really needed.<br>
<br>
> + result_strtoimax = strtoimax( nptr1_p, &endptr1, base );<br>
> + puts( "Checking Results" );<br>
And "Checking Results" is not needed.<br>
<br>
> + rtems_test_assert( result_strtoimax == 123 );<br>
> + puts( "PASS" );<br>
And "PASS" is not needed, it is implied by reaching the next print statement.<br>
<br>
> +<br>
> + puts( "2 - Valid Inputs - Negative Number" );<br>
> + result_strtoimax = strtoimax( nptr1_n, &endptr1, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoimax == -123 );<br>
> + puts( "PASS" );<br>
Again get rid of "Checking Results" and "PASS" print statements.<br>
Repeat as needed below.<br>
<br>
> +<br>
> + puts( "Checking Garbage end of endptr" );<br>
I'd suggest you use the language from POSIX strtol, and say 'final<br>
string' instead of 'Garbage'.<br>
<br>
> + rtems_test_assert( *endptr1 != '\0' );<br>
Would it be more correct to check that *endptr1 == 'a', or that<br>
(endptr1 == nptr1_n+4)?<br>
<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "3 - Invalid Input - Send NULL Pointer" );<br>
> + result_strtoimax = strtoimax( NULL, &endptr1, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoimax == 0 );<br>
> + rtems_test_assert( errno == EINVAL );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "4 - Invalid Input - Invalid base - Use base = 40" );<br>
> + result_strtoimax = strtoimax( nptr1_p, &endptr1, invalid_base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoimax == 0 );<br>
> + rtems_test_assert( errno == EINVAL );<br>
> + puts( "PASS" );<br>
> +<br>
<br>
There should be tests for out-of-range. Pass a string with a larger<br>
magnitude (positive and then negative) and check the return/errno.<br>
<br>
> + /*Test for strtoumax */<br>
> + puts( "\nStrtoumax Testcases...." );<br>
> + puts( "Generating Results" );<br>
> + puts( "1 - Valid Inputs - Positive Number" );<br>
> + result_strtoumax = strtoumax( nptr1_p, &endptr1, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoumax ==123 );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "2 - Valid Inputs - Negative Number" );<br>
> + result_strtoumax = strtoumax( nptr1_n, &endptr1, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoumax == ( UINTMAX_MAX - 123 + 1 ) );<br>
> + puts( "PASS" );<br>
Is it expected to convert the negative number correctly like this?<br></blockquote><div>In previous code, the test was rtems_test_assert( result_strtoumax != 0 );</div><div>On suggestion, I converted it to assert it with the output instead of zero.</div><div>.<br></div><div>I matched it with output, ( UINTMAX_MAX - 123 + 1 ) is giving correct result.<br></div><div>Can you brief, how else I should convert this negative number?<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> +<br>
> + puts( "Checking Garbage end of endptr" );<br>
> + rtems_test_assert( *endptr1 != '\0' );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "3 - Invalid Input - Send NULL Pointer" );<br>
> + result_strtoumax = strtoumax( NULL, &endptr1, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoumax == 0 );<br>
> + rtems_test_assert( errno == EINVAL );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "4 - Invalid Input - Invalid base - Use base = 40" );<br>
> + result_strtoumax = strtoumax( nptr1_p, &endptr1, invalid_base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoumax == 0 );<br>
> + rtems_test_assert( errno == EINVAL );<br>
> + puts( "PASS" );<br>
> +<br>
> + /*Test for wcstoimax */<br>
> + puts( "\nWcstoimax Testcases...." );<br>
> + puts( "Generating Results" );<br>
> + puts( "1 - Valid Inputs - Positive Number" );<br>
> + result_strtoimax = wcstoimax( nptr2_p, &endptr2, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoimax == 123 );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "2 - Valid Inputs - Negative Number" );<br>
> + result_strtoimax = wcstoimax( nptr2_n, &endptr2, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoimax == -123 );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "Checking Garbage end of endptr" );<br>
> + rtems_test_assert( *endptr2 != '\0' );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "3 - Invalid Input - Send NULL Pointer" );<br>
> + result_strtoimax = wcstoimax( NULL, &endptr2, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoimax == 0 );<br>
> + rtems_test_assert( errno == EINVAL );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "4 - Invalid Input - Invalid base - Use base = 40" );<br>
> + result_strtoimax = wcstoimax( nptr2_p, &endptr2, invalid_base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoimax == 0 );<br>
> + rtems_test_assert( errno == EINVAL );<br>
> + puts( "PASS" );<br>
> +<br>
> + /*Test for wcstoumax */<br>
> + puts( "\nWcstoumax Testcases...." );<br>
> + puts( "Generating Results" );<br>
> + puts( "1 - Valid Inputs - Positive Number" );<br>
> + result_strtoumax = wcstoumax( nptr2_p, &endptr2, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoumax == 123 );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "2 - Valid Inputs - Negative Number" );<br>
> + result_strtoumax = wcstoumax( nptr2_n, &endptr2, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoumax == ( UINTMAX_MAX - 123 + 1 ) );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "Checking Garbage end of endptr" );<br>
> + rtems_test_assert( *endptr2 != '\0' );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "3 - Invalid Input - Send NULL Pointer" );<br>
> + result_strtoumax = wcstoumax( NULL, &endptr2, base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoumax == 0 );<br>
> + rtems_test_assert( errno == EINVAL );<br>
> + puts( "PASS" );<br>
> +<br>
> + puts( "4 - Invalid Input - Invalid base - Use base = 40" );<br>
> + result_strtoumax = wcstoumax( nptr2_p, &endptr2, invalid_base );<br>
> + puts( "Checking Results" );<br>
> + rtems_test_assert( result_strtoumax == 0 );<br>
> + rtems_test_assert( errno == EINVAL );<br>
> + puts( "PASS" );<br>
> +<br>
> +<br>
> +<br>
Excess whitespace<br>
<br>
> + TEST_END();<br>
> + rtems_test_exit(0);<br>
> +<br>
> +}<br>
> +<br>
> +/* NOTICE: the clock driver is explicitly disabled */<br>
> +<br>
> +#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER<br>
> +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER<br>
> +<br>
> +#define CONFIGURE_MAXIMUM_TASKS 1<br>
> +<br>
> +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE<br>
> +<br>
> +#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION<br>
> +<br>
> +#define CONFIGURE_INIT<br>
> +#include <rtems/confdefs.h><br>
> diff --git a/testsuites/psxtests/psxinttypes01/psxinttypes01.doc b/testsuites/psxtests/psxinttypes01/psxinttypes01.doc<br>
> new file mode 100644<br>
> index 0000000000..50962dd930<br>
> --- /dev/null<br>
> +++ b/testsuites/psxtests/psxinttypes01/psxinttypes01.doc<br>
> @@ -0,0 +1,67 @@<br>
> +/**<br>
> + * @file<br>
> + * @brief Doc for Test suite for inttypes.h methods<br>
> + */<br>
Don't put in .doc file<br>
<br>
> +<br>
> +/*<br>
> + * SPDX-License-Identifier: BSD-2-Clause<br>
> + *<br>
> + * Copyright (C) 2019, Vaibhav Gupta<br>
> + *<br>
> + * Redistribution and use in source and binary forms, with or without<br>
> + * modification, are permitted provided that the following conditions<br>
> + * are met:<br>
> + * 1. Redistributions of source code must retain the above copyright<br>
> + * notice, this list of conditions and the following disclaimer.<br>
> + * 2. Redistributions in binary form must reproduce the above copyright<br>
> + * notice, this list of conditions and the following disclaimer in the<br>
> + * documentation and/or other materials provided with the distribution.<br>
> + *<br>
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE<br>
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
> + * POSSIBILITY OF SUCH DAMAGE.<br>
> + */<br>
ditto<br>
> +<br>
> +This File describes the concepts tested by this test suite.<br>
> +<br>
> +inttypes.h - fixed size integer types<br>
> +<br>
> +test suite name: PSXINTTYPE 01<br>
> +<br>
> +- Checks for invalid base value<br>
Delete this line<br>
> +<br>
> +- Checks for Strtoimax Testcases<br>
> + - checks for output for string having a positive number<br>
> + - checks for output for string having a negative number<br>
> + - checks for Garbage end of endptr<br>
> + - checks for output for invalid argument - NULL Pointer<br>
> + - checks for output for invalid argument - Invalid Base<br>
> +<br>
> +- Checks for Strtoumax Test Cases<br>
> + - checks for output for string having a positive number<br>
> + - checks for output for string having a negative number<br>
> + - checks for Garbage end of endptr<br>
> + - checks for output for invalid argument - NULL Pointer<br>
> + - checks for output for invalid argument - Invalid Base<br>
> +<br>
> +- Checks for Wcstoimax Testcases<br>
> + - checks for output for string having a positive number<br>
> + - checks for output for string having a negative number<br>
> + - checks for Garbage end of endptr<br>
> + - checks for output for invalid argument - NULL Pointer<br>
> + - checks for output for invalid argument - Invalid Base<br>
> +<br>
> +- Checks for Wcstoumax Testcases<br>
> + - checks for output for string having a positive number<br>
> + - checks for output for string having a negative number<br>
> + - checks for Garbage end of endptr<br>
> + - checks for output for invalid argument - NULL Pointer<br>
> + - checks for output for invalid argument - Invalid Base<br>
> diff --git a/testsuites/psxtests/psxinttypes01/psxinttypes01.scn b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn<br>
> new file mode 100644<br>
> index 0000000000..6d50e64672<br>
> --- /dev/null<br>
> +++ b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn<br>
> @@ -0,0 +1,75 @@<br>
> +*** PSXINTTYPE 01 TEST ***<br>
> +<br>
> +Checking invalid base value<br>
> +<br>
> +Strtoimax Testcases....<br>
> +Generating Results<br>
> +1 - Valid Inputs - Positive Number<br>
> +Checking Results<br>
> +PASS<br>
> +2 - Valid Inputs - Negative Number<br>
> +Checking Results<br>
> +PASS<br>
> +Checking Garbage end of endptr<br>
> +PASS<br>
> +3 - Invalid Input - Send NULL Pointer<br>
> +Checking Results<br>
> +PASS<br>
> +4 - Invalid Input - Invalid base - Use base = 40<br>
> +Checking Results<br>
> +PASS<br>
> +<br>
> +Strtoumax Testcases....<br>
> +Generating Results<br>
> +1 - Valid Inputs - Positive Number<br>
> +Checking Results<br>
> +PASS<br>
> +2 - Valid Inputs - Negative Number<br>
> +Checking Results<br>
> +PASS<br>
> +Checking Garbage end of endptr<br>
> +PASS<br>
> +3 - Invalid Input - Send NULL Pointer<br>
> +Checking Results<br>
> +PASS<br>
> +4 - Invalid Input - Invalid base - Use base = 40<br>
> +Checking Results<br>
> +PASS<br>
> +<br>
> +Wcstoimax Testcases....<br>
> +Generating Results<br>
> +1 - Valid Inputs - Positive Number<br>
> +Checking Results<br>
> +PASS<br>
> +2 - Valid Inputs - Negative Number<br>
> +Checking Results<br>
> +PASS<br>
> +Checking Garbage end of endptr<br>
> +PASS<br>
> +3 - Invalid Input - Send NULL Pointer<br>
> +Checking Results<br>
> +PASS<br>
> +4 - Invalid Input - Invalid base - Use base = 40<br>
> +Checking Results<br>
> +PASS<br>
> +<br>
> +Wcstoumax Testcases....<br>
> +Generating Results<br>
> +1 - Valid Inputs - Positive Number<br>
> +Checking Results<br>
> +PASS<br>
> +2 - Valid Inputs - Negative Number<br>
> +Checking Results<br>
> +PASS<br>
> +Checking Garbage end of endptr<br>
> +PASS<br>
> +3 - Invalid Input - Send NULL Pointer<br>
> +Checking Results<br>
> +PASS<br>
> +4 - Invalid Input - Invalid base - Use base = 40<br>
> +Checking Results<br>
> +PASS<br>
> +<br>
> +<br>
> +*** END OF PSXINTTYPE 01 TEST ***<br>
> +<br>
Regenerate<br>
<br>
> --<br>
> 2.21.0<br>
><br>
</blockquote></div></div>