Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 45 additions & 37 deletions centipede/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -976,36 +976,6 @@ cc_library(
],
)

cc_library(
name = "engine_worker",
srcs = [
"engine_worker.cc",
"runner_utils.cc",
"runner_utils.h",
],
hdrs = ["engine_worker_abi.h"],
deps = [
":engine_abi",
":execution_metadata",
":feature",
":runner_request",
":runner_result",
":shared_memory_blob_sequence",
"@abseil-cpp//absl/base:nullability",
"@com_google_fuzztest//common:defs",
],
)

cc_library(
name = "engine_controller_with_subprocess",
srcs = ["engine_controller_with_subprocess.cc"],
hdrs = ["engine_controller_abi.h"],
deps = [
"@com_google_fuzztest//centipede:engine_abi",
"@com_google_fuzztest//fuzztest/internal:escaping",
],
)

# The runner library is special:
# * It must not be instrumented with asan, sancov, etc.
# * It must not have heavy dependencies, and ideally not at all.
Expand All @@ -1026,8 +996,6 @@ RUNNER_SOURCES_NO_MAIN = [
"runner_dl_info.cc",
"runner_dl_info.h",
"runner_interface.h",
"runner_utils.cc",
"runner_utils.h",
"sancov_callbacks.cc",
"sancov_interceptors.cc",
"sancov_object_array.cc",
Expand Down Expand Up @@ -1075,11 +1043,12 @@ RUNNER_DEPS = [
":knobs",
":mutation_data",
":rolling_hash",
":engine_abi",
":runner_cmp_trace",
":runner_fork_server",
":runner_request",
":runner_result",
":runner_utils",
":engine_abi",
":engine_worker",
":shared_memory_blob_sequence",
"@com_google_fuzztest//common:defs",
"@abseil-cpp//absl/base:core_headers",
Expand All @@ -1088,6 +1057,45 @@ RUNNER_DEPS = [
"@abseil-cpp//absl/types:span",
]

cc_library(
name = "runner_utils",
srcs = ["runner_utils.cc"],
hdrs = ["runner_utils.h"],
copts = RUNNER_COPTS,
deps = ["@abseil-cpp//absl/base:nullability"],
)

cc_library(
name = "engine_worker",
srcs = [
"engine_worker.cc",
],
hdrs = ["engine_worker_abi.h"],
copts = RUNNER_COPTS,
deps = [
":engine_abi",
":execution_metadata",
":feature",
":runner_fork_server",
":runner_request",
":runner_result",
":runner_utils",
":shared_memory_blob_sequence",
"@abseil-cpp//absl/base:nullability",
"@com_google_fuzztest//common:defs",
],
)

cc_library(
name = "engine_controller_with_subprocess",
srcs = ["engine_controller_with_subprocess.cc"],
hdrs = ["engine_controller_abi.h"],
deps = [
"@com_google_fuzztest//centipede:engine_abi",
"@com_google_fuzztest//fuzztest/internal:escaping",
],
)

# A fuzz target needs to link with this library in order to run with Centipede.
# The fuzz target must provide its own main().
#
Expand Down Expand Up @@ -1139,6 +1147,7 @@ cc_library(
linkstatic = True, # Must be linked statically even when dynamic_mode=on.
deps = [
":centipede_runner_no_main",
":execution_metadata",
":mutation_data",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/types:span",
Expand Down Expand Up @@ -1216,8 +1225,6 @@ cc_library(
"reverse_pc_table.h",
"runner_dl_info.cc",
"runner_dl_info.h",
"runner_utils.cc",
"runner_utils.h",
"sancov_callbacks.cc",
"sancov_interceptors.cc",
"sancov_object_array.cc",
Expand All @@ -1239,6 +1246,7 @@ cc_library(
":foreach_nonzero",
":int_utils",
":runner_cmp_trace",
":runner_utils",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/numeric:bits",
Expand Down Expand Up @@ -1957,7 +1965,7 @@ cc_test(
timeout = "long",
srcs = ["centipede_test.cc"],
data = [
"@com_google_fuzztest//centipede",
":centipede",
"@com_google_fuzztest//centipede/testing:abort_fuzz_target",
"@com_google_fuzztest//centipede/testing:async_failing_target",
"@com_google_fuzztest//centipede/testing:expensive_startup_fuzz_target",
Expand Down
21 changes: 8 additions & 13 deletions centipede/centipede_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -963,14 +963,8 @@ TEST_F(CentipedeWithTemporaryLocalDir, GetsSeedInputs) {
CentipedeDefaultCallbacks callbacks(env, stop_condition);

std::vector<ByteArray> seeds;
EXPECT_EQ(callbacks.GetSeeds(10, seeds), 10);
EXPECT_THAT(seeds, testing::ContainerEq(std::vector<ByteArray>{
{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}}));
EXPECT_EQ(callbacks.GetSeeds(5, seeds), 10);
EXPECT_THAT(seeds, testing::ContainerEq(
std::vector<ByteArray>{{0}, {1}, {2}, {3}, {4}}));
EXPECT_EQ(callbacks.GetSeeds(100, seeds), 10);
EXPECT_THAT(seeds, testing::ContainerEq(std::vector<ByteArray>{
callbacks.GetSeeds(10, seeds);
EXPECT_THAT(seeds, testing::IsSupersetOf(std::vector<ByteArray>{
{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}}));
}

Expand Down Expand Up @@ -1277,12 +1271,13 @@ TEST_F(CentipedeWithTemporaryLocalDir, UsesProvidedCustomMutator) {
"centipede/testing/fuzz_target_with_custom_mutator");
CentipedeDefaultCallbacks callbacks(env, stop_condition);

const std::vector<ByteArray> inputs = {{1}, {2}, {3}, {4}, {5}, {6}};
const std::vector<Mutant> mutants = callbacks.Mutate(
GetMutationInputRefsFromDataInputs(inputs), inputs.size());
const std::vector<ByteArray> inputs = {{99}};
const std::vector<Mutant> mutants =
callbacks.Mutate(GetMutationInputRefsFromDataInputs(inputs), 5);

// The custom mutator just returns the original inputs as mutants.
EXPECT_EQ(inputs, GetDataFromMutants(mutants));
// The custom mutator just duplicates the original inputs as mutants.
EXPECT_EQ(GetDataFromMutants(mutants),
(std::vector<ByteArray>{{99}, {99}, {99}, {99}, {99}}));
}

TEST_F(CentipedeWithTemporaryLocalDir, FailsOnMisbehavingCustomMutator) {
Expand Down
Loading
Loading