From 073a9080f3cc34151d53fb314ea032e36f90a98f Mon Sep 17 00:00:00 2001 From: maier Date: Sun, 15 Dec 2013 15:23:40 +0000 Subject: [PATCH] Testsuite: Override the tbb assertion handler when TBB_DO_ASSERT is set. The override does print the original tbb error message and after that reenables abort_on_exception and show_stacktrace and emits a deal.II exception. git-svn-id: https://svn.dealii.org/trunk@32017 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/tests.h | 110 +++++++++++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 42 deletions(-) diff --git a/tests/tests.h b/tests/tests.h index 76ceab1f2e..c961df8192 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -85,6 +85,8 @@ void srand(int seed) throw() } } + + // given the name of a file, copy it to deallog // and then delete it inline void cat_file(const char *filename) @@ -104,6 +106,7 @@ inline void cat_file(const char *filename) } + #ifdef DEAL_II_WITH_PETSC #include @@ -119,17 +122,18 @@ inline void check_petsc_allocations() bool errors = false; for (int i=0;istageInfo->classLog->numClasses;++i) { - if (stageLog->stageInfo->classLog->classInfo[i].destructions - != stageLog->stageInfo->classLog->classInfo[i].creations) - { - errors = true; - std::cerr << "ERROR: PETSc objects leaking of type '" - << stageLog->classLog->classInfo[i].name << "'" - << " with " << stageLog->stageInfo->classLog->classInfo[i].creations - << " creations and only " - << stageLog->stageInfo->classLog->classInfo[i].destructions - << " destructions." << std::endl; - } + if (stageLog->stageInfo->classLog->classInfo[i].destructions != + stageLog->stageInfo->classLog->classInfo[i].creations) + { + errors = true; + std::cerr << "ERROR: PETSc objects leaking of type '" + << stageLog->classLog->classInfo[i].name << "'" + << " with " + << stageLog->stageInfo->classLog->classInfo[i].creations + << " creations and only " + << stageLog->stageInfo->classLog->classInfo[i].destructions + << " destructions." << std::endl; + } } if (errors) @@ -278,11 +282,11 @@ struct MPILogInitAll void sort_file_contents (const std::string &filename) { int error = std::system ((std::string ("LC_ALL=C sort ") + filename + " -o " + filename).c_str()); - Assert (error == 0, - ExcInternalError()); + Assert (error == 0, ExcInternalError()); } + /* * Replace all occurences of ' &' by '& ' from the given file to hopefully be * more compiler independent with respect to __PRETTY_FUNCTION__ @@ -292,25 +296,19 @@ void sort_file_contents (const std::string &filename) */ void unify_pretty_function (const std::string &filename) { - int error = std::system ((std::string ("sed -i -e 's/ \\&/ \\& /g' -e 's/ & ,/\\&,/g' -e 's/ \\& )/\\&)/g' -e 's/ \\& /\\& /g' -e 's/^DEAL::virtual /DEAL::/g' ") + filename).c_str()); - Assert (error == 0, - ExcInternalError()); - + Assert (error == 0, ExcInternalError()); } +DEAL_II_NAMESPACE_OPEN +/* + * Now, change some global behaviour of deal.II and supporting libraries: + */ +/* Disable stack traces: */ - -#ifndef DEAL_II_STACKTRACE_SWITCH -#define DEAL_II_STACKTRACE_SWITCH - -// A structure and a variable that are used to make sure that we do -// not show a stacktrace in out testcases, since this would lead to -// trouble with automatic comparison of output against a fixed -// baseline struct SwitchOffStacktrace { SwitchOffStacktrace () @@ -319,46 +317,74 @@ struct SwitchOffStacktrace } } deal_II_stacktrace_dummy; -#endif -DEAL_II_NAMESPACE_OPEN +/* Set grainsizes for parallel mode smaller than they would otherwise be. + * This is used to test that the parallel algorithms in lac/ work alright: + */ + namespace internal { - namespace Vector { - extern unsigned int minimum_parallel_grain_size; - } - namespace SparseMatrix { - extern unsigned int minimum_parallel_grain_size; - } - } -// A structure and a variable that are used to set grainsizes for parallel -// mode smaller than they would otherwise be. this is used to test that the -// parallel algorithms in lac/ work alright. struct SetGrainSizes { - SetGrainSizes () { - internal::Vector::minimum_parallel_grain_size = 2; - internal::SparseMatrix::minimum_parallel_grain_size = 2; - } +} set_grain_sizes; + +/* Override the tbb assertion handler in order to print a stacktrace:*/ + +#ifdef TBB_DO_ASSERT + +#include + +namespace deal_II_exceptions +{ + extern bool abort_on_exception; + extern bool show_stacktrace; } -set_grain_sizes; + +void new_tbb_assertion_handler(const char *file, int line, const char *expr, + const char *comment) +{ + // Print out the original assertion message + std::cerr << "TBB assertion:" << std::endl; + std::cerr << "Assertion " << expr << " failed on line " << line << " of file " + << file << std::endl; + std::cerr << "Detailed description: " << comment << std::endl; + + // Reenable abort and stacktraces: + deal_II_exceptions::abort_on_exception = true; + deal_II_exceptions::show_stacktrace = true; + + // And abort with a deal.II exception: + Assert(false, ExcMessage("TBB Exception, see above")); +} + +struct SetTBBAssertionHandler +{ + SetTBBAssertionHandler () + { + ::tbb::set_assertion_handler(new_tbb_assertion_handler); + } +} set_tbb_assertion_handler; + +#endif /*TBB_DO_ASSERT*/ + DEAL_II_NAMESPACE_CLOSE + #endif // __tests_tests_h -- 2.39.5