From: Francesco Chemolli Date: Thu, 19 Feb 2015 14:52:14 +0000 (+0100) Subject: Implemented selective debugs() output for unit tests X-Git-Tag: merge-candidate-3-v1~259 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03714d23847ca8af08fa88c8f342b56269f0ca0f;p=thirdparty%2Fsquid.git Implemented selective debugs() output for unit tests --- diff --git a/include/unitTestMain.h b/include/unitTestMain.h index dfd8e35492..840b32da92 100644 --- a/include/unitTestMain.h +++ b/include/unitTestMain.h @@ -9,6 +9,10 @@ #ifndef SQUID_INCLUDE_UNITTESTMAIN_H #define SQUID_INCLUDE_UNITTESTMAIN_H +#if ENABLE_DEBUG_SECTION +#include "Debug.h" +#endif /* ENABLE_DEBUG_SECTION */ + #include #include #include @@ -20,6 +24,10 @@ int main( int argc, char* argv[] ) { +#if ENABLE_DEBUG_SECTION + Debug::Levels[ENABLE_DEBUG_SECTION] = 99; +#endif + // Create the event manager and test controller CPPUNIT_NS::TestResult controller; diff --git a/src/Debug.h b/src/Debug.h index 596d3d55e3..ff7f25cab0 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -88,7 +88,12 @@ extern FILE *debug_log; size_t BuildPrefixInit(); const char * SkipBuildPrefix(const char* path); -/* Debug stream */ +/* Debug stream + * + * Unit tests can enable full debugging to stderr for one + * debug section; to enable this, #define ENABLE_DEBUG_SECTION to the + * section number before any header + */ #define debugs(SECTION, LEVEL, CONTENT) \ do { \ if ((Debug::level = (LEVEL)) <= Debug::Levels[SECTION]) { \ diff --git a/src/tests/stub_debug.cc b/src/tests/stub_debug.cc index 6064641daa..5cd6f178e4 100644 --- a/src/tests/stub_debug.cc +++ b/src/tests/stub_debug.cc @@ -91,15 +91,8 @@ Debug::OutStream *Debug::CurrentDebug(NULL); std::ostream & Debug::getDebugOut() { - assert(TheDepth >= 0); - ++TheDepth; - if (TheDepth > 1) { - assert(CurrentDebug); - *CurrentDebug << std::endl << "reentrant debuging " << TheDepth << "-{"; - } else { - assert(!CurrentDebug); + if (!CurrentDebug) { CurrentDebug = new Debug::OutStream; - // set default formatting flags CurrentDebug->setf(std::ios::fixed); CurrentDebug->precision(2); } @@ -113,26 +106,16 @@ Debug::parseOptions(char const *) void Debug::finishDebug() { - assert(TheDepth >= 0); - assert(CurrentDebug); - if (TheDepth > 1) { - *CurrentDebug << "}-" << TheDepth << std::endl; - } else { - assert(TheDepth == 1); - _db_print("%s\n", CurrentDebug->str().c_str()); - delete CurrentDebug; - CurrentDebug = NULL; - } - --TheDepth; + std::cerr << "debugs: " << CurrentDebug->str() << std::endl; + delete CurrentDebug; + CurrentDebug = NULL; } void Debug::xassert(const char *msg, const char *file, int line) { - if (CurrentDebug) { - *CurrentDebug << "assertion failed: " << file << ":" << line << - ": \"" << msg << "\""; - } + getDebugOut() << "assertion failed: " << file << ":" << line << + ": \"" << msg << "\""; abort(); }