-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtestFloatingPointExceptions.cpp
More file actions
81 lines (65 loc) · 1.85 KB
/
testFloatingPointExceptions.cpp
File metadata and controls
81 lines (65 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) 2021, Lawrence Livermore National Security, LLC and LvArray contributors.
* All rights reserved.
* See the LICENSE file for details.
* SPDX-License-Identifier: (BSD-3-Clause)
*/
// Source includes
#include "testFloatingPointExceptionsHelpers.hpp"
#include "system.hpp"
#include "system.hpp"
// TPL includes
#include <gtest/gtest.h>
// System includes
#include <fenv.h>
#include <cmath>
#include <float.h>
using namespace testFloatingPointExceptionsHelpers;
const char IGNORE_OUTPUT[] = ".*";
namespace LvArray
{
namespace testing
{
TEST( TestFloatingPointEnvironment, Underflow )
{
system::enableFloatingPointExceptions( FE_UNDERFLOW );
EXPECT_DEATH_IF_SUPPORTED( divide( DBL_MIN, 2 ), IGNORE_OUTPUT );
system::disableFloatingPointExceptions( FE_UNDERFLOW );
system::setFPE();
double fpnum = divide( DBL_MIN, 2 );
int fpclassification = std::fpclassify( fpnum );
EXPECT_NE( fpclassification, FP_SUBNORMAL );
}
TEST( TestFloatingPointEnvironment, DivideByZero )
{
system::setFPE();
EXPECT_DEATH_IF_SUPPORTED( divide( 1, 0 ), IGNORE_OUTPUT );
}
TEST( TestFloatingPointEnvironment, Overlow )
{
system::setFPE();
EXPECT_DEATH_IF_SUPPORTED( multiply( DBL_MAX, 2 ), IGNORE_OUTPUT );
}
TEST( TestFloatingPointEnvironment, Invalid )
{
system::setFPE();
EXPECT_DEATH_IF_SUPPORTED( invalid(), IGNORE_OUTPUT );
}
TEST( TestFloatingPointEnvironment, FloatingPointExceptionGuard )
{
system::setFPE();
{
system::FloatingPointExceptionGuard guard( FE_UNDERFLOW );
divide( DBL_MIN, 2 );
EXPECT_DEATH_IF_SUPPORTED( multiply( DBL_MAX, 2 ), IGNORE_OUTPUT );
}
}
} // namespace testing
} // namespace LvArray
// This is the default gtest main method. It is included for ease of debugging.
int main( int argc, char * * argv )
{
::testing::InitGoogleTest( &argc, argv );
int const result = RUN_ALL_TESTS();
return result;
}