Skip to content

fuzz: Add fuzz-only build mode option for targets#31028

Closed
marcofleon wants to merge 1 commit intobitcoin:masterfrom
marcofleon:2024/10/fuzzonly-build-mode-option
Closed

fuzz: Add fuzz-only build mode option for targets#31028
marcofleon wants to merge 1 commit intobitcoin:masterfrom
marcofleon:2024/10/fuzzonly-build-mode-option

Conversation

@marcofleon
Copy link
Contributor

Addresses #30950.

Any targets that require BUILD_ON_FUZZING=ON (currently only p2p_headers_presync) to work properly can now set require_build_for_fuzzing as an option. If BUILD_FOR_FUZZING is not on and you try to run a target that has this option, then there's a message printed upon exit.

With this change, the CI will be able to run the fuzz test runner without any timeouts/failures.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 3, 2024

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #30882 (wip: Split fuzz binary (take 2) by dergoegge)

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.

@marcofleon
Copy link
Contributor Author

To test, build with -DBUILD_FUZZ_BINARY=ON but not BUILD_FOR_FUZZING. Then run the fuzz test runner and you should see the message in place of the p2p_headers_presync test.

@theuni
Copy link
Member

theuni commented Oct 4, 2024

If we already know at compile-time that FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION is required, is there any value in registering p2p_headers_presync as a target if it's not set? Maybe a new FUZZ_BUILD_ONLY_TARGET or so, which would conditionally register?

Copy link
Member

Choose a reason for hiding this comment

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

I think this patch is still incomplete. This will just turn the timeout into an early error. Obviously a fast error is better than a long timeout, but it would be better to exclude the test from the non-fuzz-only builds in the CI and mention in the pull request description that require_build_for_fuzzing targets must be excluded manually in non-fuzz-only builds.

An alternative would be to not register it, as explained by Cory.

@marcofleon marcofleon force-pushed the 2024/10/fuzzonly-build-mode-option branch from 09917ed to 7272a0c Compare October 7, 2024 14:00
Copy link
Member

Choose a reason for hiding this comment

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

style nit: Seems fine, but I preferred the previous approach where all fuzz targets are registered with the same macro. This should be possible by guarding the FuzzFrameworkRegisterTarget behind a if constexpr (opts.require_build_for_fuzzing and not build_for_fuzzing).

This should also make #30882 easier to implement, because it doesn't have to deal with two macros.

Copy link
Member

@maflcko maflcko Oct 7, 2024

Choose a reason for hiding this comment

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

This may also work around the CI false positive?

Copy link
Contributor Author

@marcofleon marcofleon Oct 7, 2024

Choose a reason for hiding this comment

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

Agreed, that's a better way to do it. Let me know what you think about d470af3. Another possibility I was thinking of was something like:

#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
#define CONDITIONAL_REGISTER(name, target, opts) FuzzFrameworkRegisterTarget(name, target, opts)
#else
#define CONDITIONAL_REGISTER(name, target, opts)                     
    do {                                                                                                   
        if (!(opts).requires_fuzz_build) {                                                  
            FuzzFrameworkRegisterTarget(name, target, opts);               
        }               
    } while(0)
#endif

Is there an approach I'm missing?

Copy link
Contributor Author

@marcofleon marcofleon Oct 7, 2024

Choose a reason for hiding this comment

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

Dealing with the logic in DETAIL_FUZZ seems better. And not as many macros.

@marcofleon marcofleon marked this pull request as draft October 7, 2024 14:27
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 7, 2024

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

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.

@marcofleon marcofleon force-pushed the 2024/10/fuzzonly-build-mode-option branch from 7272a0c to d470af3 Compare October 7, 2024 16:58
@DrahtBot DrahtBot removed the CI failed label Oct 7, 2024
@DrahtBot DrahtBot mentioned this pull request Oct 7, 2024
3 tasks
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines +38 to +42
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
constexpr bool should_register = true;
#else
constexpr bool should_register = false;
#endif
Copy link
Member

@maflcko maflcko Oct 8, 2024

Choose a reason for hiding this comment

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

Suggested change
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
constexpr bool should_register = true;
#else
constexpr bool should_register = false;
#endif
constexpr bool build_for_fuzzing
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
{true};
#else
{false};
#endif

nit: Could rename, so that it can be re-used in the future for other stuff, if needed?

@marcofleon
Copy link
Contributor Author

Closing, as #31093 has been merged.

@marcofleon marcofleon closed this Oct 28, 2024
@marcofleon marcofleon deleted the 2024/10/fuzzonly-build-mode-option branch January 13, 2025 14:09
@bitcoin bitcoin locked and limited conversation to collaborators Jan 13, 2026
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.

4 participants