1 #include "catch2/catch.hpp" 11 #include <type_traits> 20 Hexable(
T const t) : t_(t) {}
21 operator T()
const {
return t_; }
40 CHECK(hexit(
getFPCW()) == hexit(right));
41 CHECK(hexit(static_cast<unsigned short int>(fpc.
getPrecision())) ==
42 hexit(right & fpControl_ALL_PREC));
43 CHECK(hexit(fpc.
getMask()) == hexit(right & FE_ALL_EXCEPT));
47 verify_report(std::ostringstream
const& os,
fpcw_t mask)
49 auto test_string = os.str();
50 auto const pos = test_string.rfind(
"DivByZero exception is ");
51 if (
pos != std::string::npos) {
53 "DivByZero exception is"s +
on_or_off((~mask) & FE_DIVBYZERO) +
54 "\tInvalid exception is" +
on_or_off((~mask) & FE_INVALID) +
55 "\tOverFlow exception is" +
on_or_off((~mask) & FE_OVERFLOW) +
56 "\tUnderFlow exception is" +
on_or_off((~mask) & FE_UNDERFLOW) +
'\n');
57 CHECK(test_string.substr(
pos) == ref);
64 verify_report(std::ostringstream
const& os)
73 struct StringMaker<Hexable<
T>> {
78 std::ostringstream out;
86 SCENARIO(
"We wish to affect the floating point control on our system")
88 GIVEN(
"An empty activity registry and simple parameter set")
93 ps.
put(
"reportSettings",
true);
99 auto const fpcw_def =
getFPCW();
100 auto const fpcw_ref = fpcw_def;
101 auto const fpcw_ref_dp =
102 (fpcw_ref & ~fpControl_ALL_PREC) | fpControl_DOUBLE_PREC;
104 static auto verify_cleanup = [fpcw_def, &
reg](
auto& fpc) {
106 compare_fpcw(fpc, fpcw_def,
"Checking final FP state against default"s);
109 WHEN(
"We want the basic configuration")
112 THEN(
"The configuration is unchanged except for double precision math.")
114 compare_fpcw(fpc, fpcw_ref_dp);
115 verify_report(tstream);
120 WHEN(
"We want to suppress divide-by-zero exceptions")
122 ps.
put(
"enableDivByZeroEx",
true);
124 THEN(
"The configuration shows suppressed divide-by-zero exceptions")
126 compare_fpcw(fpc, fpcw_ref_dp & ~FE_DIVBYZERO);
127 verify_report(tstream, FE_DIVBYZERO);
132 WHEN(
"We want to suppress \"invalid\" exceptions")
134 ps.
put(
"enableInvalidEx",
true);
136 THEN(
"The configuration shows suppressed \"invalid\" exceptions")
138 compare_fpcw(fpc, fpcw_ref_dp & ~FE_INVALID);
139 verify_report(tstream, FE_INVALID);
144 WHEN(
"We want to suppress overflow exceptions")
146 ps.
put(
"enableOverFlowEx",
true);
148 THEN(
"The configuration shows suppressed overflow exceptions")
150 compare_fpcw(fpc, fpcw_ref_dp & ~FE_OVERFLOW);
151 verify_report(tstream, FE_OVERFLOW);
156 WHEN(
"We want to suppress underflow exceptions")
158 ps.
put(
"enableUnderFlowEx",
true);
160 THEN(
"The configuration shows suppressed underflow exceptions")
162 compare_fpcw(fpc, fpcw_ref_dp & ~FE_UNDERFLOW);
163 verify_report(tstream, FE_UNDERFLOW);
168 WHEN(
"We want default precision")
170 ps.
put(
"setPrecisionDouble",
false);
172 THEN(
"The configuration shows default precision")
174 compare_fpcw(fpc, fpcw_ref);
175 verify_report(tstream);
void msg(const char *fmt,...)
GlobalSignal< detail::SignalResponseType::LIFO, void()> sPostEndJob
QTextStream & hex(QTextStream &s)
std::ostringstream & getStringStream(std::string const &psetName)
precision_t getPrecision() const
char const * on_or_off(bool const b)
static std::string convert(T const t)
static constexpr double ps
cet::registry_via_id< success_t, val > reg
void put(std::string const &key)
SCENARIO("We wish to affect the floating point control on our system")