Bläddra i källkod

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.
Jon Ross-Perkins 2 år sedan
förälder
incheckning
60c9b202f6

+ 0 - 5
bazel/fuzzing/BUILD

@@ -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.

+ 10 - 9
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",

+ 6 - 6
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

+ 1 - 1
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 {
 

+ 1 - 1
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 {
 

+ 1 - 1
explorer/fuzzing/ast_to_proto_test.cpp

@@ -14,8 +14,8 @@
 #include <set>
 #include <variant>
 
-#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 {

+ 1 - 1
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 {

+ 1 - 1
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 {
 

+ 1 - 1
explorer/fuzzing/fuzzer_util_test.cpp

@@ -9,9 +9,9 @@
 
 #include <fstream>
 
-#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 {

+ 0 - 0
common/fuzzing/BUILD → testing/fuzzing/BUILD


+ 0 - 0
common/fuzzing/carbon.proto → testing/fuzzing/carbon.proto


+ 2 - 2
common/fuzzing/proto_to_carbon.cpp → 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 <google/protobuf/text_format.h>
 
 #include <string_view>
 
-#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 {
 

+ 4 - 4
common/fuzzing/proto_to_carbon.h → 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_

+ 1 - 1
common/fuzzing/proto_to_carbon_main.cpp → 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 {
 

+ 2 - 2
common/fuzzing/proto_to_carbon_test.cpp → 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 <gmock/gmock.h>
 #include <gtest/gtest.h>
 
 #include "common/error.h"
-#include "common/fuzzing/carbon.pb.h"
+#include "testing/fuzzing/carbon.pb.h"
 
 namespace Carbon::Testing {
 namespace {

+ 0 - 0
bazel/fuzzing/rules.bzl → testing/fuzzing/rules.bzl


+ 1 - 1
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"])
 

+ 1 - 1
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")
 

+ 1 - 1
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")
 

+ 1 - 1
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")