test-fesetexcept-traps.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Test fesetexcept: exception traps enabled.
  2. Copyright (C) 2016-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <fenv.h>
  16. #include <stdio.h>
  17. #include <math-tests.h>
  18. static int
  19. do_test (void)
  20. {
  21. int result = 0;
  22. fedisableexcept (FE_ALL_EXCEPT);
  23. int ret = feenableexcept (FE_ALL_EXCEPT);
  24. if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (ret == -1))
  25. {
  26. puts ("feenableexcept (FE_ALL_EXCEPT) not supported, cannot test");
  27. return 77;
  28. }
  29. else if (ret != 0)
  30. {
  31. puts ("feenableexcept (FE_ALL_EXCEPT) failed");
  32. result = 1;
  33. return result;
  34. }
  35. if (EXCEPTION_SET_FORCES_TRAP)
  36. {
  37. puts ("setting exceptions traps, cannot test on this architecture");
  38. return 77;
  39. }
  40. /* Verify fesetexcept does not cause exception traps. */
  41. ret = fesetexcept (FE_ALL_EXCEPT);
  42. if (ret == 0)
  43. puts ("fesetexcept (FE_ALL_EXCEPT) succeeded");
  44. else
  45. {
  46. puts ("fesetexcept (FE_ALL_EXCEPT) failed");
  47. if (EXCEPTION_TESTS (float))
  48. {
  49. puts ("failure of fesetexcept was unexpected");
  50. result = 1;
  51. }
  52. else
  53. puts ("failure of fesetexcept OK");
  54. }
  55. feclearexcept (FE_ALL_EXCEPT);
  56. return result;
  57. }
  58. #define TEST_FUNCTION do_test ()
  59. #include "../test-skeleton.c"