summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-12-09 17:29:00 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-12-10 10:20:39 +0000
commit81719351c67385dece9dc6656530de31f5778f03 (patch)
tree6e2abcb7b76acdc019796963f6d21032427cff2a
parent4e5032fe8ae6e2d9e59eebb8708b004b5cf3136b (diff)
Introduce CPPUNIT_PROPAGATE_EXCEPTIONS environment variable
Often a developer debugging a failing CppUnit test wants a core dump with the place where an uncaught exception is thrown. So if the newly introduced CPPUNIT_PROPAGATE_EXCEPTIONS environment variable is set (to any value), disable all the protectors that would otherwise catch such exceptions (and just report some limited information about them). Change-Id: I3052f71c0787583c496279a6f5b35a0299c357b3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143882 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--external/cppunit/UnpackedTarball_cppunit.mk1
-rw-r--r--external/cppunit/propagate-exceptions.patch.020
-rw-r--r--sal/cppunittester/cppunittester.cxx11
-rw-r--r--unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx3
4 files changed, 29 insertions, 6 deletions
diff --git a/external/cppunit/UnpackedTarball_cppunit.mk b/external/cppunit/UnpackedTarball_cppunit.mk
index 5dc750bbdd9b..d5a3ddea2ddf 100644
--- a/external/cppunit/UnpackedTarball_cppunit.mk
+++ b/external/cppunit/UnpackedTarball_cppunit.mk
@@ -23,6 +23,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,cppunit,\
external/cppunit/rtti.patch.0 \
external/cppunit/order.patch.0 \
external/cppunit/windows-arm64.patch.1 \
+ external/cppunit/propagate-exceptions.patch.0 \
))
ifeq ($(DISABLE_DYNLOADING),TRUE)
$(eval $(call gb_UnpackedTarball_add_patches,cppunit,\
diff --git a/external/cppunit/propagate-exceptions.patch.0 b/external/cppunit/propagate-exceptions.patch.0
new file mode 100644
index 000000000000..dd9a6b32c542
--- /dev/null
+++ b/external/cppunit/propagate-exceptions.patch.0
@@ -0,0 +1,20 @@
+--- src/cppunit/TestResult.cpp
++++ src/cppunit/TestResult.cpp
+@@ -5,6 +5,7 @@
+ #include <cppunit/tools/Algorithm.h>
+ #include <cppunit/portability/Stream.h>
+ #include <algorithm>
++#include <cstdlib>
+ #include "DefaultProtector.h"
+ #include "ProtectorChain.h"
+ #include "ProtectorContext.h"
+@@ -18,7 +19,8 @@
+ , m_protectorChain( new ProtectorChain )
+ , m_stop( false )
+ {
+- m_protectorChain->push( new DefaultProtector() );
++ if (!std::getenv("CPPUNIT_PROPAGATE_EXCEPTIONS"))
++ m_protectorChain->push( new DefaultProtector() );
+ }
+
+
diff --git a/sal/cppunittester/cppunittester.cxx b/sal/cppunittester/cppunittester.cxx
index 81ddec1568ed..8a9e184c431d 100644
--- a/sal/cppunittester/cppunittester.cxx
+++ b/sal/cppunittester/cppunittester.cxx
@@ -465,16 +465,17 @@ static bool main2()
std::exit(EXIT_FAILURE);
}
#endif
- CppUnit::Protector *protector = fn == nullptr
- ? nullptr
- : (*reinterpret_cast< cppunittester::ProtectorFactory * >(fn))();
- if (protector == nullptr) {
+ if (fn == nullptr) {
std::cerr
<< "Failure instantiating protector \"" << convertLazy(lib)
<< "\", \"" << convertLazy(sym) << '"' << std::endl;
std::exit(EXIT_FAILURE);
}
- protectors.push_back(protector);
+ CppUnit::Protector *protector =
+ (*reinterpret_cast< cppunittester::ProtectorFactory * >(fn))();
+ if (protector != nullptr) {
+ protectors.push_back(protector);
+ }
index+=3;
}
diff --git a/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx b/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx
index 7a5b17b750c9..764f49d79bf5 100644
--- a/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx
+++ b/unotest/source/cpp/unoexceptionprotector/unoexceptionprotector.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <cstdlib>
#include <string>
#include <string_view>
@@ -75,7 +76,7 @@ bool Prot::protect(
extern "C" SAL_DLLPUBLIC_EXPORT CppUnit::Protector *
unoexceptionprotector() {
- return new Prot;
+ return std::getenv("CPPUNIT_PROPAGATE_EXCEPTIONS") == nullptr ? new Prot : nullptr;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */