Skip to content

Commit d0e313b

Browse files
Markus Kusanocopybara-github
authored andcommitted
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
1 parent 45a1c3a commit d0e313b

File tree

132 files changed

+1654
-1727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+1654
-1727
lines changed

centipede/BUILD

Lines changed: 14 additions & 71 deletions
Large diffs are not rendered by default.

centipede/analyze_corpora.cc

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include "absl/container/flat_hash_map.h"
2626
#include "absl/container/flat_hash_set.h"
27-
#include "absl/log/check.h"
28-
#include "absl/log/log.h"
2927
#include "./centipede/binary_info.h"
3028
#include "./centipede/control_flow.h"
3129
#include "./centipede/corpus.h"
@@ -48,17 +46,17 @@ std::vector<CorpusRecord> ReadCorpora(std::string_view binary_name,
4846
WorkDir workdir(std::string(workdir_path), std::string(binary_name),
4947
std::string(binary_hash), /*my_shard_index=*/0);
5048
std::vector<std::string> corpus_paths;
51-
CHECK_OK(
49+
FUZZTEST_CHECK_OK(
5250
RemoteGlobMatch(workdir.CorpusFilePaths().AllShardsGlob(), corpus_paths));
5351
std::vector<std::string> features_paths;
54-
CHECK_OK(RemoteGlobMatch(workdir.FeaturesFilePaths().AllShardsGlob(),
55-
features_paths));
52+
FUZZTEST_CHECK_OK(RemoteGlobMatch(workdir.FeaturesFilePaths().AllShardsGlob(),
53+
features_paths));
5654

57-
CHECK_EQ(corpus_paths.size(), features_paths.size());
55+
FUZZTEST_CHECK_EQ(corpus_paths.size(), features_paths.size());
5856
std::vector<CorpusRecord> corpus;
5957
for (int i = 0; i < corpus_paths.size(); ++i) {
60-
LOG(INFO) << "Reading corpus at: " << corpus_paths[i];
61-
LOG(INFO) << "Reading features at: " << features_paths[i];
58+
FUZZTEST_LOG(INFO) << "Reading corpus at: " << corpus_paths[i];
59+
FUZZTEST_LOG(INFO) << "Reading features at: " << features_paths[i];
6260
ReadShard(corpus_paths[i], features_paths[i],
6361
[&corpus](ByteArray input, FeatureVec features) {
6462
corpus.push_back({std::move(input), std::move(features)});
@@ -126,9 +124,10 @@ AnalyzeCorporaResults AnalyzeCorpora(const BinaryInfo &binary_info,
126124
a_only_pcs.insert(pc);
127125
}
128126
}
129-
LOG(INFO) << VV(a.size()) << VV(b.size()) << VV(a_pcs.size())
130-
<< VV(a_only_pcs.size()) << VV(b_only_pcs.size())
131-
<< VV(b_shared_indices.size()) << VV(b_unique_indices.size());
127+
FUZZTEST_LOG(INFO) << VV(a.size()) << VV(b.size()) << VV(a_pcs.size())
128+
<< VV(a_only_pcs.size()) << VV(b_only_pcs.size())
129+
<< VV(b_shared_indices.size())
130+
<< VV(b_unique_indices.size());
132131

133132
// Sort PCs to put them in the canonical order, as in pc_table.
134133
AnalyzeCorporaResults ret;
@@ -178,7 +177,7 @@ CoverageResults GetCoverage(std::string_view binary_name,
178177

179178
void DumpCoverageReport(const CoverageResults &coverage_results,
180179
std::string_view coverage_report_path) {
181-
LOG(INFO) << "Dump coverage to file: " << coverage_report_path;
180+
FUZZTEST_LOG(INFO) << "Dump coverage to file: " << coverage_report_path;
182181

183182
const fuzztest::internal::PCTable &pc_table =
184183
coverage_results.binary_info.pc_table;
@@ -187,7 +186,7 @@ void DumpCoverageReport(const CoverageResults &coverage_results,
187186

188187
fuzztest::internal::SymbolTable coverage_symbol_table;
189188
for (const PCIndex pc : coverage_results.pcs) {
190-
CHECK_LE(pc, symbols.size());
189+
FUZZTEST_CHECK_LE(pc, symbols.size());
191190
if (!pc_table[pc].has_flag(fuzztest::internal::PCInfo::kFuncEntry))
192191
continue;
193192
const SymbolTable::Entry entry = symbols.entry(pc);
@@ -197,7 +196,7 @@ void DumpCoverageReport(const CoverageResults &coverage_results,
197196
std::ostringstream symbol_table_stream;
198197
coverage_symbol_table.WriteToLLVMSymbolizer(symbol_table_stream);
199198

200-
CHECK_OK(
199+
FUZZTEST_CHECK_OK(
201200
RemoteFileSetContents(coverage_report_path, symbol_table_stream.str()));
202201
}
203202

@@ -210,8 +209,9 @@ AnalyzeCorporaResults AnalyzeCorpora(std::string_view binary_name,
210209
BinaryInfo binary_info_b =
211210
ReadBinaryInfo(binary_name, binary_hash, workdir_b);
212211

213-
CHECK_EQ(binary_info_a.pc_table.size(), binary_info_b.pc_table.size());
214-
CHECK_EQ(binary_info_a.symbols.size(), binary_info_b.symbols.size());
212+
FUZZTEST_CHECK_EQ(binary_info_a.pc_table.size(),
213+
binary_info_b.pc_table.size());
214+
FUZZTEST_CHECK_EQ(binary_info_a.symbols.size(), binary_info_b.symbols.size());
215215

216216
const std::vector<CorpusRecord> a =
217217
ReadCorpora(binary_name, binary_hash, workdir_a);
@@ -235,26 +235,26 @@ void AnalyzeCorporaToLog(std::string_view binary_name,
235235
CoverageLogger coverage_logger(pc_table, symbols);
236236

237237
// TODO(kcc): use frontier_a to show the most interesting b-only PCs.
238-
// TODO(kcc): these cause a CHECK-fail
238+
// TODO(kcc): these cause a FUZZTEST_CHECK-fail
239239
// CoverageFrontier frontier_a(results.binary_info);
240240
// frontier_a.Compute(a);
241241

242242
// First, print the newly covered functions (including partially covered).
243-
LOG(INFO) << "B-only new functions:";
243+
FUZZTEST_LOG(INFO) << "B-only new functions:";
244244
absl::flat_hash_set<std::string_view> b_only_new_functions;
245245
for (const auto pc : results.b_only_pcs) {
246246
if (!pc_table[pc].has_flag(PCInfo::kFuncEntry)) continue;
247247
auto str = coverage_logger.ObserveAndDescribeIfNew(pc);
248-
if (!str.empty()) LOG(INFO).NoPrefix() << str;
248+
if (!str.empty()) FUZZTEST_LOG(INFO).NoPrefix() << str;
249249
b_only_new_functions.insert(symbols.func(pc));
250250
}
251251

252252
// Now, print newly covered edges in functions that were covered in `a`.
253-
LOG(INFO) << "B-only new edges:";
253+
FUZZTEST_LOG(INFO) << "B-only new edges:";
254254
for (const auto pc : results.b_only_pcs) {
255255
if (b_only_new_functions.contains(symbols.func(pc))) continue;
256256
auto str = coverage_logger.ObserveAndDescribeIfNew(pc);
257-
if (!str.empty()) LOG(INFO).NoPrefix() << str;
257+
if (!str.empty()) FUZZTEST_LOG(INFO).NoPrefix() << str;
258258
}
259259
}
260260

centipede/analyze_corpora.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ AnalyzeCorporaResults AnalyzeCorpora(std::string_view binary_name,
6262
std::string_view workdir_a,
6363
std::string_view workdir_b);
6464

65-
// Same as above but `LOG`s the results for human consumption.
65+
// Same as above but `FUZZTEST_LOG`s the results for human consumption.
6666
void AnalyzeCorporaToLog(std::string_view binary_name,
6767
std::string_view binary_hash,
6868
std::string_view workdir_a,

centipede/analyze_corpora_test.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424

2525
#include "gmock/gmock.h"
2626
#include "gtest/gtest.h"
27-
#include "absl/log/check.h"
28-
#include "absl/log/log.h"
2927
#include "./centipede/binary_info.h"
3028
#include "./centipede/environment.h"
3129
#include "./centipede/symbol_table.h"
3230
#include "./centipede/test_coverage_util.h"
31+
#include "./common/logging.h"
3332
#include "./common/remote_file.h"
3433
#include "./common/test_util.h"
3534

@@ -47,7 +46,7 @@ static std::string GetTargetPath() {
4746
}
4847

4948
// TODO(ussuri): Implement.
50-
TEST(AnalyzeCorpora, AnalyzeCorpora) { LOG(INFO) << "Unimplemented"; }
49+
TEST(AnalyzeCorpora, AnalyzeCorpora) { FUZZTEST_LOG(INFO) << "Unimplemented"; }
5150

5251
TEST(GetCoverage, SimpleCoverageResults) {
5352
Environment env;

centipede/binary_info.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@
2222
#include <utility>
2323
#include <vector>
2424

25-
#include "absl/log/check.h"
26-
#include "absl/log/log.h"
2725
#include "absl/strings/str_cat.h"
2826
#include "absl/strings/str_split.h"
2927
#include "./centipede/command.h"
3028
#include "./centipede/control_flow.h"
3129
#include "./centipede/pc_info.h"
3230
#include "./centipede/util.h"
31+
#include "./common/logging.h"
3332
#include "./common/remote_file.h"
3433

3534
namespace fuzztest::internal {
@@ -45,18 +44,18 @@ void BinaryInfo::InitializeFromSanCovBinary(
4544
std::string_view symbolizer_path, std::string_view tmp_dir_path) {
4645
if (binary_path_with_args.empty()) {
4746
// This usually happens in tests.
48-
LOG(INFO) << __func__ << ": binary_path_with_args is empty";
47+
FUZZTEST_LOG(INFO) << __func__ << ": binary_path_with_args is empty";
4948
return;
5049
}
5150
// Compute names for temp files.
5251
const std::filesystem::path tmp_dir = tmp_dir_path;
53-
CHECK(std::filesystem::exists(tmp_dir) &&
54-
std::filesystem::is_directory(tmp_dir));
52+
FUZZTEST_CHECK(std::filesystem::exists(tmp_dir) &&
53+
std::filesystem::is_directory(tmp_dir));
5554
ScopedFile pc_table_path(tmp_dir_path, "pc_table_tmp");
5655
ScopedFile cf_table_path(tmp_dir_path, "cf_table_tmp");
5756
ScopedFile dso_table_path(tmp_dir_path, "dso_table_tmp");
5857
ScopedFile log_path(tmp_dir_path, "binary_info_log_tmp");
59-
LOG(INFO) << __func__ << ": tmp_dir: " << tmp_dir;
58+
FUZZTEST_LOG(INFO) << __func__ << ": tmp_dir: " << tmp_dir;
6059

6160
Command::Options cmd_options;
6261
cmd_options.env_add = {absl::StrCat(
@@ -66,7 +65,7 @@ void BinaryInfo::InitializeFromSanCovBinary(
6665
Command cmd{binary_path_with_args, std::move(cmd_options)};
6766
int exit_code = cmd.Execute();
6867
if (exit_code != EXIT_SUCCESS) {
69-
LOG(INFO) << __func__ << ": exit_code: " << exit_code;
68+
FUZZTEST_LOG(INFO) << __func__ << ": exit_code: " << exit_code;
7069
}
7170

7271
// Load PC Table.
@@ -80,24 +79,25 @@ void BinaryInfo::InitializeFromSanCovBinary(
8079
dso_table = ReadDsoTableFromFile(dso_table_path.path());
8180

8281
if (pc_table.empty()) {
83-
CHECK(dso_table.empty());
82+
FUZZTEST_CHECK(dso_table.empty());
8483
// Fallback to GetPcTableFromBinaryWithTracePC().
85-
LOG(WARNING)
84+
FUZZTEST_LOG(WARNING)
8685
<< "Failed to dump PC table directly from binary using linked-in "
8786
"runner; see target execution logs above; falling back to legacy PC "
8887
"table extraction using trace-pc and objdump";
8988
pc_table = GetPcTableFromBinaryWithTracePC(
9089
binary_path_with_args, objdump_path, pc_table_path.path());
9190
if (pc_table.empty()) {
92-
LOG(ERROR) << "Failed to extract PC table from binary using objdump; see "
93-
"objdump execution logs above";
91+
FUZZTEST_LOG(ERROR)
92+
<< "Failed to extract PC table from binary using objdump; see "
93+
"objdump execution logs above";
9494
}
9595
// For the legacy trace-pc instrumentation, set the dso_table
9696
// to 1-element array consisting of the binary name
9797
const std::vector<std::string> args =
9898
absl::StrSplit(binary_path_with_args, absl::ByAnyChar{" \t\n"},
9999
absl::SkipWhitespace{});
100-
CHECK(!args.empty());
100+
FUZZTEST_CHECK(!args.empty());
101101
dso_table.push_back({args[0], pc_table.size()});
102102
uses_legacy_trace_pc_instrumentation = true;
103103
} else {
@@ -110,7 +110,7 @@ void BinaryInfo::InitializeFromSanCovBinary(
110110
for (const auto& dso : dso_table) {
111111
num_instrumened_pcs_in_all_dsos += dso.num_instrumented_pcs;
112112
}
113-
CHECK_EQ(num_instrumened_pcs_in_all_dsos, pc_table.size());
113+
FUZZTEST_CHECK_EQ(num_instrumened_pcs_in_all_dsos, pc_table.size());
114114
}
115115

116116
// Load symbols, if there is a PC table.
@@ -125,14 +125,14 @@ void BinaryInfo::InitializeFromSanCovBinary(
125125
void BinaryInfo::Read(std::string_view dir) {
126126
std::string symbol_table_contents;
127127
// TODO(b/295978603): move calculation of paths into WorkDir class.
128-
CHECK_OK(RemoteFileGetContents(
128+
FUZZTEST_CHECK_OK(RemoteFileGetContents(
129129
(std::filesystem::path(dir) / kSymbolTableFileName).c_str(),
130130
symbol_table_contents));
131131
std::istringstream symbol_table_stream(symbol_table_contents);
132132
symbols.ReadFromLLVMSymbolizer(symbol_table_stream);
133133

134134
std::string pc_table_contents;
135-
CHECK_OK(RemoteFileGetContents(
135+
FUZZTEST_CHECK_OK(RemoteFileGetContents(
136136
(std::filesystem::path(dir) / kPCTableFileName).c_str(),
137137
pc_table_contents));
138138
std::istringstream pc_table_stream(pc_table_contents);
@@ -146,19 +146,19 @@ void BinaryInfo::Write(std::string_view dir) {
146146
std::ostringstream symbol_table_stream;
147147
symbols.WriteToLLVMSymbolizer(symbol_table_stream);
148148
// TODO(b/295978603): move calculation of paths into WorkDir class.
149-
CHECK_OK(RemoteFileSetContents(
149+
FUZZTEST_CHECK_OK(RemoteFileSetContents(
150150
(std::filesystem::path(dir) / kSymbolTableFileName).c_str(),
151151
symbol_table_stream.str()));
152152

153153
std::ostringstream pc_table_stream;
154154
WritePcTable(pc_table, pc_table_stream);
155-
CHECK_OK(RemoteFileSetContents(
155+
FUZZTEST_CHECK_OK(RemoteFileSetContents(
156156
(std::filesystem::path(dir) / kPCTableFileName).c_str(),
157157
pc_table_stream.str()));
158158

159159
std::ostringstream cf_table_stream;
160160
WriteCfTable(cf_table, cf_table_stream);
161-
CHECK_OK(RemoteFileSetContents(
161+
FUZZTEST_CHECK_OK(RemoteFileSetContents(
162162
(std::filesystem::path(dir) / kCfTableFileName).c_str(),
163163
cf_table_stream.str()));
164164
}

centipede/blob_file_converter.cc

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include "absl/base/nullability.h"
2121
#include "absl/flags/flag.h"
22-
#include "absl/log/check.h"
23-
#include "absl/log/log.h"
2422
#include "absl/status/status.h"
2523
#include "absl/strings/str_format.h"
2624
#include "absl/time/clock.h"
@@ -59,11 +57,11 @@ class StatsLogger {
5957
const std::string stats = absl::StrFormat(
6058
"blobs: %9lld | blobs/s: %5.0f | bytes: %12lld | bytes/s: %8.0f",
6159
num_blobs_, num_blobs_ / secs, num_bytes_, num_bytes_ / secs);
62-
if (ABSL_VLOG_IS_ON(3)) {
60+
if (FUZZTEST_VLOG_IS_ON(3)) {
6361
const RUsageProfiler::Snapshot& snapshot = RPROF_SNAPSHOT(stats);
64-
LOG(INFO) << stats << " | " << snapshot.memory.ShortStr();
62+
FUZZTEST_LOG(INFO) << stats << " | " << snapshot.memory.ShortStr();
6563
} else {
66-
LOG(INFO) << stats;
64+
FUZZTEST_LOG(INFO) << stats;
6765
}
6866
}
6967

@@ -90,45 +88,49 @@ class StatsLogger {
9088
void Convert( //
9189
const std::string& in, //
9290
const std::string& out, const std::string& out_format) {
93-
RPROF_THIS_FUNCTION_WITH_REPORT(/*enable=*/ABSL_VLOG_IS_ON(1));
91+
RPROF_THIS_FUNCTION_WITH_REPORT(/*enable=*/FUZZTEST_VLOG_IS_ON(1));
9492

95-
LOG(INFO) << "Converting:\n" << VV(in) << "\n" << VV(out) << VV(out_format);
93+
FUZZTEST_LOG(INFO) << "Converting:\n"
94+
<< VV(in) << "\n"
95+
<< VV(out) << VV(out_format);
9696

9797
const bool out_is_riegeli = out_format == "riegeli";
9898

9999
// Verify and prepare source and destination.
100100

101-
CHECK(RemotePathExists(in)) << VV(in);
102-
CHECK_OK(RemoteMkdir(std::filesystem::path{out}.parent_path().c_str()));
101+
FUZZTEST_CHECK(RemotePathExists(in)) << VV(in);
102+
FUZZTEST_CHECK_OK(
103+
RemoteMkdir(std::filesystem::path{out}.parent_path().c_str()));
103104

104105
// Open blob file reader and writer.
105106

106107
RPROF_START_TIMELAPSE( //
107-
absl::Seconds(20), /*also_log=*/ABSL_VLOG_IS_ON(3), "Opening --in");
108+
absl::Seconds(20), /*also_log=*/FUZZTEST_VLOG_IS_ON(3), "Opening --in");
108109
const auto in_reader = DefaultBlobFileReaderFactory();
109-
CHECK_OK(in_reader->Open(in)) << VV(in);
110+
FUZZTEST_CHECK_OK(in_reader->Open(in)) << VV(in);
110111
RPROF_STOP_TIMELAPSE();
111-
RPROF_SNAPSHOT_AND_LOG("Opened --in; opening --out");
112+
RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Opened --in; opening --out");
112113
const auto out_writer = DefaultBlobFileWriterFactory(out_is_riegeli);
113-
CHECK_OK(out_writer->Open(out, "w")) << VV(out);
114-
RPROF_SNAPSHOT_AND_LOG("Opened --out");
114+
FUZZTEST_CHECK_OK(out_writer->Open(out, "w")) << VV(out);
115+
RPROF_SNAPSHOT_AND_FUZZTEST_LOG("Opened --out");
115116

116117
// Read and write blobs one-by-one.
117118

118119
ByteSpan blob;
119120
absl::Status read_status = absl::OkStatus();
120121
StatsLogger stats_logger{
121-
absl::Seconds(ABSL_VLOG_IS_ON(1) ? 20 : 60),
122+
absl::Seconds(FUZZTEST_VLOG_IS_ON(1) ? 20 : 60),
122123
FUNCTION_LEVEL_RPROF_NAME,
123124
};
124125
while ((read_status = in_reader->Read(blob)).ok()) {
125-
CHECK_OK(out_writer->Write(blob));
126+
FUZZTEST_CHECK_OK(out_writer->Write(blob));
126127
stats_logger.UpdateStats(blob);
127128
stats_logger.MaybeLogIfTime();
128129
}
129130
stats_logger.Log();
130-
CHECK(read_status.ok() || absl::IsOutOfRange(read_status)) << VV(read_status);
131-
CHECK_OK(out_writer->Close()) << VV(out);
131+
FUZZTEST_CHECK(read_status.ok() || absl::IsOutOfRange(read_status))
132+
<< VV(read_status);
133+
FUZZTEST_CHECK_OK(out_writer->Close()) << VV(out);
132134
}
133135

134136
} // namespace
@@ -138,11 +140,12 @@ int main(int argc, char** absl_nonnull argv) {
138140
(void)fuzztest::internal::InitRuntime(argc, argv);
139141

140142
const std::string in = absl::GetFlag(FLAGS_in);
141-
QCHECK(!in.empty());
143+
FUZZTEST_QCHECK(!in.empty());
142144
const std::string out = absl::GetFlag(FLAGS_out);
143-
QCHECK(!out.empty());
145+
FUZZTEST_QCHECK(!out.empty());
144146
const std::string out_format = absl::GetFlag(FLAGS_out_format);
145-
QCHECK(out_format == "legacy" || out_format == "riegeli") << VV(out_format);
147+
FUZZTEST_QCHECK(out_format == "legacy" || out_format == "riegeli")
148+
<< VV(out_format);
146149

147150
fuzztest::internal::Convert(in, out, out_format);
148151

0 commit comments

Comments
 (0)