Skip to content

Commit ebfceca

Browse files
Ravenwaterclaude
andauthored
fix(dfloat,hfloat): add canonical regression test guards to all test files (#521)
All 18 dfloat and hfloat regression test files were missing the standard test skeleton pattern used throughout the codebase. Added: - MANUAL_TESTING guard with early EXIT_SUCCESS return - REGRESSION_LEVEL_OVERRIDE / REGRESSION_LEVEL_1..4 preprocessor block - ReportTestSuiteHeader() call replacing raw std::cout - reportTestCases defaulting to false (not true) - Existing test code placed in REGRESSION_LEVEL_1; empty L2/L3/L4 stubs Verified: 18/18 tests pass on both gcc and clang. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 3e07847 commit ebfceca

File tree

18 files changed

+729
-38
lines changed

18 files changed

+729
-38
lines changed

static/float/dfloat/api/api.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,42 @@
1111
#include <universal/number/dfloat/dfloat.hpp>
1212
#include <universal/verification/test_suite.hpp>
1313

14+
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
15+
#define MANUAL_TESTING 0
16+
// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity
17+
// It is the responsibility of the regression test to organize the tests in a quartile progression.
18+
//#undef REGRESSION_LEVEL_OVERRIDE
19+
#ifndef REGRESSION_LEVEL_OVERRIDE
20+
#undef REGRESSION_LEVEL_1
21+
#undef REGRESSION_LEVEL_2
22+
#undef REGRESSION_LEVEL_3
23+
#undef REGRESSION_LEVEL_4
24+
#define REGRESSION_LEVEL_1 1
25+
#define REGRESSION_LEVEL_2 1
26+
#define REGRESSION_LEVEL_3 1
27+
#define REGRESSION_LEVEL_4 1
28+
#endif
29+
1430
int main()
1531
try {
1632
using namespace sw::universal;
1733

1834
std::string test_suite = "dfloat<> Application Programming Interface tests";
35+
std::string test_tag = "dfloat<> API";
36+
bool reportTestCases = false;
1937
int nrOfFailedTestCases = 0;
2038

39+
ReportTestSuiteHeader(test_suite, reportTestCases);
40+
41+
#if MANUAL_TESTING
42+
// generate individual testcases to hand trace/debug
43+
44+
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
45+
return EXIT_SUCCESS; // ignore errors
46+
#else
47+
48+
#if REGRESSION_LEVEL_1
49+
2150
// important behavioral traits
2251
{
2352
using TestType = dfloat<7, 6>;
@@ -158,8 +187,21 @@ try {
158187
std::cout << "decimal32 min : " << std::numeric_limits<Real>::min() << '\n';
159188
}
160189

190+
#endif
191+
192+
#if REGRESSION_LEVEL_2
193+
#endif
194+
195+
#if REGRESSION_LEVEL_3
196+
#endif
197+
198+
#if REGRESSION_LEVEL_4
199+
#endif
200+
161201
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
162202
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
203+
204+
#endif // MANUAL_TESTING
163205
}
164206
catch (char const* msg) {
165207
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;

static/float/dfloat/arithmetic/addition.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,43 @@
88
#include <universal/number/dfloat/dfloat.hpp>
99
#include <universal/verification/test_suite.hpp>
1010

11+
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
12+
#define MANUAL_TESTING 0
13+
// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity
14+
// It is the responsibility of the regression test to organize the tests in a quartile progression.
15+
//#undef REGRESSION_LEVEL_OVERRIDE
16+
#ifndef REGRESSION_LEVEL_OVERRIDE
17+
#undef REGRESSION_LEVEL_1
18+
#undef REGRESSION_LEVEL_2
19+
#undef REGRESSION_LEVEL_3
20+
#undef REGRESSION_LEVEL_4
1121
#define REGRESSION_LEVEL_1 1
1222
#define REGRESSION_LEVEL_2 1
13-
#define REGRESSION_LEVEL_3 0
14-
#define REGRESSION_LEVEL_4 0
23+
#define REGRESSION_LEVEL_3 1
24+
#define REGRESSION_LEVEL_4 1
25+
#endif
1526

1627
int main()
1728
try {
1829
using namespace sw::universal;
1930

2031
std::string test_suite = "dfloat<> addition validation";
32+
std::string test_tag = "dfloat<> addition";
33+
bool reportTestCases = false;
2134
int nrOfFailedTestCases = 0;
22-
bool reportTestCases = true;
35+
36+
ReportTestSuiteHeader(test_suite, reportTestCases);
2337

2438
using Decimal32 = dfloat<7, 6, DecimalEncoding::BID, uint32_t>;
2539

26-
std::cout << test_suite << '\n';
40+
#if MANUAL_TESTING
41+
// generate individual testcases to hand trace/debug
42+
43+
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
44+
return EXIT_SUCCESS; // ignore errors
45+
#else
46+
47+
#if REGRESSION_LEVEL_1
2748

2849
// Test 1: Basic addition
2950
std::cout << "+--------- Basic addition\n";
@@ -155,8 +176,21 @@ try {
155176
if (!r3.isnan()) { ++nrOfFailedTestCases; if (reportTestCases) std::cerr << "FAIL: NaN + 1 should be NaN\n"; }
156177
}
157178

179+
#endif
180+
181+
#if REGRESSION_LEVEL_2
182+
#endif
183+
184+
#if REGRESSION_LEVEL_3
185+
#endif
186+
187+
#if REGRESSION_LEVEL_4
188+
#endif
189+
158190
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
159191
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
192+
193+
#endif // MANUAL_TESTING
160194
}
161195
catch (char const* msg) {
162196
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;

static/float/dfloat/arithmetic/division.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,43 @@
88
#include <universal/number/dfloat/dfloat.hpp>
99
#include <universal/verification/test_suite.hpp>
1010

11+
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
12+
#define MANUAL_TESTING 0
13+
// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity
14+
// It is the responsibility of the regression test to organize the tests in a quartile progression.
15+
//#undef REGRESSION_LEVEL_OVERRIDE
16+
#ifndef REGRESSION_LEVEL_OVERRIDE
17+
#undef REGRESSION_LEVEL_1
18+
#undef REGRESSION_LEVEL_2
19+
#undef REGRESSION_LEVEL_3
20+
#undef REGRESSION_LEVEL_4
21+
#define REGRESSION_LEVEL_1 1
22+
#define REGRESSION_LEVEL_2 1
23+
#define REGRESSION_LEVEL_3 1
24+
#define REGRESSION_LEVEL_4 1
25+
#endif
26+
1127
int main()
1228
try {
1329
using namespace sw::universal;
1430

1531
std::string test_suite = "dfloat<> division validation";
32+
std::string test_tag = "dfloat<> division";
33+
bool reportTestCases = false;
1634
int nrOfFailedTestCases = 0;
17-
bool reportTestCases = true;
35+
36+
ReportTestSuiteHeader(test_suite, reportTestCases);
1837

1938
using Decimal32 = dfloat<7, 6, DecimalEncoding::BID, uint32_t>;
2039

21-
std::cout << test_suite << '\n';
40+
#if MANUAL_TESTING
41+
// generate individual testcases to hand trace/debug
42+
43+
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
44+
return EXIT_SUCCESS; // ignore errors
45+
#else
46+
47+
#if REGRESSION_LEVEL_1
2248

2349
// Test 1: Basic division
2450
std::cout << "+--------- Basic division\n";
@@ -96,8 +122,21 @@ try {
96122
if (!r3.isnan()) { ++nrOfFailedTestCases; if (reportTestCases) std::cerr << "FAIL: NaN / 1 should be NaN\n"; }
97123
}
98124

125+
#endif
126+
127+
#if REGRESSION_LEVEL_2
128+
#endif
129+
130+
#if REGRESSION_LEVEL_3
131+
#endif
132+
133+
#if REGRESSION_LEVEL_4
134+
#endif
135+
99136
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
100137
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
138+
139+
#endif // MANUAL_TESTING
101140
}
102141
catch (char const* msg) {
103142
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;

static/float/dfloat/arithmetic/multiplication.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,43 @@
88
#include <universal/number/dfloat/dfloat.hpp>
99
#include <universal/verification/test_suite.hpp>
1010

11+
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
12+
#define MANUAL_TESTING 0
13+
// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity
14+
// It is the responsibility of the regression test to organize the tests in a quartile progression.
15+
//#undef REGRESSION_LEVEL_OVERRIDE
16+
#ifndef REGRESSION_LEVEL_OVERRIDE
17+
#undef REGRESSION_LEVEL_1
18+
#undef REGRESSION_LEVEL_2
19+
#undef REGRESSION_LEVEL_3
20+
#undef REGRESSION_LEVEL_4
21+
#define REGRESSION_LEVEL_1 1
22+
#define REGRESSION_LEVEL_2 1
23+
#define REGRESSION_LEVEL_3 1
24+
#define REGRESSION_LEVEL_4 1
25+
#endif
26+
1127
int main()
1228
try {
1329
using namespace sw::universal;
1430

1531
std::string test_suite = "dfloat<> multiplication validation";
32+
std::string test_tag = "dfloat<> multiplication";
33+
bool reportTestCases = false;
1634
int nrOfFailedTestCases = 0;
17-
bool reportTestCases = true;
35+
36+
ReportTestSuiteHeader(test_suite, reportTestCases);
1837

1938
using Decimal32 = dfloat<7, 6, DecimalEncoding::BID, uint32_t>;
2039

21-
std::cout << test_suite << '\n';
40+
#if MANUAL_TESTING
41+
// generate individual testcases to hand trace/debug
42+
43+
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
44+
return EXIT_SUCCESS; // ignore errors
45+
#else
46+
47+
#if REGRESSION_LEVEL_1
2248

2349
// Test 1: Basic multiplication
2450
std::cout << "+--------- Basic multiplication\n";
@@ -97,8 +123,21 @@ try {
97123
if (!r3.isnan()) { ++nrOfFailedTestCases; if (reportTestCases) std::cerr << "FAIL: NaN * 1 should be NaN\n"; }
98124
}
99125

126+
#endif
127+
128+
#if REGRESSION_LEVEL_2
129+
#endif
130+
131+
#if REGRESSION_LEVEL_3
132+
#endif
133+
134+
#if REGRESSION_LEVEL_4
135+
#endif
136+
100137
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
101138
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
139+
140+
#endif // MANUAL_TESTING
102141
}
103142
catch (char const* msg) {
104143
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;

static/float/dfloat/arithmetic/subtraction.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,43 @@
88
#include <universal/number/dfloat/dfloat.hpp>
99
#include <universal/verification/test_suite.hpp>
1010

11+
// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override
12+
#define MANUAL_TESTING 0
13+
// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity
14+
// It is the responsibility of the regression test to organize the tests in a quartile progression.
15+
//#undef REGRESSION_LEVEL_OVERRIDE
16+
#ifndef REGRESSION_LEVEL_OVERRIDE
17+
#undef REGRESSION_LEVEL_1
18+
#undef REGRESSION_LEVEL_2
19+
#undef REGRESSION_LEVEL_3
20+
#undef REGRESSION_LEVEL_4
21+
#define REGRESSION_LEVEL_1 1
22+
#define REGRESSION_LEVEL_2 1
23+
#define REGRESSION_LEVEL_3 1
24+
#define REGRESSION_LEVEL_4 1
25+
#endif
26+
1127
int main()
1228
try {
1329
using namespace sw::universal;
1430

1531
std::string test_suite = "dfloat<> subtraction validation";
32+
std::string test_tag = "dfloat<> subtraction";
33+
bool reportTestCases = false;
1634
int nrOfFailedTestCases = 0;
17-
bool reportTestCases = true;
35+
36+
ReportTestSuiteHeader(test_suite, reportTestCases);
1837

1938
using Decimal32 = dfloat<7, 6, DecimalEncoding::BID, uint32_t>;
2039

21-
std::cout << test_suite << '\n';
40+
#if MANUAL_TESTING
41+
// generate individual testcases to hand trace/debug
42+
43+
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
44+
return EXIT_SUCCESS; // ignore errors
45+
#else
46+
47+
#if REGRESSION_LEVEL_1
2248

2349
// Test 1: Basic subtraction
2450
std::cout << "+--------- Basic subtraction\n";
@@ -66,8 +92,21 @@ try {
6692
}
6793
}
6894

95+
#endif
96+
97+
#if REGRESSION_LEVEL_2
98+
#endif
99+
100+
#if REGRESSION_LEVEL_3
101+
#endif
102+
103+
#if REGRESSION_LEVEL_4
104+
#endif
105+
69106
ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
70107
return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS);
108+
109+
#endif // MANUAL_TESTING
71110
}
72111
catch (char const* msg) {
73112
std::cerr << "Caught ad-hoc exception: " << msg << std::endl;

0 commit comments

Comments
 (0)