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
13 changes: 13 additions & 0 deletions centipede/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ licenses(["notice"])
cc_binary(
name = "centipede",
srcs = ["centipede_main.cc"],
compatible_with = [],
deps = [
":centipede_callbacks",
":centipede_default_callbacks",
Expand All @@ -52,12 +53,14 @@ cc_binary(
cc_uninstrumented_binary(
name = "centipede_uninstrumented",
binary = ":centipede",
compatible_with = [],
)

# A standalone seed corpus generator.
cc_binary(
name = "seed_corpus_maker",
srcs = ["seed_corpus_maker.cc"],
compatible_with = [],
deps = [
":config_init",
":seed_corpus_maker_flags",
Expand All @@ -73,6 +76,7 @@ cc_binary(
cc_binary(
name = "blob_file_converter",
srcs = ["blob_file_converter.cc"],
compatible_with = [],
deps = [
":config_init",
":rusage_profiler",
Expand Down Expand Up @@ -1992,3 +1996,12 @@ sh_test(
":test_util_sh",
],
)

filegroup(
name = "oss_srcs",
srcs = [
"centipede_main.cc",
"seed_corpus_maker.cc",
],
visibility = ["//visibility:private"],
)
65 changes: 30 additions & 35 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

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

load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_test.bzl", "cc_test")

DEFAULT_VISIBILITY = ["//visibility:public"]
Expand Down Expand Up @@ -98,6 +97,17 @@ cc_library(
deps = ["@abseil-cpp//absl/types:span"],
)

cc_library(
name = "env_util",
srcs = ["env_util.cc"],
hdrs = ["env_util.h"],
deps = [
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
],
)

cc_library(
name = "hash",
srcs = ["hash.cc"],
Expand Down Expand Up @@ -126,23 +136,21 @@ cc_library(
"//conditions:default": [],
}),
deps = [
":defs",
":logging",
":status_macros",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
] + select({
"//conditions:default": [":remote_file_oss"],
}) +
select({
"@com_google_fuzztest//fuzztest:disable_riegeli": [],
"//conditions:default": [
"@com_google_riegeli//riegeli/bytes:reader",
"@com_google_riegeli//riegeli/bytes:writer",
],
}),
":defs",
":logging",
":remote_file_oss",
":status_macros",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
] + select({
"@com_google_fuzztest//fuzztest:disable_riegeli": [],
"//conditions:default": [
"@com_google_riegeli//riegeli/bytes:reader",
"@com_google_riegeli//riegeli/bytes:writer",
],
}),
)

cc_library(
Expand All @@ -155,7 +163,6 @@ cc_library(
"@com_google_fuzztest//fuzztest:disable_riegeli": ["CENTIPEDE_DISABLE_RIEGELI"],
"//conditions:default": [],
}),
visibility = ["//visibility:private"],
deps = [
":defs",
":logging",
Expand Down Expand Up @@ -253,30 +260,18 @@ cc_test(
)

# TODO(b/324462306): Merge this with remote_file_test once the bug is fixed.
cc_library(
name = "remote_file_test_lib",
testonly = True,
exports_files(["remote_file_test.cc"])

cc_test(
name = "remote_file_test",
srcs = ["remote_file_test.cc"],
defines = select({
"//conditions:default": [],
}),
deps = [
":logging",
":remote_file",
":test_util",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/time",
"@googletest//:gtest",
] + select({
"//conditions:default": [],
}),
alwayslink = True,
)

cc_test(
name = "remote_file_test",
deps = [
":remote_file_test_lib",
"@googletest//:gtest_main",
],
)
13 changes: 13 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ fuzztest_cc_library(
absl::span
)

fuzztest_cc_library(
NAME
env_util
HDRS
"env_util.h"
SRCS
"env_util.cc"
DEPS
absl::strings
absl::str_format
absl::time
)

fuzztest_cc_library(
NAME
hash
Expand Down
42 changes: 42 additions & 0 deletions common/env_util.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2026 The Centipede Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "./common/env_util.h"

#include <cstdlib>
#include <string>

#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"

namespace fuzztest::internal {

absl::Duration GetDurationFromEnv(absl::string_view env_var_name,
absl::Duration default_value) {
const char* env_val = std::getenv(std::string(env_var_name).c_str());
if (env_val == nullptr) return default_value;

absl::Duration duration;
if (absl::ParseDuration(env_val, &duration)) {
return duration;
}

absl::FPrintF(stderr,
"[!] Cannot parse env %s=%s as duration. Using default.\n",
env_var_name, env_val);
return default_value;
}

} // namespace fuzztest::internal
30 changes: 30 additions & 0 deletions common/env_util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2026 The Centipede Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef FUZZTEST_COMMON_ENV_UTIL_H_
#define FUZZTEST_COMMON_ENV_UTIL_H_

#include "absl/strings/string_view.h"
#include "absl/time/time.h"

namespace fuzztest::internal {

// Returns the duration parsed from the environment variable `env_var_name`.
// If the variable is unset or cannot be parsed, returns `default_value`.
absl::Duration GetDurationFromEnv(absl::string_view env_var_name,
absl::Duration default_value);

} // namespace fuzztest::internal

#endif // FUZZTEST_COMMON_ENV_UTIL_H_
1 change: 1 addition & 0 deletions common/remote_file_oss.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ bool RemotePathIsDirectory(std::string_view path) {
absl::StatusOr<std::vector<std::string>> RemoteListFiles(std::string_view path,
bool recursively) {
if (!std::filesystem::exists(path)) return std::vector<std::string>();
if (!std::filesystem::is_directory(path)) return std::vector<std::string>();
auto list_files = [](auto dir_iter) {
std::vector<std::string> ret;
for (const auto &entry : dir_iter) {
Expand Down
6 changes: 5 additions & 1 deletion e2e_tests/corpus_database_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ class UpdateCorpusDatabaseTest
auto &run = (*run_map_)[GetParam()];
run.workspace = std::make_unique<TempDir>();
RunOptions run_options;
std::string fuzz_for = "30s";
#if defined(__has_feature) && __has_feature(address_sanitizer)
fuzz_for = "90s";
#endif
run_options.fuzztest_flags = {
{"corpus_database", GetCorpusDatabasePath()},
{"fuzz_for", "30s"},
{"fuzz_for", fuzz_for},
{"jobs", "2"},
};
auto [status_unused, std_out_unused, std_err] = RunBinaryMaybeWithCentipede(
Expand Down
Loading
Loading