test-fexcept-traps.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Test fegetexceptflag and fesetexceptflag: 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 = feraiseexcept (FE_ALL_EXCEPT);
  24. if (ret != 0)
  25. {
  26. if (EXCEPTION_TESTS (float))
  27. {
  28. puts ("feraiseexcept (FE_ALL_EXCEPT) failed");
  29. result = 1;
  30. return result;
  31. }
  32. else
  33. {
  34. puts ("feraiseexcept (FE_ALL_EXCEPT) unsupported, cannot test");
  35. return 77;
  36. }
  37. }
  38. fexcept_t saved;
  39. ret = fegetexceptflag (&saved, FE_ALL_EXCEPT);
  40. if (ret != 0)
  41. {
  42. puts ("fegetexceptflag failed");
  43. result = 1;
  44. return result;
  45. }
  46. feclearexcept (FE_ALL_EXCEPT);
  47. ret = feenableexcept (FE_ALL_EXCEPT);
  48. if (!EXCEPTION_ENABLE_SUPPORTED (FE_ALL_EXCEPT) && (ret == -1))
  49. {
  50. puts ("feenableexcept (FE_ALL_EXCEPT) not supported, cannot test");
  51. return 77;
  52. }
  53. else if (ret != 0)
  54. {
  55. puts ("feenableexcept (FE_ALL_EXCEPT) failed");
  56. result = 1;
  57. }
  58. if (EXCEPTION_SET_FORCES_TRAP)
  59. {
  60. puts ("setting exceptions traps, cannot test on this architecture");
  61. return 77;
  62. }
  63. /* The test is that this does not cause exception traps. */
  64. ret = fesetexceptflag (&saved, FE_ALL_EXCEPT);
  65. if (ret != 0)
  66. {
  67. puts ("fesetexceptflag failed");
  68. result = 1;
  69. }
  70. feclearexcept (FE_ALL_EXCEPT);
  71. return result;
  72. }
  73. #define TEST_FUNCTION do_test ()
  74. #include "../test-skeleton.c"