Skip to content

Commit

Permalink
pw_fuzzer: Expand FuzzTest stubs
Browse files Browse the repository at this point in the history
This CL adds fake versions of the various FuzzTest domains. These
versions do not do anything except provide compile-time type-checking
that FUZZ_TEST invocations and custom domains should build.

Change-Id: Ic1cd1aa329f0ad22fe8b5ec105e8d209302f849b
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/148334
Reviewed-by: Taylor Cramer <cramertj@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Aaron Green <aarongreen@google.com>
  • Loading branch information
nopsledder authored and CQ Bot Account committed Jun 2, 2023
1 parent a833a8f commit 8dc3f4c
Show file tree
Hide file tree
Showing 7 changed files with 853 additions and 46 deletions.
26 changes: 23 additions & 3 deletions pw_fuzzer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,34 @@ config_setting(
pw_cc_library(
name = "fuzztest",
testonly = True,
deps = ["@pigweed_config//:pw_fuzzer_fuzztest_backend"],
hdrs = ["public/pw_fuzzer/fuzztest.h"] + select({
":use_fuzztest": ["private/pw_fuzzer/internal/fuzztest.h"],
"//conditions:default": [],
}),
includes = ["public"] + select({
":use_fuzztest": ["private"],
"//conditions:default": [],
}),
deps = [
"//pw_containers",
"//pw_result",
"//pw_status",
"//pw_string",
"@pigweed_config//:pw_fuzzer_fuzztest_backend",
],
)

pw_cc_library(
name = "fuzztest_stub",
testonly = True,
hdrs = ["public_overrides/fuzztest/fuzztest.h"],
includes = ["public_overrides"],
hdrs = [
"private_overrides/pw_fuzzer/internal/fuzztest.h",
"public_overrides/fuzztest/fuzztest.h",
],
includes = [
"private_overrides",
"public_overrides",
],
deps = ["//pw_unit_test"],
)

Expand Down
54 changes: 41 additions & 13 deletions pw_fuzzer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ import("$dir_pw_docgen/docs.gni")
import("$dir_pw_third_party/fuzztest/fuzztest.gni")
import("$dir_pw_unit_test/test.gni")

config("public_include_path") {
include_dirs = [ "public" ]
visibility = [ ":*" ]
}

config("private_include_path") {
include_dirs = [ "private" ]
visibility = [ ":*" ]
}

config("overrides_include_path") {
include_dirs = [
"public_overrides",
"private_overrides",
]
visibility = [ ":*" ]
}

# See https://llvm.org/docs/LibFuzzer.html#fuzzer-friendly-build-mode
config("fuzzing_build_mode_unsafe_for_production") {
defines = [ "FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION" ]
Expand Down Expand Up @@ -57,22 +75,37 @@ pw_test_group("tests") {
#
# Create FuzzTest-style fuzzers by adding a dep on dir_pw_fuzzer:fuzztest

config("public_overrides_include_path") {
include_dirs = [ "public_overrides" ]
}

# Unit tests with a dep on this target can include FuzzTest-style fuzzers.
pw_source_set("fuzztest") {
# Include headers that extend FuzzTest's interface with support for common
# Pigweed types.
public = [ "public/pw_fuzzer/fuzztest.h" ]
public_configs = [ ":public_include_path" ]
public_deps = [
dir_pw_containers,
dir_pw_result,
dir_pw_status,
dir_pw_string,
]
if (dir_pw_third_party_fuzztest != "" && pw_toolchain_FUZZING_ENABLED) {
public_deps = [ "$dir_pw_third_party/fuzztest/fuzztest" ]
public_configs = [
# Include headers and deps that provide a Pigweed-compatible subset of
# FuzzTest.
public += [ "private/pw_fuzzer/internal/fuzztest.h" ]
public_configs += [
"$dir_pw_third_party/abseil-cpp/configs:disabled_warnings",
"$dir_pw_third_party/re2/configs:disabled_warnings",
"$dir_pw_third_party/fuzztest/configs:disabled_warnings",
":private_include_path",
]
public_deps += [ "$dir_pw_third_party/fuzztest/fuzztest" ]
} else {
public = [ "public_overrides/fuzztest/fuzztest.h" ]
public_configs = [ ":public_overrides_include_path" ]
# Include headers that provide stubs of the Pigweed-compatible subset of
# FuzzTest's interface.
public += [
"private_overrides/pw_fuzzer/internal/fuzztest.h",
"public_overrides/fuzztest/fuzztest.h",
]
public_configs += [ ":overrides_include_path" ]
}
}

Expand Down Expand Up @@ -141,11 +174,6 @@ config("libfuzzer_config") {
}
}

config("public_include_path") {
include_dirs = [ "public" ]
visibility = [ ":*" ]
}

# Includes wrapper's for LLVM's libFuzzer compiler runtime library.
pw_source_set("libfuzzer") {
public = [
Expand Down
18 changes: 18 additions & 0 deletions pw_fuzzer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,33 @@ include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
# converts invocations of `FUZZ_TEST` to disabled empty unit tests.
if(pw_unit_test_GOOGLETEST_BACKEND STREQUAL "pw_third_party.fuzztest")
pw_add_library(pw_fuzzer.fuzztest INTERFACE
HEADERS
public/pw_fuzzer/fuzztest.h
private/pw_fuzzer/internal/fuzztest.h
PUBLIC_DEPS
pw_containers
pw_result
pw_status
pw_string
pw_third_party.fuzztest
PUBLIC_INCLUDES
public
private
)
else()
pw_add_library(pw_fuzzer.fuzztest INTERFACE
HEADERS
public_overrides/fuzztest/fuzztest.h
private_overrides/pw_fuzzer/internal/fuzztest.h
PUBLIC_DEPS
pw_containers
pw_result
pw_status
pw_string
PUBLIC_INCLUDES
public
public_overrides
private_overrides
)
endif()

Expand Down
25 changes: 25 additions & 0 deletions pw_fuzzer/private/pw_fuzzer/internal/fuzztest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2023 The Pigweed Authors
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
#pragma once

/// @file fuzztest.h
/// Replaceable interface to FuzzTest
///
/// @rst
/// When FuzzTest is enabled, this header includes the FuzzTest interface. It
/// exists only so that it can be replaced by stubs when FuzzTest is *not*
/// enabled.
/// @endrst

#include "fuzztest/fuzztest.h"
Loading

0 comments on commit 8dc3f4c

Please sign in to comment.