Skip to content

Commit ab9de43

Browse files
author
MarcoFalke
committed
Merge #18181: test: Remove incorrect assumptions in validation_flush_tests
faca8ef test: Remove incorrect assumptions in validation_flush_tests (MarcoFalke) fa31eeb test: Tabs to spaces in all tests (MarcoFalke) Pull request description: The tests assume standard library internals that may not hold on all supported archs or when the code is instrumented for sanitizer or debug use cases Fixes #18111 ACKs for top commit: jamesob: ACK bitcoin/bitcoin@faca8ef pending passing tests fjahr: ACK faca8ef Tree-SHA512: 60a5ae824bdffb0762f82f67957b31b185385900be5e676fcb12c23d53f5eea734601680c2e3f0bdb8052ce90e7ca1911b1342affb67e43d91a506b111406f41
2 parents 36e5072 + faca8ef commit ab9de43

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

src/test/bswap_tests.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ BOOST_FIXTURE_TEST_SUITE(bswap_tests, BasicTestingSetup)
1111

1212
BOOST_AUTO_TEST_CASE(bswap_tests)
1313
{
14-
// Sibling in bitcoin/src/qt/test/compattests.cpp
15-
uint16_t u1 = 0x1234;
16-
uint32_t u2 = 0x56789abc;
17-
uint64_t u3 = 0xdef0123456789abc;
18-
uint16_t e1 = 0x3412;
19-
uint32_t e2 = 0xbc9a7856;
20-
uint64_t e3 = 0xbc9a78563412f0de;
21-
BOOST_CHECK(bswap_16(u1) == e1);
22-
BOOST_CHECK(bswap_32(u2) == e2);
23-
BOOST_CHECK(bswap_64(u3) == e3);
14+
// Sibling in bitcoin/src/qt/test/compattests.cpp
15+
uint16_t u1 = 0x1234;
16+
uint32_t u2 = 0x56789abc;
17+
uint64_t u3 = 0xdef0123456789abc;
18+
uint16_t e1 = 0x3412;
19+
uint32_t e2 = 0xbc9a7856;
20+
uint64_t e3 = 0xbc9a78563412f0de;
21+
BOOST_CHECK(bswap_16(u1) == e1);
22+
BOOST_CHECK(bswap_32(u2) == e2);
23+
BOOST_CHECK(bswap_64(u3) == e3);
2424
}
2525

2626
BOOST_AUTO_TEST_SUITE_END()

src/test/transaction_tests.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ BOOST_AUTO_TEST_CASE(tx_valid)
122122
std::map<COutPoint, int64_t> mapprevOutValues;
123123
UniValue inputs = test[0].get_array();
124124
bool fValid = true;
125-
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
126-
const UniValue& input = inputs[inpIdx];
127-
if (!input.isArray())
128-
{
125+
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
126+
const UniValue& input = inputs[inpIdx];
127+
if (!input.isArray()) {
129128
fValid = false;
130129
break;
131130
}
@@ -209,10 +208,9 @@ BOOST_AUTO_TEST_CASE(tx_invalid)
209208
std::map<COutPoint, int64_t> mapprevOutValues;
210209
UniValue inputs = test[0].get_array();
211210
bool fValid = true;
212-
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
213-
const UniValue& input = inputs[inpIdx];
214-
if (!input.isArray())
215-
{
211+
for (unsigned int inpIdx = 0; inpIdx < inputs.size(); inpIdx++) {
212+
const UniValue& input = inputs[inpIdx];
213+
if (!input.isArray()) {
216214
fValid = false;
217215
break;
218216
}

src/test/validation_flush_tests.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44
//
5-
#include <txmempool.h>
6-
#include <validation.h>
75
#include <sync.h>
86
#include <test/util/setup_common.h>
7+
#include <txmempool.h>
8+
#include <validation.h>
99

1010
#include <boost/test/unit_test.hpp>
1111

@@ -85,12 +85,7 @@ BOOST_AUTO_TEST_CASE(getcoinscachesizestate)
8585
// This is contingent not only on the dynamic memory usage of the Coins
8686
// that we're adding (COIN_SIZE bytes per), but also on how much memory the
8787
// cacheCoins (unordered_map) preallocates.
88-
//
89-
// I came up with the count by examining the printed memory usage of the
90-
// CCoinsCacheView, so it's sort of arbitrary - but it shouldn't change
91-
// unless we somehow change the way the cacheCoins map allocates memory.
92-
//
93-
constexpr int COINS_UNTIL_CRITICAL = is_64_bit ? 4 : 5;
88+
constexpr int COINS_UNTIL_CRITICAL{3};
9489

9590
for (int i{0}; i < COINS_UNTIL_CRITICAL; ++i) {
9691
COutPoint res = add_coin(view);
@@ -101,17 +96,14 @@ BOOST_AUTO_TEST_CASE(getcoinscachesizestate)
10196
CoinsCacheSizeState::OK);
10297
}
10398

104-
// Adding an additional coin will push us over the edge to CRITICAL.
105-
add_coin(view);
106-
print_view_mem_usage(view);
107-
108-
auto size_state = chainstate.GetCoinsCacheSizeState(
109-
tx_pool, MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0);
110-
111-
if (!is_64_bit && size_state == CoinsCacheSizeState::LARGE) {
112-
// On 32 bit hosts, we may hit LARGE before CRITICAL.
99+
// Adding some additional coins will push us over the edge to CRITICAL.
100+
for (int i{0}; i < 4; ++i) {
113101
add_coin(view);
114102
print_view_mem_usage(view);
103+
if (chainstate.GetCoinsCacheSizeState(tx_pool, MAX_COINS_CACHE_BYTES, /*max_mempool_size_bytes*/ 0) ==
104+
CoinsCacheSizeState::CRITICAL) {
105+
break;
106+
}
115107
}
116108

117109
BOOST_CHECK_EQUAL(

0 commit comments

Comments
 (0)