mirror of https://github.com/grpc/grpc.git
[fuzzing] Add dep on google fuzz test (#32578)
Initial PR to establish a bazel dependency on https://github.com/google/fuzztest, with which I'm planning on basing a hardening program. Casting a relatively wide net with reviewers: I'm genuinely interested in feedback building up the docs, and general ergonomics of this change. I've located relevant files in the `fuzztest/...` directory. The tests only build with the `--config fuzztest` bazel argument for now (because of needing C++17), so locating them separately keeps `bazel test test/...` working as it does today. In a few years time, when we adopt C++17, we'll be able to rationalize the test directories a little bit. We'll need to add some kokoro jobs (maybe with this PR?) to execute the relevant tests. <!-- If you know who should review your pull request, please assign it to that person, otherwise the pull request would get assigned randomly. If your pull request is for a specific language, please add the appropriate lang label. --> --------- Co-authored-by: ctiller <ctiller@users.noreply.github.com>pull/32666/head
parent
c43d37c956
commit
dbb131b193
15 changed files with 173 additions and 7 deletions
@ -0,0 +1,25 @@ |
||||
# Copyright 2023 gRPC 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 |
||||
# |
||||
# http://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. |
||||
|
||||
load(":grpc_fuzz_test.bzl", "grpc_fuzz_test") |
||||
|
||||
grpc_fuzz_test( |
||||
name = "fuzztest_test", |
||||
srcs = ["fuzztest_test.cc"], |
||||
external_deps = ["gtest"], |
||||
deps = [ |
||||
"@com_google_fuzztest//fuzztest", |
||||
"@com_google_fuzztest//fuzztest:fuzztest_gtest_main", |
||||
], |
||||
) |
@ -0,0 +1,7 @@ |
||||
Tests that leverage fuzztest. |
||||
|
||||
These require C++17 and so cannot be run with the standard build configurations. |
||||
|
||||
To run these tests: |
||||
|
||||
bazel run //fuzztest/path/to:test -c dbg --config fuzztest |
@ -0,0 +1,24 @@ |
||||
// Copyright 2023 gRPC 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
|
||||
//
|
||||
// http://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.
|
||||
|
||||
// Test to verify Fuzztest integration
|
||||
|
||||
#include "fuzztest/fuzztest.h" |
||||
|
||||
#include "gtest/gtest.h" |
||||
|
||||
TEST(MyTestSuite, OnePlustTwoIsTwoPlusOne) { EXPECT_EQ(1 + 2, 2 + 1); } |
||||
|
||||
void IntegerAdditionCommutes(int a, int b) { EXPECT_EQ(a + b, b + a); } |
||||
FUZZ_TEST(MyTestSuite, IntegerAdditionCommutes); |
@ -0,0 +1,28 @@ |
||||
# Copyright 2023 gRPC 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 |
||||
# |
||||
# http://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. |
||||
|
||||
""" |
||||
Rules for using fuzztest. |
||||
""" |
||||
|
||||
load("//bazel:grpc_build_system.bzl", "grpc_cc_test") |
||||
|
||||
def grpc_fuzz_test(name, srcs = [], deps = [], tags = [], external_deps = []): |
||||
grpc_cc_test( |
||||
name = name, |
||||
srcs = srcs, |
||||
tags = tags + ["grpc-fuzzer", "no-cache"], |
||||
deps = deps, |
||||
external_deps = external_deps, |
||||
) |
@ -0,0 +1,43 @@ |
||||
### DO NOT EDIT. Generated file. |
||||
# |
||||
# To regenerate, run the following from your project's workspace: |
||||
# |
||||
# bazel run @com_google_fuzztest//bazel:setup_configs > fuzztest.bazelrc |
||||
# |
||||
# And don't forget to add the following to your project's .bazelrc: |
||||
# |
||||
# try-import %workspace%/fuzztest.bazelrc |
||||
|
||||
|
||||
### Common options. |
||||
# |
||||
# Do not use directly. |
||||
|
||||
# Link with Address Sanitizer (ASAN). |
||||
build:fuzztest-common --linkopt=-fsanitize=address |
||||
|
||||
# Standard define for "ifdef-ing" any fuzz test specific code. |
||||
build:fuzztest-common --copt=-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
||||
|
||||
# In fuzz tests, we want to catch assertion violations even in optimized builds. |
||||
build:fuzztest-common --copt=-UNDEBUG |
||||
|
||||
|
||||
### FuzzTest build configuration. |
||||
# |
||||
# Use with: --config=fuzztest |
||||
|
||||
build:fuzztest --config=fuzztest-common |
||||
|
||||
# Link statically. |
||||
build:fuzztest --dynamic_mode=off |
||||
|
||||
# We rely on the following flag instead of the compiler provided |
||||
# __has_feature(address_sanitizer) to know that we have an ASAN build even in |
||||
# the uninstrumented runtime. |
||||
build:fuzztest --copt=-DADDRESS_SANITIZER |
||||
|
||||
# We apply coverage tracking and ASAN instrumentation to everything but the |
||||
# FuzzTest framework itself (including GoogleTest and GoogleMock). |
||||
build:fuzztest --per_file_copt=+//,-fuzztest/.*,-googletest/.*,-googlemock/.*@-fsanitize=address,-fsanitize-coverage=inline-8bit-counters,-fsanitize-coverage=trace-cmp |
||||
|
Loading…
Reference in new issue