diff options
author | Derek Mauro <dmauro@google.com> | 2023-08-04 13:54:47 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-08-04 13:55:54 -0700 |
commit | 70172ada858b8739ce07e8c2f1ecd8c11c8768c7 (patch) | |
tree | e59640940355eb71082261dd9f5c87ae1aa31e78 /absl/log/stripping_test.cc | |
parent | 659b77b713fe5f1f75e6e1bb121c0eed1c8f964a (diff) | |
download | abseil-70172ada858b8739ce07e8c2f1ecd8c11c8768c7.tar.gz abseil-70172ada858b8739ce07e8c2f1ecd8c11c8768c7.tar.bz2 abseil-70172ada858b8739ce07e8c2f1ecd8c11c8768c7.zip |
Release the `DFATAL` pseudo-LogSeverity level
`DFATAL` is defined as `FATAL` in debug mode, and as `ERROR`
when `NDEBUG` is defined.
Closes #1279
PiperOrigin-RevId: 553904244
Change-Id: Iaa207ee65b2a39b4b7f5da241208c3d39cd5da0e
Diffstat (limited to 'absl/log/stripping_test.cc')
-rw-r--r-- | absl/log/stripping_test.cc | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/absl/log/stripping_test.cc b/absl/log/stripping_test.cc index aff91495..35357039 100644 --- a/absl/log/stripping_test.cc +++ b/absl/log/stripping_test.cc @@ -322,6 +322,49 @@ TEST_F(StrippingTest, Fatal) { } } +TEST_F(StrippingTest, DFatal) { + // We need to load a copy of the needle string into memory (so we can search + // for it) without leaving it lying around in plaintext in the executable file + // as would happen if we used a literal. We might (or might not) leave it + // lying around later; that's what the tests are for! + const std::string needle = absl::Base64Escape("StrippingTest.DFatal"); + // We don't care if the LOG statement is actually executed, we're just + // checking that it's stripped. + if (kReallyDie) LOG(DFATAL) << "U3RyaXBwaW5nVGVzdC5ERmF0YWw="; + + std::unique_ptr<FILE, std::function<void(FILE*)>> exe = OpenTestExecutable(); + ASSERT_THAT(exe, NotNull()); + // `DFATAL` can be `ERROR` or `FATAL`, and a compile-time optimizer doesn't + // know which, because `absl::kLogDebugFatal` is declared `extern` and defined + // in another TU. Link-time optimization might do better. We have six cases: + // | `AMLL` is-> | `<=ERROR` | `FATAL` | `>FATAL` | + // | ------------------- | --------- | ------- | -------- | + // | `DFATAL` is `ERROR` | present | ? | stripped | + // | `DFATAL` is `FATAL` | present | present | stripped | + + // These constexpr variables are used to suppress unreachable code warnings + // in the if-else statements below. + + // "present" in the table above: `DFATAL` exceeds `ABSL_MIN_LOG_LEVEL`, so + // `DFATAL` statements should not be stripped (and they should be logged + // when executed, but that's a different testsuite). + constexpr bool kExpectPresent = absl::kLogDebugFatal >= kAbslMinLogLevel; + + // "stripped" in the table above: even though the compiler may not know + // which value `DFATAL` has, it should be able to strip it since both + // possible values ought to be stripped. + constexpr bool kExpectStripped = kAbslMinLogLevel > absl::LogSeverity::kFatal; + + if (kExpectPresent) { + EXPECT_THAT(exe.get(), FileHasSubstr(needle)); + } else if (kExpectStripped) { + EXPECT_THAT(exe.get(), Not(FileHasSubstr(needle))); + } else { + // "?" in the table above; may or may not be stripped depending on whether + // any link-time optimization is done. Either outcome is ok. + } +} + TEST_F(StrippingTest, Level) { const std::string needle = absl::Base64Escape("StrippingTest.Level"); volatile auto severity = absl::LogSeverity::kWarning; |