From afe42bd422e1e0f7b6c6c8c91b32ff04ca2eea72 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 19 Sep 2018 13:26:43 -0400 Subject: [PATCH 1/7] Merge #14287: tests: Use MakeUnique to construct objects owned by unique_ptrs b6718e373e tests: Use MakeUnique to construct objects owned by unique_ptrs (practicalswift) Pull request description: A subset of #14211 ("Use MakeUnique to construct objects owned by unique_ptrs") as suggested by @MarcoFalke in https://github.com/bitcoin/bitcoin/pull/14211#issuecomment-423324019. Use `MakeUnique` to construct objects owned by `unique_ptr`s. Rationale: * `MakeUnique` ensures exception safety in complex expressions. * `MakeUnique` gives a more concise statement of the construction. Tree-SHA512: 1228ae6ce7beb178d79142c4e936b728178ccaa8aa35c6d8feeb33d1a667abfdd010c59996a9d833594611e913877ce5794e75953d11d9b1fdbac04aa491d9cf --- doc/developer-notes.md | 5 +++++ src/bench/bench_dash.cpp | 2 +- src/bench/coin_selection.cpp | 2 +- src/test/allocator_tests.cpp | 2 +- src/test/checkqueue_tests.cpp | 14 +++++++------- src/test/net_tests.cpp | 4 ++-- src/test/test_dash.cpp | 2 +- src/test/test_dash_fuzzy.cpp | 2 +- src/wallet/test/coinselector_tests.cpp | 2 +- 9 files changed, 20 insertions(+), 15 deletions(-) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index f1fcbd8378ed..0e69126e038b 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -460,6 +460,11 @@ General C++ - *Rationale*: This avoids memory and resource leaks, and ensures exception safety +- Use `MakeUnique()` to construct objects owned by `unique_ptr`s + + - *Rationale*: `MakeUnique` is concise and ensures exception safety in complex expressions. + `MakeUnique` is a temporary project local implementation of `std::make_unique` (C++14). + C++ data structures -------------------- diff --git a/src/bench/bench_dash.cpp b/src/bench/bench_dash.cpp index 749085d3fd9f..c549bfbafc20 100644 --- a/src/bench/bench_dash.cpp +++ b/src/bench/bench_dash.cpp @@ -95,7 +95,7 @@ int main(int argc, char** argv) return EXIT_FAILURE; } - std::unique_ptr printer(new benchmark::ConsolePrinter()); + std::unique_ptr printer = MakeUnique(); std::string printer_arg = gArgs.GetArg("-printer", DEFAULT_BENCH_PRINTER); if ("plot" == printer_arg) { printer.reset(new benchmark::PlotlyPrinter( diff --git a/src/bench/coin_selection.cpp b/src/bench/coin_selection.cpp index d68795bd0371..8730fadea33a 100644 --- a/src/bench/coin_selection.cpp +++ b/src/bench/coin_selection.cpp @@ -66,7 +66,7 @@ static void add_coin(const CAmount& nValue, int nInput, std::vector CMutableTransaction tx; tx.vout.resize(nInput + 1); tx.vout[nInput].nValue = nValue; - std::unique_ptr wtx(new CWalletTx(&testWallet, MakeTransactionRef(std::move(tx)))); + std::unique_ptr wtx = MakeUnique(&testWallet, MakeTransactionRef(std::move(tx))); set.emplace_back(COutput(wtx.get(), nInput, 0, true, true, true).GetInputCoin(), 0, true, 0, 0); wtxn.emplace_back(std::move(wtx)); } diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp index 01489cd88bb1..1e795843c9c7 100644 --- a/src/test/allocator_tests.cpp +++ b/src/test/allocator_tests.cpp @@ -163,7 +163,7 @@ class TestLockedPageAllocator: public LockedPageAllocator BOOST_AUTO_TEST_CASE(lockedpool_tests_mock) { // Test over three virtual arenas, of which one will succeed being locked - std::unique_ptr x(new TestLockedPageAllocator(3, 1)); + std::unique_ptr x = MakeUnique(3, 1); LockedPool pool(std::move(x)); BOOST_CHECK(pool.stats().total == 0); BOOST_CHECK(pool.stats().locked == 0); diff --git a/src/test/checkqueue_tests.cpp b/src/test/checkqueue_tests.cpp index 830fa95783a2..cc08112dda11 100644 --- a/src/test/checkqueue_tests.cpp +++ b/src/test/checkqueue_tests.cpp @@ -147,7 +147,7 @@ typedef CCheckQueue FrozenCleanup_Queue; */ static void Correct_Queue_range(std::vector range) { - auto small_queue = std::unique_ptr(new Correct_Queue {QUEUE_BATCH_SIZE}); + auto small_queue = MakeUnique(QUEUE_BATCH_SIZE); small_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); // Make vChecks here to save on malloc (this test can be slow...) std::vector vChecks; @@ -208,7 +208,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Correct_Random) /** Test that failing checks are caught */ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) { - auto fail_queue = std::unique_ptr(new Failing_Queue {QUEUE_BATCH_SIZE}); + auto fail_queue = MakeUnique(QUEUE_BATCH_SIZE); fail_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); for (size_t i = 0; i < 1001; ++i) { @@ -236,7 +236,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Catches_Failure) // future blocks, ie, the bad state is cleared. BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) { - auto fail_queue = std::unique_ptr(new Failing_Queue {QUEUE_BATCH_SIZE}); + auto fail_queue = MakeUnique(QUEUE_BATCH_SIZE); fail_queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); for (auto times = 0; times < 10; ++times) { @@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Recovers_From_Failure) // more than once as well BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) { - auto queue = std::unique_ptr(new Unique_Queue {QUEUE_BATCH_SIZE}); + auto queue = MakeUnique(QUEUE_BATCH_SIZE); queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); size_t COUNT = 100000; @@ -295,7 +295,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_UniqueCheck) // time could leave the data hanging across a sequence of blocks. BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) { - auto queue = std::unique_ptr(new Memory_Queue {QUEUE_BATCH_SIZE}); + auto queue = MakeUnique(QUEUE_BATCH_SIZE); queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); for (size_t i = 0; i < 1000; ++i) { size_t total = i; @@ -322,7 +322,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_Memory) // have been destructed BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) { - auto queue = std::unique_ptr(new FrozenCleanup_Queue {QUEUE_BATCH_SIZE}); + auto queue = MakeUnique(QUEUE_BATCH_SIZE); bool fails = false; queue->StartWorkerThreads(SCRIPT_CHECK_THREADS); std::thread t0([&]() { @@ -361,7 +361,7 @@ BOOST_AUTO_TEST_CASE(test_CheckQueue_FrozenCleanup) /** Test that CCheckQueueControl is threadsafe */ BOOST_AUTO_TEST_CASE(test_CheckQueueControl_Locks) { - auto queue = std::unique_ptr(new Standard_Queue{QUEUE_BATCH_SIZE}); + auto queue = MakeUnique(QUEUE_BATCH_SIZE); { boost::thread_group tg; std::atomic nThreads {0}; diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index b4904d07fc5c..957f2883c86c 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -183,12 +183,12 @@ BOOST_AUTO_TEST_CASE(cnode_simple_test) bool fInboundIn = false; // Test that fFeeler is false by default. - std::unique_ptr pnode1(new CNode(id++, NODE_NETWORK, height, hSocket, addr, 0, 0, CAddress(), pszDest, fInboundIn)); + std::unique_ptr pnode1 = MakeUnique(id++, NODE_NETWORK, height, hSocket, addr, 0, 0, CAddress(), pszDest, fInboundIn); BOOST_CHECK(pnode1->fInbound == false); BOOST_CHECK(pnode1->fFeeler == false); fInboundIn = true; - std::unique_ptr pnode2(new CNode(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, CAddress(), pszDest, fInboundIn)); + std::unique_ptr pnode2 = MakeUnique(id++, NODE_NETWORK, height, hSocket, addr, 1, 1, CAddress(), pszDest, fInboundIn); BOOST_CHECK(pnode2->fInbound == true); BOOST_CHECK(pnode2->fFeeler == false); } diff --git a/src/test/test_dash.cpp b/src/test/test_dash.cpp index 786dc00ca894..8fdb2c7c4353 100644 --- a/src/test/test_dash.cpp +++ b/src/test/test_dash.cpp @@ -110,7 +110,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha threadGroup.create_thread(boost::bind(&CScheduler::serviceQueue, &scheduler)); GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); mempool.setSanityCheck(1.0); - g_connman = std::unique_ptr(new CConnman(0x1337, 0x1337)); // Deterministic randomness for tests. + g_connman = MakeUnique(0x1337, 0x1337); // Deterministic randomness for tests. connman = g_connman.get(); pblocktree.reset(new CBlockTreeDB(1 << 20, true)); pcoinsdbview.reset(new CCoinsViewDB(1 << 23, true)); diff --git a/src/test/test_dash_fuzzy.cpp b/src/test/test_dash_fuzzy.cpp index 6cc6ad72b556..79cf623f527a 100644 --- a/src/test/test_dash_fuzzy.cpp +++ b/src/test/test_dash_fuzzy.cpp @@ -277,7 +277,7 @@ static int test_one_input(std::vector buffer) { static std::unique_ptr globalVerifyHandle; void initialize() { - globalVerifyHandle = std::unique_ptr(new ECCVerifyHandle()); + globalVerifyHandle = MakeUnique(); } // This function is used by libFuzzer diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp index 81d7a802c935..3c6a019ea140 100644 --- a/src/wallet/test/coinselector_tests.cpp +++ b/src/wallet/test/coinselector_tests.cpp @@ -66,7 +66,7 @@ static void add_coin(const CAmount& nValue, int nAge = 6*24, bool fIsFromMe = fa // so stop vin being empty, and cache a non-zero Debit to fake out IsFromMe() tx.vin.resize(1); } - std::unique_ptr wtx(new CWalletTx(&testWallet, MakeTransactionRef(std::move(tx)))); + std::unique_ptr wtx = MakeUnique(&testWallet, MakeTransactionRef(std::move(tx))); if (fIsFromMe) { wtx->fDebitCached = true; From b8a46a3c047c8727582c5ad25e1681a16c516fd1 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 19 Oct 2018 19:16:16 -0700 Subject: [PATCH 2/7] Merge #14460: tests: Improve 'CAmount' tests 29ed2d64f6 Improve CAmount tests (Hennadii Stepanov) Pull request description: This provides: - more `MoneyRange` tests; - new `CFeeRate` constructor tests with zero byte size; - explicit using of the `CAmount` type. Tree-SHA512: ca0ad6ccb37909a2a5c11034dc07b316a84c32fb40c6f8b6cfc28ebec72a1de157f31d22e767ae80d70ed06d7296f23870cc5ed0689f34a754ae763d50e23d43 --- src/test/amount_tests.cpp | 57 +++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/src/test/amount_tests.cpp b/src/test/amount_tests.cpp index e709df4ce00c..40dd04303cec 100644 --- a/src/test/amount_tests.cpp +++ b/src/test/amount_tests.cpp @@ -13,8 +13,10 @@ BOOST_FIXTURE_TEST_SUITE(amount_tests, BasicTestingSetup) BOOST_AUTO_TEST_CASE(MoneyRangeTest) { BOOST_CHECK_EQUAL(MoneyRange(CAmount(-1)), false); - BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY + CAmount(1)), false); + BOOST_CHECK_EQUAL(MoneyRange(CAmount(0)), true); BOOST_CHECK_EQUAL(MoneyRange(CAmount(1)), true); + BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY), true); + BOOST_CHECK_EQUAL(MoneyRange(MAX_MONEY + CAmount(1)), false); } BOOST_AUTO_TEST_CASE(GetFeeTest) @@ -23,43 +25,43 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) feeRate = CFeeRate(0); // Must always return 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e5), 0); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1e5), CAmount(0)); feeRate = CFeeRate(1000); // Must always just return the arg - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(1), 1); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), 121); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), 999); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), 1e3); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), 9e3); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1), CAmount(1)); + BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(121)); + BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(999)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(1e3)); + BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(9e3)); feeRate = CFeeRate(-1000); // Must always just return -1 * arg - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(1), -1); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), -121); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), -999); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), -1e3); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), -9e3); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1), CAmount(-1)); + BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(-121)); + BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(-999)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(-1e3)); + BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(-9e3)); feeRate = CFeeRate(123); // Truncates the result, if not integer - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(8), 1); // Special case: returns 1 instead of 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(9), 1); - BOOST_CHECK_EQUAL(feeRate.GetFee(121), 14); - BOOST_CHECK_EQUAL(feeRate.GetFee(122), 15); - BOOST_CHECK_EQUAL(feeRate.GetFee(999), 122); - BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), 123); - BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), 1107); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(8), CAmount(1)); // Special case: returns 1 instead of 0 + BOOST_CHECK_EQUAL(feeRate.GetFee(9), CAmount(1)); + BOOST_CHECK_EQUAL(feeRate.GetFee(121), CAmount(14)); + BOOST_CHECK_EQUAL(feeRate.GetFee(122), CAmount(15)); + BOOST_CHECK_EQUAL(feeRate.GetFee(999), CAmount(122)); + BOOST_CHECK_EQUAL(feeRate.GetFee(1e3), CAmount(123)); + BOOST_CHECK_EQUAL(feeRate.GetFee(9e3), CAmount(1107)); feeRate = CFeeRate(-123); // Truncates the result, if not integer - BOOST_CHECK_EQUAL(feeRate.GetFee(0), 0); - BOOST_CHECK_EQUAL(feeRate.GetFee(8), -1); // Special case: returns -1 instead of 0 - BOOST_CHECK_EQUAL(feeRate.GetFee(9), -1); + BOOST_CHECK_EQUAL(feeRate.GetFee(0), CAmount(0)); + BOOST_CHECK_EQUAL(feeRate.GetFee(8), CAmount(-1)); // Special case: returns -1 instead of 0 + BOOST_CHECK_EQUAL(feeRate.GetFee(9), CAmount(-1)); // check alternate constructor feeRate = CFeeRate(1000); @@ -67,6 +69,9 @@ BOOST_AUTO_TEST_CASE(GetFeeTest) BOOST_CHECK_EQUAL(feeRate.GetFee(100), altFeeRate.GetFee(100)); // Check full constructor + BOOST_CHECK(CFeeRate(CAmount(-1), 0) == CFeeRate(0)); + BOOST_CHECK(CFeeRate(CAmount(0), 0) == CFeeRate(0)); + BOOST_CHECK(CFeeRate(CAmount(1), 0) == CFeeRate(0)); // default value BOOST_CHECK(CFeeRate(CAmount(-1), 1000) == CFeeRate(-1)); BOOST_CHECK(CFeeRate(CAmount(0), 1000) == CFeeRate(0)); From 2e9da22ec88de2ab7dd59d369093d4825112f38b Mon Sep 17 00:00:00 2001 From: Munkybooty Date: Thu, 24 Jun 2021 18:19:53 -0400 Subject: [PATCH 3/7] Merge #14504: show the progress of functional test example (added the progress index `n/m`) ``` 1/107 - wallet_hd.py passed, Duration: 27 s ......................................................................................... 2/107 - mining_getblocktemplate_longpoll.py passed, Duration: 72 s .................................................................. 3/107 - feature_maxuploadtarget.py passed, Duration: 78 s ``` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - clear dots line ``` $ test/functional/test_runner.py -t can_trash Temporary test directory at can_trash/test_runner_₿_🏃_20181018_220600 1/105 - wallet_hd.py passed, Duration: 21 s 2/105 - mining_getblocktemplate_longpoll.py passed, Duration: 71 s 3/105 - feature_maxuploadtarget.py passed, Duration: 68 s .................. ``` - don't print the `dot` progressive if `--quiet` - done_str - nothing commit to check again travis tests --- test/functional/test_runner.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index d9571494744f..86a4e5284f9d 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -322,12 +322,13 @@ def main(): jobs=args.jobs, enable_coverage=args.coverage, args=passon_args, - failfast=args.failfast, runs_ci=args.ci, combined_logs_len=args.combinedlogslen, + failfast=args.failfast, + level=logging_level ) -def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=False, args=None, failfast=False, runs_ci, combined_logs_len=0): +def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=False, args=None, runs_ci, combined_logs_len=0,failfast=False, level=logging.DEBUG): args = args or [] # Warn if dashd is already running (unix only) @@ -370,22 +371,23 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage= test_list=test_list, flags=flags, timeout_duration=TRAVIS_TIMEOUT_DURATION if runs_ci else float('inf'), # in seconds + level ) start_time = time.time() test_results = [] max_len_name = len(max(test_list, key=len)) - - for _ in range(len(test_list)): + test_count = len(test_list) + for i in range(test_count): test_result, testdir, stdout, stderr = job_queue.get_next() test_results.append(test_result) - + done_str = "{}/{} - {}{}{}".format(i + 1, test_count, BOLD[1], test_result.name, BOLD[0]) if test_result.status == "Passed": - logging.debug("\n%s%s%s passed, Duration: %s s" % (BOLD[1], test_result.name, BOLD[0], test_result.time)) + logging.debug("%s passed, Duration: %s s" % (done_str, test_result.time)) elif test_result.status == "Skipped": - logging.debug("\n%s%s%s skipped" % (BOLD[1], test_result.name, BOLD[0])) + logging.debug("%s skipped" % (done_str)) else: - print("\n%s%s%s failed, Duration: %s s\n" % (BOLD[1], test_result.name, BOLD[0], test_result.time)) + print("%s failed, Duration: %s s\n" % (done_str, test_result.time)) print(BOLD[1] + 'stdout:\n' + BOLD[0] + stdout + '\n') print(BOLD[1] + 'stderr:\n' + BOLD[0] + stderr + '\n') if combined_logs_len and os.path.isdir(testdir): @@ -448,7 +450,7 @@ class TestHandler: Trigger the test scripts passed in via the list. """ - def __init__(self, *, num_tests_parallel, tests_dir, tmpdir, test_list, flags, timeout_duration): + def __init__(self, *, num_tests_parallel, tests_dir, tmpdir, test_list, flags, timeout_duration, logging_level=logging.DEBUG): assert num_tests_parallel >= 1 self.num_jobs = num_tests_parallel self.tests_dir = tests_dir @@ -456,6 +458,7 @@ def __init__(self, *, num_tests_parallel, tests_dir, tmpdir, test_list, flags, t self.timeout_duration = timeout_duration self.test_list = test_list self.flags = flags + self.logging_level = logging_level self.num_running = 0 self.jobs = [] @@ -482,6 +485,7 @@ def get_next(self): log_stderr)) if not self.jobs: raise IndexError('pop from empty list') + dot_count = 0 while True: # Return first proc that finishes time.sleep(.5) @@ -502,9 +506,14 @@ def get_next(self): status = "Failed" self.num_running -= 1 self.jobs.remove(job) - + if self.logging_level == logging.DEBUG: + clearline = '\r' + (' ' * dot_count) + '\r' + print(clearline, end='', flush=True) + dot_count = 0 return TestResult(name, status, int(time.time() - start_time)), testdir, stdout, stderr - print('.', end='', flush=True) + if self.logging_level == logging.DEBUG: + print('.', end='', flush=True) + dot_count += 1 def kill_and_join(self): """Send SIGKILL to all jobs and block until all have ended.""" From a5f0708c8651cd30c6506ed09bcd3324fab35d5e Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Thu, 1 Nov 2018 10:42:10 -0400 Subject: [PATCH 4/7] Merge #14569: tests: Print dots by default in functional tests 4bd125fff0 tests: Print dots by default (Chun Kuan Lee) Pull request description: In cron job (https://travis-ci.org/bitcoin/bitcoin/builds/445823485), the functional tests would fail due to silent for 10 mins. After applying this patch, we con't see any extra characters printed on screen but also avoid timeout (https://travis-ci.org/ken2812221/bitcoin/builds/445981698) Tree-SHA512: c0412e171a451b27f9734311c7f063ad3fd7142087ed1e3786b4f303acaebc043f970523d6c2d4ef57ec5857040e2b6f7fd6345304353e7805d76044d317344d # Conflicts: # test/functional/test_runner.py --- test/functional/test_runner.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 86a4e5284f9d..255cd3b652a5 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -228,8 +228,8 @@ def main(): parser.add_argument('--force', '-f', action='store_true', help='run tests even on platforms where they are disabled by default (e.g. windows).') parser.add_argument('--help', '-h', '-?', action='store_true', help='print help text and exit') parser.add_argument('--jobs', '-j', type=int, default=4, help='how many test scripts to run in parallel. Default=4.') - parser.add_argument('--quiet', '-q', action='store_true', help='only print results summary and failure logs') parser.add_argument('--keepcache', '-k', action='store_true', help='the default behavior is to flush the cache directory on startup. --keepcache retains the cache from the previous testrun.') + parser.add_argument('--quiet', '-q', action='store_true', help='only print dots, results summary and failure logs') parser.add_argument('--tmpdirprefix', '-t', default=tempfile.gettempdir(), help="Root directory for datadirs") parser.add_argument('--failfast', action='store_true', help='stop execution after the first test failure') args, unknown_args = parser.parse_known_args() @@ -324,11 +324,10 @@ def main(): args=passon_args, runs_ci=args.ci, combined_logs_len=args.combinedlogslen, - failfast=args.failfast, - level=logging_level + failfast=args.failfast ) -def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=False, args=None, runs_ci, combined_logs_len=0,failfast=False, level=logging.DEBUG): +def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=False, args=None, runs_ci=False, combined_logs_len=0,failfast=False): args = args or [] # Warn if dashd is already running (unix only) @@ -371,7 +370,6 @@ def run_tests(*, test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage= test_list=test_list, flags=flags, timeout_duration=TRAVIS_TIMEOUT_DURATION if runs_ci else float('inf'), # in seconds - level ) start_time = time.time() test_results = [] @@ -450,7 +448,7 @@ class TestHandler: Trigger the test scripts passed in via the list. """ - def __init__(self, *, num_tests_parallel, tests_dir, tmpdir, test_list, flags, timeout_duration, logging_level=logging.DEBUG): + def __init__(self, *, num_tests_parallel, tests_dir, tmpdir, test_list, flags, timeout_duration): assert num_tests_parallel >= 1 self.num_jobs = num_tests_parallel self.tests_dir = tests_dir @@ -458,7 +456,6 @@ def __init__(self, *, num_tests_parallel, tests_dir, tmpdir, test_list, flags, t self.timeout_duration = timeout_duration self.test_list = test_list self.flags = flags - self.logging_level = logging_level self.num_running = 0 self.jobs = [] @@ -506,14 +503,12 @@ def get_next(self): status = "Failed" self.num_running -= 1 self.jobs.remove(job) - if self.logging_level == logging.DEBUG: - clearline = '\r' + (' ' * dot_count) + '\r' - print(clearline, end='', flush=True) - dot_count = 0 + clearline = '\r' + (' ' * dot_count) + '\r' + print(clearline, end='', flush=True) + dot_count = 0 return TestResult(name, status, int(time.time() - start_time)), testdir, stdout, stderr - if self.logging_level == logging.DEBUG: - print('.', end='', flush=True) - dot_count += 1 + print('.', end='', flush=True) + dot_count += 1 def kill_and_join(self): """Send SIGKILL to all jobs and block until all have ended.""" From 92a4fb7cf9bd5c82d89dc32d0f5768d3c44f0643 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 13 Aug 2018 10:02:09 -0400 Subject: [PATCH 5/7] Merge #13534: Don't assert(foo()) where foo() has side effects 6ad0328f1c Don't assert(foo()) where foo has side effects (practicalswift) Pull request description: Don't `assert(foo())` where `foo` has side effects. From `assert(3)`: > If the macro `NDEBUG` is defined at the moment `` was last included, the macro `assert()` generates no code, and hence does nothing at all. Bitcoin currently cannot be compiled without assertions, but we shouldn't rely on that. Tree-SHA512: 28cff0c6d1c2fb612ca58c9c94142ed01c5cfd0a2fecb8e59cdb6c270374b215d952ed3491d921d84dc1b439fa49da4f0e75e080f6adcbc6b0e08be14e54c170 # Conflicts: # src/bench/block_assemble.cpp # src/bench/checkblock.cpp # src/script/sign.cpp --- src/bench/checkblock.cpp | 9 ++++++--- src/httprpc.cpp | 5 +++-- src/script/sign.cpp | 3 ++- src/test/txvalidation_tests.cpp | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/bench/checkblock.cpp b/src/bench/checkblock.cpp index 33cf3a35f3d9..a50917ca458a 100644 --- a/src/bench/checkblock.cpp +++ b/src/bench/checkblock.cpp @@ -26,7 +26,8 @@ static void DeserializeBlockTest(benchmark::State& state) while (state.KeepRunning()) { CBlock block; stream >> block; - assert(stream.Rewind(sizeof(raw_bench::block813851))); + bool rewound = stream.Rewind(sizeof(raw_bench::block813851)); + assert(rewound); } } @@ -43,10 +44,12 @@ static void DeserializeAndCheckBlockTest(benchmark::State& state) while (state.KeepRunning()) { CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here stream >> block; - assert(stream.Rewind(sizeof(raw_bench::block813851))); + bool rewound = stream.Rewind(sizeof(raw_bench::block813851)); + assert(rewound); CValidationState validationState; - assert(CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime())); + bool checked = CheckBlock(block, validationState, chainParams->GetConsensus(), block.GetBlockTime()); + assert(checked); } } diff --git a/src/httprpc.cpp b/src/httprpc.cpp index 4ad50ce8bbef..bc65581b2738 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -247,8 +247,9 @@ bool StartHTTPRPC() // ifdef can be removed once we switch to better endpoint support and API versioning RegisterHTTPHandler("/wallet/", false, HTTPReq_JSONRPC); #endif - assert(EventBase()); - httpRPCTimerInterface = MakeUnique(EventBase()); + struct event_base* eventBase = EventBase(); + assert(eventBase); + httpRPCTimerInterface = MakeUnique(eventBase); RPCSetTimerInterface(httpRPCTimerInterface.get()); return true; } diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 4231250bd0eb..77d9f6f10e46 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -361,7 +361,8 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script) SignatureData sigs; if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) { // VerifyScript check is just defensive, and should never fail. - assert(VerifyScript(sigs.scriptSig, script, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER)); + bool verified = VerifyScript(sigs.scriptSig, script, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER); + assert(verified); return true; } return false; diff --git a/src/test/txvalidation_tests.cpp b/src/test/txvalidation_tests.cpp index d81a17374d7d..2ca41e070e69 100644 --- a/src/test/txvalidation_tests.cpp +++ b/src/test/txvalidation_tests.cpp @@ -30,7 +30,7 @@ BOOST_FIXTURE_TEST_CASE(tx_mempool_reject_coinbase, TestChain100Setup) coinbaseTx.vout[0].nValue = 1 * CENT; coinbaseTx.vout[0].scriptPubKey = scriptPubKey; - assert(CTransaction(coinbaseTx).IsCoinBase()); + BOOST_CHECK(CTransaction(coinbaseTx).IsCoinBase()); CValidationState state; From 3d05f2af99b34ce0a68e7239dc0a324611cb12d9 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 13 Aug 2018 15:01:07 -0400 Subject: [PATCH 6/7] Merge #13634: ui: Compile boost::signals2 only once fa5ce27385 ui: Compile boost:signals2 only once (MarcoFalke) Pull request description: ui is one of the modules that poison other modules with `boost/signals2` headers. This moves the include to the cpp file and uses a forward declaration in the header. Locally this speeds up the incremental build (building everything that uses the ui module) with gcc by ~5% for me. Gcc uses ~5% less memory. Would be nice if someone could verify the numbers roughly. I presume the improvements will be more pronounced if the other models would stop exposing the boost header as well. Tree-SHA512: 078360eba330ddbca4268bd8552927eae242a239e18dfded25ec20be72650a68cd83af7ac160690249b943d33ae35d15df1313f1f60a0c28b9526853aa7d1e40 # Conflicts: # src/interfaces/node.cpp # src/noui.cpp # src/ui_interface.h --- src/init.cpp | 12 ++++----- src/interfaces/node.cpp | 26 +++++++++--------- src/noui.cpp | 6 ++--- src/ui_interface.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ src/ui_interface.h | 41 +++++++++++++++++------------ 5 files changed, 105 insertions(+), 38 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index fb68e041c82b..54d35b8aafc2 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -453,12 +453,12 @@ static void registerSignalHandler(int signal, void(*handler)(int)) static void OnRPCStarted() { - uiInterface.NotifyBlockTip.connect(&RPCNotifyBlockChange); + uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange); } static void OnRPCStopped() { - uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange); + uiInterface.NotifyBlockTip_disconnect(&RPCNotifyBlockChange); RPCNotifyBlockChange(false, nullptr); g_best_block_cv.notify_all(); LogPrint(BCLog::RPC, "RPC stopped.\n"); @@ -1855,7 +1855,7 @@ bool AppInitMain() */ if (gArgs.GetBoolArg("-server", false)) { - uiInterface.InitMessage.connect(SetRPCWarmupStatus); + uiInterface.InitMessage_connect(SetRPCWarmupStatus); if (!AppInitServers()) return InitError(_("Unable to start HTTP server. See debug log for details.")); } @@ -2432,13 +2432,13 @@ bool AppInitMain() // Either install a handler to notify us when genesis activates, or set fHaveGenesis directly. // No locking, as this happens before any background thread is started. if (chainActive.Tip() == nullptr) { - uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait); + uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait); } else { fHaveGenesis = true; } if (gArgs.IsArgSet("-blocknotify")) - uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); + uiInterface.NotifyBlockTip_connect(BlockNotifyCallback); std::vector vImportFiles; for (const std::string& strFile : gArgs.GetArgs("-loadblock")) { @@ -2456,7 +2456,7 @@ bool AppInitMain() while (!fHaveGenesis && !ShutdownRequested()) { g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500)); } - uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); + uiInterface.NotifyBlockTip_disconnect(BlockNotifyGenesisWait); } // As importing blocks can take several minutes, it's possible the user diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp index 7279a9a7b02f..2a4e1f17b237 100644 --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -365,44 +365,44 @@ class NodeImpl : public Node std::unique_ptr handleInitMessage(InitMessageFn fn) override { - return MakeHandler(::uiInterface.InitMessage.connect(fn)); + return MakeHandler(::uiInterface.InitMessage_connect(fn)); } std::unique_ptr handleMessageBox(MessageBoxFn fn) override { - return MakeHandler(::uiInterface.ThreadSafeMessageBox.connect(fn)); + return MakeHandler(::uiInterface.ThreadSafeMessageBox_connect(fn)); } std::unique_ptr handleQuestion(QuestionFn fn) override { - return MakeHandler(::uiInterface.ThreadSafeQuestion.connect(fn)); + return MakeHandler(::uiInterface.ThreadSafeQuestion_connect(fn)); } std::unique_ptr handleShowProgress(ShowProgressFn fn) override { - return MakeHandler(::uiInterface.ShowProgress.connect(fn)); + return MakeHandler(::uiInterface.ShowProgress_connect(fn)); } std::unique_ptr handleLoadWallet(LoadWalletFn fn) override { CHECK_WALLET( - return MakeHandler(::uiInterface.LoadWallet.connect([fn](std::shared_ptr wallet) { fn(MakeWallet(wallet)); }))); + return MakeHandler(::uiInterface.LoadWallet_connect([fn](std::shared_ptr wallet) { fn(MakeWallet(wallet)); }))); } std::unique_ptr handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyNumConnectionsChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyNumConnectionsChanged_connect(fn)); } std::unique_ptr handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyNetworkActiveChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyNetworkActiveChanged_connect(fn)); } std::unique_ptr handleNotifyAlertChanged(NotifyAlertChangedFn fn) override { - return MakeHandler(::uiInterface.NotifyAlertChanged.connect(fn)); + return MakeHandler(::uiInterface.NotifyAlertChanged_connect(fn)); } std::unique_ptr handleBannedListChanged(BannedListChangedFn fn) override { - return MakeHandler(::uiInterface.BannedListChanged.connect(fn)); + return MakeHandler(::uiInterface.BannedListChanged_connect(fn)); } std::unique_ptr handleNotifyBlockTip(NotifyBlockTipFn fn) override { - return MakeHandler(::uiInterface.NotifyBlockTip.connect([fn](bool initial_download, const CBlockIndex* block) { + return MakeHandler(::uiInterface.NotifyBlockTip_connect([fn](bool initial_download, const CBlockIndex* block) { fn(initial_download, block->nHeight, block->GetBlockTime(), block->GetBlockHash().ToString(), GuessVerificationProgress(Params().TxData(), block)); })); @@ -410,7 +410,7 @@ class NodeImpl : public Node std::unique_ptr handleNotifyHeaderTip(NotifyHeaderTipFn fn) override { return MakeHandler( - ::uiInterface.NotifyHeaderTip.connect([fn](bool initial_download, const CBlockIndex* block) { + ::uiInterface.NotifyHeaderTip_connect([fn](bool initial_download, const CBlockIndex* block) { fn(initial_download, block->nHeight, block->GetBlockTime(), block->GetBlockHash().ToString(), GuessVerificationProgress(Params().TxData(), block)); })); @@ -418,14 +418,14 @@ class NodeImpl : public Node std::unique_ptr handleNotifyMasternodeListChanged(NotifyMasternodeListChangedFn fn) override { return MakeHandler( - ::uiInterface.NotifyMasternodeListChanged.connect([fn](const CDeterministicMNList& newList) { + ::uiInterface.NotifyMasternodeListChanged_connect([fn](const CDeterministicMNList& newList) { fn(newList); })); } std::unique_ptr handleNotifyAdditionalDataSyncProgressChanged(NotifyAdditionalDataSyncProgressChangedFn fn) override { return MakeHandler( - ::uiInterface.NotifyAdditionalDataSyncProgressChanged.connect([fn](double nSyncProgress) { + ::uiInterface.NotifyAdditionalDataSyncProgressChanged_connect([fn](double nSyncProgress) { fn(nSyncProgress); })); } diff --git a/src/noui.cpp b/src/noui.cpp index 7591eb991cb9..4626d54104eb 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -53,7 +53,7 @@ static void noui_InitMessage(const std::string& message) void noui_connect() { // Connect dashd signal handlers - uiInterface.ThreadSafeMessageBox.connect(noui_ThreadSafeMessageBox); - uiInterface.ThreadSafeQuestion.connect(noui_ThreadSafeQuestion); - uiInterface.InitMessage.connect(noui_InitMessage); + uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox); + uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion); + uiInterface.InitMessage_connect(noui_InitMessage); } diff --git a/src/ui_interface.cpp b/src/ui_interface.cpp index 17565bc6c9bb..23fa8b009026 100644 --- a/src/ui_interface.cpp +++ b/src/ui_interface.cpp @@ -5,8 +5,66 @@ #include #include +#include +#include + CClientUIInterface uiInterface; +struct UISignals { + boost::signals2::signal> ThreadSafeMessageBox; + boost::signals2::signal> ThreadSafeQuestion; + boost::signals2::signal InitMessage; + boost::signals2::signal NotifyNumConnectionsChanged; + boost::signals2::signal NotifyNetworkActiveChanged; + boost::signals2::signal NotifyAlertChanged; + boost::signals2::signal LoadWallet; + boost::signals2::signal ShowProgress; + boost::signals2::signal NotifyBlockTip; + boost::signals2::signal NotifyHeaderTip; + boost::signals2::signal NotifyMasternodeListChanged; + boost::signals2::signal NotifyAdditionalDataSyncProgressChanged; + boost::signals2::signal BannedListChanged; +} g_ui_signals; + +#define ADD_SIGNALS_IMPL_WRAPPER(signal_name) \ + boost::signals2::connection CClientUIInterface::signal_name##_connect(std::function fn) \ + { \ + return g_ui_signals.signal_name.connect(fn); \ + } \ + void CClientUIInterface::signal_name##_disconnect(std::function fn) \ + { \ + return g_ui_signals.signal_name.disconnect(&fn); \ + } + +ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeMessageBox); +ADD_SIGNALS_IMPL_WRAPPER(ThreadSafeQuestion); +ADD_SIGNALS_IMPL_WRAPPER(InitMessage); +ADD_SIGNALS_IMPL_WRAPPER(NotifyNumConnectionsChanged); +ADD_SIGNALS_IMPL_WRAPPER(NotifyNetworkActiveChanged); +ADD_SIGNALS_IMPL_WRAPPER(NotifyAlertChanged); +ADD_SIGNALS_IMPL_WRAPPER(LoadWallet); +ADD_SIGNALS_IMPL_WRAPPER(ShowProgress); +ADD_SIGNALS_IMPL_WRAPPER(NotifyBlockTip); +ADD_SIGNALS_IMPL_WRAPPER(NotifyHeaderTip); +ADD_SIGNALS_IMPL_WRAPPER(NotifyMasternodeListChanged); +ADD_SIGNALS_IMPL_WRAPPER(NotifyAdditionalDataSyncProgressChanged); +ADD_SIGNALS_IMPL_WRAPPER(BannedListChanged); + +bool CClientUIInterface::ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeMessageBox(message, caption, style); } +bool CClientUIInterface::ThreadSafeQuestion(const std::string& message, const std::string& non_interactive_message, const std::string& caption, unsigned int style) { return g_ui_signals.ThreadSafeQuestion(message, non_interactive_message, caption, style); } +void CClientUIInterface::InitMessage(const std::string& message) { return g_ui_signals.InitMessage(message); } +void CClientUIInterface::NotifyNumConnectionsChanged(int newNumConnections) { return g_ui_signals.NotifyNumConnectionsChanged(newNumConnections); } +void CClientUIInterface::NotifyNetworkActiveChanged(bool networkActive) { return g_ui_signals.NotifyNetworkActiveChanged(networkActive); } +void CClientUIInterface::NotifyAlertChanged() { return g_ui_signals.NotifyAlertChanged(); } +void CClientUIInterface::LoadWallet(std::shared_ptr wallet) { return g_ui_signals.LoadWallet(wallet); } +void CClientUIInterface::ShowProgress(const std::string& title, int nProgress, bool resume_possible) { return g_ui_signals.ShowProgress(title, nProgress, resume_possible); } +void CClientUIInterface::NotifyBlockTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyBlockTip(b, i); } +void CClientUIInterface::NotifyHeaderTip(bool b, const CBlockIndex* i) { return g_ui_signals.NotifyHeaderTip(b, i); } +void CClientUIInterface::NotifyMasternodeListChanged(const CDeterministicMNList& list) { return g_ui_signals.NotifyMasternodeListChanged(list); } +void CClientUIInterface::NotifyAdditionalDataSyncProgressChanged(double nSyncProgress) { return g_ui_signals.NotifyAdditionalDataSyncProgressChanged(nSyncProgress); } +void CClientUIInterface::BannedListChanged() { return g_ui_signals.BannedListChanged(); } + + bool InitError(const std::string& str) { uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR); diff --git a/src/ui_interface.h b/src/ui_interface.h index 4452a9ed28f4..edc123b9db00 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -6,16 +6,19 @@ #ifndef BITCOIN_UI_INTERFACE_H #define BITCOIN_UI_INTERFACE_H +#include #include #include #include -#include -#include - class CWallet; class CBlockIndex; class CDeterministicMNList; +namespace boost { +namespace signals2 { +class connection; +} +} // namespace boost /** General change type (added, updated, removed). */ enum ChangeType @@ -73,49 +76,55 @@ class CClientUIInterface MSG_ERROR = (ICON_ERROR | BTN_OK | MODAL) }; +#define ADD_SIGNALS_DECL_WRAPPER(signal_name, rtype, args...) \ + rtype signal_name(args); \ + using signal_name##Sig = rtype(args); \ + boost::signals2::connection signal_name##_connect(std::function fn); \ + void signal_name##_disconnect(std::function fn); + /** Show message box. */ - boost::signals2::signal > ThreadSafeMessageBox; + ADD_SIGNALS_DECL_WRAPPER(ThreadSafeMessageBox, bool, const std::string& message, const std::string& caption, unsigned int style); /** If possible, ask the user a question. If not, falls back to ThreadSafeMessageBox(noninteractive_message, caption, style) and returns false. */ - boost::signals2::signal > ThreadSafeQuestion; + ADD_SIGNALS_DECL_WRAPPER(ThreadSafeQuestion, bool, const std::string& message, const std::string& noninteractive_message, const std::string& caption, unsigned int style); /** Progress message during initialization. */ - boost::signals2::signal InitMessage; + ADD_SIGNALS_DECL_WRAPPER(InitMessage, void, const std::string& message); /** Number of network connections changed. */ - boost::signals2::signal NotifyNumConnectionsChanged; + ADD_SIGNALS_DECL_WRAPPER(NotifyNumConnectionsChanged, void, int newNumConnections); /** Network activity state changed. */ - boost::signals2::signal NotifyNetworkActiveChanged; + ADD_SIGNALS_DECL_WRAPPER(NotifyNetworkActiveChanged, void, bool networkActive); /** * Status bar alerts changed. */ - boost::signals2::signal NotifyAlertChanged; + ADD_SIGNALS_DECL_WRAPPER(NotifyAlertChanged, void, ); /** A wallet has been loaded. */ - boost::signals2::signal wallet)> LoadWallet; + ADD_SIGNALS_DECL_WRAPPER(LoadWallet, void, std::shared_ptr wallet); /** * Show progress e.g. for verifychain. * resume_possible indicates shutting down now will result in the current progress action resuming upon restart. */ - boost::signals2::signal ShowProgress; + ADD_SIGNALS_DECL_WRAPPER(ShowProgress, void, const std::string& title, int nProgress, bool resume_possible); /** New block has been accepted */ - boost::signals2::signal NotifyBlockTip; + ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, bool, const CBlockIndex*); /** Best header has changed */ - boost::signals2::signal NotifyHeaderTip; + ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, bool, const CBlockIndex*); /** Masternode list has changed */ - boost::signals2::signal NotifyMasternodeListChanged; + ADD_SIGNALS_DECL_WRAPPER(NotifyMasternodeListChanged, void, const CDeterministicMNList&); /** Additional data sync progress changed */ - boost::signals2::signal NotifyAdditionalDataSyncProgressChanged; + ADD_SIGNALS_DECL_WRAPPER(NotifyAdditionalDataSyncProgressChanged, void, double nSyncProgress); /** Banlist did change. */ - boost::signals2::signal BannedListChanged; + ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void); }; /** Show warning message **/ From e86ea611d47c70946aa13a3944c287197caefac2 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sat, 25 Aug 2018 20:20:30 +0200 Subject: [PATCH 7/7] Merge #13961: util: Replace boost::signals2 with std::function ddddce0e46e73d4ca369f2ce9696231cc579e1f9 util: Replace boost::signals2 with std::function (MarcoFalke) Pull request description: This removes the `#include ` from `util.h` (hopefully speeding up the build time and reducing the memory usage further after #13634) The whole translation interface is replaced by a function `G_TRANSLATION_FUN` that is set to nullptr in units that don't need translation. (Thus only set in the gui) Tree-SHA512: 087c717358bbed8bdb409463e225239d667f1ced381abb10e7cd31a41dcdd2cebe20b43c2ee86f0f8e55d53301f75e963f07421a99a7ff4c0cad2c6a375c5ab1 # Conflicts: # src/bench/bench_dash.cpp # src/qt/dash.cpp # src/qt/splashscreen.cpp # src/qt/transactiontablemodel.cpp # src/test/test_dash.cpp # src/util/system.h # src/wallet/coinselection.cpp --- src/bench/bench_dash.cpp | 2 ++ src/dash-cli.cpp | 2 ++ src/dash-tx.cpp | 2 ++ src/dashd.cpp | 2 ++ src/noui.cpp | 2 ++ src/qt/bitcoingui.cpp | 2 ++ src/qt/dash.cpp | 10 +++------- src/qt/splashscreen.cpp | 4 +++- src/qt/transactiontablemodel.cpp | 4 +++- src/test/test_dash.cpp | 11 +++++++---- src/test/test_dash_fuzzy.cpp | 12 +++++++----- src/util/system.cpp | 2 -- src/util/system.h | 23 +++++++---------------- src/wallet/coinselection.cpp | 1 + 14 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/bench/bench_dash.cpp b/src/bench/bench_dash.cpp index c549bfbafc20..001e7612ee44 100644 --- a/src/bench/bench_dash.cpp +++ b/src/bench/bench_dash.cpp @@ -16,6 +16,8 @@ #include +const std::function G_TRANSLATION_FUN = nullptr; + static const int64_t DEFAULT_BENCH_EVALUATIONS = 5; static const char* DEFAULT_BENCH_FILTER = ".*"; static const char* DEFAULT_BENCH_SCALING = "1.0"; diff --git a/src/dash-cli.cpp b/src/dash-cli.cpp index cf97031aa0b4..8d6bc22f7323 100644 --- a/src/dash-cli.cpp +++ b/src/dash-cli.cpp @@ -26,6 +26,8 @@ #include +const std::function G_TRANSLATION_FUN = nullptr; + static const char DEFAULT_RPCCONNECT[] = "127.0.0.1"; static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900; static const bool DEFAULT_NAMED=false; diff --git a/src/dash-tx.cpp b/src/dash-tx.cpp index 5fe7e7d6f552..d2ff5807e385 100644 --- a/src/dash-tx.cpp +++ b/src/dash-tx.cpp @@ -32,6 +32,8 @@ static bool fCreateBlank; static std::map registers; static const int CONTINUE_EXECUTION=-1; +const std::function G_TRANSLATION_FUN = nullptr; + static void SetupBitcoinTxArgs() { gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS); diff --git a/src/dashd.cpp b/src/dashd.cpp index 3dd8012093c8..b8bf72d27d90 100644 --- a/src/dashd.cpp +++ b/src/dashd.cpp @@ -25,6 +25,8 @@ #include +const std::function G_TRANSLATION_FUN = nullptr; + /* Introduction text for doxygen: */ /*! \mainpage Developer documentation diff --git a/src/noui.cpp b/src/noui.cpp index 4626d54104eb..1fad06c085f8 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -13,6 +13,8 @@ #include #include +#include + static bool noui_ThreadSafeMessageBox(const std::string& message, const std::string& caption, unsigned int style) { bool fSecure = style & CClientUIInterface::SECURE; diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 1f87618c5f3a..3df992d45544 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -61,6 +61,8 @@ #include #include +#include + const std::string BitcoinGUI::DEFAULT_UIPLATFORM = #if defined(Q_OS_MAC) "macosx" diff --git a/src/qt/dash.cpp b/src/qt/dash.cpp index 41012a710cad..c9bd09e3880d 100644 --- a/src/qt/dash.cpp +++ b/src/qt/dash.cpp @@ -76,13 +76,10 @@ static void InitMessage(const std::string &message) LogPrintf("init message: %s\n", message); } -/* - Translate string to current locale using Qt. - */ -static std::string Translate(const char* psz) -{ +/** Translate string to current locale using Qt. */ +const std::function G_TRANSLATION_FUN = [](const char* psz) { return QCoreApplication::translate("dash-core", psz).toStdString(); -} +}; static QString GetLangTerritory() { @@ -628,7 +625,6 @@ int main(int argc, char *argv[]) // Now that QSettings are accessible, initialize translations QTranslator qtTranslatorBase, qtTranslator, translatorBase, translator; initTranslations(qtTranslatorBase, qtTranslator, translatorBase, translator); - translationInterface.Translate.connect(Translate); if (gArgs.IsArgSet("-printcrashinfo")) { auto crashInfo = GetCrashInfoStrFromSerializedStr(gArgs.GetArg("-printcrashinfo", "")); diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index 67126ee2997b..20fffe7693f4 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -18,8 +18,8 @@ #include #include #include -#include #include +#include #include #include @@ -27,6 +27,8 @@ #include #include +#include + SplashScreen::SplashScreen(interfaces::Node& node, Qt::WindowFlags f, const NetworkStyle *networkStyle) : QWidget(0, f), curAlignment(0), m_node(node) { diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index 2a443e70a1a7..505e1e0a6014 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -13,10 +13,10 @@ #include #include #include -#include #include #include #include +#include #include #include @@ -24,6 +24,8 @@ #include #include +#include + // Amount column is right-aligned it contains numbers static int column_alignments[] = { Qt::AlignLeft|Qt::AlignVCenter, /* status */ diff --git a/src/test/test_dash.cpp b/src/test/test_dash.cpp index 8fdb2c7c4353..ba48ade7d67d 100644 --- a/src/test/test_dash.cpp +++ b/src/test/test_dash.cpp @@ -9,15 +9,16 @@ #include #include #include -#include #include #include #include -#include -#include -#include #include +#include #include