xref: /aosp_15_r20/external/llvm-libc/test/src/fenv/feclearexcept_test.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- Unittests for feclearexcept with exceptions enabled ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "src/fenv/feclearexcept.h"
10 
11 #include "src/__support/FPUtil/FEnvImpl.h"
12 #include "test/UnitTest/FEnvSafeTest.h"
13 #include "test/UnitTest/Test.h"
14 
15 #include "hdr/fenv_macros.h"
16 #include <stdint.h>
17 
18 #include "excepts.h"
19 
20 using LlvmLibcFEnvTest = LIBC_NAMESPACE::testing::FEnvSafeTest;
21 
TEST_F(LlvmLibcFEnvTest,ClearTest)22 TEST_F(LlvmLibcFEnvTest, ClearTest) {
23   LIBC_NAMESPACE::fputil::disable_except(FE_ALL_EXCEPT);
24   LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
25 
26   for (int e : EXCEPTS)
27     ASSERT_EQ(LIBC_NAMESPACE::fputil::test_except(e), 0);
28 
29   LIBC_NAMESPACE::fputil::raise_except(FE_ALL_EXCEPT);
30 
31   for (int e1 : EXCEPTS) {
32     for (int e2 : EXCEPTS) {
33       for (int e3 : EXCEPTS) {
34         for (int e4 : EXCEPTS) {
35           for (int e5 : EXCEPTS) {
36             // We clear one exception and test to verify that it was cleared.
37             LIBC_NAMESPACE::feclearexcept(e1 | e2 | e3 | e4 | e5);
38             ASSERT_EQ(
39                 LIBC_NAMESPACE::fputil::test_except(e1 | e2 | e3 | e4 | e5), 0);
40             // After clearing, we raise the exception again.
41             LIBC_NAMESPACE::fputil::raise_except(e1 | e2 | e3 | e4 | e5);
42           }
43         }
44       }
45     }
46   }
47 }
48