Skip to content

Commit eef4e45

Browse files
xinhaoyuancopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 991792694
1 parent 88f66c0 commit eef4e45

6 files changed

Lines changed: 57 additions & 25 deletions

File tree

‎centipede/BUILD‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Description:
1616
# Centipede: an experimental distributed fuzzing engine.
1717

18+
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
1819
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
1920
load("@rules_cc//cc:cc_library.bzl", "cc_library")
2021
load("@rules_cc//cc:cc_static_library.bzl", "cc_static_library")
@@ -1004,10 +1005,24 @@ cc_library(
10041005
],
10051006
)
10061007

1008+
bool_flag(
1009+
name = "bundle_controller_binary",
1010+
build_setting_default = True,
1011+
)
1012+
1013+
config_setting(
1014+
name = "is_controller_binary_bundled",
1015+
flag_values = {":bundle_controller_binary": "True"},
1016+
)
1017+
10071018
cc_library(
10081019
name = "engine_controller_with_subprocess",
10091020
srcs = ["engine_controller_with_subprocess.cc"],
10101021
hdrs = ["engine_controller_abi.h"],
1022+
data = select({
1023+
":is_controller_binary_bundled": [":centipede_uninstrumented"],
1024+
"//conditions:default": [],
1025+
}),
10111026
deps = [
10121027
"@com_google_fuzztest//centipede:engine_abi",
10131028
"@com_google_fuzztest//fuzztest/internal:escaping",

‎centipede/centipede_test.cc‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,17 +1551,13 @@ TEST_F(CentipedeWithTemporaryLocalDir, EngineWorksInWorkerMode) {
15511551
}
15521552

15531553
TEST_F(CentipedeWithTemporaryLocalDir, EngineWorksInStandaloneMode) {
1554-
const std::string centipede_path =
1555-
GetDataDependencyFilepath("centipede/centipede");
15561554
const std::string test_binary_path = GetDataDependencyFilepath(
15571555
"centipede/testing/test_binary_for_engine_testing");
15581556
// Create a temporary dir and enter it for running the test binary, because
15591557
// the test binary uses CWD as the engine workdir.
15601558
TempCorpusDir tmp_dir{test_info_->name()};
15611559
const auto test_command =
1562-
absl::StrCat("cd ", tmp_dir.path().string(),
1563-
" && env FUZZTEST_CENTIPEDE_BINARY_PATH=", centipede_path,
1564-
" ", test_binary_path);
1560+
absl::StrCat("cd ", tmp_dir.path().string(), " && ", test_binary_path);
15651561
EXPECT_DEATH(
15661562
[&] {
15671563
const int status = std::system(test_command.c_str());

‎centipede/engine_controller_with_subprocess.cc‎

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,56 @@
1616

1717
#include <cstdlib>
1818
#include <cstring>
19+
#include <filesystem> // NOLINT
1920
#include <string>
21+
#include <system_error> // NOLINT
2022

2123
#include "./centipede/engine_abi.h"
2224
#include "./centipede/engine_controller_abi.h"
2325
#include "./fuzztest/internal/escaping.h"
2426

27+
namespace {
28+
2529
using fuzztest::internal::ShellEscape;
2630

31+
std::string GetBundledCentipedeBinaryPath() {
32+
constexpr const char* kBundledCentipedePathSuffix =
33+
"centipede/centipede_uninstrumented";
34+
const char* test_workspace = std::getenv("TEST_WORKSPACE");
35+
if (test_workspace == nullptr) {
36+
test_workspace = "_main";
37+
}
38+
std::string runfiles_dir;
39+
if (const char* test_srcdir = std::getenv("TEST_SRCDIR");
40+
test_srcdir != nullptr) {
41+
runfiles_dir = test_srcdir;
42+
}
43+
std::error_code ec;
44+
if (!runfiles_dir.empty()) {
45+
const auto path = std::filesystem::path{runfiles_dir} / test_workspace /
46+
kBundledCentipedePathSuffix;
47+
if (std::filesystem::exists(path, ec)) {
48+
return path.string();
49+
}
50+
}
51+
return "";
52+
}
53+
54+
} // namespace
55+
2756
FuzzTestControllerStatus FuzzTestControllerRun(
2857
const FuzzTestAdapterManager* manager, const FuzzTestBytesViews* flags) {
29-
// TODO(xinhaoyuan): Use the FuzzTest controller env var later.
3058
static auto centipede_binary_path = []() -> const char* {
31-
const char* env = std::getenv("FUZZTEST_CENTIPEDE_BINARY_PATH");
32-
if (env == nullptr) return nullptr;
33-
return strdup(env);
59+
// TODO(xinhaoyuan): Use the FuzzTest controller env var later.
60+
if (const char* env = std::getenv("FUZZTEST_CENTIPEDE_BINARY_PATH");
61+
env != nullptr) {
62+
return strdup(env);
63+
}
64+
const std::string bundled_path = GetBundledCentipedeBinaryPath();
65+
if (!bundled_path.empty()) {
66+
return strdup(bundled_path.c_str());
67+
}
68+
return nullptr;
3469
}();
3570
if (centipede_binary_path == nullptr) {
3671
return kFuzzTestControllerFailure;

‎rust/e2e_tests/BUILD‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ rust_test(
3333
name = "standalone_mode_test",
3434
srcs = ["standalone_mode_test.rs"],
3535
data = [
36-
"@com_google_fuzztest//centipede:centipede_uninstrumented",
3736
"@com_google_fuzztest//rust/e2e_tests/testdata:fuzztest_main",
3837
"@com_google_fuzztest//rust/e2e_tests/testdata:standalone_fuzz_tests_bin",
3938
],
@@ -100,7 +99,6 @@ rust_test(
10099
name = "replay_test",
101100
srcs = ["replay_test.rs"],
102101
data = [
103-
"@com_google_fuzztest//centipede:centipede_uninstrumented",
104102
"@com_google_fuzztest//rust/e2e_tests/testdata:replay_fuzz_tests_bin",
105103
],
106104
edition = "2024",

‎rust/e2e_tests/replay_test.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ fn replay_by_id_reproduces_panic(fixture: &EnvVars) {
5151
.env("FUZZTEST_CONTINUE_AFTER_CRASH", "true")
5252
.env("FUZZTEST_CORPUS_DB", &db_dir)
5353
.env("FUZZTEST_WORKDIR_ROOT", &workdir_root_dir)
54-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
5554
.status()
5655
.expect("Failed to spawn binary");
5756

@@ -64,7 +63,6 @@ fn replay_by_id_reproduces_panic(fixture: &EnvVars) {
6463
.env("FUZZTEST_LIST_CRASH_IDS", "true")
6564
.env("FUZZTEST_LIST_CRASH_IDS_FILE", &crash_ids_file)
6665
.env("FUZZTEST_CORPUS_DB", &db_dir)
67-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
6866
.status()
6967
.expect("Failed to execute target binary to list crash IDs");
7068
expect_true!(status.success());
@@ -87,7 +85,6 @@ fn replay_by_id_reproduces_panic(fixture: &EnvVars) {
8785
.arg("--nocapture")
8886
.env("FUZZTEST_REPLAY_ID", crash_id)
8987
.env("FUZZTEST_CORPUS_DB", &db_dir)
90-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
9188
.stdout(Stdio::piped())
9289
.stderr(Stdio::piped())
9390
.spawn()
@@ -131,7 +128,6 @@ fn replay_all_reproduces_all_failures(fixture: &EnvVars) {
131128
.env("FUZZTEST_CONTINUE_AFTER_CRASH", "true")
132129
.env("FUZZTEST_CORPUS_DB", &db_dir)
133130
.env("FUZZTEST_WORKDIR_ROOT", &workdir_root_dir)
134-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
135131
.status()
136132
.expect("Failed to spawn binary");
137133

@@ -141,7 +137,6 @@ fn replay_all_reproduces_all_failures(fixture: &EnvVars) {
141137
.arg("--exact")
142138
.env("FUZZTEST_REPLAY_FINDINGS", "true")
143139
.env("FUZZTEST_CORPUS_DB", &db_dir)
144-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
145140
.stdout(Stdio::piped())
146141
.stderr(Stdio::piped())
147142
.spawn()

‎rust/e2e_tests/standalone_mode_test.rs‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ fn standalone_mode_invokes_centipede(fixture: &EnvVars) {
2727
.arg(test_name)
2828
.env("FUZZTEST_FUZZ_FOR", "3s")
2929
.env("FUZZTEST_PRINT_SUBPROCESS_LOG", "true")
30-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
3130
.env("RUST_TEST_NOCAPTURE", "1")
3231
.stdout(std::process::Stdio::piped())
3332
.stderr(std::process::Stdio::piped())
@@ -39,8 +38,8 @@ fn standalone_mode_invokes_centipede(fixture: &EnvVars) {
3938

4039
// Assert that Centipede actually ran the test binary, and forwarded the worker log.
4140
// We check for "LOG: STANDALONE_VALIDATION_WORKER_EXECUTED". The prefix "LOG: " indicates that
42-
// this output is from centipede forwarding the output of the worker (due to --print_runner_log),
43-
// whereas the rest is from the fuzztest itself.
41+
// this output is from centipede forwarding the output of the worker (due to
42+
// --print_runner_log), whereas the rest is from the fuzztest itself.
4443
expect_that!(
4544
stderr,
4645
matchers::contains_substring("LOG: STANDALONE_VALIDATION_WORKER_EXECUTED")
@@ -57,7 +56,6 @@ fn standalone_mode_invokes_the_correct_fuzztest(fixture: &EnvVars) {
5756
.arg(test_name)
5857
.env("FUZZTEST_FUZZ_FOR", "3s")
5958
.env("FUZZTEST_PRINT_SUBPROCESS_LOG", "true")
60-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
6159
.env("RUST_TEST_NOCAPTURE", "1")
6260
.stdout(std::process::Stdio::piped())
6361
.stderr(std::process::Stdio::piped())
@@ -85,7 +83,6 @@ fn standalone_mode_handles_worker_crash(fixture: &EnvVars) {
8583
.arg(test_name)
8684
.env("FUZZTEST_FUZZ_FOR", "15s")
8785
.env("FUZZTEST_PRINT_SUBPROCESS_LOG", "true")
88-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
8986
.env("RUST_TEST_NOCAPTURE", "1")
9087
.stdout(std::process::Stdio::piped())
9188
.stderr(std::process::Stdio::piped())
@@ -111,7 +108,6 @@ fn standalone_mode_continues_after_crash_when_enabled(fixture: &EnvVars) {
111108
.env("FUZZTEST_FUZZ_FOR", "15s")
112109
.env("FUZZTEST_CONTINUE_AFTER_CRASH", "true")
113110
.env("FUZZTEST_PRINT_SUBPROCESS_LOG", "true")
114-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
115111
.env("RUST_TEST_NOCAPTURE", "1")
116112
.stdout(std::process::Stdio::piped())
117113
.stderr(std::process::Stdio::piped())
@@ -138,7 +134,6 @@ fn standalone_mode_spawns_parallel_jobs(fixture: &EnvVars) {
138134
.env("FUZZTEST_FUZZ_FOR", "5s")
139135
.env("FUZZTEST_JOBS", "4")
140136
.env("FUZZTEST_PRINT_SUBPROCESS_LOG", "true")
141-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
142137
.env("RUST_TEST_NOCAPTURE", "1")
143138
.stdout(std::process::Stdio::piped())
144139
.stderr(std::process::Stdio::piped())
@@ -215,7 +210,6 @@ fn standalone_mode_replay_corpus_per_test_budget(fixture: &EnvVars) {
215210
.env("FUZZTEST_REPLAY_CORPUS_FOR", "3s")
216211
.env("FUZZTEST_TIME_BUDGET_TYPE", "per-test")
217212
.env("FUZZTEST_PRINT_SUBPROCESS_LOG", "true")
218-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
219213
.env("FUZZTEST_CORPUS_DB", corpus_db.to_str().unwrap())
220214
.env("FUZZTEST_WORKDIR_ROOT", workdir_root.to_str().unwrap())
221215
.env("RUST_TEST_NOCAPTURE", "1")
@@ -307,7 +301,6 @@ fn standalone_mode_replay_corpus_total_budget(fixture: &EnvVars) {
307301
.env("FUZZTEST_REPLAY_CORPUS_FOR", "3s")
308302
.env("FUZZTEST_TIME_BUDGET_TYPE", "total")
309303
.env("FUZZTEST_PRINT_SUBPROCESS_LOG", "true")
310-
.env("FUZZTEST_CENTIPEDE_BINARY_PATH", &fixture.centipede_path)
311304
.env("FUZZTEST_CORPUS_DB", corpus_db.to_str().unwrap())
312305
.env("FUZZTEST_WORKDIR_ROOT", workdir_root.to_str().unwrap())
313306
.env("RUST_TEST_NOCAPTURE", "1")

0 commit comments

Comments
 (0)