#include "src/fenv/fegetexceptflag.h"
#include "src/fenv/fesetexceptflag.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "utils/UnitTest/Test.h"
#include <fenv.h>
TEST(LlvmLibcFenvTest, GetExceptFlagAndSetExceptFlag) {
__llvm_libc::fputil::disable_except(FE_ALL_EXCEPT);
__llvm_libc::fputil::clear_except(FE_ALL_EXCEPT);
int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW,
FE_UNDERFLOW};
for (int e : excepts) {
__llvm_libc::fputil::raise_except(e);
ASSERT_NE(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0);
fexcept_t eflags;
ASSERT_EQ(__llvm_libc::fegetexceptflag(&eflags, FE_ALL_EXCEPT), 0);
__llvm_libc::fputil::clear_except(e);
ASSERT_EQ(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0);
ASSERT_EQ(__llvm_libc::fesetexceptflag(&eflags, FE_ALL_EXCEPT), 0);
ASSERT_NE(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT) & e, 0);
__llvm_libc::fputil::clear_except(FE_ALL_EXCEPT);
}
__llvm_libc::fputil::raise_except(FE_INVALID);
fexcept_t eflags;
__llvm_libc::fegetexceptflag(&eflags, FE_ALL_EXCEPT);
__llvm_libc::fputil::clear_except(FE_ALL_EXCEPT);
__llvm_libc::fputil::raise_except(FE_OVERFLOW | FE_INEXACT);
__llvm_libc::fesetexceptflag(&eflags, FE_ALL_EXCEPT);
EXPECT_EQ(__llvm_libc::fputil::test_except(FE_ALL_EXCEPT), FE_INVALID);
}