Skip to content

Commit d356d59

Browse files
FuzzTest Teamcopybara-github
authored andcommitted
Add flatbuffers enum domain
PiperOrigin-RevId: 745943824
1 parent a7e9c58 commit d356d59

19 files changed

+1806
-3
lines changed

.github/workflows/cmake_test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
7878
-D CMAKE_BUILD_TYPE=RelWithDebug \
7979
-D FUZZTEST_BUILD_TESTING=on \
80+
-D FUZZTEST_BUILD_FLATBUFFERS=on \
8081
&& cmake --build build -j $(nproc) \
8182
&& ctest --test-dir build -j $(nproc) --output-on-failure
8283
- name: Run all tests in default mode with gcc
@@ -90,6 +91,7 @@ jobs:
9091
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
9192
-D CMAKE_BUILD_TYPE=RelWithDebug \
9293
-D FUZZTEST_BUILD_TESTING=on \
94+
-D FUZZTEST_BUILD_FLATBUFFERS=on \
9395
&& cmake --build build_gcc -j $(nproc) \
9496
&& ctest --test-dir build_gcc -j $(nproc) --output-on-failure
9597
- name: Run end-to-end tests in fuzzing mode
@@ -104,6 +106,7 @@ jobs:
104106
-D CMAKE_BUILD_TYPE=RelWithDebug \
105107
-D FUZZTEST_FUZZING_MODE=on \
106108
-D FUZZTEST_BUILD_TESTING=on \
109+
-D FUZZTEST_BUILD_FLATBUFFERS=on \
107110
&& cmake --build build -j $(nproc) \
108111
&& ctest --test-dir build -j $(nproc) --output-on-failure -R "functional_test"
109112
- name: Save new cache based on main

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.19)
22
project(fuzztest)
33

44
option(FUZZTEST_BUILD_TESTING "Building the tests." OFF)
5+
option(FUZZTEST_BUILD_FLATBUFFERS "Building the flatbuffers support." OFF)
56
option(FUZZTEST_FUZZING_MODE "Building the fuzztest in fuzzing mode." OFF)
67
set(FUZZTEST_COMPATIBILITY_MODE "" CACHE STRING "Compatibility mode. Available options: <empty>, libfuzzer")
78
set(CMAKE_CXX_STANDARD 17)

MODULE.bazel

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ bazel_dep(
4242
name = "platforms",
4343
version = "0.0.10",
4444
)
45+
bazel_dep(
46+
name = "flatbuffers",
47+
version = "25.2.10"
48+
)
4549
# GoogleTest is not a dev dependency, because it's needed when FuzzTest is used
4650
# with GoogleTest integration (e.g., googletest_adaptor). Note that the FuzzTest
4751
# framework can be used without GoogleTest integration as well.
@@ -55,8 +59,6 @@ bazel_dep(
5559
name = "protobuf",
5660
version = "30.2",
5761
)
58-
# TODO(lszekeres): Make this a dev dependency, as the protobuf library is only
59-
# required for testing.
6062
bazel_dep(
6163
name = "rules_proto",
6264
version = "7.1.0",

cmake/BuildDependencies.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ set(proto_TAG v30.2)
2121
set(nlohmann_json_URL https://github.com/nlohmann/json.git)
2222
set(nlohmann_json_TAG v3.11.3)
2323

24+
set(flatbuffers_URL https://github.com/google/flatbuffers.git)
25+
set(flatbuffers_TAG v25.2.10)
26+
2427
if(POLICY CMP0135)
2528
cmake_policy(SET CMP0135 NEW)
2629
set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
@@ -50,6 +53,14 @@ FetchContent_Declare(
5053
URL_HASH MD5=${antlr_cpp_MD5}
5154
)
5255

56+
if (FUZZTEST_BUILD_FLATBUFFERS)
57+
FetchContent_Declare(
58+
flatbuffers
59+
GIT_REPOSITORY ${flatbuffers_URL}
60+
GIT_TAG ${flatbuffers_TAG}
61+
)
62+
endif()
63+
5364
if (FUZZTEST_BUILD_TESTING)
5465

5566
FetchContent_Declare(
@@ -87,3 +98,9 @@ if (FUZZTEST_BUILD_TESTING)
8798
FetchContent_MakeAvailable(nlohmann_json)
8899

89100
endif ()
101+
102+
if (FUZZTEST_BUILD_FLATBUFFERS)
103+
set(FLATBUFFERS_BUILD_TESTS OFF)
104+
set(FLATBUFFERS_BUILD_INSTALL OFF)
105+
FetchContent_MakeAvailable(flatbuffers)
106+
endif()

cmake/generate_cmake_from_bazel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@abseil-cpp//absl/types:optional": "absl::optional",
5353
"@abseil-cpp//absl/types:span": "absl::span",
5454
"@abseil-cpp//absl/types:variant": "absl::variant",
55+
"@flatbuffers//:runtime_cc": "flatbuffers",
5556
"@googletest//:gtest": "GTest::gtest",
5657
"@googletest//:gtest_main": "GTest::gmock_main",
5758
"@protobuf//:protobuf": "protobuf::libprotobuf",

domain_tests/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ cc_test(
3737
],
3838
)
3939

40+
cc_test(
41+
name = "arbitrary_domains_flatbuffers_test",
42+
srcs = ["arbitrary_domains_flatbuffers_test.cc"],
43+
deps = [
44+
":domain_testing",
45+
"@abseil-cpp//absl/container:flat_hash_map",
46+
"@abseil-cpp//absl/random",
47+
"@com_google_fuzztest//fuzztest:domain",
48+
"@com_google_fuzztest//fuzztest:flatbuffers",
49+
"@com_google_fuzztest//fuzztest:meta",
50+
"@com_google_fuzztest//fuzztest:test_flatbuffers_cc_fbs",
51+
"@flatbuffers//:runtime_cc",
52+
"@googletest//:gtest_main",
53+
],
54+
)
55+
4056
cc_test(
4157
name = "arbitrary_domains_protobuf_test",
4258
srcs = ["arbitrary_domains_protobuf_test.cc"],

domain_tests/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ fuzztest_cc_test(
2323
GTest::gmock_main
2424
)
2525

26+
if (FUZZTEST_BUILD_FLATBUFFERS)
27+
fuzztest_cc_test(
28+
NAME
29+
arbitrary_domains_flatbuffers_test
30+
SRCS
31+
"arbitrary_domains_flatbuffers_test.cc"
32+
DEPS
33+
absl::flat_hash_set
34+
absl::random_bit_gen_ref
35+
absl::random_random
36+
absl::strings
37+
flatbuffers
38+
fuzztest::domain
39+
fuzztest::domain_testing
40+
fuzztest::flatbuffers
41+
GTest::gmock_main
42+
test_flatbuffers
43+
)
44+
add_dependencies(fuzztest_arbitrary_domains_flatbuffers_test
45+
GENERATE_test_flatbuffers
46+
)
47+
endif()
48+
2649
fuzztest_cc_test(
2750
NAME
2851
arbitrary_domains_protobuf_test

0 commit comments

Comments
 (0)