xref: /aosp_15_r20/external/crosvm/fuzz/src/lib.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2019 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 pub mod rand;
6 
7 cfg_if::cfg_if! {
8     if #[cfg(not(fuzzing))] {
9         /// A stub implementation that ensures the fuzzer code can be compiled but does not provide
10         /// any fuzzing functionality.
11         /// This allows the fuzzer code to be verified in CI without a nightly cargo toolchain.
12         #[macro_export]
13         macro_rules! fuzz_target {
14             (|$bytes:ident| $body:block) => {
15                 // fuzzers are configured with no_main. To make the binary compile, we manually
16                 // provide the main function with no_mangle.
17                 #[no_mangle]
18                 pub extern fn main($bytes: &[u8]) {
19                     $body
20                 }
21             };
22             (|$bytes:ident: &[u8]| $body:block) => {
23                 fuzz_target!(|$bytes| $body);
24             };
25         }
26     } else {
27         pub use libfuzzer_sys::fuzz_target;
28     }
29 }
30