llvm-project/libc/test/src/fenv/feupdateenv_test.cpp
Roland McGrath 837dab96d6
[libc] Make fenv and math tests preserve fenv_t state (#89658)
This adds a new test fixture class FEnvSafeTest (usable as a base
class for other fixtures) that ensures each test doesn't perturb
the `fenv_t` state that the next test will start with.  It also
provides types and methods tests can use to explicitly wrap code
under test either to check that it doesn't perturb the state or
to save and restore the state around particular test code.

All the fenv and math tests are updated to use this so that none
can affect another.  Expectations that code under test and/or
tests themselves don't perturb state can be added later.
2024-04-23 13:21:25 -07:00

29 lines
1.0 KiB
C++

//===-- Unittests for feupdateenv -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "hdr/types/fenv_t.h"
#include "src/fenv/feupdateenv.h"
#include "src/__support/FPUtil/FEnvImpl.h"
#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/Test.h"
using LlvmLibcFEnvTest = LIBC_NAMESPACE::testing::FEnvSafeTest;
TEST_F(LlvmLibcFEnvTest, UpdateEnvTest) {
LIBC_NAMESPACE::fputil::disable_except(FE_ALL_EXCEPT);
LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT);
fenv_t env;
ASSERT_EQ(LIBC_NAMESPACE::fputil::get_env(&env), 0);
LIBC_NAMESPACE::fputil::set_except(FE_INVALID | FE_INEXACT);
ASSERT_EQ(LIBC_NAMESPACE::feupdateenv(&env), 0);
ASSERT_EQ(LIBC_NAMESPACE::fputil::test_except(FE_INVALID | FE_INEXACT),
FE_INVALID | FE_INEXACT);
}