[PATCH v6] tests for fenv.h functions

Eshan Dhawan eshandhawan51 at gmail.com
Fri Mar 20 20:25:52 UTC 2020


On Sat, Mar 21, 2020 at 1:35 AM Joel Sherrill <joel.sherrill at gmail.com>
wrote:

>
>
> On Fri, Mar 20, 2020 at 2:50 PM Gedare Bloom <gedare at rtems.org> wrote:
>
>> On Sun, Mar 8, 2020 at 11:02 AM Eshan Dhawan <eshandhawan51 at gmail.com>
>> wrote:
>> >
>> > I have compiled as well as executed it for RISC V architecture function
>> Fegetround() returns error for all rounding directions other the default
>> "FETONEAREST" I asked about it on devel to which dr Joel told that it is
>> due to soft-float.
>> > So I have added its test case but they won't work on emulators.
>> >
>> There may be some emulator/simulator that simulates hard-float
>> support. You may want to investigate a little bit. That would be
>> helpful for testing purposes.
>>
>
> Jim Wilson of SiFive and long time GCC maintainer told me that about the
> RISC-V
> soft float. It is just the way it is.
>
> If there is a way to know you have soft float, perhaps the libm header
> file could
> do the right thing and not define the constants it doesn't support. That
> is the
> contract on these methods. :)
>
Can you elaborate, please :)

>
> --joel
>
>>
>> >
>> > thanks
>> > -Eshan
>> > On Sun, Mar 8, 2020 at 7:55 PM Gedare Bloom <gedare at rtems.org> wrote:
>> >>
>> >> Hi Eshan,
>> >>
>> >> This is looking good. Did you compile it? Execute it?  How was the
>> output?
>> >>
>> >> On Sat, Mar 7, 2020 at 6:51 AM Eshan dhawan <eshandhawan51 at gmail.com>
>> wrote:
>> >> >
>> >> > ---
>> >> >  testsuites/psxtests/psxfenv01/init.c | 89
>> ++++++++++++++++++++++------
>> >> >  1 file changed, 71 insertions(+), 18 deletions(-)
>> >> >
>> >> > diff --git a/testsuites/psxtests/psxfenv01/init.c
>> b/testsuites/psxtests/psxfenv01/init.c
>> >> > index cdb0fa596e..6d71463465 100644
>> >> > --- a/testsuites/psxtests/psxfenv01/init.c
>> >> > +++ b/testsuites/psxtests/psxfenv01/init.c
>> >> > @@ -46,11 +46,12 @@
>> >> >  #include <string.h>
>> >> >  #include <rtems/test.h>
>> >> >  #include <tmacros.h>
>> >> > +#include <float.h>
>> >> >
>> >> >  const char rtems_test_name[] = "PSXFENV 01";
>> >> >
>> >> >  /* forward declarations to avoid warnings */
>> >> > -rtems_task Init(rtems_task_argument ignored);
>> >> > +rtems_task Init( rtems_task_argument ignored );
>> >> >
>> >> >  /* Test Function Begins */
>> >> >  rtems_task Init(rtems_task_argument ignored)
>> >> > @@ -62,28 +63,31 @@ rtems_task Init(rtems_task_argument ignored)
>> >> >
>> >> >    /*
>> >> >     * 'FE_ALL_EXCEPT' will be defined only when 'feclearexcept()',
>> >> > -   * 'fegetexceptflag()', 'feraiseexcept()', 'fesetexceptflag()' and
>> >> > -   * 'fetestexcept()' functions are supported by the architecture.
>> >> > +   * fegetexceptflag() , feraiseexcept(), fesetexceptflag() and
>> >> > +   * fetestexcept() functions are supported by the architecture.
>> >> >     * Hence their testcases can be wrapped under #ifdef and #endif.
>> >> >     */
>> >> >    #ifdef FE_ALL_EXCEPT /* floating-point exceptions */
>> >> >      puts( "fesetenv(FE_DFL_ENV)." );
>> >> > -    r = fesetenv(FE_DFL_ENV);
>> >> > -    if (r)
>> >> > +    r = fesetenv ( FE_DFL_ENV );
>> >> > +    if ( r ) {
>> >> >        printf("fesetenv ==> %d\n", r);
>> >> > -    rtems_test_assert( r == 0 );
>> >> > +    }
>> >> > +    rtems_test_assert ( r == 0 );
>> >> >
>> >> > -    /* Test 'feclearexcept()' and 'fetestexcept()' in one go. */
>> >> > -    puts( "feclearexcept(FE_ALL_EXCEPT)." );
>> >> > -    r = feclearexcept(FE_ALL_EXCEPT);
>> >> > -    if (r)
>> >> > +    /* Test feclearexcept() and fetestexcept() in one go. */
>> >> > +    puts( "feclearexcept(FE_ALL_EXCEPT)" );
>> >> > +    r = feclearexcept ( FE_ALL_EXCEPT );
>> >> > +    if ( r ) {
>> >> >        printf("feclearexcept ==> 0x%x\n", r);
>> >> > -    rtems_test_assert( r == 0 );
>> >> > +    }
>> >> > +    rtems_test_assert ( r == 0 );
>> >> >
>> >> > -    r = fetestexcept( FE_ALL_EXCEPT );
>> >> > -    if (r)
>> >> > +    r = fetestexcept ( FE_ALL_EXCEPT );
>> >> > +    if ( r ) {
>> >> >        printf("fetestexcept ==> 0x%x\n", r);
>> >> > -    rtems_test_assert( r == 0 );
>> >> > +    }
>> >> > +    rtems_test_assert ( r == 0 );
>> >> >
>> >> >      /* Test 'FE_DIVBYZERO' */
>> >> >      puts( "Divide by zero and confirm fetestexcept()" );
>> >> > @@ -91,11 +95,60 @@ rtems_task Init(rtems_task_argument ignored)
>> >> >      b = 1.0;
>> >> >      c = b/a;
>> >> >      (void) c;
>> >> > -
>> >> > -    fegetexceptflag(&excepts,FE_ALL_EXCEPT);
>> >> > -
>> >> > +    /* Test fegetexceptflag() and fesetexceptflag() */
>> >> > +    r = fegetexceptflag ( &excepts, FE_ALL_EXCEPT );
>> >> > +    if ( r ) {
>> >> > +      printf("fegetexceptflag ==> 0x%x\n", r);
>> >> > +    }
>> >> > +    rtems_test_assert ( r == 0 );
>> >> > +
>> >> > +    r = fesetexceptflag ( &excepts, FE_ALL_EXCEPT );
>> >> > +    if ( r ) {
>> >> > +      printf("fesetexceptflag ==> 0x%x\n", r);
>> >> > +    }
>> >> > +    rtems_test_assert ( r == 0 );
>> >> > +
>> >> > +    /* Test for fegetround() and fesetround()
>> >> > +     * They have four main macros to be tested separated by ifdef
>> >> > +     * Since not all architectures support them
>> >> > +     * The test case gets and sets the rounding directions */
>> >> > +#ifdef FE_TONEAREST
>> >> > +    rtems_test_assert ( fegetround() == FE_TONEAREST ) ;
>> >> > +#endif
>> >> > +#ifdef FE_TOWARDZERO
>> >> > +  r = fesetround ( FE_TOWARDZERO ) ;
>> >> > +  if ( r ) {
>> >> > +      printf("fesetround ==> 0x%x\n", r);
>> >> > +    }
>> >> > +  rtems_test_assert ( r == 0 ) ;
>> >> > +  rtems_test_assert ( fegetround() == FE_TOWARDZERO ) ;
>> >> > +#endif
>> >> > +#ifdef FE_DOWNWARD
>> >> > +  r = fesetround ( FE_DOWNWARD );
>> >> > +  if ( r ) {
>> >> > +      printf("fesetround ==> 0x%x\n", r);
>> >> > +    }
>> >> > +  rtems_test_assert ( r == 0 ) ;
>> >> > +  rtems_test_assert ( fegetround() == FE_DOWNWARD ) ;
>> >> > +#endif
>> >> > +#ifdef FE_UPWARD
>> >> > +  r = fesetround ( FE_UPWARD );
>> >> > +  if ( r ) {
>> >> > +      printf("fesetround ==> 0x%x\n", r);
>> >> > +    }
>> >> > +  rtems_test_assert ( r == 0 ) ;
>> >> > +  rtems_test_assert ( fegetround() == FE_UPWARD ) ;
>> >> > +#endif
>> >> > +#ifdef FE_TONEAREST
>> >> > +  r = fesetround ( FE_TONEAREST );
>> >> > +  if ( r ) {
>> >> > +      printf("fesetround ==> 0x%x\n", r);
>> >> > +    }
>> >> > +  rtems_test_assert ( r == 0 ) ;
>> >> > +#endif
>> >> > +
>> >> >  #ifdef FE_DIVBYZERO
>> >> > -    r = feraiseexcept(FE_DIVBYZERO);
>> >> > +    r = feraiseexcept ( FE_DIVBYZERO ) ;
>> >> >      rtems_test_assert( fetestexcept( FE_DIVBYZERO ) );
>> >> >  #endif
>> >> >
>> >> > --
>> >> > 2.17.1
>> >> >
>> >> > _______________________________________________
>> >> > devel mailing list
>> >> > devel at rtems.org
>> >> > http://lists.rtems.org/mailman/listinfo/devel
>> _______________________________________________
>> devel mailing list
>> devel at rtems.org
>> http://lists.rtems.org/mailman/listinfo/devel
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20200321/f4908c17/attachment-0001.html>


More information about the devel mailing list