Changeset e845873 in rtems


Ignore:
Timestamp:
Apr 20, 2020, 6:22:43 PM (3 months ago)
Author:
Eshan dhawan <eshandhawan51@…>
Branches:
5, master
Children:
a2b7ab03
Parents:
bd750c9e
git-author:
Eshan dhawan <eshandhawan51@…> (04/20/20 18:22:43)
git-committer:
Joel Sherrill <joel@…> (06/06/20 20:24:59)
Message:

tests for fenv.h functions

added tests for fesetexeptflag(), fegetexeptflag(),
fegetround(), fesetround().

In the test fegetround() does not return any flag
other then FE_TONEAREST in tests.
This is probably due to soft float.

The test complies successfully and returns assert
at fegetround()

Other tests run without any errors
tested on RISCV/rv32imac

The test prints nothing if runs successfully.

updates #2971

Signed-off-by: Eshan dhawan <eshandhawan51@…>

Location:
testsuites/psxtests/psxfenv01
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • testsuites/psxtests/psxfenv01/init.c

    rbd750c9e re845873  
    77 * SPDX-License-Identifier: BSD-2-Clause
    88 *
     9 * Copyright (C) 2020 Eshan Dhawan
    910 * Copyright (C) 2019 Vaibhav Gupta
    1011 *
     
    4748#include <rtems/test.h>
    4849#include <tmacros.h>
     50#include <float.h>
    4951
    5052const char rtems_test_name[] = "PSXFENV 01";
    5153
    5254/* forward declarations to avoid warnings */
    53 rtems_task Init(rtems_task_argument ignored);
     55rtems_task Init( rtems_task_argument ignored );
    5456
    5557/* Test Function Begins */
     
    6365  /*
    6466   * 'FE_ALL_EXCEPT' will be defined only when 'feclearexcept()',
    65    * 'fegetexceptflag()', 'feraiseexcept()', 'fesetexceptflag()' and
    66    * 'fetestexcept()' functions are supported by the architecture.
     67   * fegetexceptflag() , feraiseexcept(), fesetexceptflag() and
     68   * fetestexcept() functions are supported by the architecture.
    6769   * Hence their testcases can be wrapped under #ifdef and #endif.
    6870   */
    6971  #ifdef FE_ALL_EXCEPT /* floating-point exceptions */
    70     puts( "fesetenv(FE_DFL_ENV)." );
    71     r = fesetenv(FE_DFL_ENV);
    72     if (r)
    73       printf("fesetenv ==> %d\n", r);
     72    r = fesetenv( FE_DFL_ENV );
     73    if ( r ) {
     74      printf( "fesetenv ==> %d\n", r);
     75    }
    7476    rtems_test_assert( r == 0 );
    7577
    76     /* Test 'feclearexcept()' and 'fetestexcept()' in one go. */
    77     puts( "feclearexcept(FE_ALL_EXCEPT)." );
    78     r = feclearexcept(FE_ALL_EXCEPT);
    79     if (r)
    80       printf("feclearexcept ==> 0x%x\n", r);
     78    /* Test feclearexcept() and fetestexcept() in one go. */
     79    r = feclearexcept( FE_ALL_EXCEPT );
     80    if ( r ) {
     81      printf( "feclearexcept ==> 0x%x\n", r );
     82    }
    8183    rtems_test_assert( r == 0 );
    8284
    8385    r = fetestexcept( FE_ALL_EXCEPT );
    84     if (r)
    85       printf("fetestexcept ==> 0x%x\n", r);
     86    if ( r ) {
     87      printf( "fetestexcept ==> 0x%x\n", r );
     88    }
    8689    rtems_test_assert( r == 0 );
    8790
    88     /* Test 'FE_DIVBYZERO' */
    89     puts( "Divide by zero and confirm fetestexcept()" );
     91    /* Test 'FE_DIVBYZERO'
     92     * Divide by zero and confirm fetestexcept() */
    9093    a = 0.0;
    9194    b = 1.0;
    9295    c = b/a;
    9396    (void) c;
     97    /* Test fegetexceptflag() and fesetexceptflag() */
     98    r = fegetexceptflag( &excepts, FE_ALL_EXCEPT );
     99    if ( r ) {
     100      printf( "fegetexceptflag ==> 0x%x\n", r );
     101    }
     102    rtems_test_assert( r == 0 );
    94103
    95     fegetexceptflag(&excepts,FE_ALL_EXCEPT);
     104    r = fesetexceptflag( &excepts, FE_ALL_EXCEPT );
     105    if ( r ) {
     106      printf( "fesetexceptflag ==> 0x%x\n", r );
     107    }
     108    rtems_test_assert( r == 0 );
    96109
    97 #ifdef FE_DIVBYZERO
    98     r = feraiseexcept(FE_DIVBYZERO);
     110    /* Test for fegetround() and fesetround()
     111     * They have four main macros to be tested separated by ifdef
     112     * Since not all architectures support them
     113     * The test case gets and sets the rounding directions */
     114  #ifdef FE_TONEAREST /* Rounding direction TONEAREST */
     115    rtems_test_assert( fegetround() == FE_TONEAREST );
     116  #endif /*rounding direction TONEAREST */
     117  #ifdef FE_TOWARDZERO /* rounding direction TOWARDZERO */
     118    r = fesetround( FE_TOWARDZERO );
     119    if ( r ) {
     120      printf( "fesetround ==> 0x%x\n", r );
     121    }
     122    rtems_test_assert( r == 0 );
     123    rtems_test_assert( fegetround() == FE_TOWARDZERO );
     124  #endif/*rounding direction TOWARDZERO */
     125  #ifdef FE_DOWNWARD /* rounding direction DOWNWARD */
     126    r = fesetround( FE_DOWNWARD );
     127    if ( r ) {
     128      printf( "fesetround ==> 0x%x\n", r );
     129    }
     130    rtems_test_assert( r == 0 );
     131    rtems_test_assert( fegetround() == FE_DOWNWARD );
     132  #endif /* rounding direction DOWNWARD */
     133  #ifdef FE_UPWARD /* rounding direction UPWARD */
     134    r = fesetround( FE_UPWARD );
     135    if ( r ) {
     136      printf( "fesetround ==> 0x%x\n", r );
     137    }
     138    rtems_test_assert( r == 0 );
     139    rtems_test_assert( fegetround() == FE_UPWARD );
     140  #endif /* rounding direction upward */
     141  #ifdef FE_TONEAREST /* rounding direction TONEAREST */
     142    r = fesetround( FE_TONEAREST );
     143    if ( r ) {
     144      printf( "fesetround ==> 0x%x\n", r );
     145    }
     146    rtems_test_assert( r == 0 );
     147  #endif /* rounding direction TONEAREST */
     148
     149  #ifdef FE_DIVBYZERO /* divide by zero exeption */
     150    r = feraiseexcept( FE_DIVBYZERO ) ;
    99151    rtems_test_assert( fetestexcept( FE_DIVBYZERO ) );
    100 #endif
     152  #endif /* divide by zero exeption */
    101153
    102154    /* Test 'FE_INEXACT' */
  • testsuites/psxtests/psxfenv01/psxfenv01.scn

    rbd750c9e re845873  
    11*** BEGIN OF TEST PSXFENV 01 ***
    2 fesetenv(FE_DFL_ENV).
    3 feclearexcept(FE_ALL_EXCEPT).
    4 Divide by zero and confirm fetestexcept()
    5 
    62*** END OF TEST PSXFENV 01 ***
    73
Note: See TracChangeset for help on using the changeset viewer.