Skip to content

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Oct 2, 2024

Add a NodeSteadyClock, a steady_clock that can be mocked with millisecond precision. Use this in the PCP implementation.

Then add a mock for a simple scriptable UDP server,, which is used to test various code paths (including successful mappings, timeouts and errors) in the PCP and NATPMP implementations.

Includes "net: Add optional length checking to CService::SetSockAddr" from #31014 as a prerequisite.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 2, 2024

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31022.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK darosior, achow101
Concept ACK dergoegge, i-am-yuvi
Stale ACK sipa

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #31014 (net: Use GetAdaptersAddresses to get local addresses on Windows by laanwj)
  • #30988 (Split CConnman 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.

@DrahtBot DrahtBot changed the title test: Add mockable steady clock, tests for PCP and NATPMP implementations test: Add mockable steady clock, tests for PCP and NATPMP implementations Oct 2, 2024
@laanwj laanwj force-pushed the 2024-10-pcp-tests branch 3 times, most recently from a2420fa to 41d276d Compare October 3, 2024 07:30
@laanwj laanwj force-pushed the 2024-10-pcp-tests branch from 41d276d to 85a41cb Compare October 3, 2024 07:43
@bitcoin bitcoin deleted a comment from DrahtBot Oct 3, 2024
@DrahtBot DrahtBot removed the CI failed label Oct 3, 2024
@bitcoin bitcoin deleted a comment from DrahtBot Oct 3, 2024
Copy link
Member

@dergoegge dergoegge 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

Left some comments on the approach for the steady mock time.

@darosior
Copy link
Member

darosior commented Nov 8, 2024

Concept ACK

Copy link
Member

@sipa sipa left a comment

Choose a reason for hiding this comment

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

Neat, utACK 258b2856cdc6e2c054ea573cf57de7021aebc3c5. I did not verify the test scenario byte sequences against the spec. Just a few nits.

Copy link
Member

Choose a reason for hiding this comment

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

Could be marked final.

Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't work, boost apparently does derive from it.

.../src/test/pcp_tests.cpp:260:22: error: cannot derive from ‘final’ base ‘PCPTestingSetup’ in derived type ‘pcp_tests::natpmp_ipv4’
  260 | BOOST_AUTO_TEST_CASE(natpmp_ipv4)
      |                      ^~~~~~~~~~~
.../src/test/pcp_tests.cpp:311:22: error: cannot derive from ‘final’ base ‘PCPTestingSetup’ in derived type ‘pcp_tests::pcp_ipv4’
  311 | BOOST_AUTO_TEST_CASE(pcp_ipv4)
      |                      ^~~~~~~~

@laanwj laanwj force-pushed the 2024-10-pcp-tests branch 2 times, most recently from f10c322 to e4cc03c Compare January 13, 2025 11:18
@laanwj
Copy link
Member Author

laanwj commented Jan 13, 2025

Rebased for merge conflict, and updated for @sipa's comment (thanks) to add a constant for the initial mocked clock value.

In almost all cases (the only exception is `getifaddrs`), we know the
size of the data passed into SetSockAddr, so we can check this to be
what is expected.
This adds a NodeSteadyClock, which is a steady_clock that can be mocked
with millisecond precision.
This will be needed for the test harness.
@laanwj laanwj force-pushed the 2024-10-pcp-tests branch from a5c8da9 to 9cd8528 Compare January 13, 2025 20:54
@darosior
Copy link
Member

re-ACK 9cd85281c6cc8d3fb01930e53109fae97a108dd8

Copy link
Member

@darosior darosior left a comment

Choose a reason for hiding this comment

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

Some more nits i noticed when reusing some of this code for the fuzz target. I don't think they warrant retouching, but figured i'd post them anyways.

@laanwj laanwj force-pushed the 2024-10-pcp-tests branch from 9cd8528 to 2b4e54d Compare January 16, 2025 14:25
@laanwj
Copy link
Member Author

laanwj commented Jan 16, 2025

Updated for @darosior's suggestions.

laanwj and others added 2 commits January 16, 2025 15:56
Add a mock for a simple scriptable UDP server, and use this to test
various code paths (including successful mappings, timeouts and errors)
in the PCP and NATPMP implementations.
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed.
Debug: https://github.com/bitcoin/bitcoin/runs/35719158891

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

@maflcko
Copy link
Member

maflcko commented Jan 16, 2025

The msan CI failure seems unrelated, so I've rerun it and left a comment here: https://github.com/bitcoin/bitcoin/pull/31397/files#r1918744397

@darosior
Copy link
Member

re-ACK 0f716f2