Skip to content

Commit e505dfb

Browse files
lowdaniecopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 917997132
1 parent 4639541 commit e505dfb

12 files changed

Lines changed: 199 additions & 156 deletions

File tree

centipede/BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ licenses(["notice"])
3838
cc_binary(
3939
name = "centipede",
4040
srcs = ["centipede_main.cc"],
41+
compatible_with = [],
4142
deps = [
4243
":centipede_callbacks",
4344
":centipede_default_callbacks",
@@ -52,12 +53,14 @@ cc_binary(
5253
cc_uninstrumented_binary(
5354
name = "centipede_uninstrumented",
5455
binary = ":centipede",
56+
compatible_with = [],
5557
)
5658

5759
# A standalone seed corpus generator.
5860
cc_binary(
5961
name = "seed_corpus_maker",
6062
srcs = ["seed_corpus_maker.cc"],
63+
compatible_with = [],
6164
deps = [
6265
":config_init",
6366
":seed_corpus_maker_flags",
@@ -73,6 +76,7 @@ cc_binary(
7376
cc_binary(
7477
name = "blob_file_converter",
7578
srcs = ["blob_file_converter.cc"],
79+
compatible_with = [],
7680
deps = [
7781
":config_init",
7882
":rusage_profiler",
@@ -1992,3 +1996,12 @@ sh_test(
19921996
":test_util_sh",
19931997
],
19941998
)
1999+
2000+
filegroup(
2001+
name = "oss_srcs",
2002+
srcs = [
2003+
"centipede_main.cc",
2004+
"seed_corpus_maker.cc",
2005+
],
2006+
visibility = ["//visibility:private"],
2007+
)

common/BUILD

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
# The package contains libraries that are common to both FuzzTest and Centipede.
1616

17-
load("@rules_cc//cc:cc_library.bzl", "cc_library")
1817
load("@rules_cc//cc:cc_test.bzl", "cc_test")
1918

2019
DEFAULT_VISIBILITY = ["//visibility:public"]
@@ -98,6 +97,17 @@ cc_library(
9897
deps = ["@abseil-cpp//absl/types:span"],
9998
)
10099

100+
cc_library(
101+
name = "env_util",
102+
srcs = ["env_util.cc"],
103+
hdrs = ["env_util.h"],
104+
deps = [
105+
"@abseil-cpp//absl/strings",
106+
"@abseil-cpp//absl/strings:str_format",
107+
"@abseil-cpp//absl/time",
108+
],
109+
)
110+
101111
cc_library(
102112
name = "hash",
103113
srcs = ["hash.cc"],
@@ -126,23 +136,21 @@ cc_library(
126136
"//conditions:default": [],
127137
}),
128138
deps = [
129-
":defs",
130-
":logging",
131-
":status_macros",
132-
"@abseil-cpp//absl/base:nullability",
133-
"@abseil-cpp//absl/status",
134-
"@abseil-cpp//absl/status:statusor",
135-
"@abseil-cpp//absl/strings",
136-
] + select({
137-
"//conditions:default": [":remote_file_oss"],
138-
}) +
139-
select({
140-
"@com_google_fuzztest//fuzztest:disable_riegeli": [],
141-
"//conditions:default": [
142-
"@com_google_riegeli//riegeli/bytes:reader",
143-
"@com_google_riegeli//riegeli/bytes:writer",
144-
],
145-
}),
139+
":defs",
140+
":logging",
141+
":remote_file_oss",
142+
":status_macros",
143+
"@abseil-cpp//absl/base:nullability",
144+
"@abseil-cpp//absl/status",
145+
"@abseil-cpp//absl/status:statusor",
146+
"@abseil-cpp//absl/strings",
147+
] + select({
148+
"@com_google_fuzztest//fuzztest:disable_riegeli": [],
149+
"//conditions:default": [
150+
"@com_google_riegeli//riegeli/bytes:reader",
151+
"@com_google_riegeli//riegeli/bytes:writer",
152+
],
153+
}),
146154
)
147155

148156
cc_library(
@@ -155,7 +163,6 @@ cc_library(
155163
"@com_google_fuzztest//fuzztest:disable_riegeli": ["CENTIPEDE_DISABLE_RIEGELI"],
156164
"//conditions:default": [],
157165
}),
158-
visibility = ["//visibility:private"],
159166
deps = [
160167
":defs",
161168
":logging",
@@ -253,30 +260,18 @@ cc_test(
253260
)
254261

255262
# TODO(b/324462306): Merge this with remote_file_test once the bug is fixed.
256-
cc_library(
257-
name = "remote_file_test_lib",
258-
testonly = True,
263+
exports_files(["remote_file_test.cc"])
264+
265+
cc_test(
266+
name = "remote_file_test",
259267
srcs = ["remote_file_test.cc"],
260-
defines = select({
261-
"//conditions:default": [],
262-
}),
263268
deps = [
264269
":logging",
265270
":remote_file",
266271
":test_util",
267272
"@abseil-cpp//absl/status",
268273
"@abseil-cpp//absl/time",
269274
"@googletest//:gtest",
270-
] + select({
271-
"//conditions:default": [],
272-
}),
273-
alwayslink = True,
274-
)
275-
276-
cc_test(
277-
name = "remote_file_test",
278-
deps = [
279-
":remote_file_test_lib",
280275
"@googletest//:gtest_main",
281276
],
282277
)

common/env_util.cc

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2026 The Centipede Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "./common/env_util.h"
16+
17+
#include <cstdlib>
18+
#include <string>
19+
20+
#include "absl/strings/str_format.h"
21+
#include "absl/strings/string_view.h"
22+
#include "absl/time/time.h"
23+
24+
namespace fuzztest::internal {
25+
26+
absl::Duration GetDurationFromEnv(absl::string_view env_var_name,
27+
absl::Duration default_value) {
28+
const char* env_val = std::getenv(std::string(env_var_name).c_str());
29+
if (env_val == nullptr) return default_value;
30+
31+
absl::Duration duration;
32+
if (absl::ParseDuration(env_val, &duration)) {
33+
return duration;
34+
}
35+
36+
absl::FPrintF(stderr,
37+
"[!] Cannot parse env %s=%s as duration. Using default.\n",
38+
env_var_name, env_val);
39+
return default_value;
40+
}
41+
42+
} // namespace fuzztest::internal

common/env_util.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2026 The Centipede Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef FUZZTEST_COMMON_ENV_UTIL_H_
16+
#define FUZZTEST_COMMON_ENV_UTIL_H_
17+
18+
#include "absl/strings/string_view.h"
19+
#include "absl/time/time.h"
20+
21+
namespace fuzztest::internal {
22+
23+
// Returns the duration parsed from the environment variable `env_var_name`.
24+
// If the variable is unset or cannot be parsed, returns `default_value`.
25+
absl::Duration GetDurationFromEnv(absl::string_view env_var_name,
26+
absl::Duration default_value);
27+
28+
} // namespace fuzztest::internal
29+
30+
#endif // FUZZTEST_COMMON_ENV_UTIL_H_

common/remote_file_oss.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ bool RemotePathIsDirectory(std::string_view path) {
223223
absl::StatusOr<std::vector<std::string>> RemoteListFiles(std::string_view path,
224224
bool recursively) {
225225
if (!std::filesystem::exists(path)) return std::vector<std::string>();
226+
if (!std::filesystem::is_directory(path)) return std::vector<std::string>();
226227
auto list_files = [](auto dir_iter) {
227228
std::vector<std::string> ret;
228229
for (const auto &entry : dir_iter) {

e2e_tests/corpus_database_test.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,13 @@ class UpdateCorpusDatabaseTest
9494
auto &run = (*run_map_)[GetParam()];
9595
run.workspace = std::make_unique<TempDir>();
9696
RunOptions run_options;
97+
std::string fuzz_for = "30s";
98+
#if defined(__has_feature) && __has_feature(address_sanitizer)
99+
fuzz_for = "90s";
100+
#endif
97101
run_options.fuzztest_flags = {
98102
{"corpus_database", GetCorpusDatabasePath()},
99-
{"fuzz_for", "30s"},
103+
{"fuzz_for", fuzz_for},
100104
{"jobs", "2"},
101105
};
102106
auto [status_unused, std_out_unused, std_err] = RunBinaryMaybeWithCentipede(

0 commit comments

Comments
 (0)