brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.5 KiB · f39cf4e Raw
47 lines · cpp
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-exception6//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 17#include "excepts.h"18 19using LlvmLibcFEnvTest = LIBC_NAMESPACE::testing::FEnvSafeTest;20 21TEST_F(LlvmLibcFEnvTest, ClearTest) {22  LIBC_NAMESPACE::fputil::disable_except(FE_ALL_EXCEPT);23  LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);24 25  for (int e : EXCEPTS)26    ASSERT_EQ(LIBC_NAMESPACE::fputil::test_except(e), 0);27 28  LIBC_NAMESPACE::fputil::raise_except(FE_ALL_EXCEPT);29 30  for (int e1 : EXCEPTS) {31    for (int e2 : EXCEPTS) {32      for (int e3 : EXCEPTS) {33        for (int e4 : EXCEPTS) {34          for (int e5 : EXCEPTS) {35            // We clear one exception and test to verify that it was cleared.36            LIBC_NAMESPACE::feclearexcept(e1 | e2 | e3 | e4 | e5);37            ASSERT_EQ(38                LIBC_NAMESPACE::fputil::test_except(e1 | e2 | e3 | e4 | e5), 0);39            // After clearing, we raise the exception again.40            LIBC_NAMESPACE::fputil::raise_except(e1 | e2 | e3 | e4 | e5);41          }42        }43      }44    }45  }46}47