1 //===-- Unittests for feclearexcept, feraiseexcept, fetestexpect ----------===//
2 //===-- and fesetexcept ---------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #include "src/fenv/feclearexcept.h"
11 #include "src/fenv/feraiseexcept.h"
12 #include "src/fenv/fesetexcept.h"
13 #include "src/fenv/fetestexcept.h"
15 #include "src/__support/FPUtil/FEnvImpl.h"
16 #include "test/UnitTest/FEnvSafeTest.h"
17 #include "test/UnitTest/Test.h"
19 #include "hdr/fenv_macros.h"
23 using LlvmLibcExceptionStatusTest
= LIBC_NAMESPACE::testing::FEnvSafeTest
;
25 TEST_F(LlvmLibcExceptionStatusTest
, RaiseAndTest
) {
26 // This test raises a set of exceptions and checks that the exception
27 // status flags are updated. The intention is really not to invoke the
28 // exception handler. Hence, we will disable all exceptions at the
30 LIBC_NAMESPACE::fputil::disable_except(FE_ALL_EXCEPT
);
32 for (int e
: EXCEPTS
) {
33 int r
= LIBC_NAMESPACE::feraiseexcept(e
);
35 int s
= LIBC_NAMESPACE::fetestexcept(e
);
38 r
= LIBC_NAMESPACE::feclearexcept(e
);
40 s
= LIBC_NAMESPACE::fetestexcept(e
);
43 r
= LIBC_NAMESPACE::fesetexcept(e
);
45 s
= LIBC_NAMESPACE::fetestexcept(e
);
49 for (int e1
: EXCEPTS
) {
50 for (int e2
: EXCEPTS
) {
52 int r
= LIBC_NAMESPACE::feraiseexcept(e
);
54 int s
= LIBC_NAMESPACE::fetestexcept(e
);
57 r
= LIBC_NAMESPACE::feclearexcept(e
);
59 s
= LIBC_NAMESPACE::fetestexcept(e
);
62 r
= LIBC_NAMESPACE::fesetexcept(e
);
64 s
= LIBC_NAMESPACE::fetestexcept(e
);
69 for (int e1
: EXCEPTS
) {
70 for (int e2
: EXCEPTS
) {
71 for (int e3
: EXCEPTS
) {
73 int r
= LIBC_NAMESPACE::feraiseexcept(e
);
75 int s
= LIBC_NAMESPACE::fetestexcept(e
);
78 r
= LIBC_NAMESPACE::feclearexcept(e
);
80 s
= LIBC_NAMESPACE::fetestexcept(e
);
83 r
= LIBC_NAMESPACE::fesetexcept(e
);
85 s
= LIBC_NAMESPACE::fetestexcept(e
);
91 for (int e1
: EXCEPTS
) {
92 for (int e2
: EXCEPTS
) {
93 for (int e3
: EXCEPTS
) {
94 for (int e4
: EXCEPTS
) {
95 int e
= e1
| e2
| e3
| e4
;
96 int r
= LIBC_NAMESPACE::feraiseexcept(e
);
98 int s
= LIBC_NAMESPACE::fetestexcept(e
);
101 r
= LIBC_NAMESPACE::feclearexcept(e
);
103 s
= LIBC_NAMESPACE::fetestexcept(e
);
106 r
= LIBC_NAMESPACE::fesetexcept(e
);
108 s
= LIBC_NAMESPACE::fetestexcept(e
);
115 for (int e1
: EXCEPTS
) {
116 for (int e2
: EXCEPTS
) {
117 for (int e3
: EXCEPTS
) {
118 for (int e4
: EXCEPTS
) {
119 for (int e5
: EXCEPTS
) {
120 int e
= e1
| e2
| e3
| e4
| e5
;
121 int r
= LIBC_NAMESPACE::feraiseexcept(e
);
123 int s
= LIBC_NAMESPACE::fetestexcept(e
);
126 r
= LIBC_NAMESPACE::feclearexcept(e
);
128 s
= LIBC_NAMESPACE::fetestexcept(e
);
131 r
= LIBC_NAMESPACE::fesetexcept(e
);
133 s
= LIBC_NAMESPACE::fetestexcept(e
);
141 int r
= LIBC_NAMESPACE::feraiseexcept(ALL_EXCEPTS
);
143 int s
= LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS
);
144 ASSERT_EQ(s
, ALL_EXCEPTS
);
146 r
= LIBC_NAMESPACE::fesetexcept(ALL_EXCEPTS
);
148 s
= LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS
);
149 ASSERT_EQ(s
, ALL_EXCEPTS
);