-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Win32, Reporter: Access violation causes assert(!m_sectionStack.empty()); #1967
Comments
I was able to create a code to reproduce the issue. Latest version 2.12.3 is affected as well. NDEGUB is undefined to have asserts in the release mode. #undef NDEBUG
#include <assert.h>
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
#include <windows.h>
#include <iostream>
class Example
{
public:
~Example()
{
std::cout << "destructed" << std::endl;
}
};
int filterException(int code, PEXCEPTION_POINTERS ex)
{
std::cout << "Filtering " << std::hex << code << std::endl;
return EXCEPTION_EXECUTE_HANDLER;
}
void testProcessorFault()
{
Example e;
int* p = 0;
*p = 42;
}
struct Simple
{
~Simple()
{
__try
{
testProcessorFault();
}
__except (filterException(GetExceptionCode(), GetExceptionInformation()))
{
std::cout << "caught" << std::endl;
}
}
};
TEST_CASE("Failing reporter"){
Simple a;
GIVEN("Given")
{
WHEN("When 1")
{
THEN("Then 1")
{
SUCCEED();
}
}
WHEN("When 2")
{
THEN("Then 2")
{
SUCCEED();
REQUIRE(1 == 1);
}
}
}
}
int main(int argc, char* argv[])
{
return Catch::Session().run(argc, argv);
} This is the output I have with Catch 2.12.3, and these similar results I have on my Jenkins.
|
The thing is that in our case the access violation exception happens randomly, and we could not avoid this, because for better optimization we use Intel tbb malloc library. It seems it is not well written, and sometimes it dereferences the null pointer in its internal stuff, but it has SEH handling with __try and __except, so, such dereferencing does not affect our applications in any bad way. Since Catch2 has VEH handling, it catches this exception in the first place (because VEH is prioritized over SEH), and tries to handle such fault. While handling, the m_sectionStack is cleared, and when reporting is enabled, code inside I found special define |
This can be reproduced very trivially (on Windows, at least) with a test case like this one: TEST_CASE("divide by zero") {
int zero{ 0 };
int oops = 1 / zero;
} This will unwind through the fatal exception code path but then ultimately barf when trying to pop an already-empty stack. It's not a complete fix, but simply adding a |
Any progress on this one? Still seeing sporadic failures on our CI, and it would be nice with something more descriptive being printed. (: |
The `unittest` binary crashes with ``` unittest: /var/lib/gitlab-runner/builds/yS6csq8A/0/bigdata/mutable/mutable/third-party/catch2/include/catch2/catch.hpp:5918: virtual void Catch::CumulativeReporterBase<Catch::JunitReporter>::testCaseEnded(const Catch::TestCaseStats &) [DerivedT = Catch::JunitReporter]: Assertion `m_sectionStack.size() == 0' failed. ``` This error seems to be related to the Catch 2 JUnit reporter. See catchorg/Catch2#1801 and catchorg/Catch2#1967. To remedy this problem, we simply don't use produce a report anymore. It was never used, anyway.
Describe the bug
There is a possible problem with the
RunContext::handleFatalErrorCondition( StringRef message )
function.When on the Access violation exception happens in the some code, this function is called from the
FatalConditionHandler::handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo)
.During the processing fatal error, first handler calls the
handleUnfinishedSections();
function, which cleans internal memberm_sectionStack
.After that it calls
m_reporter->sectionEnded(testCaseSectionStats);
where theassert(!m_sectionStack.empty())
exists, which terminates application.This situation happens, if I execute the test with the JUnit reporter.
Expected behavior
Handling of fatal error should not break internal Catch2 stuff and the reporting abilities.
Reproduction steps
I could not yet build the repeatable simple example for triggering the Access Violation, but the code with test looks like that:
Platform information:
Additional context
No yet
The text was updated successfully, but these errors were encountered: