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

pull marcofleon wants to merge 1 commits into bitcoin:master from marcofleon:2024/10/fuzzonly-build-mode-option changing 2 files +12 −2
  1. marcofleon commented at 5:55 pm on October 3, 2024: 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.

  2. DrahtBot commented at 5:55 pm on October 3, 2024: contributor

    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.

  3. DrahtBot added the label Tests on Oct 3, 2024
  4. marcofleon commented at 6:13 pm on October 3, 2024: contributor
    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.
  5. theuni commented at 4:54 pm on October 4, 2024: member
    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?
  6. in src/test/fuzz/fuzz.cpp:163 in 09917ed4c0 outdated
    158+// The FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION macro is set when BUILD_FOR_FUZZING=ON, so
    159+// it's used as a proxy to detect fuzzing-only build mode.
    160+#if !defined(FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION)
    161+    if (it->second.opts.require_build_for_fuzzing) {
    162+        std::cout << "The fuzz target " << g_fuzz_target << " requires BUILD_FOR_FUZZING=ON" << std::endl;
    163+        std::exit(EXIT_SUCCESS);
    


    maflcko commented at 10:41 am on October 7, 2024:

    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.

  7. marcofleon force-pushed on Oct 7, 2024
  8. in src/test/fuzz/p2p_headers_presync.cpp:136 in 7272a0cd9b outdated
    133     g_testing_setup = setup.get();
    134 }
    135 } // namespace
    136 
    137-FUZZ_TARGET(p2p_headers_presync, .init = initialize)
    138+FUZZ_BUILD_ONLY_TARGET(p2p_headers_presync, .init = initialize)
    


    maflcko commented at 2:21 pm on October 7, 2024:

    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.


    maflcko commented at 3:27 pm on October 7, 2024:
    This may also work around the CI false positive?

    marcofleon commented at 5:02 pm on October 7, 2024:

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

    0#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    1#define CONDITIONAL_REGISTER(name, target, opts) FuzzFrameworkRegisterTarget(name, target, opts)
    2#else
    3#define CONDITIONAL_REGISTER(name, target, opts)                     
    4    do {                                                                                                   
    5        if (!(opts).requires_fuzz_build) {                                                  
    6            FuzzFrameworkRegisterTarget(name, target, opts);               
    7        }               
    8    } while(0)
    9#endif
    

    Is there an approach I’m missing?


    marcofleon commented at 5:07 pm on October 7, 2024:
    Dealing with the logic in DETAIL_FUZZ seems better. And not as many macros.
  9. marcofleon marked this as a draft on Oct 7, 2024
  10. DrahtBot added the label CI failed on Oct 7, 2024
  11. DrahtBot commented at 3:08 pm on October 7, 2024: contributor

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

    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.

  12. fuzz: add conditional register logic based on fuzz-only build d470af336a
  13. marcofleon force-pushed on Oct 7, 2024
  14. DrahtBot removed the label CI failed on Oct 7, 2024
  15. in src/test/fuzz/fuzz.h:42 in d470af336a
    37 
    38+#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    39+constexpr bool should_register = true;
    40+#else
    41+constexpr bool should_register = false;
    42+#endif
    


    maflcko commented at 9:37 am on October 8, 2024:
    0constexpr bool build_for_fuzzing
    1#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    2    {true};
    3#else
    4    {false};
    5#endif
    

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

  16. maflcko approved
  17. maflcko commented at 9:38 am on October 8, 2024: member
    lgtm
  18. marcofleon commented at 11:18 am on October 28, 2024: contributor
    Closing, as #31093 has been merged.
  19. marcofleon closed this on Oct 28, 2024


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-11-21 15:12 UTC

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