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

test: boost unit tests don't handle assert very well #16700

Closed
maflcko opened this issue Aug 23, 2019 · 5 comments · Fixed by #18183
Closed

test: boost unit tests don't handle assert very well #16700

maflcko opened this issue Aug 23, 2019 · 5 comments · Fixed by #18183
Labels

Comments

@maflcko
Copy link
Member

maflcko commented Aug 23, 2019

When running into an assert failure, the boost unit test framework does not shut down cleanly. It does not call the BasicTestingSetup destructor. Thus, the test process will never shut down. As a result of that, the failure is never passed back to the caller.

On travis, this will result in frustrating and hard-to-debug timeouts: E.g. https://travis-ci.org/bitcoin/bitcoin/jobs/575909995#L3584

I see two ways to fix this:

  • Use exceptions instead of assertions, especially in non-validation debug code
  • Teach the boost unit test framework how to handle asserts
@maflcko maflcko added the Tests label Aug 23, 2019
@ariard
Copy link
Contributor

ariard commented Aug 23, 2019

Seems we need to set BOOST_TEST_CATCH_SYSTEM_ERRORS somewhere and write an handler for abort signal.

https://www.boost.org/doc/libs/1_71_0/libs/test/doc/html/boost_test/utf_reference/rt_param_reference/catch_system.html

EDIT:

$> ./src/test/test_bitcoin --catch_system_errors=no -t wallet_tests 
Running 9 test cases...
Assertion failed: detected inconsistent lock order at sync.cpp:121, details in debug log.
[1]    8770 abort      ./src/test/test_bitcoin --catch_system_errors=no -t wallet_tests

In fact, abort signals are catched which explains why we see checkpoints, but boost seems to not call destructor

sidhujag pushed a commit to syscoin/syscoin that referenced this issue Feb 22, 2020
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
sidhujag pushed a commit to syscoin-core/syscoin that referenced this issue Nov 10, 2020
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
@ariard
Copy link
Contributor

ariard commented Apr 29, 2021

@MarcoFalke

Digging up, AFAIU the issue was solved in #18183 by setting catch_system_errors=no in the ci. That said if we're willingly to exercise asserts, have we found a way to teach the unit test framework how to handle them ?

Or otherwise do you advise to replace them by exceptions and catching them with BOOST_CHECK_THROW ?

Interested in the context of #21515's test coverage.

@maflcko
Copy link
Member Author

maflcko commented Apr 29, 2021

I think if you want to exercise a logic error during a unit test, the only way is to throw something, as an assert would abort the process.

@ariard
Copy link
Contributor

ariard commented Apr 30, 2021

Thanks for the answer! Yes a lot of critical code paths with asserts aren't exercise sadly.

@maflcko
Copy link
Member Author

maflcko commented Apr 30, 2021

Obviously that assumes the logic error is reachable during the unit test. If it is not reachable, an Assert is just fine. If the program may continue execution, an Assume is also fine. See ./src/util/check.h and the dev notes.

PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jun 27, 2021
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jun 28, 2021
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jun 29, 2021
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jul 1, 2021
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jul 1, 2021
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this issue Jul 14, 2021
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
gades pushed a commit to cosanta/cosanta-core that referenced this issue Dec 3, 2023
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
gades pushed a commit to piratecash/pirate that referenced this issue Dec 10, 2023
…ests

fac52da test: Set catch_system_errors=no on boost unit tests (MarcoFalke)

Pull request description:

  Closes bitcoin#16700

  Can be tested by adding an `assert(0)` and then running either `make check` or `./src/test/test_bitcoin -t bla_tests --catch_system_errors=no/yes`

ACKs for top commit:
  practicalswift:
    ACK fac52da
  Empact:
    Tested ACK bitcoin@fac52da

Tree-SHA512: ec00636951b2c1137aaf43610739d78d16f823f7da76a726d47f93b8b089766fb66b21504b3c5413bcf8b6b5c3db0ad74027d677db24a44487d6d79a6bdee2e0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants