Skip to content

Commit 5938263

Browse files
Abseil Teamcopybara-github
authored andcommitted
Test that CHECK respects ABSL_MIN_LOG_LEVEL
Ensure that the CHECK expression and message are stripped when FATAL is below ABSL_MIN_LOG_LEVEL. PiperOrigin-RevId: 548157637 Change-Id: I4308ff7ff75aabebdd2dcefa2771cd7e77112817
1 parent c16a2f4 commit 5938263

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

absl/log/stripping_test.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,30 @@ TEST_F(StrippingTest, Level) {
345345
}
346346
}
347347

348+
TEST_F(StrippingTest, Check) {
349+
// Here we also need a variable name with enough entropy that it's unlikely to
350+
// appear in the binary by chance. `volatile` keeps the tautological
351+
// comparison (and the rest of the `CHECK`) from being optimized away.
352+
const std::string var_needle = absl::Base64Escape("StrippingTestCheckVar");
353+
const std::string msg_needle = absl::Base64Escape("StrippingTest.Check");
354+
volatile int U3RyaXBwaW5nVGVzdENoZWNrVmFy = 0xCAFE;
355+
// We don't care if the CHECK is actually executed, just that stripping works.
356+
// Hiding it behind `kReallyDie` works around some overly aggressive
357+
// optimizations in older versions of MSVC.
358+
if (kReallyDie) {
359+
CHECK(U3RyaXBwaW5nVGVzdENoZWNrVmFy != U3RyaXBwaW5nVGVzdENoZWNrVmFy)
360+
<< "U3RyaXBwaW5nVGVzdC5DaGVjaw==";
361+
}
362+
363+
std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable();
364+
ASSERT_THAT(exe, NotNull());
365+
if (absl::LogSeverity::kFatal >= kAbslMinLogLevel) {
366+
EXPECT_THAT(exe.get(), FileHasSubstr(var_needle));
367+
EXPECT_THAT(exe.get(), FileHasSubstr(msg_needle));
368+
} else {
369+
EXPECT_THAT(exe.get(), Not(FileHasSubstr(var_needle)));
370+
EXPECT_THAT(exe.get(), Not(FileHasSubstr(msg_needle)));
371+
}
372+
}
373+
348374
} // namespace

0 commit comments

Comments
 (0)