[Top][All Lists]

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

[Gnash-dev] Catching exceptions in the test suite... (heaps of Coverity

From: Petter Reinholdtsen
Subject: [Gnash-dev] Catching exceptions in the test suite... (heaps of Coverity issues to fix)
Date: Sun, 20 Apr 2014 12:24:19 +0200
User-agent: Mutt/1.5.20 (2009-12-10)

Hi.  The majority of Coverity reports in Gnash is in the test suite.
And most of these are lack of exception handling.  I'm trying to
decide how to best add exception handling to all the tests, and would
like to get some feedback.

One alternative is to modify all main() functions to fetch
std::exception and count it as a failure.  It will require quite a bit
of code changes if we are to adjust the indentation appropriately.

Another idea floating on IRC was to change main() to trymain() or
something like that, and add a generic main() handling the unhandled
exceptions.  I've tried to implement the latter, and would like
feedback on this approach.  Here is my proposed patch for one of the
tests where Coverity complain:

diff --git a/testsuite/libbase.all/NoSeekFileTest.cpp 
index 418a59b..2f29447 100644
--- a/testsuite/libbase.all/NoSeekFileTest.cpp
+++ b/testsuite/libbase.all/NoSeekFileTest.cpp
@@ -42,6 +42,7 @@
 #include <string.h>
 #include <sstream>
 #include <limits>
+#include "trymain.h"
 using namespace std;
@@ -128,8 +129,7 @@ compare_reads(gnash::IOChannel* reader, int fd, const char* 
first, const char* s
-main(int /*argc*/, char** /*argv*/)
+int trymain(int /*argc*/, char** /*argv*/)
        const char* input = INPUT; // Should be the path to this file
        const char* cachename = "NoSeekFileTestCache";
@@ -170,4 +170,4 @@ main(int /*argc*/, char** /*argv*/)
        return 0;
diff --git a/testsuite/trymain.h b/testsuite/trymain.h
new file mode 100644
index 0000000..7c1e687
--- /dev/null
+++ b/testsuite/trymain.h
@@ -0,0 +1,9 @@
+#define TRYMAIN(runtest) \
+int main(int argc, char *argv[]) { \
+  try { \
+      return trymain(argc, argv);  \
+  } catch (std::exception const&  ex) { \
+    (runtest).fail(string("caugh unexcepcted exception: ") + ex.what()); \
+    return 1; \
+  } \

Is this approach a good one, or should we go with another approach to
handle exceptions in all the tests currently missing exception

Happy hacking
Petter Reinholdtsen

reply via email to

[Prev in Thread] Current Thread [Next in Thread]