[nemiver] Bug 774122 - Part 1: Make tests more robust



commit fe7b2e12468a06184386007376c654bfaee568c3
Author: Hubert Figuière <hub figuiere net>
Date:   Tue Nov 8 21:05:09 2016 -0500

    Bug 774122 - Part 1: Make tests more robust
    
    Remove some failures unrelated and some hangs due to actual failure.
    
            * tests/test-utils.h: New file. Macros to setup Glib timeout.
            * tests/Makefile.am: Added test-utils.h where applicable.
            * tests/test-breakpoint.cc (test_main): Setup a test timer.
              (on_engine_died_signal): ensure to quit the loop in case of exception
              to avoid a hang.
            * tests/test_deref.cc (test_main): Setup a test timer.
            * tests/test_gdbmi.cc (test_str1) (test_str3): Wrap MESSAGE()
              into try block because Glib::locale_from_utf8() might throw.
            * tests/test-pretty-print.cc (test_main): Setup a test timer.
            * tests/test-var-walker.cc (test_main): Setup a test timer.
            * tests/test-variable-format.cc (on_var_evaluated): ensure to quit
              the loop in case of exception to avoid a hang.
              (test_main): Setup a test timer.
            * tests/test-local-vars-list.cc (test_main): Setup a test timer.

 tests/Makefile.am             |   12 ++++++------
 tests/test-breakpoint.cc      |   16 +++++++++++++---
 tests/test-deref.cc           |    6 +++++-
 tests/test-gdbmi.cc           |   11 +++++++++++
 tests/test-local-vars-list.cc |    4 ++++
 tests/test-pretty-print.cc    |    5 +++++
 tests/test-utils.h            |   16 ++++++++++++++++
 tests/test-var-walker.cc      |    4 ++++
 tests/test-variable-format.cc |   20 ++++++++++++++------
 9 files changed, 78 insertions(+), 16 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0e47209..f7afb43 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -59,7 +59,7 @@ forkchild_LDADD=
 prettyprint_SOURCES=pretty-print.cc
 prettyprint_LDADD=
 
-runtestbreakpoint_SOURCES=test-breakpoint.cc
+runtestbreakpoint_SOURCES=test-breakpoint.cc test-utils.h
 runtestbreakpoint_LDADD=@NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la \
 $(top_builddir)/src/dbgengine/libdebuggerutils.la
@@ -79,12 +79,12 @@ runtestvarobjwalker_LDADD=@NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la \
 $(top_builddir)/src/dbgengine/libdebuggerutils.la
 
-runtestvariableformat_SOURCES=test-variable-format.cc
+runtestvariableformat_SOURCES=test-variable-format.cc test-utils.h
 runtestvariableformat_LDADD=@NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la \
 $(top_builddir)/src/dbgengine/libdebuggerutils.la
 
-runtestprettyprint_SOURCES=test-pretty-print.cc
+runtestprettyprint_SOURCES=test-pretty-print.cc test-utils.h
 runtestprettyprint_LDADD=@NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la \
 $(top_builddir)/src/dbgengine/libdebuggerutils.la
@@ -128,17 +128,17 @@ runtestvarlist_LDADD=@NEMIVERCOMMON_LIBS@  \
 $(top_builddir)/src/common/libnemivercommon.la \
 $(top_builddir)/src/dbgengine/libdebuggerutils.la
 
-runtestvarwalker_SOURCES=test-var-walker.cc
+runtestvarwalker_SOURCES=test-var-walker.cc test-utils.h
 runtestvarwalker_LDADD=@NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la \
 $(top_builddir)/src/dbgengine/libdebuggerutils.la
 
-runtestderef_SOURCES=test-deref.cc
+runtestderef_SOURCES=test-deref.cc test-utils.h
 runtestderef_LDADD=@NEMIVERCOMMON_LIBS@ \
 $(top_builddir)/src/common/libnemivercommon.la \
 $(top_builddir)/src/dbgengine/libdebuggerutils.la
 
-runtestlocalvarslist_SOURCES=test-local-vars-list.cc
+runtestlocalvarslist_SOURCES=test-local-vars-list.cc test-utils.h
 runtestlocalvarslist_LDADD=@NEMIVERCOMMON_LIBS@  \
 $(top_builddir)/src/common/libnemivercommon.la \
 $(top_builddir)/src/dbgengine/libdebuggerutils.la
diff --git a/tests/test-breakpoint.cc b/tests/test-breakpoint.cc
index f760de7..49d55c3 100644
--- a/tests/test-breakpoint.cc
+++ b/tests/test-breakpoint.cc
@@ -7,6 +7,7 @@
 #include "common/nmv-exception.h"
 #include "nmv-i-debugger.h"
 #include "nmv-debugger-utils.h"
+#include "test-utils.h"
 
 using namespace nemiver;
 using namespace nemiver::common;
@@ -29,9 +30,13 @@ on_program_finished_signal ()
 {
     MESSAGE ("program finished");
     MESSAGE ("nb of breakpoint hit: " <<  (int)nb_bp);
-    BOOST_REQUIRE(nb_bp == 1007);
-    BOOST_REQUIRE(nb_stops > 1007);
-    loop->quit ();
+    try {
+        BOOST_REQUIRE(nb_bp == 1007);
+        BOOST_REQUIRE(nb_stops > 1007);
+    } catch(...) {
+        loop->quit ();
+        throw;
+    }
 }
 
 void
@@ -255,9 +260,14 @@ test_main (int argc, char *argv[])
     debugger->set_breakpoint ("func2");
     debugger->set_breakpoint ("func4");
     debugger->set_breakpoint ("Person::overload");
+
     debugger->run ();
+
+    NEMIVER_SETUP_TIMEOUT (loop, 10);
     loop->run ();
 
+    NEMIVER_CHECK_NO_TIMEOUT;
+
     NEMIVER_CATCH_NOX
 
     return 0;
diff --git a/tests/test-deref.cc b/tests/test-deref.cc
index 556f41c..350580c 100644
--- a/tests/test-deref.cc
+++ b/tests/test-deref.cc
@@ -6,6 +6,7 @@
 #include "nmv-i-lang-trait.h"
 #include "common/nmv-initializer.h"
 #include "nmv-debugger-utils.h"
+#include "test-utils.h"
 
 using namespace nemiver;
 using namespace nemiver::common;
@@ -158,9 +159,12 @@ test_main (int argc, char **argv)
     vector<UString> args;
     debugger->load_program (".libs/pointerderef", args, ".");
     debugger->set_breakpoint ("main");
-    debugger->run ();
 
+    NEMIVER_SETUP_TIMEOUT (loop, 10);
     loop->run ();
+
+    NEMIVER_CHECK_NO_TIMEOUT;
+
     NEMIVER_CATCH_AND_RETURN_NOX(-1)
     return 0;
 }
diff --git a/tests/test-gdbmi.cc b/tests/test-gdbmi.cc
index 0953769..8bb386e 100644
--- a/tests/test-gdbmi.cc
+++ b/tests/test-gdbmi.cc
@@ -214,7 +214,13 @@ BOOST_AUTO_TEST_CASE (test_str1)
     is_ok = parser.parse_c_string (0, to, res);
 
     BOOST_REQUIRE (is_ok);
+
+    NEMIVER_TRY
+
     MESSAGE ("got string: '" << Glib::locale_from_utf8 (res) << "'");
+
+    NEMIVER_CATCH_NOX
+
     BOOST_REQUIRE_MESSAGE (res.size () == 32, "res size was: " << res.size ());
 }
 
@@ -244,7 +250,12 @@ BOOST_AUTO_TEST_CASE (test_str3)
     is_ok = parser.parse_c_string (0, to, res);
 
     BOOST_REQUIRE (is_ok);
+    NEMIVER_TRY
+
     MESSAGE ("got string: '" << Glib::locale_from_utf8 (res) << "'");
+
+    NEMIVER_CATCH_NOX
+
     BOOST_REQUIRE_MESSAGE (res.size (), "res size was: " << res.size ());
 }
 
diff --git a/tests/test-local-vars-list.cc b/tests/test-local-vars-list.cc
index 03cf609..e1742bf 100644
--- a/tests/test-local-vars-list.cc
+++ b/tests/test-local-vars-list.cc
@@ -6,6 +6,7 @@
 #include "common/nmv-exception.h"
 #include "nmv-i-var-list.h"
 #include "nmv-debugger-utils.h"
+#include "test-utils.h"
 
 using namespace std;
 using namespace nemiver;
@@ -166,7 +167,10 @@ test_main (int argc, char **argv)
     debugger->set_breakpoint ("main");
     debugger->run ();
 
+    NEMIVER_SETUP_TIMEOUT (loop, 10);
     loop->run ();
+    NEMIVER_CHECK_NO_TIMEOUT;
+
     NEMIVER_CATCH_AND_RETURN_NOX (-1);
 
     return 0;
diff --git a/tests/test-pretty-print.cc b/tests/test-pretty-print.cc
index a3c8a90..956581e 100644
--- a/tests/test-pretty-print.cc
+++ b/tests/test-pretty-print.cc
@@ -7,6 +7,7 @@
 #include "common/nmv-initializer.h"
 #include "common/nmv-exception.h"
 #include "nmv-debugger-utils.h"
+#include "test-utils.h"
 
 using namespace nemiver;
 using namespace nemiver::common;
@@ -197,8 +198,12 @@ test_main (int, char **)
     //****************************************
     //run the event loop.
     //****************************************
+    NEMIVER_SETUP_TIMEOUT (s_loop, 10);
     s_loop->run ();
 
+    // we shouldn't have timeout.
+    NEMIVER_CHECK_NO_TIMEOUT;
+
     v_var.reset ();
     NEMIVER_CATCH_AND_RETURN_NOX (-1);
 
diff --git a/tests/test-utils.h b/tests/test-utils.h
new file mode 100644
index 0000000..b992fb8
--- /dev/null
+++ b/tests/test-utils.h
@@ -0,0 +1,16 @@
+
+
+
+#pragma once
+
+
+#define NEMIVER_SETUP_TIMEOUT(loop, sec) \
+  bool timeout = false; \
+Glib::signal_timeout ().connect_seconds_once ( \
+  [&timeout] { \
+    timeout = true; \
+    loop->quit (); \
+  }, sec)
+
+#define NEMIVER_CHECK_NO_TIMEOUT \
+  BOOST_REQUIRE (!timeout)
diff --git a/tests/test-var-walker.cc b/tests/test-var-walker.cc
index fa4f9da..0f0d659 100644
--- a/tests/test-var-walker.cc
+++ b/tests/test-var-walker.cc
@@ -8,6 +8,7 @@
 #include "common/nmv-exception.h"
 #include "nmv-i-var-list-walker.h"
 #include "nmv-debugger-utils.h"
+#include "test-utils.h"
 
 using namespace nemiver;
 using namespace nemiver::common;
@@ -243,8 +244,11 @@ test_main (int argc, char **argv)
     //****************************************
     //run the event loop.
     //****************************************
+    NEMIVER_SETUP_TIMEOUT (s_loop, 10);
     s_loop->run ();
 
+    NEMIVER_CHECK_NO_TIMEOUT;
+
     variables.clear ();
 
     BOOST_REQUIRE (actual_variables ().find ("main")  != actual_variables ().end ());
diff --git a/tests/test-variable-format.cc b/tests/test-variable-format.cc
index bd67c94..d281e97 100644
--- a/tests/test-variable-format.cc
+++ b/tests/test-variable-format.cc
@@ -9,6 +9,7 @@
 #include "common/nmv-exception.h"
 #include "nmv-i-var-list-walker.h"
 #include "nmv-debugger-utils.h"
+#include "test-utils.h"
 
 using namespace nemiver;
 using namespace nemiver::common;
@@ -45,12 +46,16 @@ static void
 on_var_evaluated (const IDebugger::VariableSafePtr a_var,
                  IDebuggerSafePtr /*a_debugger*/)
 {
-    BOOST_REQUIRE (a_var);
-    BOOST_REQUIRE (a_var->format () ==
-                  IDebugger::Variable::HEXADECIMAL_FORMAT);
-    BOOST_REQUIRE (a_var->value () == "0x12");
-    s_got_value = true;
-    s_loop->quit ();
+    try {
+        BOOST_REQUIRE (a_var);
+        BOOST_REQUIRE (a_var->format () ==
+                       IDebugger::Variable::HEXADECIMAL_FORMAT);
+        BOOST_REQUIRE (a_var->value () == "0x12");
+        s_got_value = true;
+    } catch (...) {
+        s_loop->quit ();
+        throw;
+    }
 }
 
 static void
@@ -138,8 +143,11 @@ test_main (int, char **)
     //****************************************
     //run the event loop.
     //****************************************
+    NEMIVER_SETUP_TIMEOUT(s_loop, 10);
     s_loop->run ();
 
+    NEMIVER_CHECK_NO_TIMEOUT;
+
     NEMIVER_CATCH_AND_RETURN_NOX (-1);
 
     BOOST_REQUIRE (s_got_format);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]