Bitcoin Core 30.99.0
P2P Digital Currency
logging_tests.cpp
Go to the documentation of this file.
1// Copyright (c) 2019-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <init/common.h>
6#include <logging.h>
7#include <logging/timer.h>
8#include <scheduler.h>
9#include <test/util/logging.h>
11#include <tinyformat.h>
12#include <util/fs.h>
13#include <util/fs_helpers.h>
14#include <util/string.h>
15
16#include <chrono>
17#include <fstream>
18#include <future>
19#include <ios>
20#include <iostream>
21#include <source_location>
22#include <string>
23#include <unordered_map>
24#include <utility>
25#include <vector>
26
27#include <boost/test/unit_test.hpp>
28
31
33
34static void ResetLogger()
35{
38}
39
40static std::vector<std::string> ReadDebugLogLines()
41{
42 std::vector<std::string> lines;
43 std::ifstream ifs{LogInstance().m_file_path.std_path()};
44 for (std::string line; std::getline(ifs, line);) {
45 lines.push_back(std::move(line));
46 }
47 return lines;
48}
49
50struct LogSetup : public BasicTestingSetup {
51 fs::path prev_log_path;
52 fs::path tmp_log_path;
58 std::unordered_map<BCLog::LogFlags, BCLog::Level> prev_category_levels;
61
63 tmp_log_path{m_args.GetDataDirBase() / "tmp_debug.log"},
64 prev_reopen_file{LogInstance().m_reopen_file},
65 prev_print_to_file{LogInstance().m_print_to_file},
66 prev_log_timestamps{LogInstance().m_log_timestamps},
67 prev_log_threadnames{LogInstance().m_log_threadnames},
68 prev_log_sourcelocations{LogInstance().m_log_sourcelocations},
69 prev_category_levels{LogInstance().CategoryLevels()},
71 prev_category_mask{LogInstance().GetCategoryMask()}
72 {
78
79 // Prevent tests from failing when the line number of the logs changes.
81
86 }
87
89 {
91 LogInfo("Sentinel log to reopen log file");
102 }
103};
104
106{
107 auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg");
108 const std::string_view result_prefix{"tests: msg ("};
109 BOOST_CHECK_EQUAL(micro_timer.LogMsg("msg").substr(0, result_prefix.size()), result_prefix);
110}
111
113{
115
116 struct Case {
117 std::string msg;
118 BCLog::LogFlags category;
119 BCLog::Level level;
120 std::string prefix;
121 std::source_location loc;
122 };
123
124 std::vector<Case> cases = {
125 {"foo1: bar1", BCLog::NET, BCLog::Level::Debug, "[net] ", std::source_location::current()},
126 {"foo2: bar2", BCLog::NET, BCLog::Level::Info, "[net:info] ", std::source_location::current()},
127 {"foo3: bar3", BCLog::ALL, BCLog::Level::Debug, "[debug] ", std::source_location::current()},
128 {"foo4: bar4", BCLog::ALL, BCLog::Level::Info, "", std::source_location::current()},
129 {"foo5: bar5", BCLog::NONE, BCLog::Level::Debug, "[debug] ", std::source_location::current()},
130 {"foo6: bar6", BCLog::NONE, BCLog::Level::Info, "", std::source_location::current()},
131 };
132
133 std::vector<std::string> expected;
134 for (auto& [msg, category, level, prefix, loc] : cases) {
135 expected.push_back(tfm::format("[%s:%s] [%s] %s%s", util::RemovePrefix(loc.file_name(), "./"), loc.line(), loc.function_name(), prefix, msg));
136 LogInstance().LogPrintStr(msg, std::move(loc), category, level, /*should_ratelimit=*/false);
137 }
138 std::vector<std::string> log_lines{ReadDebugLogLines()};
139 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
140}
141
142BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacrosDeprecated, LogSetup)
143{
145 LogPrintLevel(BCLog::NET, BCLog::Level::Trace, "foo4: %s\n", "bar4"); // not logged
146 LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "foo7: %s\n", "bar7");
147 LogPrintLevel(BCLog::NET, BCLog::Level::Info, "foo8: %s\n", "bar8");
148 LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "foo9: %s\n", "bar9");
149 LogPrintLevel(BCLog::NET, BCLog::Level::Error, "foo10: %s\n", "bar10");
150 std::vector<std::string> log_lines{ReadDebugLogLines()};
151 std::vector<std::string> expected{
152 "[net] foo7: bar7",
153 "[net:info] foo8: bar8",
154 "[net:warning] foo9: bar9",
155 "[net:error] foo10: bar10",
156 };
157 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
158}
159
160BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros, LogSetup)
161{
163 LogTrace(BCLog::NET, "foo6: %s", "bar6"); // not logged
164 LogDebug(BCLog::NET, "foo7: %s", "bar7");
165 LogInfo("foo8: %s", "bar8");
166 LogWarning("foo9: %s", "bar9");
167 LogError("foo10: %s", "bar10");
168 std::vector<std::string> log_lines{ReadDebugLogLines()};
169 std::vector<std::string> expected = {
170 "[net] foo7: bar7",
171 "foo8: bar8",
172 "[warning] foo9: bar9",
173 "[error] foo10: bar10",
174 };
175 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
176}
177
178BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacros_CategoryName, LogSetup)
179{
181 const auto concatenated_category_names = LogInstance().LogCategoriesString();
182 std::vector<std::pair<BCLog::LogFlags, std::string>> expected_category_names;
183 const auto category_names = SplitString(concatenated_category_names, ',');
184 for (const auto& category_name : category_names) {
185 BCLog::LogFlags category;
186 const auto trimmed_category_name = TrimString(category_name);
187 BOOST_REQUIRE(GetLogCategory(category, trimmed_category_name));
188 expected_category_names.emplace_back(category, trimmed_category_name);
189 }
190
191 std::vector<std::string> expected;
192 for (const auto& [category, name] : expected_category_names) {
193 LogDebug(category, "foo: %s\n", "bar");
194 std::string expected_log = "[";
195 expected_log += name;
196 expected_log += "] foo: bar";
197 expected.push_back(expected_log);
198 }
199
200 std::vector<std::string> log_lines{ReadDebugLogLines()};
201 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
202}
203
204BOOST_FIXTURE_TEST_CASE(logging_SeverityLevels, LogSetup)
205{
207 LogInstance().SetCategoryLogLevel(/*category_str=*/"net", /*level_str=*/"info");
208
209 // Global log level
210 LogPrintLevel(BCLog::HTTP, BCLog::Level::Info, "foo1: %s\n", "bar1");
211 LogPrintLevel(BCLog::MEMPOOL, BCLog::Level::Trace, "foo2: %s. This log level is lower than the global one.\n", "bar2");
213 LogPrintLevel(BCLog::RPC, BCLog::Level::Error, "foo4: %s\n", "bar4");
214
215 // Category-specific log level
216 LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "foo5: %s\n", "bar5");
217 LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "foo6: %s. This log level is the same as the global one but lower than the category-specific one, which takes precedence. \n", "bar6");
218 LogPrintLevel(BCLog::NET, BCLog::Level::Error, "foo7: %s\n", "bar7");
219
220 std::vector<std::string> expected = {
221 "[http:info] foo1: bar1",
222 "[validation:warning] foo3: bar3",
223 "[rpc:error] foo4: bar4",
224 "[net:warning] foo5: bar5",
225 "[net:error] foo7: bar7",
226 };
227 std::vector<std::string> log_lines{ReadDebugLogLines()};
228 BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end());
229}
230
232{
233 // Set global log level
234 {
235 ResetLogger();
238 const char* argv_test[] = {"bitcoind", "-loglevel=debug"};
239 std::string err;
240 BOOST_REQUIRE(args.ParseParameters(2, argv_test, err));
241
242 auto result = init::SetLoggingLevel(args);
243 BOOST_REQUIRE(result);
245 }
246
247 // Set category-specific log level
248 {
249 ResetLogger();
252 const char* argv_test[] = {"bitcoind", "-loglevel=net:trace"};
253 std::string err;
254 BOOST_REQUIRE(args.ParseParameters(2, argv_test, err));
255
256 auto result = init::SetLoggingLevel(args);
257 BOOST_REQUIRE(result);
259
260 const auto& category_levels{LogInstance().CategoryLevels()};
261 const auto net_it{category_levels.find(BCLog::LogFlags::NET)};
262 BOOST_REQUIRE(net_it != category_levels.end());
263 BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Trace);
264 }
265
266 // Set both global log level and category-specific log level
267 {
268 ResetLogger();
271 const char* argv_test[] = {"bitcoind", "-loglevel=debug", "-loglevel=net:trace", "-loglevel=http:info"};
272 std::string err;
273 BOOST_REQUIRE(args.ParseParameters(4, argv_test, err));
274
275 auto result = init::SetLoggingLevel(args);
276 BOOST_REQUIRE(result);
278
279 const auto& category_levels{LogInstance().CategoryLevels()};
280 BOOST_CHECK_EQUAL(category_levels.size(), 2);
281
282 const auto net_it{category_levels.find(BCLog::LogFlags::NET)};
283 BOOST_CHECK(net_it != category_levels.end());
284 BOOST_CHECK_EQUAL(net_it->second, BCLog::Level::Trace);
285
286 const auto http_it{category_levels.find(BCLog::LogFlags::HTTP)};
287 BOOST_CHECK(http_it != category_levels.end());
288 BOOST_CHECK_EQUAL(http_it->second, BCLog::Level::Info);
289 }
290}
291
294
296 {
297 scheduler.m_service_thread = std::thread([this] { scheduler.serviceQueue(); });
298 }
300 {
301 scheduler.stop();
302 }
303 void MockForwardAndSync(std::chrono::seconds duration)
304 {
305 scheduler.MockForward(duration);
306 std::promise<void> promise;
307 scheduler.scheduleFromNow([&promise] { promise.set_value(); }, 0ms);
308 promise.get_future().wait();
309 }
310 std::shared_ptr<BCLog::LogRateLimiter> GetLimiter(size_t max_bytes, std::chrono::seconds window)
311 {
312 auto sched_func = [this](auto func, auto w) {
313 scheduler.scheduleEvery(std::move(func), w);
314 };
315 return BCLog::LogRateLimiter::Create(sched_func, max_bytes, window);
316 }
317};
318
319BOOST_AUTO_TEST_CASE(logging_log_rate_limiter)
320{
321 uint64_t max_bytes{1024};
322 auto reset_window{1min};
323 ScopedScheduler scheduler{};
324 auto limiter_{scheduler.GetLimiter(max_bytes, reset_window)};
325 auto& limiter{*Assert(limiter_)};
326
327 using Status = BCLog::LogRateLimiter::Status;
328 auto source_loc_1{std::source_location::current()};
329 auto source_loc_2{std::source_location::current()};
330
331 // A fresh limiter should not have any suppressions
332 BOOST_CHECK(!limiter.SuppressionsActive());
333
334 // Resetting an unused limiter is fine
335 limiter.Reset();
336 BOOST_CHECK(!limiter.SuppressionsActive());
337
338 // No suppression should happen until more than max_bytes have been consumed
339 BOOST_CHECK_EQUAL(limiter.Consume(source_loc_1, std::string(max_bytes - 1, 'a')), Status::UNSUPPRESSED);
340 BOOST_CHECK_EQUAL(limiter.Consume(source_loc_1, "a"), Status::UNSUPPRESSED);
341 BOOST_CHECK(!limiter.SuppressionsActive());
342 BOOST_CHECK_EQUAL(limiter.Consume(source_loc_1, "a"), Status::NEWLY_SUPPRESSED);
343 BOOST_CHECK(limiter.SuppressionsActive());
344 BOOST_CHECK_EQUAL(limiter.Consume(source_loc_1, "a"), Status::STILL_SUPPRESSED);
345 BOOST_CHECK(limiter.SuppressionsActive());
346
347 // Location 2 should not be affected by location 1's suppression
348 BOOST_CHECK_EQUAL(limiter.Consume(source_loc_2, std::string(max_bytes, 'a')), Status::UNSUPPRESSED);
349 BOOST_CHECK_EQUAL(limiter.Consume(source_loc_2, "a"), Status::NEWLY_SUPPRESSED);
350 BOOST_CHECK(limiter.SuppressionsActive());
351
352 // After reset_window time has passed, all suppressions should be cleared.
353 scheduler.MockForwardAndSync(reset_window);
354
355 BOOST_CHECK(!limiter.SuppressionsActive());
356 BOOST_CHECK_EQUAL(limiter.Consume(source_loc_1, std::string(max_bytes, 'a')), Status::UNSUPPRESSED);
357 BOOST_CHECK_EQUAL(limiter.Consume(source_loc_2, std::string(max_bytes, 'a')), Status::UNSUPPRESSED);
358}
359
360BOOST_AUTO_TEST_CASE(logging_log_limit_stats)
361{
363
364 // Check that stats gets initialized correctly.
366 BOOST_CHECK_EQUAL(stats.m_dropped_bytes, uint64_t{0});
367
368 const uint64_t MESSAGE_SIZE{BCLog::RATELIMIT_MAX_BYTES / 2};
369 BOOST_CHECK(stats.Consume(MESSAGE_SIZE));
371 BOOST_CHECK_EQUAL(stats.m_dropped_bytes, uint64_t{0});
372
373 BOOST_CHECK(stats.Consume(MESSAGE_SIZE));
375 BOOST_CHECK_EQUAL(stats.m_dropped_bytes, uint64_t{0});
376
377 // Consuming more bytes after already having consumed RATELIMIT_MAX_BYTES should fail.
378 BOOST_CHECK(!stats.Consume(500));
379 BOOST_CHECK_EQUAL(stats.m_available_bytes, uint64_t{0});
380 BOOST_CHECK_EQUAL(stats.m_dropped_bytes, uint64_t{500});
381}
382
383namespace {
384
385enum class Location {
386 INFO_1,
387 INFO_2,
388 DEBUG_LOG,
389 INFO_NOLIMIT,
390};
391
392void LogFromLocation(Location location, const std::string& message) {
393 switch (location) {
394 case Location::INFO_1:
395 LogInfo("%s\n", message);
396 return;
397 case Location::INFO_2:
398 LogInfo("%s\n", message);
399 return;
400 case Location::DEBUG_LOG:
401 LogDebug(BCLog::LogFlags::HTTP, "%s\n", message);
402 return;
403 case Location::INFO_NOLIMIT:
404 LogPrintLevel_(BCLog::LogFlags::ALL, BCLog::Level::Info, /*should_ratelimit=*/false, "%s\n", message);
405 return;
406 } // no default case, so the compiler can warn about missing cases
407 assert(false);
408}
409
414void TestLogFromLocation(Location location, const std::string& message,
415 BCLog::LogRateLimiter::Status status, bool suppressions_active,
416 std::source_location source = std::source_location::current())
417{
418 BOOST_TEST_INFO_SCOPE("TestLogFromLocation called from " << source.file_name() << ":" << source.line());
419 using Status = BCLog::LogRateLimiter::Status;
420 if (!suppressions_active) assert(status == Status::UNSUPPRESSED); // developer error
421
422 std::ofstream ofs(LogInstance().m_file_path.std_path(), std::ios::out | std::ios::trunc); // clear debug log
423 LogFromLocation(location, message);
424 auto log_lines{ReadDebugLogLines()};
425 BOOST_TEST_INFO_SCOPE(log_lines.size() << " log_lines read: \n" << util::Join(log_lines, "\n"));
426
427 if (status == Status::STILL_SUPPRESSED) {
428 BOOST_CHECK_EQUAL(log_lines.size(), 0);
429 return;
430 }
431
432 if (status == Status::NEWLY_SUPPRESSED) {
433 BOOST_REQUIRE_EQUAL(log_lines.size(), 2);
434 BOOST_CHECK(log_lines[0].starts_with("[*] [warning] Excessive logging detected"));
435 log_lines.erase(log_lines.begin());
436 }
437 BOOST_REQUIRE_EQUAL(log_lines.size(), 1);
438 auto& payload{log_lines.back()};
439 BOOST_CHECK_EQUAL(suppressions_active, payload.starts_with("[*]"));
440 BOOST_CHECK(payload.ends_with(message));
441}
442
443} // namespace
444
445BOOST_FIXTURE_TEST_CASE(logging_filesize_rate_limit, LogSetup)
446{
447 using Status = BCLog::LogRateLimiter::Status;
452
453 constexpr int64_t line_length{1024};
454 constexpr int64_t num_lines{10};
455 constexpr int64_t bytes_quota{line_length * num_lines};
456 constexpr auto time_window{1h};
457
458 ScopedScheduler scheduler{};
459 auto limiter{scheduler.GetLimiter(bytes_quota, time_window)};
460 LogInstance().SetRateLimiting(limiter);
461
462 const std::string log_message(line_length - 1, 'a'); // subtract one for newline
463
464 for (int i = 0; i < num_lines; ++i) {
465 TestLogFromLocation(Location::INFO_1, log_message, Status::UNSUPPRESSED, /*suppressions_active=*/false);
466 }
467 TestLogFromLocation(Location::INFO_1, "a", Status::NEWLY_SUPPRESSED, /*suppressions_active=*/true);
468 TestLogFromLocation(Location::INFO_1, "b", Status::STILL_SUPPRESSED, /*suppressions_active=*/true);
469 TestLogFromLocation(Location::INFO_2, "c", Status::UNSUPPRESSED, /*suppressions_active=*/true);
470 {
471 scheduler.MockForwardAndSync(time_window);
472 BOOST_CHECK(ReadDebugLogLines().back().starts_with("[warning] Restarting logging"));
473 }
474 // Check that logging from previously suppressed location is unsuppressed again.
475 TestLogFromLocation(Location::INFO_1, log_message, Status::UNSUPPRESSED, /*suppressions_active=*/false);
476 // Check that conditional logging, and unconditional logging with should_ratelimit=false is
477 // not being ratelimited.
478 for (Location location : {Location::DEBUG_LOG, Location::INFO_NOLIMIT}) {
479 for (int i = 0; i < num_lines + 2; ++i) {
480 TestLogFromLocation(location, log_message, Status::UNSUPPRESSED, /*suppressions_active=*/false);
481 }
482 }
483}
484
ArgsManager & args
Definition: bitcoind.cpp:277
#define Assert(val)
Identity function.
Definition: check.h:113
@ ALLOW_ANY
disable validation
Definition: args.h:106
bool ParseParameters(int argc, const char *const argv[], std::string &error)
Definition: args.cpp:177
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: args.cpp:568
static std::shared_ptr< LogRateLimiter > Create(SchedulerFunction &&scheduler_func, uint64_t max_bytes, std::chrono::seconds reset_window)
Definition: logging.cpp:378
Status
Suppression status of a source log location.
Definition: logging.h:157
void LogPrintStr(std::string_view str, std::source_location &&source_loc, BCLog::LogFlags category, BCLog::Level level, bool should_ratelimit) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Send a string to the log output.
Definition: logging.cpp:423
bool m_log_sourcelocations
Definition: logging.h:228
void SetCategoryLogLevel(const std::unordered_map< LogFlags, Level > &levels) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.h:292
void SetLogLevel(Level level)
Definition: logging.h:305
fs::path m_file_path
Definition: logging.h:231
bool m_log_threadnames
Definition: logging.h:227
void SetRateLimiting(std::shared_ptr< LogRateLimiter > limiter) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.h:271
void EnableCategory(LogFlags flag)
Definition: logging.cpp:123
bool m_log_timestamps
Definition: logging.h:225
std::atomic< bool > m_reopen_file
Definition: logging.h:232
bool m_print_to_file
Definition: logging.h:223
std::unordered_map< LogFlags, Level > CategoryLevels() const EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
Definition: logging.h:287
std::string LogCategoriesString() const
Returns a string with the log categories in alphabetical order.
Definition: logging.h:321
void DisableCategory(LogFlags flag)
Definition: logging.cpp:136
RAII-style object that outputs timing information to logs.
Definition: timer.h:24
Simple class for background tasks that should be run periodically or once "after a while".
Definition: scheduler.h:40
void MockForward(std::chrono::seconds delta_seconds) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Mock the scheduler to fast forward in time.
Definition: scheduler.cpp:80
void serviceQueue() EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Services the queue 'forever'.
Definition: scheduler.cpp:23
void scheduleEvery(Function f, std::chrono::milliseconds delta) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Repeat f until the scheduler is stopped.
Definition: scheduler.cpp:108
std::thread m_service_thread
Definition: scheduler.h:45
void stop() EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Tell any threads running serviceQueue to stop as soon as the current task is done.
Definition: scheduler.h:79
void scheduleFromNow(Function f, std::chrono::milliseconds delta) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Call f once after the delta has passed.
Definition: scheduler.h:53
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
Common init functions shared by bitcoin-node, bitcoin-wallet, etc.
bool GetLogCategory(BCLog::LogFlags &flag, std::string_view str)
Return true if str parses as a log category and set the flag.
Definition: logging.cpp:219
BCLog::Logger & LogInstance()
Definition: logging.cpp:26
#define LogPrintLevel(category, level,...)
Definition: logging.h:381
#define LogPrintLevel_(category, level, should_ratelimit,...)
Definition: logging.h:362
#define LogWarning(...)
Definition: logging.h:369
#define LogInfo(...)
Definition: logging.h:368
#define LogError(...)
Definition: logging.h:370
#define LogTrace(category,...)
Definition: logging.h:391
#define LogDebug(category,...)
Definition: logging.h:390
static std::vector< std::string > ReadDebugLogLines()
BOOST_FIXTURE_TEST_CASE(logging_LogPrintStr, LogSetup)
BOOST_AUTO_TEST_CASE(logging_timer)
static void ResetLogger()
Level
Definition: logging.h:100
constexpr uint64_t RATELIMIT_MAX_BYTES
Definition: logging.h:109
uint64_t CategoryMask
Definition: logging.h:63
constexpr auto DEFAULT_LOG_LEVEL
Definition: logging.h:107
LogFlags
Definition: logging.h:64
@ ALL
Definition: logging.h:98
@ RPC
Definition: logging.h:73
@ HTTP
Definition: logging.h:69
@ NONE
Definition: logging.h:65
@ VALIDATION
Definition: logging.h:87
@ MEMPOOL
Definition: logging.h:68
@ NET
Definition: logging.h:66
util::Result< void > SetLoggingLevel(const ArgsManager &args)
Definition: common.cpp:60
void format(std::ostream &out, FormatStringCheck< sizeof...(Args)> fmt, const Args &... args)
Format list of arguments to the stream according to given format string.
Definition: tinyformat.h:1079
std::vector< std::string > SplitString(std::string_view str, char sep)
Definition: string.h:148
std::string TrimString(std::string_view str, std::string_view pattern=" \f\n\r\t\v")
Definition: string.h:168
std::string RemovePrefix(std::string_view str, std::string_view prefix)
Definition: string.h:189
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
Definition: string.h:204
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
const char * prefix
Definition: rest.cpp:1107
const char * name
Definition: rest.cpp:48
const char * source
Definition: rpcconsole.cpp:62
Keeps track of an individual source location and how many available bytes are left for logging from i...
Definition: logging.h:118
uint64_t m_available_bytes
Remaining bytes.
Definition: logging.h:120
bool Consume(uint64_t bytes)
Updates internal accounting and returns true if enough available_bytes were remaining.
Definition: logging.cpp:572
uint64_t m_dropped_bytes
Number of bytes that were consumed but didn't fit in the available bytes.
Definition: logging.h:122
Basic testing setup.
Definition: setup_common.h:64
ArgsManager m_args
Test-specific arguments and settings.
Definition: setup_common.h:99
fs::path tmp_log_path
bool prev_reopen_file
fs::path prev_log_path
std::unordered_map< BCLog::LogFlags, BCLog::Level > prev_category_levels
bool prev_print_to_file
BCLog::Level prev_log_level
bool prev_log_threadnames
bool prev_log_sourcelocations
bool prev_log_timestamps
BCLog::CategoryMask prev_category_mask
std::shared_ptr< BCLog::LogRateLimiter > GetLimiter(size_t max_bytes, std::chrono::seconds window)
CScheduler scheduler
void MockForwardAndSync(std::chrono::seconds duration)
assert(!tx.IsCoinBase())