From: Wolfgang Bangerth Date: Wed, 30 Apr 2014 12:04:32 +0000 (+0000) Subject: Reshuffle and sort the contents of this file. X-Git-Tag: v8.2.0-rc1~531 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddb42b66082883cf2d90810fbc8a466417b3ec4d;p=dealii.git Reshuffle and sort the contents of this file. git-svn-id: https://svn.dealii.org/trunk@32865 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/tests.h b/tests/tests.h index c961df8192..0760341b2f 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -1,7 +1,7 @@ // --------------------------------------------------------------------- // $Id$ // -// Copyright (C) 2004 - 2013 by the deal.II authors +// Copyright (C) 2004 - 2014 by the deal.II authors // // This file is part of the deal.II library. // @@ -33,6 +33,13 @@ #include +// implicitly use the deal.II namespace everywhere, without us having to say +// so in each and every testcase +using namespace dealii; + + +// ------------------------------ Utility functions used in tests ----------------------- + // Cygwin has a different implementation for rand() which causes many tests to fail. // This here is a reimplementation that gives the same sequence of numbers as a program // that uses rand() on a typical linux machine. @@ -89,7 +96,7 @@ 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) +void cat_file(const char *filename) { std::ifstream in(filename); Assert (in, dealii::ExcIO()); @@ -106,47 +113,81 @@ inline void cat_file(const char *filename) } +/* + * Some tests (notably base/thread*, base/task*) create output that + * comes out in random order. To make the output of these tests comparable, + * we need to sort them. + * + * This function does just that with the file given. All streams writing + * to this should be closed when calling this function. + */ +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()); +} + + + +/* + * Replace all occurences of ' &' by '& ' from the given file to hopefully be + * more compiler independent with respect to __PRETTY_FUNCTION__ + * + * Also, while GCC prepends the name by "virtual " if the function is virtual, + * Intel's ICC does not do that, so filter that out as well. + */ +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()); +} + + +// ------------------------------ Functions used in initializing subsystems ------------------- + #ifdef DEAL_II_WITH_PETSC #include -inline void check_petsc_allocations() +namespace { - PetscStageLog stageLog; - PetscLogGetStageLog(&stageLog); + void check_petsc_allocations() + { + PetscStageLog stageLog; + PetscLogGetStageLog(&stageLog); - // I don't quite understand petsc and it looks like stageLog->stageInfo->classLog->classInfo[i].id - // is always -1, so we look it up in stageLog->classLog, make sure it has the same number of entries: - Assert(stageLog->stageInfo->classLog->numClasses == stageLog->classLog->numClasses, dealii::ExcInternalError()); + // I don't quite understand petsc and it looks like + // stageLog->stageInfo->classLog->classInfo[i].id is always -1, so we look + // it up in stageLog->classLog, make sure it has the same number of entries: + Assert(stageLog->stageInfo->classLog->numClasses == stageLog->classLog->numClasses, + dealii::ExcInternalError()); - 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; - } - } + 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 (errors) - throw dealii::ExcMessage("PETSc memory leak"); + if (errors) + throw dealii::ExcMessage("PETSc memory leak"); + } } #endif -// implicitly use the deal.II namespace everywhere, without us having to say -// so in each and every testcase -using namespace dealii; - -// Function for initialize deallog. Normally, it should be called at +// Function to initialize deallog. Normally, it should be called at // the beginning of main() like // // initlog(); @@ -157,7 +198,6 @@ using namespace dealii; std::string deallogname; std::ofstream deallogfile; -inline void initlog(bool console=false) { @@ -271,40 +311,55 @@ struct MPILogInitAll -/* - * Some tests (notably base/thread*, base/task*) create output that - * comes out in random order. To make the output of these tests comparable, - * we need to sort them. - * - * This function does just that with the file given. All streams writing - * to this should be closed when calling this function. - */ -void sort_file_contents (const std::string &filename) +/* Override the tbb assertion handler in order to print a stacktrace:*/ + +#ifdef TBB_DO_ASSERT + +#include + +DEAL_II_NAMESPACE_OPEN +namespace deal_II_exceptions { - int error = std::system ((std::string ("LC_ALL=C sort ") + filename + " -o " + filename).c_str()); - Assert (error == 0, ExcInternalError()); + extern bool abort_on_exception; + extern bool show_stacktrace; } +DEAL_II_NAMESPACE_CLOSE - -/* - * Replace all occurences of ' &' by '& ' from the given file to hopefully be - * more compiler independent with respect to __PRETTY_FUNCTION__ - * - * Also, while GCC prepends the name by "virtual " if the function is virtual, - * Intel's ICC does not do that, so filter that out as well. - */ -void unify_pretty_function (const std::string &filename) +void new_tbb_assertion_handler(const char *file, int line, const char *expr, + const char *comment) { - 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()); + // 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; - Assert (error == 0, ExcInternalError()); + // 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*/ + + +// ------------------------------ Adjust global variables in deal.II ----------------------- + DEAL_II_NAMESPACE_OPEN /* - * Now, change some global behaviour of deal.II and supporting libraries: + * Now, change some global behavior of deal.II and supporting libraries: */ /* Disable stack traces: */ @@ -343,47 +398,6 @@ struct SetGrainSizes } } 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; -} - -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