Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libc / test / src / fenv / exception_status_test.cpp
blobfdf9421457866e6d729e1f944f75ec2a1dd1c45f
1 //===-- Unittests for feclearexcept, feraiseexcept, fetestexpect ----------===//
2 //===-- and fesetexcept ---------------------------------------------------===//
3 //
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
7 //
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"
21 #include "excepts.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
29 // beginning.
30 LIBC_NAMESPACE::fputil::disable_except(FE_ALL_EXCEPT);
32 for (int e : EXCEPTS) {
33 int r = LIBC_NAMESPACE::feraiseexcept(e);
34 ASSERT_EQ(r, 0);
35 int s = LIBC_NAMESPACE::fetestexcept(e);
36 ASSERT_EQ(s, e);
38 r = LIBC_NAMESPACE::feclearexcept(e);
39 ASSERT_EQ(r, 0);
40 s = LIBC_NAMESPACE::fetestexcept(e);
41 ASSERT_EQ(s, 0);
43 r = LIBC_NAMESPACE::fesetexcept(e);
44 ASSERT_EQ(r, 0);
45 s = LIBC_NAMESPACE::fetestexcept(e);
46 ASSERT_EQ(s, e);
49 for (int e1 : EXCEPTS) {
50 for (int e2 : EXCEPTS) {
51 int e = e1 | e2;
52 int r = LIBC_NAMESPACE::feraiseexcept(e);
53 ASSERT_EQ(r, 0);
54 int s = LIBC_NAMESPACE::fetestexcept(e);
55 ASSERT_EQ(s, e);
57 r = LIBC_NAMESPACE::feclearexcept(e);
58 ASSERT_EQ(r, 0);
59 s = LIBC_NAMESPACE::fetestexcept(e);
60 ASSERT_EQ(s, 0);
62 r = LIBC_NAMESPACE::fesetexcept(e);
63 ASSERT_EQ(r, 0);
64 s = LIBC_NAMESPACE::fetestexcept(e);
65 ASSERT_EQ(s, e);
69 for (int e1 : EXCEPTS) {
70 for (int e2 : EXCEPTS) {
71 for (int e3 : EXCEPTS) {
72 int e = e1 | e2 | e3;
73 int r = LIBC_NAMESPACE::feraiseexcept(e);
74 ASSERT_EQ(r, 0);
75 int s = LIBC_NAMESPACE::fetestexcept(e);
76 ASSERT_EQ(s, e);
78 r = LIBC_NAMESPACE::feclearexcept(e);
79 ASSERT_EQ(r, 0);
80 s = LIBC_NAMESPACE::fetestexcept(e);
81 ASSERT_EQ(s, 0);
83 r = LIBC_NAMESPACE::fesetexcept(e);
84 ASSERT_EQ(r, 0);
85 s = LIBC_NAMESPACE::fetestexcept(e);
86 ASSERT_EQ(s, 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);
97 ASSERT_EQ(r, 0);
98 int s = LIBC_NAMESPACE::fetestexcept(e);
99 ASSERT_EQ(s, e);
101 r = LIBC_NAMESPACE::feclearexcept(e);
102 ASSERT_EQ(r, 0);
103 s = LIBC_NAMESPACE::fetestexcept(e);
104 ASSERT_EQ(s, 0);
106 r = LIBC_NAMESPACE::fesetexcept(e);
107 ASSERT_EQ(r, 0);
108 s = LIBC_NAMESPACE::fetestexcept(e);
109 ASSERT_EQ(s, 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);
122 ASSERT_EQ(r, 0);
123 int s = LIBC_NAMESPACE::fetestexcept(e);
124 ASSERT_EQ(s, e);
126 r = LIBC_NAMESPACE::feclearexcept(e);
127 ASSERT_EQ(r, 0);
128 s = LIBC_NAMESPACE::fetestexcept(e);
129 ASSERT_EQ(s, 0);
131 r = LIBC_NAMESPACE::fesetexcept(e);
132 ASSERT_EQ(r, 0);
133 s = LIBC_NAMESPACE::fetestexcept(e);
134 ASSERT_EQ(s, e);
141 int r = LIBC_NAMESPACE::feraiseexcept(ALL_EXCEPTS);
142 ASSERT_EQ(r, 0);
143 int s = LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS);
144 ASSERT_EQ(s, ALL_EXCEPTS);
146 r = LIBC_NAMESPACE::fesetexcept(ALL_EXCEPTS);
147 ASSERT_EQ(r, 0);
148 s = LIBC_NAMESPACE::fetestexcept(ALL_EXCEPTS);
149 ASSERT_EQ(s, ALL_EXCEPTS);