Merge pull request #405 from haberman/bazel-fuzzing

Updated Bazel fuzzing to use the newest fuzz rules.
pull/13171/head
Joshua Haberman 4 years ago committed by GitHub
commit e230b32b8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      .bazelrc
  2. 16
      WORKSPACE
  3. 8
      bazel/workspace_deps.bzl
  4. 6
      cmake/make_cmakelists.py
  5. 26
      tests/BUILD
  6. 4
      tests/file_descriptor_parsenew_fuzzer.cc

@ -24,4 +24,16 @@ build:analyzer --per_file_copt=json/parser@-fno-analyzer
build:analyzer --per_file_copt=com_google_protobuf@-fno-analyzer
build:analyzer --per_file_copt=com_github_google_benchmark@-fno-analyzer
build:asan-fuzzer --copt=-fsanitize=address,fuzzer --linkopt=-fsanitize=address,fuzzer --define fuzz=true
# --config=asan-libfuzzer
build:asan-libfuzzer --action_env=CC=clang
build:asan-libfuzzer --action_env=CXX=clang++
build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:libfuzzer
build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer
build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_sanitizer=asan
# --config=msan-libfuzzer
build:msan-libfuzzer --action_env=CC=clang
build:msan-libfuzzer --action_env=CXX=clang++
build:msan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:libfuzzer
build:msan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer
build:msan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_sanitizer=msan

@ -3,6 +3,7 @@ workspace(name = "upb")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("//bazel:workspace_deps.bzl", "upb_deps")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
upb_deps()
@ -38,3 +39,18 @@ new_git_repository(
build_file = "//benchmarks:BUILD.googleapis",
patch_cmds = ["find google -type f -name BUILD.bazel -delete"],
)
http_archive(
name = "rules_fuzzing",
sha256 = "127d7c45e9b7520b3c42145b3cb1b8c26477cdaed0521b02a0298907339fefa1",
strip_prefix = "rules_fuzzing-0.2.0",
urls = ["https://github.com/bazelbuild/rules_fuzzing/archive/v0.2.0.zip"],
)
load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
rules_fuzzing_dependencies()
load("@rules_fuzzing//fuzzing:init.bzl", "rules_fuzzing_init")
rules_fuzzing_init()

@ -25,12 +25,8 @@ def upb_deps():
maybe(
http_archive,
name = "rules_python",
sha256 = "e5470e92a18aa51830db99a4d9c492cc613761d5bdb7131c04bd92b9834380f6",
strip_prefix = "rules_python-4b84ad270387a7c439ebdccfd530e2339601ef27",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz",
"https://github.com/bazelbuild/rules_python/archive/4b84ad270387a7c439ebdccfd530e2339601ef27.tar.gz",
],
url = "https://github.com/bazelbuild/rules_python/releases/download/0.1.0/rules_python-0.1.0.tar.gz",
sha256 = "b6d46438523a3ec0f3cead544190ee13223a52f6a6765a29eae7b7cc24cc83a0",
)
maybe(

@ -214,6 +214,12 @@ class WorkspaceFileFunctions(object):
def upb_deps(self):
pass
def rules_fuzzing_dependencies(self):
pass
def rules_fuzzing_init(self):
pass
class Converter(object):
def __init__(self):

@ -34,14 +34,10 @@ load(
"upb_proto_library",
"upb_proto_reflection_library",
)
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
licenses(["notice"])
config_setting(
name = "fuzz",
values = {"define": "fuzz=true"},
)
cc_library(
name = "upb_test",
testonly = 1,
@ -144,22 +140,22 @@ cc_test(
)
# OSS-Fuzz test
cc_binary(
config_setting(
name = "is_clang",
flag_values = {"@bazel_tools//tools/cpp:compiler": "clang"},
)
cc_fuzz_test(
name = "file_descriptor_parsenew_fuzzer",
testonly = 1,
srcs = ["file_descriptor_parsenew_fuzzer.cc"],
copts = UPB_DEFAULT_CPPOPTS + select({
"//conditions:default": [],
":fuzz": ["-fsanitize=fuzzer,address"],
}),
defines = select({
"//conditions:default": [],
":fuzz": ["HAVE_FUZZER"],
}),
deps = [
"//:descriptor_upb_proto",
"//:upb",
],
target_compatible_with = select({
":is_clang": [],
"//conditions:default": ["@platforms//:incompatible"]
}),
)
upb_proto_library(

@ -34,7 +34,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
size, arena.ptr());
return 0;
}
#ifndef HAVE_FUZZER
int main() {}
#endif

Loading…
Cancel
Save