Skip to content

Commit ff9e534

Browse files
xinhaoyuancopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 743985768
1 parent bf274c6 commit ff9e534

11 files changed

+586
-604
lines changed

centipede/BUILD

+8
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ cc_library(
734734
}),
735735
visibility = PUBLIC_API_VISIBILITY,
736736
deps = [
737+
":centipede_flags",
737738
":environment",
738739
"@abseil-cpp//absl/flags:flag",
739740
"@abseil-cpp//absl/log",
@@ -744,6 +745,11 @@ cc_library(
744745
],
745746
)
746747

748+
cc_library(
749+
name = "centipede_flags",
750+
textual_hdrs = ["centipede_flags.inc"],
751+
)
752+
747753
cc_library(
748754
name = "centipede_lib",
749755
srcs = [
@@ -857,11 +863,13 @@ cc_library(
857863
}),
858864
visibility = PUBLIC_API_VISIBILITY,
859865
deps = [
866+
":centipede_flags",
860867
":feature",
861868
":knobs",
862869
":util",
863870
"@abseil-cpp//absl/base:no_destructor",
864871
"@abseil-cpp//absl/container:flat_hash_map",
872+
"@abseil-cpp//absl/flags:marshalling",
865873
"@abseil-cpp//absl/log",
866874
"@abseil-cpp//absl/log:check",
867875
"@abseil-cpp//absl/strings",

centipede/centipede_flags.inc

+448
Large diffs are not rendered by default.

centipede/centipede_interface.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "absl/status/status.h"
3939
#include "absl/status/statusor.h"
4040
#include "absl/strings/ascii.h"
41+
#include "absl/strings/escaping.h"
4142
#include "absl/strings/str_cat.h"
4243
#include "absl/strings/str_format.h"
4344
#include "absl/strings/str_join.h"
@@ -807,7 +808,9 @@ int CentipedeMain(const Environment &env,
807808
if (!env.binary.empty() && !env.has_input_wildcards) {
808809
const auto serialized_target_config = [&]() -> absl::StatusOr<std::string> {
809810
if (!env.fuzztest_configuration.empty()) {
810-
return env.fuzztest_configuration;
811+
std::string result;
812+
CHECK(absl::HexStringToBytes(env.fuzztest_configuration, &result));
813+
return result;
811814
}
812815
ScopedCentipedeCallbacks scoped_callbacks(callbacks_factory, env);
813816
return scoped_callbacks.callbacks()->GetSerializedTargetConfig();

centipede/config_util_test.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ using ::testing::IsSupersetOf;
4646
TEST(FlagUtilTest, GetFlagsPerSource) {
4747
constexpr const char* kCentipedeRoot = "centipede/";
4848
constexpr const char* kThisCc = "centipede/config_util_test.cc";
49-
constexpr const char* kEnvironmentFlagsCc =
50-
"centipede/environment_flags.cc";
49+
constexpr const char* kCentipedeFlagsInc =
50+
"././centipede/centipede_flags.inc";
5151

5252
// Change some flag values to non-defaults.
5353
absl::SetFlag(&FLAGS_foo, "baz");
@@ -61,13 +61,13 @@ TEST(FlagUtilTest, GetFlagsPerSource) {
6161
const FlagInfosPerSource flags = GetFlagsPerSource(kCentipedeRoot);
6262
SCOPED_TRACE(FormatFlagfileString(flags));
6363
ASSERT_EQ(flags.count(kThisCc), 1);
64-
ASSERT_EQ(flags.count(kEnvironmentFlagsCc), 1);
64+
ASSERT_EQ(flags.count(kCentipedeFlagsInc), 1);
6565
ASSERT_THAT(flags.at(kThisCc),
6666
ElementsAreArray({
6767
FlagInfo{"foo", "baz", "bar", "foo help"},
6868
FlagInfo{"qux", "true", "false", "qux help"},
6969
}));
70-
ASSERT_THAT(flags.at(kEnvironmentFlagsCc),
70+
ASSERT_THAT(flags.at(kCentipedeFlagsInc),
7171
IsSupersetOf({
7272
FlagInfo{"binary", "*", "*", "*"},
7373
FlagInfo{"workdir", "*", "*", "*"},
@@ -78,7 +78,7 @@ TEST(FlagUtilTest, GetFlagsPerSource) {
7878
const FlagInfosPerSource flags = GetFlagsPerSource(kThisCc);
7979
SCOPED_TRACE(FormatFlagfileString(flags));
8080
ASSERT_EQ(flags.count(kThisCc), 1);
81-
ASSERT_EQ(flags.count(kEnvironmentFlagsCc), 0);
81+
ASSERT_EQ(flags.count(kCentipedeFlagsInc), 0);
8282
ASSERT_THAT(flags.at(kThisCc),
8383
ElementsAreArray({
8484
FlagInfo{"foo", "baz", "bar", "foo help"},
@@ -91,7 +91,7 @@ TEST(FlagUtilTest, GetFlagsPerSource) {
9191
GetFlagsPerSource(kThisCc, /*exclude_flags=*/{"qux"});
9292
SCOPED_TRACE(FormatFlagfileString(flags));
9393
ASSERT_EQ(flags.count(kThisCc), 1);
94-
ASSERT_EQ(flags.count(kEnvironmentFlagsCc), 0);
94+
ASSERT_EQ(flags.count(kCentipedeFlagsInc), 0);
9595
ASSERT_THAT(flags.at(kThisCc),
9696
ElementsAreArray({
9797
FlagInfo{"foo", "baz", "bar", "foo help"},

centipede/environment.cc

+20
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626

2727
#include "absl/base/no_destructor.h"
2828
#include "absl/container/flat_hash_map.h"
29+
#include "absl/flags/marshalling.h"
2930
#include "absl/log/check.h"
3031
#include "absl/log/log.h"
32+
#include "absl/strings/str_cat.h"
3133
#include "absl/strings/str_split.h"
3234
#include "absl/strings/string_view.h"
3335
#include "absl/time/time.h"
@@ -335,4 +337,22 @@ void Environment::UpdateBinaryHashIfEmpty() {
335337
}
336338
}
337339

340+
std::vector<std::string> Environment::SerializeToCommandFlags() const {
341+
std::vector<std::string> flags;
342+
#define CENTIPEDE_FLAG(TYPE, NAME, _DEFAULT, _DESC) \
343+
if (NAME != Default().NAME) { \
344+
flags.push_back(absl::StrCat("--" #NAME "=", absl::UnparseFlag(NAME))); \
345+
}
346+
#define CENTIPEDE_FLAG_ALIAS(_TYPE, _ALIAS_NAME, _FLAG_NAME, _DEFAULT)
347+
#define CENTIPEDE_FUZZTEST_FLAG(TYPE, NAME, _DEFAULT, _DESC) \
348+
if (NAME != Default().NAME) { \
349+
flags.push_back(absl::StrCat("--" #NAME "=", absl::UnparseFlag(NAME))); \
350+
}
351+
#include "./centipede/centipede_flags.inc"
352+
#undef CENTIPEDE_FLAG
353+
#undef CENTIPEDE_FLAG_ALIAS
354+
#undef CENTIPEDE_FUZZTEST_FLAG
355+
return flags;
356+
}
357+
338358
} // namespace centipede

centipede/environment.h

+10-108
Original file line numberDiff line numberDiff line change
@@ -35,120 +35,20 @@ namespace centipede {
3535
// the flags defined in environment_flags.cc, while other users can use
3636
// CentipedeMain() as a library function without importing the flags.
3737
struct Environment {
38-
// Global params. See environment_flags.cc for help on each parameter. -------
39-
40-
std::string binary;
41-
std::string coverage_binary;
42-
std::string clang_coverage_binary;
43-
std::vector<std::string> extra_binaries;
44-
std::string workdir;
45-
std::string merge_from;
46-
size_t num_runs = std::numeric_limits<size_t>::max();
47-
size_t total_shards = 1;
48-
size_t my_shard_index = 0;
49-
size_t num_threads = 1;
50-
size_t j = 0;
51-
size_t max_len = 4000;
52-
size_t batch_size = 1000;
53-
size_t mutate_batch_size = 2;
54-
bool use_legacy_default_mutator = false;
55-
size_t load_other_shard_frequency = 10;
56-
bool serialize_shard_loads = false;
57-
size_t seed = 0;
58-
size_t prune_frequency = 100;
59-
#ifdef __APPLE__
60-
// Address space limit is ignored on MacOS.
61-
// Reference: https://bugs.chromium.org/p/chromium/issues/detail?id=853873#c2
62-
size_t address_space_limit_mb = 0;
63-
#else // __APPLE__
64-
size_t address_space_limit_mb = 8192;
65-
#endif // __APPLE__
66-
size_t rss_limit_mb = 4096;
67-
size_t stack_limit_kb = 0;
68-
size_t timeout_per_input = 60;
69-
size_t timeout_per_batch = 0;
70-
bool ignore_timeout_reports = false;
71-
absl::Time stop_at = absl::InfiniteFuture();
72-
bool fork_server = true;
73-
bool full_sync = false;
74-
bool use_corpus_weights = true;
75-
bool use_coverage_frontier = false;
76-
size_t max_corpus_size = 100000;
77-
size_t crossover_level = 50;
78-
bool use_pc_features = true;
79-
size_t path_level = 0;
80-
bool use_cmp_features = true;
81-
size_t callstack_level = 0;
82-
bool use_auto_dictionary = true;
83-
bool use_dataflow_features = true;
84-
bool use_counter_features = false;
85-
bool use_pcpair_features = false;
86-
uint64_t user_feature_domain_mask = ~0UL;
87-
size_t feature_frequency_threshold = 100;
88-
bool require_pc_table = true;
89-
int telemetry_frequency = 0;
90-
bool print_runner_log = false;
91-
bool distill = false;
92-
size_t log_features_shards = 0;
93-
std::string knobs_file;
94-
std::string corpus_to_files;
95-
std::string corpus_from_files;
96-
std::vector<std::string> corpus_dir;
97-
std::string symbolizer_path = "llvm-symbolizer";
98-
std::string objdump_path = "objdump";
99-
std::string runner_dl_path_suffix;
100-
std::string input_filter;
101-
std::vector<std::string> dictionary;
102-
std::string function_filter;
103-
std::string for_each_blob;
104-
std::string experiment;
105-
bool analyze = false;
106-
bool exit_on_crash = false;
107-
size_t max_num_crash_reports = 5;
108-
std::string minimize_crash_file_path;
109-
bool batch_triage_suspect_only = false;
110-
size_t shmem_size_mb = 1024;
111-
#ifdef __APPLE__
112-
bool use_posix_shmem = true;
113-
#else
114-
bool use_posix_shmem = false;
115-
#endif
116-
bool dry_run = false;
117-
bool save_binary_info = false;
118-
bool populate_binary_info = true;
119-
#ifdef CENTIPEDE_DISABLE_RIEGELI
120-
bool riegeli = false;
121-
#else
122-
bool riegeli = true;
123-
#endif // CENTIPEDE_DISABLE_RIEGELI
124-
125-
// Internal settings without global flags ------------------------------------
126-
127-
// If set, treat the first entry of `corpus_dir` as output-only.
128-
bool first_corpus_dir_output_only = false;
129-
// If set, load/merge shards without fuzzing new inputs.
130-
bool load_shards_only = false;
131-
// If set, operate on the corpus database for a single test specified by
132-
// FuzzTest instead of all the tests.
133-
bool fuzztest_single_test_mode = false;
134-
// If set, deserializes the configuration from the value instead of querying
135-
// the configuration via runner callbacks.
136-
std::string fuzztest_configuration;
137-
// The crash ID used for `replay_crash` or `export_crash`.
138-
std::string crash_id;
139-
// If set, replay `crash_id` in the corpus database.
140-
bool replay_crash = false;
141-
// If set, export the input contents of `crash_id` from the corpus database.
142-
bool export_crash = false;
143-
// The path to export the input contents of `crash_id` for `export_crash`.
144-
std::string export_crash_file;
38+
#define CENTIPEDE_FLAG(TYPE, NAME, DEFAULT, _DESC) TYPE NAME = DEFAULT;
39+
#define CENTIPEDE_FLAG_ALIAS(_TYPE, _ALIAS_NAME, _FLAG_NAME, _DEFAULT)
40+
#define CENTIPEDE_FUZZTEST_FLAG(TYPE, NAME, DEFAULT, _DESC) TYPE NAME = DEFAULT;
41+
#include "./centipede/centipede_flags.inc"
42+
#undef CENTIPEDE_FLAG
43+
#undef CENTIPEDE_FLAG_ALIAS
44+
#undef CENTIPEDE_FUZZTEST_FLAG
14545

14646
// Command line-related fields -----------------------------------------------
14747

14848
std::string exec_name; // copied from argv[0]
14949
std::vector<std::string> args; // copied from argv[1:].
15050
std::string binary_name; // Name of `coverage_binary`, w/o directories.
151-
std::string binary_hash; // Hash of the `coverage_binary` file.
51+
// std::string binary_hash; // Hash of the `coverage_binary` file.
15252
bool has_input_wildcards = false; // Set to true iff `binary` contains "@@".
15353

15454
// Experiment-related settings -----------------------------------------------
@@ -236,6 +136,8 @@ struct Environment {
236136
void UpdateTimeoutPerBatchIfEqualTo(size_t val);
237137
// If `binary_hash` is empty, updates it using the file in `coverage_binary`.
238138
void UpdateBinaryHashIfEmpty();
139+
140+
std::vector<std::string> SerializeToCommandFlags() const;
239141
};
240142

241143
} // namespace centipede

0 commit comments

Comments
 (0)