[PATCH v11] tests for fenv.h functions

Gedare Bloom gedare at rtems.org
Fri Apr 3 19:00:59 UTC 2020


On Fri, Apr 3, 2020 at 12:54 PM Gedare Bloom <gedare at rtems.org> wrote:
>
> On Fri, Apr 3, 2020 at 12:35 PM Vaibhav Gupta <vaibhav.varodek at gmail.com> wrote:
> >
> > On Fri, 27 Mar 2020 at 22:35, Eshan dhawan <eshandhawan51 at gmail.com> wrote:
> > >
> > > ---
> > >  testsuites/psxtests/psxfenv01/init.c        | 88 ++++++++++++++++-----
> > >  testsuites/psxtests/psxfenv01/psxfenv01.doc |  9 ++-
> > >  testsuites/psxtests/psxfenv01/psxfenv01.scn |  4 -
> > >  3 files changed, 76 insertions(+), 25 deletions(-)
> > >
> > > diff --git a/testsuites/psxtests/psxfenv01/init.c b/testsuites/psxtests/psxfenv01/init.c
> > > index cdb0fa596e..cfa31d6a16 100644
> > > --- a/testsuites/psxtests/psxfenv01/init.c
> > > +++ b/testsuites/psxtests/psxfenv01/init.c
> > > @@ -6,6 +6,7 @@
> > >  /*
> > >   * SPDX-License-Identifier: BSD-2-Clause
> > >   *
> > > + * Copyright (C) 2020 Eshan Dhawan
> > >   * Copyright (C) 2019 Vaibhav Gupta
> > >   *
> > >   * Redistribution and use in source and binary forms, with or without
> > > @@ -46,11 +47,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,40 +64,90 @@ 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 */
> > This line is referred below.
> > > -    puts( "fesetenv(FE_DFL_ENV)." );
> > > -    r = fesetenv(FE_DFL_ENV);
> > > -    if (r)
> > > -      printf("fesetenv ==> %d\n", r);
> > > +    r = fesetenv( FE_DFL_ENV );
> > > +    if ( r ) {
> > > +      printf( "fesetenv ==> %d\n", r);
> > > +    }
> > >      rtems_test_assert( r == 0 );
> > >
> > > -    /* 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);
> > > +    /* Test feclearexcept() and fetestexcept() in one go. */
> > > +    r = feclearexcept( FE_ALL_EXCEPT );
> > > +    if ( r ) {
> > > +      printf( "feclearexcept ==> 0x%x\n", r );
> > > +    }
> > >      rtems_test_assert( r == 0 );
> > >
> > >      r = fetestexcept( FE_ALL_EXCEPT );
> > > -    if (r)
> > > -      printf("fetestexcept ==> 0x%x\n", r);
> > > +    if ( r ) {
> > > +      printf( "fetestexcept ==> 0x%x\n", r );
> > > +    }
> > >      rtems_test_assert( r == 0 );
> > >
> > > -    /* Test 'FE_DIVBYZERO' */
> > > -    puts( "Divide by zero and confirm fetestexcept()" );
> > > +    /* Test 'FE_DIVBYZERO'
> > > +     *Divide by zero and confirm fetestexcept() */
> > >      a = 0.0;
> > >      b = 1.0;
> > >      c = b/a;
> > >      (void) c;
> > > +    /* Test fegetexceptflag() and fesetexceptflag() */
> > > +    r = fegetexceptflag( &excepts, FE_ALL_EXCEPT );
> > > +    if ( r ) {
> > > +      printf( "fegetexceptflag ==> 0x%x\n", r );
> > > +    }
> > > +    rtems_test_assert( r == 0 );
> > >
> > > -    fegetexceptflag(&excepts,FE_ALL_EXCEPT);
> > > +    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
> > Correct the Indentation. This and below conditional directives are
> > contained inside above #ifdef directive.
> > Also, like above, the best practice is to provide a
> > comment for the both opening and closing conditional directives.
> > (#ifdef and #endif).
> > Ex: When you open-
> > #ifdef xyz /* 3-5 words description */
> > ..
> > ....
> > #endif /* same description */
> >
> > This helps developers to understand which closing directive
> > belongs to which opening directive. Easy to understand.
> > Indentation too for same reason.
> >
>
> Good advice, although I'm not sure if we have these 2 things in our
> conventions yet: nesting CPP conditional blocks, and comments on CPP
> conditional blocks?
>

I think the prevailing condition in RTEMS (certainly in testsuites) is
to put the CPP define on the first line w/o indents. I don't know if
there are any examples of nested conditionals or not. And commenting
the conditional is also not done with any regularity.

So, I would be ok to leave as submitted unless there was anything else
to resolve?

> > --Vaibhav Gupta
> > > +    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
> > >
> > > diff --git a/testsuites/psxtests/psxfenv01/psxfenv01.doc b/testsuites/psxtests/psxfenv01/psxfenv01.doc
> > > index 3aa7757496..52d9fd19c7 100644
> > > --- a/testsuites/psxtests/psxfenv01/psxfenv01.doc
> > > +++ b/testsuites/psxtests/psxfenv01/psxfenv01.doc
> > > @@ -1,4 +1,4 @@
> > > -#  COPYRIGHT (c) 2019
> > > +#  COPYRIGHT (c) 2019
> > >  #  On-Line Applications Research Corporation (OAR).
> > >  #
> > >  # SPDX-License-Identifier: BSD-2-Clause
> > > @@ -12,9 +12,12 @@ Directives:
> > >    fesetenv
> > >    feclearexcept
> > >    fetestexcept
> > > -  texceptflag
> > >    feraiseexcept
> > > -
> > > +  fesetexeptflag
> > > +  fegetexeptflag
> > > +  fegetround
> > > +  fesetround
> > > +
> > >  Concepts:
> > >
> > >  + This test exercises the fenv.h methods.
> > > diff --git a/testsuites/psxtests/psxfenv01/psxfenv01.scn b/testsuites/psxtests/psxfenv01/psxfenv01.scn
> > > index 21395e6712..6ea3bc255e 100644
> > > --- a/testsuites/psxtests/psxfenv01/psxfenv01.scn
> > > +++ b/testsuites/psxtests/psxfenv01/psxfenv01.scn
> > > @@ -1,7 +1,3 @@
> > >  *** BEGIN OF TEST PSXFENV 01 ***
> > > -fesetenv(FE_DFL_ENV).
> > > -feclearexcept(FE_ALL_EXCEPT).
> > > -Divide by zero and confirm fetestexcept()
> > > -
> > >  *** END OF TEST PSXFENV 01 ***
> > >
> > > --
> > > 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


More information about the devel mailing list