MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / TestLogFromLocation

Function TestLogFromLocation

src/test/logging_tests.cpp:402–429  ·  view source on GitHub ↗

* For a given `location` and `message`, ensure that the on-disk debug log behaviour resembles what * we'd expect it to be for `status` and `suppressions_active`. */

Source from the content-addressed store, hash-verified

400 * we'd expect it to be for `status` and `suppressions_active`.
401 */
402void TestLogFromLocation(Location location, const std::string& message,
403 BCLog::LogRateLimiter::Status status, bool suppressions_active,
404 std::source_location source = std::source_location::current())
405{
406 BOOST_TEST_INFO_SCOPE("TestLogFromLocation called from " << source.file_name() << ":" << source.line());
407 using Status = BCLog::LogRateLimiter::Status;
408 if (!suppressions_active) assert(status == Status::UNSUPPRESSED); // developer error
409
410 std::ofstream ofs(LogInstance().m_file_path.std_path(), std::ios::out | std::ios::trunc); // clear debug log
411 LogFromLocation(location, message);
412 auto log_lines{ReadDebugLogLines()};
413 BOOST_TEST_INFO_SCOPE(log_lines.size() << " log_lines read: \n" << util::Join(log_lines, "\n"));
414
415 if (status == Status::STILL_SUPPRESSED) {
416 BOOST_CHECK_EQUAL(log_lines.size(), 0);
417 return;
418 }
419
420 if (status == Status::NEWLY_SUPPRESSED) {
421 BOOST_REQUIRE_EQUAL(log_lines.size(), 2);
422 BOOST_CHECK(log_lines[0].starts_with("[*] [warning] Excessive logging detected"));
423 log_lines.erase(log_lines.begin());
424 }
425 BOOST_REQUIRE_EQUAL(log_lines.size(), 1);
426 auto& payload{log_lines.back()};
427 BOOST_CHECK_EQUAL(suppressions_active, payload.starts_with("[*]"));
428 BOOST_CHECK(payload.ends_with(message));
429}
430
431} // namespace
432

Callers 1

BOOST_FIXTURE_TEST_CASEFunction · 0.85

Calls 9

LogFromLocationFunction · 0.85
ReadDebugLogLinesFunction · 0.85
JoinFunction · 0.85
file_nameMethod · 0.80
lineMethod · 0.80
sizeMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected