6 #ifndef CHEBYSHEV_ERR_H
7 #define CHEBYSHEV_ERR_H
53 "name",
"evaluated",
"failed",
"description"
62 "name",
"evaluated",
"expectedFlags",
"failed"
71 "name",
"thrown",
"correctType",
"failed"
89 unsigned int totalChecks = 0;
113 const std::string& moduleName,
int argc = 0,
const char** argv =
nullptr) {
116 for (
int i = 1; i < argc; ++i)
117 settings.pickedChecks[argv[i]] =
true;
119 std::cout <<
"Starting error checking on "
120 << moduleName <<
" ..." << std::endl;
123 results.failedChecks = 0;
124 results.totalChecks = 0;
137 output::settings.quiet = settings.
quiet;
141 !output::settings.outputFiles.size() &&
142 !settings.assertOutputFiles.size() &&
143 !settings.errnoOutputFiles.size() &&
144 !settings.exceptionOutputFiles.size() &&
150 std::vector<std::string> outputFiles;
154 outputFiles.insert(outputFiles.end(), settings.assertOutputFiles.begin(), settings.assertOutputFiles.end());
161 outputFiles.insert(outputFiles.end(), settings.errnoOutputFiles.begin(), settings.errnoOutputFiles.end());
168 outputFiles.insert(outputFiles.end(), settings.exceptionOutputFiles.begin(), settings.exceptionOutputFiles.end());
173 std::cout <<
"Finished error checking " << settings.
moduleName <<
" ...\n";
174 std::cout << results.totalChecks
176 << results.failedChecks <<
" failed (" << std::setprecision(3)
177 << (results.failedChecks / (double) results.totalChecks * 100.0)
178 <<
"%)" << std::endl;
185 std::exit(results.failedChecks);
199 bool quiet =
false) {
206 res.description = description;
209 results.totalChecks++;
212 results.failedChecks++;
214 results.assertResults[name].push_back(res);
224 template<
typename Function,
typename InputType>
230 bool quiet =
false) {
236 volatile auto r = f(x);
241 res.evaluated = errno;
242 res.expectedFlags = { expected_errno };
243 res.failed = (errno != expected_errno);
246 results.totalChecks++;
249 results.failedChecks++;
251 results.errnoResults[name].push_back(res);
262 template<
typename Function,
typename InputType>
265 std::function<InputType()> generator,
267 bool quiet =
false) {
269 check_errno(name, f, generator(), expected_errno, quiet);
279 template<
typename Function,
typename InputType>
284 std::vector<int>& expected_flags,
285 bool quiet =
false) {
292 volatile auto r = f(x);
297 res.evaluated = errno;
298 res.expectedFlags = expected_flags;
302 for (
int flag : expected_flags)
306 results.totalChecks++;
309 results.failedChecks++;
311 results.errnoResults[name].push_back(res);
322 template<
typename Function,
typename InputType>
325 std::function<InputType()> generator,
326 std::vector<int>& expected_flags,
327 bool quiet =
false) {
329 check_errno(name, f, generator(), expected_flags, quiet);
338 template<
typename Function,
typename InputType>
343 bool quiet =
false) {
349 volatile auto r = f(x);
357 res.failed = !thrown;
358 res.correctType =
true;
361 results.totalChecks++;
363 results.failedChecks++;
365 results.exceptionResults[name].push_back(res);
375 template<
typename Function,
typename InputType>
378 std::function<InputType()> generator,
379 bool quiet =
false) {
391 template<
typename ExceptionType,
typename Function,
typename InputType>
396 bool quiet =
false) {
400 bool correctType =
false;
403 volatile auto r = f(x);
405 }
catch(ExceptionType& exc) {
416 res.failed = !(thrown && correctType);
417 res.correctType = correctType;
420 results.totalChecks++;
422 results.failedChecks++;
424 results.exceptionResults[name].push_back(res);
435 template<
typename ExceptionType,
typename Function,
typename InputType>
438 std::function<InputType()> generator,
439 bool quiet =
false) {
Common definitions for the framework.
Structures for the error checking module.
void setup(const std::string &moduleName, int argc=0, const char **argv=nullptr)
Setup error checking module.
Definition: err.h:112
void check_errno(const std::string &name, Function f, InputType x, int expected_errno, bool quiet=false)
Check errno value after function call.
Definition: err.h:225
void check_exception(const std::string &name, Function f, InputType x, bool quiet=false)
Check that an exception is thrown during a function call.
Definition: err.h:339
void terminate(bool exit=true)
Terminate the error testing environment.
Definition: err.h:135
void assert(const std::string &name, bool exp, std::string description="", bool quiet=false)
Assert that an expression is true.
Definition: err.h:195
void print_results(const std::map< std::string, std::vector< ResultType >> &results, const std::vector< std::string > &fields, const std::vector< std::string > &filenames)
Print the test results to standard output and output files with their given formats,...
Definition: output.h:907
void setup()
Setup printing to the output stream with default options.
Definition: output.h:539
void terminate()
Terminate the output module by closing all output files and resetting its settings.
Definition: output.h:598
std::string string(size_t length)
Generate a random string made of human-readable ASCII characters.
Definition: random.h:102
void setup(uint64_t seed=0)
Initialize the random module.
Definition: random.h:32
General namespace of the framework.
Definition: benchmark_structures.h:16
Vector exp(const Vector &v)
Parallel element-wise evaluation of the exp function.
Definition: parallel.h:179
The pseudorandom number generation and sampling module.
std::string moduleName
Name of the module currently being benchmarked.
Definition: benchmark.h:38
bool outputToFile
Whether to output results to a file.
Definition: benchmark.h:47
std::vector< std::string > outputFiles
The files to write all benchmark results to.
Definition: benchmark.h:50
bool quiet
Whether to print benchmark results to standard output.
Definition: benchmark.h:35
Result of assertion checking of a function.
Definition: err_structures.h:21
std::string name
Identifying name of the function or test case.
Definition: err_structures.h:24
error checking
Definition: err.h:86
std::map< std::string, std::vector< errno_result > > errnoResults
Results of checking errno.
Definition: err.h:98
unsigned int failedChecks
Number of failed checks.
Definition: err.h:92
std::map< std::string, std::vector< exception_result > > exceptionResults
Results of exception testing.
Definition: err.h:101
std::map< std::string, std::vector< assert_result > > assertResults
Results of checking assertions.
Definition: err.h:95
Global settings of the error testing module.
Definition: err.h:36
std::vector< std::string > outputFiles
The files to write all error checking results to.
Definition: err.h:45
std::vector< std::string > assertOutputFiles
The files to write assertion results results to (if empty, all results are output to a generic file).
Definition: err.h:49
std::vector< std::string > exceptionOutputFiles
The files to write exception results results to (if empty, all results are output to a generic file).
Definition: err.h:67
std::vector< std::string > assertColumns
Default columns to print for assertions.
Definition: err.h:52
std::vector< std::string > exceptionColumns
Default columns to print for exception checks.
Definition: err.h:70
std::map< std::string, bool > pickedChecks
Target checks marked for execution, can be picked by passing test case names by command line.
Definition: err.h:77
std::string moduleName
Name of the module being tested.
Definition: err.h:39
std::vector< std::string > errnoOutputFiles
The files to write errno checking results to (if empty, all results are output to a generic file).
Definition: err.h:58
std::vector< std::string > errnoColumns
Default columns to print for errno checks.
Definition: err.h:61
bool quiet
Whether to print to standard output.
Definition: err.h:80
bool outputToFile
Whether to print to an output file.
Definition: err.h:42
Result of errno checking of a function.
Definition: err_structures.h:42
Result of exception checking of a function.
Definition: err_structures.h:63