Skip to content

Conversation

vasild
Copy link
Contributor

@vasild vasild commented Oct 27, 2021

Previously command line arguments passed to unit and fuzz tests would be ignored by the tests themselves. They would be used by the boost test framework (e.g. --run_test="addrman_tests/*") or by the fuzzer (e.g. -runs=1). However both provide ways to pass down the extra arguments to the test itself. Use that, parse the arguments and make them available to the tests via gArgs.

This makes the tests more flexible as they can be run with any bitcoind config option specified on the command line.

When creating AddrMan objects in tests, use -checkaddrman= (if provided) instead of hardcoding the check ratio in many different places. See #20233 (comment) for further motivation for this.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 27, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23545 (scripted-diff: Use clang-tidy syntax for C++ named arguments by MarcoFalke)
  • #22910 ([RFC] Encapsulate asmap in NetGroupManager by jnewbery)
  • #21878 (Make all networking code mockable by vasild)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial lightly tested code review ACK, was distracted by addrman unit test failures I was seeing that turned out to be already on master (and spurious, not sure yet what happened); will come back to finish reviewing here.

Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK, I think it would be useful to have the option of providing arguments to unit and fuzz tests.

Is all the code processing -- DEBUG_LOG_OUT still needed when we might do as well -- -printttoconsole=1 ?

@vasild
Copy link
Contributor Author

vasild commented Nov 4, 2021

Is all the code processing -- DEBUG_LOG_OUT still needed when we might do as well -- -printttoconsole=1 ?

Not needed anymore. I did not remove it because I do not want to break existing functionality - I do not know how many scripts out there use it, or in CI, or how many devs are just used to it. Given that it is just for testing/development purposes, not used in real/production nodes I think it should be ok to remove it in a followup PR some time after this is merged.

@vasild vasild force-pushed the checkaddrman_in_tests branch from 9b6098f to 0c541a6 Compare November 4, 2021 15:31
@vasild
Copy link
Contributor Author

vasild commented Nov 4, 2021

9b6098f41f...0c541a6dba: take suggestions and print the error from unit tests if parsing of the arguments fails.

Copy link
Member

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a bit more testing. It seems it could be very helpful for this patch to print the parsed arguments and values as feedback to the user, to be sure they are correct. A few minor comments follow.

@vasild vasild force-pushed the checkaddrman_in_tests branch from 0c541a6 to 17fac01 Compare November 5, 2021 14:31
@vasild
Copy link
Contributor Author

vasild commented Nov 5, 2021

0c541a6dba...17fac018c2: address suggestions, biggest changes due to avoidance of gArgs.

@vasild vasild force-pushed the checkaddrman_in_tests branch from 17fac01 to b374709 Compare November 5, 2021 16:59
@vasild
Copy link
Contributor Author

vasild commented Nov 5, 2021

17fac018c2...b374709725: address suggestions

@vasild
Copy link
Contributor Author

vasild commented Nov 12, 2021

b374709725...51b241bf2a: rebase due to conflicts

@josibake
Copy link
Member

ACK 72544a0

verified the change using git range-diff and also ran the fuzzer to verify. I think it makes sense to limit just to libFuzz for now, but it would be nice to confirm if this is an issue for other fuzzers or not

@DrahtBot DrahtBot added the GUI label Dec 27, 2021
@maflcko maflcko added Tests and removed GUI labels Dec 27, 2021
@maflcko maflcko changed the title Parse command line arguments from unit and fuzz tests, make addrman consistency check ratio easier to change test: Parse command line arguments from unit and fuzz tests, make addrman consistency check ratio easier to change Dec 27, 2021
@@ -71,6 +71,14 @@ block^@M-^?M-^?M-^?M-^?M-^?nM-^?M-^?

In this case the fuzzer managed to create a `block` message which when passed to `ProcessMessage(...)` increased coverage.

It is possible to specify `bitcoind` arguments to the `fuzz` executable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be possible if that specific FUZZ test starts a Bitcoin Core node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, added some more words to make it clearer (hopefully). Feel free to suggest how to explain it better, if still unclear.


test_bitcoin --log_level=all --run_test=getarg_tests -- DEBUG_LOG_OUT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think --printtoconsole=1 is a replacement for -- DEBUG_LOG_OUT. DEBUG_LOG_OUT would work even if the unit test didn't start a Bitcoin Core node internally, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. However, currently all unit tests create such a node: BOOST_FIXTURE_TEST_SUITE(..., X) where X is BasicTestingSetup or something that has inherited from it. So I think DEBUG_LOG_OUT can be completely phased out, following this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to create "pure" unit tests without any fixture, IIRC

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, are you suggesting to restore the mention of DEBUG_LOG_OUT in src/test/README.md or to not phase out DEBUG_LOG_OUT after this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it is fine to remove DEBUG_LOG_OUT. I just wanted to mention that not all test spin up a node.

@vasild
Copy link
Contributor Author

vasild commented Jan 4, 2022

72544a0053...e25dce2e91: rebase due to conflicts, elaborate the added doc snippet

Invalidates ACK from @mzumsande, @josibake

@mzumsande
Copy link
Contributor

ACK e25dce2 after rebase.

@maflcko
Copy link
Member

maflcko commented Jan 11, 2022

ACK e25dce2 after rebase.

Oh, I didn't realize this meant re-ACK. I interpreted it as I'll ack after rebase, so I didn't merge this.

Retrieve the command line arguments from boost and pass them to
`BasicTestingSetup` so that we gain extra flexibility of passing any
config options on the test command line, e.g.:

```
test_bitcoin -- -printtoconsole=1 -checkaddrman=5
```
Retrieve the command line arguments from the fuzzer and save them for
later retrieval by `BasicTestingSetup` so that we gain extra flexibility
of passing any config options on the test command line, e.g.:

```
FUZZ=addrman ./src/test/fuzz/fuzz --checkaddrman=5
```

A fuzz test should call `MakeNoLogFileContext<>()` in its initialize
function in order to invoke the constructor of `BasicTestingSetup`,
which sets `gArgs`.
So that it is easy to modify through the file `bench/addrman.cpp`.
In addrman unit tests, make it possible to override the check ratio from
the command line, without recompiling:

```
test_bitcoin --run_test="addrman_tests/*" -- -checkaddrman=1
```

Also, make the arguments of the constructor of `AddrManTest` the
same as the arguments of `AddrMan`.
Make it possible to override from the command line (without recompiling)
the addrman check ratio in the common `TestingSetup::m_node::addrman`
(used by all unit tests) instead of hardcoding it to 0:

```
test_bitcoin --run_test="transaction_tests/tx_valid" -- -checkaddrman=1
```
Make it possible to override from the command line (without recompiling)
the addrman check ratio in addrman fuzz tests instead of hardcoding it
to 0:

```
FUZZ=addrman ./src/test/fuzz/fuzz --checkaddrman=5
```
Make it possible to override from the command line (without recompiling)
the addrman check ratio in non-addrman fuzz tests (connman and
deserialize) instead of hardcoding it to 0:

```
FUZZ=connman ./src/test/fuzz/fuzz --checkaddrman=5
```
@vasild
Copy link
Contributor Author

vasild commented Jan 11, 2022

e25dce2e91...7f122a4188: rebase due to conflicts

Invalidates ACK from @mzumsande

Previously invalidated ACK from @josibake

@vasild vasild force-pushed the checkaddrman_in_tests branch from e25dce2 to 7f122a4 Compare January 11, 2022 11:17
@mzumsande
Copy link
Contributor

re-ACK 7f122a4

@josibake
Copy link
Member

reACK 7f122a4

@maflcko maflcko merged commit d0bf9bb into bitcoin:master Jan 17, 2022
@vasild vasild deleted the checkaddrman_in_tests branch January 17, 2022 08:53
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 18, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Jan 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants