From 6c41e5c92c7a38bf21be3debaf70828df138e34d Mon Sep 17 00:00:00 2001 From: Dmitry Panin Date: Tue, 19 Nov 2013 02:41:30 +0400 Subject: [PATCH 1/4] Added option (#define CAPTURE_STDERR) if set then the DebugTrace calls only for failing tests are shown --- JGE/include/DebugRoutines.h | 15 ++++++++++++++- JGE/include/OutputCapturer.h | 28 ++++++++++++++++++++++++++++ JGE/src/OutputCapturer.cpp | 3 +++ JGE/src/Qtconsole.cpp | 3 +++ projects/mtg/src/TestSuiteAI.cpp | 12 ++++++++++++ projects/mtg/wagic-qt.pro | 2 ++ travis-script.sh | 2 +- 7 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 JGE/include/OutputCapturer.h create mode 100644 JGE/src/OutputCapturer.cpp diff --git a/JGE/include/DebugRoutines.h b/JGE/include/DebugRoutines.h index 944d4e7a1..1ce188214 100644 --- a/JGE/include/DebugRoutines.h +++ b/JGE/include/DebugRoutines.h @@ -4,6 +4,8 @@ // dirty, but I get OS header includes this way #include "JGE.h" +#include "OutputCapturer.h" + #include #include #include @@ -29,12 +31,23 @@ std::string ToHex(T* pointer) #if defined (WIN32) || defined (LINUX) #ifdef QT_CONFIG + +#ifdef CAPTURE_STDERR #define DebugTrace(inString) \ { \ std::ostringstream stream; \ stream << inString; \ - qDebug("%s", stream.str().c_str()); \ + OutputCapturer::add(stream.str()); \ } +#else // CAPTURE_STDERR +#define DebugTrace(inString) \ +{ \ + std::ostringstream stream; \ + stream << inString; \ + qDebug("%s", stream.str().c_str()); \ +} +#endif // CAPTURE_STDERR + #elif defined (ANDROID) #include #define DebugTrace(inString) \ diff --git a/JGE/include/OutputCapturer.h b/JGE/include/OutputCapturer.h new file mode 100644 index 000000000..9e2f3d924 --- /dev/null +++ b/JGE/include/OutputCapturer.h @@ -0,0 +1,28 @@ +#ifndef OUTPUTCAPTURER_H +#define OUTPUTCAPTURER_H + +#if defined(QT_CONFIG) +#include +#include +#include + +class OutputCapturer +{ +private: + static std::ostringstream stream; +public: + static void add(const std::string& s) { + stream << s << "\n"; + } + static void debugAndClear() { + stream.flush(); + qDebug("%s", stream.str().c_str()); + stream.str(""); + } + static void clear() { + stream.str(""); + } +}; +#endif + +#endif // OUTPUTCAPTURER_H diff --git a/JGE/src/OutputCapturer.cpp b/JGE/src/OutputCapturer.cpp new file mode 100644 index 000000000..3c31da724 --- /dev/null +++ b/JGE/src/OutputCapturer.cpp @@ -0,0 +1,3 @@ +#include "../include/OutputCapturer.h" + +std::ostringstream OutputCapturer::stream; diff --git a/JGE/src/Qtconsole.cpp b/JGE/src/Qtconsole.cpp index 96b0c9efb..9f3078393 100644 --- a/JGE/src/Qtconsole.cpp +++ b/JGE/src/Qtconsole.cpp @@ -98,5 +98,8 @@ int main(int argc, char* argv[]) result = testSuite.run(); delete wagicCore; DebugTrace("TestSuite done: failed test: " << result); +#ifdef CAPTURE_STDERR + OutputCapturer::debugAndClear(); +#endif return result; } diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 80c930ef8..eeb279fd2 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -433,6 +433,15 @@ void TestSuiteGame::assertGame() Log("==Test Succesful !=="); else Log("==Test Failed !=="); +#ifdef CAPTURE_STDERR + if (error) + { + OutputCapturer::debugAndClear(); + } else + { + OutputCapturer::clear(); + } +#endif mMutex.unlock(); } @@ -585,6 +594,9 @@ void TestSuite::ThreadProc(void* inParam) { LOG("Entering TestSuite::ThreadProc"); TestSuite* instance = reinterpret_cast(inParam); +#ifdef CAPTURE_STDERR + OutputCapturer::debugAndClear(); +#endif if (instance) { string filename; diff --git a/projects/mtg/wagic-qt.pro b/projects/mtg/wagic-qt.pro index 5f9544b9b..715823a8a 100644 --- a/projects/mtg/wagic-qt.pro +++ b/projects/mtg/wagic-qt.pro @@ -327,6 +327,7 @@ SOURCES += \ ../../JGE/src/pc/JSocket.cpp\ ../../JGE/src/pc/JSfx.cpp\ ../../JGE/src/JSprite.cpp\ + ../../JGE/src/OutputCapturer.cpp\ ../../JGE/src/Vector2D.cpp\ ../../JGE/src/tinyxml/tinystr.cpp\ ../../JGE/src/tinyxml/tinyxml.cpp\ @@ -393,6 +394,7 @@ HEADERS += \ ../../JGE/include/JSpline.h\ ../../JGE/include/JSprite.h\ ../../JGE/include/JTypes.h\ + ../../JGE/include/OutputCapturer.h\ ../../JGE/include/Vector2D.h\ ../../JGE/include/Vector3D.h\ ../../JGE/include/vram.h\ diff --git a/travis-script.sh b/travis-script.sh index f01edd15b..b9461e8a9 100755 --- a/travis-script.sh +++ b/travis-script.sh @@ -10,7 +10,7 @@ make -j 8 # let's try an Intel linux binary cd ../.. -qmake projects/mtg/wagic-qt.pro CONFIG+=console CONFIG+=debug +qmake projects/mtg/wagic-qt.pro CONFIG+=console CONFIG+=debug DEFINES+=CAPTURE_STDERR make -j 8 # and finish by running the testsuite From 331e126787489353ec704298f8b42d1bcb3ecfd1 Mon Sep 17 00:00:00 2001 From: Dmitry Panin Date: Tue, 19 Nov 2013 02:57:42 +0400 Subject: [PATCH 2/4] Added info about total number of tests --- JGE/src/Qtconsole.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/JGE/src/Qtconsole.cpp b/JGE/src/Qtconsole.cpp index 9f3078393..a09f5ba25 100644 --- a/JGE/src/Qtconsole.cpp +++ b/JGE/src/Qtconsole.cpp @@ -96,8 +96,9 @@ int main(int argc, char* argv[]) options.reloadProfile(); TestSuite testSuite("test/_tests.txt"); result = testSuite.run(); + int totalTests = testSuite.nbTests + testSuite.nbAITests; delete wagicCore; - DebugTrace("TestSuite done: failed test: " << result); + DebugTrace("TestSuite done: failed test: " << result << " out of " << totalTests << " total"); #ifdef CAPTURE_STDERR OutputCapturer::debugAndClear(); #endif From f370899a8abd137376e3dd7887bf705ae4d397a1 Mon Sep 17 00:00:00 2001 From: Dmitry Panin Date: Tue, 19 Nov 2013 03:58:43 +0400 Subject: [PATCH 3/4] Thread-safe version of OutputCapturer --- JGE/include/OutputCapturer.h | 4 ++++ JGE/include/Threading.h | 1 - JGE/src/OutputCapturer.cpp | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/JGE/include/OutputCapturer.h b/JGE/include/OutputCapturer.h index 9e2f3d924..fe23f1e89 100644 --- a/JGE/include/OutputCapturer.h +++ b/JGE/include/OutputCapturer.h @@ -5,13 +5,17 @@ #include #include #include +#include "Threading.h" class OutputCapturer { private: static std::ostringstream stream; + static boost::mutex mMutex; + public: static void add(const std::string& s) { + boost::mutex::scoped_lock lock(mMutex); stream << s << "\n"; } static void debugAndClear() { diff --git a/JGE/include/Threading.h b/JGE/include/Threading.h index fe3c79068..2c0667ce7 100644 --- a/JGE/include/Threading.h +++ b/JGE/include/Threading.h @@ -315,7 +315,6 @@ namespace boost #include #include -#include "../include/DebugRoutines.h" #include "../include/JLogger.h" namespace boost diff --git a/JGE/src/OutputCapturer.cpp b/JGE/src/OutputCapturer.cpp index 3c31da724..41dc4fb81 100644 --- a/JGE/src/OutputCapturer.cpp +++ b/JGE/src/OutputCapturer.cpp @@ -1,3 +1,4 @@ #include "../include/OutputCapturer.h" std::ostringstream OutputCapturer::stream; +boost::mutex mMutex; From 071a487100ea300a8b72aba178ee797d8feb6883 Mon Sep 17 00:00:00 2001 From: Dmitry Panin Date: Tue, 19 Nov 2013 11:06:31 +0400 Subject: [PATCH 4/4] Fixed compilation error --- JGE/include/OutputCapturer.h | 15 +++------------ JGE/src/OutputCapturer.cpp | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/JGE/include/OutputCapturer.h b/JGE/include/OutputCapturer.h index fe23f1e89..4b32e301a 100644 --- a/JGE/include/OutputCapturer.h +++ b/JGE/include/OutputCapturer.h @@ -14,18 +14,9 @@ private: static boost::mutex mMutex; public: - static void add(const std::string& s) { - boost::mutex::scoped_lock lock(mMutex); - stream << s << "\n"; - } - static void debugAndClear() { - stream.flush(); - qDebug("%s", stream.str().c_str()); - stream.str(""); - } - static void clear() { - stream.str(""); - } + static void add(const std::string& s); + static void debugAndClear(); + static void clear(); }; #endif diff --git a/JGE/src/OutputCapturer.cpp b/JGE/src/OutputCapturer.cpp index 41dc4fb81..902dc10e8 100644 --- a/JGE/src/OutputCapturer.cpp +++ b/JGE/src/OutputCapturer.cpp @@ -1,4 +1,22 @@ #include "../include/OutputCapturer.h" std::ostringstream OutputCapturer::stream; -boost::mutex mMutex; +boost::mutex OutputCapturer::mMutex; + +void OutputCapturer::add(const std::string& s) +{ + boost::mutex::scoped_lock lock(mMutex); + stream << s << "\n"; +} + +void OutputCapturer::debugAndClear() +{ + stream.flush(); + qDebug("%s", stream.str().c_str()); + stream.str(""); +} + +void OutputCapturer::clear() +{ + stream.str(""); +}