From 60c9b202f6790d1bde04f8cb58542c1cc602df20 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Tue, 25 Jul 2023 06:27:56 -0700 Subject: [PATCH] Relocate fuzzer files and the explorer_fuzzer rule. (#3017) Putting fuzzer files under //testing to emphasize the testonly aspect (consolidates bazel and common subdirectories). The attributes on explorer_fuzzer are also a little skewed from what's desirable; it's been working okay, but this should still be a refinement. --- bazel/fuzzing/BUILD | 5 ----- explorer/fuzzing/BUILD | 19 ++++++++++--------- explorer/fuzzing/README.md | 12 ++++++------ explorer/fuzzing/ast_to_proto.h | 2 +- explorer/fuzzing/ast_to_proto_main.cpp | 2 +- explorer/fuzzing/ast_to_proto_test.cpp | 2 +- explorer/fuzzing/fuzzer_util.cpp | 2 +- explorer/fuzzing/fuzzer_util.h | 2 +- explorer/fuzzing/fuzzer_util_test.cpp | 2 +- {common => testing}/fuzzing/BUILD | 0 {common => testing}/fuzzing/carbon.proto | 0 .../fuzzing/proto_to_carbon.cpp | 4 ++-- {common => testing}/fuzzing/proto_to_carbon.h | 8 ++++---- .../fuzzing/proto_to_carbon_main.cpp | 2 +- .../fuzzing/proto_to_carbon_test.cpp | 4 ++-- {bazel => testing}/fuzzing/rules.bzl | 0 toolchain/driver/BUILD | 2 +- toolchain/lexer/BUILD | 2 +- toolchain/parser/BUILD | 2 +- toolchain/semantics/BUILD | 2 +- 20 files changed, 35 insertions(+), 39 deletions(-) delete mode 100644 bazel/fuzzing/BUILD rename {common => testing}/fuzzing/BUILD (100%) rename {common => testing}/fuzzing/carbon.proto (100%) rename {common => testing}/fuzzing/proto_to_carbon.cpp (99%) rename {common => testing}/fuzzing/proto_to_carbon.h (81%) rename {common => testing}/fuzzing/proto_to_carbon_main.cpp (96%) rename {common => testing}/fuzzing/proto_to_carbon_test.cpp (95%) rename {bazel => testing}/fuzzing/rules.bzl (100%) diff --git a/bazel/fuzzing/BUILD b/bazel/fuzzing/BUILD deleted file mode 100644 index 74906e61dd59..000000000000 --- a/bazel/fuzzing/BUILD +++ /dev/null @@ -1,5 +0,0 @@ -# Part of the Carbon Language project, under the Apache License v2.0 with LLVM -# Exceptions. See /LICENSE for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Empty BUILD file to allow access to Bazel extensions. diff --git a/explorer/fuzzing/BUILD b/explorer/fuzzing/BUILD index e08f1a6f3a83..9edaf6beed24 100644 --- a/explorer/fuzzing/BUILD +++ b/explorer/fuzzing/BUILD @@ -2,7 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test") +load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") cc_library( name = "ast_to_proto_lib", @@ -10,8 +10,8 @@ cc_library( srcs = ["ast_to_proto.cpp"], hdrs = ["ast_to_proto.h"], deps = [ - "//common/fuzzing:carbon_cc_proto", "//explorer/ast", + "//testing/fuzzing:carbon_cc_proto", "@llvm-project//llvm:Support", ], ) @@ -24,10 +24,10 @@ cc_binary( ":ast_to_proto_lib", "//common:bazel_working_dir", "//common:error", - "//common/fuzzing:carbon_cc_proto", "//explorer/ast", "//explorer/common:arena", "//explorer/syntax", + "//testing/fuzzing:carbon_cc_proto", "@com_google_protobuf//:protobuf_headers", ], ) @@ -45,9 +45,9 @@ cc_test( ], deps = [ ":ast_to_proto_lib", - "//common/fuzzing:carbon_cc_proto", - "//common/fuzzing:proto_to_carbon_lib", "//explorer/syntax", + "//testing/fuzzing:carbon_cc_proto", + "//testing/fuzzing:proto_to_carbon_lib", "//testing/util:test_raw_ostream", "@com_google_googletest//:gtest", "@com_google_protobuf//:protobuf_headers", @@ -62,10 +62,10 @@ cc_library( deps = [ "//common:check", "//common:error", - "//common/fuzzing:carbon_cc_proto", - "//common/fuzzing:proto_to_carbon_lib", "//explorer/ast", "//explorer/parse_and_execute", + "//testing/fuzzing:carbon_cc_proto", + "//testing/fuzzing:proto_to_carbon_lib", "@bazel_tools//tools/cpp/runfiles", "@com_google_protobuf//:protobuf_headers", "@llvm-project//llvm:Support", @@ -80,7 +80,7 @@ cc_test( ], deps = [ ":fuzzer_util", - "//common/fuzzing:proto_to_carbon_lib", + "//testing/fuzzing:proto_to_carbon_lib", "//testing/util:gtest_main", "@com_google_googletest//:gtest", "@com_google_protobuf//:protobuf_headers", @@ -90,10 +90,11 @@ cc_test( cc_fuzz_test( name = "explorer_fuzzer", - testonly = 1, + size = "small", srcs = ["explorer_fuzzer.cpp"], corpus = glob(["fuzzer_corpus/*"]), shard_count = 8, + tags = ["proto-fuzzer"], deps = [ ":fuzzer_util", "//common:error", diff --git a/explorer/fuzzing/README.md b/explorer/fuzzing/README.md index cc6dd5032622..06681ef62c1f 100644 --- a/explorer/fuzzing/README.md +++ b/explorer/fuzzing/README.md @@ -32,11 +32,11 @@ execute the code using `explorer` implementation. `libprotobuf-mutator` supports fuzzer inputs in either text or binary protocol buffer format. `explorer_fuzzer` uses text proto format with `Carbon` proto -message definition in `common/fuzzing/carbon.proto`. +message definition in `testing/fuzzing/carbon.proto`. ## Incorporating AST changes into the fuzzer -Fuzzer AST representation in [carbon.proto](/common/fuzzing/carbon.proto) needs +Fuzzer AST representation in [carbon.proto](/testing/fuzzing/carbon.proto) needs to be updated when changes are made to the AST, like adding a new AST node classes or changing relevant data members of existing nodes. @@ -47,10 +47,10 @@ changes, as tests work off of Carbon test files in To incorporate AST changes into fuzzing logic: 1. Add appropriate AST information to - [carbon.proto](/common/fuzzing/carbon.proto). Use existing similar cases as + [carbon.proto](/testing/fuzzing/carbon.proto). Use existing similar cases as examples. -2. Modify [proto_to_carbon.cpp](/common/fuzzing/proto_to_carbon.cpp) which +2. Modify [proto_to_carbon.cpp](/testing/fuzzing/proto_to_carbon.cpp) which handles printing of a Carbon proto instance as a Carbon source string. For example, add code to print newly introduced proto fields. @@ -88,9 +88,9 @@ program directly. You can do this with: ```bash # Convert a specific fuzzer test to a source file -bazel run //common/fuzzing:proto_to_carbon -- explorer/fuzzing/fuzzer_corpus/abcd1234 > crash.carbon +bazel run //testing/fuzzing:proto_to_carbon -- explorer/fuzzing/fuzzer_corpus/abcd1234 > crash.carbon # Or convert the crash to a source file. -bazel run //common/fuzzing:proto_to_carbon -- /tmp/crash.textproto > crash.carbon +bazel run //testing/fuzzing:proto_to_carbon -- /tmp/crash.textproto > crash.carbon # Run explorer on the crash. bazel run //explorer -- crash.carbon diff --git a/explorer/fuzzing/ast_to_proto.h b/explorer/fuzzing/ast_to_proto.h index eac3c696bcdf..c2fcb856b0c4 100644 --- a/explorer/fuzzing/ast_to_proto.h +++ b/explorer/fuzzing/ast_to_proto.h @@ -5,8 +5,8 @@ #ifndef CARBON_EXPLORER_FUZZING_AST_TO_PROTO_H_ #define CARBON_EXPLORER_FUZZING_AST_TO_PROTO_H_ -#include "common/fuzzing/carbon.pb.h" #include "explorer/ast/ast.h" +#include "testing/fuzzing/carbon.pb.h" namespace Carbon::Testing { diff --git a/explorer/fuzzing/ast_to_proto_main.cpp b/explorer/fuzzing/ast_to_proto_main.cpp index ebdf1ef48b6d..f7962400a3d4 100644 --- a/explorer/fuzzing/ast_to_proto_main.cpp +++ b/explorer/fuzzing/ast_to_proto_main.cpp @@ -13,11 +13,11 @@ #include "common/bazel_working_dir.h" #include "common/error.h" -#include "common/fuzzing/carbon.pb.h" #include "explorer/ast/ast.h" #include "explorer/common/arena.h" #include "explorer/fuzzing/ast_to_proto.h" #include "explorer/syntax/parse.h" +#include "testing/fuzzing/carbon.pb.h" namespace Carbon::Testing { diff --git a/explorer/fuzzing/ast_to_proto_test.cpp b/explorer/fuzzing/ast_to_proto_test.cpp index 8563cc2de537..744307d8dac1 100644 --- a/explorer/fuzzing/ast_to_proto_test.cpp +++ b/explorer/fuzzing/ast_to_proto_test.cpp @@ -14,8 +14,8 @@ #include #include -#include "common/fuzzing/proto_to_carbon.h" #include "explorer/syntax/parse.h" +#include "testing/fuzzing/proto_to_carbon.h" #include "testing/util/test_raw_ostream.h" namespace Carbon::Testing { diff --git a/explorer/fuzzing/fuzzer_util.cpp b/explorer/fuzzing/fuzzer_util.cpp index 67de69c82bf5..a40488d658ef 100644 --- a/explorer/fuzzing/fuzzer_util.cpp +++ b/explorer/fuzzing/fuzzer_util.cpp @@ -8,10 +8,10 @@ #include "common/check.h" #include "common/error.h" -#include "common/fuzzing/proto_to_carbon.h" #include "explorer/parse_and_execute/parse_and_execute.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" +#include "testing/fuzzing/proto_to_carbon.h" #include "tools/cpp/runfiles/runfiles.h" namespace Carbon::Testing { diff --git a/explorer/fuzzing/fuzzer_util.h b/explorer/fuzzing/fuzzer_util.h index 79cc71a5d044..fc8aa1694384 100644 --- a/explorer/fuzzing/fuzzer_util.h +++ b/explorer/fuzzing/fuzzer_util.h @@ -6,8 +6,8 @@ #define CARBON_EXPLORER_FUZZING_FUZZER_UTIL_H_ #include "common/error.h" -#include "common/fuzzing/carbon.pb.h" #include "explorer/ast/ast.h" +#include "testing/fuzzing/carbon.pb.h" namespace Carbon::Testing { diff --git a/explorer/fuzzing/fuzzer_util_test.cpp b/explorer/fuzzing/fuzzer_util_test.cpp index 62e26b9f3495..3ac76ccbdd7f 100644 --- a/explorer/fuzzing/fuzzer_util_test.cpp +++ b/explorer/fuzzing/fuzzer_util_test.cpp @@ -9,9 +9,9 @@ #include -#include "common/fuzzing/proto_to_carbon.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" +#include "testing/fuzzing/proto_to_carbon.h" namespace Carbon::Testing { namespace { diff --git a/common/fuzzing/BUILD b/testing/fuzzing/BUILD similarity index 100% rename from common/fuzzing/BUILD rename to testing/fuzzing/BUILD diff --git a/common/fuzzing/carbon.proto b/testing/fuzzing/carbon.proto similarity index 100% rename from common/fuzzing/carbon.proto rename to testing/fuzzing/carbon.proto diff --git a/common/fuzzing/proto_to_carbon.cpp b/testing/fuzzing/proto_to_carbon.cpp similarity index 99% rename from common/fuzzing/proto_to_carbon.cpp rename to testing/fuzzing/proto_to_carbon.cpp index 1bcd1c2f2ed7..a9cb40ebc00b 100644 --- a/common/fuzzing/proto_to_carbon.cpp +++ b/testing/fuzzing/proto_to_carbon.cpp @@ -2,15 +2,15 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include "common/fuzzing/proto_to_carbon.h" +#include "testing/fuzzing/proto_to_carbon.h" #include #include -#include "common/fuzzing/carbon.pb.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Support/raw_ostream.h" +#include "testing/fuzzing/carbon.pb.h" namespace Carbon { diff --git a/common/fuzzing/proto_to_carbon.h b/testing/fuzzing/proto_to_carbon.h similarity index 81% rename from common/fuzzing/proto_to_carbon.h rename to testing/fuzzing/proto_to_carbon.h index 88196a297970..4455c77ec447 100644 --- a/common/fuzzing/proto_to_carbon.h +++ b/testing/fuzzing/proto_to_carbon.h @@ -2,11 +2,11 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#ifndef CARBON_COMMON_FUZZING_PROTO_TO_CARBON_H_ -#define CARBON_COMMON_FUZZING_PROTO_TO_CARBON_H_ +#ifndef CARBON_TESTING_FUZZING_PROTO_TO_CARBON_H_ +#define CARBON_TESTING_FUZZING_PROTO_TO_CARBON_H_ #include "common/error.h" -#include "common/fuzzing/carbon.pb.h" +#include "testing/fuzzing/carbon.pb.h" namespace Carbon { @@ -24,4 +24,4 @@ auto ParseCarbonTextProto(const std::string& contents) } // namespace Carbon -#endif // CARBON_COMMON_FUZZING_PROTO_TO_CARBON_H_ +#endif // CARBON_TESTING_FUZZING_PROTO_TO_CARBON_H_ diff --git a/common/fuzzing/proto_to_carbon_main.cpp b/testing/fuzzing/proto_to_carbon_main.cpp similarity index 96% rename from common/fuzzing/proto_to_carbon_main.cpp rename to testing/fuzzing/proto_to_carbon_main.cpp index 7598b033895d..0483ad7269bd 100644 --- a/common/fuzzing/proto_to_carbon_main.cpp +++ b/testing/fuzzing/proto_to_carbon_main.cpp @@ -13,7 +13,7 @@ #include "common/bazel_working_dir.h" #include "common/error.h" -#include "common/fuzzing/proto_to_carbon.h" +#include "testing/fuzzing/proto_to_carbon.h" namespace Carbon { diff --git a/common/fuzzing/proto_to_carbon_test.cpp b/testing/fuzzing/proto_to_carbon_test.cpp similarity index 95% rename from common/fuzzing/proto_to_carbon_test.cpp rename to testing/fuzzing/proto_to_carbon_test.cpp index 18227f3543ae..063fe9ab2f32 100644 --- a/common/fuzzing/proto_to_carbon_test.cpp +++ b/testing/fuzzing/proto_to_carbon_test.cpp @@ -2,13 +2,13 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -#include "common/fuzzing/proto_to_carbon.h" +#include "testing/fuzzing/proto_to_carbon.h" #include #include #include "common/error.h" -#include "common/fuzzing/carbon.pb.h" +#include "testing/fuzzing/carbon.pb.h" namespace Carbon::Testing { namespace { diff --git a/bazel/fuzzing/rules.bzl b/testing/fuzzing/rules.bzl similarity index 100% rename from bazel/fuzzing/rules.bzl rename to testing/fuzzing/rules.bzl diff --git a/toolchain/driver/BUILD b/toolchain/driver/BUILD index 3b2b74e5aa72..153cfc39ccbb 100644 --- a/toolchain/driver/BUILD +++ b/toolchain/driver/BUILD @@ -3,7 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception load("//bazel/cc_toolchains:defs.bzl", "cc_env") -load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test") +load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") package(default_visibility = ["//visibility:public"]) diff --git a/toolchain/lexer/BUILD b/toolchain/lexer/BUILD index 24b106237c00..571af41b4fa8 100644 --- a/toolchain/lexer/BUILD +++ b/toolchain/lexer/BUILD @@ -2,7 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test") +load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") load("//bazel/sh_run:rules.bzl", "glob_sh_run") load("//testing/file_test:rules.bzl", "file_test") diff --git a/toolchain/parser/BUILD b/toolchain/parser/BUILD index 6e6b2f9f76b3..1d20fff7d90b 100644 --- a/toolchain/parser/BUILD +++ b/toolchain/parser/BUILD @@ -2,7 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test") +load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") load("//bazel/sh_run:rules.bzl", "glob_sh_run") load("//testing/file_test:rules.bzl", "file_test") diff --git a/toolchain/semantics/BUILD b/toolchain/semantics/BUILD index 700bc87a5825..efada5e3da2e 100644 --- a/toolchain/semantics/BUILD +++ b/toolchain/semantics/BUILD @@ -2,7 +2,7 @@ # Exceptions. See /LICENSE for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -load("//bazel/fuzzing:rules.bzl", "cc_fuzz_test") +load("//testing/fuzzing:rules.bzl", "cc_fuzz_test") load("//bazel/sh_run:rules.bzl", "glob_sh_run") load("//testing/file_test:rules.bzl", "file_test")