56 "name",
"evaluated",
"failed",
"description"
65 "name",
"evaluated",
"expectedFlags",
"failed"
74 "name",
"thrown",
"correctType",
"failed"
94 std::map<std::string, std::vector<assert_result>> assertResults {};
97 std::map<std::string, std::vector<errno_result>> errnoResults {};
100 std::map<std::string, std::vector<exception_result>> exceptionResults {};
103 bool wasTerminated {
false};
112 std::shared_ptr<output::output_context>
output;
116 std::shared_ptr<random::random_context>
random;
126 const std::string& moduleName,
127 int argc = 0,
const char** argv =
nullptr) {
131 output = std::make_shared<output::output_context>();
132 random = std::make_shared<random::random_context>();
135 for (
int i = 1; i < argc; ++i)
136 settings.pickedChecks[argv[i]] =
true;
138 output->info(
"Starting error checking on the " + moduleName +
" module ...");
141 wasTerminated =
false;
151 unsigned int failedChecks = 0;
152 unsigned int totalChecks = 0;
154 for (
const auto& pair : assertResults) {
155 for (
const auto& testCase : pair.second) {
157 failedChecks += testCase.failed ? 1 : 0;
161 for (
const auto& pair : errnoResults) {
162 for (
const auto& testCase : pair.second) {
164 failedChecks += testCase.failed ? 1 : 0;
168 for (
const auto& pair : exceptionResults) {
169 for (
const auto& testCase : pair.second) {
171 failedChecks += testCase.failed ? 1 : 0;
177 !
output->settings.outputFiles.size() &&
178 !
settings.assertOutputFiles.size() &&
179 !
settings.errnoOutputFiles.size() &&
180 !
settings.exceptionOutputFiles.size() &&
186 std::vector<std::string> outputFiles;
222 settings.exceptionOutputFiles.begin(),
234 double percent = totalChecks > 0 ? (failedChecks / (double) totalChecks) * 100 : 0.0;
235 output->info(
"Finished error checking on the " +
settings.moduleName +
" module ...");
237 std::to_string(totalChecks) +
" total checks, " + std::to_string(failedChecks) +
238 " failed (" + std::to_string(percent).substr(0, 4) +
"%)"
241 if (totalChecks == 0)
242 output->warn(
"No checks were executed!");
246 std::exit(failedChecks);
249 wasTerminated =
true;
255 std::string moduleName,
257 const char** argv =
nullptr) {
259 setup(moduleName, argc, argv);
276 const std::string& name,
278 std::string description =
"",
279 bool quiet =
false) {
281 output->debug(
"Checking assertion: " + name);
290 assertResults[name].push_back(res);
300 template<
typename Function,
typename InputType>
302 const std::string& name,
306 bool quiet =
false) {
308 output->debug(
"Checking errno value for: " + name);
314 volatile auto r = f(x);
321 res.
failed = (errno != expected_errno);
324 errnoResults[name].push_back(res);
334 template<
typename Function,
typename InputType>
336 const std::string& name, Function f,
337 std::function<InputType()> generator,
339 bool quiet =
false) {
341 errno_value(name, f, generator(), expected_errno, quiet);
353 template<
typename Function,
typename InputType>
355 const std::string& name,
358 std::vector<int>& expected_flags,
359 bool quiet =
false) {
361 output->debug(
"Checking errno flags for: " + name);
367 volatile auto r = f(x);
377 for (
int flag : expected_flags)
381 errnoResults[name].push_back(res);
393 template<
typename Function,
typename InputType>
395 const std::string& name, Function f,
396 std::function<InputType()> generator,
397 std::vector<int>& expected_flags,
398 bool quiet =
false) {
400 errno_flags(name, f, generator(), expected_flags, quiet);
410 template<
typename Function,
typename InputType>
412 const std::string& name,
415 bool quiet =
false) {
417 output->debug(
"Checking exception for: " + name);
423 volatile auto r = f(x);
435 exceptionResults[name].push_back(res);
445 template<
typename Function,
typename InputType>
447 const std::string& name, Function f,
448 std::function<InputType()> generator,
449 bool quiet =
false) {
451 throws(name, f, generator(), quiet);
462 typename ExceptionType,
467 const std::string& name,
470 bool quiet =
false) {
472 output->debug(
"Checking exception for: " + name);
476 bool correctType =
false;
479 volatile auto r = f(x);
481 }
catch(ExceptionType& exc) {
492 res.
failed = !(thrown && correctType);
496 exceptionResults[name].push_back(res);
508 typename ExceptionType,
513 const std::string& name, Function f,
514 std::function<InputType()> generator,
515 bool quiet =
false) {
517 throws(name, f, generator(), quiet);
523 return assertResults[name];
529 return assertResults[name].at(i);
534 inline std::vector<errno_result>
get_errno(
const std::string& name) {
535 return errnoResults[name];
541 return errnoResults[name].at(i);
546 inline std::vector<exception_result>
get_exception(
const std::string& name) {
547 return exceptionResults[name];
553 return exceptionResults[name].at(i);
565 int argc = 0,
const char** argv =
nullptr) {
Error checking context, for assertions and exception checking.
Definition err.h:90
void errno_value(const std::string &name, Function f, InputType x, int expected_errno, bool quiet=false)
Check errno value after function call.
Definition err.h:301
void errno_flags(const std::string &name, Function f, InputType x, std::vector< int > &expected_flags, bool quiet=false)
Check the value of errno after a function call, comparing to multiple expected flags which should all...
Definition err.h:354
std::vector< errno_result > get_errno(const std::string &name)
Get the results of errno checking by name or label.
Definition err.h:534
err_context(std::string moduleName, int argc=0, const char **argv=nullptr)
Setup the error checking module.
Definition err.h:254
~err_context()
Terminate the error checking module.
Definition err.h:264
void setup(const std::string &moduleName, int argc=0, const char **argv=nullptr)
Setup error checking module.
Definition err.h:125
std::shared_ptr< random::random_context > random
Random module settings for the context, dynamically allocated and possibly shared between multiple co...
Definition err.h:116
std::vector< assert_result > get_assertion(const std::string &name)
Get the results of an assertion by name or label.
Definition err.h:522
errno_result get_errno(const std::string &name, unsigned int i)
Get a single result of errno checking by label and index.
Definition err.h:540
assert_result get_assertion(const std::string &name, unsigned int i)
Get a single result of an assertion by label and index.
Definition err.h:528
std::vector< exception_result > get_exception(const std::string &name)
Get the results of exception checking by name or label.
Definition err.h:546
void errno_flags(const std::string &name, Function f, std::function< InputType()> generator, std::vector< int > &expected_flags, bool quiet=false)
Check the value of errno after a function call, comparing to multiple expected flags which should all...
Definition err.h:394
err_settings settings
Settings for the benchmark context.
Definition err.h:108
std::shared_ptr< output::output_context > output
Output module settings for the context, dynamically allocated and possibly shared between multiple co...
Definition err.h:112
exception_result get_exception(const std::string &name, unsigned int i)
Get a single result of exception checking by label and index.
Definition err.h:552
void errno_value(const std::string &name, Function f, std::function< InputType()> generator, int expected_errno, bool quiet=false)
Check errno value after function call.
Definition err.h:335
void terminate(bool exit=false)
Terminate the error testing environment.
Definition err.h:149
void assert(const std::string &name, bool exp, std::string description="", bool quiet=false)
Assert that an expression is true.
Definition err.h:275
Common definitions for the framework.
Structures for the error checking module.
err_context make_context(const std::string &moduleName, int argc=0, const char **argv=nullptr)
Construct an error checking context with the given parameters.
Definition err.h:564
General namespace of the framework.
Definition benchmark.h:22
The output module, with formatting capabilities.
The pseudorandom number generation and sampling module.
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
bool evaluated
Evaluated boolean value.
Definition err_structures.h:27
bool quiet
Whether to print to standard output or not.
Definition err_structures.h:36
bool failed
Whether the test failed.
Definition err_structures.h:33
std::string description
Description of the assertion.
Definition err_structures.h:30
Settings of the error testing module, used in err_context.
Definition err.h:39
std::vector< std::string > outputFiles
The files to write all error checking results to.
Definition err.h:48
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:52
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:70
std::vector< std::string > assertColumns
Default columns to print for assertions.
Definition err.h:55
std::vector< std::string > exceptionColumns
Default columns to print for exception checks.
Definition err.h:73
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:80
std::string moduleName
Name of the module being tested.
Definition err.h:42
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:61
std::vector< std::string > errnoColumns
Default columns to print for errno checks.
Definition err.h:64
bool quiet
Whether to print to standard output.
Definition err.h:83
bool outputToFile
Whether to print to an output file.
Definition err.h:45
Result of errno checking of a function.
Definition err_structures.h:42
int evaluated
Evaluated errno value.
Definition err_structures.h:48
std::string name
Identifying name of the function or test case.
Definition err_structures.h:45
std::vector< int > expectedFlags
Expected errno flags.
Definition err_structures.h:51
bool quiet
Whether to print to standard output or not.
Definition err_structures.h:57
bool failed
Whether the test failed.
Definition err_structures.h:54
Result of exception checking of a function.
Definition err_structures.h:63
bool thrown
Whether the function has thrown.
Definition err_structures.h:69
std::string name
Identifying name of the function or test case.
Definition err_structures.h:66
bool correctType
Whether the type of the thrown exception was correct.
Definition err_structures.h:73
bool quiet
Whether to print to standard output or not.
Definition err_structures.h:79
bool failed
Whether the test failed.
Definition err_structures.h:76