test: Run AppInitSanityChecks before all tests #21763

pull MarcoFalke wants to merge 2 commits into bitcoin:master from MarcoFalke:2104-testCommonInit changing 4 files +2 −26
  1. MarcoFalke commented at 9:16 am on April 23, 2021: member

    Instead of running the sanity checks as part of a single test case, run them as part of the normal setup for each test case. Benefits are:

    • Errors during test development (e.g. wrong datadir) are caught early in the setup
    • It makes the test setup procedure closer to the bitcoind setup
  2. fanquake added the label Tests on Apr 23, 2021
  3. MarcoFalke force-pushed on Apr 23, 2021
  4. DrahtBot commented at 8:20 pm on April 24, 2021: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Conflicts

    No conflicts as of last run.

  5. brunoerg approved
  6. brunoerg commented at 3:24 pm on May 8, 2021: contributor

    tACK fa8145af797a6dac2cff049399fc8d85fd30fe0b

    Ran the tests several times and seems ok (MacOS 11.3)

  7. fanquake commented at 2:00 am on May 12, 2021: member
    Concept ACK
  8. MarcoFalke commented at 5:39 am on May 12, 2021: member
    @ryanofsky Any Concept NACK thoughts on this?
  9. ryanofsky approved
  10. ryanofsky commented at 3:22 pm on May 12, 2021: contributor

    @ryanofsky Any Concept NACK thoughts on this?

    Code review ACK fa8145af797a6dac2cff049399fc8d85fd30fe0b, and this seems fine to me. I do have an irrational dislike of the sanity checks because they throw exceptions and cause GDB catch throw false positives. Also in the future, I think it would be good to strip down the base test class and make extra setup like this optional. But this seems like a good change to make for current tests to be more consistent with the app.

  11. laanwj commented at 1:18 pm on May 14, 2021: member
    It seems somewhat overkill to run the sanity tests for every test, but they run fast so also no concept NACK.
  12. DrahtBot added the label Needs rebase on Dec 10, 2021
  13. pg156 commented at 10:10 pm on December 19, 2021: none

    Reviewed https://github.com/bitcoin/bitcoin/pull/21763/commits/fa8145af797a6dac2cff049399fc8d85fd30fe0b. Unit and functional tests are run successfully.

    Errors during test development (e.g. wrong datadir) are caught early in the setup

    I can see LockDataDirectory is called inside AppInitSanityChecks. But how do I manually generate an error by providing the wrong datadir, for both before and after this change, to verify the error is caught earlier after the change? E.g. can I give a wrong datadir to the command test_bitcoin?

    After this change, 3 sanity checks (stdlib, secp256k1, chrono) which were in sanity_tests.cpp are now called in AppInitSanityChecks in setup_common.cpp, for all test cases. As the same AppInitSanityChecks is called in bitcoind.cpp, I agree individual tests setup are closer to the bitcoind setup, which is generally desirable. But I feel I don’t have enough experience and knowledge to consider all pluses and minuses to give an ACK.

  14. MarcoFalke force-pushed on Mar 21, 2022
  15. MarcoFalke force-pushed on Mar 21, 2022
  16. MarcoFalke commented at 4:32 pm on March 21, 2022: member

    they throw exceptions and cause GDB catch throw false positives.

    I think any code may throw exceptions, so I am wondering if this is something specific to init code?

    Also in the future, I think it would be good to strip down the base test class and make extra setup like this optional.

    Agree, though the ECCVerifyHandle is pretty basic. If you don’t need that, you likely don’t need any setup at all.

  17. MarcoFalke commented at 4:39 pm on March 21, 2022: member

    I can see LockDataDirectory is called inside AppInitSanityChecks. But how do I manually generate an error by providing the wrong datadir, for both before and after this change, to verify the error is caught earlier after the change? E.g. can I give a wrong datadir to the command test_bitcoin?

    Without any warranty, this may be possible by removing g_insecure_rand_ctx_temp_path.rand256().ToString() or replacing it with a constant literal string, so that m_path_root will conflict with other’s when multiple tests are run in parallel (make check -j 2 or larger).

  18. DrahtBot removed the label Needs rebase on Mar 21, 2022
  19. DrahtBot added the label Needs rebase on May 30, 2022
  20. MarcoFalke force-pushed on May 30, 2022
  21. DrahtBot removed the label Needs rebase on May 30, 2022
  22. DrahtBot added the label Needs rebase on Jun 4, 2022
  23. test: Run SetupEnvironment first
    This is also run first in the main() function of bitcoind
    fa2c04a82a
  24. MarcoFalke force-pushed on Jul 22, 2022
  25. DrahtBot removed the label Needs rebase on Jul 22, 2022
  26. MarcoFalke force-pushed on Jul 22, 2022
  27. jamesob approved
  28. jamesob commented at 2:42 pm on July 22, 2022: member

    Github ACK https://github.com/bitcoin/bitcoin/pull/21763/commits/fa607f8250edf9aaffd91ebc6d341f287b93e4cf

    More closely resembles bitcoind startup and removes code.

  29. MarcoFalke requested review from ryanofsky on Jul 22, 2022
  30. test: Run AppInitSanityChecks before all tests
    Also remove sanity unit tests, as they are run before all tests.
    facdfb61b8
  31. MarcoFalke force-pushed on Jul 22, 2022
  32. MarcoFalke commented at 3:36 pm on July 22, 2022: member
    Force pushed to remove one more unit test
  33. in src/test/sanity_tests.cpp:11 in facdfb61b8
     5-#include <test/util/setup_common.h>
     6-#include <util/time.h>
     7-
     8-#include <boost/test/unit_test.hpp>
     9-
    10-BOOST_FIXTURE_TEST_SUITE(sanity_tests, BasicTestingSetup)
    


    ryanofsky commented at 7:23 pm on August 2, 2022:

    In commit “test: Run AppInitSanityChecks before all tests” (facdfb61b8df2958e47ced2c5014383fcf5affef)

    I wish this commit would just add the AppInitSanityChecks assert without deleting the other tests. I don’t see a reason to delete low level tests just because high level code calls some of the same functions. Low level tests can be useful because they can find identify errors that might be masked in high level tests that are changing other state. Also they can be provide more granular errors in case of failure, and they can serve as examples to show how low-level APIs can be called.

  34. ryanofsky approved
  35. ryanofsky commented at 7:24 pm on August 2, 2022: contributor
    Code review ACK facdfb61b8df2958e47ced2c5014383fcf5affef
  36. MarcoFalke commented at 8:54 am on August 3, 2022: member
    Closing for now to redirect review to other open pulls.
  37. MarcoFalke closed this on Aug 3, 2022

  38. MarcoFalke deleted the branch on Aug 3, 2022
  39. bitcoin locked this on Aug 3, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-18 21:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me