Skip to content
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

SIGABRT - Abort (abnormal termination) signal #1169

Closed
bkda opened this issue Jan 29, 2018 · 6 comments
Closed

SIGABRT - Abort (abnormal termination) signal #1169

bkda opened this issue Jan 29, 2018 · 6 comments

Comments

@bkda
Copy link

bkda commented Jan 29, 2018

Description

Hi,guys, I'm using Catch2 to do unit testting for my project, I'm stuck with this exception:

test_server.cpp:52: FAILED:
due to a fatal error condition:
SIGABRT - Abort (abnormal termination) signal

The problem is that I write code on Mac os with (gcc 5.5.0 homebrew version not clang),and these tests work well, but it just raises exception on Debain.

  • gcc-4.9.2
  • gcc-6.4.0

Both of these compilers raise the above exception,and I also tried catch1.x, and still doesn't work.

Any help would be great appreciated.

  • Catch version: v2.1.1
  • Operating System: Mac os
  • Compiler+version: gcc -4.9.2
@horenmar
Copy link
Member

One of your tests calls to abort(). Maybe an assertion is firing?

@horenmar
Copy link
Member

horenmar commented Feb 2, 2018

Catch does not support multiple threads hitting assertions/sections, but as long as only one thread touches these, the use of multiple threads is OK.

However, the test as it is now has another problem, in that if the assertions fail, it attempts to destruct a non-joined/non-detached thread, which aborts the program.

Judging by your symptoms, my guess is that

  1. One of the REQUIREs fails on debian
  2. This leads to stack unwinding out of the TEST_CASE
  3. s1 destructor is run. Because it is neither detached nor joined, the destructor aborts the program
  4. Catch catches SIGABRT and reports on it.

Checking this is easy enough, just detach the thread after starting it. It shouldn't abort anymore, but you will have a permanently running thread instead. Alternatively use debugger to look around the incriminating code.

@KingDuckZ
Copy link

Could it be the same problem I'm hitting? I have my own my_assert macro implementation and my unit test program provides a bool report_failure() function, which is invoked by my_assert when the condition is false. In this case its body is just REQUIRE_FALSE(assert_msg), where assert_msg is a const char* != null.

In my actual non-unit test code I have:

SafeCountable::~SafeCountable() {
    my_assert(m_count == 0);
}

The unit test I'm writing is for making sure that assert triggers correctly. To recap:

  • m_count == 1
  • TEST_CASE destroys object -> ~SafeCountable -> my_assert -> report_failure(mesg) (body in different translation unit) -> REQUIRE_FALSE(mesg)
  • failed test is reported correctly
  • unit test crashes

I get this output:

<path>/assertion_failure.cpp:39: FAILED:
REQUIRE_FALSE( mesg )
with expansion:
!"m_count == 0"

terminate called after throwing an instance of 'Catch::TestFailureException'
<path>/test_safe_ptr.cpp:21: FAILED:
{Unknown expression after the reported line}
due to a fatal error condition:
SIGABRT - Abort (abnormal termination) signal

I can't really figure out what's going on, but it seems to be happening after Catch's ~AssertionHandler() returns. I don't spawn any threads, unlike the OP. Any help is very appreciated.

@horenmar
Copy link
Member

@KingDuckZ If I understand you correctly, my_assert calls into report_failure and that calls into REQUIRE_FALSE.

The problem here is that you are throwing an exception in a destructor that is not marked noexcept(false), see this example. If you don't rely on report_failure aborting the execution of a test, you can instead use the CHECK family of macros, as those don't throw exceptions.

@horenmar horenmar added the Resolved - pending review Issue waiting for feedback from the original author label Sep 15, 2018
@KingDuckZ
Copy link

facepalm of course, I forgot destructors are implicitly noexcept! I could add some test_noexcept macro to every destructor declaration but that sounds hard to maintain and easy to forget... so I'll stick to just using CHECK. I hope this "REQUIRE throws, CHECK doesn't" rule is never going to change in Catch2! Thanks for spotting the problem!

@horenmar
Copy link
Member

It won't, because the fundamental difference between the two assertion families is that a failedREQUIRE stops the test from continuing, while a failed CHECK doesn't. This is done by either throwing, or not throwing, a special exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants