Consolidate CHECK and LOG implementations.
Suggested reviewing order:
1. New macro definitions in common/logging.h
2. Everything else: updating use sites to use new logging/CHECK macros
PiperOrigin-RevId: 759666044
diff --git a/centipede/BUILD b/centipede/BUILD
index 6366036..ef5c270 100644
--- a/centipede/BUILD
+++ b/centipede/BUILD
@@ -63,8 +63,7 @@
":util",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/flags:flag",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:remote_file",
],
)
@@ -77,8 +76,6 @@
":rusage_profiler",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/flags:flag",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
@@ -132,8 +129,6 @@
":thread_pool",
":util",
"@abseil-cpp//absl/container:node_hash_set",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/types:span",
"@com_google_fuzztest//common:logging",
@@ -168,9 +163,9 @@
hdrs = ["pc_info.h"],
visibility = PUBLIC_API_VISIBILITY,
deps = [
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/types:span",
"@com_google_fuzztest//common:defs",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -211,7 +206,6 @@
":feature",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/base:nullability",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/synchronization",
@@ -264,8 +258,6 @@
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/flags:parse",
"@abseil-cpp//absl/flags:reflection",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:remote_file",
@@ -290,10 +282,10 @@
visibility = ["//visibility:public"],
deps = [
"@abseil-cpp//absl/base:nullability",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -307,12 +299,11 @@
":rusage_stats",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/base:nullability",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/synchronization",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -323,12 +314,11 @@
deps = [
":rusage_stats",
"@abseil-cpp//absl/base:core_headers",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/synchronization",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -360,8 +350,6 @@
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/container:btree",
"@abseil-cpp//absl/container:flat_hash_map",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
@@ -385,8 +373,6 @@
":util",
":workdir",
"@abseil-cpp//absl/base:core_headers",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/synchronization",
"@com_google_fuzztest//common:defs",
"@com_google_fuzztest//common:hash",
@@ -410,8 +396,6 @@
":workdir",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@com_google_fuzztest//common:defs",
"@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:remote_file",
@@ -519,9 +503,9 @@
":symbol_table",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/synchronization",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:remote_file",
"@com_google_fuzztest//common:status_macros",
],
@@ -544,8 +528,6 @@
":util",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@com_google_fuzztest//common:defs",
"@com_google_fuzztest//common:logging",
@@ -569,7 +551,6 @@
":pc_info",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log:check",
"@com_google_fuzztest//common:logging",
],
)
@@ -582,8 +563,6 @@
":control_flow",
":feature",
":util",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@com_google_fuzztest//common:logging",
],
@@ -602,8 +581,6 @@
":feature",
":feature_set",
":util",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@com_google_fuzztest//common:defs",
"@com_google_fuzztest//common:logging",
@@ -621,8 +598,6 @@
":stop",
":util",
"@abseil-cpp//absl/base:core_headers",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
@@ -647,9 +622,8 @@
":pc_info",
":symbol_table",
":util",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:remote_file",
],
)
@@ -677,8 +651,6 @@
":util",
":workdir",
"@abseil-cpp//absl/base:nullability",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
@@ -697,8 +669,6 @@
":feature",
":rusage_profiler",
":util",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/time",
"@abseil-cpp//absl/types:span",
@@ -737,8 +707,6 @@
":centipede_flags",
":environment",
"@abseil-cpp//absl/flags:flag",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"@com_google_fuzztest//common:logging",
@@ -783,8 +751,6 @@
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
@@ -830,8 +796,6 @@
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/cleanup",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
@@ -870,8 +834,6 @@
"@abseil-cpp//absl/base:no_destructor",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/flags:marshalling",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"@com_google_fuzztest//common:defs",
@@ -900,8 +862,6 @@
":workdir",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/synchronization",
"@abseil-cpp//absl/time",
@@ -925,8 +885,6 @@
":mutation_input",
":runner_result",
":stop",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@com_google_fuzztest//common:defs",
@@ -1151,8 +1109,6 @@
":util",
":workdir",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/random",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
@@ -1176,7 +1132,6 @@
":seed_corpus_config_cc_proto",
":seed_corpus_maker_lib",
":workdir",
- "@abseil-cpp//absl/log",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
@@ -1206,8 +1161,6 @@
visibility = PUBLIC_API_VISIBILITY,
deps = [
":environment",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@com_google_fuzztest//common:logging",
@@ -1227,7 +1180,6 @@
":mutation_input",
":runner_result",
":util",
- "@abseil-cpp//absl/log:check",
"@com_google_fuzztest//common:defs",
],
)
@@ -1264,8 +1216,8 @@
srcs = ["environment_test.cc"],
deps = [
":environment",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:configuration",
"@googletest//:gtest_main",
],
@@ -1318,9 +1270,9 @@
":thread_pool",
":util",
"@abseil-cpp//absl/container:flat_hash_map",
- "@abseil-cpp//absl/log",
"@com_google_fuzztest//common:defs",
"@com_google_fuzztest//common:hash",
+ "@com_google_fuzztest//common:logging",
"@googletest//:gtest_main",
],
)
@@ -1360,7 +1312,6 @@
":thread_pool",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/flags:flag",
- "@abseil-cpp//absl/log",
"@abseil-cpp//absl/synchronization",
"@abseil-cpp//absl/time",
"@com_google_fuzztest//common:logging",
@@ -1379,9 +1330,9 @@
":util",
":workdir",
"@abseil-cpp//absl/flags:reflection",
- "@abseil-cpp//absl/log:check",
"@com_google_fuzztest//common:blob_file",
"@com_google_fuzztest//common:defs",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:test_util",
"@googletest//:gtest_main",
],
@@ -1397,8 +1348,8 @@
":rusage_profiler",
":rusage_stats",
"@abseil-cpp//absl/flags:flag",
- "@abseil-cpp//absl/log",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
"@googletest//:gtest_main",
],
)
@@ -1410,7 +1361,6 @@
":environment",
":stats",
":util",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/log:log_entry",
"@abseil-cpp//absl/log:log_sink",
"@abseil-cpp//absl/log:log_sink_registry",
@@ -1453,8 +1403,7 @@
":environment",
":symbol_table",
":test_coverage_util",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:remote_file",
"@com_google_fuzztest//common:test_util",
"@googletest//:gtest_main",
@@ -1606,10 +1555,10 @@
":feature",
":util",
":workdir",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/types:span",
"@com_google_fuzztest//common:blob_file",
"@com_google_fuzztest//common:defs",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:test_util",
"@googletest//:gtest_main",
],
@@ -1650,9 +1599,9 @@
":command",
":stop",
":util",
- "@abseil-cpp//absl/log",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:test_util",
"@googletest//:gtest_main",
],
@@ -1683,8 +1632,6 @@
":symbol_table",
":thread_pool",
"@abseil-cpp//absl/container:flat_hash_map",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:test_util",
"@googletest//:gtest_main",
@@ -1720,7 +1667,6 @@
":feature",
":seed_corpus_maker_lib",
":workdir",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@com_google_fuzztest//common:defs",
"@com_google_fuzztest//common:logging",
@@ -1778,7 +1724,6 @@
":resource_pool",
":rusage_stats",
":thread_pool",
- "@abseil-cpp//absl/log",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/time",
"@com_google_fuzztest//common:logging",
@@ -1871,8 +1816,6 @@
":workdir",
"@abseil-cpp//absl/base:nullability",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"@com_google_fuzztest//common:defs",
diff --git a/centipede/analyze_corpora.cc b/centipede/analyze_corpora.cc
index 56e75c7..0216d83 100644
--- a/centipede/analyze_corpora.cc
+++ b/centipede/analyze_corpora.cc
@@ -24,8 +24,6 @@
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "./centipede/binary_info.h"
#include "./centipede/control_flow.h"
#include "./centipede/corpus.h"
@@ -48,17 +46,17 @@
WorkDir workdir(std::string(workdir_path), std::string(binary_name),
std::string(binary_hash), /*my_shard_index=*/0);
std::vector<std::string> corpus_paths;
- CHECK_OK(
+ FUZZTEST_CHECK_OK(
RemoteGlobMatch(workdir.CorpusFilePaths().AllShardsGlob(), corpus_paths));
std::vector<std::string> features_paths;
- CHECK_OK(RemoteGlobMatch(workdir.FeaturesFilePaths().AllShardsGlob(),
- features_paths));
+ FUZZTEST_CHECK_OK(RemoteGlobMatch(workdir.FeaturesFilePaths().AllShardsGlob(),
+ features_paths));
- CHECK_EQ(corpus_paths.size(), features_paths.size());
+ FUZZTEST_CHECK_EQ(corpus_paths.size(), features_paths.size());
std::vector<CorpusRecord> corpus;
for (int i = 0; i < corpus_paths.size(); ++i) {
- LOG(INFO) << "Reading corpus at: " << corpus_paths[i];
- LOG(INFO) << "Reading features at: " << features_paths[i];
+ FUZZTEST_LOG(INFO) << "Reading corpus at: " << corpus_paths[i];
+ FUZZTEST_LOG(INFO) << "Reading features at: " << features_paths[i];
ReadShard(corpus_paths[i], features_paths[i],
[&corpus](ByteArray input, FeatureVec features) {
corpus.push_back({std::move(input), std::move(features)});
@@ -126,9 +124,10 @@
a_only_pcs.insert(pc);
}
}
- LOG(INFO) << VV(a.size()) << VV(b.size()) << VV(a_pcs.size())
- << VV(a_only_pcs.size()) << VV(b_only_pcs.size())
- << VV(b_shared_indices.size()) << VV(b_unique_indices.size());
+ FUZZTEST_LOG(INFO) << VV(a.size()) << VV(b.size()) << VV(a_pcs.size())
+ << VV(a_only_pcs.size()) << VV(b_only_pcs.size())
+ << VV(b_shared_indices.size())
+ << VV(b_unique_indices.size());
// Sort PCs to put them in the canonical order, as in pc_table.
AnalyzeCorporaResults ret;
@@ -178,7 +177,7 @@
void DumpCoverageReport(const CoverageResults &coverage_results,
std::string_view coverage_report_path) {
- LOG(INFO) << "Dump coverage to file: " << coverage_report_path;
+ FUZZTEST_LOG(INFO) << "Dump coverage to file: " << coverage_report_path;
const fuzztest::internal::PCTable &pc_table =
coverage_results.binary_info.pc_table;
@@ -187,7 +186,7 @@
fuzztest::internal::SymbolTable coverage_symbol_table;
for (const PCIndex pc : coverage_results.pcs) {
- CHECK_LE(pc, symbols.size());
+ FUZZTEST_CHECK_LE(pc, symbols.size());
if (!pc_table[pc].has_flag(fuzztest::internal::PCInfo::kFuncEntry))
continue;
const SymbolTable::Entry entry = symbols.entry(pc);
@@ -197,7 +196,7 @@
std::ostringstream symbol_table_stream;
coverage_symbol_table.WriteToLLVMSymbolizer(symbol_table_stream);
- CHECK_OK(
+ FUZZTEST_CHECK_OK(
RemoteFileSetContents(coverage_report_path, symbol_table_stream.str()));
}
@@ -210,8 +209,9 @@
BinaryInfo binary_info_b =
ReadBinaryInfo(binary_name, binary_hash, workdir_b);
- CHECK_EQ(binary_info_a.pc_table.size(), binary_info_b.pc_table.size());
- CHECK_EQ(binary_info_a.symbols.size(), binary_info_b.symbols.size());
+ FUZZTEST_CHECK_EQ(binary_info_a.pc_table.size(),
+ binary_info_b.pc_table.size());
+ FUZZTEST_CHECK_EQ(binary_info_a.symbols.size(), binary_info_b.symbols.size());
const std::vector<CorpusRecord> a =
ReadCorpora(binary_name, binary_hash, workdir_a);
@@ -235,26 +235,26 @@
CoverageLogger coverage_logger(pc_table, symbols);
// TODO(kcc): use frontier_a to show the most interesting b-only PCs.
- // TODO(kcc): these cause a CHECK-fail
+ // TODO(kcc): these cause a FUZZTEST_CHECK-fail
// CoverageFrontier frontier_a(results.binary_info);
// frontier_a.Compute(a);
// First, print the newly covered functions (including partially covered).
- LOG(INFO) << "B-only new functions:";
+ FUZZTEST_LOG(INFO) << "B-only new functions:";
absl::flat_hash_set<std::string_view> b_only_new_functions;
for (const auto pc : results.b_only_pcs) {
if (!pc_table[pc].has_flag(PCInfo::kFuncEntry)) continue;
auto str = coverage_logger.ObserveAndDescribeIfNew(pc);
- if (!str.empty()) LOG(INFO).NoPrefix() << str;
+ if (!str.empty()) FUZZTEST_LOG(INFO).NoPrefix() << str;
b_only_new_functions.insert(symbols.func(pc));
}
// Now, print newly covered edges in functions that were covered in `a`.
- LOG(INFO) << "B-only new edges:";
+ FUZZTEST_LOG(INFO) << "B-only new edges:";
for (const auto pc : results.b_only_pcs) {
if (b_only_new_functions.contains(symbols.func(pc))) continue;
auto str = coverage_logger.ObserveAndDescribeIfNew(pc);
- if (!str.empty()) LOG(INFO).NoPrefix() << str;
+ if (!str.empty()) FUZZTEST_LOG(INFO).NoPrefix() << str;
}
}
diff --git a/centipede/analyze_corpora.h b/centipede/analyze_corpora.h
index 3343e05..d1731b8 100644
--- a/centipede/analyze_corpora.h
+++ b/centipede/analyze_corpora.h
@@ -62,7 +62,7 @@
std::string_view workdir_a,
std::string_view workdir_b);
-// Same as above but `LOG`s the results for human consumption.
+// Same as above but `FUZZTEST_LOG`s the results for human consumption.
void AnalyzeCorporaToLog(std::string_view binary_name,
std::string_view binary_hash,
std::string_view workdir_a,
diff --git a/centipede/analyze_corpora_test.cc b/centipede/analyze_corpora_test.cc
index f65106d..cf00c54 100644
--- a/centipede/analyze_corpora_test.cc
+++ b/centipede/analyze_corpora_test.cc
@@ -24,12 +24,11 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "./centipede/binary_info.h"
#include "./centipede/environment.h"
#include "./centipede/symbol_table.h"
#include "./centipede/test_coverage_util.h"
+#include "./common/logging.h"
#include "./common/remote_file.h"
#include "./common/test_util.h"
@@ -47,7 +46,7 @@
}
// TODO(ussuri): Implement.
-TEST(AnalyzeCorpora, AnalyzeCorpora) { LOG(INFO) << "Unimplemented"; }
+TEST(AnalyzeCorpora, AnalyzeCorpora) { FUZZTEST_LOG(INFO) << "Unimplemented"; }
TEST(GetCoverage, SimpleCoverageResults) {
Environment env;
diff --git a/centipede/binary_info.cc b/centipede/binary_info.cc
index d604be3..227bb88 100644
--- a/centipede/binary_info.cc
+++ b/centipede/binary_info.cc
@@ -22,14 +22,13 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "./centipede/command.h"
#include "./centipede/control_flow.h"
#include "./centipede/pc_info.h"
#include "./centipede/util.h"
+#include "./common/logging.h"
#include "./common/remote_file.h"
namespace fuzztest::internal {
@@ -45,18 +44,18 @@
std::string_view symbolizer_path, std::string_view tmp_dir_path) {
if (binary_path_with_args.empty()) {
// This usually happens in tests.
- LOG(INFO) << __func__ << ": binary_path_with_args is empty";
+ FUZZTEST_LOG(INFO) << __func__ << ": binary_path_with_args is empty";
return;
}
// Compute names for temp files.
const std::filesystem::path tmp_dir = tmp_dir_path;
- CHECK(std::filesystem::exists(tmp_dir) &&
- std::filesystem::is_directory(tmp_dir));
+ FUZZTEST_CHECK(std::filesystem::exists(tmp_dir) &&
+ std::filesystem::is_directory(tmp_dir));
ScopedFile pc_table_path(tmp_dir_path, "pc_table_tmp");
ScopedFile cf_table_path(tmp_dir_path, "cf_table_tmp");
ScopedFile dso_table_path(tmp_dir_path, "dso_table_tmp");
ScopedFile log_path(tmp_dir_path, "binary_info_log_tmp");
- LOG(INFO) << __func__ << ": tmp_dir: " << tmp_dir;
+ FUZZTEST_LOG(INFO) << __func__ << ": tmp_dir: " << tmp_dir;
Command::Options cmd_options;
cmd_options.env_add = {absl::StrCat(
@@ -66,7 +65,7 @@
Command cmd{binary_path_with_args, std::move(cmd_options)};
int exit_code = cmd.Execute();
if (exit_code != EXIT_SUCCESS) {
- LOG(INFO) << __func__ << ": exit_code: " << exit_code;
+ FUZZTEST_LOG(INFO) << __func__ << ": exit_code: " << exit_code;
}
// Load PC Table.
@@ -80,24 +79,25 @@
dso_table = ReadDsoTableFromFile(dso_table_path.path());
if (pc_table.empty()) {
- CHECK(dso_table.empty());
+ FUZZTEST_CHECK(dso_table.empty());
// Fallback to GetPcTableFromBinaryWithTracePC().
- LOG(WARNING)
+ FUZZTEST_LOG(WARNING)
<< "Failed to dump PC table directly from binary using linked-in "
"runner; see target execution logs above; falling back to legacy PC "
"table extraction using trace-pc and objdump";
pc_table = GetPcTableFromBinaryWithTracePC(
binary_path_with_args, objdump_path, pc_table_path.path());
if (pc_table.empty()) {
- LOG(ERROR) << "Failed to extract PC table from binary using objdump; see "
- "objdump execution logs above";
+ FUZZTEST_LOG(ERROR)
+ << "Failed to extract PC table from binary using objdump; see "
+ "objdump execution logs above";
}
// For the legacy trace-pc instrumentation, set the dso_table
// to 1-element array consisting of the binary name
const std::vector<std::string> args =
absl::StrSplit(binary_path_with_args, absl::ByAnyChar{" \t\n"},
absl::SkipWhitespace{});
- CHECK(!args.empty());
+ FUZZTEST_CHECK(!args.empty());
dso_table.push_back({args[0], pc_table.size()});
uses_legacy_trace_pc_instrumentation = true;
} else {
@@ -110,7 +110,7 @@
for (const auto& dso : dso_table) {
num_instrumened_pcs_in_all_dsos += dso.num_instrumented_pcs;
}
- CHECK_EQ(num_instrumened_pcs_in_all_dsos, pc_table.size());
+ FUZZTEST_CHECK_EQ(num_instrumened_pcs_in_all_dsos, pc_table.size());
}
// Load symbols, if there is a PC table.
@@ -125,14 +125,14 @@
void BinaryInfo::Read(std::string_view dir) {
std::string symbol_table_contents;
// TODO(b/295978603): move calculation of paths into WorkDir class.
- CHECK_OK(RemoteFileGetContents(
+ FUZZTEST_CHECK_OK(RemoteFileGetContents(
(std::filesystem::path(dir) / kSymbolTableFileName).c_str(),
symbol_table_contents));
std::istringstream symbol_table_stream(symbol_table_contents);
symbols.ReadFromLLVMSymbolizer(symbol_table_stream);
std::string pc_table_contents;
- CHECK_OK(RemoteFileGetContents(
+ FUZZTEST_CHECK_OK(RemoteFileGetContents(
(std::filesystem::path(dir) / kPCTableFileName).c_str(),
pc_table_contents));
std::istringstream pc_table_stream(pc_table_contents);
@@ -146,19 +146,19 @@
std::ostringstream symbol_table_stream;
symbols.WriteToLLVMSymbolizer(symbol_table_stream);
// TODO(b/295978603): move calculation of paths into WorkDir class.
- CHECK_OK(RemoteFileSetContents(
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(
(std::filesystem::path(dir) / kSymbolTableFileName).c_str(),
symbol_table_stream.str()));
std::ostringstream pc_table_stream;
WritePcTable(pc_table, pc_table_stream);
- CHECK_OK(RemoteFileSetContents(
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(
(std::filesystem::path(dir) / kPCTableFileName).c_str(),
pc_table_stream.str()));
std::ostringstream cf_table_stream;
WriteCfTable(cf_table, cf_table_stream);
- CHECK_OK(RemoteFileSetContents(
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(
(std::filesystem::path(dir) / kCfTableFileName).c_str(),
cf_table_stream.str()));
}
diff --git a/centipede/blob_file_converter.cc b/centipede/blob_file_converter.cc
index de21421..e9cb69b 100644
--- a/centipede/blob_file_converter.cc
+++ b/centipede/blob_file_converter.cc
@@ -19,8 +19,6 @@
#include "absl/base/nullability.h"
#include "absl/flags/flag.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "absl/time/clock.h"
@@ -59,11 +57,11 @@
const std::string stats = absl::StrFormat(
"blobs: %9lld | blobs/s: %5.0f | bytes: %12lld | bytes/s: %8.0f",
num_blobs_, num_blobs_ / secs, num_bytes_, num_bytes_ / secs);
- if (ABSL_VLOG_IS_ON(3)) {
+ if (FUZZTEST_VLOG_IS_ON(3)) {
const RUsageProfiler::Snapshot& snapshot = RPROF_SNAPSHOT(stats);
- LOG(INFO) << stats << " | " << snapshot.memory.ShortStr();
+ FUZZTEST_LOG(INFO) << stats << " | " << snapshot.memory.ShortStr();
} else {
- LOG(INFO) << stats;
+ FUZZTEST_LOG(INFO) << stats;
}
}
@@ -90,45 +88,49 @@
void Convert( //
const std::string& in, //
const std::string& out, const std::string& out_format) {
- RPROF_THIS_FUNCTION_WITH_REPORT(/*enable=*/ABSL_VLOG_IS_ON(1));
+ RPROF_THIS_FUNCTION_WITH_REPORT(/*enable=*/FUZZTEST_VLOG_IS_ON(1));
- LOG(INFO) << "Converting:\n" << VV(in) << "\n" << VV(out) << VV(out_format);
+ FUZZTEST_LOG(INFO) << "Converting:\n"
+ << VV(in) << "\n"
+ << VV(out) << VV(out_format);
const bool out_is_riegeli = out_format == "riegeli";
// Verify and prepare source and destination.
- CHECK(RemotePathExists(in)) << VV(in);
- CHECK_OK(RemoteMkdir(std::filesystem::path{out}.parent_path().c_str()));
+ FUZZTEST_CHECK(RemotePathExists(in)) << VV(in);
+ FUZZTEST_CHECK_OK(
+ RemoteMkdir(std::filesystem::path{out}.parent_path().c_str()));
// Open blob file reader and writer.
RPROF_START_TIMELAPSE( //
- absl::Seconds(20), /*also_log=*/ABSL_VLOG_IS_ON(3), "Opening --in");
+ absl::Seconds(20), /*also_log=*/FUZZTEST_VLOG_IS_ON(3), "Opening --in");
const auto in_reader = DefaultBlobFileReaderFactory();
- CHECK_OK(in_reader->Open(in)) << VV(in);
+ FUZZTEST_CHECK_OK(in_reader->Open(in)) << VV(in);
RPROF_STOP_TIMELAPSE();
- RPROF_SNAPSHOT_AND_LOG("Opened --in; opening --out");
+ RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Opened --in; opening --out");
const auto out_writer = DefaultBlobFileWriterFactory(out_is_riegeli);
- CHECK_OK(out_writer->Open(out, "w")) << VV(out);
- RPROF_SNAPSHOT_AND_LOG("Opened --out");
+ FUZZTEST_CHECK_OK(out_writer->Open(out, "w")) << VV(out);
+ RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Opened --out");
// Read and write blobs one-by-one.
ByteSpan blob;
absl::Status read_status = absl::OkStatus();
StatsLogger stats_logger{
- absl::Seconds(ABSL_VLOG_IS_ON(1) ? 20 : 60),
+ absl::Seconds(FUZZTEST_VLOG_IS_ON(1) ? 20 : 60),
FUNCTION_LEVEL_RPROF_NAME,
};
while ((read_status = in_reader->Read(blob)).ok()) {
- CHECK_OK(out_writer->Write(blob));
+ FUZZTEST_CHECK_OK(out_writer->Write(blob));
stats_logger.UpdateStats(blob);
stats_logger.MaybeLogIfTime();
}
stats_logger.Log();
- CHECK(read_status.ok() || absl::IsOutOfRange(read_status)) << VV(read_status);
- CHECK_OK(out_writer->Close()) << VV(out);
+ FUZZTEST_CHECK(read_status.ok() || absl::IsOutOfRange(read_status))
+ << VV(read_status);
+ FUZZTEST_CHECK_OK(out_writer->Close()) << VV(out);
}
} // namespace
@@ -138,11 +140,12 @@
(void)fuzztest::internal::InitRuntime(argc, argv);
const std::string in = absl::GetFlag(FLAGS_in);
- QCHECK(!in.empty());
+ FUZZTEST_QCHECK(!in.empty());
const std::string out = absl::GetFlag(FLAGS_out);
- QCHECK(!out.empty());
+ FUZZTEST_QCHECK(!out.empty());
const std::string out_format = absl::GetFlag(FLAGS_out_format);
- QCHECK(out_format == "legacy" || out_format == "riegeli") << VV(out_format);
+ FUZZTEST_QCHECK(out_format == "legacy" || out_format == "riegeli")
+ << VV(out_format);
fuzztest::internal::Convert(in, out, out_format);
diff --git a/centipede/call_graph.cc b/centipede/call_graph.cc
index 9121557..b78c37f 100644
--- a/centipede/call_graph.cc
+++ b/centipede/call_graph.cc
@@ -18,9 +18,9 @@
#include <cstdint>
#include <vector>
-#include "absl/log/check.h"
#include "./centipede/control_flow.h"
#include "./centipede/pc_info.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -54,7 +54,7 @@
++j;
}
++j; // Step over the delimeter.
- CHECK_LE(j, cf_table.size());
+ FUZZTEST_CHECK_LE(j, cf_table.size());
if (current_callees.empty()) continue;
basic_block_callees_[current_pc] = current_callees;
@@ -64,7 +64,7 @@
current_callees.end());
}
// This should stay empty.
- CHECK(empty_.empty());
+ FUZZTEST_CHECK(empty_.empty());
}
} // namespace fuzztest::internal
diff --git a/centipede/call_graph.h b/centipede/call_graph.h
index 3e3c03b..2377e36 100644
--- a/centipede/call_graph.h
+++ b/centipede/call_graph.h
@@ -20,7 +20,6 @@
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
#include "./centipede/control_flow.h"
#include "./centipede/pc_info.h"
#include "./common/logging.h"
@@ -34,13 +33,15 @@
void InitializeCallGraph(const CFTable& cf_table, const PCTable& pc_table);
const std::vector<uintptr_t>& GetFunctionCallees(uintptr_t pc) const {
- CHECK(IsFunctionEntry(pc)) << VV(pc) << " is not a function entry.";
+ FUZZTEST_CHECK(IsFunctionEntry(pc))
+ << VV(pc) << " is not a function entry.";
const auto it = call_graph_.find(pc);
if (it == call_graph_.cend()) return empty_;
return it->second;
}
const std::vector<uintptr_t>& GetBasicBlockCallees(uintptr_t pc) const {
- CHECK(basic_blocks_.contains(pc)) << VV(pc) << " is not a basic block.";
+ FUZZTEST_CHECK(basic_blocks_.contains(pc))
+ << VV(pc) << " is not a basic block.";
const auto it = basic_block_callees_.find(pc);
if (it == basic_block_callees_.cend()) return empty_;
return it->second;
diff --git a/centipede/centipede.cc b/centipede/centipede.cc
index 84490e4..d366c75 100644
--- a/centipede/centipede.cc
+++ b/centipede/centipede.cc
@@ -64,8 +64,6 @@
#include "absl/base/const_init.h" // NOLINT
#include "absl/base/nullability.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
@@ -132,15 +130,15 @@
/*raii_actions=*/RUsageProfiler::kRaiiOff,
/*location=*/{__FILE__, __LINE__},
/*description=*/"Engine") {
- CHECK(env_.seed) << "env_.seed must not be zero";
+ FUZZTEST_CHECK(env_.seed) << "env_.seed must not be zero";
if (!env_.input_filter.empty() && env_.fork_server)
input_filter_cmd_.StartForkServer(TemporaryLocalDirPath(), "input_filter");
}
void Centipede::CorpusToFiles(const Environment &env, std::string_view dir) {
std::vector<std::string> sharded_corpus_files;
- CHECK_OK(RemoteGlobMatch(WorkDir{env}.CorpusFilePaths().AllShardsGlob(),
- sharded_corpus_files));
+ FUZZTEST_CHECK_OK(RemoteGlobMatch(
+ WorkDir{env}.CorpusFilePaths().AllShardsGlob(), sharded_corpus_files));
ExportCorpus(sharded_corpus_files, dir);
}
@@ -161,7 +159,7 @@
// If the destination `workdir` is specified (note that empty means "use the
// current directory"), we might need to create it.
if (!env.workdir.empty()) {
- CHECK_OK(RemoteMkdir(env.workdir));
+ FUZZTEST_CHECK_OK(RemoteMkdir(env.workdir));
}
// Iterate over all shards, adding inputs to the current shard.
@@ -184,23 +182,23 @@
}
// Add inputs to the current shard, if the shard doesn't have them already.
auto appender = DefaultBlobFileWriterFactory(env.riegeli);
- CHECK_OK(appender->Open(corpus_file_path, "a"))
+ FUZZTEST_CHECK_OK(appender->Open(corpus_file_path, "a"))
<< "Failed to open corpus file: " << corpus_file_path;
ByteArray shard_data;
for (const auto &path : sharded_paths[shard]) {
std::string input;
- CHECK_OK(RemoteFileGetContents(path, input));
+ FUZZTEST_CHECK_OK(RemoteFileGetContents(path, input));
if (input.empty() || existing_hashes.contains(Hash(input))) {
++inputs_ignored;
continue;
}
- CHECK_OK(appender->Write(ByteArray{input.begin(), input.end()}));
+ FUZZTEST_CHECK_OK(appender->Write(ByteArray{input.begin(), input.end()}));
++inputs_added;
}
- LOG(INFO) << VV(shard) << VV(inputs_added) << VV(inputs_ignored)
- << VV(num_shard_bytes) << VV(shard_data.size());
+ FUZZTEST_LOG(INFO) << VV(shard) << VV(inputs_added) << VV(inputs_ignored)
+ << VV(num_shard_bytes) << VV(shard_data.size());
}
- CHECK_EQ(total_paths, inputs_added + inputs_ignored);
+ FUZZTEST_CHECK_EQ(total_paths, inputs_added + inputs_ignored);
}
absl::Status Centipede::CrashesToFiles(const Environment &env,
@@ -228,7 +226,7 @@
(std::filesystem::path{dir} / absl::StrCat(id, ".data")).string()));
const auto shard_index = wd.CrashReproducerDirPaths().GetShardIndex(
std::filesystem::path{reproducer_path}.parent_path().string());
- CHECK(shard_index.has_value());
+ FUZZTEST_CHECK(shard_index.has_value());
const auto metadata_dir = wd.CrashMetadataDirPaths().Shard(*shard_index);
const auto description_filename = absl::StrCat(id, ".desc");
const auto signature_filename = absl::StrCat(id, ".sig");
@@ -339,7 +337,7 @@
os << " exec/s: "
<< (execs_per_sec < 1.0 ? execs_per_sec : std::round(execs_per_sec));
os << " mb: " << (rusage_memory.mem_rss >> 20);
- LOG(INFO) << os.str();
+ FUZZTEST_LOG(INFO) << os.str();
}
void Centipede::LogFeaturesAsSymbols(const FeatureVec &fv) {
@@ -349,7 +347,7 @@
PCIndex pc_index = ConvertPCFeatureToPcIndex(feature);
auto description = coverage_logger_.ObserveAndDescribeIfNew(pc_index);
if (description.empty()) continue;
- LOG(INFO) << description;
+ FUZZTEST_LOG(INFO) << description;
}
}
@@ -417,7 +415,7 @@
BlobFileWriter *absl_nullable unconditional_features_file) {
BatchResult batch_result;
bool success = ExecuteAndReportCrash(env_.binary, input_vec, batch_result);
- CHECK_EQ(input_vec.size(), batch_result.results().size());
+ FUZZTEST_CHECK_EQ(input_vec.size(), batch_result.results().size());
for (const auto &extra_binary : env_.extra_binaries) {
if (ShouldStop()) break;
@@ -428,11 +426,11 @@
}
if (EarlyStopRequested()) return false;
if (!success && env_.exit_on_crash) {
- LOG(INFO) << "--exit_on_crash is enabled; exiting soon";
+ FUZZTEST_LOG(INFO) << "--exit_on_crash is enabled; exiting soon";
RequestEarlyStop(EXIT_FAILURE);
return false;
}
- CHECK_EQ(batch_result.results().size(), input_vec.size());
+ FUZZTEST_CHECK_EQ(batch_result.results().size(), input_vec.size());
num_runs_ += input_vec.size();
bool batch_gained_new_coverage = false;
for (size_t i = 0; i < input_vec.size(); i++) {
@@ -443,7 +441,7 @@
if (env_.use_pcpair_features && AddPcPairFeatures(fv) != 0)
input_gained_new_coverage = true;
if (unconditional_features_file != nullptr) {
- CHECK_OK(unconditional_features_file->Write(
+ FUZZTEST_CHECK_OK(unconditional_features_file->Write(
PackFeaturesAndHash(input_vec[i], fv)));
}
if (input_gained_new_coverage) {
@@ -452,19 +450,20 @@
fs_.IncrementFrequencies(fv);
LogFeaturesAsSymbols(fv);
batch_gained_new_coverage = true;
- CHECK_GT(fv.size(), 0UL);
+ FUZZTEST_CHECK_GT(fv.size(), 0UL);
if (function_filter_passed) {
corpus_.Add(input_vec[i], fv, batch_result.results()[i].metadata(), fs_,
coverage_frontier_);
}
if (corpus_file != nullptr) {
- CHECK_OK(corpus_file->Write(input_vec[i]));
+ FUZZTEST_CHECK_OK(corpus_file->Write(input_vec[i]));
}
if (!env_.corpus_dir.empty() && !env_.corpus_dir[0].empty()) {
WriteToLocalHashedFileInDir(env_.corpus_dir[0], input_vec[i]);
}
if (features_file != nullptr) {
- CHECK_OK(features_file->Write(PackFeaturesAndHash(input_vec[i], fv)));
+ FUZZTEST_CHECK_OK(
+ features_file->Write(PackFeaturesAndHash(input_vec[i], fv)));
}
}
}
@@ -474,8 +473,8 @@
// TODO(kcc): [impl] don't reread the same corpus twice.
void Centipede::LoadShard(const Environment &load_env, size_t shard_index,
bool rerun) {
- VLOG(1) << "Loading shard " << shard_index
- << (rerun ? " with rerunning" : " without rerunning");
+ FUZZTEST_VLOG(1) << "Loading shard " << shard_index
+ << (rerun ? " with rerunning" : " without rerunning");
size_t num_added_inputs = 0;
size_t num_skipped_inputs = 0;
std::vector<ByteArray> inputs_to_rerun;
@@ -491,14 +490,14 @@
const auto num_new_features =
fs_.PruneFeaturesAndCountUnseen(input_features);
if (num_new_features != 0) {
- VLOG(10) << "Adding input " << Hash(input)
- << "; new features: " << num_new_features;
+ FUZZTEST_VLOG(10) << "Adding input " << Hash(input)
+ << "; new features: " << num_new_features;
fs_.IncrementFrequencies(input_features);
// TODO(kcc): cmp_args are currently not saved to disk and not reloaded.
corpus_.Add(input, input_features, {}, fs_, coverage_frontier_);
++num_added_inputs;
} else {
- VLOG(10) << "Skipping input: " << Hash(input);
+ FUZZTEST_VLOG(10) << "Skipping input: " << Hash(input);
++num_skipped_inputs;
}
}
@@ -517,8 +516,9 @@
ReadShard(corpus_path, features_path, input_features_callback);
}
- VLOG(1) << "Loaded shard " << shard_index << ": added " << num_added_inputs
- << " / skipped " << num_skipped_inputs << " inputs";
+ FUZZTEST_VLOG(1) << "Loaded shard " << shard_index << ": added "
+ << num_added_inputs << " / skipped " << num_skipped_inputs
+ << " inputs";
if (num_added_inputs > 0) UpdateAndMaybeLogStats("load-shard", 1);
if (!inputs_to_rerun.empty()) Rerun(inputs_to_rerun);
@@ -536,7 +536,8 @@
for (size_t shard_idx : shard_idxs) {
const bool rerun = rerun_my_shard && shard_idx == env_.my_shard_index;
LoadShard(load_env, shard_idx, rerun);
- LOG_IF(INFO, (++num_shards_loaded % 100) == 0) << VV(num_shards_loaded);
+ FUZZTEST_LOG_IF(INFO, (++num_shards_loaded % 100) == 0)
+ << VV(num_shards_loaded);
}
}
@@ -544,9 +545,9 @@
if (to_rerun.empty()) return;
auto features_file_path = wd_.FeaturesFilePaths().Shard(env_.my_shard_index);
auto features_file = DefaultBlobFileWriterFactory(env_.riegeli);
- CHECK_OK(features_file->Open(features_file_path, "a"));
+ FUZZTEST_CHECK_OK(features_file->Open(features_file_path, "a"));
- LOG(INFO) << to_rerun.size() << " inputs to rerun";
+ FUZZTEST_LOG(INFO) << to_rerun.size() << " inputs to rerun";
// Re-run all inputs for which we don't know their features.
// Run in batches of at most env_.batch_size inputs each.
while (!to_rerun.empty()) {
@@ -565,8 +566,8 @@
if (pc_table_.empty()) return;
auto coverage_path = wd_.CoverageReportPath(filename_annotation);
- LOG(INFO) << "Generate coverage report [" << description << "]; "
- << VV(coverage_path);
+ FUZZTEST_LOG(INFO) << "Generate coverage report [" << description << "]; "
+ << VV(coverage_path);
auto pci_vec = fs_.ToCoveragePCs();
Coverage coverage(pc_table_, pci_vec);
coverage.DumpReportToFile(symbols_, coverage_path, description);
@@ -575,8 +576,8 @@
void Centipede::GenerateCorpusStats(std::string_view filename_annotation,
std::string_view description) {
auto stats_path = wd_.CorpusStatsPath(filename_annotation);
- LOG(INFO) << "Generate corpus stats [" << description << "]; "
- << VV(stats_path);
+ FUZZTEST_LOG(INFO) << "Generate corpus stats [" << description << "]; "
+ << VV(stats_path);
corpus_.DumpStatsToFile(fs_, stats_path, description);
}
@@ -586,14 +587,14 @@
if (env_.clang_coverage_binary.empty()) return;
auto report_path = wd_.SourceBasedCoverageReportPath(filename_annotation);
- LOG(INFO) << "Generate source based coverage report [" << description << "]; "
- << VV(report_path);
- CHECK_OK(RemoteMkdir(report_path));
+ FUZZTEST_LOG(INFO) << "Generate source based coverage report [" << description
+ << "]; " << VV(report_path);
+ FUZZTEST_CHECK_OK(RemoteMkdir(report_path));
std::vector<std::string> raw_profiles = wd_.EnumerateRawCoverageProfiles();
if (raw_profiles.empty()) {
- LOG(ERROR) << "No raw profiles found for coverage report";
+ FUZZTEST_LOG(ERROR) << "No raw profiles found for coverage report";
return;
}
@@ -610,7 +611,7 @@
merge_cmd_options.args = std::move(merge_arguments);
Command merge_command{"llvm-profdata", std::move(merge_cmd_options)};
if (merge_command.Execute() != EXIT_SUCCESS) {
- LOG(ERROR) << "Failed to run command " << merge_command.ToString();
+ FUZZTEST_LOG(ERROR) << "Failed to run command " << merge_command.ToString();
return;
}
@@ -622,8 +623,8 @@
Command generate_report_command{"llvm-cov",
std::move(generate_report_cmd_options)};
if (generate_report_command.Execute() != EXIT_SUCCESS) {
- LOG(ERROR) << "Failed to run command "
- << generate_report_command.ToString();
+ FUZZTEST_LOG(ERROR) << "Failed to run command "
+ << generate_report_command.ToString();
return;
}
}
@@ -634,15 +635,16 @@
public:
explicit ReportDumper(std::string_view path)
: file_{*RemoteFileOpen(path, "w")} {
- CHECK(file_ != nullptr) << VV(path);
- CHECK_OK(RemoteFileSetWriteBufferSize(file_, 10UL * 1024 * 1024));
+ FUZZTEST_CHECK(file_ != nullptr) << VV(path);
+ FUZZTEST_CHECK_OK(
+ RemoteFileSetWriteBufferSize(file_, 10UL * 1024 * 1024));
}
- ~ReportDumper() override { CHECK_OK(RemoteFileClose(file_)); }
+ ~ReportDumper() override { FUZZTEST_CHECK_OK(RemoteFileClose(file_)); }
ReportDumper &operator<<(std::string_view fragment) override {
- CHECK_OK(RemoteFileAppend(file_,
- ByteArray{fragment.cbegin(), fragment.cend()}));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(
+ file_, ByteArray{fragment.cbegin(), fragment.cend()}));
return *this;
}
@@ -652,10 +654,11 @@
const auto &snapshot = rusage_profiler_.TakeSnapshot(
{__FILE__, __LINE__}, std::string{description});
- VLOG(1) << "Rusage @ " << description << ": " << snapshot.ShortMetricsStr();
+ FUZZTEST_VLOG(1) << "Rusage @ " << description << ": "
+ << snapshot.ShortMetricsStr();
auto path = wd_.RUsageReportPath(filename_annotation);
- LOG(INFO) << "Generate rusage report [" << description << "]; "
- << VV(env_.my_shard_index) << VV(path);
+ FUZZTEST_LOG(INFO) << "Generate rusage report [" << description << "]; "
+ << VV(env_.my_shard_index) << VV(path);
ReportDumper dumper{path};
rusage_profiler_.GenerateReport(&dumper);
}
@@ -682,22 +685,23 @@
void Centipede::MergeFromOtherCorpus(std::string_view merge_from_dir,
size_t shard_index_to_merge) {
- LOG(INFO) << __func__ << ": " << merge_from_dir;
+ FUZZTEST_LOG(INFO) << __func__ << ": " << merge_from_dir;
Environment merge_from_env = env_;
merge_from_env.workdir = merge_from_dir;
size_t initial_corpus_size = corpus_.NumActive();
LoadShard(merge_from_env, shard_index_to_merge, /*rerun=*/true);
size_t new_corpus_size = corpus_.NumActive();
- CHECK_GE(new_corpus_size, initial_corpus_size); // Corpus can't shrink here.
+ FUZZTEST_CHECK_GE(new_corpus_size,
+ initial_corpus_size); // Corpus can't shrink here.
if (new_corpus_size > initial_corpus_size) {
auto appender = DefaultBlobFileWriterFactory(env_.riegeli);
- CHECK_OK(
+ FUZZTEST_CHECK_OK(
appender->Open(wd_.CorpusFilePaths().Shard(env_.my_shard_index), "a"));
for (size_t idx = initial_corpus_size; idx < new_corpus_size; ++idx) {
- CHECK_OK(appender->Write(corpus_.Get(idx)));
+ FUZZTEST_CHECK_OK(appender->Write(corpus_.Get(idx)));
}
- LOG(INFO) << "Merge: " << (new_corpus_size - initial_corpus_size)
- << " new inputs added";
+ FUZZTEST_LOG(INFO) << "Merge: " << (new_corpus_size - initial_corpus_size)
+ << " new inputs added";
}
}
@@ -712,16 +716,16 @@
// Save the distilled corpus to a file in workdir and possibly to a hashed
// file in the first corpus dir passed in `--corpus_dir`.
const auto distill_to_path = wd_.DistilledCorpusFilePaths().MyShard();
- LOG(INFO) << "Distilling: shard: " << env_.my_shard_index
- << " output: " << distill_to_path << " "
- << " distilled size: " << corpus_.NumActive();
+ FUZZTEST_LOG(INFO) << "Distilling: shard: " << env_.my_shard_index
+ << " output: " << distill_to_path << " "
+ << " distilled size: " << corpus_.NumActive();
const auto appender = DefaultBlobFileWriterFactory(env_.riegeli);
// NOTE: Always overwrite distilled corpus files -- never append, unlike
// "regular", per-shard corpus files.
- CHECK_OK(appender->Open(distill_to_path, "w"));
+ FUZZTEST_CHECK_OK(appender->Open(distill_to_path, "w"));
for (size_t i = 0; i < corpus_.NumActive(); ++i) {
const ByteArray &input = corpus_.Get(i);
- CHECK_OK(appender->Write(input));
+ FUZZTEST_CHECK_OK(appender->Write(input));
if (!env_.corpus_dir.empty() && !env_.corpus_dir[0].empty()) {
WriteToLocalHashedFileInDir(env_.corpus_dir[0], input);
}
@@ -734,21 +738,22 @@
const size_t num_seeds_available =
user_callbacks_.GetSeeds(env_.batch_size, seed_inputs);
if (num_seeds_available > env_.batch_size) {
- LOG(WARNING) << "More seeds available than requested: "
- << num_seeds_available << " > " << env_.batch_size;
+ FUZZTEST_LOG(WARNING) << "More seeds available than requested: "
+ << num_seeds_available << " > " << env_.batch_size;
}
if (seed_inputs.empty()) {
- QCHECK(!env_.require_seeds)
+ FUZZTEST_QCHECK(!env_.require_seeds)
<< "No seeds returned and --require_seeds=true, exiting early.";
- LOG(WARNING)
+ FUZZTEST_LOG(WARNING)
<< "No seeds returned - will use the default seed of single byte {0}";
seed_inputs.push_back({0});
}
RunBatch(seed_inputs, corpus_file, features_file,
/*unconditional_features_file=*/nullptr);
- LOG(INFO) << "Number of input seeds available: " << num_seeds_available
- << ", number included in corpus: " << corpus_.NumTotal();
+ FUZZTEST_LOG(INFO) << "Number of input seeds available: "
+ << num_seeds_available
+ << ", number included in corpus: " << corpus_.NumTotal();
// Forcely add all seed inputs to avoid empty corpus if none of them increased
// coverage and passed the filters.
@@ -759,9 +764,10 @@
}
void Centipede::FuzzingLoop() {
- LOG(INFO) << "Shard: " << env_.my_shard_index << "/" << env_.total_shards
- << " " << TemporaryLocalDirPath() << " "
- << "seed: " << env_.seed << "\n\n\n";
+ FUZZTEST_LOG(INFO) << "Shard: " << env_.my_shard_index << "/"
+ << env_.total_shards << " " << TemporaryLocalDirPath()
+ << " "
+ << "seed: " << env_.seed << "\n\n\n";
UpdateAndMaybeLogStats("begin-fuzz", 0);
@@ -780,10 +786,10 @@
auto corpus_path = wd_.CorpusFilePaths().Shard(env_.my_shard_index);
auto corpus_file = DefaultBlobFileWriterFactory(env_.riegeli);
- CHECK_OK(corpus_file->Open(corpus_path, "a"));
+ FUZZTEST_CHECK_OK(corpus_file->Open(corpus_path, "a"));
auto features_path = wd_.FeaturesFilePaths().Shard(env_.my_shard_index);
auto features_file = DefaultBlobFileWriterFactory(env_.riegeli);
- CHECK_OK(features_file->Open(features_path, "a"));
+ FUZZTEST_CHECK_OK(features_file->Open(features_path, "a"));
LoadSeedInputs(corpus_file.get(), features_file.get());
@@ -809,7 +815,7 @@
size_t corpus_size_at_last_prune = corpus_.NumActive();
for (size_t batch_index = 0; batch_index < number_of_batches; batch_index++) {
if (ShouldStop()) break;
- CHECK_LT(new_runs, env_.num_runs);
+ FUZZTEST_CHECK_LT(new_runs, env_.num_runs);
auto remaining_runs = env_.num_runs - new_runs;
auto batch_size = std::min(env_.batch_size, remaining_runs);
std::vector<MutationInputRef> mutation_inputs;
@@ -846,7 +852,7 @@
size_t rand = rng_() % (env_.total_shards - 1);
size_t other_shard_index =
(env_.my_shard_index + 1 + rand) % env_.total_shards;
- CHECK_NE(other_shard_index, env_.my_shard_index);
+ FUZZTEST_CHECK_NE(other_shard_index, env_.my_shard_index);
LoadShard(env_, other_shard_index, /*rerun=*/false);
}
@@ -870,49 +876,49 @@
void Centipede::ReportCrash(std::string_view binary,
const std::vector<ByteArray> &input_vec,
const BatchResult &batch_result) {
- CHECK_EQ(input_vec.size(), batch_result.results().size());
+ FUZZTEST_CHECK_EQ(input_vec.size(), batch_result.results().size());
const size_t suspect_input_idx = std::clamp<size_t>(
batch_result.num_outputs_read(), 0, input_vec.size() - 1);
auto log_execution_failure = [&](std::string_view log_prefix) {
- LOG(INFO) << log_prefix << "Batch execution failed:"
- << "\nBinary : " << binary
- << "\nExit code : " << batch_result.exit_code()
- << "\nFailure : "
- << batch_result.failure_description()
- << "\nSignature : "
- << AsPrintableString(AsByteSpan(batch_result.failure_signature()),
- /*max_len=*/32)
- << "\nNumber of inputs : " << input_vec.size()
- << "\nNumber of inputs read: " << batch_result.num_outputs_read()
- << (batch_result.IsSetupFailure()
- ? ""
- : absl::StrCat("\nSuspect input index : ",
- suspect_input_idx))
- << "\nCrash log :\n\n";
+ FUZZTEST_LOG(INFO)
+ << log_prefix << "Batch execution failed:"
+ << "\nBinary : " << binary
+ << "\nExit code : " << batch_result.exit_code()
+ << "\nFailure : " << batch_result.failure_description()
+ << "\nSignature : "
+ << AsPrintableString(AsByteSpan(batch_result.failure_signature()),
+ /*max_len=*/32)
+ << "\nNumber of inputs : " << input_vec.size()
+ << "\nNumber of inputs read: " << batch_result.num_outputs_read()
+ << (batch_result.IsSetupFailure()
+ ? ""
+ : absl::StrCat("\nSuspect input index : ", suspect_input_idx))
+ << "\nCrash log :\n\n";
for (const auto &log_line :
absl::StrSplit(absl::StripAsciiWhitespace(batch_result.log()), '\n')) {
- LOG(INFO).NoPrefix() << "CRASH LOG: " << log_line;
+ FUZZTEST_LOG(INFO).NoPrefix() << "CRASH LOG: " << log_line;
}
- LOG(INFO).NoPrefix() << "\n";
+ FUZZTEST_LOG(INFO).NoPrefix() << "\n";
};
if (batch_result.IsIgnoredFailure()) {
- LOG(INFO) << "Skip further processing of "
- << batch_result.failure_description();
+ FUZZTEST_LOG(INFO) << "Skip further processing of "
+ << batch_result.failure_description();
return;
}
if (batch_result.IsSkippedTest()) {
log_execution_failure("Skipped Test: ");
- LOG(INFO) << "Requesting early stop due to skipped test.";
+ FUZZTEST_LOG(INFO) << "Requesting early stop due to skipped test.";
RequestEarlyStop(EXIT_SUCCESS);
return;
}
if (batch_result.IsSetupFailure()) {
log_execution_failure("Test Setup Failure: ");
- LOG(INFO) << "Requesting early stop due to setup failure in the test.";
+ FUZZTEST_LOG(INFO)
+ << "Requesting early stop due to setup failure in the test.";
RequestEarlyStop(EXIT_FAILURE);
return;
}
@@ -927,14 +933,15 @@
absl::StrCat("ReportCrash[", num_crashes_, "]: ");
log_execution_failure(log_prefix);
- LOG_IF(INFO, num_crashes_ == env_.max_num_crash_reports)
+ FUZZTEST_LOG_IF(INFO, num_crashes_ == env_.max_num_crash_reports)
<< log_prefix
<< "Reached --max_num_crash_reports: further reports will be suppressed";
if (batch_result.failure_description() == kExecutionFailurePerBatchTimeout) {
- LOG(INFO) << log_prefix
- << "Failure applies to entire batch: not executing inputs "
- "one-by-one, trying to find the reproducer";
+ FUZZTEST_LOG(INFO)
+ << log_prefix
+ << "Failure applies to entire batch: not executing inputs "
+ "one-by-one, trying to find the reproducer";
return;
}
@@ -952,14 +959,15 @@
// primed for a crash by the sequence of inputs that preceded the crasher.
std::iota(input_idxs_to_try.begin() + 1, input_idxs_to_try.end(), 0);
} else {
- LOG(INFO)
+ FUZZTEST_LOG(INFO)
<< log_prefix
<< "Skip finding the reproducer from the inputs other than the suspect";
}
// Try inputs one-by-one in the determined order.
- LOG(INFO) << log_prefix
- << "Executing inputs one-by-one, trying to find the reproducer";
+ FUZZTEST_LOG(INFO)
+ << log_prefix
+ << "Executing inputs one-by-one, trying to find the reproducer";
for (auto input_idx : input_idxs_to_try) {
if (ShouldStop()) return;
const auto &one_input = input_vec[input_idx];
@@ -967,38 +975,38 @@
if (!user_callbacks_.Execute(binary, {one_input}, one_input_batch_result)) {
auto hash = Hash(one_input);
auto crash_dir = wd_.CrashReproducerDirPaths().MyShard();
- CHECK_OK(RemoteMkdir(crash_dir));
+ FUZZTEST_CHECK_OK(RemoteMkdir(crash_dir));
std::string input_file_path = std::filesystem::path(crash_dir) / hash;
auto crash_metadata_dir = wd_.CrashMetadataDirPaths().MyShard();
- CHECK_OK(RemoteMkdir(crash_metadata_dir));
+ FUZZTEST_CHECK_OK(RemoteMkdir(crash_metadata_dir));
std::string crash_metadata_path_prefix =
std::filesystem::path(crash_metadata_dir) / hash;
- LOG(INFO) << log_prefix << "Detected crash-reproducing input:"
- << "\nInput index : " << input_idx << "\nInput bytes : "
- << AsPrintableString(one_input, /*max_len=*/32)
- << "\nExit code : " << one_input_batch_result.exit_code()
- << "\nFailure : "
- << one_input_batch_result.failure_description()
- << "\nSignature : "
- << AsPrintableString(
- AsByteSpan(one_input_batch_result.failure_signature()),
- /*max_len=*/32)
- << "\nSaving input to: " << input_file_path
- << "\nSaving crash" //
- << "\nmetadata to : " << crash_metadata_path_prefix << ".*";
- CHECK_OK(RemoteFileSetContents(input_file_path, one_input));
- CHECK_OK(RemoteFileSetContents(
+ FUZZTEST_LOG(INFO)
+ << log_prefix << "Detected crash-reproducing input:"
+ << "\nInput index : " << input_idx << "\nInput bytes : "
+ << AsPrintableString(one_input, /*max_len=*/32)
+ << "\nExit code : " << one_input_batch_result.exit_code()
+ << "\nFailure : "
+ << one_input_batch_result.failure_description()
+ << "\nSignature : "
+ << AsPrintableString(
+ AsByteSpan(one_input_batch_result.failure_signature()),
+ /*max_len=*/32)
+ << "\nSaving input to: " << input_file_path << "\nSaving crash" //
+ << "\nmetadata to : " << crash_metadata_path_prefix << ".*";
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(input_file_path, one_input));
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(
absl::StrCat(crash_metadata_path_prefix, ".desc"),
one_input_batch_result.failure_description()));
- CHECK_OK(RemoteFileSetContents(
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(
absl::StrCat(crash_metadata_path_prefix, ".sig"),
one_input_batch_result.failure_signature()));
return;
}
}
- LOG(INFO) << log_prefix
- << "Crash was not observed when running inputs one-by-one";
+ FUZZTEST_LOG(INFO) << log_prefix
+ << "Crash was not observed when running inputs one-by-one";
// There will be cases when several inputs collectively cause a crash, but no
// single input does. Handle this by writing out the inputs from the batch
@@ -1011,27 +1019,28 @@
const auto &suspect_input = input_vec[suspect_input_idx];
auto suspect_hash = Hash(suspect_input);
auto crash_dir = wd_.CrashReproducerDirPaths().MyShard();
- CHECK_OK(RemoteMkdir(crash_dir));
+ FUZZTEST_CHECK_OK(RemoteMkdir(crash_dir));
std::string crashing_batch_name =
absl::StrCat("crashing_batch-", suspect_hash);
std::string save_dir = std::filesystem::path(crash_dir) / crashing_batch_name;
- CHECK_OK(RemoteMkdir(save_dir));
- LOG(INFO) << log_prefix << "Saving used inputs from batch to: " << save_dir;
+ FUZZTEST_CHECK_OK(RemoteMkdir(save_dir));
+ FUZZTEST_LOG(INFO) << log_prefix
+ << "Saving used inputs from batch to: " << save_dir;
for (int i = 0; i <= suspect_input_idx; ++i) {
const auto &one_input = input_vec[i];
auto hash = Hash(one_input);
std::string file_path = std::filesystem::path(save_dir).append(
absl::StrFormat("input-%010d-%s", i, hash));
- CHECK_OK(RemoteFileSetContents(file_path, one_input));
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(file_path, one_input));
}
auto crash_metadata_dir = wd_.CrashMetadataDirPaths().MyShard();
- CHECK_OK(RemoteMkdir(crash_metadata_dir));
+ FUZZTEST_CHECK_OK(RemoteMkdir(crash_metadata_dir));
std::string crash_metadata_file_path =
std::filesystem::path(crash_metadata_dir) / crashing_batch_name;
- LOG(INFO) << log_prefix
- << "Saving crash metadata to: " << crash_metadata_file_path;
- CHECK_OK(RemoteFileSetContents(crash_metadata_file_path,
- batch_result.failure_description()));
+ FUZZTEST_LOG(INFO) << log_prefix << "Saving crash metadata to: "
+ << crash_metadata_file_path;
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(crash_metadata_file_path,
+ batch_result.failure_description()));
}
} // namespace fuzztest::internal
diff --git a/centipede/centipede_callbacks.cc b/centipede/centipede_callbacks.cc
index 8a2ec0c..5b010b4 100644
--- a/centipede/centipede_callbacks.cc
+++ b/centipede/centipede_callbacks.cc
@@ -24,8 +24,6 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/ascii.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
@@ -81,17 +79,18 @@
// Check the PC table.
if (binary_info.pc_table.empty()) {
if (env_.require_pc_table) {
- LOG(ERROR) << "Could not get PC table; exiting (override with "
- "--require_pc_table=false)";
+ FUZZTEST_LOG(ERROR) << "Could not get PC table; exiting (override with "
+ "--require_pc_table=false)";
exit(EXIT_FAILURE);
}
- LOG(WARNING) << "Could not get PC table; CF table and debug symbols will "
- "not be used";
+ FUZZTEST_LOG(WARNING)
+ << "Could not get PC table; CF table and debug symbols will "
+ "not be used";
return;
}
// Check CF table.
if (binary_info.cf_table.empty()) {
- LOG(WARNING)
+ FUZZTEST_LOG(WARNING)
<< "Could not get CF table; binary should be built with Clang 16 (or "
"later) and with -fsanitize-coverage=control-flow flag";
} else {
@@ -197,7 +196,7 @@
size_t num_inputs_written = 0;
if (env_.has_input_wildcards) {
- CHECK_EQ(inputs.size(), 1);
+ FUZZTEST_CHECK_EQ(inputs.size(), 1);
WriteToLocalFile(temp_input_file_path_, inputs[0]);
num_inputs_written = 1;
} else {
@@ -206,9 +205,9 @@
}
if (num_inputs_written != inputs.size()) {
- LOG(INFO) << "Wrote " << num_inputs_written << "/" << inputs.size()
- << " inputs; shmem_size_mb might be too small: "
- << env_.shmem_size_mb;
+ FUZZTEST_LOG(INFO) << "Wrote " << num_inputs_written << "/" << inputs.size()
+ << " inputs; shmem_size_mb might be too small: "
+ << env_.shmem_size_mb;
}
// Run.
@@ -219,7 +218,7 @@
// Get results.
batch_result.exit_code() = retval;
const bool read_success = batch_result.Read(outputs_blobseq_);
- LOG_IF(ERROR, !read_success) << "Failed to read batch result!";
+ FUZZTEST_LOG_IF(ERROR, !read_success) << "Failed to read batch result!";
outputs_blobseq_.ReleaseSharedMemory(); // Outputs are already consumed.
// We may have fewer feature blobs than inputs if
@@ -231,10 +230,10 @@
// * Logged by the following code.
if (retval == 0 && read_success &&
batch_result.num_outputs_read() != num_inputs_written) {
- LOG(INFO) << "Read " << batch_result.num_outputs_read() << "/"
- << num_inputs_written
- << " outputs; shmem_size_mb might be too small: "
- << env_.shmem_size_mb;
+ FUZZTEST_LOG(INFO) << "Read " << batch_result.num_outputs_read() << "/"
+ << num_inputs_written
+ << " outputs; shmem_size_mb might be too small: "
+ << env_.shmem_size_mb;
}
if (env_.print_runner_log) PrintExecutionLog();
@@ -256,7 +255,7 @@
std::filesystem::remove(failure_description_path_);
std::filesystem::remove(failure_signature_path_);
}
- VLOG(1) << __FUNCTION__ << " took " << (absl::Now() - start_time);
+ FUZZTEST_VLOG(1) << __FUNCTION__ << " took " << (absl::Now() - start_time);
return retval;
}
@@ -266,8 +265,8 @@
std::vector<ByteArray> &seeds) {
const auto output_dir = std::filesystem::path{temp_dir_} / "seed_inputs";
std::error_code error;
- CHECK(std::filesystem::create_directories(output_dir, error));
- CHECK(!error);
+ FUZZTEST_CHECK(std::filesystem::create_directories(output_dir, error));
+ FUZZTEST_CHECK(!error);
std::string centipede_runner_flags = absl::StrCat(
"CENTIPEDE_RUNNER_FLAGS=:dump_seed_inputs:test=", env_.test_name,
@@ -286,7 +285,8 @@
const int retval = cmd.Execute();
if (env_.print_runner_log) {
- LOG(INFO) << "Getting seeds via external binary returns " << retval;
+ FUZZTEST_LOG(INFO) << "Getting seeds via external binary returns "
+ << retval;
PrintExecutionLog();
}
@@ -344,7 +344,7 @@
}
std::error_code error;
std::filesystem::remove(config_file_path, error);
- CHECK(!error);
+ FUZZTEST_CHECK(!error);
return is_success;
}
@@ -353,7 +353,7 @@
MutationResult CentipedeCallbacks::MutateViaExternalBinary(
std::string_view binary, const std::vector<MutationInputRef> &inputs,
size_t num_mutants) {
- CHECK(!env_.has_input_wildcards)
+ FUZZTEST_CHECK(!env_.has_input_wildcards)
<< "Standalone binary does not support custom mutator";
auto start_time = absl::Now();
@@ -362,7 +362,7 @@
size_t num_inputs_written =
RequestMutation(num_mutants, inputs, inputs_blobseq_);
- LOG_IF(INFO, num_inputs_written != inputs.size())
+ FUZZTEST_LOG_IF(INFO, num_inputs_written != inputs.size())
<< VV(num_inputs_written) << VV(inputs.size());
// Execute.
@@ -371,7 +371,7 @@
inputs_blobseq_.ReleaseSharedMemory(); // Inputs are already consumed.
if (retval != EXIT_SUCCESS) {
- LOG(WARNING) << "Custom mutator failed with exit code: " << retval;
+ FUZZTEST_LOG(WARNING) << "Custom mutator failed with exit code: " << retval;
}
if (env_.print_runner_log || retval != EXIT_SUCCESS) {
PrintExecutionLog();
@@ -382,7 +382,7 @@
result.Read(num_mutants, outputs_blobseq_);
outputs_blobseq_.ReleaseSharedMemory(); // Outputs are already consumed.
- VLOG(1) << __FUNCTION__ << " took " << (absl::Now() - start_time);
+ FUZZTEST_VLOG(1) << __FUNCTION__ << " took " << (absl::Now() - start_time);
return result;
}
@@ -398,43 +398,44 @@
env_.use_legacy_default_mutator
? byte_array_mutator_.AddToDictionary(entries)
: fuzztest_mutator_.AddToDictionary(entries);
- LOG(INFO) << "Loaded " << entries.size()
- << " dictionary entries from AFL/libFuzzer dictionary "
- << dictionary_path;
+ FUZZTEST_LOG(INFO) << "Loaded " << entries.size()
+ << " dictionary entries from AFL/libFuzzer dictionary "
+ << dictionary_path;
return entries.size();
}
// Didn't parse as plain text. Assume encoded corpus format.
auto reader = DefaultBlobFileReaderFactory();
- CHECK_OK(reader->Open(dictionary_path))
+ FUZZTEST_CHECK_OK(reader->Open(dictionary_path))
<< "Error in opening dictionary file: " << dictionary_path;
std::vector<ByteArray> unpacked_dictionary;
ByteSpan blob;
while (reader->Read(blob).ok()) {
unpacked_dictionary.emplace_back(blob.begin(), blob.end());
}
- CHECK_OK(reader->Close())
+ FUZZTEST_CHECK_OK(reader->Close())
<< "Error in closing dictionary file: " << dictionary_path;
- CHECK(!unpacked_dictionary.empty())
+ FUZZTEST_CHECK(!unpacked_dictionary.empty())
<< "Empty or corrupt dictionary file: " << dictionary_path;
env_.use_legacy_default_mutator
? byte_array_mutator_.AddToDictionary(unpacked_dictionary)
: fuzztest_mutator_.AddToDictionary(unpacked_dictionary);
- LOG(INFO) << "Loaded " << unpacked_dictionary.size()
- << " dictionary entries from " << dictionary_path;
+ FUZZTEST_LOG(INFO) << "Loaded " << unpacked_dictionary.size()
+ << " dictionary entries from " << dictionary_path;
return unpacked_dictionary.size();
}
void CentipedeCallbacks::PrintExecutionLog() const {
if (!std::filesystem::exists(execute_log_path_)) {
- LOG(WARNING) << "Log file for the last executed binary does not exist: "
- << execute_log_path_;
+ FUZZTEST_LOG(WARNING)
+ << "Log file for the last executed binary does not exist: "
+ << execute_log_path_;
return;
}
std::string log_text;
ReadFromLocalFile(execute_log_path_, log_text);
for (const auto &log_line :
absl::StrSplit(absl::StripAsciiWhitespace(log_text), '\n')) {
- LOG(INFO).NoPrefix() << "LOG: " << log_line;
+ FUZZTEST_LOG(INFO).NoPrefix() << "FUZZTEST_LOG: " << log_line;
}
}
diff --git a/centipede/centipede_callbacks.h b/centipede/centipede_callbacks.h
index 57b9aab..94d8ec5 100644
--- a/centipede/centipede_callbacks.h
+++ b/centipede/centipede_callbacks.h
@@ -22,7 +22,6 @@
#include <vector>
#include "absl/base/nullability.h"
-#include "absl/log/check.h"
#include "absl/status/statusor.h"
#include "./centipede/binary_info.h"
#include "./centipede/byte_array_mutator.h"
@@ -54,9 +53,9 @@
outputs_blobseq_(shmem_name2_.c_str(), env.shmem_size_mb << 20,
env.use_posix_shmem) {
if (env.use_legacy_default_mutator)
- CHECK(byte_array_mutator_.set_max_len(env.max_len));
+ FUZZTEST_CHECK(byte_array_mutator_.set_max_len(env.max_len));
else
- CHECK(fuzztest_mutator_.set_max_len(env.max_len));
+ FUZZTEST_CHECK(fuzztest_mutator_.set_max_len(env.max_len));
}
virtual ~CentipedeCallbacks() {}
diff --git a/centipede/centipede_default_callbacks.cc b/centipede/centipede_default_callbacks.cc
index 20b2efa..ee54c2a 100644
--- a/centipede/centipede_default_callbacks.cc
+++ b/centipede/centipede_default_callbacks.cc
@@ -21,8 +21,6 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "./centipede/centipede_callbacks.h"
@@ -42,7 +40,7 @@
}
if (env_.has_input_wildcards) {
- LOG(INFO) << "Disabling custom mutator for standalone target";
+ FUZZTEST_LOG(INFO) << "Disabling custom mutator for standalone target";
custom_mutator_is_usable_ = false;
}
}
@@ -85,29 +83,33 @@
if (!custom_mutator_is_usable_.has_value()) {
custom_mutator_is_usable_ = result.has_custom_mutator();
if (*custom_mutator_is_usable_) {
- LOG(INFO) << "Custom mutator detected; will use it.";
+ FUZZTEST_LOG(INFO) << "Custom mutator detected; will use it.";
} else {
- LOG(INFO) << "Custom mutator not detected; falling back to the "
- "built-in mutator.";
+ FUZZTEST_LOG(INFO)
+ << "Custom mutator not detected; falling back to the "
+ "built-in mutator.";
}
}
if (*custom_mutator_is_usable_) {
// TODO(b/398261908): Exit with failure instead of crashing.
- CHECK(result.has_custom_mutator())
+ FUZZTEST_CHECK(result.has_custom_mutator())
<< "Test binary no longer has a custom mutator, even though it was "
"previously detected.";
if (!result.mutants().empty()) return std::move(result).mutants();
- LOG_FIRST_N(WARNING, 5) << "Custom mutator returned no mutants; will "
- "generate some using the built-in mutator.";
+ FUZZTEST_LOG_FIRST_N(WARNING, 5)
+ << "Custom mutator returned no mutants; will "
+ "generate some using the built-in mutator.";
}
} else if (ShouldStop()) {
- LOG(WARNING) << "Custom mutator failed, but ignored since the stop "
- "condition it met. Possibly what triggered the stop "
- "condition also interrupted the mutator.";
+ FUZZTEST_LOG(WARNING)
+ << "Custom mutator failed, but ignored since the stop "
+ "condition it met. Possibly what triggered the stop "
+ "condition also interrupted the mutator.";
// Returning whatever mutants we got before the failure.
return std::move(result).mutants();
} else {
- LOG(ERROR) << "Test binary failed when asked to mutate inputs - exiting.";
+ FUZZTEST_LOG(ERROR)
+ << "Test binary failed when asked to mutate inputs - exiting.";
RequestEarlyStop(EXIT_FAILURE);
return {};
}
diff --git a/centipede/centipede_interface.cc b/centipede/centipede_interface.cc
index 77b7a2d..1e74b45 100644
--- a/centipede/centipede_interface.cc
+++ b/centipede/centipede_interface.cc
@@ -33,8 +33,6 @@
#include "absl/base/optimization.h"
#include "absl/cleanup/cleanup.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/ascii.h"
@@ -85,7 +83,7 @@
sigact.sa_flags = SA_ONSTACK;
sigact.sa_handler = [](int received_signum) {
if (received_signum == SIGINT) {
- LOG(INFO) << "Ctrl-C pressed: winding down";
+ FUZZTEST_LOG(INFO) << "Ctrl-C pressed: winding down";
RequestEarlyStop(EXIT_FAILURE);
return;
}
@@ -102,11 +100,11 @@
std::string tmpfile = std::filesystem::path(tmpdir).append("t");
for (const auto &arg : env.args) {
- LOG(INFO) << "Running '" << env.for_each_blob << "' on " << arg;
+ FUZZTEST_LOG(INFO) << "Running '" << env.for_each_blob << "' on " << arg;
auto blob_reader = DefaultBlobFileReaderFactory();
absl::Status open_status = blob_reader->Open(arg);
if (!open_status.ok()) {
- LOG(INFO) << "Failed to open " << arg << ": " << open_status;
+ FUZZTEST_LOG(INFO) << "Failed to open " << arg << ": " << open_status;
return EXIT_FAILURE;
}
ByteSpan blob;
@@ -132,8 +130,8 @@
// provided, analyzes differences. If there is one arg provided, reports the
// function coverage. Returns EXIT_SUCCESS on success, EXIT_FAILURE otherwise.
int Analyze(const Environment &env) {
- LOG(INFO) << "Analyze " << absl::StrJoin(env.args, ",");
- CHECK(!env.binary.empty()) << "--binary must be used";
+ FUZZTEST_LOG(INFO) << "Analyze " << absl::StrJoin(env.args, ",");
+ FUZZTEST_CHECK(!env.binary.empty()) << "--binary must be used";
if (env.args.size() == 1) {
const CoverageResults coverage_results =
GetCoverage(env.binary_name, env.binary_hash, env.args[0]);
@@ -145,8 +143,9 @@
AnalyzeCorporaToLog(env.binary_name, env.binary_hash, env.args[0],
env.args[1]);
} else {
- LOG(FATAL) << "for now, --analyze supports only 1 or 2 work dirs; got "
- << env.args.size();
+ FUZZTEST_LOG(FATAL)
+ << "for now, --analyze supports only 1 or 2 work dirs; got "
+ << env.args.size();
}
return EXIT_SUCCESS;
}
@@ -167,8 +166,8 @@
}
if (env.save_binary_info) {
const std::string binary_info_dir = WorkDir{env}.BinaryInfoDirPath();
- CHECK_OK(RemoteMkdir(binary_info_dir));
- LOG(INFO) << "Serializing binary info to: " << binary_info_dir;
+ FUZZTEST_CHECK_OK(RemoteMkdir(binary_info_dir));
+ FUZZTEST_LOG(INFO) << "Serializing binary info to: " << binary_info_dir;
binary_info.Write(binary_info_dir);
}
if (binary_info.uses_legacy_trace_pc_instrumentation) {
@@ -176,7 +175,7 @@
SavePCTableToFile(binary_info.pc_table, pcs_file_path);
}
if (env.use_pcpair_features) {
- CHECK(!binary_info.pc_table.empty())
+ FUZZTEST_CHECK(!binary_info.pc_table.empty())
<< "--use_pcpair_features requires non-empty pc_table";
}
return binary_info;
@@ -215,7 +214,7 @@
return absl::Minutes(std::clamp(iteration, 0UL, 10UL));
},
});
- if (!envs.front().experiment.empty() || ABSL_VLOG_IS_ON(1)) {
+ if (!envs.front().experiment.empty() || FUZZTEST_VLOG_IS_ON(1)) {
stats_reporters.emplace_back(
[logger = StatsLogger{stats_vec, envs}]() mutable {
logger.ReportCurrStats();
@@ -303,7 +302,8 @@
for (const std::string &crashing_input_file : crashing_input_files) {
ByteArray crashing_input;
- CHECK_OK(RemoteFileGetContents(crashing_input_file, crashing_input));
+ FUZZTEST_CHECK_OK(
+ RemoteFileGetContents(crashing_input_file, crashing_input));
const bool is_reproducible = !scoped_callbacks.callbacks()->Execute(
env.binary, {crashing_input}, batch_result);
const bool is_duplicate =
@@ -311,9 +311,10 @@
!remaining_crash_signatures.insert(batch_result.failure_signature())
.second;
if (!is_reproducible || batch_result.IsSetupFailure() || is_duplicate) {
- CHECK_OK(RemotePathDelete(crashing_input_file, /*recursively=*/false));
+ FUZZTEST_CHECK_OK(
+ RemotePathDelete(crashing_input_file, /*recursively=*/false));
} else {
- CHECK_OK(RemotePathTouchExistingFile(crashing_input_file));
+ FUZZTEST_CHECK_OK(RemotePathTouchExistingFile(crashing_input_file));
}
}
return remaining_crash_signatures;
@@ -334,7 +335,7 @@
const std::filesystem::path crash_metadata_dir =
workdir.CrashMetadataDirPaths().Shard(shard_idx);
- CHECK_OK(RemoteMkdir(crashing_dir.c_str()));
+ FUZZTEST_CHECK_OK(RemoteMkdir(crashing_dir.c_str()));
for (const std::string &crashing_input_file : new_crashing_input_files) {
const std::string crashing_input_file_name =
std::filesystem::path(crashing_input_file).filename();
@@ -344,15 +345,15 @@
const absl::Status status =
RemoteFileGetContents(crash_signature_path, new_crash_signature);
if (!status.ok()) {
- LOG(WARNING) << "Ignoring crashing input " << crashing_input_file_name
- << " due to failure to read the crash signature: "
- << status;
+ FUZZTEST_LOG(WARNING)
+ << "Ignoring crashing input " << crashing_input_file_name
+ << " due to failure to read the crash signature: " << status;
continue;
}
const bool is_duplicate =
!crash_signatures.insert(new_crash_signature).second;
if (is_duplicate) continue;
- CHECK_OK(
+ FUZZTEST_CHECK_OK(
RemoteFileRename(crashing_input_file,
(crashing_dir / crashing_input_file_name).c_str()));
}
@@ -401,12 +402,13 @@
absl::Duration ReadFuzzingTime(std::string_view fuzzing_time_file) {
std::string fuzzing_time_str;
- CHECK_OK(RemoteFileGetContents(fuzzing_time_file, fuzzing_time_str));
+ FUZZTEST_CHECK_OK(RemoteFileGetContents(fuzzing_time_file, fuzzing_time_str));
absl::Duration fuzzing_time;
if (!absl::ParseDuration(absl::StripAsciiWhitespace(fuzzing_time_str),
&fuzzing_time)) {
- LOG(WARNING) << "Failed to parse fuzzing time of a resuming fuzz test: '"
- << fuzzing_time_str << "'. Assuming no fuzzing time so far.";
+ FUZZTEST_LOG(WARNING)
+ << "Failed to parse fuzzing time of a resuming fuzz test: '"
+ << fuzzing_time_str << "'. Assuming no fuzzing time so far.";
return absl::ZeroDuration();
}
return fuzzing_time;
@@ -418,7 +420,7 @@
absl::Status status = RemoteFileSetContents(
fuzzing_time_file,
absl::FormatDuration(absl::Now() - start_time));
- LOG_IF(WARNING, !status.ok())
+ FUZZTEST_LOG_IF(WARNING, !status.ok())
<< "Failed to write fuzzing time: " << status;
},
PeriodicAction::ZeroDelayConstInterval(absl::Seconds(15))};
@@ -431,9 +433,10 @@
env.UpdateWithTargetConfig(fuzztest_config);
absl::Time start_time = absl::Now();
- LOG(INFO) << "Starting the update of the corpus database for fuzz tests:"
- << "\nBinary: " << env.binary
- << "\nCorpus database: " << fuzztest_config.corpus_database;
+ FUZZTEST_LOG(INFO)
+ << "Starting the update of the corpus database for fuzz tests:"
+ << "\nBinary: " << env.binary
+ << "\nCorpus database: " << fuzztest_config.corpus_database;
// Step 1: Preliminary set up of test sharding, binary info, etc.
const auto [test_shard_index, total_test_shards] = SetUpTestSharding();
@@ -457,7 +460,7 @@
}();
std::vector<std::string> fuzz_tests_to_run;
if (env.fuzztest_single_test_mode) {
- CHECK(fuzztest_config.fuzz_tests_in_current_shard.size() == 1)
+ FUZZTEST_CHECK(fuzztest_config.fuzz_tests_in_current_shard.size() == 1)
<< "Must select exactly one fuzz test when running in the single test "
"mode";
fuzz_tests_to_run = fuzztest_config.fuzz_tests_in_current_shard;
@@ -468,10 +471,11 @@
}
}
}
- LOG(INFO) << "Fuzz tests to run:" << absl::StrJoin(fuzz_tests_to_run, ", ");
+ FUZZTEST_LOG(INFO) << "Fuzz tests to run:"
+ << absl::StrJoin(fuzz_tests_to_run, ", ");
const bool is_workdir_specified = !env.workdir.empty();
- CHECK(!is_workdir_specified || env.fuzztest_single_test_mode);
+ FUZZTEST_CHECK(!is_workdir_specified || env.fuzztest_single_test_mode);
// When env.workdir is empty, the full workdir paths will be formed by
// appending the fuzz test names to the base workdir path. We use different
// path when only replaying to avoid replaying an unfinished fuzzing sessions.
@@ -489,8 +493,8 @@
BinaryInfo binary_info = PopulateBinaryInfoAndSavePCsIfNecessary(
env, callbacks_factory, pcs_file_path);
- LOG(INFO) << "Test shard index: " << test_shard_index
- << " Total test shards: " << total_test_shards;
+ FUZZTEST_LOG(INFO) << "Test shard index: " << test_shard_index
+ << " Total test shards: " << total_test_shards;
// Step 2: Iterate over the fuzz tests and run them.
const std::string binary = env.binary;
@@ -504,7 +508,7 @@
const absl::Status has_enough_time = VerifyBazelHasEnoughTimeToRunTest(
start_time, test_time_limit,
/*executed_tests_in_shard=*/i, fuzztest_config.fuzz_tests.size());
- CHECK_OK(has_enough_time)
+ FUZZTEST_CHECK_OK(has_enough_time)
<< "Not enough time for running the fuzz test "
<< fuzz_tests_to_run[i] << " for " << test_time_limit;
}
@@ -521,39 +525,41 @@
// Use the execution IDs to resume or skip tests.
const bool execution_id_matched = [&] {
if (!RemotePathExists(execution_id_path)) return false;
- CHECK(!RemotePathIsDirectory(execution_id_path));
+ FUZZTEST_CHECK(!RemotePathIsDirectory(execution_id_path));
std::string prev_execution_id;
- CHECK_OK(RemoteFileGetContents(execution_id_path, prev_execution_id));
+ FUZZTEST_CHECK_OK(
+ RemoteFileGetContents(execution_id_path, prev_execution_id));
return prev_execution_id == *fuzztest_config.execution_id;
}();
if (execution_id_matched) {
// If execution IDs match but the previous coverage is missing, it means
// the test was previously finished, and we skip running for the test.
if (!RemotePathExists(WorkDir{env}.CoverageDirPath())) {
- LOG(INFO) << "Skipping running the fuzz test "
- << fuzz_tests_to_run[i];
+ FUZZTEST_LOG(INFO)
+ << "Skipping running the fuzz test " << fuzz_tests_to_run[i];
continue;
}
// If execution IDs match and the previous coverage exists, it means
// the same workflow got interrupted when running the test. So we resume
// the test.
is_resuming = true;
- LOG(INFO) << "Resuming running the fuzz test " << fuzz_tests_to_run[i];
+ FUZZTEST_LOG(INFO) << "Resuming running the fuzz test "
+ << fuzz_tests_to_run[i];
} else {
// If the execution IDs mismatch, we start a new run.
is_resuming = false;
- LOG(INFO) << "Starting a new run of the fuzz test "
- << fuzz_tests_to_run[i];
+ FUZZTEST_LOG(INFO) << "Starting a new run of the fuzz test "
+ << fuzz_tests_to_run[i];
}
}
if (RemotePathExists(env.workdir) && !is_resuming) {
// This could be a workdir from a failed run that used a different version
// of the binary. We delete it so that we don't have to deal with
// the assumptions under which it is safe to reuse an old workdir.
- CHECK_OK(RemotePathDelete(env.workdir, /*recursively=*/true));
+ FUZZTEST_CHECK_OK(RemotePathDelete(env.workdir, /*recursively=*/true));
}
const WorkDir workdir{env};
- CHECK_OK(RemoteMkdir(
+ FUZZTEST_CHECK_OK(RemoteMkdir(
workdir.CoverageDirPath())); // Implicitly creates the workdir
// Updating execution ID must be after creating the coverage dir. Otherwise
@@ -561,13 +567,13 @@
// attempt would skip this test.
if (!is_workdir_specified && fuzztest_config.execution_id.has_value() &&
!is_resuming) {
- CHECK_OK(RemoteFileSetContents(execution_id_path,
- *fuzztest_config.execution_id));
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(execution_id_path,
+ *fuzztest_config.execution_id));
}
absl::Cleanup clean_up_workdir = [is_workdir_specified, &env] {
if (!is_workdir_specified && !EarlyStopRequested()) {
- CHECK_OK(RemotePathDelete(env.workdir, /*recursively=*/true));
+ FUZZTEST_CHECK_OK(RemotePathDelete(env.workdir, /*recursively=*/true));
}
};
@@ -580,7 +586,7 @@
// Seed the fuzzing session with the latest coverage corpus and regression
// inputs from the previous fuzzing session.
if (!is_resuming) {
- CHECK_OK(GenerateSeedCorpusFromConfig(
+ FUZZTEST_CHECK_OK(GenerateSeedCorpusFromConfig(
GetSeedCorpusConfig(env, regression_dir.c_str(),
fuzztest_config.replay_coverage_inputs
? coverage_dir.c_str()
@@ -612,14 +618,15 @@
is_resuming = false;
if (EarlyStopRequested()) {
- LOG(INFO) << "Skipping test " << fuzz_tests_to_run[i]
- << " because early stop requested.";
+ FUZZTEST_LOG(INFO) << "Skipping test " << fuzz_tests_to_run[i]
+ << " because early stop requested.";
continue;
}
- LOG(INFO) << (fuzztest_config.only_replay ? "Replaying " : "Fuzzing ")
- << fuzz_tests_to_run[i] << " for " << time_limit
- << "\n\tTest binary: " << env.binary;
+ FUZZTEST_LOG(INFO) << (fuzztest_config.only_replay ? "Replaying "
+ : "Fuzzing ")
+ << fuzz_tests_to_run[i] << " for " << time_limit
+ << "\n\tTest binary: " << env.binary;
const absl::Time start_time = absl::Now();
ClearEarlyStopRequestAndSetStopTime(/*stop_time=*/start_time + time_limit);
@@ -631,15 +638,16 @@
if (!stats_root_path.empty()) {
const auto stats_dir = stats_root_path / fuzz_tests_to_run[i];
- CHECK_OK(RemoteMkdir(stats_dir.c_str()));
- CHECK_OK(RemoteFileRename(
+ FUZZTEST_CHECK_OK(RemoteMkdir(stats_dir.c_str()));
+ FUZZTEST_CHECK_OK(RemoteFileRename(
workdir.FuzzingStatsPath(),
(stats_dir / absl::StrCat("fuzzing_stats_", execution_stamp))
.c_str()));
}
if (EarlyStopRequested()) {
- LOG(INFO) << "Skip updating corpus database due to early stop requested.";
+ FUZZTEST_LOG(INFO)
+ << "Skip updating corpus database due to early stop requested.";
continue;
}
@@ -652,16 +660,18 @@
if (RemotePathExists(coverage_dir.c_str())) {
// In the future, we will store k latest coverage corpora for some k, but
// for now we only keep the latest one.
- CHECK_OK(RemotePathDelete(coverage_dir.c_str(), /*recursively=*/true));
+ FUZZTEST_CHECK_OK(
+ RemotePathDelete(coverage_dir.c_str(), /*recursively=*/true));
}
- CHECK_OK(RemoteMkdir(coverage_dir.c_str()));
+ FUZZTEST_CHECK_OK(RemoteMkdir(coverage_dir.c_str()));
std::vector<std::string> distilled_corpus_files;
- CHECK_OK(RemoteGlobMatch(workdir.DistilledCorpusFilePaths().AllShardsGlob(),
- distilled_corpus_files));
+ FUZZTEST_CHECK_OK(
+ RemoteGlobMatch(workdir.DistilledCorpusFilePaths().AllShardsGlob(),
+ distilled_corpus_files));
for (const std::string &corpus_file : distilled_corpus_files) {
const std::string file_name =
std::filesystem::path(corpus_file).filename();
- CHECK_OK(
+ FUZZTEST_CHECK_OK(
RemoteFileRename(corpus_file, (coverage_dir / file_name).c_str()));
}
@@ -679,9 +689,9 @@
int ListCrashIds(const Environment &env,
const fuzztest::internal::Configuration &target_config) {
- CHECK(!env.list_crash_ids_file.empty())
+ FUZZTEST_CHECK(!env.list_crash_ids_file.empty())
<< "Need list_crash_ids_file to be set for listing crash IDs";
- CHECK_EQ(target_config.fuzz_tests_in_current_shard.size(), 1);
+ FUZZTEST_CHECK_EQ(target_config.fuzz_tests_in_current_shard.size(), 1);
std::vector<std::string> crash_paths;
// TODO: b/406003594 - move the path construction to a library.
const auto crash_dir = std::filesystem::path(target_config.corpus_database) /
@@ -689,7 +699,7 @@
target_config.fuzz_tests_in_current_shard[0] /
"crashing";
if (RemotePathExists(crash_dir.string())) {
- CHECK(RemotePathIsDirectory(crash_dir.string()))
+ FUZZTEST_CHECK(RemotePathIsDirectory(crash_dir.string()))
<< "Crash dir " << crash_dir << " in the corpus database "
<< target_config.corpus_database << " is not a directory";
crash_paths =
@@ -701,16 +711,17 @@
std::string crash_id = std::filesystem::path{crash_path}.filename();
results.push_back(std::move(crash_id));
}
- CHECK_OK(RemoteFileSetContents(env.list_crash_ids_file,
- absl::StrJoin(results, "\n")));
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(env.list_crash_ids_file,
+ absl::StrJoin(results, "\n")));
return EXIT_SUCCESS;
}
int ReplayCrash(const Environment &env,
const fuzztest::internal::Configuration &target_config,
CentipedeCallbacksFactory &callbacks_factory) {
- CHECK(!env.crash_id.empty()) << "Need crash_id to be set for replay a crash";
- CHECK(target_config.fuzz_tests_in_current_shard.size() == 1)
+ FUZZTEST_CHECK(!env.crash_id.empty())
+ << "Need crash_id to be set for replay a crash";
+ FUZZTEST_CHECK(target_config.fuzz_tests_in_current_shard.size() == 1)
<< "Expecting exactly one test for replay_crash";
// TODO: b/406003594 - move the path construction to a library.
const auto crash_dir = std::filesystem::path(target_config.corpus_database) /
@@ -732,8 +743,8 @@
.filename(),
/*shard_index_digits=*/WorkDir::kDigitsInShardIndex,
/*num_shards=*/1}};
- CHECK_OK(GenerateSeedCorpusFromConfig(crash_corpus_config, env.binary_name,
- env.binary_hash));
+ FUZZTEST_CHECK_OK(GenerateSeedCorpusFromConfig(
+ crash_corpus_config, env.binary_name, env.binary_hash));
Environment run_crash_env = env;
run_crash_env.load_shards_only = true;
return Fuzz(run_crash_env, {}, "", callbacks_factory);
@@ -741,11 +752,11 @@
int ExportCrash(const Environment &env,
const fuzztest::internal::Configuration &target_config) {
- CHECK(!env.crash_id.empty())
+ FUZZTEST_CHECK(!env.crash_id.empty())
<< "Need crash_id to be set for exporting a crash";
- CHECK(!env.export_crash_file.empty())
+ FUZZTEST_CHECK(!env.export_crash_file.empty())
<< "Need export_crash_file to be set for exporting a crash";
- CHECK(target_config.fuzz_tests_in_current_shard.size() == 1)
+ FUZZTEST_CHECK(target_config.fuzz_tests_in_current_shard.size() == 1)
<< "Expecting exactly one test for exporting a crash";
// TODO: b/406003594 - move the path construction to a library.
const auto crash_dir = std::filesystem::path(target_config.corpus_database) /
@@ -756,15 +767,15 @@
const auto read_status =
RemoteFileGetContents((crash_dir / env.crash_id).c_str(), crash_contents);
if (!read_status.ok()) {
- LOG(ERROR) << "Failed reading the crash " << env.crash_id << " from "
- << crash_dir.c_str() << ": " << read_status;
+ FUZZTEST_LOG(ERROR) << "Failed reading the crash " << env.crash_id
+ << " from " << crash_dir.c_str() << ": " << read_status;
return EXIT_FAILURE;
}
const auto write_status =
RemoteFileSetContents(env.export_crash_file, crash_contents);
if (!write_status.ok()) {
- LOG(ERROR) << "Failed write the crash " << env.crash_id << " to "
- << env.export_crash_file << ": " << write_status;
+ FUZZTEST_LOG(ERROR) << "Failed write the crash " << env.crash_id << " to "
+ << env.export_crash_file << ": " << write_status;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
@@ -785,7 +796,8 @@
if (!env.crashes_to_files.empty()) {
const auto status = Centipede::CrashesToFiles(env, env.crashes_to_files);
if (status.ok()) return EXIT_SUCCESS;
- LOG(ERROR) << "Got error when exporting crashes to files: " << status;
+ FUZZTEST_LOG(ERROR) << "Got error when exporting crashes to files: "
+ << status;
return EXIT_FAILURE;
}
@@ -830,21 +842,22 @@
// to the unified execution model.
if (!env.fuzztest_configuration.empty()) {
std::string result;
- CHECK(absl::WebSafeBase64Unescape(env.fuzztest_configuration, &result));
+ FUZZTEST_CHECK(
+ absl::WebSafeBase64Unescape(env.fuzztest_configuration, &result));
return result;
}
ScopedCentipedeCallbacks scoped_callbacks(callbacks_factory, env);
return scoped_callbacks.callbacks()->GetSerializedTargetConfig();
}();
- CHECK_OK(serialized_target_config.status());
+ FUZZTEST_CHECK_OK(serialized_target_config.status());
if (!serialized_target_config->empty()) {
const auto target_config = fuzztest::internal::Configuration::Deserialize(
*serialized_target_config);
- CHECK_OK(target_config.status())
+ FUZZTEST_CHECK_OK(target_config.status())
<< "Failed to deserialize target configuration";
if (!target_config->corpus_database.empty()) {
- LOG_IF(FATAL,
- env.list_crash_ids + env.replay_crash + env.export_crash > 1)
+ FUZZTEST_LOG_IF(
+ FATAL, env.list_crash_ids + env.replay_crash + env.export_crash > 1)
<< "At most one of list_crash_ids/replay_crash/export_crash can "
"be set, but seeing list_crash_ids: "
<< env.list_crash_ids << ", replay_crash: " << env.replay_crash
@@ -860,11 +873,11 @@
}
const auto time_limit_per_test = target_config->GetTimeLimitPerTest();
- CHECK(target_config->only_replay ||
- time_limit_per_test < absl::InfiniteDuration())
+ FUZZTEST_CHECK(target_config->only_replay ||
+ time_limit_per_test < absl::InfiniteDuration())
<< "Updating corpus database requires specifying time limit per "
"fuzz test.";
- CHECK(time_limit_per_test >= absl::Seconds(1))
+ FUZZTEST_CHECK(time_limit_per_test >= absl::Seconds(1))
<< "Time limit per fuzz test must be at least 1 second.";
return UpdateCorpusDatabaseForFuzzTests(env, *target_config,
callbacks_factory);
@@ -874,9 +887,9 @@
// Create the remote coverage dirs once, before creating any threads.
const auto coverage_dir = WorkDir{env}.CoverageDirPath();
- CHECK_OK(RemoteMkdir(coverage_dir));
- LOG(INFO) << "Coverage dir: " << coverage_dir
- << "; temporary dir: " << tmpdir;
+ FUZZTEST_CHECK_OK(RemoteMkdir(coverage_dir));
+ FUZZTEST_LOG(INFO) << "Coverage dir: " << coverage_dir
+ << "; temporary dir: " << tmpdir;
std::string pcs_file_path;
BinaryInfo binary_info = PopulateBinaryInfoAndSavePCsIfNecessary(
diff --git a/centipede/centipede_test.cc b/centipede/centipede_test.cc
index c66e7ab..b048e6e 100644
--- a/centipede/centipede_test.cc
+++ b/centipede/centipede_test.cc
@@ -31,8 +31,6 @@
#include "gtest/gtest.h"
#include "absl/base/nullability.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/time/time.h"
#include "./centipede/centipede_callbacks.h"
@@ -360,14 +358,14 @@
// Will not be called.
bool Execute(std::string_view binary, const std::vector<ByteArray> &inputs,
BatchResult &batch_result) override {
- CHECK(false);
+ FUZZTEST_CHECK(false);
return false;
}
// Will not be called.
std::vector<ByteArray> Mutate(const std::vector<MutationInputRef> &inputs,
size_t num_mutants) override {
- CHECK(false);
+ FUZZTEST_CHECK(false);
}
// Redeclare a protected member function as public so the tests can call it.
@@ -505,7 +503,7 @@
BatchResult &batch_result) override {
batch_result.results().resize(inputs.size());
for (size_t i = 0, n = inputs.size(); i < n; ++i) {
- CHECK_EQ(inputs[i].size(), 1);
+ FUZZTEST_CHECK_EQ(inputs[i].size(), 1);
batch_result.results()[i].mutable_features() = {inputs[i][0]};
}
return true;
@@ -582,8 +580,10 @@
: CentipedeCallbacks(env) {
std::vector<ByteArray> seed_inputs;
const size_t num_seeds_available = GetSeeds(/*num_seeds=*/1, seed_inputs);
- CHECK_EQ(num_seeds_available, 1) << "Default seeds must have size one.";
- CHECK_EQ(seed_inputs.size(), 1) << "Default seeds must have size one.";
+ FUZZTEST_CHECK_EQ(num_seeds_available, 1)
+ << "Default seeds must have size one.";
+ FUZZTEST_CHECK_EQ(seed_inputs.size(), 1)
+ << "Default seeds must have size one.";
seed_inputs_.insert(seed_inputs.begin(), seed_inputs.end());
}
@@ -646,7 +646,7 @@
FunctionFilterMock mock(env);
MockFactory factory(mock);
CentipedeMain(env, factory);
- LOG(INFO) << mock.observed_inputs_.size();
+ FUZZTEST_LOG(INFO) << mock.observed_inputs_.size();
std::vector<ByteArray> res(mock.observed_inputs_.begin(),
mock.observed_inputs_.end());
std::sort(res.begin(), res.end());
@@ -808,7 +808,7 @@
explicit UndetectedCrashingInputMock(const Environment &env,
size_t crashing_input_idx)
: CentipedeCallbacks{env}, crashing_input_idx_{crashing_input_idx} {
- CHECK_LE(crashing_input_idx_, std::numeric_limits<uint8_t>::max());
+ FUZZTEST_CHECK_LE(crashing_input_idx_, std::numeric_limits<uint8_t>::max());
}
// Doesn't execute anything.
@@ -822,7 +822,7 @@
num_inputs_triaged_ += inputs.size();
}
for (const auto &input : inputs) {
- CHECK_EQ(input.size(), 1); // By construction in `Mutate()`.
+ FUZZTEST_CHECK_EQ(input.size(), 1); // By construction in `Mutate()`.
// The contents of each mutant is its sequential number.
if (input[0] == crashing_input_idx_) {
if (first_pass_) {
@@ -881,8 +881,8 @@
constexpr size_t kCrashingInputIdx =
(kNumBatches / 2) * kBatchSize + kCrashingInputIdxInBatch;
- LOG(INFO) << VV(kNumBatches) << VV(kBatchSize)
- << VV(kCrashingInputIdxInBatch) VV(kCrashingInputIdx);
+ FUZZTEST_LOG(INFO) << VV(kNumBatches) << VV(kBatchSize)
+ << VV(kCrashingInputIdxInBatch) VV(kCrashingInputIdx);
TempDir temp_dir{test_info_->name()};
Environment env;
diff --git a/centipede/command.cc b/centipede/command.cc
index d533bde..c5d7fd8 100644
--- a/centipede/command.cc
+++ b/centipede/command.cc
@@ -37,8 +37,6 @@
#include <vector>
#include "absl/base/const_init.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/match.h"
@@ -125,13 +123,14 @@
~ForkServerProps() {
for (int i = 0; i < 2; ++i) {
if (pipe_[i] >= 0 && close(pipe_[i]) != 0) {
- LOG(ERROR) << "Failed to close fork server pipe for " << fifo_path_[i];
+ FUZZTEST_LOG(ERROR)
+ << "Failed to close fork server pipe for " << fifo_path_[i];
}
std::error_code ec;
if (!fifo_path_[i].empty() &&
!std::filesystem::remove(fifo_path_[i], ec)) {
- LOG(ERROR) << "Failed to remove fork server pipe file " << fifo_path_[i]
- << ": " << ec;
+ FUZZTEST_LOG(ERROR) << "Failed to remove fork server pipe file "
+ << fifo_path_[i] << ": " << ec;
}
}
}
@@ -171,7 +170,7 @@
// Replace @@ with temp_file_path_.
constexpr std::string_view kTempFileWildCard = "@@";
if (absl::StrContains(path, kTempFileWildCard)) {
- CHECK(!options_.temp_file_path.empty());
+ FUZZTEST_CHECK(!options_.temp_file_path.empty());
path = absl::StrReplaceAll(path,
{{kTempFileWildCard, options_.temp_file_path}});
}
@@ -198,10 +197,10 @@
bool Command::StartForkServer(std::string_view temp_dir_path,
std::string_view prefix) {
if (absl::StartsWith(path_, kNoForkServerRequestPrefix)) {
- VLOG(2) << "Fork server disabled for " << path();
+ FUZZTEST_VLOG(2) << "Fork server disabled for " << path();
return false;
}
- VLOG(2) << "Starting fork server for " << path();
+ FUZZTEST_VLOG(2) << "Starting fork server for " << path();
fork_server_.reset(new ForkServerProps);
fork_server_->fifo_path_[0] = std::filesystem::path(temp_dir_path)
@@ -212,7 +211,7 @@
std::filesystem::path(temp_dir_path).append("pid");
(void)std::filesystem::create_directory(temp_dir_path); // it may not exist.
for (int i = 0; i < 2; ++i) {
- PCHECK(mkfifo(fork_server_->fifo_path_[i].c_str(), 0600) == 0)
+ FUZZTEST_PCHECK(mkfifo(fork_server_->fifo_path_[i].c_str(), 0600) == 0)
<< VV(i) << VV(fork_server_->fifo_path_[i]);
}
@@ -231,7 +230,7 @@
const std::string fork_server_command = absl::StrFormat(
kForkServerCommandStub, fork_server_->fifo_path_[0],
fork_server_->fifo_path_[1], command_line_, pid_file_path);
- VLOG(2) << "Fork server command:" << fork_server_command;
+ FUZZTEST_VLOG(2) << "Fork server command:" << fork_server_command;
const int exit_code = system(fork_server_command.c_str());
@@ -267,7 +266,7 @@
std::string pid_str;
ReadFromLocalFile(pid_file_path, pid_str);
- CHECK(absl::SimpleAtoi(pid_str, &fork_server_->pid_)) << VV(pid_str);
+ FUZZTEST_CHECK(absl::SimpleAtoi(pid_str, &fork_server_->pid_)) << VV(pid_str);
auto creation_stamp = GetProcessCreationStamp(fork_server_->pid_);
if (!creation_stamp.ok()) {
LogProblemInfo(
@@ -285,9 +284,10 @@
// Preconditions: the callers (`Execute()`) should call us only when the fork
// server is presumed to be running (`fork_server_pid_` >= 0). If it is, the
// comms pipes are guaranteed to be opened by `StartForkServer()`.
- CHECK(fork_server_ != nullptr) << "Fork server wasn't started";
- CHECK(fork_server_->pid_ >= 0) << "Fork server process failed to start";
- CHECK(fork_server_->pipe_[0] >= 0 && fork_server_->pipe_[1] >= 0)
+ FUZZTEST_CHECK(fork_server_ != nullptr) << "Fork server wasn't started";
+ FUZZTEST_CHECK(fork_server_->pid_ >= 0)
+ << "Fork server process failed to start";
+ FUZZTEST_CHECK(fork_server_->pipe_[0] >= 0 && fork_server_->pipe_[1] >= 0)
<< "Failed to connect to fork server";
// A process with the fork server PID exists (_some_ process, possibly with a
@@ -309,13 +309,13 @@
}
int Command::Execute() {
- VLOG(1) << "Executing command '" << command_line_ << "'...";
+ FUZZTEST_VLOG(1) << "Executing command '" << command_line_ << "'...";
int exit_code = EXIT_SUCCESS;
if (fork_server_ != nullptr) {
- VLOG(1) << "Sending execution request to fork server: "
- << VV(options_.timeout);
+ FUZZTEST_VLOG(1) << "Sending execution request to fork server: "
+ << VV(options_.timeout);
if (const auto status = VerifyForkServerIsHealthy(); !status.ok()) {
LogProblemInfo(absl::StrCat("Fork server should be running, but isn't: ",
@@ -325,7 +325,7 @@
// Wake up the fork server.
char x = ' ';
- CHECK_EQ(1, write(fork_server_->pipe_[0], &x, 1));
+ FUZZTEST_CHECK_EQ(1, write(fork_server_->pipe_[0], &x, 1));
// The fork server forks, the child is running. Block until some readable
// data appears in the pipe (that is, after the fork server writes the
@@ -361,10 +361,10 @@
}
// The fork server wrote the execution result to the pipe: read it.
- CHECK_EQ(sizeof(exit_code),
- read(fork_server_->pipe_[1], &exit_code, sizeof(exit_code)));
+ FUZZTEST_CHECK_EQ(sizeof(exit_code), read(fork_server_->pipe_[1],
+ &exit_code, sizeof(exit_code)));
} else {
- VLOG(1) << "Fork server disabled - executing command directly";
+ FUZZTEST_VLOG(1) << "Fork server disabled - executing command directly";
// No fork server, use system().
exit_code = system(command_line_.c_str());
}
@@ -454,21 +454,21 @@
static absl::Mutex mu{absl::kConstInit};
absl::MutexLock lock(&mu);
- LOG(ERROR) << message;
- LOG(ERROR).NoPrefix() << "=== COMMAND ===";
- LOG(ERROR).NoPrefix() << command_line_;
- LOG(ERROR).NoPrefix() << "=== STDOUT ===";
+ FUZZTEST_LOG(ERROR) << message;
+ FUZZTEST_LOG(ERROR).NoPrefix() << "=== COMMAND ===";
+ FUZZTEST_LOG(ERROR).NoPrefix() << command_line_;
+ FUZZTEST_LOG(ERROR).NoPrefix() << "=== STDOUT ===";
for (const auto &line : absl::StrSplit(ReadRedirectedStdout(), '\n')) {
- LOG(ERROR).NoPrefix() << line;
+ FUZZTEST_LOG(ERROR).NoPrefix() << line;
}
- LOG(ERROR).NoPrefix() << "=== STDERR ===";
+ FUZZTEST_LOG(ERROR).NoPrefix() << "=== STDERR ===";
for (const auto &line : absl::StrSplit(ReadRedirectedStderr(), '\n')) {
- LOG(ERROR).NoPrefix() << line;
+ FUZZTEST_LOG(ERROR).NoPrefix() << line;
}
}
void Command::VlogProblemInfo(std::string_view message, int vlog_level) const {
- if (ABSL_VLOG_IS_ON(vlog_level)) LogProblemInfo(message);
+ if (FUZZTEST_VLOG_IS_ON(vlog_level)) LogProblemInfo(message);
}
} // namespace fuzztest::internal
diff --git a/centipede/command.h b/centipede/command.h
index 80c7877..66095a6 100644
--- a/centipede/command.h
+++ b/centipede/command.h
@@ -101,8 +101,8 @@
// by the the command line, followed by the redirected stdout and stderr read
// from `options_.out` and `options_.err` files, if any.
void LogProblemInfo(std::string_view message) const;
- // Just as `LogCrashInfo()`, but logging occurs only when the VLOG level (set
- // via `--v` or its equivalents) is >= `min_vlog`.
+ // Just as `LogCrashInfo()`, but logging occurs only when the FUZZTEST_VLOG
+ // level (set via `--v` or its equivalents) is >= `min_vlog`.
void VlogProblemInfo(std::string_view message, int vlog_level) const;
const std::string path_;
diff --git a/centipede/command_test.cc b/centipede/command_test.cc
index 3129a41..bd75068 100644
--- a/centipede/command_test.cc
+++ b/centipede/command_test.cc
@@ -24,11 +24,11 @@
#include <utility>
#include "gtest/gtest.h"
-#include "absl/log/log.h"
#include "absl/strings/substitute.h"
#include "absl/time/time.h"
#include "./centipede/stop.h"
#include "./centipede/util.h"
+#include "./common/logging.h"
#include "./common/test_util.h"
namespace fuzztest::internal {
@@ -96,7 +96,7 @@
Command self_sigint{"bash -c 'kill -SIGINT $$'"};
self_sigint.Execute();
if (ShouldStop()) {
- LOG(INFO) << "Early stop requested";
+ FUZZTEST_LOG(INFO) << "Early stop requested";
exit(ExitCode());
}
};
diff --git a/centipede/concurrent_bitset.h b/centipede/concurrent_bitset.h
index 09d1aa1..2e38d79 100644
--- a/centipede/concurrent_bitset.h
+++ b/centipede/concurrent_bitset.h
@@ -22,7 +22,7 @@
//
// This library must not depend on anything other than libc so that fuzz targets
// using it doesn't gain redundant coverage. For the same reason this library
-// uses raw __builtin_trap instead of CHECKs.
+// uses raw __builtin_trap instead of FUZZTEST_CHECKs.
// We make an exception for <algorithm> for std::sort/std::unique,
// since <algorithm> is very lightweight.
// This library is also header-only, with all functions defined as inline.
diff --git a/centipede/config_file.cc b/centipede/config_file.cc
index 2b288f1..89c0613 100644
--- a/centipede/config_file.cc
+++ b/centipede/config_file.cc
@@ -29,8 +29,6 @@
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "absl/flags/reflection.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
@@ -116,7 +114,9 @@
const std::string& new_arg = argv_.emplace_back(
absl::StrReplaceAll(flag_replaced_arg.value_or(old_arg), replacements));
if (new_arg != old_arg) {
- VLOG(1) << "Augmented argv arg:\n" << VV(old_arg) << "\n" << VV(new_arg);
+ FUZZTEST_VLOG(1) << "Augmented argv arg:\n"
+ << VV(old_arg) << "\n"
+ << VV(new_arg);
was_augmented_ = true;
}
}
@@ -147,7 +147,7 @@
const std::filesystem::path path = absl::GetFlag(FLAGS_config);
if (!path.empty()) {
- CHECK_NE(path, absl::GetFlag(FLAGS_save_config))
+ FUZZTEST_CHECK_NE(path, absl::GetFlag(FLAGS_save_config))
<< "To update config in place, use " << DASHED_FLAG_NAME(update_config);
}
@@ -162,15 +162,16 @@
if (!path.empty() && !std::filesystem::exists(path)) { // assume remote
// Read the remote file.
std::string contents;
- CHECK_OK(RemoteFileGetContents(path.c_str(), contents));
+ FUZZTEST_CHECK_OK(RemoteFileGetContents(path.c_str(), contents));
// Save a temporary local copy.
const std::filesystem::path tmp_dir = TemporaryLocalDirPath();
const std::filesystem::path local_path = tmp_dir / path.filename();
- LOG(INFO) << "Localizing remote config: " << VV(path) << VV(local_path);
+ FUZZTEST_LOG(INFO) << "Localizing remote config: " << VV(path)
+ << VV(local_path);
// NOTE: Ignore "Remote" in the API names here: the paths are always local.
- CHECK_OK(RemoteMkdir(tmp_dir.c_str()));
- CHECK_OK(RemoteFileSetContents(local_path.c_str(), contents));
+ FUZZTEST_CHECK_OK(RemoteMkdir(tmp_dir.c_str()));
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(local_path.c_str(), contents));
// Augment the argv to point at the local copy and ensure it is cleaned up.
replacements.emplace_back(path.c_str(), local_path.c_str());
@@ -188,16 +189,16 @@
// Initialize `path` if --save_config or --update_config is passed.
if (!absl::GetFlag(FLAGS_save_config).empty()) {
path = absl::GetFlag(FLAGS_save_config);
- CHECK_NE(path, absl::GetFlag(FLAGS_config))
+ FUZZTEST_CHECK_NE(path, absl::GetFlag(FLAGS_config))
<< "To update config in place, use " << DASHED_FLAG_NAME(update_config);
- CHECK(!absl::GetFlag(FLAGS_update_config))
+ FUZZTEST_CHECK(!absl::GetFlag(FLAGS_update_config))
<< DASHED_FLAG_NAME(save_config) << " and "
<< DASHED_FLAG_NAME(update_config) << " are mutually exclusive";
} else if (absl::GetFlag(FLAGS_update_config)) {
path = absl::GetFlag(FLAGS_config);
- CHECK(!path.empty()) << DASHED_FLAG_NAME(update_config)
- << " must be used in combination with "
- << DASHED_FLAG_NAME(config);
+ FUZZTEST_CHECK(!path.empty())
+ << DASHED_FLAG_NAME(update_config)
+ << " must be used in combination with " << DASHED_FLAG_NAME(config);
}
// Save or update the config file.
@@ -244,7 +245,7 @@
} else {
file_contents = flags_str;
}
- CHECK_OK(RemoteFileSetContents(path.c_str(), file_contents));
+ FUZZTEST_CHECK_OK(RemoteFileSetContents(path.c_str(), file_contents));
}
return path;
@@ -269,7 +270,7 @@
const AugmentedArgvWithCleanup localized_argv =
LocalizeConfigFilesInArgv(saved_argv);
if (localized_argv.was_augmented()) {
- LOG(INFO) << "Command line was augmented; reparsing";
+ FUZZTEST_LOG(INFO) << "Command line was augmented; reparsing";
runtime_state->leftover_argv() = CastArgv(absl::ParseCommandLine(
localized_argv.argc(), CastArgv(localized_argv.argv()).data()));
}
@@ -279,15 +280,15 @@
const FlagInfosPerSource flags = GetFlagsPerSource("centipede");
const std::string flags_str = FormatFlagfileString(
flags, DefaultedFlags::kCommentedOut, FlagComments::kNone);
- LOG(INFO) << "Final resolved config:\n" << flags_str;
+ FUZZTEST_LOG(INFO) << "Final resolved config:\n" << flags_str;
}
// If --save_config was passed, save the final resolved flags to the requested
// file and exit the program.
const auto path = MaybeSaveConfigToFile(leftover_argv);
if (!path.empty()) {
- LOG(INFO) << "Config written to file: " << VV(path);
- LOG(INFO) << "Nothing left to do; exiting";
+ FUZZTEST_LOG(INFO) << "Config written to file: " << VV(path);
+ FUZZTEST_LOG(INFO) << "Nothing left to do; exiting";
exit(EXIT_SUCCESS);
}
diff --git a/centipede/config_init.cc b/centipede/config_init.cc
index 5c5c555..2d22a33 100644
--- a/centipede/config_init.cc
+++ b/centipede/config_init.cc
@@ -37,7 +37,7 @@
ABSL_ATTRIBUTE_WEAK std::unique_ptr<RuntimeState> InitRuntime(int argc,
char* argv[]) {
// NB: The invocation order below is very important. Do not change.
- // Make `LOG(INFO)` to go to stderr by default. Note that an explicit
+ // Make `FUZZTEST_LOG(INFO)` to go to stderr by default. Note that an explicit
// `--stderrthreshold=N` on the command line will override this.
absl::SetStderrThreshold(absl::LogSeverityAtLeast::kInfo);
// Make --help print any flags defined by any Centipede source.
diff --git a/centipede/config_init.h b/centipede/config_init.h
index 740d2cc..59436df 100644
--- a/centipede/config_init.h
+++ b/centipede/config_init.h
@@ -42,8 +42,8 @@
};
// * Initializes the relevant runtime subsystems in the correct order.
-// * Directs all `LOG(INFO)`s to also to stderr (by default, only `LOG(ERROR)`s
-// and higher go to stderr).
+// * Directs all `FUZZTEST_LOG(INFO)`s to also to stderr (by default, only
+// `FUZZTEST_LOG(ERROR)`s and higher go to stderr).
// * Tweaks --help behavior to print any flags defined by any Centipede source
// (by default, --help only prints flags defined in the source named
// <program>.cc or <program_main>.cc).
diff --git a/centipede/control_flow.cc b/centipede/control_flow.cc
index 68c443e..e053a80 100644
--- a/centipede/control_flow.cc
+++ b/centipede/control_flow.cc
@@ -30,8 +30,6 @@
#include <vector>
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
@@ -47,11 +45,11 @@
PCTable ReadPcTableFromFile(std::string_view file_path) {
ByteArray pc_infos_as_bytes;
ReadFromLocalFile(file_path, pc_infos_as_bytes);
- CHECK_EQ(pc_infos_as_bytes.size() % sizeof(PCInfo), 0);
+ FUZZTEST_CHECK_EQ(pc_infos_as_bytes.size() % sizeof(PCInfo), 0);
size_t pc_table_size = pc_infos_as_bytes.size() / sizeof(PCInfo);
const auto *pc_infos = reinterpret_cast<PCInfo *>(pc_infos_as_bytes.data());
PCTable pc_table{pc_infos, pc_infos + pc_table_size};
- CHECK_EQ(pc_table.size(), pc_table_size);
+ FUZZTEST_CHECK_EQ(pc_table.size(), pc_table_size);
return pc_table;
}
@@ -68,9 +66,9 @@
if (exit_code != EXIT_SUCCESS) {
std::string log_text;
ReadFromLocalFile(stderr_path, log_text);
- LOG(ERROR) << "Failed to use objdump to get PC table; stderr is:";
+ FUZZTEST_LOG(ERROR) << "Failed to use objdump to get PC table; stderr is:";
for (const auto &line : absl::StrSplit(log_text, '\n')) {
- LOG(ERROR).NoPrefix() << line;
+ FUZZTEST_LOG(ERROR).NoPrefix() << line;
}
std::filesystem::remove(tmp_path);
std::filesystem::remove(stderr_path);
@@ -79,7 +77,7 @@
std::filesystem::remove(stderr_path);
PCTable pc_table;
std::ifstream in(std::string{tmp_path});
- CHECK(in.good()) << VV(tmp_path);
+ FUZZTEST_CHECK(in.good()) << VV(tmp_path);
bool saw_new_function = false;
// Read the objdump output, find lines that start a function
@@ -107,7 +105,7 @@
CFTable ReadCfTable(std::istream &in) {
const std::string input_string(std::istreambuf_iterator<char>(in), {});
const ByteArray cf_table_as_bytes(input_string.begin(), input_string.end());
- CHECK_EQ(cf_table_as_bytes.size() % sizeof(CFTable::value_type), 0);
+ FUZZTEST_CHECK_EQ(cf_table_as_bytes.size() % sizeof(CFTable::value_type), 0);
const size_t cf_table_size =
cf_table_as_bytes.size() / sizeof(CFTable::value_type);
const auto *cf_entries =
@@ -117,7 +115,7 @@
CFTable ReadCfTable(std::string_view file_path) {
std::string cf_table_contents;
- CHECK_OK(RemoteFileGetContents(file_path, cf_table_contents));
+ FUZZTEST_CHECK_OK(RemoteFileGetContents(file_path, cf_table_contents));
std::istringstream cf_table_stream(cf_table_contents);
return ReadCfTable(cf_table_stream);
}
@@ -135,7 +133,7 @@
// Use std::string; there is no std::stoul for std::string_view.
const std::vector<std::string> tokens =
absl::StrSplit(line, ' ', absl::SkipEmpty());
- CHECK_EQ(tokens.size(), 2) << VV(line);
+ FUZZTEST_CHECK_EQ(tokens.size(), 2) << VV(line);
result.push_back(DsoInfo{tokens[0], std::stoul(tokens[1])});
}
return result;
@@ -143,7 +141,7 @@
void ControlFlowGraph::InitializeControlFlowGraph(const CFTable &cf_table,
const PCTable &pc_table) {
- CHECK(!cf_table.empty());
+ FUZZTEST_CHECK(!cf_table.empty());
func_entries_.resize(pc_table.size());
reachability_.resize(pc_table.size());
@@ -162,14 +160,14 @@
// Record the list of successors
graph_[curr_pc] = std::move(successors);
// TODO(ussuri): Remove after debugging.
- VLOG(100) << "Added PC: " << curr_pc;
+ FUZZTEST_VLOG(100) << "Added PC: " << curr_pc;
// Iterate over callees.
while (cf_table[j]) {
++j;
}
++j; // Step over the delimiter.
- CHECK_LE(j, cf_table.size());
+ FUZZTEST_CHECK_LE(j, cf_table.size());
}
// Calculate cyclomatic complexity for all functions.
for (PCIndex i = 0; i < pc_table.size(); ++i) {
@@ -186,7 +184,7 @@
const std::vector<uintptr_t> &ControlFlowGraph::GetSuccessors(
uintptr_t basic_block) const {
auto it = graph_.find(basic_block);
- CHECK(it != graph_.end()) << VV(basic_block);
+ FUZZTEST_CHECK(it != graph_.end()) << VV(basic_block);
return it->second;
}
diff --git a/centipede/control_flow.h b/centipede/control_flow.h
index f401d84..2feb9fa 100644
--- a/centipede/control_flow.h
+++ b/centipede/control_flow.h
@@ -25,7 +25,6 @@
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
#include "./centipede/pc_info.h"
#include "./common/defs.h"
#include "./common/logging.h"
@@ -86,26 +85,27 @@
return graph_.contains(basic_block);
}
- // Returns cyclomatic complexity of function PC. CHECK-fails if it is not a
- // valid function PC.
+ // Returns cyclomatic complexity of function PC. FUZZTEST_CHECK-fails if it is
+ // not a valid function PC.
uint32_t GetCyclomaticComplexity(uintptr_t pc) const {
auto it = function_complexities_.find(pc);
- CHECK(it != function_complexities_.end());
+ FUZZTEST_CHECK(it != function_complexities_.end());
return it->second;
}
// Returns true if the given basic block is function entry.
bool BlockIsFunctionEntry(PCIndex pc_index) const {
- // TODO(ussuri): Change the following to use CHECK_LE(pc_index,
+ // TODO(ussuri): Change the following to use FUZZTEST_CHECK_LE(pc_index,
// func_entries_.size()) and have a death test.
return pc_index < func_entries_.size() ? func_entries_[pc_index] : false;
}
- // Returns the idx in pc_table associated with the PC, CHECK-fails if the PC
- // is not in the pc_table.
+ // Returns the idx in pc_table associated with the PC, FUZZTEST_CHECK-fails if
+ // the PC is not in the pc_table.
PCIndex GetPcIndex(uintptr_t pc) const {
auto it = pc_index_map_.find(pc);
- CHECK(it != pc_index_map_.end()) << VV(pc) << " is not in pc_table.";
+ FUZZTEST_CHECK(it != pc_index_map_.end())
+ << VV(pc) << " is not in pc_table.";
return it->second;
}
@@ -117,7 +117,7 @@
// The method is const, under the hood it uses a mutable data member.
// Thread-safe: can be called concurrently from multiple threads
const std::vector<uintptr_t> &LazyGetReachabilityForPc(uintptr_t pc) const {
- CHECK_EQ(reachability_.size(), pc_index_map_.size());
+ FUZZTEST_CHECK_EQ(reachability_.size(), pc_index_map_.size());
auto pc_index = GetPcIndex(pc);
std::call_once(*(reachability_[pc_index].once), [this, &pc, &pc_index]() {
reachability_[pc_index].reach = ComputeReachabilityForPc(pc);
diff --git a/centipede/control_flow_test.cc b/centipede/control_flow_test.cc
index 4d63e59..2d21d21 100644
--- a/centipede/control_flow_test.cc
+++ b/centipede/control_flow_test.cc
@@ -25,8 +25,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/container/flat_hash_map.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "./centipede/binary_info.h"
#include "./centipede/pc_info.h"
#include "./centipede/symbol_table.h"
@@ -87,17 +85,17 @@
EXPECT_TRUE(cfg.GetSuccessors(4).empty());
}
- CHECK_EQ(cfg.GetPcIndex(1), 0);
- CHECK_EQ(cfg.GetPcIndex(2), 1);
- CHECK_EQ(cfg.GetPcIndex(3), 2);
- CHECK_EQ(cfg.GetPcIndex(4), 3);
+ FUZZTEST_CHECK_EQ(cfg.GetPcIndex(1), 0);
+ FUZZTEST_CHECK_EQ(cfg.GetPcIndex(2), 1);
+ FUZZTEST_CHECK_EQ(cfg.GetPcIndex(3), 2);
+ FUZZTEST_CHECK_EQ(cfg.GetPcIndex(4), 3);
EXPECT_TRUE(cfg.BlockIsFunctionEntry(0));
EXPECT_FALSE(cfg.BlockIsFunctionEntry(1));
EXPECT_FALSE(cfg.BlockIsFunctionEntry(2));
EXPECT_FALSE(cfg.BlockIsFunctionEntry(3));
- CHECK_EQ(cfg.GetCyclomaticComplexity(1), 2);
+ FUZZTEST_CHECK_EQ(cfg.GetCyclomaticComplexity(1), 2);
}
TEST(CFTable, SerializesAndDeserializesCfTable) {
@@ -205,9 +203,9 @@
target_path, GetObjDumpPath(), GetLLVMSymbolizerPath(),
GetTestTempDir(test_info_->name()).string());
const auto &cf_table = binary_info.cf_table;
- LOG(INFO) << VV(target_path) << VV(tmp_path1) << VV(cf_table.size());
+ FUZZTEST_LOG(INFO) << VV(target_path) << VV(tmp_path1) << VV(cf_table.size());
if (cf_table.empty()) {
- LOG(INFO) << "__sancov_cfs is empty.";
+ FUZZTEST_LOG(INFO) << "__sancov_cfs is empty.";
// TODO(ussuri): This should be removed once OSS clang supports
// control-flow.
GTEST_SKIP();
@@ -215,7 +213,7 @@
ASSERT_FALSE(
std::filesystem::exists(tmp_path1.c_str())); // tmp_path1 was deleted.
- LOG(INFO) << VV(cf_table.size());
+ FUZZTEST_LOG(INFO) << VV(cf_table.size());
const auto &pc_table = binary_info.pc_table;
EXPECT_FALSE(binary_info.uses_legacy_trace_pc_instrumentation);
@@ -304,7 +302,7 @@
for (size_t i = 0; i < symbols.size(); i++) {
bool is_func_entry = pc_table[i].has_flag(PCInfo::kFuncEntry);
if (is_func_entry) {
- LOG(INFO) << symbols.full_description(i);
+ FUZZTEST_LOG(INFO) << symbols.full_description(i);
}
single_edge_func_num_edges += symbols.func(i) == "SingleEdgeFunc";
multi_edge_func_num_edges += symbols.func(i) == "MultiEdgeFunc";
diff --git a/centipede/corpus.cc b/centipede/corpus.cc
index 42f3e4b..16f4b5d 100644
--- a/centipede/corpus.cc
+++ b/centipede/corpus.cc
@@ -22,8 +22,6 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/substitute.h"
@@ -80,7 +78,7 @@
const CoverageFrontier &coverage_frontier,
size_t max_corpus_size, Rng &rng) {
// TODO(kcc): use coverage_frontier.
- CHECK(max_corpus_size);
+ FUZZTEST_CHECK(max_corpus_size);
if (records_.size() < 2UL) return 0;
// Recompute the weights.
size_t num_zero_weights = 0;
@@ -103,7 +101,7 @@
RemoveSubset(subset_to_remove, records_);
weighted_distribution_.RecomputeInternalState();
- CHECK(!records_.empty());
+ FUZZTEST_CHECK(!records_.empty());
// Features may have shrunk from CountUnseenAndPruneFrequentFeatures.
// Call shrink_to_fit for the features that survived the pruning.
@@ -119,9 +117,9 @@
const ExecutionMetadata &metadata, const FeatureSet &fs,
const CoverageFrontier &coverage_frontier) {
// TODO(kcc): use coverage_frontier.
- CHECK(!data.empty())
+ FUZZTEST_CHECK(!data.empty())
<< "Got request to add empty element to corpus: ignoring";
- CHECK_EQ(records_.size(), weighted_distribution_.size());
+ FUZZTEST_CHECK_EQ(records_.size(), weighted_distribution_.size());
records_.push_back({data, fv, metadata});
weighted_distribution_.AddWeight(ComputeWeight(fv, fs, coverage_frontier));
}
@@ -137,8 +135,8 @@
void Corpus::DumpStatsToFile(const FeatureSet &fs, std::string_view filepath,
std::string_view description) {
auto *file = ValueOrDie(RemoteFileOpen(filepath, "w"));
- CHECK(file != nullptr) << "Failed to open file: " << filepath;
- CHECK_OK(RemoteFileSetWriteBufferSize(file, 100UL * 1024 * 1024));
+ FUZZTEST_CHECK(file != nullptr) << "Failed to open file: " << filepath;
+ FUZZTEST_CHECK_OK(RemoteFileSetWriteBufferSize(file, 100UL * 1024 * 1024));
static constexpr std::string_view kHeaderStub = R"(# $0
{
"num_inputs": $1,
@@ -151,7 +149,7 @@
)";
const std::string header_str =
absl::Substitute(kHeaderStub, description, records_.size());
- CHECK_OK(RemoteFileAppend(file, header_str));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, header_str));
std::string before_record;
for (const auto &record : records_) {
std::vector<size_t> frequencies;
@@ -162,11 +160,11 @@
const std::string frequencies_str = absl::StrJoin(frequencies, ", ");
const std::string record_str = absl::Substitute(
kRecordStub, before_record, record.data.size(), frequencies_str);
- CHECK_OK(RemoteFileAppend(file, record_str));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, record_str));
before_record = ",";
}
- CHECK_OK(RemoteFileAppend(file, std::string{kFooter}));
- CHECK_OK(RemoteFileClose(file));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, std::string{kFooter}));
+ FUZZTEST_CHECK_OK(RemoteFileClose(file));
}
std::string Corpus::MemoryUsageString() const {
@@ -184,7 +182,7 @@
//------------------------------------------------------------------------------
void WeightedDistribution::AddWeight(uint64_t weight) {
- CHECK_EQ(weights_.size(), cumulative_weights_.size());
+ FUZZTEST_CHECK_EQ(weights_.size(), cumulative_weights_.size());
weights_.push_back(weight);
if (cumulative_weights_.empty()) {
cumulative_weights_.push_back(weight);
@@ -194,7 +192,7 @@
}
void WeightedDistribution::ChangeWeight(size_t idx, uint64_t new_weight) {
- CHECK_LT(idx, size());
+ FUZZTEST_CHECK_LT(idx, size());
weights_[idx] = new_weight;
cumulative_weights_valid_ = false;
}
@@ -212,15 +210,15 @@
__attribute__((noinline)) // to see it in profile.
size_t
WeightedDistribution::RandomIndex(size_t random) const {
- CHECK(!weights_.empty());
- CHECK(cumulative_weights_valid_);
+ FUZZTEST_CHECK(!weights_.empty());
+ FUZZTEST_CHECK(cumulative_weights_valid_);
uint64_t sum_of_all_weights = cumulative_weights_.back();
if (sum_of_all_weights == 0)
return random % size(); // can't do much else here.
random = random % sum_of_all_weights;
auto it = std::upper_bound(cumulative_weights_.begin(),
cumulative_weights_.end(), random);
- CHECK(it != cumulative_weights_.end());
+ FUZZTEST_CHECK(it != cumulative_weights_.end());
return it - cumulative_weights_.begin();
}
diff --git a/centipede/corpus.h b/centipede/corpus.h
index e297f06..dc6bb00 100644
--- a/centipede/corpus.h
+++ b/centipede/corpus.h
@@ -23,7 +23,6 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
#include "./centipede/binary_info.h"
#include "./centipede/execution_metadata.h"
#include "./centipede/feature.h"
@@ -180,7 +179,7 @@
// Returns true iff `idx` belongs to the frontier.
bool PcIndexIsFrontier(size_t idx) const {
- CHECK_LT(idx, MaxPcIndex());
+ FUZZTEST_CHECK_LT(idx, MaxPcIndex());
return frontier_[idx];
}
@@ -189,7 +188,7 @@
// Returns the frontier weight of pc at `idx`, weight of a non-frontier is 0.
uint64_t FrontierWeight(size_t idx) const {
- CHECK_LT(idx, MaxPcIndex());
+ FUZZTEST_CHECK_LT(idx, MaxPcIndex());
return frontier_weight_[idx];
}
diff --git a/centipede/corpus_io.cc b/centipede/corpus_io.cc
index 23e63c3..cdc6de9 100644
--- a/centipede/corpus_io.cc
+++ b/centipede/corpus_io.cc
@@ -22,8 +22,6 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
@@ -46,13 +44,13 @@
!features_path.empty() && RemotePathExists(features_path);
if (!good_corpus_path) {
- LOG(WARNING) << "Corpus file path empty or not found - returning: "
- << corpus_path;
+ FUZZTEST_LOG(WARNING) << "Corpus file path empty or not found - returning: "
+ << corpus_path;
return;
}
RPROF_THIS_FUNCTION_WITH_TIMELAPSE( //
- /*enable=*/ABSL_VLOG_IS_ON(10), //
+ /*enable=*/FUZZTEST_VLOG_IS_ON(10), //
/*timelapse_interval=*/absl::Seconds(30), //
/*also_log_timelapses=*/false);
@@ -64,7 +62,7 @@
std::multimap<std::string /*hash*/, ByteArray /*input*/> hash_to_input;
// Read inputs from the corpus file into `hash_to_input`.
auto corpus_reader = DefaultBlobFileReaderFactory();
- CHECK_OK(corpus_reader->Open(corpus_path)) << VV(corpus_path);
+ FUZZTEST_CHECK_OK(corpus_reader->Open(corpus_path)) << VV(corpus_path);
ByteSpan blob;
while (corpus_reader->Read(blob).ok()) {
std::string hash = Hash(blob);
@@ -82,15 +80,17 @@
// If the features file is not passed or doesn't exist, simply ignore it.
if (!good_features_path) {
- LOG(WARNING) << "Features file path empty or not found - ignoring: "
- << features_path;
+ FUZZTEST_LOG(WARNING)
+ << "Features file path empty or not found - ignoring: "
+ << features_path;
} else {
// Read features from the features file. For each feature, find a matching
// input in `hash_to_input`, call `callback` for the pair, and remove the
// entry from `hash_to_input`. In the end, `hash_to_input` will contain
// only inputs without matching features.
auto features_reader = DefaultBlobFileReaderFactory();
- CHECK_OK(features_reader->Open(features_path)) << VV(features_path);
+ FUZZTEST_CHECK_OK(features_reader->Open(features_path))
+ << VV(features_path);
ByteSpan hash_and_features;
while (features_reader->Read(hash_and_features).ok()) {
// Every valid feature record must contain the hash at the end.
@@ -127,7 +127,7 @@
RPROF_SNAPSHOT("Reported inputs with no matching features");
- VLOG(1) //
+ FUZZTEST_VLOG(1) //
<< "Finished shard reading:\n"
<< "Corpus path : " << corpus_path << "\n"
<< "Features path : " << features_path << "\n"
@@ -140,17 +140,17 @@
void ExportCorpus(absl::Span<const std::string> sharded_file_paths,
std::string_view out_dir) {
- LOG(INFO) << "Exporting corpus to " << out_dir;
+ FUZZTEST_LOG(INFO) << "Exporting corpus to " << out_dir;
for (const std::string &file : sharded_file_paths) {
auto reader = DefaultBlobFileReaderFactory();
- CHECK_OK(reader->Open(file)) << VV(file);
+ FUZZTEST_CHECK_OK(reader->Open(file)) << VV(file);
ByteSpan blob;
size_t num_read = 0;
while (reader->Read(blob).ok()) {
++num_read;
WriteToRemoteHashedFileInDir(out_dir, blob);
}
- LOG(INFO) << "Exported " << num_read << " inputs from " << file;
+ FUZZTEST_LOG(INFO) << "Exported " << num_read << " inputs from " << file;
}
}
diff --git a/centipede/corpus_io_test.cc b/centipede/corpus_io_test.cc
index a97572d..f368a31 100644
--- a/centipede/corpus_io_test.cc
+++ b/centipede/corpus_io_test.cc
@@ -22,7 +22,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/log/check.h"
#include "absl/types/span.h"
#include "./centipede/corpus.h"
#include "./centipede/feature.h"
@@ -30,6 +29,7 @@
#include "./centipede/workdir.h"
#include "./common/blob_file.h"
#include "./common/defs.h"
+#include "./common/logging.h"
#include "./common/test_util.h"
namespace fuzztest::internal {
@@ -40,11 +40,11 @@
void WriteBlobsToFile(std::string_view blob_file_path,
absl::Span<const ByteArray> blobs) {
auto writer = DefaultBlobFileWriterFactory();
- CHECK_OK(writer->Open(blob_file_path, "w"));
+ FUZZTEST_CHECK_OK(writer->Open(blob_file_path, "w"));
for (const ByteArray& blob : blobs) {
- CHECK_OK(writer->Write(blob));
+ FUZZTEST_CHECK_OK(writer->Write(blob));
}
- CHECK_OK(writer->Close());
+ FUZZTEST_CHECK_OK(writer->Close());
}
std::vector<ByteArray> ReadInputsFromFiles(std::string_view dir) {
@@ -109,7 +109,7 @@
TEST(ExportCorpusTest, ExportsCorpusToIndividualFiles) {
const std::filesystem::path temp_dir = GetTestTempDir(test_info_->name());
const std::filesystem::path out_dir = temp_dir / "out_dir";
- CHECK(std::filesystem::create_directory(out_dir));
+ FUZZTEST_CHECK(std::filesystem::create_directory(out_dir));
const WorkDir workdir{temp_dir.c_str(), "fake_binary_name",
"fake_binary_hash", /*my_shard_index=*/0};
const auto corpus_file_paths = workdir.CorpusFilePaths();
diff --git a/centipede/corpus_test.cc b/centipede/corpus_test.cc
index 13b576c..8975571 100644
--- a/centipede/corpus_test.cc
+++ b/centipede/corpus_test.cc
@@ -135,7 +135,7 @@
EXPECT_EQ(corpus.Prune(fs, coverage_frontier, 1, rng), 1);
EXPECT_EQ(corpus.NumActive(), 1);
EXPECT_DEATH(corpus.Prune(fs, coverage_frontier, 0, rng),
- "max_corpus_size"); // CHECK-fail.
+ "max_corpus_size"); // FUZZTEST_CHECK-fail.
EXPECT_EQ(corpus.NumTotal(), 6);
}
diff --git a/centipede/coverage.cc b/centipede/coverage.cc
index 28373ea..a5a96e2 100644
--- a/centipede/coverage.cc
+++ b/centipede/coverage.cc
@@ -25,13 +25,13 @@
#include <vector>
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
#include "absl/strings/str_split.h"
#include "absl/synchronization/mutex.h"
#include "./centipede/control_flow.h"
#include "./centipede/feature.h"
#include "./centipede/pc_info.h"
#include "./centipede/symbol_table.h"
+#include "./common/logging.h"
#include "./common/remote_file.h"
#include "./common/status_macros.h"
@@ -41,7 +41,7 @@
: func_entries_(pc_table.size()),
fully_covered_funcs_vec_(pc_table.size()),
covered_pcs_vec_(pc_table.size()) {
- CHECK_LT(pc_table.size(), std::numeric_limits<PCIndex>::max());
+ FUZZTEST_CHECK_LT(pc_table.size(), std::numeric_limits<PCIndex>::max());
absl::flat_hash_set<PCIndex> covered_pcs(pci_vec.begin(), pci_vec.end());
// Iterate though all the pc_table entries.
// The first one is some function's kFuncEntry.
@@ -51,7 +51,7 @@
// to fully_covered_funcs or uncovered_funcs correspondingly.
// For all others add them to partially_covered_funcs.
for (size_t this_func = 0; this_func < pc_table.size();) {
- CHECK(pc_table[this_func].has_flag(PCInfo::kFuncEntry));
+ FUZZTEST_CHECK(pc_table[this_func].has_flag(PCInfo::kFuncEntry));
func_entries_[this_func] = true;
// Find next entry.
size_t next_func = this_func + 1;
@@ -78,9 +78,10 @@
} else if (pcf.covered.empty()) {
uncovered_funcs.push_back(this_func);
} else {
- CHECK(!pcf.covered.empty());
- CHECK(!pcf.uncovered.empty());
- CHECK_EQ(pcf.covered.size() + pcf.uncovered.size(), num_func_pcs);
+ FUZZTEST_CHECK(!pcf.covered.empty());
+ FUZZTEST_CHECK(!pcf.uncovered.empty());
+ FUZZTEST_CHECK_EQ(pcf.covered.size() + pcf.uncovered.size(),
+ num_func_pcs);
partially_covered_funcs.push_back(pcf);
}
// Move to the next function.
@@ -92,46 +93,51 @@
std::string_view filepath,
std::string_view description) {
auto *file = ValueOrDie(RemoteFileOpen(filepath, "w"));
- CHECK(file != nullptr) << "Failed to open file: " << filepath;
- CHECK_OK(RemoteFileSetWriteBufferSize(file, 100UL * 1024 * 1024));
+ FUZZTEST_CHECK(file != nullptr) << "Failed to open file: " << filepath;
+ FUZZTEST_CHECK_OK(RemoteFileSetWriteBufferSize(file, 100UL * 1024 * 1024));
if (!description.empty()) {
- CHECK_OK(RemoteFileAppend(file, "# "));
- CHECK_OK(RemoteFileAppend(file, std::string{description}));
- CHECK_OK(RemoteFileAppend(file, ":\n\n"));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "# "));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, std::string{description}));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, ":\n\n"));
}
// Print symbolized function names for all covered functions.
for (auto pc_index : fully_covered_funcs) {
- CHECK_OK(RemoteFileAppend(file, "FULL: "));
- CHECK_OK(RemoteFileAppend(file, symbols.full_description(pc_index)));
- CHECK_OK(RemoteFileAppend(file, "\n"));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "FULL: "));
+ FUZZTEST_CHECK_OK(
+ RemoteFileAppend(file, symbols.full_description(pc_index)));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "\n"));
}
- CHECK_OK(RemoteFileFlush(file));
+ FUZZTEST_CHECK_OK(RemoteFileFlush(file));
// Same for uncovered functions.
for (auto pc_index : uncovered_funcs) {
- CHECK_OK(RemoteFileAppend(file, "NONE: "));
- CHECK_OK(RemoteFileAppend(file, symbols.full_description(pc_index)));
- CHECK_OK(RemoteFileAppend(file, "\n"));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "NONE: "));
+ FUZZTEST_CHECK_OK(
+ RemoteFileAppend(file, symbols.full_description(pc_index)));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "\n"));
}
- CHECK_OK(RemoteFileFlush(file));
+ FUZZTEST_CHECK_OK(RemoteFileFlush(file));
// For every partially covered function, first print its name,
// then print its covered edges, then uncovered edges.
for (auto &pcf : partially_covered_funcs) {
- CHECK_OK(RemoteFileAppend(file, "PARTIAL: "));
- CHECK_OK(RemoteFileAppend(file, symbols.full_description(pcf.covered[0])));
- CHECK_OK(RemoteFileAppend(file, "\n"));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "PARTIAL: "));
+ FUZZTEST_CHECK_OK(
+ RemoteFileAppend(file, symbols.full_description(pcf.covered[0])));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "\n"));
for (auto pc_index : pcf.covered) {
- CHECK_OK(RemoteFileAppend(file, " + "));
- CHECK_OK(RemoteFileAppend(file, symbols.full_description(pc_index)));
- CHECK_OK(RemoteFileAppend(file, "\n"));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, " + "));
+ FUZZTEST_CHECK_OK(
+ RemoteFileAppend(file, symbols.full_description(pc_index)));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "\n"));
}
for (auto pc_index : pcf.uncovered) {
- CHECK_OK(RemoteFileAppend(file, " - "));
- CHECK_OK(RemoteFileAppend(file, symbols.full_description(pc_index)));
- CHECK_OK(RemoteFileAppend(file, "\n"));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, " - "));
+ FUZZTEST_CHECK_OK(
+ RemoteFileAppend(file, symbols.full_description(pc_index)));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file, "\n"));
}
}
- CHECK_OK(RemoteFileFlush(file));
- CHECK_OK(RemoteFileClose(file));
+ FUZZTEST_CHECK_OK(RemoteFileFlush(file));
+ FUZZTEST_CHECK_OK(RemoteFileClose(file));
}
std::string CoverageLogger::ObserveAndDescribeIfNew(PCIndex pc_index) {
@@ -215,7 +221,7 @@
auto cyclomatic_comp = cfg.GetCyclomaticComplexity(callee);
// Determine knob based on callee coverage kind.
auto callee_idx = cfg.GetPcIndex(callee);
- CHECK(cfg.BlockIsFunctionEntry(callee_idx));
+ FUZZTEST_CHECK(cfg.BlockIsFunctionEntry(callee_idx));
auto coverage_multiplier = SelectMultiplierByCoverageKind(
uncovered_knob, partially_covered_knob, fully_covered_knob, callee_idx,
coverage);
diff --git a/centipede/coverage.h b/centipede/coverage.h
index 7e681c0..340027c 100644
--- a/centipede/coverage.h
+++ b/centipede/coverage.h
@@ -26,7 +26,6 @@
#include "absl/base/thread_annotations.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
#include "absl/synchronization/mutex.h"
#include "./centipede/control_flow.h"
#include "./centipede/feature.h"
@@ -55,7 +54,7 @@
// Returns true if the function is fully covered. pc_index is for a function
// entry.
bool FunctionIsFullyCovered(PCIndex pc_index) const {
- CHECK(func_entries_[pc_index]);
+ FUZZTEST_CHECK(func_entries_[pc_index]);
return fully_covered_funcs_vec_[pc_index];
}
// Returns true if the given basic block is covered. pc_index is for any BB.
diff --git a/centipede/distill.cc b/centipede/distill.cc
index 1b16a2b..74ecf67 100644
--- a/centipede/distill.cc
+++ b/centipede/distill.cc
@@ -30,8 +30,6 @@
#include "absl/base/thread_annotations.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/synchronization/mutex.h"
@@ -136,9 +134,10 @@
CorpusEltVec ReadShard(size_t shard_idx) {
const auto corpus_path = workdir_.CorpusFilePaths().Shard(shard_idx);
const auto features_path = workdir_.FeaturesFilePaths().Shard(shard_idx);
- VLOG(1) << log_prefix_ << "reading input shard " << shard_idx << ":\n"
- << VV(corpus_path) << "\n"
- << VV(features_path);
+ FUZZTEST_VLOG(1) << log_prefix_ << "reading input shard " << shard_idx
+ << ":\n"
+ << VV(corpus_path) << "\n"
+ << VV(features_path);
CorpusEltVec elts;
// Read elements from the current shard.
fuzztest::internal::ReadShard( //
@@ -171,8 +170,9 @@
features_path_{workdir_.DistilledFeaturesFilePaths().MyShard()},
corpus_writer_{DefaultBlobFileWriterFactory()},
feature_writer_{DefaultBlobFileWriterFactory()} {
- CHECK_OK(corpus_writer_->Open(corpus_path_, append ? "a" : "w"));
- CHECK_OK(feature_writer_->Open(features_path_, append ? "a" : "w"));
+ FUZZTEST_CHECK_OK(corpus_writer_->Open(corpus_path_, append ? "a" : "w"));
+ FUZZTEST_CHECK_OK(
+ feature_writer_->Open(features_path_, append ? "a" : "w"));
}
virtual ~CorpusShardWriter() = default;
@@ -184,10 +184,10 @@
void WriteBatch(CorpusEltVec elts) {
absl::MutexLock lock(&mu_);
- VLOG(1) << log_prefix_ << "writing " << elts.size()
- << " elements to output shard:\n"
- << VV(corpus_path_) << "\n"
- << VV(features_path_);
+ FUZZTEST_VLOG(1) << log_prefix_ << "writing " << elts.size()
+ << " elements to output shard:\n"
+ << VV(corpus_path_) << "\n"
+ << VV(features_path_);
for (auto &elt : elts) {
WriteEltImpl(std::move(elt));
}
@@ -214,8 +214,9 @@
const auto preprocessed_elt = PreprocessElt(std::move(elt));
if (preprocessed_elt.has_value()) {
// Append to the distilled corpus and features files.
- CHECK_OK(corpus_writer_->Write(preprocessed_elt->input));
- CHECK_OK(feature_writer_->Write(preprocessed_elt->PackedFeatures()));
+ FUZZTEST_CHECK_OK(corpus_writer_->Write(preprocessed_elt->input));
+ FUZZTEST_CHECK_OK(
+ feature_writer_->Write(preprocessed_elt->PackedFeatures()));
++stats_.num_written_elts;
}
}
@@ -337,9 +338,9 @@
DistillingInputFilter &input_filter, //
ResourcePool<RUsageMemory> &ram_pool, //
int parallelism) {
- LOG(INFO) << LogPrefix(env) << "Distilling to output shard "
- << env.my_shard_index << "; input shard indices:\n"
- << absl::StrJoin(shard_indices, ", ");
+ FUZZTEST_LOG(INFO) << LogPrefix(env) << "Distilling to output shard "
+ << env.my_shard_index << "; input shard indices:\n"
+ << absl::StrJoin(shard_indices, ", ");
// Read and write the shards in parallel, but gate reading of each on the
// availability of free RAM to keep the peak RAM usage under control.
@@ -360,7 +361,7 @@
/*mem_rss=*/reader.EstimateRamFootprint(shard_idx)},
/*timeout=*/kRamLeaseTimeout,
});
- CHECK_OK(ram_lease.status());
+ FUZZTEST_CHECK_OK(ram_lease.status());
CorpusEltVec shard_elts = reader.ReadShard(shard_idx);
// Reverse the order of elements. The intuition is as follows:
@@ -371,23 +372,25 @@
std::reverse(shard_elts.begin(), shard_elts.end());
writer.WriteBatch(std::move(shard_elts));
const CorpusShardWriter::Stats shard_stats = writer.GetStats();
- LOG(INFO) << LogPrefix(env)
- << "batches: " << shard_stats.num_written_batches << "/"
- << num_shards << " inputs: " << shard_stats.num_total_elts
- << " written: " << shard_stats.num_written_elts;
+ FUZZTEST_LOG(INFO) << LogPrefix(env)
+ << "batches: " << shard_stats.num_written_batches
+ << "/" << num_shards
+ << " inputs: " << shard_stats.num_total_elts
+ << " written: " << shard_stats.num_written_elts;
});
}
} // The threads join here.
- LOG(INFO) << LogPrefix(env) << "Done distilling to output shard "
- << env.my_shard_index;
+ FUZZTEST_LOG(INFO) << LogPrefix(env) << "Done distilling to output shard "
+ << env.my_shard_index;
}
int Distill(const Environment &env, const DistillOptions &opts) {
- RPROF_THIS_FUNCTION_WITH_TIMELAPSE( //
- /*enable=*/ABSL_VLOG_IS_ON(1), //
- /*timelapse_interval=*/absl::Seconds(ABSL_VLOG_IS_ON(2) ? 10 : 60), //
- /*also_log_timelapses=*/ABSL_VLOG_IS_ON(10));
+ RPROF_THIS_FUNCTION_WITH_TIMELAPSE( //
+ /*enable=*/FUZZTEST_VLOG_IS_ON(1), //
+ /*timelapse_interval=*/
+ absl::Seconds(FUZZTEST_VLOG_IS_ON(2) ? 10 : 60), //
+ /*also_log_timelapses=*/FUZZTEST_VLOG_IS_ON(10));
// Prepare the per-thread envs.
std::vector<Environment> envs_per_thread(env.num_threads, env);
@@ -423,16 +426,16 @@
PeriodicAction progress_logger{
[&input_filter]() {
const auto stats = input_filter.GetStats();
- LOG(INFO) << LogPrefix() << stats.coverage_str
- << " inputs: " << stats.num_total_elts
- << " unique: " << stats.num_byte_unique_elts
- << " distilled: " << stats.num_feature_unique_elts;
+ FUZZTEST_LOG(INFO) << LogPrefix() << stats.coverage_str
+ << " inputs: " << stats.num_total_elts
+ << " unique: " << stats.num_byte_unique_elts
+ << " distilled: " << stats.num_feature_unique_elts;
},
// Seeing 0's at the beginning is not interesting, unless debugging.
// Likewise, increase the frequency --v >= 1 to aid debugging.
PeriodicAction::ConstDelayConstInterval(
- absl::Seconds(ABSL_VLOG_IS_ON(1) ? 0 : 60),
- absl::Seconds(ABSL_VLOG_IS_ON(1) ? 10 : 60)),
+ absl::Seconds(FUZZTEST_VLOG_IS_ON(1) ? 0 : 60),
+ absl::Seconds(FUZZTEST_VLOG_IS_ON(1) ? 10 : 60)),
};
// The RAM pool shared between all the `DistillToOneOutputShard()` threads.
ResourcePool ram_pool{kRamQuota};
diff --git a/centipede/distill_test.cc b/centipede/distill_test.cc
index 2d88010..047f67f 100644
--- a/centipede/distill_test.cc
+++ b/centipede/distill_test.cc
@@ -25,7 +25,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/flags/reflection.h"
-#include "absl/log/check.h"
#include "./centipede/corpus_io.h"
#include "./centipede/environment.h"
#include "./centipede/feature.h"
@@ -33,6 +32,7 @@
#include "./centipede/workdir.h"
#include "./common/blob_file.h"
#include "./common/defs.h"
+#include "./common/logging.h"
#include "./common/test_util.h"
namespace fuzztest::internal {
@@ -70,10 +70,10 @@
const auto features_path = wd.FeaturesFilePaths().Shard(shard_index);
const auto corpus_appender = DefaultBlobFileWriterFactory(env.riegeli);
const auto features_appender = DefaultBlobFileWriterFactory(env.riegeli);
- CHECK_OK(corpus_appender->Open(corpus_path, "a"));
- CHECK_OK(features_appender->Open(features_path, "a"));
- CHECK_OK(corpus_appender->Write(record.input));
- CHECK_OK(features_appender->Write(
+ FUZZTEST_CHECK_OK(corpus_appender->Open(corpus_path, "a"));
+ FUZZTEST_CHECK_OK(features_appender->Open(features_path, "a"));
+ FUZZTEST_CHECK_OK(corpus_appender->Write(record.input));
+ FUZZTEST_CHECK_OK(features_appender->Write(
PackFeaturesAndHash(record.input, record.feature_vec)));
}
diff --git a/centipede/environment.cc b/centipede/environment.cc
index 443a611..16da62c 100644
--- a/centipede/environment.cc
+++ b/centipede/environment.cc
@@ -27,8 +27,6 @@
#include "absl/base/no_destructor.h"
#include "absl/container/flat_hash_map.h"
#include "absl/flags/marshalling.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
@@ -46,7 +44,7 @@
namespace {
size_t ComputeTimeoutPerBatch(size_t timeout_per_input, size_t batch_size) {
- CHECK_GT(batch_size, 0);
+ FUZZTEST_CHECK_GT(batch_size, 0);
// NOTE: If `timeout_per_input` == 0, leave `timeout_per_batch` at 0 too:
// the implementation interprets both as "no limit".
if (timeout_per_input == 0) return 0;
@@ -117,18 +115,19 @@
// Returns true if `value` is one of "1", "true".
// Returns true if `value` is one of "0", "false".
-// CHECK-fails otherwise.
+// FUZZTEST_CHECK-fails otherwise.
static bool GetBoolFlag(std::string_view value) {
if (value == "0" || value == "false") return false;
- CHECK(value == "1" || value == "true") << value;
+ FUZZTEST_CHECK(value == "1" || value == "true") << value;
return true;
}
-// Returns `value` as a size_t, CHECK-fails on parse error.
+// Returns `value` as a size_t, FUZZTEST_CHECK-fails on parse error.
static size_t GetIntFlag(std::string_view value) {
size_t result{};
- CHECK(std::from_chars(value.data(), value.data() + value.size(), result).ec ==
- std::errc())
+ FUZZTEST_CHECK(
+ std::from_chars(value.data(), value.data() + value.size(), result).ec ==
+ std::errc())
<< value;
return result;
}
@@ -169,7 +168,8 @@
return;
}
- LOG(FATAL) << "Unknown flag for experiment: " << name << "=" << value;
+ FUZZTEST_LOG(FATAL) << "Unknown flag for experiment: " << name << "="
+ << value;
}
void Environment::UpdateForExperiment() {
@@ -183,7 +183,7 @@
std::vector<Experiment> experiments;
for (auto flag : absl::StrSplit(this->experiment, ':', absl::SkipEmpty())) {
std::vector<std::string> flag_and_value = absl::StrSplit(flag, '=');
- CHECK_EQ(flag_and_value.size(), 2) << flag;
+ FUZZTEST_CHECK_EQ(flag_and_value.size(), 2) << flag;
experiments.emplace_back(
Experiment{flag_and_value[0], absl::StrSplit(flag_and_value[1], ',')});
}
@@ -191,15 +191,15 @@
// Count the number of flag combinations.
size_t num_combinations = 1;
for (const auto &exp : experiments) {
- CHECK_NE(exp.flag_values.size(), 0) << exp.flag_name;
+ FUZZTEST_CHECK_NE(exp.flag_values.size(), 0) << exp.flag_name;
num_combinations *= exp.flag_values.size();
}
- CHECK_GT(num_combinations, 0);
- CHECK_EQ(num_threads % num_combinations, 0)
+ FUZZTEST_CHECK_GT(num_combinations, 0);
+ FUZZTEST_CHECK_EQ(num_threads % num_combinations, 0)
<< VV(num_threads) << VV(num_combinations);
// Update the flags for the current shard and compute experiment_name.
- CHECK_LT(my_shard_index, num_threads);
+ FUZZTEST_CHECK_LT(my_shard_index, num_threads);
size_t my_combination_num = my_shard_index % num_combinations;
experiment_name.clear();
experiment_flags.clear();
@@ -228,14 +228,14 @@
if (knobs_file_path.empty()) return;
ByteArray knob_bytes;
auto *f = ValueOrDie(RemoteFileOpen(knobs_file, "r"));
- CHECK(f) << "Failed to open remote file " << knobs_file;
- CHECK_OK(RemoteFileRead(f, knob_bytes));
- CHECK_OK(RemoteFileClose(f));
- VLOG(1) << "Knobs: " << knob_bytes.size() << " knobs read from "
- << knobs_file;
+ FUZZTEST_CHECK(f) << "Failed to open remote file " << knobs_file;
+ FUZZTEST_CHECK_OK(RemoteFileRead(f, knob_bytes));
+ FUZZTEST_CHECK_OK(RemoteFileClose(f));
+ FUZZTEST_VLOG(1) << "Knobs: " << knob_bytes.size() << " knobs read from "
+ << knobs_file;
knobs.Set(knob_bytes);
knobs.ForEachKnob([](std::string_view name, Knobs::value_type value) {
- VLOG(1) << "knob " << name << ": " << static_cast<uint32_t>(value);
+ FUZZTEST_VLOG(1) << "knob " << name << ": " << static_cast<uint32_t>(value);
});
}
@@ -248,11 +248,11 @@
// enough.
if (max_num_crash_reports == Default().max_num_crash_reports) {
max_num_crash_reports = 20;
- LOG(INFO) << "Overriding the default max_num_crash_reports to "
- << max_num_crash_reports << " for FuzzTest.";
+ FUZZTEST_LOG(INFO) << "Overriding the default max_num_crash_reports to "
+ << max_num_crash_reports << " for FuzzTest.";
}
if (config.jobs != 0) {
- CHECK(j == Default().j || j == config.jobs)
+ FUZZTEST_CHECK(j == Default().j || j == config.jobs)
<< "Value for --j is inconsistent with the value for jobs in the "
"target binary:"
<< VV(j) << VV(config.jobs);
@@ -266,7 +266,7 @@
[&](absl::Duration duration, absl::string_view duration_name) -> size_t {
if (duration == absl::InfiniteDuration()) return 0;
// Centipede's time-related fields are in seconds, so we need at least 1s.
- CHECK_GE(duration, absl::Seconds(1))
+ FUZZTEST_CHECK_GE(duration, absl::Seconds(1))
<< duration_name << " must not be less than one second";
return static_cast<size_t>(absl::ToInt64Seconds(duration));
};
@@ -274,9 +274,9 @@
// Update `timeout_per_input` and consequently `timeout_per_batch`.
const size_t time_limit_per_input_sec =
convert_to_seconds(config.time_limit_per_input, "Time limit per input");
- CHECK(timeout_per_input == 0 ||
- timeout_per_input == Default().timeout_per_input ||
- timeout_per_input == time_limit_per_input_sec)
+ FUZZTEST_CHECK(timeout_per_input == 0 ||
+ timeout_per_input == Default().timeout_per_input ||
+ timeout_per_input == time_limit_per_input_sec)
<< "Value for --timeout_per_input is inconsistent with the value for "
"time_limit_per_input in the target binary:"
<< VV(timeout_per_input) << VV(config.time_limit_per_input);
@@ -300,8 +300,8 @@
constexpr auto bytes_to_mb = [](size_t bytes) {
return bytes == 0 ? 0 : (bytes - 1) / 1024 / 1024 + 1;
};
- CHECK(rss_limit_mb == Default().rss_limit_mb ||
- rss_limit_mb == bytes_to_mb(config.rss_limit))
+ FUZZTEST_CHECK(rss_limit_mb == Default().rss_limit_mb ||
+ rss_limit_mb == bytes_to_mb(config.rss_limit))
<< "Value for --rss_limit_mb is inconsistent with the value for "
"rss_limit in the target binary:"
<< VV(rss_limit_mb) << VV(config.rss_limit);
@@ -311,8 +311,8 @@
constexpr auto bytes_to_kb = [](size_t bytes) {
return bytes == 0 ? 0 : (bytes - 1) / 1024 + 1;
};
- CHECK(stack_limit_kb == Default().stack_limit_kb ||
- stack_limit_kb == bytes_to_kb(config.stack_limit))
+ FUZZTEST_CHECK(stack_limit_kb == Default().stack_limit_kb ||
+ stack_limit_kb == bytes_to_kb(config.stack_limit))
<< "Value for --stack_limit_kb is inconsistent with the value for "
"stack_limit in the target binary:"
<< VV(stack_limit_kb) << VV(config.stack_limit);
@@ -327,8 +327,8 @@
void Environment::UpdateTimeoutPerBatchIfEqualTo(size_t val) {
if (timeout_per_batch != val) return;
timeout_per_batch = ComputeTimeoutPerBatch(timeout_per_input, batch_size);
- VLOG(1) << "--timeout_per_batch auto-computed: " << timeout_per_batch
- << " sec (see --help for details)";
+ FUZZTEST_VLOG(1) << "--timeout_per_batch auto-computed: " << timeout_per_batch
+ << " sec (see --help for details)";
}
void Environment::UpdateBinaryHashIfEmpty() {
diff --git a/centipede/environment.h b/centipede/environment.h
index aeaeb44..4871fc8 100644
--- a/centipede/environment.h
+++ b/centipede/environment.h
@@ -56,7 +56,7 @@
Knobs knobs; // Read from a file by `ReadKnobsFileIfSpecified`, see knobs.h.
// Defines internal logging level. Set to zero to reduce logging in tests.
- // TODO(ussuri): Retire in favor of VLOGs?
+ // TODO(ussuri): Retire in favor of FUZZTEST_VLOGs?
size_t log_level = 1;
// Path to a file with PCs. This file is created and the field is set in
@@ -103,7 +103,7 @@
// shard 5 will have {foo=2,bar=30},
// and so on.
//
- // CHECK-fails if the `--experiment` flag is not well-formed,
+ // FUZZTEST_CHECK-fails if the `--experiment` flag is not well-formed,
// or if num_threads is not a multiple of the number of flag combinations
// (which is 6 in this example).
//
@@ -113,7 +113,7 @@
// which means "value #0 is used for foo and value #1 is used for bar".
void UpdateForExperiment();
- // Sets flag 'name' to `value` for an experiment. CHECK-fails on
+ // Sets flag 'name' to `value` for an experiment. FUZZTEST_CHECK-fails on
// invalid name/value combination. Used in `UpdateForExperiment()`.
void SetFlagForExperiment(std::string_view name, std::string_view value);
@@ -121,9 +121,9 @@
// Reads `knobs` from `knobs_file`. Does nothing if the `knobs_file` is empty.
void ReadKnobsFileIfSpecified();
- // Updates `this` with `config` obtained from the target binary. CHECK-fails
- // if the fields are non-default and inconsistent with the corresponding
- // values in `config`.
+ // Updates `this` with `config` obtained from the target binary.
+ // FUZZTEST_CHECK-fails if the fields are non-default and inconsistent with
+ // the corresponding values in `config`.
void UpdateWithTargetConfig(const fuzztest::internal::Configuration& config);
// If `timeout_per_batch` is `val`, computes it as a function of
// `timeout_per_input` and `batch_size` and updates it. Otherwise, leaves it
diff --git a/centipede/environment_flags.cc b/centipede/environment_flags.cc
index 72b3d1c..8db3381 100644
--- a/centipede/environment_flags.cc
+++ b/centipede/environment_flags.cc
@@ -20,8 +20,6 @@
#include <vector>
#include "absl/flags/flag.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "absl/strings/str_split.h"
#include "absl/time/clock.h"
@@ -64,7 +62,7 @@
absl::Time GetStopAtTime(absl::Time stop_at, absl::Duration stop_after) {
const bool stop_at_is_non_default = stop_at != absl::InfiniteFuture();
const bool stop_after_is_non_default = stop_after != absl::InfiniteDuration();
- CHECK_LE(stop_at_is_non_default + stop_after_is_non_default, 1)
+ FUZZTEST_CHECK_LE(stop_at_is_non_default + stop_after_is_non_default, 1)
<< "At most one of --stop_at and --stop_after should be specified, "
"including via --config file: "
<< VV(stop_at) << VV(stop_after);
@@ -106,12 +104,12 @@
env_from_flags.num_threads = j;
env_from_flags.my_shard_index = 0;
}
- CHECK_GE(env_from_flags.total_shards, 1);
- CHECK_GE(env_from_flags.batch_size, 1);
- CHECK_GE(env_from_flags.num_threads, 1);
- CHECK_LE(env_from_flags.num_threads, env_from_flags.total_shards);
- CHECK_LE(env_from_flags.my_shard_index + env_from_flags.num_threads,
- env_from_flags.total_shards)
+ FUZZTEST_CHECK_GE(env_from_flags.total_shards, 1);
+ FUZZTEST_CHECK_GE(env_from_flags.batch_size, 1);
+ FUZZTEST_CHECK_GE(env_from_flags.num_threads, 1);
+ FUZZTEST_CHECK_LE(env_from_flags.num_threads, env_from_flags.total_shards);
+ FUZZTEST_CHECK_LE(env_from_flags.my_shard_index + env_from_flags.num_threads,
+ env_from_flags.total_shards)
<< VV(env_from_flags.my_shard_index) << VV(env_from_flags.num_threads);
if (!argv.empty()) {
@@ -126,7 +124,8 @@
env_from_flags.clang_coverage_binary);
if (absl::StrContains(env_from_flags.binary, "@@")) {
- LOG(INFO) << "@@ detected; running in standalone mode with batch_size=1";
+ FUZZTEST_LOG(INFO)
+ << "@@ detected; running in standalone mode with batch_size=1";
env_from_flags.has_input_wildcards = true;
env_from_flags.batch_size = 1;
// TODO(kcc): do we need to check if extra_binaries have @@?
diff --git a/centipede/environment_test.cc b/centipede/environment_test.cc
index f78c1be..a906b99 100644
--- a/centipede/environment_test.cc
+++ b/centipede/environment_test.cc
@@ -18,8 +18,8 @@
#include <string_view>
#include "gtest/gtest.h"
-#include "absl/log/check.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/configuration.h"
namespace fuzztest::internal {
@@ -152,7 +152,7 @@
fuzztest::internal::Configuration config;
config.time_limit = absl::Seconds(123);
config.time_budget_type = fuzztest::internal::TimeBudgetType::kPerTest;
- CHECK(config.GetTimeLimitPerTest() == absl::Seconds(123));
+ FUZZTEST_CHECK(config.GetTimeLimitPerTest() == absl::Seconds(123));
env.UpdateWithTargetConfig(config);
EXPECT_EQ(env.timeout_per_batch, 123)
<< "`timeout_per_batch` should be set to the test time limit when it was "
diff --git a/centipede/feature.h b/centipede/feature.h
index 80cee6b..e69d756 100644
--- a/centipede/feature.h
+++ b/centipede/feature.h
@@ -22,7 +22,7 @@
//
// This library must not depend on anything other than libc so that fuzz targets
// using it doesn't gain redundant coverage. For the same reason this library
-// uses raw __builtin_trap instead of CHECKs.
+// uses raw __builtin_trap instead of FUZZTEST_CHECKs.
// We make an exception for <algorithm> for std::sort/std::unique,
// since <algorithm> is very lightweight.
// This library is also header-only, with all functions defined as inline.
diff --git a/centipede/feature_set.cc b/centipede/feature_set.cc
index 09d9361..f13cc5a 100644
--- a/centipede/feature_set.cc
+++ b/centipede/feature_set.cc
@@ -21,7 +21,6 @@
#include <string>
#include <string_view>
-#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "./centipede/control_flow.h"
#include "./centipede/feature.h"
@@ -102,10 +101,10 @@
// The less frequent is the domain, the more valuable are its features.
auto domain_id = feature_domains::Domain::FeatureToDomainId(feature);
auto features_in_domain = features_per_domain_[domain_id];
- CHECK(features_in_domain);
+ FUZZTEST_CHECK(features_in_domain);
auto domain_weight = num_features_ / features_in_domain;
auto feature_frequency = frequencies_[feature];
- CHECK_GT(feature_frequency, 0)
+ FUZZTEST_CHECK_GT(feature_frequency, 0)
<< VV(feature) << VV(domain_id) << VV(features_in_domain)
<< VV(domain_weight) << VV((int)feature_frequency) << DebugString();
weight += domain_weight * (256 / feature_frequency);
diff --git a/centipede/feature_set.h b/centipede/feature_set.h
index ce05712..59a5341 100644
--- a/centipede/feature_set.h
+++ b/centipede/feature_set.h
@@ -22,10 +22,10 @@
#include <ostream>
#include <string>
-#include "absl/log/log.h"
#include "./centipede/control_flow.h"
#include "./centipede/feature.h"
#include "./centipede/util.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -111,7 +111,7 @@
size_t domain_id = feature_domains::Domain::FeatureToDomainId(feature);
// TODO(b/385774476): Remove this check once the root cause is fixed.
if (domain_id >= feature_domains::kNumDomains) {
- LOG(ERROR) << "Unexpected feature with id: " << feature;
+ FUZZTEST_LOG(WARNING) << "Unexpected feature with id: " << feature;
return true;
}
return should_discard_domain_.test(domain_id);
diff --git a/centipede/hashed_ring_buffer.h b/centipede/hashed_ring_buffer.h
index f7bc646..86d555c 100644
--- a/centipede/hashed_ring_buffer.h
+++ b/centipede/hashed_ring_buffer.h
@@ -22,7 +22,7 @@
//
// This library must not depend on anything other than libc so that fuzz targets
// using it doesn't gain redundant coverage. For the same reason this library
-// uses raw __builtin_trap instead of CHECKs.
+// uses raw __builtin_trap instead of FUZZTEST_CHECKs.
// We make an exception for <algorithm> for std::sort/std::unique,
// since <algorithm> is very lightweight.
// This library is also header-only, with all functions defined as inline.
@@ -69,7 +69,8 @@
// Resets the current state, sets the ring buffer size to `size_` (<= kSize).
void Reset(size_t size) {
memset(this, 0, sizeof(*this));
- if (size > kSize) __builtin_trap(); // can't use CHECK in the runner.
+ if (size > kSize)
+ __builtin_trap(); // can't use FUZZTEST_CHECK in the runner.
size_ = size;
hash_.Reset(size);
}
diff --git a/centipede/minimize_crash.cc b/centipede/minimize_crash.cc
index a9c081f..66d417a 100644
--- a/centipede/minimize_crash.cc
+++ b/centipede/minimize_crash.cc
@@ -23,8 +23,6 @@
#include <vector>
#include "absl/base/thread_annotations.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/synchronization/mutex.h"
#include "./centipede/centipede_callbacks.h"
#include "./centipede/environment.h"
@@ -65,7 +63,7 @@
// The crasher must be smaller than the original one.
void AddCrasher(ByteArray crasher) {
absl::MutexLock lock(&mutex_);
- CHECK_LT(crasher.size(), crashers_.front().size());
+ FUZZTEST_CHECK_LT(crasher.size(), crashers_.front().size());
crashers_.emplace_back(crasher);
// Write the crasher to disk.
auto hash = Hash(crasher);
@@ -96,13 +94,14 @@
size_t num_batches = env.num_runs / env.batch_size;
for (size_t i = 0; i < num_batches; ++i) {
- LOG_EVERY_POW_2(INFO) << "[" << i << "] Minimizing... Interrupt to stop";
+ FUZZTEST_LOG_EVERY_POW_2(INFO)
+ << "[" << i << "] Minimizing... Interrupt to stop";
if (ShouldStop()) break;
// Get up to kMaxNumCrashersToGet most recent crashers. We don't want just
// the most recent crasher to avoid being stuck in local minimum.
constexpr size_t kMaxNumCrashersToGet = 20;
const auto recent_crashers = queue.GetRecentCrashers(kMaxNumCrashersToGet);
- CHECK(!recent_crashers.empty());
+ FUZZTEST_CHECK(!recent_crashers.empty());
// Compute the minimal known crasher size.
size_t min_known_size = recent_crashers.front().size();
for (const auto &crasher : recent_crashers) {
@@ -125,10 +124,10 @@
// Execute all mutants. If a new crasher is found, add it to `queue`.
if (!callbacks->Execute(env.binary, smaller_mutants, batch_result)) {
size_t crash_inputs_idx = batch_result.num_outputs_read();
- CHECK_LT(crash_inputs_idx, smaller_mutants.size());
+ FUZZTEST_CHECK_LT(crash_inputs_idx, smaller_mutants.size());
const auto &new_crasher = smaller_mutants[crash_inputs_idx];
- LOG(INFO) << "Crasher: size: " << new_crasher.size() << ": "
- << AsPrintableString(new_crasher, /*max_len=*/40);
+ FUZZTEST_LOG(INFO) << "Crasher: size: " << new_crasher.size() << ": "
+ << AsPrintableString(new_crasher, /*max_len=*/40);
queue.AddCrasher(new_crasher);
}
}
@@ -139,17 +138,17 @@
ScopedCentipedeCallbacks scoped_callback(callbacks_factory, env);
auto callbacks = scoped_callback.callbacks();
- LOG(INFO) << "MinimizeCrash: trying the original crashy input";
+ FUZZTEST_LOG(INFO) << "MinimizeCrash: trying the original crashy input";
BatchResult batch_result;
ByteArray original_crashy_input(crashy_input.begin(), crashy_input.end());
if (callbacks->Execute(env.binary, {original_crashy_input}, batch_result)) {
- LOG(INFO) << "The original crashy input did not crash; exiting";
+ FUZZTEST_LOG(INFO) << "The original crashy input did not crash; exiting";
return EXIT_FAILURE;
}
- LOG(INFO) << "Starting the crash minimization loop in " << env.num_threads
- << "threads";
+ FUZZTEST_LOG(INFO) << "Starting the crash minimization loop in "
+ << env.num_threads << "threads";
MinimizerWorkQueue queue(WorkDir{env}.CrashReproducerDirPaths().MyShard(),
original_crashy_input);
diff --git a/centipede/pc_info.cc b/centipede/pc_info.cc
index 9d99cb5..bbabced 100644
--- a/centipede/pc_info.cc
+++ b/centipede/pc_info.cc
@@ -20,9 +20,9 @@
#include <ostream>
#include <string>
-#include "absl/log/check.h"
#include "absl/types/span.h"
#include "./common/defs.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -34,11 +34,11 @@
std::string input_string(std::istreambuf_iterator<char>(in), {});
ByteArray pc_infos_as_bytes(input_string.begin(), input_string.end());
- CHECK_EQ(pc_infos_as_bytes.size() % sizeof(PCInfo), 0);
+ FUZZTEST_CHECK_EQ(pc_infos_as_bytes.size() % sizeof(PCInfo), 0);
size_t pc_table_size = pc_infos_as_bytes.size() / sizeof(PCInfo);
const auto *pc_infos = reinterpret_cast<PCInfo *>(pc_infos_as_bytes.data());
PCTable pc_table{pc_infos, pc_infos + pc_table_size};
- CHECK_EQ(pc_table.size(), pc_table_size);
+ FUZZTEST_CHECK_EQ(pc_table.size(), pc_table_size);
return pc_table;
}
diff --git a/centipede/periodic_action.h b/centipede/periodic_action.h
index 302d9a0..8af5b21 100644
--- a/centipede/periodic_action.h
+++ b/centipede/periodic_action.h
@@ -19,7 +19,7 @@
// Example:
// MyStats stats = ...;
// PeriodicAction stats_logger{
-// [&stats]() { LOG(INFO) << "Current stats are: " << stats; },
+// [&stats]() { FUZZTEST_LOG(INFO) << "Current stats are: " << stats; },
// {.delay = absl::Minutes(5), .interval = absl::Minutes(1)}
// };
// while (true) {
diff --git a/centipede/resource_pool.cc b/centipede/resource_pool.cc
index 28a2aec..a499a8f 100644
--- a/centipede/resource_pool.cc
+++ b/centipede/resource_pool.cc
@@ -19,14 +19,13 @@
#include <thread> // NOLINT: For thread IDs.
#include <utility>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/synchronization/mutex.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "./centipede/rusage_stats.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -44,7 +43,7 @@
template <typename ResourceT>
ResourcePool<ResourceT>::LeaseToken::~LeaseToken() {
- CHECK(status_checked_) //
+ FUZZTEST_CHECK(status_checked_) //
<< "status() was never consulted by caller: " << *this;
if (status_.ok()) {
leaser_.ReturnLease(*this);
@@ -88,18 +87,18 @@
template <typename ResourceT>
ResourcePool<ResourceT>::ResourcePool(const ResourceT& quota)
: quota_{quota}, pool_{quota} {
- LOG(INFO) << "Creating pool with quota=[" << quota.ShortStr() << "]";
+ FUZZTEST_LOG(INFO) << "Creating pool with quota=[" << quota.ShortStr() << "]";
}
template <typename ResourceT>
typename ResourcePool<ResourceT>::LeaseToken
ResourcePool<ResourceT>::AcquireLeaseBlocking(LeaseRequest&& request) {
- if (ABSL_VLOG_IS_ON(1)) {
+ if (FUZZTEST_VLOG_IS_ON(1)) {
absl::ReaderMutexLock lock{&pool_mu_};
- VLOG(1) << "Received lease request " << request.id //
- << "\nrequested: " << request.amount.FormattedStr() //
- << "\nquota: " << quota_.FormattedStr() //
- << "\navailable: " << pool_.FormattedStr();
+ FUZZTEST_VLOG(1) << "Received lease request " << request.id //
+ << "\nrequested: " << request.amount.FormattedStr() //
+ << "\nquota: " << quota_.FormattedStr() //
+ << "\navailable: " << pool_.FormattedStr();
}
if (request.amount == ResourceT::Zero()) {
@@ -123,7 +122,7 @@
pool_mu_.AssertReaderHeld();
const bool got_pool = request.amount <= pool_;
if (!got_pool) {
- VLOG(10) //
+ FUZZTEST_VLOG(10) //
<< "Pending lease '" << request.id << "':" //
<< "\nreq age : " << request.age() //
<< "\navailable : " << pool_.FormattedStr() //
@@ -138,7 +137,7 @@
// the timeout is reached, proceed to the else-branch.
if (pool_mu_.LockWhenWithTimeout( //
absl::Condition{&got_enough_free_pool}, request.timeout)) {
- VLOG(1) //
+ FUZZTEST_VLOG(1) //
<< "Granting lease " << request.id //
<< "\nreq age : " << request.age() //
<< "\nbefore : " << pool_.FormattedStr() //
@@ -161,7 +160,7 @@
template <typename ResourceT>
void ResourcePool<ResourceT>::ReturnLease(const LeaseToken& lease) {
absl::WriterMutexLock lock{&pool_mu_};
- VLOG(1) //
+ FUZZTEST_VLOG(1) //
<< "Returning lease " << lease.request().id //
<< "\nreq age : " << lease.request().age() //
<< "\nlease age : " << lease.age() //
diff --git a/centipede/resource_pool.h b/centipede/resource_pool.h
index 241150f..c33a8ff 100644
--- a/centipede/resource_pool.h
+++ b/centipede/resource_pool.h
@@ -76,7 +76,7 @@
// .amount = RUsageMemory{.mem_rss = EstimateShardPeakRss()},
// .timeout = absl::Minutes(10),
// });
-// CHECK_OK(rss_lease.status());
+// FUZZTEST_CHECK_OK(rss_lease.status());
// ...
// }
// // `rss_lease` dtor returns the leased RSS to `rss_pool` and unblocks
@@ -138,7 +138,7 @@
// The outcome of resource acquisition (ie. of
// `ResourcePool::AcquireLeaseBlocking()`). Must be consulted by the client
- // at least once, otherwise the dtor will CHECK.
+ // at least once, otherwise the dtor will FUZZTEST_CHECK.
const absl::Status& status() const;
// The originating request.
const LeaseRequest& request() const;
diff --git a/centipede/resource_pool_test.cc b/centipede/resource_pool_test.cc
index 23bf03b..c5b3f5e 100644
--- a/centipede/resource_pool_test.cc
+++ b/centipede/resource_pool_test.cc
@@ -21,7 +21,6 @@
#include <utility>
#include "gtest/gtest.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
diff --git a/centipede/runner_fork_server.cc b/centipede/runner_fork_server.cc
index 7467f94..db99a7e 100644
--- a/centipede/runner_fork_server.cc
+++ b/centipede/runner_fork_server.cc
@@ -84,8 +84,8 @@
}
// Maybe writes the `reason` to stderr; then calls _exit. We use this instead of
-// CHECK/RunnerCheck since the fork server runs at the very early stage of the
-// process, where the logging functions used there may not work.
+// FUZZTEST_CHECK/RunnerCheck since the fork server runs at the very early stage
+// of the process, where the logging functions used there may not work.
void Exit(const char *absl_nonnull reason) {
Log(reason);
_exit(0); // The exit code does not matter, it won't be checked anyway.
diff --git a/centipede/runner_utils.h b/centipede/runner_utils.h
index ff3b044..efa2b10 100644
--- a/centipede/runner_utils.h
+++ b/centipede/runner_utils.h
@@ -26,7 +26,7 @@
// as it is a more common pattern.
void PrintErrorAndExitIf(bool condition, const char* absl_nonnull error);
-// A rough equivalent of "CHECK(condition) << error;".
+// A rough equivalent of "FUZZTEST_CHECK(condition) << error;".
inline void RunnerCheck(bool condition, const char* absl_nonnull error) {
PrintErrorAndExitIf(!condition, error);
}
diff --git a/centipede/rusage_profiler.cc b/centipede/rusage_profiler.cc
index ae99463..a8b2ec4 100644
--- a/centipede/rusage_profiler.cc
+++ b/centipede/rusage_profiler.cc
@@ -29,8 +29,6 @@
#include "absl/base/attributes.h"
#include "absl/base/const_init.h"
#include "absl/base/nullability.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/synchronization/mutex.h"
@@ -38,6 +36,7 @@
#include "absl/time/time.h"
#include "./centipede/periodic_action.h"
#include "./centipede/rusage_stats.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -102,7 +101,7 @@
const RUsageProfiler::Snapshot& RUsageProfiler::Snapshot::Log() const {
if (id >= 0) {
- LOG(INFO).AtLocation(location.file, location.line)
+ FUZZTEST_LOG(INFO).AtLocation(location.file, location.line)
<< "PROFILER [P." << profiler_id << (profiler_desc.empty() ? "" : " ")
<< profiler_desc << "] SNAPSHOT [S." << id << (title.empty() ? "" : " ")
<< title << "]:\n"
@@ -214,7 +213,7 @@
low_water >= kZero ? 0 :
std::floor(std::abs(low_water / notch_size));
// clang-format on
- CHECK_GE(kBarNotches, notch_zero);
+ FUZZTEST_CHECK_GE(kBarNotches, notch_zero);
// Print a zero mark only if a delta metric goes negative.
std::string zero_mark = low_water < kZero ? "|" : "";
@@ -231,7 +230,7 @@
notch_size == kZero
? kBarNotches : std::floor((current - low_water) / notch_size);
// clang-format on
- CHECK_GE(kBarNotches, notches);
+ FUZZTEST_CHECK_GE(kBarNotches, notches);
if (!is_delta) {
// Non-delta metrics can't go negative, so the bar always looks like
@@ -422,7 +421,7 @@
bool also_log, //
std::string title) {
absl::WriterMutexLock lock{&mutex_};
- CHECK(!timelapse_recorder_) << "StopTimelapse() wasn't called";
+ FUZZTEST_CHECK(!timelapse_recorder_) << "StopTimelapse() wasn't called";
timelapse_recorder_ = std::make_unique<PeriodicAction>(
[this, loc = std::move(loc), title = std::move(title), also_log]() {
const auto& s = TakeSnapshot(loc, title);
@@ -433,7 +432,7 @@
void RUsageProfiler::StopTimelapse() {
absl::WriterMutexLock lock{&mutex_};
- CHECK(timelapse_recorder_) << "StartTimelapse() wasn't called";
+ FUZZTEST_CHECK(timelapse_recorder_) << "StartTimelapse() wasn't called";
timelapse_recorder_.reset();
}
@@ -441,30 +440,31 @@
SourceLocation loc, const std::string& title) {
if (metrics_ == kMetricsOff) return;
- // Logs streamed-in text to LOG(INFO), while dropping the usual log prefix
- // (date/time/thread/source). LOG()'s limit on the size of a single message
- // applies to one streamed text fragment only (if needed, this can be reduced
- // even further to a single line of text in a fragment): this is the main
- // purpose of this class, as profiling reports can get very long. especially
- // with automatic timelapse snapshotting.
+ // Logs streamed-in text to FUZZTEST_LOG(INFO), while dropping the usual log
+ // prefix (date/time/thread/source). FUZZTEST_LOG()'s limit on the size of a
+ // single message applies to one streamed text fragment only (if needed, this
+ // can be reduced even further to a single line of text in a fragment): this
+ // is the main purpose of this class, as profiling reports can get very long.
+ // especially with automatic timelapse snapshotting.
class ReportLogger final : public ReportSink {
public:
ReportLogger(SourceLocation loc) : loc_{loc} {}
~ReportLogger() override {
if (!buffer_.empty()) {
- LOG(INFO).AtLocation(loc_.file, loc_.line).NoPrefix() << buffer_;
+ FUZZTEST_LOG(INFO).AtLocation(loc_.file, loc_.line).NoPrefix()
+ << buffer_;
}
}
ReportLogger& operator<<(std::string_view fragment) override {
const auto last_newline = fragment.rfind('\n');
if (last_newline == std::string_view::npos) {
- // Accumulate no-'\n' fragments: LOG() always wraps around.
+ // Accumulate no-'\n' fragments: FUZZTEST_LOG() always wraps around.
buffer_ += fragment;
} else {
// Now we can log, but save the last bit of text
- LOG(INFO).AtLocation(loc_.file, loc_.line).NoPrefix()
+ FUZZTEST_LOG(INFO).AtLocation(loc_.file, loc_.line).NoPrefix()
<< buffer_ << fragment.substr(0, last_newline);
buffer_ = fragment.substr(last_newline + 1);
}
@@ -476,7 +476,7 @@
std::string buffer_;
};
- LOG(INFO).AtLocation(loc.file, loc.line) << title << "\n";
+ FUZZTEST_LOG(INFO).AtLocation(loc.file, loc.line) << title << "\n";
ReportLogger report_logger{loc};
GenerateReport(&report_logger);
}
diff --git a/centipede/rusage_profiler.h b/centipede/rusage_profiler.h
index 7e12b96..a45e6d3 100644
--- a/centipede/rusage_profiler.h
+++ b/centipede/rusage_profiler.h
@@ -106,18 +106,21 @@
// ...
// profiler.TakeSnapshot(ABSL_LOC).Log(); // Records and logs a snapshot
// ...
-// VLOG(1) << profiler.TakeSnapshot(ABSL_LOC); // A different way to log
+// FUZZTEST_VLOG(1) << profiler.TakeSnapshot(ABSL_LOC); // A different way
+// to log
// ...
// } // Dtor logs a final snapshot
//
// EXAMPLE USAGE - MACROS
//
// void foo() {
-// RPROF_THIS_FUNCTION(VLOG_IS_ON(2)); // Profile the function @ --v>=2
+// RPROF_THIS_FUNCTION(FUZZTEST_VLOG_IS_ON(2)); // Profile the function @
+// --v>=2
// ...
-// RPROF_SNAPSHOT_AND_LOG(); // Record and log a function-level snapshot
-// for (...) {
-// RPROF_THIS_SCOPE(VLOG_IS_ON(3)); // Profile loop iterations @ --v>=3
+// RPROF_SNAPSHOT_AND_FUZZTEST_LOG(); // Record and log a function-level
+// snapshot for (...) {
+// RPROF_THIS_SCOPE(FUZZTEST_VLOG_IS_ON(3)); // Profile loop iterations
+// @ --v>=3
// ...
// }
// RPROF_SNAPSHOT(); // Record (not log) another function-level snapshot
@@ -261,9 +264,9 @@
// table-like formatting.
std::string ShortMetricsStr() const;
- // Logs this snapshot to LOG(INFO). The source location that annotates the
- // log message is set to `location` instead of the actual call's location.
- // Returns *this so clients can do either of
+ // Logs this snapshot to FUZZTEST_LOG(INFO). The source location that
+ // annotates the log message is set to `location` instead of the actual
+ // call's location. Returns *this so clients can do either of
// Snapshot s = profiler.TakeSnapshot();
// Snapshot s = profiler.TakeSnapshot().Log();
const Snapshot& Log() const;
@@ -289,8 +292,8 @@
};
// An abstract interface used to stream in a profiling report in
- // GenerateReport(). Also used inside PrintReport() to overcome the LOG()'s
- // limitation on the size of a single printed message.
+ // GenerateReport(). Also used inside PrintReport() to overcome the
+ // FUZZTEST_LOG()'s limitation on the size of a single printed message.
class ReportSink {
public:
virtual ~ReportSink() = default;
@@ -529,7 +532,7 @@
// earlier RPROF_THIS_FUNCTION() in the same function. An optional snapshot
// title can be passed as a macro argument.
// clang-format off
-#define RPROF_SNAPSHOT_AND_LOG(...) \
+#define RPROF_SNAPSHOT_AND_FUZZTEST_LOG(...) \
FUNCTION_LEVEL_RPROF_NAME.TakeSnapshot( \
{__FILE__, __LINE__}, ##__VA_ARGS__).Log()
// clang-format on
@@ -550,7 +553,7 @@
// RPROF_THIS_FUNCTION in the same function. An optional report title can be
// passed as a macro argument.
// clang-format off
-#define RPROF_DUMP_REPORT_TO_LOG(...) \
+#define RPROF_DUMP_REPORT_TO_FUZZTEST_LOG(...) \
FUNCTION_LEVEL_RPROF_NAME.PrintReport({__FILE__, __LINE__}, ##__VA_ARGS__)
// clang-format on
diff --git a/centipede/rusage_profiler_test.cc b/centipede/rusage_profiler_test.cc
index 3960dd4..c8c0b9f 100644
--- a/centipede/rusage_profiler_test.cc
+++ b/centipede/rusage_profiler_test.cc
@@ -23,10 +23,10 @@
#include "gtest/gtest.h"
#include "absl/flags/flag.h"
-#include "absl/log/log.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "./centipede/rusage_stats.h"
+#include "./common/logging.h"
ABSL_FLAG(bool, verbose, false, "Print extra info for debugging");
ABSL_FLAG(bool, enable_system_load_sensitive_tests, false,
@@ -99,7 +99,7 @@
RPROF_START_TIMELAPSE(absl::Seconds(1), /*also_log=*/true, "Timelapse");
WasteTimeAndGobbleBytes();
RPROF_STOP_TIMELAPSE();
- RPROF_DUMP_REPORT_TO_LOG("Report");
+ RPROF_DUMP_REPORT_TO_FUZZTEST_LOG("Report");
}
// NOTE: Exclude this test from MSAN: 1) MSAN messes with the system memory
@@ -144,16 +144,18 @@
const RUsageMemory delta_memory = after_memory - before_memory;
if (absl::GetFlag(FLAGS_verbose)) {
- LOG(INFO) << "before_snapshot:\n" << before_snapshot.FormattedMetricsStr();
- LOG(INFO) << "after_snapshot:\n" << after_snapshot.FormattedMetricsStr();
- LOG(INFO) << "";
- LOG(INFO) << "before_timing: " << before_timing.FormattedStr();
- LOG(INFO) << "after_timing: " << after_timing.FormattedStr();
- LOG(INFO) << "delta_timing: " << delta_timing.FormattedStr();
- LOG(INFO) << "";
- LOG(INFO) << "before_memory: " << before_memory.FormattedStr();
- LOG(INFO) << "after_memory: " << after_memory.FormattedStr();
- LOG(INFO) << "delta_memory: " << delta_memory.FormattedStr();
+ FUZZTEST_LOG(INFO) << "before_snapshot:\n"
+ << before_snapshot.FormattedMetricsStr();
+ FUZZTEST_LOG(INFO) << "after_snapshot:\n"
+ << after_snapshot.FormattedMetricsStr();
+ FUZZTEST_LOG(INFO) << "";
+ FUZZTEST_LOG(INFO) << "before_timing: " << before_timing.FormattedStr();
+ FUZZTEST_LOG(INFO) << "after_timing: " << after_timing.FormattedStr();
+ FUZZTEST_LOG(INFO) << "delta_timing: " << delta_timing.FormattedStr();
+ FUZZTEST_LOG(INFO) << "";
+ FUZZTEST_LOG(INFO) << "before_memory: " << before_memory.FormattedStr();
+ FUZZTEST_LOG(INFO) << "after_memory: " << after_memory.FormattedStr();
+ FUZZTEST_LOG(INFO) << "delta_memory: " << delta_memory.FormattedStr();
}
EXPECT_EQ(after_snapshot.delta_timing,
@@ -172,7 +174,8 @@
EXPECT_SYS_TIMING_NEAR(after_snapshot.timing, after_timing);
// EXPECT_SYS_TIMING_NEAR(after_snapshot.delta_timing, delta_timing);
#else
- LOG(WARNING) << "Validation of some test results omitted under *SANs";
+ FUZZTEST_LOG(WARNING)
+ << "Validation of some test results omitted under *SANs";
#endif
if (absl::GetFlag(FLAGS_enable_system_load_sensitive_tests)) {
@@ -207,7 +210,8 @@
EXPECT_TIME_NEAR(snapshots[i].time - snapshots[i - 1].time, kInterval, .05);
}
#else
- LOG(WARNING) << "Validation of some test results omitted under *SANs";
+ FUZZTEST_LOG(WARNING)
+ << "Validation of some test results omitted under *SANs";
#endif
}
@@ -232,7 +236,7 @@
public:
~ReportCapture() override = default;
ReportCapture& operator<<(std::string_view fragment) override {
- LOG(INFO).NoPrefix() << fragment;
+ FUZZTEST_LOG(INFO).NoPrefix() << fragment;
return *this;
}
};
diff --git a/centipede/rusage_stats.cc b/centipede/rusage_stats.cc
index 8ca674b..ec5df9d 100644
--- a/centipede/rusage_stats.cc
+++ b/centipede/rusage_stats.cc
@@ -39,11 +39,11 @@
#include <thread> // NOLINT: For hardware_concurrency() only.
#include "absl/base/nullability.h"
-#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -102,7 +102,7 @@
// Returns a path to the /proc/<pid>/<file> or /proc/<pid>/task/<tid>/<file>.
[[nodiscard]] const std::string& GetProcFilePath(ProcFile file) const {
- CHECK_LT(file, proc_file_paths_.size());
+ FUZZTEST_CHECK_LT(file, proc_file_paths_.size());
return proc_file_paths_[file];
}
@@ -366,7 +366,8 @@
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, scope.info().pid()};
struct kinfo_proc info = {};
size_t size = sizeof(info);
- CHECK(sysctl(mib, sizeof(mib) / sizeof(mib[0]), &info, &size, NULL, 0) == 0)
+ FUZZTEST_CHECK(
+ sysctl(mib, sizeof(mib) / sizeof(mib[0]), &info, &size, NULL, 0) == 0)
<< "Error getting process information: " << strerror(errno);
cpu_utilization = info.kp_proc.p_pctcpu;
#else // __APPLE__
@@ -429,7 +430,7 @@
}
RUsageTiming operator/(const RUsageTiming& t, int64_t div) {
- CHECK_NE(div, 0);
+ FUZZTEST_CHECK_NE(div, 0);
// NOTE: Can't use RUsageTimingOp() as this operation is asymmetrical.
// clang-format off
return RUsageTiming{
@@ -519,13 +520,13 @@
#ifdef __APPLE__
if (scope.info().pid() != getpid()) return {};
struct proc_taskinfo pti = {};
- CHECK(proc_pidinfo(scope.info().pid(), PROC_PIDTASKINFO, 0, &pti,
- PROC_PIDTASKINFO_SIZE) == PROC_PIDTASKINFO_SIZE)
+ FUZZTEST_CHECK(proc_pidinfo(scope.info().pid(), PROC_PIDTASKINFO, 0, &pti,
+ PROC_PIDTASKINFO_SIZE) == PROC_PIDTASKINFO_SIZE)
<< "Unable to get system resource information";
vsize = pti.pti_virtual_size;
rss = pti.pti_resident_size;
struct rusage rusage = {};
- CHECK(getrusage(RUSAGE_SELF, &rusage) == 0)
+ FUZZTEST_CHECK(getrusage(RUSAGE_SELF, &rusage) == 0)
<< "Failed to get memory stats by getrusage";
// `data` and `shared` are not supported in MacOS.
// MacOS does not have a builtin way to query the peak size of virtual memory.
@@ -608,7 +609,7 @@
}
RUsageMemory operator/(const RUsageMemory& m, int64_t div) {
- CHECK_NE(div, 0);
+ FUZZTEST_CHECK_NE(div, 0);
// NOTE: Can't use RUsageMemoryOp() as this operation is asymmetrical.
// clang-format off
return RUsageMemory{
diff --git a/centipede/rusage_stats.h b/centipede/rusage_stats.h
index ad6d04e..d0d1cde 100644
--- a/centipede/rusage_stats.h
+++ b/centipede/rusage_stats.h
@@ -31,8 +31,8 @@
#include <ostream>
#include <string>
-#include "absl/log/check.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -78,7 +78,7 @@
const PlatformInfo& info() const {
// This can fail only when called after the object is moved.
- CHECK(info_ != nullptr);
+ FUZZTEST_CHECK(info_ != nullptr);
return *info_;
}
diff --git a/centipede/rusage_stats_test.cc b/centipede/rusage_stats_test.cc
index 6d4ea55..69d1a76 100644
--- a/centipede/rusage_stats_test.cc
+++ b/centipede/rusage_stats_test.cc
@@ -23,7 +23,6 @@
#include "gtest/gtest.h"
#include "absl/base/nullability.h"
#include "absl/flags/flag.h"
-#include "absl/log/log.h"
#include "absl/synchronization/barrier.h"
#include "absl/synchronization/mutex.h"
#include "absl/synchronization/notification.h"
@@ -208,9 +207,9 @@
}
if (absl::GetFlag(FLAGS_verbose)) {
- LOG(INFO) << "before: " << before;
- LOG(INFO) << "after: " << after;
- LOG(INFO) << "delta: " << delta;
+ FUZZTEST_LOG(INFO) << "before: " << before;
+ FUZZTEST_LOG(INFO) << "after: " << after;
+ FUZZTEST_LOG(INFO) << "delta: " << delta;
}
EXPECT_EQ(delta.user_time, after.user_time - before.user_time);
@@ -220,10 +219,10 @@
if (absl::GetFlag(FLAGS_enable_system_load_sensitive_tests)) {
if (absl::GetFlag(FLAGS_verbose)) {
- LOG(INFO) << "user_time_histo:\n" << user_time_histo;
- LOG(INFO) << "cpu_util_histo:\n" << cpu_util_histo;
- LOG(INFO) << "wall_time_histo:\n" << wall_time_histo;
- LOG(INFO) << "cpu_cores_histo:\n" << cpu_cores_histo;
+ FUZZTEST_LOG(INFO) << "user_time_histo:\n" << user_time_histo;
+ FUZZTEST_LOG(INFO) << "cpu_util_histo:\n" << cpu_util_histo;
+ FUZZTEST_LOG(INFO) << "wall_time_histo:\n" << wall_time_histo;
+ FUZZTEST_LOG(INFO) << "cpu_cores_histo:\n" << cpu_cores_histo;
}
EXPECT_NEAR( //
@@ -260,9 +259,9 @@
const auto delta = after - before;
if (absl::GetFlag(FLAGS_verbose)) {
- LOG(INFO) << "before: " << before;
- LOG(INFO) << "after: " << after;
- LOG(INFO) << "delta: " << delta;
+ FUZZTEST_LOG(INFO) << "before: " << before;
+ FUZZTEST_LOG(INFO) << "after: " << after;
+ FUZZTEST_LOG(INFO) << "delta: " << delta;
}
// NOTE: The sanitizers heavily instrument the code and skew any time
@@ -280,15 +279,16 @@
EXPECT_LE(before.mem_rss, before.mem_vsize);
EXPECT_LE(after.mem_rss, after.mem_vsize);
#else
- LOG(WARNING) << "Validation of test results omitted under *SAN: see code";
+ FUZZTEST_LOG(WARNING)
+ << "Validation of test results omitted under *SAN: see code";
#endif
mem_rss_histo.Add(delta.mem_rss);
mem_data_histo.Add(delta.mem_data);
}
if (absl::GetFlag(FLAGS_verbose)) {
- LOG(INFO) << "mem_rss_histo:\n" << mem_rss_histo;
- LOG(INFO) << "mem_data_histo:\n" << mem_data_histo;
+ FUZZTEST_LOG(INFO) << "mem_rss_histo:\n" << mem_rss_histo;
+ FUZZTEST_LOG(INFO) << "mem_data_histo:\n" << mem_data_histo;
}
// NOTE: The sanitizers heavily instrument the code and skew any time
@@ -302,22 +302,19 @@
EXPECT_NEAR(mem_data_histo.Average(), kBytes, kDataLeeway) << mem_data_histo;
#endif
#else
- LOG(WARNING) << "Validation of test results omitted under *SAN: see code";
+ FUZZTEST_LOG(WARNING)
+ << "Validation of test results omitted under *SAN: see code";
#endif
}
TEST(RUsageMemoryTest, BadScope) {
constexpr pid_t kBadPid = 999999999;
EXPECT_NO_FATAL_FAILURE( //
- const auto timing =
- RUsageTiming::Snapshot(RUsageScope::Process(kBadPid));
- VLOG(1) << "Timing: " << timing;
- );
+ const auto timing = RUsageTiming::Snapshot(RUsageScope::Process(kBadPid));
+ FUZZTEST_VLOG(1) << "Timing: " << timing;);
EXPECT_NO_FATAL_FAILURE( //
- const auto memory =
- RUsageMemory::Snapshot(RUsageScope::Process(kBadPid));
- VLOG(1) << "Memory: " << memory;
- );
+ const auto memory = RUsageMemory::Snapshot(RUsageScope::Process(kBadPid));
+ FUZZTEST_VLOG(1) << "Memory: " << memory;);
}
TEST(RUsageTimingTest, ConstantsAndMath) {
diff --git a/centipede/seed_corpus_maker.cc b/centipede/seed_corpus_maker.cc
index 695ce07..01830d8 100644
--- a/centipede/seed_corpus_maker.cc
+++ b/centipede/seed_corpus_maker.cc
@@ -18,35 +18,35 @@
#include "absl/base/nullability.h"
#include "absl/flags/flag.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "./centipede/config_init.h"
#include "./centipede/seed_corpus_maker_flags.h"
#include "./centipede/seed_corpus_maker_proto_lib.h"
#include "./centipede/util.h"
+#include "./common/logging.h"
#include "./common/remote_file.h"
int main(int argc, char** absl_nonnull argv) {
(void)fuzztest::internal::InitRuntime(argc, argv);
const std::string config = absl::GetFlag(FLAGS_config);
- QCHECK(!config.empty());
+ FUZZTEST_QCHECK(!config.empty());
const std::string override_out_dir = absl::GetFlag(FLAGS_override_out_dir);
const std::string binary_path = absl::GetFlag(FLAGS_coverage_binary_path);
const std::string binary_name = std::filesystem::path{binary_path}.filename();
- QCHECK(!binary_name.empty())
+ FUZZTEST_QCHECK(!binary_name.empty())
<< "--coverage_binary_path yields empty basename";
std::string binary_hash = absl::GetFlag(FLAGS_coverage_binary_hash);
if (binary_hash.empty()) {
- QCHECK(fuzztest::internal::RemotePathExists(binary_path))
+ FUZZTEST_QCHECK(fuzztest::internal::RemotePathExists(binary_path))
<< "--coverage_binary_path doesn't exist";
binary_hash = fuzztest::internal::HashOfFileContents(binary_path);
- LOG(INFO) << "--coverage_binary_hash was not provided: computed "
- << binary_hash
- << " from actual file at --coverage_binary_path=" << binary_path;
+ FUZZTEST_LOG(INFO) << "--coverage_binary_hash was not provided: computed "
+ << binary_hash
+ << " from actual file at --coverage_binary_path="
+ << binary_path;
}
- QCHECK_OK(fuzztest::internal::GenerateSeedCorpusFromConfigProto( //
+ FUZZTEST_QCHECK_OK(fuzztest::internal::GenerateSeedCorpusFromConfigProto( //
config, binary_name, binary_hash, override_out_dir));
return EXIT_SUCCESS;
diff --git a/centipede/seed_corpus_maker_lib.cc b/centipede/seed_corpus_maker_lib.cc
index 0a3c701..f1f588f 100644
--- a/centipede/seed_corpus_maker_lib.cc
+++ b/centipede/seed_corpus_maker_lib.cc
@@ -37,8 +37,6 @@
#include <vector>
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/random/random.h"
#include "absl/status/status.h"
#include "absl/strings/match.h"
@@ -71,7 +69,7 @@
std::string ShardPathsForLogging( //
const std::string& corpus_fname, const std::string& features_fname) {
- if (ABSL_VLOG_IS_ON(3)) {
+ if (FUZZTEST_VLOG_IS_ON(3)) {
return absl::StrCat( //
":\nCorpus: ", corpus_fname, "\nFeatures:", features_fname);
}
@@ -93,13 +91,15 @@
coverage_binary_name, ", and ", coverage_binary_hash));
}
- RPROF_THIS_FUNCTION_WITH_TIMELAPSE( //
- /*enable=*/ABSL_VLOG_IS_ON(1), //
- /*timelapse_interval=*/absl::Seconds(ABSL_VLOG_IS_ON(2) ? 10 : 60), //
- /*also_log_timelapses=*/ABSL_VLOG_IS_ON(10));
+ RPROF_THIS_FUNCTION_WITH_TIMELAPSE( //
+ /*enable=*/FUZZTEST_VLOG_IS_ON(1), //
+ /*timelapse_interval=*/
+ absl::Seconds(FUZZTEST_VLOG_IS_ON(2) ? 10 : 60), //
+ /*also_log_timelapses=*/FUZZTEST_VLOG_IS_ON(10));
- LOG(INFO) << "Reading/sampling seed corpus elements from source glob: "
- << source.dir_glob;
+ FUZZTEST_LOG(INFO)
+ << "Reading/sampling seed corpus elements from source glob: "
+ << source.dir_glob;
// Find `source.dir_glob()`-matching dirs and pick at most
// `source.num_recent_dirs()` most recent ones.
@@ -109,14 +109,14 @@
!match_status.ok() && !absl::IsNotFound(match_status)) {
return match_status;
}
- LOG(INFO) << "Found " << src_dirs.size() << " corpus dir(s) matching "
- << source.dir_glob;
+ FUZZTEST_LOG(INFO) << "Found " << src_dirs.size()
+ << " corpus dir(s) matching " << source.dir_glob;
// Sort in the ascending lexicographical order. We expect that dir names
// contain timestamps and therefore will be sorted from oldest to newest.
std::sort(src_dirs.begin(), src_dirs.end(), std::less<std::string>());
if (source.num_recent_dirs < src_dirs.size()) {
src_dirs.erase(src_dirs.begin(), src_dirs.end() - source.num_recent_dirs);
- LOG(INFO) << "Selected " << src_dirs.size() << " corpus dir(s)";
+ FUZZTEST_LOG(INFO) << "Selected " << src_dirs.size() << " corpus dir(s)";
}
// Find all the corpus shard and individual input files in the found dirs.
@@ -130,16 +130,16 @@
const std::string glob = fs::path{dir} / source.shard_rel_glob;
const auto match_status = RemoteGlobMatch(glob, matched_fnames);
if (!match_status.ok() && !absl::IsNotFound(match_status)) {
- LOG(ERROR) << "Got error when glob-matching in " << dir << ": "
- << match_status;
+ FUZZTEST_LOG(ERROR) << "Got error when glob-matching in " << dir << ": "
+ << match_status;
} else {
current_corpus_shard_fnames.insert(matched_fnames.begin(),
matched_fnames.end());
corpus_shard_fnames.insert(corpus_shard_fnames.end(),
matched_fnames.begin(),
matched_fnames.end());
- LOG(INFO) << "Found " << matched_fnames.size() << " shard(s) matching "
- << glob;
+ FUZZTEST_LOG(INFO) << "Found " << matched_fnames.size()
+ << " shard(s) matching " << glob;
}
}
if (!source.individual_input_rel_glob.empty()) {
@@ -147,8 +147,8 @@
const std::string glob = fs::path{dir} / source.individual_input_rel_glob;
const auto match_status = RemoteGlobMatch(glob, matched_fnames);
if (!match_status.ok() && !absl::IsNotFound(match_status)) {
- LOG(ERROR) << "Got error when glob-matching in " << dir << ": "
- << match_status;
+ FUZZTEST_LOG(ERROR) << "Got error when glob-matching in " << dir << ": "
+ << match_status;
} else {
size_t num_added_individual_inputs = 0;
for (auto& fname : matched_fnames) {
@@ -157,17 +157,18 @@
++num_added_individual_inputs;
individual_input_fnames.push_back(std::move(fname));
}
- LOG(INFO) << "Found " << num_added_individual_inputs
- << " individual input(s) with glob " << glob;
+ FUZZTEST_LOG(INFO) << "Found " << num_added_individual_inputs
+ << " individual input(s) with glob " << glob;
}
}
}
- LOG(INFO) << "Found " << corpus_shard_fnames.size() << " shard(s) and "
- << individual_input_fnames.size()
- << " individual input(s) total in source " << source.dir_glob;
+ FUZZTEST_LOG(INFO) << "Found " << corpus_shard_fnames.size()
+ << " shard(s) and " << individual_input_fnames.size()
+ << " individual input(s) total in source "
+ << source.dir_glob;
if (corpus_shard_fnames.empty() && individual_input_fnames.empty()) {
- LOG(WARNING) << "Skipping empty source " << source.dir_glob;
+ FUZZTEST_LOG(WARNING) << "Skipping empty source " << source.dir_glob;
return absl::OkStatus();
}
@@ -205,8 +206,8 @@
? work_dir.DistilledFeaturesFilePaths().MyShard()
: "";
- VLOG(2) << "Reading elements from source shard " << shard
- << ShardPathsForLogging(corpus_fname, features_fname);
+ FUZZTEST_VLOG(2) << "Reading elements from source shard " << shard
+ << ShardPathsForLogging(corpus_fname, features_fname);
ReadShard(corpus_fname, features_fname,
[shard, &shard_elts, &shard_elts_with_features]( //
@@ -219,21 +220,23 @@
++shard_elts_with_features;
}
shard_elts.emplace_back(input, std::move(features));
- VLOG_EVERY_N(10, 100000)
+ FUZZTEST_VLOG_EVERY_N(10, 100000)
<< "Read " << shard_elts.size()
<< " elements from shard " << shard << " so far";
});
- LOG(INFO) << "Read " << shard_elts.size() << " elements ("
- << shard_elts_with_features
- << " with computed features) from source shard " << shard
- << ShardPathsForLogging(corpus_fname, features_fname);
+ FUZZTEST_LOG(INFO) << "Read " << shard_elts.size() << " elements ("
+ << shard_elts_with_features
+ << " with computed features) from source shard "
+ << shard
+ << ShardPathsForLogging(corpus_fname,
+ features_fname);
};
threads.Schedule(read_shard);
}
- RPROF_SNAPSHOT_AND_LOG("Done reading shards");
+ RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Done reading shards");
src_elts.resize(individual_input_fnames.size());
for (size_t index = 0; index < individual_input_fnames.size(); ++index) {
@@ -242,8 +245,8 @@
const auto& path = individual_input_fnames[index];
const auto read_status = RemoteFileGetContents(path, input);
if (!read_status.ok()) {
- LOG(WARNING) << "Skipping individual input path " << path
- << " due to read error: " << read_status;
+ FUZZTEST_LOG(WARNING) << "Skipping individual input path " << path
+ << " due to read error: " << read_status;
return;
}
src_elts[index] = {std::move(input), {}};
@@ -251,7 +254,7 @@
}
}
- RPROF_SNAPSHOT_AND_LOG("Done reading");
+ RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Done reading");
size_t src_num_features = 0;
@@ -270,21 +273,22 @@
src_elts_with_features_per_shard.clear();
src_elts_with_features_per_shard.shrink_to_fit();
- RPROF_SNAPSHOT_AND_LOG("Done merging");
+ RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Done merging");
// Remove empty inputs possibly due to read errors.
auto remove_it =
std::remove_if(src_elts.begin(), src_elts.end(),
[](const auto& elt) { return std::get<0>(elt).empty(); });
if (remove_it != src_elts.end()) {
- LOG(WARNING) << "Removed " << std::distance(remove_it, src_elts.end())
- << " empty inputs";
+ FUZZTEST_LOG(WARNING) << "Removed "
+ << std::distance(remove_it, src_elts.end())
+ << " empty inputs";
src_elts.erase(remove_it, src_elts.end());
}
- LOG(INFO) << "Read total of " << src_elts.size() << " elements ("
- << src_num_features << " with features) from source "
- << source.dir_glob;
+ FUZZTEST_LOG(INFO) << "Read total of " << src_elts.size() << " elements ("
+ << src_num_features << " with features) from source "
+ << source.dir_glob;
// Extract a sample of the elements of the size specified in
// `source.sample_size`.
@@ -306,10 +310,10 @@
}
if (sample_size < src_elts.size()) {
- LOG(INFO) << "Sampling " << sample_size << " elements out of "
- << src_elts.size();
+ FUZZTEST_LOG(INFO) << "Sampling " << sample_size << " elements out of "
+ << src_elts.size();
} else {
- LOG(INFO) << "Using all " << src_elts.size() << " elements";
+ FUZZTEST_LOG(INFO) << "Using all " << src_elts.size() << " elements";
}
// Extract a sample by shuffling the elements' indices and resizing to the
@@ -321,7 +325,7 @@
std::shuffle(src_sample_idxs.begin(), src_sample_idxs.end(), absl::BitGen{});
src_sample_idxs.resize(sample_size);
- RPROF_SNAPSHOT_AND_LOG("Done sampling");
+ RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Done sampling");
// Now move each sampled element from `src_elts` to `elements`.
elements.reserve(elements.size() + sample_size);
@@ -329,7 +333,7 @@
elements.emplace_back(std::move(src_elts[idx]));
}
- RPROF_SNAPSHOT_AND_LOG("Done appending");
+ RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Done appending");
return absl::OkStatus();
}
@@ -356,13 +360,15 @@
"Unable to write seed corpus to empty destination path");
}
- RPROF_THIS_FUNCTION_WITH_TIMELAPSE( //
- /*enable=*/ABSL_VLOG_IS_ON(1), //
- /*timelapse_interval=*/absl::Seconds(ABSL_VLOG_IS_ON(2) ? 10 : 60), //
- /*also_log_timelapses=*/ABSL_VLOG_IS_ON(10));
+ RPROF_THIS_FUNCTION_WITH_TIMELAPSE( //
+ /*enable=*/FUZZTEST_VLOG_IS_ON(1), //
+ /*timelapse_interval=*/
+ absl::Seconds(FUZZTEST_VLOG_IS_ON(2) ? 10 : 60), //
+ /*also_log_timelapses=*/FUZZTEST_VLOG_IS_ON(10));
- LOG(INFO) << "Writing " << elements.size()
- << " seed corpus elements to destination: " << destination.dir_path;
+ FUZZTEST_LOG(INFO) << "Writing " << elements.size()
+ << " seed corpus elements to destination: "
+ << destination.dir_path;
if (destination.num_shards <= 0) {
return absl::InvalidArgumentError(
@@ -379,7 +385,7 @@
// first N shards.
const size_t num_shards =
std::min<size_t>(destination.num_shards, elements.size());
- CHECK_GT(num_shards, 0);
+ FUZZTEST_CHECK_GT(num_shards, 0);
const size_t shard_size = elements.size() / num_shards;
std::vector<size_t> shard_sizes(num_shards, shard_size);
const size_t excess_elts = elements.size() % num_shards;
@@ -402,7 +408,7 @@
const auto elt_range_begin = shard_elt_it;
std::advance(shard_elt_it, shard_size);
const auto elt_range_end = shard_elt_it;
- CHECK(shard_elt_it <= elements.cend()) << VV(shard);
+ FUZZTEST_CHECK(shard_elt_it <= elements.cend()) << VV(shard);
const auto write_shard = [shard, elt_range_begin, elt_range_end,
coverage_binary_name, coverage_binary_hash,
@@ -436,11 +442,12 @@
work_dir.CorpusFilePaths().IsShard(corpus_fname)
? work_dir.FeaturesFilePaths().MyShard()
: work_dir.DistilledFeaturesFilePaths().MyShard();
- CHECK(!features_fname.empty());
+ FUZZTEST_CHECK(!features_fname.empty());
- VLOG(2) << "Writing " << std::distance(elt_range_begin, elt_range_end)
- << " elements to destination shard " << shard
- << ShardPathsForLogging(corpus_fname, features_fname);
+ FUZZTEST_VLOG(2) << "Writing "
+ << std::distance(elt_range_begin, elt_range_end)
+ << " elements to destination shard " << shard
+ << ShardPathsForLogging(corpus_fname, features_fname);
// Features files are always saved in a subdir of the workdir
// (== `destination.dir_path` here), which might not exist yet, so we
@@ -463,12 +470,12 @@
const std::unique_ptr<BlobFileWriter> corpus_writer =
DefaultBlobFileWriterFactory();
- CHECK(corpus_writer != nullptr);
+ FUZZTEST_CHECK(corpus_writer != nullptr);
RETURN_IF_NOT_OK(corpus_writer->Open(corpus_fname, "w"));
const std::unique_ptr<BlobFileWriter> features_writer =
DefaultBlobFileWriterFactory();
- CHECK(features_writer != nullptr);
+ FUZZTEST_CHECK(features_writer != nullptr);
RETURN_IF_NOT_OK(features_writer->Open(features_fname, "w"));
// Write the shard's elements to the corpus and features shard files.
@@ -486,10 +493,12 @@
}
}
- LOG(INFO) << "Wrote " << std::distance(elt_range_begin, elt_range_end)
- << " elements (" << shard_elts_with_features
- << " with features) to destination shard " << shard
- << ShardPathsForLogging(corpus_fname, features_fname);
+ FUZZTEST_LOG(INFO) << "Wrote "
+ << std::distance(elt_range_begin, elt_range_end)
+ << " elements (" << shard_elts_with_features
+ << " with features) to destination shard " << shard
+ << ShardPathsForLogging(corpus_fname,
+ features_fname);
dst_elts_with_features += shard_elts_with_features;
@@ -506,10 +515,10 @@
RETURN_IF_NOT_OK(write_status);
}
- LOG(INFO) << "Wrote total of " << elements.size() << " elements ("
- << dst_elts_with_features
- << " with precomputed features) to destination "
- << destination.dir_path;
+ FUZZTEST_LOG(INFO) << "Wrote total of " << elements.size() << " elements ("
+ << dst_elts_with_features
+ << " with precomputed features) to destination "
+ << destination.dir_path;
return absl::OkStatus();
}
@@ -524,19 +533,19 @@
RETURN_IF_NOT_OK(SampleSeedCorpusElementsFromSource( //
source, coverage_binary_name, coverage_binary_hash, elements));
}
- LOG(INFO) << "Sampled " << elements.size() << " elements from "
- << config.sources.size() << " seed corpus source(s)";
+ FUZZTEST_LOG(INFO) << "Sampled " << elements.size() << " elements from "
+ << config.sources.size() << " seed corpus source(s)";
// Write the sampled elements to the destination.
if (elements.empty()) {
- LOG(WARNING)
+ FUZZTEST_LOG(WARNING)
<< "No elements to write to seed corpus destination - doing nothing";
} else {
RETURN_IF_NOT_OK(WriteSeedCorpusElementsToDestination( //
elements, coverage_binary_name, coverage_binary_hash,
config.destination));
- LOG(INFO) << "Wrote " << elements.size()
- << " elements to seed corpus destination";
+ FUZZTEST_LOG(INFO) << "Wrote " << elements.size()
+ << " elements to seed corpus destination";
}
return absl::OkStatus();
}
diff --git a/centipede/seed_corpus_maker_lib_test.cc b/centipede/seed_corpus_maker_lib_test.cc
index 2be35f0..d749ca3 100644
--- a/centipede/seed_corpus_maker_lib_test.cc
+++ b/centipede/seed_corpus_maker_lib_test.cc
@@ -25,7 +25,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "./centipede/feature.h"
#include "./centipede/workdir.h"
@@ -207,7 +206,7 @@
/*shard_index_digits=*/kIdxDigits,
/*num_shards=*/kNumShards,
};
- CHECK_OK(WriteSeedCorpusElementsToDestination( //
+ FUZZTEST_CHECK_OK(WriteSeedCorpusElementsToDestination( //
kShardedInputs, kCovBin, kCovHash, destination));
const std::string workdir = (test_dir / kRelDir).c_str();
ASSERT_NO_FATAL_FAILURE(VerifyShardsExist( //
@@ -218,7 +217,8 @@
for (int i = 0; i < kIndividualInputs.size(); ++i) {
const auto path = std::filesystem::path(test_dir) / kRelDir /
absl::StrCat("individual_input_", i);
- CHECK_OK(RemoteFileSetContents(path.string(), kIndividualInputs[i]));
+ FUZZTEST_CHECK_OK(
+ RemoteFileSetContents(path.string(), kIndividualInputs[i]));
}
// Test that sharded and individual inputs matches what we wrote.
diff --git a/centipede/seed_corpus_maker_proto_lib.cc b/centipede/seed_corpus_maker_proto_lib.cc
index 80ae4c9..fd44c58 100644
--- a/centipede/seed_corpus_maker_proto_lib.cc
+++ b/centipede/seed_corpus_maker_proto_lib.cc
@@ -19,7 +19,6 @@
#include <utility>
#include <variant>
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
@@ -48,16 +47,18 @@
}
if (RemotePathExists(config_spec)) {
- LOG(INFO) << "Config spec points at an existing file; trying to parse "
- "textproto config from it: "
- << VV(config_spec);
+ FUZZTEST_LOG(INFO)
+ << "Config spec points at an existing file; trying to parse "
+ "textproto config from it: "
+ << VV(config_spec);
RETURN_IF_NOT_OK(RemoteFileGetContents(config_spec, config_str));
- LOG(INFO) << "Raw config read from file:\n" << config_str;
+ FUZZTEST_LOG(INFO) << "Raw config read from file:\n" << config_str;
base_dir = std::filesystem::path{config_spec}.parent_path();
} else {
- LOG(INFO) << "Config spec is not a file, or file doesn't exist; trying to "
- "parse textproto config verbatim: "
- << VV(config_spec);
+ FUZZTEST_LOG(INFO)
+ << "Config spec is not a file, or file doesn't exist; trying to "
+ "parse textproto config verbatim: "
+ << VV(config_spec);
config_str = config_spec;
base_dir = fs::current_path();
}
@@ -73,7 +74,7 @@
"destination, config_spec: ",
config_spec, ", config: ", config));
}
- LOG(INFO) << "Parsed config:\n" << config;
+ FUZZTEST_LOG(INFO) << "Parsed config:\n" << config;
// Resolve relative `source.dir_glob`s in the config to absolute ones.
for (auto& src : *config.mutable_sources()) {
@@ -99,7 +100,7 @@
WorkDir::kDigitsInShardIndex);
}
- LOG(INFO) << "Resolved config:\n" << config;
+ FUZZTEST_LOG(INFO) << "Resolved config:\n" << config;
return config;
}
@@ -164,7 +165,7 @@
const proto::SeedCorpusConfig config_proto,
ResolveSeedCorpusConfigProto(config_spec, override_out_dir));
if (config_proto.sources_size() == 0 || !config_proto.has_destination()) {
- LOG(WARNING) << "Config is empty: skipping seed corpus generation";
+ FUZZTEST_LOG(WARNING) << "Config is empty: skipping seed corpus generation";
return absl::OkStatus();
}
RETURN_IF_NOT_OK(DumpConfigProtoToDebugDir(config_proto, coverage_binary_name,
diff --git a/centipede/stats.cc b/centipede/stats.cc
index 748c6f5..50225ed 100644
--- a/centipede/stats.cc
+++ b/centipede/stats.cc
@@ -34,8 +34,6 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/ascii.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
@@ -60,7 +58,7 @@
StatsReporter::StatsReporter(const std::vector<std::atomic<Stats>> &stats_vec,
const std::vector<Environment> &env_vec)
: stats_vec_{stats_vec}, env_vec_{env_vec} {
- CHECK_EQ(stats_vec.size(), env_vec.size());
+ FUZZTEST_CHECK_EQ(stats_vec.size(), env_vec.size());
for (size_t i = 0; i < env_vec.size(); ++i) {
const auto &env = env_vec[i];
group_to_indices_[env.experiment_name].push_back(i);
@@ -162,7 +160,8 @@
}
void StatsLogger::DoneFieldSamplesBatch() {
- LOG(INFO) << "Current stats:\n" << absl::StripAsciiWhitespace(os_.str());
+ FUZZTEST_LOG(INFO) << "Current stats:\n"
+ << absl::StripAsciiWhitespace(os_.str());
// Reset the stream for the next round of logging.
os_.str("");
}
@@ -173,7 +172,7 @@
StatsCsvFileAppender::~StatsCsvFileAppender() {
if (files_ == nullptr) return;
for (const auto &[group_name, file] : *files_) {
- CHECK_OK(RemoteFileClose(file.file));
+ FUZZTEST_CHECK_OK(RemoteFileClose(file.file));
}
}
@@ -195,7 +194,7 @@
}
void StatsCsvFileAppender::SetCurrGroup(const Environment &master_env) {
- CHECK(files_ != nullptr);
+ FUZZTEST_CHECK(files_ != nullptr);
BufferedRemoteFile &file = (*files_)[master_env.experiment_name];
if (file.file == nullptr) {
const std::string filename =
@@ -208,20 +207,21 @@
bool append = false;
if (RemotePathExists(filename)) {
std::string contents;
- CHECK_OK(RemoteFileGetContents(filename, contents));
+ FUZZTEST_CHECK_OK(RemoteFileGetContents(filename, contents));
// NOTE: `csv_header_` ends with '\n', so the match is exact.
if (absl::StartsWith(contents, csv_header_)) {
append = true;
} else {
append = false;
- CHECK_OK(RemoteFileSetContents(GetBackupFilename(filename), contents));
+ FUZZTEST_CHECK_OK(
+ RemoteFileSetContents(GetBackupFilename(filename), contents));
}
}
file.file = *RemoteFileOpen(filename, append ? "a" : "w");
- CHECK(file.file != nullptr) << VV(filename);
+ FUZZTEST_CHECK(file.file != nullptr) << VV(filename);
if (!append) {
- CHECK_OK(RemoteFileAppend(file.file, csv_header_));
- CHECK_OK(RemoteFileFlush(file.file));
+ FUZZTEST_CHECK_OK(RemoteFileAppend(file.file, csv_header_));
+ FUZZTEST_CHECK_OK(RemoteFileFlush(file.file));
}
}
// This is OK even though hash maps provide no pointer stability because the
@@ -245,7 +245,7 @@
}
double avg = !values.empty() ? (1.0 * sum / values.size()) : 0;
- CHECK(curr_file_ != nullptr);
+ FUZZTEST_CHECK(curr_file_ != nullptr);
std::string &values_str = curr_file_->buffer;
if (curr_field_info_.traits & TraitBits::kMin)
absl::StrAppendFormat(&values_str, "%" PRIu64 ",", min);
@@ -263,10 +263,11 @@
}
void StatsCsvFileAppender::DoneFieldSamplesBatch() {
- CHECK(files_ != nullptr);
+ FUZZTEST_CHECK(files_ != nullptr);
for (auto &[group_name, file] : *files_) {
- CHECK_OK(RemoteFileAppend(file.file, absl::StrCat(file.buffer, "\n")));
- CHECK_OK(RemoteFileFlush(file.file));
+ FUZZTEST_CHECK_OK(
+ RemoteFileAppend(file.file, absl::StrCat(file.buffer, "\n")));
+ FUZZTEST_CHECK_OK(RemoteFileFlush(file.file));
file.buffer.clear();
}
}
@@ -286,7 +287,7 @@
void PrintRewardValues(absl::Span<const std::atomic<Stats>> stats_vec,
std::ostream &os) {
size_t n = stats_vec.size();
- CHECK_GT(n, 0);
+ FUZZTEST_CHECK_GT(n, 0);
std::vector<size_t> num_covered_pcs(n);
for (size_t i = 0; i < n; ++i) {
num_covered_pcs[i] = stats_vec[i].load().num_covered_pcs;
diff --git a/centipede/stats.h b/centipede/stats.h
index 603afcc..635533d 100644
--- a/centipede/stats.h
+++ b/centipede/stats.h
@@ -514,8 +514,9 @@
inline StatsReporter::StatsReporter(StatsReporter &&) noexcept = default;
// Takes a set of `Stats` objects and a corresponding set of `Environment`
-// objects and logs the current `Stats` values to LOG(INFO) on each invocation
-// of `ReportCurrStats()`. If the environments indicate the use of the
+// objects and logs the current `Stats` values to FUZZTEST_LOG(INFO) on each
+// invocation of `ReportCurrStats()`. If the environments indicate the use of
+// the
// --experiment flag, the stats for each of the experiment are juxtaposed for
// easy visual comparison.
class StatsLogger : public StatsReporter {
diff --git a/centipede/stats_test.cc b/centipede/stats_test.cc
index d21221a..491a428 100644
--- a/centipede/stats_test.cc
+++ b/centipede/stats_test.cc
@@ -25,7 +25,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/log/check.h"
#include "absl/log/log_entry.h"
#include "absl/log/log_sink.h"
#include "absl/log/log_sink_registry.h"
@@ -847,7 +846,8 @@
ReadFromLocalFile(kExpectedCsvBak, contents_bak);
const std::vector<std::string> lines_bak =
absl::StrSplit(contents_bak, '\n');
- CHECK_NE(lines.size(), kFakeOldCsvLines.size()); // Prevent false positives
+ FUZZTEST_CHECK_NE(lines.size(),
+ kFakeOldCsvLines.size()); // Prevent false positives
EXPECT_EQ(lines_bak.size(), kFakeOldCsvLines.size());
}
}
diff --git a/centipede/symbol_table.cc b/centipede/symbol_table.cc
index d6aecb4..2168c00 100644
--- a/centipede/symbol_table.cc
+++ b/centipede/symbol_table.cc
@@ -27,8 +27,6 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
@@ -68,13 +66,15 @@
if (lines_view.size() == 1 && lines_view.back().empty()) return;
while (!lines_view.empty()) {
- CHECK_GE(lines_view.size(), 3) << "Unexpected symbolizer output format.";
+ FUZZTEST_CHECK_GE(lines_view.size(), 3)
+ << "Unexpected symbolizer output format.";
std::string_view func = lines_view[0];
std::string_view file = lines_view[1];
std::string_view empty = lines_view[2];
- CHECK(empty.empty()) << "Unexpected symbolizer output format: " << VV(func)
- << VV(file) << VV(empty);
+ FUZZTEST_CHECK(empty.empty())
+ << "Unexpected symbolizer output format: " << VV(func) << VV(file)
+ << VV(empty);
for (auto &useless_prefix : {"/proc/self/cwd/", "./"}) {
file = absl::StripPrefix(file, useless_prefix);
}
@@ -113,8 +113,8 @@
WriteToLocalFile(pcs_file.path(), pcs_string);
// Run the symbolizer.
- LOG(INFO) << "Symbolizing " << pc_infos.size() << " PCs from "
- << dso_basename;
+ FUZZTEST_LOG(INFO) << "Symbolizing " << pc_infos.size() << " PCs from "
+ << dso_basename;
Command::Options cmd_options;
cmd_options.args = {
"--no-inlines",
@@ -127,8 +127,9 @@
Command cmd{symbolizer_path, std::move(cmd_options)};
int exit_code = cmd.Execute();
if (exit_code != EXIT_SUCCESS) {
- LOG(ERROR) << "Symbolization failed, debug symbols will not be used: "
- << VV(dso_path) << VV(cmd.ToString()) << VV(exit_code);
+ FUZZTEST_LOG(ERROR)
+ << "Symbolization failed, debug symbols will not be used: "
+ << VV(dso_path) << VV(cmd.ToString()) << VV(exit_code);
return;
}
@@ -139,9 +140,10 @@
size_t new_size = size();
size_t added_size = new_size - old_size;
if (added_size != pc_infos.size()) {
- LOG(ERROR) << "Symbolization failed: debug symbols will not be used: "
- << VV(dso_path) << VV(cmd.ToString()) << VV(exit_code)
- << VV(pc_infos.size()) << VV(added_size);
+ FUZZTEST_LOG(ERROR)
+ << "Symbolization failed: debug symbols will not be used: "
+ << VV(dso_path) << VV(cmd.ToString()) << VV(exit_code)
+ << VV(pc_infos.size()) << VV(added_size);
}
}
@@ -152,12 +154,14 @@
// NOTE: --symbolizer_path=/dev/null is a somewhat expected alternative to
// "" that users might pass.
if (symbolizer_path.empty() || symbolizer_path == "/dev/null") {
- LOG(WARNING) << "Symbolizer unspecified: debug symbols will not be used";
+ FUZZTEST_LOG(WARNING)
+ << "Symbolizer unspecified: debug symbols will not be used";
SetAllToUnknown(pc_table.size());
return;
}
- LOG(INFO) << "Symbolizing " << dso_table.size() << " instrumented DSOs.";
+ FUZZTEST_LOG(INFO) << "Symbolizing " << dso_table.size()
+ << " instrumented DSOs.";
// Iterate all DSOs, symbolize their respective PCs.
// Symbolizing the PCs can take time, so we
@@ -173,7 +177,8 @@
for (size_t dso_id = 0; dso_id < dso_table.size(); ++dso_id) {
const auto &dso_info = dso_table[dso_id];
auto &symbol_table = symbol_tables[dso_id];
- CHECK_LE(pc_idx_begin + dso_info.num_instrumented_pcs, pc_table.size())
+ FUZZTEST_CHECK_LE(pc_idx_begin + dso_info.num_instrumented_pcs,
+ pc_table.size())
<< VV(pc_idx_begin) << VV(dso_info.num_instrumented_pcs);
const absl::Span<const PCInfo> pc_infos = {pc_table.data() + pc_idx_begin,
dso_info.num_instrumented_pcs};
@@ -188,7 +193,7 @@
for (const auto &table : symbol_tables) {
AddEntries(table);
}
- CHECK_EQ(pc_idx_begin, pc_table.size());
+ FUZZTEST_CHECK_EQ(pc_idx_begin, pc_table.size());
if (size() != pc_table.size()) {
// Something went wrong. Set symbols to unknown so the sizes of pc_table and
@@ -214,19 +219,19 @@
}
const std::vector<std::string_view> file_line_col_split =
absl::StrSplit(file_line_col, ':');
- CHECK_LE(file_line_col_split.size(), 3);
- CHECK_GE(file_line_col_split.size(), 1)
+ FUZZTEST_CHECK_LE(file_line_col_split.size(), 3);
+ FUZZTEST_CHECK_GE(file_line_col_split.size(), 1)
<< "Unexpected symbolizer input format when getting source location: "
<< file_line_col;
int line = -1;
int col = -1;
if (file_line_col_split.size() >= 2) {
- CHECK(absl::SimpleAtoi(file_line_col_split[1], &line))
+ FUZZTEST_CHECK(absl::SimpleAtoi(file_line_col_split[1], &line))
<< "Unable to convert line number string to an int: "
<< file_line_col_split[1];
}
if (file_line_col_split.size() == 3) {
- CHECK(absl::SimpleAtoi(file_line_col_split[2], &col))
+ FUZZTEST_CHECK(absl::SimpleAtoi(file_line_col_split[2], &col))
<< "Unable to convert column number string to an int: "
<< file_line_col_split[2];
}
diff --git a/centipede/test_coverage_util.cc b/centipede/test_coverage_util.cc
index d65dff0..e499179 100644
--- a/centipede/test_coverage_util.cc
+++ b/centipede/test_coverage_util.cc
@@ -18,7 +18,6 @@
#include <string>
#include <vector>
-#include "absl/log/check.h"
#include "./centipede/corpus.h"
#include "./centipede/environment.h"
#include "./centipede/feature.h"
@@ -46,7 +45,7 @@
// Repackage execution results into a vector of CorpusRecords.
std::vector<CorpusRecord> corpus_records;
std::vector<ExecutionResult> &execution_results = batch_result.results();
- CHECK_EQ(byte_array_inputs.size(), execution_results.size());
+ FUZZTEST_CHECK_EQ(byte_array_inputs.size(), execution_results.size());
corpus_records.reserve(byte_array_inputs.size());
for (int i = 0; i < byte_array_inputs.size(); ++i) {
diff --git a/centipede/test_coverage_util.h b/centipede/test_coverage_util.h
index 6a9b5d5..c06a9bf 100644
--- a/centipede/test_coverage_util.h
+++ b/centipede/test_coverage_util.h
@@ -21,7 +21,6 @@
#include <string_view>
#include <vector>
-#include "absl/log/check.h"
#include "./centipede/centipede_callbacks.h"
#include "./centipede/corpus.h"
#include "./centipede/environment.h"
@@ -48,7 +47,7 @@
BatchResult &batch_result) override {
int result =
ExecuteCentipedeSancovBinaryWithShmem(binary, inputs, batch_result);
- CHECK_EQ(EXIT_SUCCESS, result);
+ FUZZTEST_CHECK_EQ(EXIT_SUCCESS, result);
return true;
}
std::vector<ByteArray> Mutate(const std::vector<MutationInputRef> &inputs,
diff --git a/centipede/thread_pool.h b/centipede/thread_pool.h
index a742ba6..7c22801 100644
--- a/centipede/thread_pool.h
+++ b/centipede/thread_pool.h
@@ -24,7 +24,6 @@
#include "absl/base/thread_annotations.h"
#include "absl/functional/any_invocable.h"
-#include "absl/log/check.h"
#include "absl/synchronization/mutex.h"
namespace fuzztest::internal {
@@ -60,7 +59,7 @@
// Schedules a function to be run on a ThreadPool thread immediately.
void Schedule(absl::AnyInvocable<void()> func) {
- CHECK(func != nullptr);
+ FUZZTEST_CHECK(func != nullptr);
absl::MutexLock l{&mu_};
queue_.push(std::move(func));
}
diff --git a/centipede/util.cc b/centipede/util.cc
index c5e1b74..988f25e 100644
--- a/centipede/util.cc
+++ b/centipede/util.cc
@@ -45,7 +45,6 @@
#include "absl/base/const_init.h"
#include "absl/base/nullability.h"
#include "absl/base/thread_annotations.h"
-#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_replace.h"
#include "absl/strings/str_split.h"
@@ -86,11 +85,11 @@
f.seekg(0, std::ios_base::end);
auto size = f.tellg();
f.seekg(0, std::ios_base::beg);
- CHECK_EQ(size % sizeof(data[0]), 0);
+ FUZZTEST_CHECK_EQ(size % sizeof(data[0]), 0);
data.resize(size / sizeof(data[0]));
f.read(reinterpret_cast<char *>(data.data()), size);
- CHECK(f) << "Failed to read from local file: " << VV(file_path) << VV(f.eof())
- << VV(f.bad()) << VV(f.fail()) << VV(size);
+ FUZZTEST_CHECK(f) << "Failed to read from local file: " << VV(file_path)
+ << VV(f.eof()) << VV(f.bad()) << VV(f.fail()) << VV(size);
f.close();
}
@@ -110,15 +109,15 @@
void ClearLocalFileContents(std::string_view file_path) {
std::ofstream f(std::string{file_path}, std::ios::out | std::ios::trunc);
- CHECK(f) << "Failed to clear the file: " << file_path;
+ FUZZTEST_CHECK(f) << "Failed to clear the file: " << file_path;
}
void WriteToLocalFile(std::string_view file_path, ByteSpan data) {
std::ofstream f(std::string{file_path});
- CHECK(f) << "Failed to open local file: " << file_path;
+ FUZZTEST_CHECK(f) << "Failed to open local file: " << file_path;
f.write(reinterpret_cast<const char *>(data.data()),
static_cast<int64_t>(data.size()));
- CHECK(f) << "Failed to write to local file: " << file_path;
+ FUZZTEST_CHECK(f) << "Failed to write to local file: " << file_path;
f.close();
}
@@ -140,14 +139,14 @@
void WriteToRemoteHashedFileInDir(std::string_view dir_path, ByteSpan data) {
if (dir_path.empty()) return;
std::string file_path = std::filesystem::path(dir_path).append(Hash(data));
- CHECK_OK(
+ FUZZTEST_CHECK_OK(
RemoteFileSetContents(file_path, std::string(data.begin(), data.end())));
}
std::string HashOfFileContents(std::string_view file_path) {
if (file_path.empty()) return "";
std::string file_contents;
- CHECK_OK(RemoteFileGetContents(file_path, file_contents));
+ FUZZTEST_CHECK_OK(RemoteFileGetContents(file_path, file_contents));
return Hash(file_contents);
}
@@ -183,7 +182,7 @@
void CreateLocalDirRemovedAtExit(std::string_view path) {
// Safeguard against removing dirs not created by TemporaryLocalDirPath().
- CHECK_NE(path.find("/centipede-"), std::string::npos);
+ FUZZTEST_CHECK_NE(path.find("/centipede-"), std::string::npos);
// Create the dir.
std::filesystem::remove_all(path);
std::filesystem::create_directories(path);
@@ -202,12 +201,12 @@
ScopedFile::~ScopedFile() { std::filesystem::remove_all(my_path_); }
void AppendHashToArray(ByteArray &ba, std::string_view hash) {
- CHECK_EQ(hash.size(), kHashLen);
+ FUZZTEST_CHECK_EQ(hash.size(), kHashLen);
ba.insert(ba.end(), hash.begin(), hash.end());
}
std::string ExtractHashFromArray(ByteArray &ba) {
- CHECK_GE(ba.size(), kHashLen);
+ FUZZTEST_CHECK_GE(ba.size(), kHashLen);
std::string res;
res.insert(res.end(), ba.end() - kHashLen, ba.end());
ba.resize(ba.size() - kHashLen);
@@ -223,7 +222,7 @@
ByteSpan features) {
ByteArray feature_bytes_with_hash(features.size() + kHashLen);
auto hash = Hash(data);
- CHECK_EQ(hash.size(), kHashLen);
+ FUZZTEST_CHECK_EQ(hash.size(), kHashLen);
memcpy(feature_bytes_with_hash.data(), features.data(), features.size());
memcpy(feature_bytes_with_hash.data() + features.size(), hash.data(),
kHashLen);
@@ -350,13 +349,13 @@
uint8_t *MmapNoReserve(size_t size) {
auto result = mmap(0, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANON | MAP_NORESERVE, -1, 0);
- CHECK(result != MAP_FAILED);
+ FUZZTEST_CHECK(result != MAP_FAILED);
return reinterpret_cast<uint8_t *>(result);
}
void Munmap(uint8_t *ptr, size_t size) {
auto result = munmap(ptr, size);
- CHECK_EQ(result, 0);
+ FUZZTEST_CHECK_EQ(result, 0);
}
} // namespace fuzztest::internal
diff --git a/centipede/util.h b/centipede/util.h
index 1f31e40..93ca1cb 100644
--- a/centipede/util.h
+++ b/centipede/util.h
@@ -23,10 +23,10 @@
#include <vector>
#include "absl/base/nullability.h"
-#include "absl/log/check.h"
#include "absl/types/span.h"
#include "./centipede/feature.h"
#include "./common/defs.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -158,13 +158,13 @@
std::vector<ByteArray> &dictionary_entries);
// Maps `size` bytes with `mmap(NO_RESERVE)` or equivalent, returns the result.
-// CHECK-fails on error.
+// FUZZTEST_CHECK-fails on error.
// The resulting memory is unreserved, and will be zero-initialized on first
// access.
uint8_t *MmapNoReserve(size_t size);
// Unmaps memory returned by `MmapNoReserve`().
-// CHECK-fails on error.
+// FUZZTEST_CHECK-fails on error.
void Munmap(uint8_t *ptr, size_t size);
// Fixed size array allocated/deallocated with MmapNoReserve/Munmap.
@@ -179,11 +179,11 @@
MmapNoReserveArray(MmapNoReserveArray &&) = delete;
MmapNoReserveArray &operator=(MmapNoReserveArray &&) = delete;
uint8_t operator[](size_t i) const {
- CHECK_LT(i, kSize);
+ FUZZTEST_CHECK_LT(i, kSize);
return array_[i];
}
uint8_t &operator[](size_t i) {
- CHECK_LT(i, kSize);
+ FUZZTEST_CHECK_LT(i, kSize);
return array_[i];
}
diff --git a/centipede/util_test.cc b/centipede/util_test.cc
index 792c9f9..7be77e8 100644
--- a/centipede/util_test.cc
+++ b/centipede/util_test.cc
@@ -24,11 +24,11 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/container/flat_hash_map.h"
-#include "absl/log/log.h"
#include "./centipede/feature.h"
#include "./centipede/thread_pool.h"
#include "./common/defs.h"
#include "./common/hash.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -106,7 +106,7 @@
{
// Check that repeated calls return the same path.
auto temp_dir = TemporaryLocalDirPath();
- LOG(INFO) << temp_dir;
+ FUZZTEST_LOG(INFO) << temp_dir;
EXPECT_EQ(temp_dir, TemporaryLocalDirPath());
}
diff --git a/centipede/workdir.cc b/centipede/workdir.cc
index 59b2e0f..c0f4090 100644
--- a/centipede/workdir.cc
+++ b/centipede/workdir.cc
@@ -23,8 +23,6 @@
#include <utility>
#include <vector>
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/match.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
@@ -46,7 +44,7 @@
std::string NormalizeAnnotation(std::string_view annotation) {
std::string ret;
if (!annotation.empty()) {
- CHECK_NE(annotation.front(), '.');
+ FUZZTEST_CHECK_NE(annotation.front(), '.');
ret = absl::StrCat(".", annotation);
}
return ret;
@@ -101,15 +99,16 @@
const std::filesystem::path path{corpus_shard_path};
const std::string dir = path.parent_path();
const std::string stem = path.stem();
- CHECK(stem == kCorpusShardStem ||
- absl::StartsWith(stem, kDistilledCorpusShardStemPrefix))
+ FUZZTEST_CHECK(stem == kCorpusShardStem ||
+ absl::StartsWith(stem, kDistilledCorpusShardStemPrefix))
<< VV(corpus_shard_path);
const std::string dot_ext = path.extension();
- CHECK(!dot_ext.empty() && dot_ext[0] == '.') << VV(corpus_shard_path);
+ FUZZTEST_CHECK(!dot_ext.empty() && dot_ext[0] == '.')
+ << VV(corpus_shard_path);
const std::string ext = dot_ext.substr(1);
- CHECK_EQ(ext.size(), kDigitsInShardIndex) << VV(corpus_shard_path);
+ FUZZTEST_CHECK_EQ(ext.size(), kDigitsInShardIndex) << VV(corpus_shard_path);
size_t shard_index = -1;
- CHECK(absl::SimpleAtoi(ext, &shard_index)) << VV(corpus_shard_path);
+ FUZZTEST_CHECK(absl::SimpleAtoi(ext, &shard_index)) << VV(corpus_shard_path);
return WorkDir{
dir,
std::string{binary_name},
@@ -241,8 +240,8 @@
const auto dir_iter =
std::filesystem::directory_iterator(dir_path, dir_error);
if (dir_error) {
- LOG(ERROR) << "Failed to access coverage dir '" << dir_path
- << "': " << dir_error.message();
+ FUZZTEST_LOG(ERROR) << "Failed to access coverage dir '" << dir_path
+ << "': " << dir_error.message();
return {};
}
std::vector<std::string> raw_profiles;
diff --git a/common/BUILD b/common/BUILD
index 753a042..d0fb585 100644
--- a/common/BUILD
+++ b/common/BUILD
@@ -40,7 +40,7 @@
srcs = ["bazel.cc"],
hdrs = ["bazel.h"],
deps = [
- "@abseil-cpp//absl/log:check",
+ ":logging",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
@@ -64,8 +64,6 @@
":status_macros",
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/base:nullability",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings:str_format",
@@ -106,8 +104,8 @@
name = "logging",
hdrs = ["logging.h"],
deps = [
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
+ "@abseil-cpp//absl/log:absl_check",
+ "@abseil-cpp//absl/log:absl_log",
],
)
@@ -124,7 +122,6 @@
":logging",
":status_macros",
"@abseil-cpp//absl/base:nullability",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
@@ -156,8 +153,6 @@
":logging",
":status_macros",
"@abseil-cpp//absl/base:nullability",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
@@ -186,8 +181,8 @@
name = "status_macros",
hdrs = ["status_macros.h"],
deps = [
+ ":logging",
"@abseil-cpp//absl/base:core_headers",
- "@abseil-cpp//absl/log",
],
)
@@ -200,8 +195,6 @@
":blob_file",
":defs",
":logging",
- "@abseil-cpp//absl/log",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@googletest//:gtest",
@@ -213,7 +206,7 @@
srcs = ["temp_dir.cc"],
hdrs = ["temp_dir.h"],
deps = [
- "@abseil-cpp//absl/log:check",
+ ":logging",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:string_view",
],
@@ -254,7 +247,6 @@
":logging",
":remote_file",
":test_util",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/time",
"@googletest//:gtest",
diff --git a/common/bazel.cc b/common/bazel.cc
index 1a9780d..75f2141 100644
--- a/common/bazel.cc
+++ b/common/bazel.cc
@@ -18,12 +18,12 @@
#include <cstdlib>
#include <string>
-#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -40,7 +40,7 @@
return absl::InfiniteDuration();
}
int timeout_s = 0;
- CHECK(absl::SimpleAtoi(test_timeout_env, &timeout_s))
+ FUZZTEST_CHECK(absl::SimpleAtoi(test_timeout_env, &timeout_s))
<< "Failed to parse TEST_TIMEOUT: \"" << test_timeout_env << "\"";
return absl::Seconds(timeout_s);
}
@@ -52,18 +52,20 @@
TestShard test_shard;
if (const char *test_total_shards_env = std::getenv("TEST_TOTAL_SHARDS");
test_total_shards_env != nullptr) {
- CHECK(absl::SimpleAtoi(test_total_shards_env, &test_shard.total_shards))
+ FUZZTEST_CHECK(
+ absl::SimpleAtoi(test_total_shards_env, &test_shard.total_shards))
<< "Failed to parse TEST_TOTAL_SHARDS as an integer: \""
<< test_total_shards_env << "\"";
- CHECK_GT(test_shard.total_shards, 0)
+ FUZZTEST_CHECK_GT(test_shard.total_shards, 0)
<< "TEST_TOTAL_SHARDS must be greater than 0.";
}
if (const char *test_shard_index_env = std::getenv("TEST_SHARD_INDEX");
test_shard_index_env != nullptr) {
- CHECK(absl::SimpleAtoi(test_shard_index_env, &test_shard.index))
+ FUZZTEST_CHECK(absl::SimpleAtoi(test_shard_index_env, &test_shard.index))
<< "Failed to parse TEST_SHARD_INDEX as an integer: \""
<< test_shard_index_env << "\"";
- CHECK(0 <= test_shard.index && test_shard.index < test_shard.total_shards)
+ FUZZTEST_CHECK(0 <= test_shard.index &&
+ test_shard.index < test_shard.total_shards)
<< "TEST_SHARD_INDEX must be in the range [0, "
<< test_shard.total_shards << ").";
}
@@ -102,7 +104,7 @@
// timeout. This case can only happen if we would in fact need more than
// `kMaxShardCount` shards, indicating that there are simply too many fuzz
// tests in a binary.
- CHECK_EQ(suggested_shard_count, kMaxShardCount);
+ FUZZTEST_CHECK_EQ(suggested_shard_count, kMaxShardCount);
absl::StrAppend(&error,
"split the fuzz tests into several test binaries where "
"each binary has at most ",
@@ -112,7 +114,7 @@
// In this case, `suggested_shard_count` must be greater than
// `shard_count`, otherwise we would have already executed all the tests
// without a timeout.
- CHECK_GT(suggested_shard_count, shard_count);
+ FUZZTEST_CHECK_GT(suggested_shard_count, shard_count);
absl::StrAppend(&error, "increase the `shard_count` to ",
suggested_shard_count, ", ");
}
diff --git a/common/blob_file.cc b/common/blob_file.cc
index dc9a40e..6193c4f 100644
--- a/common/blob_file.cc
+++ b/common/blob_file.cc
@@ -27,8 +27,6 @@
#include "absl/base/nullability.h"
#include "absl/base/optimization.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
@@ -71,7 +69,7 @@
~SimpleBlobFileReader() override {
if (file_ && !closed_) {
// Virtual resolution is off in dtors, so use a specific Close().
- CHECK_OK(SimpleBlobFileReader::Close());
+ FUZZTEST_CHECK_OK(SimpleBlobFileReader::Close());
}
}
@@ -125,12 +123,12 @@
~SimpleBlobFileWriter() override {
if (file_ && !closed_) {
// Virtual resolution is off in dtors, so use a specific Close().
- CHECK_OK(SimpleBlobFileWriter::Close());
+ FUZZTEST_CHECK_OK(SimpleBlobFileWriter::Close());
}
}
absl::Status Open(std::string_view path, std::string_view mode) override {
- CHECK(mode == "w" || mode == "a") << VV(mode);
+ FUZZTEST_CHECK(mode == "w" || mode == "a") << VV(mode);
if (closed_) return absl::FailedPreconditionError("already closed");
if (file_) return absl::FailedPreconditionError("already open");
ASSIGN_OR_RETURN_IF_NOT_OK(file_, RemoteFileOpen(path, mode.data()));
@@ -170,7 +168,7 @@
public:
~DefaultBlobFileReader() override {
// Virtual resolution is off in dtors, so use a specific Close().
- CHECK_OK(DefaultBlobFileReader::Close());
+ FUZZTEST_CHECK_OK(DefaultBlobFileReader::Close());
}
absl::Status Open(std::string_view path) override {
@@ -247,8 +245,8 @@
// TODO(b/313706444): Reconsider error handling after experiments.
// TODO(b/310701588): Try adding a test for this.
if (riegeli_reader_.ok() && !riegeli_reader_.Close()) {
- LOG(WARNING) << "Ignoring errors while closing Riegeli file: "
- << riegeli_reader_.status();
+ FUZZTEST_LOG(WARNING) << "Ignoring errors while closing Riegeli file: "
+ << riegeli_reader_.status();
}
// Any non-ok status of `riegeli_reader_` persists for subsequent
// operations; therefore, re-initialize it to a closed ok state.
@@ -272,11 +270,11 @@
public:
~RiegeliWriter() override {
// Virtual resolution is off in dtors, so use a specific Close().
- CHECK_OK(RiegeliWriter::Close());
+ FUZZTEST_CHECK_OK(RiegeliWriter::Close());
}
absl::Status Open(std::string_view path, std::string_view mode) override {
- CHECK(mode == "w" || mode == "a") << VV(mode);
+ FUZZTEST_CHECK(mode == "w" || mode == "a") << VV(mode);
if (absl::Status s = Close(); !s.ok()) return s;
const auto kWriterOpts =
riegeli::RecordWriterBase::Options{}.set_chunk_size(kMaxBufferedBytes);
@@ -305,7 +303,7 @@
if (!PostWriteFlush(blob.size())) return writer_.status();
write_duration_ += absl::Now() - now;
if (written_blobs_ + buffered_blobs_ % 10000 == 0)
- VLOG(10) << "Current stats: " << StatsString();
+ FUZZTEST_VLOG(10) << "Current stats: " << StatsString();
return absl::OkStatus();
}
@@ -322,7 +320,7 @@
written_bytes_ += buffered_bytes_;
buffered_blobs_ = 0;
buffered_bytes_ = 0;
- VLOG(1) << "Final stats: " << StatsString();
+ FUZZTEST_VLOG(1) << "Final stats: " << StatsString();
return absl::OkStatus();
}
@@ -358,7 +356,8 @@
: (absl::Now() - flushed_at_ > kMaxFlushInterval) ? "time"
: "";
if (!flush_reason.empty()) {
- VLOG(20) << "Flushing b/c " << flush_reason << ": " << StatsString();
+ FUZZTEST_VLOG(20) << "Flushing b/c " << flush_reason << ": "
+ << StatsString();
if (!writer_.Flush(riegeli::FlushType::kFromMachine)) return false;
flushed_at_ = absl::Now();
written_blobs_ += buffered_blobs_;
@@ -376,7 +375,8 @@
bool PostWriteFlush(size_t blob_size) {
const auto record_size = blob_size + kRiegeliPerRecordMetadataSize;
if (record_size >= kMaxBufferedBytes) {
- VLOG(20) << "Post-write flushing b/c blob size: " << StatsString();
+ FUZZTEST_VLOG(20) << "Post-write flushing b/c blob size: "
+ << StatsString();
if (!writer_.Flush(riegeli::FlushType::kFromMachine)) return false;
flushed_at_ = absl::Now();
written_blobs_ += 1;
@@ -446,7 +446,7 @@
ByteArray PackBytesForAppendFile(ByteSpan blob) {
ByteArray res;
auto hash = Hash(blob);
- CHECK_EQ(hash.size(), kHashLen);
+ FUZZTEST_CHECK_EQ(hash.size(), kHashLen);
size_t size = blob.size();
uint8_t size_bytes[sizeof(size)];
std::memcpy(size_bytes, &size, sizeof(size));
@@ -496,7 +496,8 @@
std::unique_ptr<BlobFileWriter> DefaultBlobFileWriterFactory(bool riegeli) {
if (riegeli)
#ifdef CENTIPEDE_DISABLE_RIEGELI
- LOG(FATAL) << "Riegeli unavailable: built with --use_riegeli set to false.";
+ FUZZTEST_LOG(FATAL)
+ << "Riegeli unavailable: built with --use_riegeli set to false.";
#else
return std::make_unique<RiegeliWriter>();
#endif // CENTIPEDE_DISABLE_RIEGELI
diff --git a/common/logging.h b/common/logging.h
index 7020085..8f25c92 100644
--- a/common/logging.h
+++ b/common/logging.h
@@ -15,13 +15,32 @@
#ifndef FUZZTEST_COMMON_LOGGING_H_
#define FUZZTEST_COMMON_LOGGING_H_
-// TODO(b/315519925): Temporary leftover from switching to now-available
-// OSS Abseil VLOG and friends. Explicitly include these wherever necessary and
-// remove from here.
-#include "absl/log/check.h" // IWYU pragma: keep
-#include "absl/log/log.h" // IWYU pragma: keep
+#include "absl/log/absl_check.h"
+#include "absl/log/absl_log.h"
-// Easy variable value logging: LOG(INFO) << VV(foo) << VV(bar);
+// Easy variable value logging: FUZZTEST_LOG(INFO) << VV(foo) << VV(bar);
#define VV(x) #x ": " << (x) << " "
+// NOTE: these macros are for internal use within the fuzztest codebase.
+#define FUZZTEST_LOG(severity) ABSL_LOG(severity)
+#define FUZZTEST_LOG_EVERY_POW_2(severity) ABSL_LOG_EVERY_POW_2(severity)
+#define FUZZTEST_LOG_FIRST_N(severity, n) ABSL_LOG_FIRST_N(severity, n)
+#define FUZZTEST_VLOG(verbose_level) ABSL_VLOG(verbose_level)
+#define FUZZTEST_VLOG_EVERY_N(verbose_level, n) \
+ ABSL_VLOG_EVERY_N(verbose_level, n)
+#define FUZZTEST_VLOG_IS_ON(verbose_level) ABSL_VLOG_IS_ON(verbose_level)
+#define FUZZTEST_LOG_IF(severity, condition) ABSL_LOG_IF(severity, condition)
+#define FUZZTEST_CHECK(cond) ABSL_CHECK(cond) << "Internal error: "
+#define FUZZTEST_PCHECK(cond) ABSL_PCHECK(cond) << "Internal error: "
+#define FUZZTEST_PRECONDITION(cond) ABSL_CHECK(cond) << "Failed precondition: "
+#define FUZZTEST_CHECK_OK(status) ABSL_CHECK_OK(status)
+#define FUZZTEST_CHECK_GT(a, b) ABSL_CHECK_GT(a, b)
+#define FUZZTEST_CHECK_GE(a, b) ABSL_CHECK_GE(a, b)
+#define FUZZTEST_CHECK_EQ(a, b) ABSL_CHECK_EQ(a, b)
+#define FUZZTEST_CHECK_NE(a, b) ABSL_CHECK_NE(a, b)
+#define FUZZTEST_CHECK_LE(a, b) ABSL_CHECK_LE(a, b)
+#define FUZZTEST_CHECK_LT(a, b) ABSL_CHECK_LT(a, b)
+#define FUZZTEST_QCHECK(cond) ABSL_QCHECK(cond)
+#define FUZZTEST_QCHECK_OK(status) ABSL_QCHECK_OK(status)
+
#endif // FUZZTEST_COMMON_LOGGING_H_
diff --git a/common/remote_file.cc b/common/remote_file.cc
index 714855e..b628ad6 100644
--- a/common/remote_file.cc
+++ b/common/remote_file.cc
@@ -21,7 +21,6 @@
#include <string_view>
#include "absl/base/nullability.h"
-#include "absl/log/check.h"
#include "absl/status/status.h"
#include "./common/defs.h"
#include "./common/logging.h"
diff --git a/common/remote_file_oss.cc b/common/remote_file_oss.cc
index 0f0acba..fb6f23a 100644
--- a/common/remote_file_oss.cc
+++ b/common/remote_file_oss.cc
@@ -37,8 +37,6 @@
#include <vector>
#include "absl/base/nullability.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
@@ -69,7 +67,8 @@
}
~LocalRemoteFile() {
- CHECK(file_ == nullptr) << "Dtor called before Close(): " << VV(path_);
+ FUZZTEST_CHECK(file_ == nullptr)
+ << "Dtor called before Close(): " << VV(path_);
}
// Movable but not copyable.
@@ -123,7 +122,7 @@
": ", std::strerror(errno)));
}
static constexpr auto elt_size = sizeof(ba[0]);
- CHECK_EQ(file_size % elt_size, 0)
+ FUZZTEST_CHECK_EQ(file_size % elt_size, 0)
<< VV(file_size) << VV(elt_size) << VV(path_);
if (file_size % elt_size != 0) {
return absl::FailedPreconditionError(
@@ -165,36 +164,36 @@
#if defined(FUZZTEST_STUB_STD_FILESYSTEM)
absl::Status RemoteMkdir(std::string_view path) {
- LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
bool RemotePathExists(std::string_view path) {
- LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
bool RemotePathIsDirectory(std::string_view path) {
- LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
absl::StatusOr<std::vector<std::string>> RemoteListFiles(std::string_view path,
bool recursively) {
- LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
absl::Status RemoteFileRename(std::string_view from, std::string_view to) {
- LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
absl::Status RemoteFileCopy(std::string_view from, std::string_view to) {
- LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
absl::Status RemotePathTouchExistingFile(std::string_view path) {
- LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
absl::Status RemotePathDelete(std::string_view path, bool recursively) {
- LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
#else
@@ -310,7 +309,7 @@
// TODO(ussuri): For now, simulate the old behavior, where a failure to open
// a file returned nullptr. Adjust the clients to expect non-null and use a
-// normal ctor with a CHECK instead of `Create()` here instead.
+// normal ctor with a FUZZTEST_CHECK instead of `Create()` here instead.
absl::StatusOr<RemoteFile *> RemoteFileOpen(std::string_view path,
const char *mode) {
return LocalRemoteFile::Create(std::string(path), mode);
@@ -367,7 +366,8 @@
#if defined(FUZZTEST_HAS_OSS_GLOB)
int HandleGlobError(const char *epath, int eerrno) {
if (eerrno == ENOENT) return 0;
- LOG(FATAL) << "Error while globbing path: " << VV(epath) << VV(eerrno);
+ FUZZTEST_LOG(FATAL) << "Error while globbing path: " << VV(epath)
+ << VV(eerrno);
return -1;
}
#endif // defined(FUZZTEST_HAS_OSS_GLOB)
diff --git a/common/remote_file_test.cc b/common/remote_file_test.cc
index ade0988..82fd85b 100644
--- a/common/remote_file_test.cc
+++ b/common/remote_file_test.cc
@@ -23,7 +23,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
@@ -40,9 +39,9 @@
void CreateFileOrDie(std::string_view path, std::string_view contents = "") {
std::ofstream f{std::string(path)};
- CHECK(f.good()) << VV(path);
+ FUZZTEST_CHECK(f.good()) << VV(path);
f << contents;
- CHECK(f.good()) << VV(path);
+ FUZZTEST_CHECK(f.good()) << VV(path);
}
TEST(RemoteFile, GetSize) {
@@ -137,7 +136,7 @@
TEST(RemotePathDelete, RecursivelyDeletesAllFilesAndSubdirectories) {
const fs::path temp_dir = GetTestTempDir(test_info_->name());
const fs::path a_b_c = temp_dir / "a" / "b" / "c";
- CHECK(fs::create_directories(a_b_c)) << VV(a_b_c);
+ FUZZTEST_CHECK(fs::create_directories(a_b_c)) << VV(a_b_c);
const std::string file_path = a_b_c / "file";
CreateFileOrDie(file_path);
diff --git a/common/status_macros.h b/common/status_macros.h
index 0fe940f..882f2f5 100644
--- a/common/status_macros.h
+++ b/common/status_macros.h
@@ -21,7 +21,7 @@
#include "absl/base/attributes.h"
#include "absl/base/optimization.h"
-#include "absl/log/log.h"
+#include "./common/logging.h"
// If `status_expr` (an expression of type `absl::Status`) is not OK then return
// it from the current function. Otherwise, do nothing.
@@ -55,8 +55,9 @@
std::uint_least32_t line = __builtin_LINE(),
const char* file_name = __builtin_FILE()) {
if (ABSL_PREDICT_FALSE(!value.ok())) {
- LOG(FATAL) << file_name << ":" << line
- << ": ValueOrDie on non-OK status: " << value.status();
+ FUZZTEST_CHECK(false) << file_name << ":" << line
+ << ": ValueOrDie on non-OK status: "
+ << value.status();
}
return *std::forward<T>(value);
}
diff --git a/common/temp_dir.cc b/common/temp_dir.cc
index e57e237..f9dba37 100644
--- a/common/temp_dir.cc
+++ b/common/temp_dir.cc
@@ -4,9 +4,9 @@
#include <filesystem> // NOLINT
#include <system_error> // NOLINT
-#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -18,24 +18,24 @@
if (temp_root.empty()) {
std::error_code error;
temp_root = std::filesystem::temp_directory_path(error);
- CHECK(!error) << "Failed to get the root temp directory path: "
- << error.message();
+ FUZZTEST_CHECK(!error) << "Failed to get the root temp directory path: "
+ << error.message();
}
absl::string_view prefix = custom_prefix.empty() ? "temp_dir" : custom_prefix;
const fs::path path_template = temp_root / absl::StrCat(prefix, "_XXXXXX");
#if !defined(_MSC_VER)
path_ = mkdtemp(path_template.string().data());
#else
- CHECK(false) << "Windows is not supported yet.";
+ FUZZTEST_CHECK(false) << "Windows is not supported yet.";
#endif
- CHECK(std::filesystem::is_directory(path_));
+ FUZZTEST_CHECK(std::filesystem::is_directory(path_));
}
TempDir::~TempDir() {
std::error_code error;
std::filesystem::remove_all(path_, error);
- CHECK(!error) << "Unable to clean up temporary dir " << path_ << ": "
- << error.message();
+ FUZZTEST_CHECK(!error) << "Unable to clean up temporary dir " << path_ << ": "
+ << error.message();
}
} // namespace fuzztest::internal
diff --git a/common/test_util.cc b/common/test_util.cc
index 368f673..3232d55 100644
--- a/common/test_util.cc
+++ b/common/test_util.cc
@@ -19,8 +19,6 @@
#include <system_error> // NOLINT
#include "gtest/gtest.h"
-#include "absl/log/check.h"
-#include "absl/log/log.h"
#include "absl/strings/str_cat.h"
#include "./common/logging.h"
@@ -28,13 +26,14 @@
std::filesystem::path GetTestTempDir(std::string_view subdir) {
const std::filesystem::path test_tempdir = ::testing::TempDir();
- CHECK(!test_tempdir.empty())
+ FUZZTEST_CHECK(!test_tempdir.empty())
<< "testing::TempDir() is expected to always return non-empty path";
const auto dir = test_tempdir / subdir;
if (!std::filesystem::exists(dir)) {
std::error_code error;
std::filesystem::create_directories(dir, error);
- CHECK(!error) << "Failed to create dir: " VV(dir) << error.message();
+ FUZZTEST_CHECK(!error) << "Failed to create dir: " VV(dir)
+ << error.message();
}
return std::filesystem::canonical(dir);
}
@@ -45,13 +44,13 @@
std::filesystem::path GetTestRunfilesDir() {
const auto test_srcdir = ::testing::SrcDir();
- CHECK(!test_srcdir.empty())
+ FUZZTEST_CHECK(!test_srcdir.empty())
<< "testing::SrcDir() is expected to always return non-empty path";
const char* test_workspace = std::getenv("TEST_WORKSPACE");
- CHECK(test_workspace != nullptr)
+ FUZZTEST_CHECK(test_workspace != nullptr)
<< "TEST_WORKSPACE envvar is expected to be set by build system";
auto path = std::filesystem::path{test_srcdir}.append(test_workspace);
- CHECK(std::filesystem::exists(path)) //
+ FUZZTEST_CHECK(std::filesystem::exists(path)) //
<< "No such dir: " << VV(path) << VV(test_srcdir) << VV(test_workspace);
return path;
}
@@ -60,19 +59,19 @@
const auto runfiles_dir = GetTestRunfilesDir();
auto path = runfiles_dir;
path.append(rel_path);
- CHECK(std::filesystem::exists(path)) //
+ FUZZTEST_CHECK(std::filesystem::exists(path)) //
<< "No such path: " << VV(path) << VV(runfiles_dir) << VV(rel_path);
return path;
}
std::string GetLLVMSymbolizerPath() {
- CHECK_EQ(system("which llvm-symbolizer"), EXIT_SUCCESS)
+ FUZZTEST_CHECK_EQ(system("which llvm-symbolizer"), EXIT_SUCCESS)
<< "llvm-symbolizer has to be installed and findable via PATH";
return "llvm-symbolizer";
}
std::string GetObjDumpPath() {
- CHECK_EQ(system("which objdump"), EXIT_SUCCESS)
+ FUZZTEST_CHECK_EQ(system("which objdump"), EXIT_SUCCESS)
<< "objdump has to be installed and findable via PATH";
return "objdump";
}
@@ -80,7 +79,7 @@
void PrependDirToPathEnvvar(std::string_view dir) {
const std::string new_path_envvar = absl::StrCat(dir, ":", getenv("PATH"));
setenv("PATH", new_path_envvar.c_str(), /*replace*/ 1);
- LOG(INFO) << "New PATH: " << new_path_envvar;
+ FUZZTEST_LOG(INFO) << "New PATH: " << new_path_envvar;
}
} // namespace fuzztest::internal
diff --git a/common/test_util.h b/common/test_util.h
index 11cc60c..c859bff 100644
--- a/common/test_util.h
+++ b/common/test_util.h
@@ -22,10 +22,10 @@
#include <string_view>
#include <vector>
-#include "absl/log/check.h"
#include "absl/strings/str_format.h"
#include "./common/blob_file.h"
#include "./common/defs.h"
+#include "./common/logging.h"
#include "./common/logging.h"
@@ -116,7 +116,7 @@
while (reader_->Read(blob).ok()) {
corpus.emplace_back(blob.begin(), blob.end());
}
- CHECK_OK(reader_->Close());
+ FUZZTEST_CHECK_OK(reader_->Close());
return corpus;
}
diff --git a/domain_tests/BUILD b/domain_tests/BUILD
index a2584b1..a558db2 100644
--- a/domain_tests/BUILD
+++ b/domain_tests/BUILD
@@ -126,6 +126,7 @@
"@abseil-cpp//absl/random:bit_gen_ref",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:logging",
"@com_google_fuzztest//fuzztest/internal:meta",
"@com_google_fuzztest//fuzztest/internal:serialization",
diff --git a/domain_tests/domain_testing.h b/domain_tests/domain_testing.h
index e8b9009..9574b58 100644
--- a/domain_tests/domain_testing.h
+++ b/domain_tests/domain_testing.h
@@ -35,6 +35,7 @@
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/mutation_metadata.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/meta.h"
@@ -145,8 +146,8 @@
Value(const Domain& domain, T user_value)
: corpus_value([&]() {
auto corpus_value = domain.FromValue(user_value);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(corpus_value.has_value(),
- "Invalid user_value!");
+ FUZZTEST_PRECONDITION(corpus_value.has_value())
+ << "Invalid user_value!";
return *corpus_value;
}()),
user_value(std::move(user_value)) {}
diff --git a/e2e_tests/BUILD b/e2e_tests/BUILD
index 78cb11b..9ca044f 100644
--- a/e2e_tests/BUILD
+++ b/e2e_tests/BUILD
@@ -25,10 +25,10 @@
hdrs = ["test_binary_util.h"],
deps = [
"@abseil-cpp//absl/container:flat_hash_map",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:string_view",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:flag_name",
"@com_google_fuzztest//fuzztest/internal:subprocess",
],
@@ -65,6 +65,7 @@
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
"@com_google_fuzztest//centipede:weak_sancov_stubs",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:temp_dir",
"@com_google_fuzztest//fuzztest/internal:escaping",
"@com_google_fuzztest//fuzztest/internal:io",
@@ -91,7 +92,7 @@
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
- "@com_google_fuzztest//fuzztest/internal:logging",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:subprocess",
"@re2",
],
@@ -146,7 +147,6 @@
":test_binary_util",
"@abseil-cpp//absl/base:no_destructor",
"@abseil-cpp//absl/container:flat_hash_map",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
diff --git a/e2e_tests/benchmark_test.cc b/e2e_tests/benchmark_test.cc
index feaa786..ef6146c 100644
--- a/e2e_tests/benchmark_test.cc
+++ b/e2e_tests/benchmark_test.cc
@@ -37,7 +37,7 @@
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "absl/time/time.h"
-#include "./fuzztest/internal/logging.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/subprocess.h"
#include "re2/re2.h"
@@ -65,7 +65,7 @@
std::string SelfPath() {
char buf[4096];
ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf));
- FUZZTEST_INTERNAL_CHECK(len < sizeof(buf), "Path too long!");
+ FUZZTEST_CHECK(len < sizeof(buf)) << "Path too long!";
return std::string(buf, len);
}
std::string MicrobenchmarksBinaryPath() {
@@ -73,28 +73,30 @@
const std::size_t dir_path_len = self_path.find_last_of('/');
std::string binary_path = self_path.substr(0, dir_path_len) +
"/testdata/fuzz_tests_for_microbenchmarking";
- FUZZTEST_INTERNAL_CHECK(std::filesystem::exists(binary_path), "Can't find ",
- binary_path);
+ FUZZTEST_CHECK(std::filesystem::exists(binary_path))
+ << "Can't find " << binary_path;
return binary_path;
}
uint64_t ExtractTime(absl::string_view output) {
static constexpr LazyRE2 kElapsedTimeRE = {"\nElapsed time: (.+)\n"};
std::string duration_str;
- FUZZTEST_INTERNAL_CHECK(
- RE2::PartialMatch(output, *kElapsedTimeRE, &duration_str),
- "\n\nCould not find:\n\nElapsed time:\n\nin:\n\n", output);
+ FUZZTEST_CHECK(RE2::PartialMatch(output, *kElapsedTimeRE, &duration_str))
+ << "\n\nCould not find:\n\nElapsed time:\n\nin:\n\n"
+ << output;
absl::Duration duration;
- FUZZTEST_INTERNAL_CHECK(absl::ParseDuration(duration_str, &duration),
- "Could not parse duration:", duration_str);
+ FUZZTEST_CHECK(absl::ParseDuration(duration_str, &duration))
+ << "Could not parse duration:" << duration_str;
return absl::ToInt64Nanoseconds(duration);
}
uint64_t ExtractNumber(absl::string_view output, absl::string_view name) {
uint64_t number;
- FUZZTEST_INTERNAL_CHECK(
- RE2::PartialMatch(output, absl::StrCat("\n", name, ": (.+)\n"), &number),
- "\n\nCould not find\n\n", name, ":\n\nin:\n\n", output);
+ FUZZTEST_CHECK(
+ RE2::PartialMatch(output, absl::StrCat("\n", name, ": (.+)\n"), &number))
+ << "\n\nCould not find\n\n"
+ << name << ":\n\nin:\n\n"
+ << output;
return number;
}
@@ -141,8 +143,8 @@
// This measures the cost of the framework on processing the edge map.
// This way we can see if differences in a CL come from edge count
// change or from implementation changes.
- FUZZTEST_INTERNAL_CHECK(result.stats.total_edges != 0,
- "Total edges cannot be zero!");
+ FUZZTEST_CHECK(result.stats.total_edges != 0)
+ << "Total edges cannot be zero!";
json_results.push_back(SingleJsonResult(
"Control.Edges10000(time)",
10000 * result.stats.nanos / result.stats.total_edges));
@@ -226,8 +228,7 @@
int main(int argc, char** argv) {
#if defined(__has_feature)
#if !__has_feature(coverage_sanitizer)
- FUZZTEST_INTERNAL_CHECK(false,
- "\n\nPlease compile with --config=fuzztest.\n");
+ FUZZTEST_CHECK(false) << "\n\nPlease compile with --config=fuzztest.\n";
#endif
#endif
absl::ParseCommandLine(argc, argv);
diff --git a/e2e_tests/corpus_database_test.cc b/e2e_tests/corpus_database_test.cc
index 98422cd..af147ec 100644
--- a/e2e_tests/corpus_database_test.cc
+++ b/e2e_tests/corpus_database_test.cc
@@ -22,7 +22,6 @@
#include "gtest/gtest.h"
#include "absl/base/no_destructor.h"
#include "absl/container/flat_hash_map.h"
-#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
@@ -75,11 +74,12 @@
static void SetUpTestSuite() {
#if defined(__has_feature)
#if !__has_feature(address_sanitizer)
- CHECK(false) << "The test binary is not built with ASAN. Please run with "
- "--config=asan.";
+ FUZZTEST_CHECK(false)
+ << "The test binary is not built with ASAN. Please run with "
+ "--config=asan.";
#elif !__has_feature(coverage_sanitizer) || !defined(FUZZTEST_USE_CENTIPEDE)
- CHECK(false) << "The test binary is not built with coverage "
- "instrumentation for Centipede. "
+ FUZZTEST_CHECK(false) << "The test binary is not built with coverage "
+ "instrumentation for Centipede. "
"Please run with --config=fuzztest-experimental.";
#endif
#endif
@@ -146,7 +146,7 @@
return RunBinary(CentipedePath(), centipede_options);
}
}
- FUZZTEST_INTERNAL_CHECK(false, "Unsupported execution model!\n");
+ FUZZTEST_INTERNAL_FUZZTEST_CHECK(false, "Unsupported execution model!\n");
}
private:
diff --git a/e2e_tests/functional_test.cc b/e2e_tests/functional_test.cc
index 9ee676e..591013b 100644
--- a/e2e_tests/functional_test.cc
+++ b/e2e_tests/functional_test.cc
@@ -33,6 +33,7 @@
#include "absl/strings/substitute.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
#include "./common/temp_dir.h"
#include "./e2e_tests/test_binary_util.h"
#include "./fuzztest/internal/escaping.h"
@@ -1288,7 +1289,7 @@
return RunBinary(CentipedePath(), run_options);
}
}
- FUZZTEST_INTERNAL_CHECK(false, "Unsupported execution model!\n");
+ FUZZTEST_CHECK(false) << "Unsupported execution model!\n";
}
};
diff --git a/e2e_tests/test_binary_util.cc b/e2e_tests/test_binary_util.cc
index 7aac989..0fe3112 100644
--- a/e2e_tests/test_binary_util.cc
+++ b/e2e_tests/test_binary_util.cc
@@ -20,10 +20,10 @@
#include <system_error> // NOLINT
#include <vector>
-#include "absl/log/check.h"
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/flag_name.h"
#include "./fuzztest/internal/subprocess.h"
@@ -34,12 +34,14 @@
// root.
std::string GetFullPath(const std::filesystem::path& relative_path) {
const auto test_srcdir = absl::NullSafeStringView(std::getenv("TEST_SRCDIR"));
- CHECK(!test_srcdir.empty()) << "Please set TEST_SRCDIR to non-empty value or "
- "use bazel to run the test.";
+ FUZZTEST_CHECK(!test_srcdir.empty())
+ << "Please set TEST_SRCDIR to non-empty value or "
+ "use bazel to run the test.";
const std::string full_path =
std::filesystem::path(test_srcdir) / "_main"
/ relative_path;
- CHECK(std::filesystem::exists(full_path)) << "Can't find " << full_path;
+ FUZZTEST_CHECK(std::filesystem::exists(full_path))
+ << "Can't find " << full_path;
return full_path;
}
diff --git a/e2e_tests/testdata/BUILD b/e2e_tests/testdata/BUILD
index 3c623f3..b21cb8f 100644
--- a/e2e_tests/testdata/BUILD
+++ b/e2e_tests/testdata/BUILD
@@ -50,7 +50,6 @@
"@abseil-cpp//absl/algorithm:container",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"@abseil-cpp//absl/types:span",
@@ -93,13 +92,13 @@
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/functional:function_ref",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/random:bit_gen_ref",
"@abseil-cpp//absl/random:distributions",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest",
"@com_google_fuzztest//fuzztest:fuzztest_gtest_main",
"@com_google_fuzztest//fuzztest:googletest_fixture_adapter",
diff --git a/e2e_tests/testdata/fuzz_tests_for_functional_testing.cc b/e2e_tests/testdata/fuzz_tests_for_functional_testing.cc
index 8049505..17df652 100644
--- a/e2e_tests/testdata/fuzz_tests_for_functional_testing.cc
+++ b/e2e_tests/testdata/fuzz_tests_for_functional_testing.cc
@@ -38,6 +38,7 @@
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/test_protobuf.pb.h"
#include "google/protobuf/descriptor.h"
@@ -735,12 +736,11 @@
// where the callbacks from the signal handler happen in a separate stack.
new_sigact.sa_flags = SA_SIGINFO | SA_ONSTACK;
- FUZZTEST_INTERNAL_CHECK(sigaction(SIGUSR1, &new_sigact, nullptr) == 0,
- errno);
+ FUZZTEST_CHECK(sigaction(SIGUSR1, &new_sigact, nullptr) == 0) << errno;
stack_t test_stack = {};
test_stack.ss_size = 1 << 20;
test_stack.ss_sp = malloc(test_stack.ss_size);
- FUZZTEST_INTERNAL_CHECK(sigaltstack(&test_stack, &old_stack) == 0, errno);
+ FUZZTEST_CHECK(sigaltstack(&test_stack, &old_stack) == 0) << errno;
}
void StackCalculationWorksWithAlternateStackForSignalHandlers(int i) {
@@ -750,7 +750,7 @@
// "stack overflow" detection and we will continue here.
raise(SIGUSR1);
// Just make sure the signal handler ran.
- FUZZTEST_INTERNAL_CHECK(dummy_to_trigger_cmp_in_handler != 0, "");
+ FUZZTEST_CHECK(dummy_to_trigger_cmp_in_handler != 0);
if (i == 123456789) {
std::abort();
@@ -760,7 +760,7 @@
~AlternateSignalStackFixture() {
stack_t test_stack = {};
// Resume to the old signal stack.
- FUZZTEST_INTERNAL_CHECK(sigaltstack(&old_stack, &test_stack) == 0, errno);
+ FUZZTEST_CHECK(sigaltstack(&old_stack, &test_stack) == 0) << errno;
free(test_stack.ss_sp);
}
diff --git a/e2e_tests/testdata/fuzz_tests_with_proto_inputs.cc b/e2e_tests/testdata/fuzz_tests_with_proto_inputs.cc
index 5fbc362..5cc7ee1 100644
--- a/e2e_tests/testdata/fuzz_tests_with_proto_inputs.cc
+++ b/e2e_tests/testdata/fuzz_tests_with_proto_inputs.cc
@@ -30,7 +30,6 @@
#include "absl/algorithm/container.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
-#include "absl/log/check.h"
#include "absl/strings/str_cat.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
diff --git a/fuzztest/BUILD b/fuzztest/BUILD
index 7dc2a14..11ef509 100644
--- a/fuzztest/BUILD
+++ b/fuzztest/BUILD
@@ -79,6 +79,7 @@
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:string_view",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:logging",
"@com_google_fuzztest//fuzztest/internal:registration",
"@com_google_fuzztest//fuzztest/internal:registry",
@@ -91,9 +92,9 @@
srcs = ["fuzztest_macros_test.cc"],
deps = [
":fuzztest_macros",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:temp_dir",
"@googletest//:gtest_main",
],
@@ -124,6 +125,7 @@
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:configuration",
"@com_google_fuzztest//fuzztest/internal:flag_name",
"@com_google_fuzztest//fuzztest/internal:googletest_adaptor",
@@ -160,12 +162,11 @@
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/base:no_destructor",
"@abseil-cpp//absl/flags:flag",
- "@abseil-cpp//absl/log:absl_check",
"@abseil-cpp//absl/random",
"@abseil-cpp//absl/random:bit_gen_ref",
"@abseil-cpp//absl/synchronization",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:io",
- "@com_google_fuzztest//fuzztest/internal:logging",
"@com_google_fuzztest//fuzztest/internal/domains:core_domains_impl",
],
alwayslink = True,
@@ -193,6 +194,7 @@
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings:string_view",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:any",
"@com_google_fuzztest//fuzztest/internal:logging",
"@com_google_fuzztest//fuzztest/internal:meta",
diff --git a/fuzztest/domain_core.h b/fuzztest/domain_core.h
index 926aba4..86a520e 100644
--- a/fuzztest/domain_core.h
+++ b/fuzztest/domain_core.h
@@ -44,6 +44,7 @@
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/any.h"
#include "./fuzztest/internal/domains/aggregate_of_impl.h"
#include "./fuzztest/internal/domains/arbitrary_impl.h"
@@ -83,18 +84,18 @@
// values it can handle until we call Set on the name.
template <typename T>
Domain<T> Get(std::string_view name) {
- FUZZTEST_INTERNAL_CHECK(domain_lookup_table_ != nullptr,
- "Finalize() has been called!");
+ FUZZTEST_CHECK(domain_lookup_table_ != nullptr)
+ << "Finalize() has been called!";
return IndirectDomain<T>(GetIndirect<T>(name));
}
template <typename T>
void Set(std::string_view name, const Domain<T>& domain) {
- FUZZTEST_INTERNAL_CHECK(domain_lookup_table_ != nullptr,
- "Finalize() has been called!");
+ FUZZTEST_CHECK(domain_lookup_table_ != nullptr)
+ << "Finalize() has been called!";
auto* indirect = GetIndirect<T>(name);
- FUZZTEST_INTERNAL_CHECK(!indirect->has_value(),
- "Cannot set the same domain twice!");
+ FUZZTEST_CHECK(!indirect->has_value())
+ << "Cannot set the same domain twice!";
*indirect = internal::MoveOnlyAny(std::in_place_type<Domain<T>>, domain);
}
@@ -105,18 +106,17 @@
// anymore.
template <typename T>
Domain<T> Finalize(std::string_view name) && {
- FUZZTEST_INTERNAL_CHECK(domain_lookup_table_ != nullptr,
- "Finalize() has been called!");
- FUZZTEST_INTERNAL_CHECK(
- GetIndirect<T>(name)->has_value(),
- // FUZZTEST_INTERNAL_CHECK uses absl::StrCat, which does not accept
+ FUZZTEST_CHECK(domain_lookup_table_ != nullptr)
+ << "Finalize() has been called!";
+ FUZZTEST_CHECK(GetIndirect<T>(name)->has_value())
+ <<
+ // FUZZTEST_CHECK uses absl::StrCat, which does not accept
// std::string_view in iOS builds, so convert to absl::string_view.
- "Finalize() has been called with an unknown name: ",
- absl::string_view{name.data(), name.size()});
+ "Finalize() has been called with an unknown name: "
+ << absl::string_view{name.data(), name.size()};
for (auto& iter : *domain_lookup_table_) {
- FUZZTEST_INTERNAL_CHECK(
- iter.second != nullptr && iter.second->has_value(),
- "Some domain is not set yet!");
+ FUZZTEST_CHECK(iter.second != nullptr && iter.second->has_value())
+ << "Some domain is not set yet!";
}
auto domain = GetIndirect<T>(name)->template GetAs<Domain<T>>();
return OwningDomain<T>(std::move(domain), std::move(domain_lookup_table_));
@@ -140,9 +140,8 @@
if (!indirection) {
indirection = std::make_unique<internal::MoveOnlyAny>();
}
- FUZZTEST_INTERNAL_CHECK(
- !indirection->has_value() || indirection->Has<Domain<T>>(),
- "The indirection must either be empty or hold a value of Domain<T>");
+ FUZZTEST_CHECK(!indirection->has_value() || indirection->Has<Domain<T>>())
+ << "The indirection must either be empty or hold a value of Domain<T>";
return indirection.get();
}
diff --git a/fuzztest/fuzztest_macros.cc b/fuzztest/fuzztest_macros.cc
index c8b5da3..ee3b1c5 100644
--- a/fuzztest/fuzztest_macros.cc
+++ b/fuzztest/fuzztest_macros.cc
@@ -32,6 +32,7 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/runtime.h"
@@ -88,17 +89,17 @@
std::string_view dir, std::function<bool(std::string_view)> filter) {
std::vector<std::tuple<std::string>> out;
const std::filesystem::path fs_dir(dir);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(std::filesystem::is_directory(fs_dir),
- "Not a directory: ", fs_dir.string());
+ FUZZTEST_PRECONDITION(std::filesystem::is_directory(fs_dir))
+ << "Not a directory: " << fs_dir.string();
for (const auto& entry :
std::filesystem::recursive_directory_iterator(fs_dir)) {
if (std::filesystem::is_directory(entry)) continue;
if (!filter(entry.path().string())) continue;
std::ifstream stream(entry.path());
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- stream.good(), "Cannot read input file: ", entry.path().string(), ": ",
- strerror(errno));
+ FUZZTEST_PRECONDITION(stream.good())
+ << "Cannot read input file: " << entry.path().string() << ": "
+ << strerror(errno);
std::stringstream buffer;
buffer << stream.rdbuf();
@@ -145,20 +146,19 @@
std::vector<std::string> ReadDictionaryFromFile(
std::string_view dictionary_file) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !std::filesystem::is_directory(dictionary_file),
- "Not a file: ", dictionary_file);
+ FUZZTEST_PRECONDITION(!std::filesystem::is_directory(dictionary_file))
+ << "Not a file: " << dictionary_file;
const std::filesystem::path fs_path(dictionary_file);
std::ifstream stream(fs_path);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(stream.good(), "Error reading ",
- fs_path.string(), ": ", strerror(errno));
+ FUZZTEST_PRECONDITION(stream.good())
+ << "Error reading " << fs_path.string() << ": " << strerror(errno);
std::stringstream buffer;
buffer << stream.rdbuf();
absl::StatusOr<std::vector<std::string>> parsed_entries =
ParseDictionary(buffer.str());
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- parsed_entries.status().ok(), "Could not parse dictionary file ",
- fs_path.string(), ": ", parsed_entries.status());
+ FUZZTEST_PRECONDITION(parsed_entries.status().ok())
+ << "Could not parse dictionary file " << fs_path.string() << ": "
+ << parsed_entries.status();
return *parsed_entries;
}
diff --git a/fuzztest/fuzztest_macros_test.cc b/fuzztest/fuzztest_macros_test.cc
index 0ddc009..41f44d9 100644
--- a/fuzztest/fuzztest_macros_test.cc
+++ b/fuzztest/fuzztest_macros_test.cc
@@ -8,9 +8,9 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/match.h"
+#include "./common/logging.h"
#include "./common/temp_dir.h"
namespace fuzztest::internal {
@@ -24,7 +24,7 @@
void WriteFile(const std::string& file_name, const std::string& contents) {
std::ofstream f(file_name);
- CHECK(f.is_open());
+ FUZZTEST_CHECK(f.is_open());
f << contents;
f.close();
}
diff --git a/fuzztest/init_fuzztest.cc b/fuzztest/init_fuzztest.cc
index 39b6d59..421c0d8 100644
--- a/fuzztest/init_fuzztest.cc
+++ b/fuzztest/init_fuzztest.cc
@@ -30,6 +30,7 @@
#include "absl/strings/string_view.h"
#include "absl/strings/strip.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/configuration.h"
#include "./fuzztest/internal/flag_name.h"
#include "./fuzztest/internal/googletest_adaptor.h"
@@ -189,12 +190,12 @@
"Internal-only flag - do not use directly. If set, only perform operations "
"for the exact fuzz test regardless of other flags.")
.OnUpdate([] {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
+ FUZZTEST_PRECONDITION(
!absl::GetFlag(FUZZTEST_FLAG(internal_override_fuzz_test))
- .has_value() ||
- std::getenv("CENTIPEDE_RUNNER_FLAGS") != nullptr,
- "must not set --" FUZZTEST_FLAG_PREFIX
- "internal_override_fuzz_test directly");
+ .has_value() ||
+ std::getenv("CENTIPEDE_RUNNER_FLAGS") != nullptr)
+ << "must not set --" FUZZTEST_FLAG_PREFIX
+ "internal_override_fuzz_test directly";
});
FUZZTEST_DEFINE_FLAG(
@@ -205,12 +206,12 @@
"--" FUZZTEST_FLAG_PREFIX "fuzz_for / --" FUZZTEST_FLAG_PREFIX
"replay_corpus_for with --time_budget_type set to total.")
.OnUpdate([] {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
+ FUZZTEST_PRECONDITION(
absl::GetFlag(FUZZTEST_FLAG(internal_override_total_time_limit)) ==
- absl::InfiniteDuration() ||
- std::getenv("CENTIPEDE_RUNNER_FLAGS") != nullptr,
- "must not set --" FUZZTEST_FLAG_PREFIX
- "internal_override_total_time_limit directly");
+ absl::InfiniteDuration() ||
+ std::getenv("CENTIPEDE_RUNNER_FLAGS") != nullptr)
+ << "must not set --" FUZZTEST_FLAG_PREFIX
+ "internal_override_total_time_limit directly";
});
FUZZTEST_DEFINE_FLAG(std::optional<std::string>,
@@ -220,12 +221,12 @@
"internal_override_fuzz_test are set, replay "
"the input in the corpus database with the specified ID.")
.OnUpdate([] {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
+ FUZZTEST_PRECONDITION(
!absl::GetFlag(FUZZTEST_FLAG(internal_crashing_input_to_reproduce))
- .has_value() ||
- std::getenv("CENTIPEDE_RUNNER_FLAGS") != nullptr,
- "must not set --" FUZZTEST_FLAG_PREFIX
- "internal_crashing_input_to_reproduce directly");
+ .has_value() ||
+ std::getenv("CENTIPEDE_RUNNER_FLAGS") != nullptr)
+ << "must not set --" FUZZTEST_FLAG_PREFIX
+ "internal_crashing_input_to_reproduce directly";
});
namespace fuzztest {
@@ -324,8 +325,9 @@
? internal::TimeBudgetType::kTotal
: absl::GetFlag(FUZZTEST_FLAG(time_budget_type));
const std::optional<size_t> jobs = absl::GetFlag(FUZZTEST_FLAG(jobs));
- FUZZTEST_INTERNAL_CHECK(!jobs.has_value() || *jobs > 0, "If specified, --",
- FUZZTEST_FLAG(jobs).Name(), " must be positive.");
+ FUZZTEST_CHECK(!jobs.has_value() || *jobs > 0)
+ << "If specified, --" << FUZZTEST_FLAG(jobs).Name()
+ << " must be positive.";
return internal::Configuration{
absl::GetFlag(FUZZTEST_FLAG(corpus_database)),
/*stats_root=*/"",
@@ -378,9 +380,8 @@
std::optional<absl::Duration> fuzzing_time_limit = GetFuzzingTime();
std::optional<absl::Duration> replay_corpus_time_limit =
GetReplayCorpusTime();
- FUZZTEST_INTERNAL_CHECK(
- !fuzzing_time_limit || !replay_corpus_time_limit,
- "Cannot run in fuzzing and corpus replay mode at the same time.");
+ FUZZTEST_CHECK(!fuzzing_time_limit || !replay_corpus_time_limit)
+ << "Cannot run in fuzzing and corpus replay mode at the same time.";
const auto test_to_fuzz = absl::GetFlag(FUZZTEST_FLAG(fuzz));
const auto test_to_replay_corpus =
absl::GetFlag(FUZZTEST_FLAG(replay_corpus));
diff --git a/fuzztest/internal/BUILD b/fuzztest/internal/BUILD
index 5f88da0..01f5c94 100644
--- a/fuzztest/internal/BUILD
+++ b/fuzztest/internal/BUILD
@@ -24,6 +24,7 @@
deps = [
":logging",
":meta",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -56,7 +57,6 @@
"@abseil-cpp//absl/algorithm:container",
"@abseil-cpp//absl/base:no_destructor",
"@abseil-cpp//absl/functional:any_invocable",
- "@abseil-cpp//absl/log:absl_log",
"@abseil-cpp//absl/memory",
"@abseil-cpp//absl/random",
"@abseil-cpp//absl/random:distributions",
@@ -78,6 +78,7 @@
"@com_google_fuzztest//centipede:stop",
"@com_google_fuzztest//centipede:workdir",
"@com_google_fuzztest//common:defs",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:remote_file",
"@com_google_fuzztest//common:temp_dir",
"@com_google_fuzztest//fuzztest/internal/domains:core_domains_impl",
@@ -107,12 +108,12 @@
srcs = ["configuration.cc"],
hdrs = ["configuration.h"],
deps = [
- "@abseil-cpp//absl/log:absl_check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:string_view",
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -155,7 +156,7 @@
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/types:span",
- "@com_google_fuzztest//fuzztest/internal/domains:core_domains_impl",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -196,6 +197,7 @@
":registration",
"@abseil-cpp//absl/functional:any_invocable",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest:domain_core",
"@googletest//:gtest_main",
],
@@ -243,6 +245,7 @@
"@abseil-cpp//absl/types:span",
"@com_google_fuzztest//common:blob_file",
"@com_google_fuzztest//common:defs",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:remote_file",
] + select({
"//conditions:default": [],
@@ -254,7 +257,6 @@
srcs = ["io_test.cc"],
deps = [
":io",
- "@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
@@ -274,6 +276,7 @@
"@abseil-cpp//absl/base:core_headers",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/synchronization",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -299,9 +302,9 @@
deps = [
"@abseil-cpp//absl/base:fast_type_id",
"@abseil-cpp//absl/functional:function_ref",
- "@abseil-cpp//absl/log:absl_check",
"@abseil-cpp//absl/random:distributions",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -360,7 +363,6 @@
"@abseil-cpp//absl/functional:any_invocable",
"@abseil-cpp//absl/functional:bind_front",
"@abseil-cpp//absl/functional:function_ref",
- "@abseil-cpp//absl/log:absl_check",
"@abseil-cpp//absl/random",
"@abseil-cpp//absl/random:bit_gen_ref",
"@abseil-cpp//absl/random:distributions",
@@ -371,6 +373,7 @@
"@abseil-cpp//absl/time",
"@abseil-cpp//absl/types:span",
"@com_google_fuzztest//common:bazel",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal/domains:core_domains_impl",
],
)
@@ -400,6 +403,7 @@
"@abseil-cpp//absl/random",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
],
)
@@ -454,12 +458,12 @@
srcs = ["subprocess.cc"],
hdrs = ["subprocess.h"],
deps = [
- ":logging",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/functional:function_ref",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
],
)
diff --git a/fuzztest/internal/any.h b/fuzztest/internal/any.h
index 6c26c97..184e3a7 100644
--- a/fuzztest/internal/any.h
+++ b/fuzztest/internal/any.h
@@ -20,6 +20,7 @@
#include <type_traits>
#include <utility>
+#include "./common/logging.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/meta.h"
@@ -44,8 +45,8 @@
}
bool has_value() const {
- FUZZTEST_INTERNAL_CHECK((vtable_ == nullptr) == (value_ == nullptr),
- "Inconsistent state between value and vtable.");
+ FUZZTEST_CHECK((vtable_ == nullptr) == (value_ == nullptr))
+ << "Inconsistent state between value and vtable.";
return value_ != nullptr;
}
@@ -56,29 +57,29 @@
template <typename T>
T& GetAs() & {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(has_value(), "Object is empty!");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(Has<T>(), "Wrong type!");
+ FUZZTEST_PRECONDITION(has_value()) << "Object is empty!";
+ FUZZTEST_PRECONDITION(Has<T>()) << "Wrong type!";
return *static_cast<T*>(value_);
}
template <typename T>
const T& GetAs() const& {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(has_value(), "Object is empty!");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(Has<T>(), "Wrong type!");
+ FUZZTEST_PRECONDITION(has_value()) << "Object is empty!";
+ FUZZTEST_PRECONDITION(Has<T>()) << "Wrong type!";
return *static_cast<T*>(value_);
}
template <typename T>
T&& GetAs() && {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(has_value(), "Object is empty!");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(Has<T>(), "Wrong type!");
+ FUZZTEST_PRECONDITION(has_value()) << "Object is empty!";
+ FUZZTEST_PRECONDITION(Has<T>()) << "Wrong type!";
return std::move(*static_cast<T*>(value_));
}
template <typename T>
const T&& GetAs() const&& {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(has_value(), "Object is empty!");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(Has<T>(), "Wrong type!");
+ FUZZTEST_PRECONDITION(has_value()) << "Object is empty!";
+ FUZZTEST_PRECONDITION(Has<T>()) << "Wrong type!";
return std::move(*static_cast<const T*>(value_));
}
@@ -104,7 +105,7 @@
}
void CopyFrom(const AnyBase& other) {
- FUZZTEST_INTERNAL_CHECK(!has_value(), "CopyFrom called on a full object");
+ FUZZTEST_CHECK(!has_value()) << "CopyFrom called on a full object";
if (other.has_value()) {
vtable_ = other.vtable_;
value_ = vtable_->copy(other.value_);
diff --git a/fuzztest/internal/centipede_adaptor.cc b/fuzztest/internal/centipede_adaptor.cc
index 13833ca..8266266 100644
--- a/fuzztest/internal/centipede_adaptor.cc
+++ b/fuzztest/internal/centipede_adaptor.cc
@@ -48,7 +48,6 @@
#include "absl/algorithm/container.h"
#include "absl/base/no_destructor.h"
#include "absl/functional/any_invocable.h"
-#include "absl/log/absl_log.h"
#include "absl/memory/memory.h"
#include "absl/random/distributions.h"
#include "absl/random/random.h"
@@ -75,6 +74,7 @@
#include "./centipede/stop.h"
#include "./centipede/workdir.h"
#include "./common/defs.h"
+#include "./common/logging.h"
#include "./common/remote_file.h"
#include "./common/temp_dir.h"
#include "./fuzztest/internal/any.h"
@@ -209,19 +209,17 @@
std::numeric_limits<decltype(env.timeout_per_input)>::max());
}
constexpr size_t kMiB = 1024 * 1024;
- FUZZTEST_INTERNAL_CHECK(configuration.rss_limit % kMiB == 0,
- "configuration.rss_limit is not a multiple of MiB.");
+ FUZZTEST_CHECK(configuration.rss_limit % kMiB == 0)
+ << "configuration.rss_limit is not a multiple of MiB.";
env.rss_limit_mb = configuration.rss_limit / kMiB;
constexpr size_t kKiB = 1024;
- FUZZTEST_INTERNAL_CHECK(
- configuration.stack_limit % kKiB == 0,
- "configuration.stack_limit is not a multiple of KiB.");
+ FUZZTEST_CHECK(configuration.stack_limit % kKiB == 0)
+ << "configuration.stack_limit is not a multiple of KiB.";
env.stack_limit_kb = configuration.stack_limit / kKiB;
env.populate_binary_info = false;
const auto args = GetProcessArgs();
- FUZZTEST_INTERNAL_CHECK(
- args.ok(),
- absl::StrCat("failed to get the original process args: ", args.status()));
+ FUZZTEST_CHECK(args.ok()) << absl::StrCat(
+ "failed to get the original process args: ", args.status());
env.binary.clear();
for (const auto& arg : *args) {
// We need shell escaping, because env.binary will be passed to system(),
@@ -348,9 +346,9 @@
// needs to be properly handled.
new_sigact.sa_flags = SA_ONSTACK;
- FUZZTEST_INTERNAL_CHECK(sigaction(signum, &new_sigact, nullptr) == 0,
- "Error installing signal handler: %s\n",
- strerror(errno));
+ FUZZTEST_CHECK(sigaction(signum, &new_sigact, nullptr) == 0)
+ << "Error installing signal handler: %s\n"
+ << strerror(errno);
}
return true;
}();
@@ -387,8 +385,8 @@
// Encoding signaled exit similarly as Bash.
return 128 + static_cast<int>(std::get<SignalT>(status.Status()));
}
- FUZZTEST_INTERNAL_CHECK(
- status.Exited(), "Termination status must be Exited if not Signaled");
+ FUZZTEST_CHECK(status.Exited())
+ << "Termination status must be Exited if not Signaled";
return static_cast<int>(std::get<ExitCodeT>(status.Status()));
}
static absl::NoDestructor<DefaultCallbacksFactory<CentipedeDefaultCallbacks>>
@@ -557,8 +555,8 @@
metadata->ForEachCmpEntry(
[&cmp_tables](fuzztest::internal::ByteSpan a,
fuzztest::internal::ByteSpan b) {
- FUZZTEST_INTERNAL_CHECK(a.size() == b.size(),
- "cmp operands must have the same size");
+ FUZZTEST_CHECK(a.size() == b.size())
+ << "cmp operands must have the same size";
const size_t size = a.size();
if (size < kMinCmpEntrySize) return;
if (size > kMaxCmpEntrySize) return;
@@ -627,8 +625,8 @@
void RunFuzzTest(absl::AnyInvocable<void() &&> run_fuzz_test_once) override {
orig_fixture_driver_->RunFuzzTest([&, this] {
- FUZZTEST_INTERNAL_CHECK(configuration_ != nullptr,
- "Setting up a fuzz test without configuration!");
+ FUZZTEST_CHECK(configuration_ != nullptr)
+ << "Setting up a fuzz test without configuration!";
PopulateTestLimitsToCentipedeRunner(*configuration_);
std::move(run_fuzz_test_once)();
});
@@ -675,8 +673,8 @@
centipede_fixture_driver_(
new CentipedeFixtureDriver(runtime_, std::move(fixture_driver))),
fuzzer_impl_(test_, absl::WrapUnique(centipede_fixture_driver_)) {
- FUZZTEST_INTERNAL_CHECK(centipede_fixture_driver_ != nullptr,
- "Invalid fixture driver!");
+ FUZZTEST_CHECK(centipede_fixture_driver_ != nullptr)
+ << "Invalid fixture driver!";
}
bool CentipedeFuzzerAdaptor::RunInUnitTestMode(
@@ -768,9 +766,8 @@
output.dir_path);
break;
default:
- FUZZTEST_INTERNAL_CHECK(false,
- "unsupported reproducer output location type "
- "to report reproducers from Centipede");
+ FUZZTEST_CHECK(false) << "unsupported reproducer output location type "
+ "to report reproducers from Centipede";
}
// Will be set when there is only one reproducer - nullopt otherwise.
@@ -903,26 +900,25 @@
runner_callbacks);
return;
});
- FUZZTEST_INTERNAL_CHECK(result.has_value(),
- "No result is set for running fuzz test");
+ FUZZTEST_CHECK(result.has_value())
+ << "No result is set for running fuzz test";
return *result == EXIT_SUCCESS;
} else if (is_running_property_function_in_this_process) {
// If `is_running_property_function_in_this_process` holds at this point. We
// assume it is for `ReplayInputsIfAvailable` to handle `FUZZTEST_REPLAY`
// and `FUZZTEST_MINIMIZE_REPRODUCER`, which Centipede does not support.
// This is fine because it does not require coverage instrumentation.
- FUZZTEST_INTERNAL_CHECK(
- std::getenv("FUZZTEST_REPLAY") ||
- std::getenv("FUZZTEST_MINIMIZE_REPRODUCER"),
- "Both env vars `FUZZTEST_REPLAY` and `FUZZTEST_MINIMIZE_REPRODUCER` "
- "are not set when calling the legacy input replaying - this is a "
- "FuzzTest bug!");
+ FUZZTEST_CHECK(std::getenv("FUZZTEST_REPLAY") ||
+ std::getenv("FUZZTEST_MINIMIZE_REPRODUCER"))
+ << "Both env vars `FUZZTEST_REPLAY` and `FUZZTEST_MINIMIZE_REPRODUCER` "
+ "are not set when calling the legacy input replaying - this is a "
+ "FuzzTest bug!";
fuzzer_impl_.fixture_driver_->RunFuzzTest([&, this]() {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- fuzzer_impl_.ReplayInputsIfAvailable(configuration),
- "ReplayInputsIfAvailable failed to handle env vars `FUZZTEST_REPLAY` "
- "or `FUZZTEST_MINIMIZE_REPRODUCER`. Please check if they are set "
- "properly.");
+ FUZZTEST_PRECONDITION(fuzzer_impl_.ReplayInputsIfAvailable(configuration))
+ << "ReplayInputsIfAvailable failed to handle env vars "
+ "`FUZZTEST_REPLAY` "
+ "or `FUZZTEST_MINIMIZE_REPRODUCER`. Please check if they are set "
+ "properly.";
return;
});
return true;
@@ -942,9 +938,9 @@
const std::string minimize_dir = minimize_dir_chars;
const char* corpus_out_dir_chars =
std::getenv("FUZZTEST_TESTSUITE_OUT_DIR");
- FUZZTEST_INTERNAL_CHECK(corpus_out_dir_chars != nullptr,
- "FUZZTEST_TESTSUITE_OUT_DIR must be specified "
- "when minimizing testsuite");
+ FUZZTEST_CHECK(corpus_out_dir_chars != nullptr)
+ << "FUZZTEST_TESTSUITE_OUT_DIR must be specified "
+ "when minimizing testsuite";
const std::string corpus_out_dir = corpus_out_dir_chars;
absl::FPrintF(
GetStderr(),
@@ -957,32 +953,32 @@
// The first empty path means no output dir.
replay_env.corpus_dir = {"", minimize_dir};
replay_env.load_shards_only = true;
- FUZZTEST_INTERNAL_CHECK(
- RunCentipede(replay_env, configuration.centipede_command) == 0,
- "Failed to replaying the testsuite for minimization");
+ FUZZTEST_CHECK(
+ RunCentipede(replay_env, configuration.centipede_command) == 0)
+ << "Failed to replaying the testsuite for minimization";
absl::FPrintF(GetStderr(), "[.] Imported the corpus from %s.\n",
minimize_dir);
// 2. Run Centipede distillation on the shard.
auto distill_env = env;
distill_env.distill = true;
- FUZZTEST_INTERNAL_CHECK(
- RunCentipede(distill_env, configuration.centipede_command) == 0,
- "Failed to minimize the testsuite");
+ FUZZTEST_CHECK(
+ RunCentipede(distill_env, configuration.centipede_command) == 0)
+ << "Failed to minimize the testsuite";
absl::FPrintF(GetStderr(),
"[.] Minimized the corpus using Centipede distillation.\n");
// 3. Replace the shard corpus data with the distillation result.
auto distill_workdir = fuzztest::internal::WorkDir(distill_env);
- FUZZTEST_INTERNAL_CHECK(
+ FUZZTEST_CHECK(
std::rename(
distill_workdir.DistilledCorpusFilePaths().MyShard().c_str(),
- distill_workdir.CorpusFilePaths().MyShard().c_str()) == 0,
- "Failed to replace the corpus data with the minimized result");
+ distill_workdir.CorpusFilePaths().MyShard().c_str()) == 0)
+ << "Failed to replace the corpus data with the minimized result";
// 4. Export the corpus of the shard.
auto export_env = env;
export_env.corpus_to_files = corpus_out_dir;
- FUZZTEST_INTERNAL_CHECK(
- RunCentipede(export_env, configuration.centipede_command) == 0,
- "Failed to export the corpus to FUZZTEST_MINIMIZE_TESTSUITE_DIR");
+ FUZZTEST_CHECK(
+ RunCentipede(export_env, configuration.centipede_command) == 0)
+ << "Failed to export the corpus to FUZZTEST_MINIMIZE_TESTSUITE_DIR";
absl::FPrintF(GetStderr(),
"[.] Exported the minimized the corpus to %s.\n",
corpus_out_dir);
diff --git a/fuzztest/internal/configuration.cc b/fuzztest/internal/configuration.cc
index f4f0ffc..ebe7304 100644
--- a/fuzztest/internal/configuration.cc
+++ b/fuzztest/internal/configuration.cc
@@ -22,12 +22,12 @@
#include <utility>
#include <vector>
-#include "absl/log/absl_check.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
@@ -99,14 +99,14 @@
template <int&... ExplicitArgumentBarrier, typename IntT,
typename = std::enable_if_t<std::is_integral_v<IntT>>>
size_t WriteIntegral(std::string& out, size_t offset, IntT val) {
- ABSL_CHECK_GE(out.size(), offset + SpaceFor(val));
+ FUZZTEST_CHECK_GE(out.size(), offset + SpaceFor(val));
std::memcpy(out.data() + offset, &val, SpaceFor(val));
offset += SpaceFor(val);
return offset;
}
size_t WriteString(std::string& out, size_t offset, absl::string_view str) {
- ABSL_CHECK_GE(out.size(), offset + SpaceFor(str));
+ FUZZTEST_CHECK_GE(out.size(), offset + SpaceFor(str));
offset = WriteIntegral(out, offset, str.size());
std::memcpy(out.data() + offset, str.data(), str.size());
offset += str.size();
@@ -115,7 +115,7 @@
size_t WriteOptionalString(std::string& out, size_t offset,
const std::optional<std::string>& str) {
- ABSL_CHECK_GE(out.size(), offset + SpaceFor(str));
+ FUZZTEST_CHECK_GE(out.size(), offset + SpaceFor(str));
offset = WriteIntegral(out, offset, str.has_value());
if (str.has_value()) {
offset = WriteString(out, offset, *str);
@@ -125,7 +125,7 @@
size_t WriteVectorOfStrings(std::string& out, size_t offset,
const std::vector<std::string>& vec) {
- ABSL_CHECK_GE(out.size(), offset + SpaceFor(vec));
+ FUZZTEST_CHECK_GE(out.size(), offset + SpaceFor(vec));
offset = WriteIntegral(out, offset, vec.size());
for (const std::string& str : vec) {
offset = WriteString(out, offset, str);
@@ -236,7 +236,7 @@
offset = WriteOptionalString(out, offset, centipede_command);
offset = WriteOptionalString(out, offset, crashing_input_to_reproduce);
offset = WriteOptionalString(out, offset, reproduction_command_template);
- ABSL_CHECK_EQ(offset, out.size());
+ FUZZTEST_CHECK_EQ(offset, out.size());
return out;
}
diff --git a/fuzztest/internal/coverage.cc b/fuzztest/internal/coverage.cc
index bb647d4..43c25d7 100644
--- a/fuzztest/internal/coverage.cc
+++ b/fuzztest/internal/coverage.cc
@@ -26,6 +26,7 @@
#include "absl/base/attributes.h"
#include "absl/strings/str_format.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/flag_name.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/table_of_recent_compares.h"
@@ -198,8 +199,8 @@
FUZZTEST_INTERNAL_NOSANITIZE bool UpdateVectorized(
const uint8_t *execution_data, uint8_t *corpus_data, size_t size,
size_t offset_to_align) {
- FUZZTEST_INTERNAL_CHECK(size >= kVectorSize,
- "size cannot be smaller than block size!");
+ FUZZTEST_CHECK(size >= kVectorSize)
+ << "size cannot be smaller than block size!";
// Avoid collapsing the "greater than" vector until the end.
Vector any_greater{};
@@ -290,8 +291,8 @@
absl::Span<uint8_t> execution_map = execution_coverage->GetCounterMap();
// Note: corpus_map_size_ will be larger than execution_map.size().
// See the constructor for more details.
- FUZZTEST_INTERNAL_CHECK(execution_map.size() <= corpus_map_size_,
- "Map size mismatch.");
+ FUZZTEST_CHECK(execution_map.size() <= corpus_map_size_)
+ << "Map size mismatch.";
// Calculate the offset required to align `p` to alignof(Vector).
void* p = execution_map.data();
@@ -348,10 +349,8 @@
// where [start,end) is the array of 8-bit counters created for the current DSO.
extern "C" void __sanitizer_cov_8bit_counters_init(uint8_t* start,
uint8_t* stop) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(start != nullptr,
- "Invalid counter map address.");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(start < stop,
- "Invalid counter map size.");
+ FUZZTEST_PRECONDITION(start != nullptr) << "Invalid counter map address.";
+ FUZZTEST_PRECONDITION(start < stop) << "Invalid counter map size.";
size_t map_size = stop - start;
// For now, we assume single DSO. This means that this call back should get
diff --git a/fuzztest/internal/domains/BUILD b/fuzztest/internal/domains/BUILD
index 5a1d738..5e605dd 100644
--- a/fuzztest/internal/domains/BUILD
+++ b/fuzztest/internal/domains/BUILD
@@ -21,6 +21,7 @@
hdrs = ["absl_helpers.h"],
deps = [
"@abseil-cpp//absl/time",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:logging",
],
)
@@ -57,8 +58,6 @@
":absl_helpers",
"@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/functional:function_ref",
- "@abseil-cpp//absl/log:absl_check",
- "@abseil-cpp//absl/log:absl_log",
"@abseil-cpp//absl/numeric:bits",
"@abseil-cpp//absl/numeric:int128",
"@abseil-cpp//absl/random",
@@ -69,6 +68,7 @@
"@abseil-cpp//absl/strings:str_format",
"@abseil-cpp//absl/time",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest:fuzzing_bit_gen",
"@com_google_fuzztest//fuzztest/internal:any",
"@com_google_fuzztest//fuzztest/internal:logging",
@@ -89,30 +89,18 @@
],
deps = [
":core_domains_impl",
- ":in_grammar_impl",
- ":in_regexp_impl",
- ":protobuf_domain_impl",
- "@abseil-cpp//absl/base:core_headers",
- "@abseil-cpp//absl/base:no_destructor",
- "@abseil-cpp//absl/container:flat_hash_map",
- "@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/functional:function_ref",
- "@abseil-cpp//absl/random",
"@abseil-cpp//absl/random:bit_gen_ref",
"@abseil-cpp//absl/random:distributions",
"@abseil-cpp//absl/status",
- "@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
- "@abseil-cpp//absl/synchronization",
- "@abseil-cpp//absl/types:span",
- "@com_google_fuzztest//fuzztest:domain_core",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:any",
"@com_google_fuzztest//fuzztest/internal:logging",
"@com_google_fuzztest//fuzztest/internal:meta",
"@com_google_fuzztest//fuzztest/internal:printer",
"@com_google_fuzztest//fuzztest/internal:serialization",
- "@com_google_fuzztest//fuzztest/internal:status",
"@com_google_fuzztest//fuzztest/internal:type_support",
],
)
@@ -154,6 +142,7 @@
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:logging",
"@com_google_fuzztest//fuzztest/internal:serialization",
"@com_google_fuzztest//fuzztest/internal:status",
@@ -177,6 +166,7 @@
"@abseil-cpp//absl/strings:string_view",
"@abseil-cpp//absl/synchronization",
"@abseil-cpp//absl/types:span",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest:domain_core",
"@com_google_fuzztest//fuzztest/internal:any",
"@com_google_fuzztest//fuzztest/internal:logging",
@@ -199,6 +189,7 @@
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:string_view",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:logging",
"@re2",
],
diff --git a/fuzztest/internal/domains/absl_helpers.h b/fuzztest/internal/domains/absl_helpers.h
index 57eafed..efcfe7c 100644
--- a/fuzztest/internal/domains/absl_helpers.h
+++ b/fuzztest/internal/domains/absl_helpers.h
@@ -20,6 +20,7 @@
#include <utility>
#include "absl/time/time.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/logging.h"
namespace fuzztest::internal {
@@ -31,8 +32,8 @@
inline absl::Duration MakeDuration(int64_t secs, uint32_t ticks) {
// The granularity of a duration is as small as a quarter of a
// nanosecond.
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(ticks >= 0u && ticks <= 3'999'999'999u,
- "Ticks should be in range [0, 4B - 1]!");
+ FUZZTEST_PRECONDITION(ticks >= 0u && ticks <= 3'999'999'999u)
+ << "Ticks should be in range [0, 4B - 1]!";
return absl::Seconds(secs) + (absl::Nanoseconds(1) / 4) * ticks;
}
@@ -43,13 +44,13 @@
int64_t ticks = (4 * rem) / absl::Nanoseconds(1);
if (ticks < 0) {
// It is impossible to have both a negative remainder and int64min seconds.
- FUZZTEST_INTERNAL_CHECK(secs != std::numeric_limits<int64_t>::min(),
- "Seconds should not be int64 min!");
+ FUZZTEST_CHECK(secs != std::numeric_limits<int64_t>::min())
+ << "Seconds should not be int64 min!";
secs -= 1;
ticks += 4'000'000'000;
}
- FUZZTEST_INTERNAL_CHECK(0 <= ticks && ticks < 4'000'000'000,
- "Ticks should be in range [0, 4B - 1]!");
+ FUZZTEST_CHECK(0 <= ticks && ticks < 4'000'000'000)
+ << "Ticks should be in range [0, 4B - 1]!";
return {secs, static_cast<uint32_t>(ticks)};
}
diff --git a/fuzztest/internal/domains/bit_flag_combination_of_impl.h b/fuzztest/internal/domains/bit_flag_combination_of_impl.h
index 3ed7a52..6ad3deb 100644
--- a/fuzztest/internal/domains/bit_flag_combination_of_impl.h
+++ b/fuzztest/internal/domains/bit_flag_combination_of_impl.h
@@ -21,6 +21,7 @@
#include "absl/random/bit_gen_ref.h"
#include "absl/status/status.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/type_support.h"
@@ -35,19 +36,18 @@
explicit BitFlagCombinationOfImpl(absl::Span<const T> flags)
: flags_(flags.begin(), flags.end()), all_flags_combo_{} {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !flags.empty(), "BitFlagCombinationOf requires a non empty list.");
+ FUZZTEST_PRECONDITION(!flags.empty())
+ << "BitFlagCombinationOf requires a non empty list.";
// Make sure they are mutually exclusive metadata, only_shrink and none are
// empty.
for (int i = 0; i < flags.size(); ++i) {
T v1 = flags[i];
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- v1 != T{}, "BitFlagCombinationOf requires non zero flags.");
+ FUZZTEST_PRECONDITION(v1 != T{})
+ << "BitFlagCombinationOf requires non zero flags.";
for (int j = i + 1; j < flags.size(); ++j) {
T v2 = flags[j];
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- BitAnd(v1, v2) == T{},
- "BitFlagCombinationOf requires flags to be mutually exclusive.");
+ FUZZTEST_PRECONDITION(BitAnd(v1, v2) == T{})
+ << "BitFlagCombinationOf requires flags to be mutually exclusive.";
}
all_flags_combo_ = BitOr(all_flags_combo_, v1);
}
diff --git a/fuzztest/internal/domains/bit_gen_ref.h b/fuzztest/internal/domains/bit_gen_ref.h
index 980985d..824d35e 100644
--- a/fuzztest/internal/domains/bit_gen_ref.h
+++ b/fuzztest/internal/domains/bit_gen_ref.h
@@ -20,11 +20,10 @@
#include <utility>
#include <vector>
-#include "absl/log/absl_check.h"
-#include "absl/log/absl_log.h"
#include "absl/random/bit_gen_ref.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
+#include "./common/logging.h"
#include "./fuzztest/fuzzing_bit_gen.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/printer.h"
@@ -52,7 +51,7 @@
: initializer_data_(o.initializer_data_), bitgen_(std::nullopt) {}
BitGenCorpusValue& operator=(const BitGenCorpusValue& o) {
// The internal URBG should be unused.
- ABSL_CHECK(!bitgen_.has_value());
+ FUZZTEST_CHECK(!bitgen_.has_value());
initializer_data_ = o.initializer_data_;
return *this;
}
@@ -61,8 +60,8 @@
bitgen_(std::nullopt) {}
BitGenCorpusValue& operator=(BitGenCorpusValue&& o) {
// The internal URBG should be unused.
- ABSL_CHECK(!o.bitgen_.has_value());
- ABSL_CHECK(!bitgen_.has_value());
+ FUZZTEST_CHECK(!o.bitgen_.has_value());
+ FUZZTEST_CHECK(!bitgen_.has_value());
initializer_data_ = std::move(o.initializer_data_);
return *this;
}
@@ -137,7 +136,7 @@
value_type GetRandomValue(absl::BitGenRef prng) {
// See b/404828355
- ABSL_LOG(FATAL) << "The domain doesn't support GetRandomValue().";
+ FUZZTEST_LOG(FATAL) << "The domain doesn't support GetRandomValue().";
}
std::optional<corpus_type> FromValue(const value_type&) const {
diff --git a/fuzztest/internal/domains/container_of_impl.h b/fuzztest/internal/domains/container_of_impl.h
index 1db432c..d4202b8 100644
--- a/fuzztest/internal/domains/container_of_impl.h
+++ b/fuzztest/internal/domains/container_of_impl.h
@@ -31,6 +31,7 @@
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/container_mutation_helpers.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/logging.h"
@@ -113,9 +114,9 @@
const domain_implementor::MutationMetadata& metadata,
bool only_shrink) {
permanent_dict_candidate_ = std::nullopt;
- FUZZTEST_INTERNAL_CHECK(
- min_size() <= val.size() && val.size() <= max_size(), "Size ",
- val.size(), " is not between ", min_size(), " and ", max_size());
+ FUZZTEST_CHECK(min_size() <= val.size() && val.size() <= max_size())
+ << "Size " << val.size() << " is not between " << min_size() << " and "
+ << max_size();
const bool can_shrink = val.size() > min_size();
const bool can_grow = !only_shrink && val.size() < max_size();
@@ -220,16 +221,16 @@
return Self();
}
Derived& WithMinSize(size_t s) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !max_size_.has_value() || s <= *max_size_, "Minimal size ", s,
- " cannot be larger than maximal size ", *max_size_);
+ FUZZTEST_PRECONDITION(!max_size_.has_value() || s <= *max_size_)
+ << "Minimal size " << s << " cannot be larger than maximal size "
+ << *max_size_;
min_size_ = s;
return Self();
}
Derived& WithMaxSize(size_t s) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- min_size_ <= s, "Maximal size ", s,
- " cannot be smaller than minimal size ", min_size_);
+ FUZZTEST_PRECONDITION(min_size_ <= s)
+ << "Maximal size " << s << " cannot be smaller than minimal size "
+ << min_size_;
max_size_ = s;
return Self();
}
@@ -238,9 +239,8 @@
"Manual Dictionary now only supports std::vector or "
"std::string or std::string_view.\n");
for (const value_type& entry : manual_dict) {
- FUZZTEST_INTERNAL_CHECK(
- entry.size() <= max_size(),
- "At least one dictionary entry is larger than max container size.");
+ FUZZTEST_CHECK(entry.size() <= max_size())
+ << "At least one dictionary entry is larger than max container size.";
manual_dict_.AddEntry({std::nullopt, entry});
}
return Self();
diff --git a/fuzztest/internal/domains/domain_type_erasure.h b/fuzztest/internal/domains/domain_type_erasure.h
index 2dd3b08..442af9d 100644
--- a/fuzztest/internal/domains/domain_type_erasure.h
+++ b/fuzztest/internal/domains/domain_type_erasure.h
@@ -33,6 +33,7 @@
#include "absl/random/bit_gen_ref.h"
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/any.h"
#include "./fuzztest/internal/domains/mutation_metadata.h"
#include "./fuzztest/internal/logging.h"
@@ -228,9 +229,8 @@
printer.PrintFormattedAggregateValue(val.GetAs<CorpusType>(), out, mode,
prefix, suffix, element_formatter);
} else {
- FUZZTEST_INTERNAL_CHECK(false,
- "PrintFormattedAggregateValue() can only be "
- "called on AggregatePrinter!");
+ FUZZTEST_LOG(FATAL) << "PrintFormattedAggregateValue() can only be "
+ "called on AggregatePrinter!";
}
}
diff --git a/fuzztest/internal/domains/element_of_impl.h b/fuzztest/internal/domains/element_of_impl.h
index 38fd281..0f3783f 100644
--- a/fuzztest/internal/domains/element_of_impl.h
+++ b/fuzztest/internal/domains/element_of_impl.h
@@ -24,6 +24,7 @@
#include "absl/random/bit_gen_ref.h"
#include "absl/random/distributions.h"
#include "absl/time/time.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/logging.h"
#include "./fuzztest/internal/serialization.h"
@@ -42,8 +43,8 @@
using typename ElementOfImpl::DomainBase::value_type;
explicit ElementOfImpl(std::vector<T> values) : values_(values) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !values.empty(), "ElementOf requires a non empty list.");
+ FUZZTEST_PRECONDITION(!values.empty())
+ << "ElementOf requires a non empty list.";
}
corpus_type Init(absl::BitGenRef prng) {
diff --git a/fuzztest/internal/domains/filter_impl.h b/fuzztest/internal/domains/filter_impl.h
index a9b3130..f37b8f9 100644
--- a/fuzztest/internal/domains/filter_impl.h
+++ b/fuzztest/internal/domains/filter_impl.h
@@ -22,6 +22,7 @@
#include "absl/random/bit_gen_ref.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/domain.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/logging.h"
@@ -95,10 +96,10 @@
bool res = predicate_(GetValue(v));
if (!res) {
++num_skips_;
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- num_skips_ <= 100 || static_cast<double>(num_skips_) <=
- .9 * static_cast<double>(num_values_),
- absl::StrFormat(R"(
+ FUZZTEST_PRECONDITION(num_skips_ <= 100 ||
+ static_cast<double>(num_skips_) <=
+ .9 * static_cast<double>(num_values_))
+ << absl::StrFormat(R"(
[!] Ineffective use of Filter() detected!
@@ -109,7 +110,7 @@
chunk of the input domain, consider defining a custom domain by construction.
See more details in the User Guide.
)",
- num_skips_, num_values_));
+ num_skips_, num_values_);
}
return res;
}
diff --git a/fuzztest/internal/domains/in_grammar_impl.h b/fuzztest/internal/domains/in_grammar_impl.h
index ac34361..edcb72c 100644
--- a/fuzztest/internal/domains/in_grammar_impl.h
+++ b/fuzztest/internal/domains/in_grammar_impl.h
@@ -117,9 +117,8 @@
static bool IsMutable(const ASTNode& /*val*/) { return false; }
static IRObject SerializeCorpus(const ASTNode& astnode) {
- FUZZTEST_INTERNAL_CHECK(
- CheckASTNodeTypeIdAndChildType<std::monostate>(astnode, id),
- "Invalid node!");
+ FUZZTEST_CHECK(CheckASTNodeTypeIdAndChildType<std::monostate>(astnode, id))
+ << "Invalid node!";
return WrapASTIntoIRObject(astnode, {});
}
@@ -166,9 +165,8 @@
static ASTTypeId TypeId() { return id; }
static void ToString(std::string& output, const ASTNode& val) {
- FUZZTEST_INTERNAL_CHECK(
- CheckASTNodeTypeIdAndChildType<RegexpDFA::Path>(val, id),
- "Not a regex literal!");
+ FUZZTEST_CHECK(CheckASTNodeTypeIdAndChildType<RegexpDFA::Path>(val, id))
+ << "Not a regex literal!";
absl::StrAppend(&output, GetInnerRegexpDomain().GetValue(
std::get<RegexpDFA::Path>(val.children)));
}
@@ -176,9 +174,8 @@
static bool IsMutable(const ASTNode& /*val*/) { return true; }
static IRObject SerializeCorpus(const ASTNode& astnode) {
- FUZZTEST_INTERNAL_CHECK(
- CheckASTNodeTypeIdAndChildType<RegexpDFA::Path>(astnode, id),
- "Not a regex literal!");
+ FUZZTEST_CHECK(CheckASTNodeTypeIdAndChildType<RegexpDFA::Path>(astnode, id))
+ << "Not a regex literal!";
return WrapASTIntoIRObject(
astnode, GetInnerRegexpDomain().SerializeCorpus(
std::get<RegexpDFA::Path>(astnode.children)));
@@ -258,9 +255,9 @@
static void Mutate(ASTNode& val, absl::BitGenRef prng,
const domain_implementor::MutationMetadata& metadata,
bool only_shrink) {
- FUZZTEST_INTERNAL_CHECK(
- CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(val, id),
- "Not a vector!");
+ FUZZTEST_CHECK(
+ CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(val, id))
+ << "Not a vector!";
std::vector<ASTNode>& elements =
std::get<std::vector<ASTNode>>(val.children);
if (only_shrink) {
@@ -272,7 +269,7 @@
!elements.empty() && ElementT::IsMutable(elements.back());
constexpr bool can_change_element_num = max > min;
if (!can_mutate_element && !can_change_element_num) {
- FUZZTEST_INTERNAL_CHECK(false, "We shouldn't pick an unmutable node.");
+ FUZZTEST_LOG(FATAL) << "We shouldn't pick an unmutable node.";
return;
}
if (!can_mutate_element) {
@@ -301,9 +298,9 @@
static bool IsMutable(const ASTNode& /*val*/) { return true; }
static IRObject SerializeCorpus(const ASTNode& astnode) {
- FUZZTEST_INTERNAL_CHECK(
- CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(astnode, id),
- "Not a vector!");
+ FUZZTEST_CHECK(
+ CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(astnode, id))
+ << "Not a vector!";
IRObject expansion_obj;
auto& inner_subs = expansion_obj.MutableSubs();
for (auto& node : std::get<std::vector<ASTNode>>(astnode.children)) {
@@ -425,11 +422,11 @@
static void Mutate(ASTNode& val, absl::BitGenRef prng,
const domain_implementor::MutationMetadata& metadata,
bool only_shrink) {
- FUZZTEST_INTERNAL_CHECK(
+ FUZZTEST_CHECK(
CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(val, id) &&
- std::get<std::vector<ASTNode>>(val.children).size() ==
- sizeof...(ElementT),
- "Tuple elements number doesn't match!");
+ std::get<std::vector<ASTNode>>(val.children).size() ==
+ sizeof...(ElementT))
+ << "Tuple elements number doesn't match!";
std::vector<int> mutables;
ApplyIndex<sizeof...(ElementT)>([&](auto... I) {
@@ -439,9 +436,8 @@
...);
});
- FUZZTEST_INTERNAL_CHECK(
- !mutables.empty(),
- "If the tuple is immutable it shouldn't be picked for mutation.");
+ FUZZTEST_CHECK(!mutables.empty())
+ << "If the tuple is immutable it shouldn't be picked for mutation.";
int choice = mutables[absl::Uniform<int>(prng, 0, mutables.size())];
ApplyIndex<sizeof...(ElementT)>([&](auto... I) {
@@ -472,9 +468,9 @@
}
static IRObject SerializeCorpus(const ASTNode& astnode) {
- FUZZTEST_INTERNAL_CHECK(
- CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(astnode, id),
- "Invalid node!");
+ FUZZTEST_CHECK(
+ CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(astnode, id))
+ << "Invalid node!";
IRObject expansion_obj;
auto& inner_subs = expansion_obj.MutableSubs();
ApplyIndex<sizeof...(ElementT)>([&](auto... I) {
@@ -571,8 +567,8 @@
: (void)0),
...);
- FUZZTEST_INTERNAL_CHECK(is_current_value_mutable || has_alternative,
- "Impossible at" + std::to_string(id));
+ FUZZTEST_CHECK(is_current_value_mutable || has_alternative)
+ << "Impossible at" << id;
if (only_shrink) {
if (is_current_value_mutable) {
MutateCurrentValue(val, prng, metadata, only_shrink);
@@ -594,9 +590,8 @@
}
static void ToString(std::string& output, const ASTNode& val) {
- FUZZTEST_INTERNAL_CHECK(
- std::get<std::vector<ASTNode>>(val.children).size() == 1,
- "This is not a variant ast node.");
+ FUZZTEST_CHECK(std::get<std::vector<ASTNode>>(val.children).size() == 1)
+ << "This is not a variant ast node.";
auto child = std::get<std::vector<ASTNode>>(val.children).front();
((ElementT::TypeId() == child.type_id ? (ElementT::ToString(output, child))
: (void)0),
@@ -618,9 +613,9 @@
}
static IRObject SerializeCorpus(const ASTNode& astnode) {
- FUZZTEST_INTERNAL_CHECK(
- CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(astnode, id),
- "Invalid node!");
+ FUZZTEST_CHECK(
+ CheckASTNodeTypeIdAndChildType<std::vector<ASTNode>>(astnode, id))
+ << "Invalid node!";
ASTTypeId child_id =
std::get<std::vector<ASTNode>>(astnode.children).front().type_id;
@@ -690,7 +685,7 @@
}
static void SwitchToAlternative(ASTNode& val, absl::BitGenRef prng) {
constexpr int n_alternative = sizeof...(ElementT);
- FUZZTEST_INTERNAL_CHECK(n_alternative > 1, "No alternative to switch!");
+ FUZZTEST_CHECK(n_alternative > 1) << "No alternative to switch!";
int child_type_id =
std::get<std::vector<ASTNode>>(val.children).front().type_id;
int current_choice = 0;
@@ -751,7 +746,7 @@
}
std::optional<corpus_type> FromValue(const value_type& /*v*/) const {
- FUZZTEST_INTERNAL_CHECK(false, "Parsing is not implemented yet!");
+ FUZZTEST_CHECK(false) << "Parsing is not implemented yet!";
return std::nullopt;
}
@@ -790,8 +785,8 @@
size_t src_index =
absl::Uniform<size_t>(prng, dst_index + 1, candidates.size());
- FUZZTEST_INTERNAL_CHECK(src_index < candidates.size(), "Out of bound!");
- FUZZTEST_INTERNAL_CHECK(dst_index < candidates.size(), "Out of bound!");
+ FUZZTEST_CHECK(src_index < candidates.size()) << "Out of bound!";
+ FUZZTEST_CHECK(dst_index < candidates.size()) << "Out of bound!";
if (candidates[dst_index]->NodeCount() <
candidates[src_index]->NodeCount()) {
std::swap(dst_index, src_index);
diff --git a/fuzztest/internal/domains/in_range_impl.h b/fuzztest/internal/domains/in_range_impl.h
index 8b6cff5..0d77a50 100644
--- a/fuzztest/internal/domains/in_range_impl.h
+++ b/fuzztest/internal/domains/in_range_impl.h
@@ -29,6 +29,7 @@
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/domains/special_values.h"
#include "./fuzztest/internal/domains/value_mutation_helpers.h"
@@ -53,15 +54,13 @@
IntegerDictionary<T>, bool>;
explicit InRangeImpl(T min, T max) : min_(min), max_(max) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- min <= max, "min must be less than or equal to max!");
+ FUZZTEST_PRECONDITION(min <= max)
+ << "min must be less than or equal to max!";
if constexpr (!T_is_integer) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !(min == std::numeric_limits<T>::lowest() &&
- max == std::numeric_limits<T>::max()),
- "Consider using the Finite<T>() domain instead.");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(std::isfinite(max - min),
- "Range is too large!");
+ FUZZTEST_PRECONDITION(!(min == std::numeric_limits<T>::lowest() &&
+ max == std::numeric_limits<T>::max()))
+ << "Consider using the Finite<T>() domain instead.";
+ FUZZTEST_PRECONDITION(std::isfinite(max - min)) << "Range is too large!";
}
if constexpr (T_is_integer) {
// Find the longest common prefix
diff --git a/fuzztest/internal/domains/in_regexp_impl.cc b/fuzztest/internal/domains/in_regexp_impl.cc
index 81d8141..ae97e62 100644
--- a/fuzztest/internal/domains/in_regexp_impl.cc
+++ b/fuzztest/internal/domains/in_regexp_impl.cc
@@ -28,6 +28,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/domains/regexp_dfa.h"
#include "./fuzztest/internal/logging.h"
@@ -44,8 +45,7 @@
if (auto seed = MaybeGetRandomSeed(prng)) return *seed;
absl::StatusOr<RegexpDFA::Path> path =
dfa_.StringToPath(dfa_.GenerateString(prng));
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(path.ok(),
- "Init should generate valid paths");
+ FUZZTEST_PRECONDITION(path.ok()) << "Init should generate valid paths";
return *path;
}
@@ -102,7 +102,7 @@
InRegexpImpl::value_type InRegexpImpl::GetValue(const corpus_type& v) const {
absl::StatusOr<std::string> val = dfa_.PathToString(v);
- FUZZTEST_INTERNAL_CHECK(val.ok(), "Corpus is invalid!");
+ FUZZTEST_CHECK(val.ok()) << "Corpus is invalid!";
return *val;
}
@@ -150,9 +150,9 @@
void InRegexpImpl::ValidatePathRoundtrip(const RegexpDFA::Path& path) const {
absl::StatusOr<std::string> str = dfa_.PathToString(path);
- FUZZTEST_INTERNAL_CHECK(str.ok(), "Invalid path in the DFA!");
+ FUZZTEST_CHECK(str.ok()) << "Invalid path in the DFA!";
absl::StatusOr<RegexpDFA::Path> new_path = dfa_.StringToPath(*str);
- FUZZTEST_INTERNAL_CHECK(new_path.ok(), "Invalid path in the DFA!");
+ FUZZTEST_CHECK(new_path.ok()) << "Invalid path in the DFA!";
}
bool InRegexpImpl::ShrinkByRemoveLoop(absl::BitGenRef prng,
diff --git a/fuzztest/internal/domains/optional_of_impl.h b/fuzztest/internal/domains/optional_of_impl.h
index e80b93d..812a92e 100644
--- a/fuzztest/internal/domains/optional_of_impl.h
+++ b/fuzztest/internal/domains/optional_of_impl.h
@@ -27,6 +27,7 @@
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/domain.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/domains/serialization_helpers.h"
@@ -98,12 +99,12 @@
value_type GetValue(const corpus_type& v) const {
if (v.index() == 0) {
- FUZZTEST_INTERNAL_CHECK(policy_ != OptionalPolicy::kWithoutNull,
- "Value cannot be null!");
+ FUZZTEST_CHECK(policy_ != OptionalPolicy::kWithoutNull)
+ << "Value cannot be null!";
return value_type();
}
- FUZZTEST_INTERNAL_CHECK(policy_ != OptionalPolicy::kAlwaysNull,
- "Value cannot be non-null!");
+ FUZZTEST_CHECK(policy_ != OptionalPolicy::kAlwaysNull)
+ << "Value cannot be non-null!";
return value_type(inner_.GetValue(std::get<1>(v)));
}
diff --git a/fuzztest/internal/domains/overlap_of_impl.h b/fuzztest/internal/domains/overlap_of_impl.h
index 92ed0b9..1e074cf 100644
--- a/fuzztest/internal/domains/overlap_of_impl.h
+++ b/fuzztest/internal/domains/overlap_of_impl.h
@@ -25,6 +25,7 @@
#include "absl/random/distributions.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/domains/serialization_helpers.h"
#include "./fuzztest/internal/logging.h"
@@ -88,9 +89,9 @@
Switch<kNumDomains>(mutation_index, [&](auto I) {
auto& domain = std::get<I>(domains_);
auto inner_corpus = domain.FromValue(*orig_value);
- FUZZTEST_INTERNAL_CHECK(inner_corpus.has_value(),
- "Mutate() called on a user value that is not "
- "valid in all overlapping domains");
+ FUZZTEST_CHECK(inner_corpus.has_value())
+ << "Mutate() called on a user value that is not "
+ "valid in all overlapping domains";
domain.Mutate(*inner_corpus, prng, metadata, only_shrink);
mutant_corpus =
corpus_type(std::in_place_index<I>, *std::move(inner_corpus));
@@ -103,8 +104,8 @@
only_shrink);
});
}
- FUZZTEST_INTERNAL_CHECK(mutant_corpus.has_value(),
- "mutant corpus value is missing");
+ FUZZTEST_CHECK(mutant_corpus.has_value())
+ << "mutant corpus value is missing";
const bool valid =
ValidateCorpusValueForOtherDomains(*mutant_corpus).ok();
MaybeReportOnValidationResult(valid);
@@ -169,9 +170,9 @@
return Switch<kNumDomains>(*serialization_domain_index_, [&](auto I) {
auto& domain = std::get<I>(domains_);
const auto inner_corpus = domain.FromValue(user_value);
- FUZZTEST_INTERNAL_CHECK(inner_corpus.has_value(),
- "Mutate() called on a user value that is not "
- "valid in all overlapping domains");
+ FUZZTEST_CHECK(inner_corpus.has_value())
+ << "Mutate() called on a user value that is not "
+ "valid in all overlapping domains";
return domain.SerializeCorpus(*inner_corpus);
});
}
@@ -199,10 +200,8 @@
size_t num_validation_failures_ = 0;
OverlapOfImpl& WithSerializationDomain(size_t index) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- index < kNumDomains,
- absl::StrFormat("Serialization domain index must be less than %d",
- kNumDomains));
+ FUZZTEST_PRECONDITION(index < kNumDomains)
+ << "Serialization domain index must be less than " << kNumDomains;
serialization_domain_index_ = index;
return *this;
}
@@ -235,18 +234,19 @@
++num_validation_attempts_;
if (!succeeded) {
++num_validation_failures_;
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
+ FUZZTEST_PRECONDITION(
num_validation_attempts_ <= 100 ||
- static_cast<double>(num_validation_failures_) <=
- .9 * static_cast<double>(num_validation_attempts_),
- absl::StrFormat(R"(
+ static_cast<double>(num_validation_failures_) <=
+ .9 * static_cast<double>(num_validation_attempts_))
+ << absl::StrFormat(R"(
[!] Ineffective use of overlapping domains detected!
Values were not valid on all of the overlapping domains on more than 90%% of the samples.
%d out of %d have failed.
)",
- num_validation_failures_, num_validation_attempts_));
+ num_validation_failures_,
+ num_validation_attempts_);
}
}
};
diff --git a/fuzztest/internal/domains/protobuf_domain_impl.h b/fuzztest/internal/domains/protobuf_domain_impl.h
index 0a71274..be0e9b0 100644
--- a/fuzztest/internal/domains/protobuf_domain_impl.h
+++ b/fuzztest/internal/domains/protobuf_domain_impl.h
@@ -40,6 +40,7 @@
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
#include "./fuzztest/domain_core.h"
#include "./fuzztest/internal/any.h"
#include "./fuzztest/internal/domains/arbitrary_impl.h"
@@ -284,39 +285,36 @@
}
OptionalPolicy GetOptionalPolicy(const FieldDescriptor* field) const {
- FUZZTEST_INTERNAL_CHECK(
- !field->is_required() && !field->is_repeated(),
- "GetOptionalPolicy should apply to optional fields only!");
+ FUZZTEST_CHECK(!field->is_required() && !field->is_repeated())
+ << "GetOptionalPolicy should apply to optional fields only!";
std::optional<OptionalPolicy> result =
GetPolicyValue(optional_policies_, field);
- FUZZTEST_INTERNAL_CHECK(result.has_value(), "optional policy is not set!");
+ FUZZTEST_CHECK(result.has_value()) << "optional policy is not set!";
return *result;
}
std::optional<int64_t> GetMinRepeatedFieldSize(
const FieldDescriptor* field) const {
- FUZZTEST_INTERNAL_CHECK(
- field->is_repeated(),
- "GetMinRepeatedFieldSize should apply to repeated fields only!");
+ FUZZTEST_CHECK(field->is_repeated())
+ << "GetMinRepeatedFieldSize should apply to repeated fields only!";
auto min = GetPolicyValue(min_repeated_fields_sizes_, field);
auto max = GetPolicyValue(max_repeated_fields_sizes_, field);
if (min.has_value() && max.has_value()) {
- FUZZTEST_INTERNAL_CHECK(*min <= *max, "Repeated field ",
- field->full_name(), " size range is not valid!");
+ FUZZTEST_CHECK(*min <= *max) << "Repeated field " << field->full_name()
+ << " size range is not valid!";
}
return min;
}
std::optional<int64_t> GetMaxRepeatedFieldSize(
const FieldDescriptor* field) const {
- FUZZTEST_INTERNAL_CHECK(
- field->is_repeated(),
- "GetMaxRepeatedFieldSize should apply to repeated fields only!");
+ FUZZTEST_CHECK(field->is_repeated())
+ << "GetMaxRepeatedFieldSize should apply to repeated fields only!";
auto min = GetPolicyValue(min_repeated_fields_sizes_, field);
auto max = GetPolicyValue(max_repeated_fields_sizes_, field);
if (min.has_value() && max.has_value()) {
- FUZZTEST_INTERNAL_CHECK(*min <= *max, "Repeated field ",
- field->full_name(), " size range is not valid!");
+ FUZZTEST_CHECK(*min <= *max) << "Repeated field " << field->full_name()
+ << " size range is not valid!";
}
return max;
}
@@ -344,13 +342,13 @@
auto domain = filter_to_values[i].value;
auto obj = domain.GetValue(domain.Init(gen));
auto* descriptor = obj->GetDescriptor();
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- descriptor->full_name() == field->message_type()->full_name(),
- "Input domain does not match the expected message type. The "
- "domain produced a message of type `",
- descriptor->full_name(),
- "` but the field needs a message of type `",
- field->message_type()->full_name(), "`.");
+ FUZZTEST_PRECONDITION(descriptor->full_name() ==
+ field->message_type()->full_name())
+ << "Input domain does not match the expected message type. The "
+ "domain produced a message of type `"
+ << descriptor->full_name()
+ << "` but the field needs a message of type `"
+ << field->message_type()->full_name() << "`.";
}
return filter_to_values[i].value;
}
@@ -414,8 +412,8 @@
: prototype_factory_(std::move(prototype_factory)), prototype_(nullptr) {}
PrototypePtr(const Prototype* prototype)
: prototype_factory_(), prototype_(prototype) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(prototype != nullptr,
- "Prototype should not be nullptr");
+ FUZZTEST_PRECONDITION(prototype != nullptr)
+ << "Prototype should not be nullptr";
}
PrototypePtr& operator=(const PrototypePtr<Prototype>& other) = default;
@@ -471,10 +469,10 @@
corpus_type Init(absl::BitGenRef prng) {
if (auto seed = this->MaybeGetRandomSeed(prng)) return *seed;
const auto* descriptor = prototype_.Get()->GetDescriptor();
- FUZZTEST_INTERNAL_CHECK(
- !IsCustomizedRecursivelyOnly() || !IsInfinitelyRecursive(descriptor),
- absl::StrCat("Cannot set recursive fields for ",
- descriptor->full_name(), " by default."));
+ FUZZTEST_CHECK(!IsCustomizedRecursivelyOnly() ||
+ !IsInfinitelyRecursive(descriptor))
+ << "Cannot set recursive fields for " << descriptor->full_name()
+ << " by default.";
corpus_type val;
absl::flat_hash_map<int, int> oneof_to_field;
@@ -593,7 +591,7 @@
for (auto& [number, inner] : v) {
if (IsMetadataEntry(number)) continue;
auto* field = GetField(number);
- FUZZTEST_INTERNAL_CHECK(field, "Field not found by number: ", number);
+ FUZZTEST_CHECK(field) << "Field not found by number: " << number;
IRObject& pair = subs.emplace_back();
auto& pair_subs = pair.MutableSubs();
pair_subs.reserve(2);
@@ -1061,9 +1059,9 @@
auto& domain = self.GetSubDomain<T, false>(field);
auto value = domain.GetValue(data);
if (!value.has_value()) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !field->is_required(), "required field '",
- std::string(field->full_name()), "' cannot have null values.");
+ FUZZTEST_PRECONDITION(!field->is_required())
+ << "required field '" << std::string(field->full_name())
+ << "' cannot have null values.";
message.GetReflection()->ClearField(&message, field);
return;
}
@@ -1269,10 +1267,9 @@
template <typename T, typename DomainT, bool is_repeated>
void ApplyDomain(const FieldDescriptor* field) {
if constexpr (!std::is_constructible_v<DomainT, Inner>) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- (std::is_constructible_v<DomainT, Inner>),
- "Input domain does not match field `", field->full_name(),
- "` type.");
+ FUZZTEST_PRECONDITION((std::is_constructible_v<DomainT, Inner>))
+ << "Input domain does not match field `" << field->full_name()
+ << "` type.";
} else {
if constexpr (std::is_same_v<T, ProtoMessageTag>) {
// Verify that the type matches.
@@ -1285,22 +1282,22 @@
domain.Mutate(val, gen, {}, false);
descriptor = GetDescriptor<is_repeated>(val);
}
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !descriptor ||
- descriptor->full_name() == field->message_type()->full_name(),
- "Input domain does not match the expected message type. The "
- "domain produced a message of type `",
- descriptor->full_name(),
- "` but the field needs a message of type `",
- field->message_type()->full_name(), "`.");
+ FUZZTEST_PRECONDITION(!descriptor ||
+ descriptor->full_name() ==
+ field->message_type()->full_name())
+ << "Input domain does not match the expected message type. The "
+ "domain produced a message of type `"
+ << descriptor->full_name()
+ << "` but the field needs a message of type `"
+ << field->message_type()->full_name() << "`.";
}
absl::MutexLock l(&self.mutex_);
auto res = self.domains_.try_emplace(field->number(),
std::in_place_type<DomainT>,
std::forward<Inner>(domain));
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(res.second, "Domain for field `",
- field->full_name(),
- "` has been set multiple times.");
+ FUZZTEST_PRECONDITION(res.second)
+ << "Domain for field `" << field->full_name()
+ << "` has been set multiple times.";
}
}
@@ -1337,9 +1334,8 @@
auto GetField(absl::string_view field_name) const {
auto* field = GetFieldWithoutCheck(field_name);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(field != nullptr,
- "Invalid field name '",
- std::string(field_name), "'.");
+ FUZZTEST_PRECONDITION(field != nullptr)
+ << "Invalid field name '" << std::string(field_name) << "'.";
return field;
}
@@ -1395,11 +1391,10 @@
void WithOneofField(absl::string_view field_name, OptionalPolicy policy) {
const FieldDescriptor* field = GetField(field_name);
if (!field->containing_oneof()) return;
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- policy != OptionalPolicy::kWithoutNull ||
- field->containing_oneof()->field_count() <= 1,
- "Cannot always set oneof field ", field_name,
- " (try using WithOneofAlwaysSet).");
+ FUZZTEST_PRECONDITION(policy != OptionalPolicy::kWithoutNull ||
+ field->containing_oneof()->field_count() <= 1)
+ << "Cannot always set oneof field " << field_name
+ << " (try using WithOneofAlwaysSet).";
if (policy == OptionalPolicy::kAlwaysNull) {
MarkOneofFieldAsUnset(field);
}
@@ -1416,15 +1411,13 @@
void SetOneofAlwaysSet(absl::string_view oneof_name) {
const std::string name(oneof_name);
auto* oneof = prototype_.Get()->GetDescriptor()->FindOneofByName(name);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(oneof != nullptr,
- "Invalid oneof name '", name, "'.");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !always_set_oneofs_.contains(oneof->index()), "oneof '", name,
- "' is AlwaysSet before.");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !uncustomizable_oneofs_.contains(oneof->index()),
- "WithOneofAlwaysSet(\"", name,
- "\") should be called before customizing sub-fields.");
+ FUZZTEST_PRECONDITION(oneof != nullptr)
+ << "Invalid oneof name '" << name << "'.";
+ FUZZTEST_PRECONDITION(!always_set_oneofs_.contains(oneof->index()))
+ << "oneof '" << name << "' is AlwaysSet before.";
+ FUZZTEST_PRECONDITION(!uncustomizable_oneofs_.contains(oneof->index()))
+ << "WithOneofAlwaysSet(\"" << name
+ << "\") should be called before customizing sub-fields.";
always_set_oneofs_.insert(oneof->index());
}
@@ -1478,11 +1471,10 @@
template <typename T>
auto VisitSingular(const FieldDescriptor* field) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- false,
- "Customizing repeated field size is not applicable to non-repeated "
- "field ",
- field->full_name(), ".");
+ FUZZTEST_PRECONDITION(false) << "Customizing repeated field size is not "
+ "applicable to non-repeated "
+ "field "
+ << field->full_name() << ".";
}
template <typename T>
@@ -1550,10 +1542,9 @@
}
OptionalPolicy GetOneofFieldPolicy(const FieldDescriptor* field) const {
- FUZZTEST_INTERNAL_CHECK(
- field->containing_oneof(),
- "GetOneofFieldPolicy should apply to oneof fields only! ",
- field->full_name());
+ FUZZTEST_CHECK(field->containing_oneof())
+ "GetOneofFieldPolicy should apply to oneof fields only! "
+ << field->full_name();
auto field_policy = policy_.GetOptionalPolicy(field);
// Field being unset via a policy overwrites the oneof policy.
if (field_policy == OptionalPolicy::kAlwaysNull) return field_policy;
@@ -1568,11 +1559,11 @@
}
void CheckIfPolicyCanBeUpdated() const {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- customized_fields_.empty(),
- "All singular modifiers (i.e., .With_Field_()) should come after "
- "plural modifiers (i.e., .With_Fields_()). Consider reordering .With_ "
- "modifiers.");
+ FUZZTEST_PRECONDITION(customized_fields_.empty())
+ << "All singular modifiers (i.e., .With_Field_()) should come after "
+ "plural modifiers (i.e., .With_Fields_()). Consider reordering "
+ ".With_ "
+ "modifiers.";
}
// Get the existing domain for `field`, if exists.
// Otherwise, create the appropriate `Arbitrary<>` domain for the field and
@@ -1730,7 +1721,7 @@
// Returns true if there are subprotos in the `descriptor` that form an
// infinite recursion.
bool IsInfinitelyRecursive(const Descriptor* descriptor) const {
- FUZZTEST_INTERNAL_CHECK(IsCustomizedRecursivelyOnly(), "Internal error.");
+ FUZZTEST_CHECK(IsCustomizedRecursivelyOnly()) << "Internal error.";
absl::flat_hash_set<const FieldDescriptor*> parents;
return IsProtoRecursive(/*field=*/nullptr, parents,
RecursionType::kInfinitelyRecursive, descriptor);
@@ -1741,14 +1732,14 @@
// because all Fi-s have to be set (e.g., Fi is a required field, or is
// customized using `WithFieldsAlwaysSet`).
bool IsInfinitelyRecursive(const FieldDescriptor* field) const {
- FUZZTEST_INTERNAL_CHECK(IsCustomizedRecursivelyOnly(), "Internal error.");
+ FUZZTEST_CHECK(IsCustomizedRecursivelyOnly()) << "Internal error.";
absl::flat_hash_set<const FieldDescriptor*> parents;
return IsProtoRecursive(field, parents,
RecursionType::kInfinitelyRecursive);
}
bool IsFieldFinitelyRecursive(const FieldDescriptor* field) {
- FUZZTEST_INTERNAL_CHECK(IsCustomizedRecursivelyOnly(), "Internal error.");
+ FUZZTEST_CHECK(IsCustomizedRecursivelyOnly()) << "Internal error.";
if (!field->message_type()) return false;
ABSL_CONST_INIT static absl::Mutex mutex(absl::kConstInit);
static absl::NoDestructor<
@@ -1801,7 +1792,7 @@
}
bool MustBeSet(const FieldDescriptor* field) const {
- FUZZTEST_INTERNAL_CHECK(IsCustomizedRecursivelyOnly(), "Internal error.");
+ FUZZTEST_CHECK(IsCustomizedRecursivelyOnly()) << "Internal error.";
if (IsRequired(field)) {
return true;
} else if (field->containing_oneof()) {
@@ -1812,13 +1803,12 @@
return policy_.GetMinRepeatedFieldSize(field).has_value() &&
*policy_.GetMinRepeatedFieldSize(field) > 0;
}
- FUZZTEST_INTERNAL_CHECK(false,
- "Field is not optional, repeated, or required");
+ FUZZTEST_CHECK(false) << "Field is not optional, repeated, or required";
return false;
}
bool MustBeUnset(const FieldDescriptor* field) const {
- FUZZTEST_INTERNAL_CHECK(IsCustomizedRecursivelyOnly(), "Internal error.");
+ FUZZTEST_CHECK(IsCustomizedRecursivelyOnly()) << "Internal error.";
if (field->message_type() && IsInfinitelyRecursive(field)) {
absl::FPrintF(
GetStderr(),
@@ -1836,8 +1826,7 @@
return policy_.GetMaxRepeatedFieldSize(field).has_value() &&
*policy_.GetMaxRepeatedFieldSize(field) == 0;
}
- FUZZTEST_INTERNAL_CHECK(false,
- "Field is not optional, repeated, or required");
+ FUZZTEST_CHECK(false) << "Field is not optional, repeated, or required";
return false;
}
@@ -1851,8 +1840,8 @@
parents.insert(field);
descriptor = field->message_type();
} else {
- FUZZTEST_INTERNAL_CHECK(descriptor,
- "one of field or descriptor must be non-null!");
+ FUZZTEST_CHECK(descriptor)
+ << "one of field or descriptor must be non-null!";
}
for (int i = 0; i < descriptor->oneof_decl_count(); ++i) {
const auto* oneof = descriptor->oneof_decl(i);
@@ -2314,10 +2303,10 @@
private:
void FailIfIsOneof(absl::string_view field) {
const FieldDescriptor* descriptor = inner_.GetField(field);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !descriptor->containing_oneof(), "Cannot customize oneof field ", field,
- " with WithOptional<Type>Field (try using "
- "WithOneofAlwaysSet or WithOptional<Type>Unset).");
+ FUZZTEST_PRECONDITION(!descriptor->containing_oneof())
+ << "Cannot customize oneof field " << field
+ << " with WithOptional<Type>Field (try using "
+ "WithOneofAlwaysSet or WithOptional<Type>Unset).";
}
template <typename Inner>
diff --git a/fuzztest/internal/domains/regexp_dfa.cc b/fuzztest/internal/domains/regexp_dfa.cc
index ff6fa70..acca7e1 100644
--- a/fuzztest/internal/domains/regexp_dfa.cc
+++ b/fuzztest/internal/domains/regexp_dfa.cc
@@ -33,6 +33,7 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/logging.h"
#include "re2/prog.h"
#include "re2/regexp.h"
@@ -57,9 +58,8 @@
result.insert(result.end(), fragment.begin(), fragment.end());
state = &states_[next_id];
if (state->is_end_state()) {
- FUZZTEST_INTERNAL_CHECK(
- fragment.back() == kEndOfString,
- "The last character leading to the end state should be EOS!");
+ FUZZTEST_CHECK(fragment.back() == kEndOfString)
+ << "The last character leading to the end state should be EOS!";
result.pop_back();
break;
}
@@ -73,8 +73,8 @@
Path path;
int cur_state_id = from_state_id;
State* cur_state = &states_[cur_state_id];
- FUZZTEST_INTERNAL_CHECK(!cur_state->is_end_state(),
- "Cannot start a DFA path from an end state!");
+ FUZZTEST_CHECK(!cur_state->is_end_state())
+ << "Cannot start a DFA path from an end state!";
while (true) {
// Pick a random next state.
int offset = cur_state->edge_weight_distribution(prng);
@@ -146,7 +146,7 @@
candidate_lens.push_back(len);
}
}
- FUZZTEST_INTERNAL_CHECK(!candidate_lens.empty(), "Cannot find a path!");
+ FUZZTEST_CHECK(!candidate_lens.empty()) << "Cannot find a path!";
int state_id = to_state_id;
Path result;
@@ -156,8 +156,8 @@
result.push_back(*(last_edges_and_counters[state_id][len].edge));
state_id = result.back().from_state_id;
}
- FUZZTEST_INTERNAL_CHECK(state_id == from_state_id,
- "Cannot find a path from from_state");
+ FUZZTEST_CHECK(state_id == from_state_id)
+ << "Cannot find a path from from_state";
std::reverse(result.begin(), result.end());
return result;
}
@@ -209,9 +209,8 @@
const std::vector<std::int16_t>& fragment = transition.chars_to_match;
result.insert(result.end(), fragment.begin(), fragment.end());
if (next_state_id == end_state_id_) {
- FUZZTEST_INTERNAL_CHECK(
- fragment.back() == kEndOfString,
- "The last character leading to the end state should be EOS!");
+ FUZZTEST_CHECK(fragment.back() == kEndOfString)
+ << "The last character leading to the end state should be EOS!";
result.pop_back();
}
}
@@ -230,7 +229,7 @@
const std::vector<std::int16_t>& chars) {
const size_t compare_size = std::min(transition.chars_to_match.size(),
chars.size() - cur_index);
- FUZZTEST_INTERNAL_CHECK(compare_size != 0, "Nothing to compare!");
+ FUZZTEST_CHECK(compare_size != 0) << "Nothing to compare!";
for (size_t i = 0; i < compare_size; ++i) {
if (transition.chars_to_match[i] == chars[cur_index + i]) continue;
return transition.chars_to_match[i] < chars[cur_index + i];
@@ -262,10 +261,9 @@
re2::Regexp::Parse(full_text_regexp, re2::Regexp::LikePerl, nullptr);
// Is the regexp valid?
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(re != nullptr,
- "Invalid RE2 regular expression.");
+ FUZZTEST_PRECONDITION(re != nullptr) << "Invalid RE2 regular expression.";
re2::Prog* prog = re->CompileToProg(0);
- FUZZTEST_INTERNAL_CHECK(prog != nullptr, "RE2 compilation failed!");
+ FUZZTEST_CHECK(prog != nullptr) << "RE2 compilation failed!";
re->Decref();
return std::unique_ptr<re2::Prog>(prog);
}
@@ -279,14 +277,13 @@
// Full match has no effect on re2::Prog::BuildEntireDFA.
int state_n = compiled_regexp->BuildEntireDFA(
re2::Prog::kFirstMatch, [&](const int* next, bool match) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- next != nullptr,
- "The memory budget for building the state machine (DFA) for the "
- "given regular expression has been exhausted. "
- "You might try to reduce the number of states by using more "
- "specific character classes (e.g., [[:alpha:]] instead of `.`, "
- "i.e., any character) in your regular expression, or wait until "
- "the issue is fixed.");
+ FUZZTEST_PRECONDITION(next != nullptr)
+ << "The memory budget for building the state machine (DFA) for the "
+ "given regular expression has been exhausted. "
+ "You might try to reduce the number of states by using more "
+ "specific character classes (e.g., [[:alpha:]] instead of `.`, "
+ "i.e., any character) in your regular expression, or wait until "
+ "the issue is fixed.";
transition_table.emplace_back(
next, next + compiled_regexp->bytemap_range() + 1);
@@ -328,8 +325,8 @@
return a.chars_to_match.front() < b.chars_to_match.front();
});
if (end_vec[i]) end_state_id_ = i;
- FUZZTEST_INTERNAL_CHECK((!end_vec[i] || state.next.empty()),
- "An end state must have no outgoing edges!");
+ FUZZTEST_CHECK((!end_vec[i] || state.next.empty()))
+ << "An end state must have no outgoing edges!";
}
}
@@ -365,9 +362,8 @@
edge_to_unsafe_nodes.push_back(j);
}
}
- FUZZTEST_INTERNAL_CHECK(
- state_id == end_state_id_ || !edge_to_safe_nodes.empty(),
- "A non-end node must have at least one safe edge");
+ FUZZTEST_CHECK(state_id == end_state_id_ || !edge_to_safe_nodes.empty())
+ << "A non-end node must have at least one safe edge";
double probability_to_safe_node =
edge_to_unsafe_nodes.empty() ? 1 : kProbToSafeNode;
@@ -402,9 +398,8 @@
State& state = states_[i];
if (state.next.size() != 1) continue;
const auto& [chars_to_match, next_state_id] = state.next[0];
- FUZZTEST_INTERNAL_CHECK(
- next_state_id != i,
- "A self-loop state should have at least two outgoing edges.");
+ FUZZTEST_CHECK(next_state_id != i)
+ << "A self-loop state should have at least two outgoing edges.";
for (size_t j = 0; j < states_.size(); ++j) {
for (auto& [next_chars_to_match, state_id] : states_[j].next) {
if (state_id == i) {
diff --git a/fuzztest/internal/fixture_driver.h b/fuzztest/internal/fixture_driver.h
index 43286e3..e489e9f 100644
--- a/fuzztest/internal/fixture_driver.h
+++ b/fuzztest/internal/fixture_driver.h
@@ -260,10 +260,9 @@
target_function_(target_function) {}
void Test(MoveOnlyAny&& args_untyped) const override {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- fixture_ != nullptr,
- "fixture is nullptr. Did you forget to instantiate it in one of the "
- "SetUp methods?");
+ FUZZTEST_PRECONDITION(fixture_ != nullptr)
+ << "fixture is nullptr. Did you forget to instantiate it in one of the "
+ "SetUp methods?";
std::apply(
[&](auto&&... args) {
(fixture_.get()->*target_function_)(
@@ -277,10 +276,10 @@
if constexpr (std::is_invocable_v<SeedProvider, Fixture*>) {
static_assert(std::is_same_v<std::invoke_result_t<SeedProvider, Fixture*>,
std::vector<value_type_t<DomainT>>>);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- fixture_ != nullptr,
- "fixture is nullptr. Did you forget to instantiate it in one of the "
- "SetUp methods?");
+ FUZZTEST_PRECONDITION(fixture_ != nullptr)
+ << "fixture is nullptr. Did you forget to instantiate it in one of "
+ "the "
+ "SetUp methods?";
return this->GetSeedsFromUserValues(
std::invoke(this->seed_provider(), fixture_.get()));
} else if constexpr (std::is_invocable_v<SeedProvider>) {
diff --git a/fuzztest/internal/fixture_driver_test.cc b/fuzztest/internal/fixture_driver_test.cc
index b296e65..7995061 100644
--- a/fuzztest/internal/fixture_driver_test.cc
+++ b/fuzztest/internal/fixture_driver_test.cc
@@ -22,6 +22,7 @@
#include "gtest/gtest.h"
#include "absl/functional/any_invocable.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
#include "./fuzztest/domain_core.h"
#include "./fuzztest/internal/any.h"
#include "./fuzztest/internal/logging.h"
@@ -273,8 +274,7 @@
std::vector<T> values;
values.reserve(generic_values.size());
for (const auto& generic_value : generic_values) {
- FUZZTEST_INTERNAL_CHECK(generic_value.Has<T>(),
- "Generic value of a wrong type.");
+ FUZZTEST_CHECK(generic_value.Has<T>()) << "Generic value of a wrong type.";
values.push_back(generic_value.GetAs<T>());
}
return values;
diff --git a/fuzztest/internal/io.cc b/fuzztest/internal/io.cc
index 760c830..70ba1c7 100644
--- a/fuzztest/internal/io.cc
+++ b/fuzztest/internal/io.cc
@@ -37,6 +37,7 @@
#include "absl/types/span.h"
#include "./common/blob_file.h"
#include "./common/defs.h"
+#include "./common/logging.h"
#include "./common/remote_file.h"
#include "./fuzztest/internal/logging.h"
@@ -47,27 +48,27 @@
// TODO(lszekeres): Return absl::Status instead of bool for these.
bool WriteFile(absl::string_view path, absl::string_view contents) {
- FUZZTEST_INTERNAL_CHECK(false, "Filesystem API not supported in iOS/MacOS");
+ FUZZTEST_LOG(FATAL)( << "Filesystem API not supported in iOS/MacOS";
}
std::optional<std::string> ReadFile(absl::string_view path) {
- FUZZTEST_INTERNAL_CHECK(false, "Filesystem API not supported in iOS/MacOS");
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
bool IsDirectory(absl::string_view path) {
- FUZZTEST_INTERNAL_CHECK(false, "Filesystem API not supported in iOS/MacOS");
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
bool CreateDirectory(absl::string_view path) {
- FUZZTEST_INTERNAL_CHECK(false, "Filesystem API not supported in iOS/MacOS");
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
std::vector<std::string> ListDirectory(absl::string_view path) {
- FUZZTEST_INTERNAL_CHECK(false, "Filesystem API not supported in iOS/MacOS");
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
std::vector<std::string> ListDirectoryRecursively(absl::string_view path) {
- FUZZTEST_INTERNAL_CHECK(false, "Filesystem API not supported in iOS/MacOS");
+ FUZZTEST_LOG(FATAL) << "Filesystem API not supported in iOS/MacOS";
}
#else
@@ -214,12 +215,10 @@
int total_invalid_inputs = 0;
const absl::Time start_time = absl::Now();
for (const std::string& file_path : file_paths) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- fuzztest::internal::RemotePathExists(file_path), "File path ",
- file_path, " does not exist.");
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !fuzztest::internal::RemotePathIsDirectory(file_path), "File path ",
- file_path, " is a directory.");
+ FUZZTEST_PRECONDITION(fuzztest::internal::RemotePathExists(file_path))
+ << "File path " << file_path << " does not exist.";
+ FUZZTEST_PRECONDITION(!fuzztest::internal::RemotePathIsDirectory(file_path))
+ << "File path " << file_path << " is a directory.";
int loaded_inputs_from_file = 0;
int invalid_inputs_from_file = 0;
// The reader cannot be reused for multiple files because of the way it
@@ -273,9 +272,9 @@
std::string contents;
const absl::Status get_contents_status =
fuzztest::internal::RemoteFileGetContents(file_path, contents);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- get_contents_status.ok(), "RemoteFileGetContents failed on ", file_path,
- ", status: ", get_contents_status.message());
+ FUZZTEST_PRECONDITION(get_contents_status.ok())
+ << "RemoteFileGetContents failed on " << file_path
+ << ", status: " << get_contents_status.message();
absl::Status result = consume(file_path, std::nullopt, std::move(contents));
if (result.ok()) {
++total_loaded_inputs;
diff --git a/fuzztest/internal/io_test.cc b/fuzztest/internal/io_test.cc
index be07851..5eb7c17 100644
--- a/fuzztest/internal/io_test.cc
+++ b/fuzztest/internal/io_test.cc
@@ -31,7 +31,6 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/time/clock.h"
@@ -200,14 +199,14 @@
TestWrite(serialized_file, "Input1");
std::unique_ptr<fuzztest::internal::BlobFileWriter> writer =
fuzztest::internal::DefaultBlobFileWriterFactory();
- CHECK(writer->Open(blob_file, "w").ok());
- CHECK(
+ FUZZTEST_CHECK(writer->Open(blob_file, "w").ok());
+ FUZZTEST_CHECK(
writer->Write(fuzztest::internal::AsByteSpan(absl::string_view("Input2")))
.ok());
- CHECK(
+ FUZZTEST_CHECK(
writer->Write(fuzztest::internal::AsByteSpan(absl::string_view("Input3")))
.ok());
- CHECK(writer->Close().ok());
+ FUZZTEST_CHECK(writer->Close().ok());
using InputInFile = std::tuple<std::string, std::optional<int>, std::string>;
std::vector<InputInFile> inputs;
@@ -229,14 +228,14 @@
const std::string file = tmp_dir.path() / "file";
std::unique_ptr<fuzztest::internal::BlobFileWriter> writer =
fuzztest::internal::DefaultBlobFileWriterFactory();
- CHECK(writer->Open(file, "w").ok());
- CHECK(
+ FUZZTEST_CHECK(writer->Open(file, "w").ok());
+ FUZZTEST_CHECK(
writer->Write(fuzztest::internal::AsByteSpan(absl::string_view("Ignore")))
.ok());
- CHECK(
+ FUZZTEST_CHECK(
writer->Write(fuzztest::internal::AsByteSpan(absl::string_view("Accept")))
.ok());
- CHECK(writer->Close().ok());
+ FUZZTEST_CHECK(writer->Close().ok());
using InputInFile = std::tuple<std::string, std::optional<int>, std::string>;
std::vector<InputInFile> inputs;
diff --git a/fuzztest/internal/logging.cc b/fuzztest/internal/logging.cc
index 4521afe..1418360 100644
--- a/fuzztest/internal/logging.cc
+++ b/fuzztest/internal/logging.cc
@@ -21,6 +21,7 @@
#include "absl/base/const_init.h"
#include "absl/base/thread_annotations.h"
#include "absl/synchronization/mutex.h"
+#include "./common/logging.h"
#if defined(__linux__)
#include <unistd.h>
@@ -47,10 +48,10 @@
void Silence(int fd) {
FILE* tmp = fopen("/dev/null", "w");
- FUZZTEST_INTERNAL_CHECK(tmp, "fopen() error:", strerror(errno));
- FUZZTEST_INTERNAL_CHECK(dup2(fileno(tmp), fd) != -1,
- "dup2() error:", strerror(errno));
- FUZZTEST_INTERNAL_CHECK(fclose(tmp) == 0, "fclose() error:", strerror(errno));
+ FUZZTEST_CHECK(tmp) << "fopen() error: " << strerror(errno);
+ FUZZTEST_CHECK(dup2(fileno(tmp), fd) != -1) << "dup2() error: ",
+ strerror(errno);
+ FUZZTEST_CHECK(fclose(tmp) == 0) << "fclose() error: " << strerror(errno);
}
// Only accepts 1 or 2 (stdout or stderr).
@@ -59,12 +60,12 @@
// If it's a stderr, silence it after duping it as the global stderr, which
// will be used internally to log and be used when restoring the stderr.
void DupAndSilence(int fd) {
- FUZZTEST_INTERNAL_CHECK(fd == STDOUT_FILENO || fd == STDERR_FILENO,
- "DupAndSilence only accepts stderr or stdout.");
+ FUZZTEST_CHECK(fd == STDOUT_FILENO || fd == STDERR_FILENO)
+ << "DupAndSilence only accepts stderr or stdout.";
int new_fd = dup(fd);
- FUZZTEST_INTERNAL_CHECK(new_fd != -1, "dup() error:", strerror(errno));
+ FUZZTEST_CHECK(new_fd != -1) << "dup() error:" << strerror(errno);
FILE* new_output_file = fdopen(new_fd, "w");
- FUZZTEST_INTERNAL_CHECK(new_output_file, "fdopen error:", strerror(errno));
+ FUZZTEST_CHECK(new_output_file) << "fdopen error:" << strerror(errno);
if (new_output_file) {
if (fd == STDOUT_FILENO) {
stdout_file_ = new_output_file;
@@ -90,21 +91,21 @@
FILE* silenced_stderr = stderr_file_;
stderr_file_ = stderr;
stderr_file_guard_.Unlock();
- FUZZTEST_INTERNAL_CHECK(silenced_stderr != stderr,
- "Error, calling RestoreStderr without calling"
- "DupandSilenceStderr first.");
- FUZZTEST_INTERNAL_CHECK(dup2(fileno(silenced_stderr), STDERR_FILENO) != -1,
- "dup2 error:", strerror(errno));
- FUZZTEST_INTERNAL_CHECK(fclose(silenced_stderr) == 0,
- "close() error:", strerror(errno));
+ FUZZTEST_CHECK(silenced_stderr != stderr)
+ << "Error, calling RestoreStderr without calling"
+ "DupandSilenceStderr first.";
+ FUZZTEST_CHECK(dup2(fileno(silenced_stderr), STDERR_FILENO) != -1)
+ << "dup2 error:" << strerror(errno);
+ FUZZTEST_CHECK(fclose(silenced_stderr) == 0)
+ << "close() error:" << strerror(errno);
- FUZZTEST_INTERNAL_CHECK(stdout_file_ != stdout,
- "Error, calling RestoreStdout without calling"
- "DupandSilenceStdout first.");
- FUZZTEST_INTERNAL_CHECK(dup2(fileno(stdout_file_), STDOUT_FILENO) != -1,
- "dup2() error:", strerror(errno));
- FUZZTEST_INTERNAL_CHECK(fclose(stdout_file_) == 0,
- "close() error:", strerror(errno));
+ FUZZTEST_CHECK(stdout_file_ != stdout)
+ << "Error, calling RestoreStdout without calling"
+ "DupandSilenceStdout first.";
+ FUZZTEST_CHECK(dup2(fileno(stdout_file_), STDOUT_FILENO) != -1)
+ << "dup2() error:" << strerror(errno);
+ FUZZTEST_CHECK(fclose(stdout_file_) == 0)
+ << "close() error:" << strerror(errno);
stdout_file_ = stdout;
}
@@ -130,11 +131,6 @@
return stderr_file_;
}
-void Abort(const char* file, int line, const std::string& message) {
- fprintf(GetStderr(), "%s:%d: %s\n", file, line, message.c_str());
- std::abort();
-}
-
const std::string* volatile test_abort_message = nullptr;
void AbortInTest(const std::string& message) {
// When we are within a test, we set the message here and call abort().
diff --git a/fuzztest/internal/logging.h b/fuzztest/internal/logging.h
index b7b8d4a..94c9b53 100644
--- a/fuzztest/internal/logging.h
+++ b/fuzztest/internal/logging.h
@@ -20,6 +20,7 @@
#include "absl/strings/str_cat.h"
+// TODO(b/422182911): Remove this library.
namespace fuzztest::internal {
// Returns the current FILE pointing to the original stderr.
@@ -36,21 +37,6 @@
// Check if FUZZTEST_SILENCE_TARGET env set.
bool IsSilenceTargetEnabled();
-[[noreturn]] void Abort(const char* file, int line, const std::string& message);
-
-#define FUZZTEST_INTERNAL_CHECK_PRECONDITION(P, ...) \
- ((P) ? (void)0 \
- : ::fuzztest::internal::Abort( \
- __FILE__, __LINE__, \
- absl::StrCat("Failed precondition (", #P, "): ", __VA_ARGS__)))
-
-#define FUZZTEST_INTERNAL_CHECK(cond, ...) \
- ((cond) ? (void)0 \
- : ::fuzztest::internal::Abort( \
- __FILE__, __LINE__, \
- absl::StrCat("Internal error! Check (", #cond, \
- ") failed: ", __VA_ARGS__)))
-
// This Abort function will inject `message` into the signal handler's output
// along with the file, line and test name of the currently running test.
// Meant for failures related to test setup and not the code under test itself.
diff --git a/fuzztest/internal/register_fuzzing_mocks.cc b/fuzztest/internal/register_fuzzing_mocks.cc
index 1a51cea..6bb05df 100644
--- a/fuzztest/internal/register_fuzzing_mocks.cc
+++ b/fuzztest/internal/register_fuzzing_mocks.cc
@@ -26,7 +26,6 @@
#include "absl/base/fast_type_id.h"
#include "absl/functional/function_ref.h"
-#include "absl/log/absl_check.h"
#include "absl/random/bernoulli_distribution.h"
#include "absl/random/beta_distribution.h"
#include "absl/random/distributions.h"
@@ -36,6 +35,7 @@
#include "absl/random/poisson_distribution.h"
#include "absl/random/zipf_distribution.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
namespace fuzztest::internal {
namespace {
@@ -103,7 +103,7 @@
// Returns a value in the closed-closed range [min, max].
template <typename T>
T ConsumeValueInRange(T min, T max) {
- ABSL_CHECK_LE(min, max);
+ FUZZTEST_CHECK_LE(min, max);
if (min == max) return min;
diff --git a/fuzztest/internal/runtime.cc b/fuzztest/internal/runtime.cc
index 6bb21fe..9db208f 100644
--- a/fuzztest/internal/runtime.cc
+++ b/fuzztest/internal/runtime.cc
@@ -40,7 +40,6 @@
#include "absl/functional/bind_front.h"
#include "absl/functional/function_ref.h"
-#include "absl/log/absl_check.h"
#include "absl/random/bit_gen_ref.h"
#include "absl/random/discrete_distribution.h"
#include "absl/random/random.h"
@@ -58,6 +57,7 @@
#include "absl/time/time.h"
#include "absl/types/span.h"
#include "./common/bazel.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/configuration.h"
#include "./fuzztest/internal/corpus_database.h"
#include "./fuzztest/internal/coverage.h"
@@ -107,7 +107,7 @@
absl::string_view test_name) {
const bool is_reproducer_in_corpus_db =
configuration && configuration->crashing_input_to_reproduce;
- ABSL_CHECK(!reproducer_path.empty() || is_reproducer_in_corpus_db);
+ FUZZTEST_CHECK(!reproducer_path.empty() || is_reproducer_in_corpus_db);
if (!configuration || !configuration->reproduction_command_template) {
absl::string_view reproducer =
is_reproducer_in_corpus_db ? *configuration->crashing_input_to_reproduce
@@ -121,8 +121,8 @@
}
const std::string command_template =
*configuration->reproduction_command_template;
- ABSL_CHECK(absl::StrContains(command_template, kTestFilterPlaceholder));
- ABSL_CHECK(absl::StrContains(command_template, kExtraArgsPlaceholder));
+ FUZZTEST_CHECK(absl::StrContains(command_template, kTestFilterPlaceholder));
+ FUZZTEST_CHECK(absl::StrContains(command_template, kExtraArgsPlaceholder));
if (is_reproducer_in_corpus_db) {
const std::string corpus_db = configuration->corpus_database;
std::vector<std::string> extra_args = {absl::StrCat(
@@ -218,9 +218,8 @@
Basename(reproducer_path));
break;
default:
- FUZZTEST_INTERNAL_CHECK(false,
- "unsupported reproducer output location type "
- "to print reproduction command for");
+ FUZZTEST_CHECK(false) << "unsupported reproducer output location type "
+ "to print reproduction command for";
}
}
absl::Format(
@@ -258,9 +257,9 @@
"- not writing the reproducer file.\n");
return "";
}
- FUZZTEST_INTERNAL_CHECK(!out_location.dir_path.empty(),
- "Reproducer output directory must not be empty if "
- "not reporting to controller.");
+ FUZZTEST_CHECK(!out_location.dir_path.empty())
+ << "Reproducer output directory must not be empty if "
+ "not reporting to controller.";
const std::string content =
current_args_->domain.SerializeCorpus(current_args_->corpus_value)
.ToString();
@@ -474,7 +473,7 @@
void Runtime::SetCurrentTest(const FuzzTest* test,
const Configuration* configuration) {
- ABSL_CHECK((test != nullptr) == (configuration != nullptr));
+ FUZZTEST_CHECK((test != nullptr) == (configuration != nullptr));
current_test_ = test;
current_configuration_ = configuration;
if (configuration == nullptr) return;
@@ -484,11 +483,9 @@
fuzztest::internal::VerifyBazelHasEnoughTimeToRunTest(
creation_time_, test_time_limit, test_counter_,
configuration->fuzz_tests.size());
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- has_enough_time.ok(),
- absl::StrCat("Not enough time for running the fuzz test ",
- test->full_name(), " for ", test_time_limit, ": ",
- has_enough_time));
+ FUZZTEST_PRECONDITION(has_enough_time.ok())
+ << "Not enough time for running the fuzz test " << test->full_name()
+ << " for " << test_time_limit << ": " << has_enough_time;
}
++test_counter_;
}
@@ -678,8 +675,8 @@
corpus_coverage_(execution_coverage_ != nullptr
? execution_coverage_->GetCounterMap().size()
: 0) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(fixture_driver_ != nullptr,
- "Invalid fixture driver!");
+ FUZZTEST_PRECONDITION(fixture_driver_ != nullptr)
+ << "Invalid fixture driver!";
stats_.start_time = absl::Now();
const char* corpus_out_dir_chars = getenv("FUZZTEST_TESTSUITE_OUT_DIR");
if (corpus_out_dir_chars) corpus_out_dir_ = corpus_out_dir_chars;
@@ -807,12 +804,11 @@
std::optional<corpus_type> reproducer;
ForEachInput({std::string(file)},
[&](absl::string_view, std::optional<int>, Input input) {
- FUZZTEST_INTERNAL_CHECK(!reproducer.has_value(),
- "Multiple inputs found in ", file);
+ FUZZTEST_CHECK(!reproducer.has_value())
+ << "Multiple inputs found in " << file;
reproducer = std::move(input.args);
});
- FUZZTEST_INTERNAL_CHECK(reproducer.has_value(),
- "Failed to read minimizer file!");
+ FUZZTEST_CHECK(reproducer.has_value()) << "Failed to read minimizer file!";
return *reproducer;
}
@@ -1066,9 +1062,8 @@
auto duration = absl::Seconds(1);
const auto fuzz_for = absl::NullSafeStringView(getenv("FUZZTEST_FUZZ_FOR"));
if (!fuzz_for.empty()) {
- FUZZTEST_INTERNAL_CHECK(
- absl::ParseDuration(fuzz_for, &duration),
- "Could not parse duration in FUZZTEST_FUZZ_FOR=", fuzz_for);
+ FUZZTEST_CHECK(absl::ParseDuration(fuzz_for, &duration))
+ << "Could not parse duration in FUZZTEST_FUZZ_FOR=" << fuzz_for;
}
const auto time_limit = stats_.start_time + duration;
Input mutation{params_domain_.Init(prng)};
@@ -1158,9 +1153,8 @@
constexpr int kMaxTriedWithoutFailure = 10000;
while (tries_without_failure < kMaxTriedWithoutFailure &&
absl::Now() < deadline) {
- FUZZTEST_INTERNAL_CHECK(
- minimal_non_fatal_counterexample_.has_value(),
- "Caller didn't populate minimal_non_fatal_counterexample_");
+ FUZZTEST_CHECK(minimal_non_fatal_counterexample_.has_value())
+ << "Caller didn't populate minimal_non_fatal_counterexample_";
auto copy = *minimal_non_fatal_counterexample_;
// Mutate a random number of times, in case one is not enough to
// reach another failure, but prefer a low number of mutations (thus Zipf).
@@ -1238,9 +1232,9 @@
corpus_database.GetCoverageInputsIfAny(test_.full_name()));
InitializeCorpus(prng);
- FUZZTEST_INTERNAL_CHECK(!corpus_.empty(),
- "No seed input coverage registered. Test function "
- "might be uninstrumented?");
+ FUZZTEST_CHECK(!corpus_.empty())
+ << "No seed input coverage registered. Test function "
+ "might be uninstrumented?";
constexpr size_t kRunsPerInit = 32000;
size_t next_init = kRunsPerInit;
@@ -1305,8 +1299,8 @@
return {params_domain_.Init(prng)};
} else {
size_t idx = static_cast<size_t>(corpus_distribution_(prng));
- FUZZTEST_INTERNAL_CHECK(0 <= idx && idx < corpus_.size(),
- "Corpus input weights are outdated!\n");
+ FUZZTEST_CHECK(0 <= idx && idx < corpus_.size())
+ << "Corpus input weights are outdated!\n";
return corpus_[idx];
}
}();
diff --git a/fuzztest/internal/seed_seq.cc b/fuzztest/internal/seed_seq.cc
index 1bf485c..2f8896b 100644
--- a/fuzztest/internal/seed_seq.cc
+++ b/fuzztest/internal/seed_seq.cc
@@ -29,6 +29,7 @@
#include "absl/strings/escaping.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
+#include "./common/logging.h"
#include "./fuzztest/internal/logging.h"
namespace fuzztest::internal {
@@ -51,9 +52,9 @@
}
std::optional<std::vector<uint32_t>> seed_material =
DecodeSeedMaterial(encoded_seed_material);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- seed_material.has_value(),
- "Failed to decode seed material from the environment variable ", env_var);
+ FUZZTEST_PRECONDITION(seed_material.has_value())
+ << "Failed to decode seed material from the environment variable "
+ << env_var;
return *std::move(seed_material);
}
diff --git a/fuzztest/internal/subprocess.cc b/fuzztest/internal/subprocess.cc
index 1dbf7e8..54e0aff 100644
--- a/fuzztest/internal/subprocess.cc
+++ b/fuzztest/internal/subprocess.cc
@@ -45,7 +45,7 @@
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/span.h"
-#include "./fuzztest/internal/logging.h"
+#include "./common/logging.h"
#if !defined(_MSC_VER)
// Needed to pass the current environment to posix_spawn, which needs an
@@ -68,7 +68,7 @@
std::variant<ExitCodeT, SignalT> TerminationStatus::Status() const {
if (Exited()) return static_cast<ExitCodeT>(WEXITSTATUS(status_));
- FUZZTEST_INTERNAL_CHECK(Signaled(), "!Exited && !Signaled");
+ FUZZTEST_CHECK(Signaled()) << "!Exited && !Signaled";
return static_cast<SignalT>(WTERMSIG(status_));
}
@@ -108,29 +108,28 @@
void SubProcess::CreatePipes() {
for (int channel : {kStdOutIdx, kStdErrIdx}) {
int pipe_fds[2];
- FUZZTEST_INTERNAL_CHECK(pipe(pipe_fds) == 0,
- "Cannot create pipe: ", strerror(errno));
+ FUZZTEST_CHECK(pipe(pipe_fds) == 0) << "Cannot create pipe: ",
+ strerror(errno);
parent_pipe_[channel] = pipe_fds[0];
child_pipe_[channel] = pipe_fds[1];
- FUZZTEST_INTERNAL_CHECK(
- fcntl(parent_pipe_[channel], F_SETFL, O_NONBLOCK) != -1,
- "Cannot make pipe non-blocking: ", strerror(errno));
+ FUZZTEST_CHECK(fcntl(parent_pipe_[channel], F_SETFL, O_NONBLOCK) != -1)
+ << "Cannot make pipe non-blocking: " << strerror(errno);
}
}
void SubProcess::CloseChildPipes() {
for (int channel : {kStdOutIdx, kStdErrIdx}) {
- FUZZTEST_INTERNAL_CHECK(close(child_pipe_[channel]) != -1,
- "Cannot close pipe: ", strerror(errno));
+ FUZZTEST_CHECK(close(child_pipe_[channel]) != -1)
+ << "Cannot close pipe: " << strerror(errno);
}
}
void SubProcess::CloseParentPipes() {
for (int channel : {kStdOutIdx, kStdErrIdx}) {
- FUZZTEST_INTERNAL_CHECK(close(parent_pipe_[channel]) != -1,
- "Cannot close pipe: ", strerror(errno));
+ FUZZTEST_CHECK(close(parent_pipe_[channel]) != -1)
+ << "Cannot close pipe: " << strerror(errno);
}
}
@@ -141,28 +140,24 @@
int err;
err = posix_spawn_file_actions_init(&actions);
- FUZZTEST_INTERNAL_CHECK(err == 0,
- "Cannot initialize file actions: ", strerror(err));
+ FUZZTEST_CHECK(err == 0) << "Cannot initialize file actions: "
+ << strerror(err);
// Close stdin.
err = posix_spawn_file_actions_addclose(&actions, STDIN_FILENO);
- FUZZTEST_INTERNAL_CHECK(err == 0,
- "Cannot add close() action: ", strerror(err));
+ FUZZTEST_CHECK(err == 0) << "Cannot add close() action: " << strerror(err);
for (int channel : {kStdOutIdx, kStdErrIdx}) {
// Close parent-side pipes.
err = posix_spawn_file_actions_addclose(&actions, parent_pipe_[channel]);
- FUZZTEST_INTERNAL_CHECK(err == 0,
- "Cannot add close() action: ", strerror(err));
+ FUZZTEST_CHECK(err == 0) << "Cannot add close() action: " << strerror(err);
// Replace stdout/stderr file descriptors with the pipes.
int fd = channel == kStdOutIdx ? STDOUT_FILENO : STDERR_FILENO;
err = posix_spawn_file_actions_adddup2(&actions, child_pipe_[channel], fd);
- FUZZTEST_INTERNAL_CHECK(err == 0,
- "Cannot add dup2() action: ", strerror(err));
+ FUZZTEST_CHECK(err == 0) << "Cannot add dup2() action: " << strerror(err);
err = posix_spawn_file_actions_addclose(&actions, child_pipe_[channel]);
- FUZZTEST_INTERNAL_CHECK(err == 0,
- "Cannot add close() action: ", strerror(err));
+ FUZZTEST_CHECK(err == 0) << "Cannot add close() action: " << strerror(err);
}
return actions;
@@ -198,16 +193,15 @@
int err;
err = posix_spawnp(&child_pid, argv[0], &actions, nullptr, argv.data(),
environment.has_value() ? envp.data() : environ);
- FUZZTEST_INTERNAL_CHECK(err == 0,
- "Cannot spawn child process: ", strerror(err));
+ FUZZTEST_CHECK(err == 0) << "Cannot spawn child process: ", strerror(err);
// Free up the used parameters.
for (char* p : argv) free(p);
for (char* p : envp) free(p);
err = posix_spawn_file_actions_destroy(&actions);
- FUZZTEST_INTERNAL_CHECK(err == 0,
- "Cannot destroy file actions: ", strerror(err));
+ FUZZTEST_CHECK(err == 0)
+ "Cannot destroy file actions: " << strerror(err);
return child_pid;
}
@@ -235,9 +229,9 @@
while (fd_remain > 0) {
int ret = poll(pfd, fd_count, -1);
if ((ret == -1) && !ShouldRetry(errno)) {
- FUZZTEST_INTERNAL_CHECK(false, "Cannot poll(): ", strerror(errno));
+ FUZZTEST_CHECK(false) << "Cannot poll(): " << strerror(errno);
} else if (ret == 0) {
- FUZZTEST_INTERNAL_CHECK(false, "Impossible timeout: ", strerror(errno));
+ FUZZTEST_CHECK(false) << "Impossible timeout: " << strerror(errno);
} else if (ret > 0) {
for (int channel : {kStdOutIdx, kStdErrIdx}) {
// According to the poll() spec, use -1 for ignored entries.
@@ -274,7 +268,7 @@
} else if (ret == pid && (WIFEXITED(status) || WIFSIGNALED(status))) {
return status;
} else {
- FUZZTEST_INTERNAL_CHECK(false, "wait() error: ", strerror(errno));
+ FUZZTEST_CHECK(false) << "wait() error: " << strerror(errno);
}
}
}
@@ -291,8 +285,8 @@
continue;
} else if (ret == 0) { // Still running.
if (should_stop()) {
- FUZZTEST_INTERNAL_CHECK(kill(pid, SIGTERM) == 0,
- "Cannot kill(): ", strerror(errno));
+ FUZZTEST_CHECK(kill(pid, SIGTERM) == 0)
+ << "Cannot kill(): " << strerror(errno);
return Wait(pid);
} else {
absl::SleepFor(sleep_duration);
@@ -301,7 +295,7 @@
} else if (ret == pid && (WIFEXITED(status) || WIFSIGNALED(status))) {
return status;
} else {
- FUZZTEST_INTERNAL_CHECK(false, "wait() error: ", strerror(errno));
+ FUZZTEST_CHECK(false) "wait() error: " << strerror(errno);
}
}
}
@@ -336,15 +330,13 @@
const std::optional<absl::flat_hash_map<std::string, std::string>>&
environment) {
#if defined(_MSC_VER)
- FUZZTEST_INTERNAL_CHECK(false,
- "Subprocess library not implemented on Windows yet.");
+ FUZZTEST_CHECK(false) << "Subprocess library not implemented on Windows yet.";
#elif defined(__ANDROID_MIN_SDK_VERSION__) && __ANDROID_MIN_SDK_VERSION__ < 28
- FUZZTEST_INTERNAL_CHECK(
- false,
- "Subprocess library not implemented on older Android NDK versions yet");
+ FUZZTEST_CHECK(false)
+ << "Subprocess library not implemented on older Android NDK versions yet";
#elif defined(TARGET_OS_TV) && TARGET_OS_TV
- FUZZTEST_INTERNAL_CHECK(
- false, "Subprocess library not implemented on Apple tvOS yet");
+ FUZZTEST_INTERNAL_CHECK(false)
+ << "Subprocess library not implemented on Apple tvOS yet";
#else
SubProcess proc;
return proc.Run(command_line, on_stdout_output, on_stderr_output, should_stop,
diff --git a/fuzztest/llvm_fuzzer_wrapper.cc b/fuzztest/llvm_fuzzer_wrapper.cc
index 49c3235..c187773 100644
--- a/fuzztest/llvm_fuzzer_wrapper.cc
+++ b/fuzztest/llvm_fuzzer_wrapper.cc
@@ -12,17 +12,16 @@
#include "absl/base/thread_annotations.h"
#include "absl/flags/declare.h"
#include "absl/flags/flag.h"
-#include "absl/log/absl_check.h"
#include "absl/random/bit_gen_ref.h"
#include "absl/random/random.h"
#include "absl/synchronization/mutex.h"
+#include "./common/logging.h"
#include "./fuzztest/fuzztest.h"
#include "./fuzztest/fuzztest_macros.h"
#include "./fuzztest/internal/domains/arbitrary_impl.h"
#include "./fuzztest/internal/domains/container_of_impl.h"
#include "./fuzztest/internal/domains/domain_base.h"
#include "./fuzztest/internal/io.h"
-#include "./fuzztest/internal/logging.h"
ABSL_DECLARE_FLAG(std::string, llvm_fuzzer_wrapper_dict_file);
ABSL_DECLARE_FLAG(std::string, llvm_fuzzer_wrapper_corpus_dir);
@@ -75,7 +74,7 @@
for (const fuzztest::internal::FilePathAndData& file : files) {
absl::StatusOr<std::vector<std::string>> parsed_entries =
fuzztest::ParseDictionary(file.data);
- ABSL_CHECK(parsed_entries.status().ok())
+ FUZZTEST_CHECK(parsed_entries.status().ok())
<< "Could not parse dictionary file " << file.path << ": "
<< parsed_entries.status();
for (const std::string& parsed_entry : *parsed_entries) {
@@ -104,45 +103,38 @@
public:
void Activate(MutationMetadata mutation_metadata) {
absl::MutexLock lock(&mu_);
- FUZZTEST_INTERNAL_CHECK(
- !mutation_metadata_.has_value(),
- "MutationMetadata is already active before calling Activate()!");
- FUZZTEST_INTERNAL_CHECK(
- acquire_count_ == 0,
- "MutationMetadata still has readers before being calling Activate()!");
+ FUZZTEST_CHECK(!mutation_metadata_.has_value())
+ << "MutationMetadata is already active before calling Activate()!";
+ FUZZTEST_CHECK(acquire_count_ == 0) << "MutationMetadata still has readers "
+ "before being calling Activate()!";
mutation_metadata_ = std::move(mutation_metadata);
}
void Deactivate() {
absl::MutexLock lock(&mu_);
- FUZZTEST_INTERNAL_CHECK(
- mutation_metadata_.has_value(),
- "MutationMetadata is not active before calling Deactivate()!");
- FUZZTEST_INTERNAL_CHECK(
- acquire_count_ == 0,
- "MutationMetadata still has readers before calling Deactivate()!");
+ FUZZTEST_CHECK(mutation_metadata_.has_value())
+ << "MutationMetadata is not active before calling Deactivate()!";
+ FUZZTEST_CHECK(acquire_count_ == 0)
+ << "MutationMetadata still has readers before calling Deactivate()!";
mutation_metadata_ = std::nullopt;
}
const MutationMetadata& Acquire() {
absl::MutexLock lock(&mu_);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- mutation_metadata_.has_value(),
- "Cannot acquire unavailable mutation metadata, likely due to the "
- "fuzzer calling LLVMFuzzerMutate() outside of "
- "LLVMFuzzerCustomMutator() invocation, which is not allowed.");
+ FUZZTEST_PRECONDITION(mutation_metadata_.has_value())
+ << "Cannot acquire unavailable mutation metadata, likely due to the "
+ "fuzzer calling LLVMFuzzerMutate() outside of "
+ "LLVMFuzzerCustomMutator() invocation, which is not allowed.";
++acquire_count_;
return *mutation_metadata_;
}
void Release() {
absl::MutexLock lock(&mu_);
- FUZZTEST_INTERNAL_CHECK(
- mutation_metadata_.has_value(),
- "MutationMetadata is not active before calling Release()!");
- FUZZTEST_INTERNAL_CHECK(
- acquire_count_ > 0,
- "MutationMetadata has no readers before calling Release()!");
+ FUZZTEST_CHECK(mutation_metadata_.has_value())
+ << "MutationMetadata is not active before calling Release()!";
+ FUZZTEST_CHECK(acquire_count_ > 0)
+ << "MutationMetadata has no readers before calling Release()!";
--acquire_count_;
}
diff --git a/grammar_codegen/BUILD b/grammar_codegen/BUILD
index 8b6b140..f7155bd 100644
--- a/grammar_codegen/BUILD
+++ b/grammar_codegen/BUILD
@@ -29,9 +29,11 @@
features = ["-use_header_modules"], # Incompatible with -fexceptions.
deps = [
":grammar_info",
+ "@abseil-cpp//absl/log:absl_check",
+ "@abseil-cpp//absl/log:absl_log",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
- "@com_google_fuzztest//fuzztest/internal:logging",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//grammar_codegen/generated_antlr_parser",
],
)
@@ -46,6 +48,7 @@
"@abseil-cpp//absl/container:flat_hash_set",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/strings:str_format",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//fuzztest/internal:logging",
],
)
diff --git a/grammar_codegen/antlr_frontend.cc b/grammar_codegen/antlr_frontend.cc
index cabb68b..4174fdf 100644
--- a/grammar_codegen/antlr_frontend.cc
+++ b/grammar_codegen/antlr_frontend.cc
@@ -25,9 +25,9 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
#include "./grammar_codegen/generated_antlr_parser/ANTLRv4Lexer.h"
#include "./grammar_codegen/grammar_info.h"
-#include "./fuzztest/internal/logging.h"
namespace fuzztest::internal::grammar {
@@ -56,9 +56,9 @@
// Add '^' to the char set if it is a NOT set.
std::string ConstructCharSetString(absl::string_view raw_str,
bool is_not_set = false) {
- FUZZTEST_INTERNAL_CHECK(
- raw_str.size() > 2 && raw_str.front() == '[' && raw_str.back() == ']',
- "Passed argument is not a range string: `" + std::string(raw_str) + "`");
+ FUZZTEST_CHECK(raw_str.size() > 2 && raw_str.front() == '[' &&
+ raw_str.back() == ']')
+ << "Passed argument is not a range string: `" << raw_str << "`";
std::string result(raw_str);
if (is_not_set) {
result = absl::StrFormat("[^%s]", result.substr(1, result.size() - 2));
@@ -104,7 +104,7 @@
if (lexer_atom_ctx->terminal() && lexer_atom_ctx->terminal()->TOKEN_REF()) {
auto k = block.element.emplace<kNonTerminal>(
NonTerminal{lexer_atom_ctx->getText()});
- FUZZTEST_INTERNAL_CHECK(!k.name.empty(), "Empty name!");
+ FUZZTEST_CHECK(!k.name.empty()) << "Empty name!";
} else {
auto& terminal = block.element.emplace<kTerminal>();
std::string text = lexer_atom_ctx->getText();
@@ -123,16 +123,16 @@
terminal.content =
ConstructCharSetString(set_element_p->getText(), true);
} else {
- FUZZTEST_INTERNAL_CHECK(false, "Not lexer char set!");
+ FUZZTEST_CHECK(false) << "Not lexer char set!";
}
} else {
- FUZZTEST_INTERNAL_CHECK(false, "Unhandled case!");
+ FUZZTEST_CHECK(false) << "Unhandled case!";
}
} else if (lexer_atom_ctx->DOT()) {
terminal.type = TerminalType::kCharSet;
terminal.content = EscapeString(lexer_atom_ctx->DOT()->getText());
} else {
- FUZZTEST_INTERNAL_CHECK(false, "Unhandled case!");
+ FUZZTEST_CHECK(false) << "Unhandled case!";
}
}
return block;
@@ -152,7 +152,7 @@
} else if (element->lexerAtom() != NULL) {
block = ConstructBlock(element->lexerAtom());
} else {
- FUZZTEST_INTERNAL_CHECK(false, "Unhandled case!");
+ FUZZTEST_CHECK(false) << "Unhandled case!";
}
if (element->ebnfSuffix()) {
block.range = ParseRange(element->ebnfSuffix()->getText());
@@ -175,13 +175,14 @@
}
Range GrammarInfoBuilder::ParseRange(absl::string_view s) {
- return (s == "?") ? Range::kOptional
- : (s == "+" || s == "+?") ? Range::kNonEmpty
- : (s == "*" || s == "*?")
- ? Range::kUnlimited
- : (FUZZTEST_INTERNAL_CHECK(false,
- absl::StrCat("Unhandled case: ", s)),
- Range::kNoRange);
+ if (s == "?") {
+ return Range::kOptional;
+ } else if (s == "+" || s == "*?") {
+ return Range::kNonEmpty;
+ } else if (s == "*" || s == "*?") {
+ return Range::kUnlimited;
+ }
+ FUZZTEST_CHECK(false) << "Unhandled case: " << s;
}
Block GrammarInfoBuilder::ConstructBlock(
@@ -209,7 +210,7 @@
ChangeStringQuote(node_name);
terminal_node.content = node_name;
} else {
- FUZZTEST_INTERNAL_CHECK(false, "Unhandled case!");
+ FUZZTEST_CHECK(false) << "Unhandled case!";
}
return constructed_block;
}
@@ -231,15 +232,14 @@
} else if (labeled_element->block()) {
constructed_block = ConstructBlock(labeled_element->block());
} else {
- FUZZTEST_INTERNAL_CHECK(false, "Impossible case!");
+ FUZZTEST_CHECK(false) << "Impossible case!";
}
} else {
- FUZZTEST_INTERNAL_CHECK(false, "Unhandled case!");
+ FUZZTEST_CHECK(false) << "Unhandled case!";
}
if (element->ebnfSuffix()) {
- FUZZTEST_INTERNAL_CHECK(!suffix.has_value(),
- "It should have only one suffix.");
+ FUZZTEST_CHECK(!suffix.has_value()) << "It should have only one suffix.";
suffix = element->ebnfSuffix()->getText();
}
@@ -272,7 +272,7 @@
auto labeledAlt_vec = pctx->ruleBlock()->ruleAltList()->labeledAlt();
for (auto labeled_alt : pctx->ruleBlock()->ruleAltList()->labeledAlt()) {
auto ctx = labeled_alt->alternative();
- FUZZTEST_INTERNAL_CHECK(ctx != nullptr, "Unhandeled case!");
+ FUZZTEST_CHECK(ctx != nullptr) << "Unhandeled case!";
grammar_rule.productions.production_rules.push_back(
ConstructProductionRule(ctx));
}
@@ -282,8 +282,7 @@
Grammar GrammarInfoBuilder::BuildGrammarInfo(
const std::vector<std::string>& input_grammar_specs,
std::optional<std::string> grammar_name, bool insert_space_between_blocks) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(!input_grammar_specs.empty(),
- "No input files!");
+ FUZZTEST_PRECONDITION(!input_grammar_specs.empty()) << "No input files!";
insert_space_between_blocks_ = insert_space_between_blocks;
@@ -297,18 +296,18 @@
antlr4::tree::ParseTree* tree = parser.grammarSpec();
antlr4::tree::ParseTreeWalker::DEFAULT.walk(this, tree);
} catch (antlr4::ParseCancellationException) {
- FUZZTEST_INTERNAL_CHECK(false, "Cannot parse the grammar files!");
+ FUZZTEST_CHECK(false) << "Cannot parse the grammar files!";
} catch (...) {
// The ParseCancellationException might miss some errors. So we need to
// catch everything here.
- FUZZTEST_INTERNAL_CHECK(false, "Unknown errors!");
+ FUZZTEST_CHECK(false) << "Unknown errors!";
}
}
if (grammar_name.has_value()) {
grammar_name_ = *grammar_name;
}
- FUZZTEST_INTERNAL_CHECK(!grammar_name_.empty() && !rules_.empty(),
- "Wrong grammar file!");
+ FUZZTEST_CHECK(!grammar_name_.empty() && !rules_.empty())
+ << "Wrong grammar file!";
return Grammar{std::move(grammar_name_), std::move(rules_)};
}
diff --git a/grammar_codegen/backend.cc b/grammar_codegen/backend.cc
index c3dae47..532318f 100644
--- a/grammar_codegen/backend.cc
+++ b/grammar_codegen/backend.cc
@@ -24,6 +24,7 @@
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
#include "absl/strings/string_view.h"
+#include "./common/logging.h"
#include "./grammar_codegen/grammar_info.h"
#include "./fuzztest/internal/logging.h"
@@ -45,11 +46,9 @@
std::string CreateIRNodeNameForClass(absl::string_view symbol_name) {
static int counter = 0;
- FUZZTEST_INTERNAL_CHECK(
- symbol_name.size() > 4 &&
- symbol_name.substr(symbol_name.size() - 4) == "Node",
- std::string("Not a valid symbol class name: ") + " " +
- std::string(symbol_name));
+ FUZZTEST_CHECK(symbol_name.size() > 4 &&
+ symbol_name.substr(symbol_name.size() - 4) == "Node")
+ << "Not a valid symbol class name: " << symbol_name;
return absl::StrFormat(
"%sSubNode%d", symbol_name.substr(0, symbol_name.size() - 4), counter++);
}
@@ -284,18 +283,16 @@
std::string class_name = GetClassNameForSymbol(rule.symbol_name);
const std::vector<ProductionRule>& prod_rules =
rule.productions.production_rules;
- FUZZTEST_INTERNAL_CHECK(!prod_rules.empty(), "No expansion!");
+ FUZZTEST_CHECK(!prod_rules.empty()) << "No expansion!";
if (prod_rules.size() > 1) {
// This is a variant.
std::vector<std::string> production_child_types;
for (const ProductionRule& prod_rule : prod_rules) {
- FUZZTEST_INTERNAL_CHECK(prod_rule.blocks.size() == 1,
- "Incorrect preprocess.");
+ FUZZTEST_CHECK(prod_rule.blocks.size() == 1) << "Incorrect preprocess.";
auto block = prod_rule.blocks[0];
- FUZZTEST_INTERNAL_CHECK(
- block.range == Range::kNoRange &&
- block.element.index() != BlockType::kSubProductions,
- "Incorrect preprocess.");
+ FUZZTEST_CHECK(block.range == Range::kNoRange &&
+ block.element.index() != BlockType::kSubProductions)
+ << "Incorrect preprocess.";
production_child_types.push_back(GetClassName(block));
}
return absl::StrFormat("VariantDomain<k%s, %d, %s>", class_name,
@@ -312,10 +309,9 @@
std::vector<std::string> production_child_types;
auto blocks = prod_rules[0].blocks;
for (const auto& block : blocks) {
- FUZZTEST_INTERNAL_CHECK(
- block.range == Range::kNoRange &&
- block.element.index() != BlockType::kSubProductions,
- "Incorrect preprocess.");
+ FUZZTEST_CHECK(block.range == Range::kNoRange &&
+ block.element.index() != BlockType::kSubProductions)
+ << "Incorrect preprocess.";
production_child_types.push_back(GetClassName(block));
}
return absl::StrFormat("TupleDomain<k%s, %s>", class_name,
@@ -390,7 +386,7 @@
return is_safe;
}
default:
- FUZZTEST_INTERNAL_CHECK(false, "The execution should never reach here!");
+ FUZZTEST_LOG(FATAL) << "unreachable";
}
}
@@ -422,9 +418,8 @@
} while (has_change);
for (size_t i = 0; i < safe_rule_indexes.size(); ++i) {
- FUZZTEST_INTERNAL_CHECK(
- safe_rule_indexes[i],
- absl::StrCat("Some node is not safe: ", rules[i].symbol_name));
+ FUZZTEST_CHECK(safe_rule_indexes[i])
+ << "Some node is not safe: " << rules[i].symbol_name;
}
// Ensure that every sub-block is marked safe. For example, a grammar rule
@@ -453,13 +448,13 @@
return GetClassNameForSymbol(
std::get<BlockType::kNonTerminal>(block.element).name);
default:
- FUZZTEST_INTERNAL_CHECK(false, "A sub-block doesn't have a name!");
+ FUZZTEST_LOG(FATAL) << "A sub-block doesn't have a name!";
}
return "";
}
std::string CodeGenerator::GetClassNameForSymbol(std::string id) {
- FUZZTEST_INTERNAL_CHECK(!id.empty(), "Empty node name!");
+ FUZZTEST_CHECK(!id.empty()) << "Empty node name!";
id[0] = toupper(id[0]);
if (std::isdigit(id.back())) {
return id;
diff --git a/tools/BUILD b/tools/BUILD
index 4587e7a..e441ce5 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -29,7 +29,7 @@
deps = [
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/flags:parse",
- "@com_google_fuzztest//fuzztest/internal:logging",
+ "@com_google_fuzztest//common:logging",
"@com_google_fuzztest//grammar_codegen:code_generation",
],
)
diff --git a/tools/grammar_domain_code_generator.cc b/tools/grammar_domain_code_generator.cc
index 66ba9bc..0e0377e 100644
--- a/tools/grammar_domain_code_generator.cc
+++ b/tools/grammar_domain_code_generator.cc
@@ -27,8 +27,8 @@
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
+#include "./common/logging.h"
#include "./grammar_codegen/code_generation.h"
-#include "./fuzztest/internal/logging.h"
ABSL_FLAG(std::string, output_header_file_path, "",
"Required. The path of the generated grammar header file.");
@@ -62,19 +62,16 @@
absl::ParseCommandLine(argc, argv);
std::string output_file_path = absl::GetFlag(FLAGS_output_header_file_path);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !output_file_path.empty(),
- "You must specify output file with --output_header_file_path");
+ FUZZTEST_PRECONDITION(!output_file_path.empty())
+ << "You must specify output file with --output_header_file_path";
std::ofstream output_file(output_file_path);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(output_file.is_open(),
- "Cannot open output file!");
+ FUZZTEST_PRECONDITION(output_file.is_open()) << "Cannot open output file!";
std::vector<std::string> input_files =
absl::GetFlag(FLAGS_input_grammar_files);
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(
- !input_files.empty(),
- "You must provide the list of input files, separated by ','");
+ FUZZTEST_PRECONDITION(!input_files.empty())
+ << "You must provide the list of input files, separated by ','";
std::optional<std::string> grammar_name = std::nullopt;
if (!absl::GetFlag(FLAGS_top_level_rule).empty()) {
@@ -83,8 +80,8 @@
std::vector<std::string> input_grammar_specs;
for (const std::string& input_file : input_files) {
- FUZZTEST_INTERNAL_CHECK_PRECONDITION(std::filesystem::exists(input_file),
- input_file.c_str(), " not exist!");
+ FUZZTEST_PRECONDITION(std::filesystem::exists(input_file))
+ << input_file.c_str() << " not exist!";
input_grammar_specs.push_back(GetContents(input_file));
}
output_file << fuzztest::internal::grammar::GenerateGrammarHeader(