Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/addrman.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ struct AddressPosition {
const int bucket;
const int position;

bool operator==(AddressPosition other) {
bool operator==(AddressPosition other) const {
return std::tie(tried, multiplicity, bucket, position) ==
std::tie(other.tried, other.multiplicity, other.bucket, other.position);
}
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/hmac_sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CHMAC_SHA256
CSHA256 inner;

public:
static const size_t OUTPUT_SIZE = 32;
static constexpr size_t OUTPUT_SIZE = 32;

CHMAC_SHA256(const unsigned char* key, size_t keylen);
CHMAC_SHA256& Write(const unsigned char* data, size_t len)
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/hmac_sha512.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CHMAC_SHA512
CSHA512 inner;

public:
static const size_t OUTPUT_SIZE = 64;
static constexpr size_t OUTPUT_SIZE = 64;

CHMAC_SHA512(const unsigned char* key, size_t keylen);
CHMAC_SHA512& Write(const unsigned char* data, size_t len)
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/ripemd160.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CRIPEMD160
uint64_t bytes{0};

public:
static const size_t OUTPUT_SIZE = 20;
static constexpr size_t OUTPUT_SIZE = 20;

CRIPEMD160();
CRIPEMD160& Write(const unsigned char* data, size_t len);
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CSHA1
uint64_t bytes{0};

public:
static const size_t OUTPUT_SIZE = 20;
static constexpr size_t OUTPUT_SIZE = 20;

CSHA1();
CSHA1& Write(const unsigned char* data, size_t len);
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/sha256.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CSHA256
uint64_t bytes{0};

public:
static const size_t OUTPUT_SIZE = 32;
static constexpr size_t OUTPUT_SIZE = 32;

CSHA256();
CSHA256& Write(const unsigned char* data, size_t len);
Expand Down
36 changes: 18 additions & 18 deletions src/ipc/test/ipc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <kj/test.h>
#include <stdexcept>

#include <boost/test/unit_test.hpp>
#include <test/util/framework.hpp>

static_assert(ipc::capnp::messages::MAX_MONEY == MAX_MONEY);
static_assert(ipc::capnp::messages::MAX_DOUBLE == std::numeric_limits<double>::max());
Expand All @@ -45,8 +45,8 @@ static std::string TempPath(std::string_view pattern)
std::string temp{fs::PathToString(fs::path{fs::temp_directory_path()} / fs::PathFromString(std::string{pattern}))};
temp.push_back('\0');
int fd{mkstemp(temp.data())};
BOOST_CHECK_GE(fd, 0);
BOOST_CHECK_EQUAL(close(fd), 0);
CHECK(fd >= 0);
CHECK(close(fd) == 0);
temp.resize(temp.size() - 1);
fs::remove(fs::PathFromString(temp));
return temp;
Expand Down Expand Up @@ -85,17 +85,17 @@ void IpcPipeTest()
std::unique_ptr<mp::ProxyClient<gen::FooInterface>> foo{foo_promise.get_future().get()};

// Test: make sure arguments were sent and return value is received
BOOST_CHECK_EQUAL(foo->add(1, 2), 3);
CHECK(foo->add(1, 2) == 3);

COutPoint txout1{Txid::FromUint256(uint256{100}), 200};
COutPoint txout2{foo->passOutPoint(txout1)};
BOOST_CHECK(txout1 == txout2);
CHECK(txout1 == txout2);

UniValue uni1{UniValue::VOBJ};
uni1.pushKV("i", 1);
uni1.pushKV("s", "two");
UniValue uni2{foo->passUniValue(uni1)};
BOOST_CHECK_EQUAL(uni1.write(), uni2.write());
CHECK(uni1.write() == uni2.write());

CMutableTransaction mtx;
mtx.version = 2;
Expand All @@ -104,15 +104,15 @@ void IpcPipeTest()
mtx.vout.emplace_back(COIN, CScript());
CTransactionRef tx1{MakeTransactionRef(mtx)};
CTransactionRef tx2{foo->passTransaction(tx1)};
BOOST_CHECK(*Assert(tx1) == *Assert(tx2));
CHECK(*Assert(tx1) == *Assert(tx2));

std::vector<char> vec1{'H', 'e', 'l', 'l', 'o'};
std::vector<char> vec2{foo->passVectorChar(vec1)};
BOOST_CHECK_EQUAL(std::string_view(vec1.begin(), vec1.end()), std::string_view(vec2.begin(), vec2.end()));
CHECK(std::string_view(vec1.begin(), vec1.end()) == std::string_view(vec2.begin(), vec2.end()));

auto script1{CScript() << OP_11};
auto script2{foo->passScript(script1)};
BOOST_CHECK_EQUAL(HexStr(script1), HexStr(script2));
CHECK(HexStr(script1) == HexStr(script2));

// Test cleanup: disconnect and join thread
foo.reset();
Expand All @@ -123,7 +123,7 @@ void IpcPipeTest()
void IpcSocketPairTest()
{
int fds[2];
BOOST_CHECK_EQUAL(socketpair(AF_UNIX, SOCK_STREAM, 0, fds), 0);
CHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
std::unique_ptr<interfaces::Init> init{std::make_unique<TestInit>()};
std::unique_ptr<ipc::Protocol> protocol{ipc::capnp::MakeCapnpProtocol()};
std::promise<void> promise;
Expand All @@ -133,10 +133,10 @@ void IpcSocketPairTest()
promise.get_future().wait();
std::unique_ptr<interfaces::Init> remote_init{protocol->connect(fds[1], "test-connect")};
std::unique_ptr<interfaces::Echo> remote_echo{remote_init->makeEcho()};
BOOST_CHECK_EQUAL(remote_echo->echo("echo test"), "echo test");
CHECK(remote_echo->echo("echo test") == "echo test");
remote_echo.reset();
remote_init->stop();
BOOST_CHECK(static_cast<TestInit*>(init.get())->stop_called.load());
CHECK(static_cast<TestInit*>(init.get())->stop_called.load());
remote_init.reset();
thread.join();
}
Expand All @@ -149,24 +149,24 @@ void IpcSocketTest(const fs::path& datadir)
std::unique_ptr<ipc::Process> process{ipc::MakeProcess()};

std::string invalid_bind{"invalid:"};
BOOST_CHECK_THROW(process->bind(datadir, "test_bitcoin", invalid_bind), std::invalid_argument);
BOOST_CHECK_THROW(process->connect(datadir, "test_bitcoin", invalid_bind), std::invalid_argument);
CHECK_THROWS_AS(process->bind(datadir, "test_bitcoin", invalid_bind), std::invalid_argument);
CHECK_THROWS_AS(process->connect(datadir, "test_bitcoin", invalid_bind), std::invalid_argument);

auto bind_and_listen{[&](const std::string& bind_address) {
std::string address{bind_address};
int serve_fd = process->bind(datadir, "test_bitcoin", address);
BOOST_CHECK_GE(serve_fd, 0);
BOOST_CHECK_EQUAL(address, bind_address);
CHECK(serve_fd >= 0);
CHECK(address == bind_address);
protocol->listen(serve_fd, "test-serve", *init);
}};

auto connect_and_test{[&](const std::string& connect_address) {
std::string address{connect_address};
int connect_fd{process->connect(datadir, "test_bitcoin", address)};
BOOST_CHECK_EQUAL(address, connect_address);
CHECK(address == connect_address);
std::unique_ptr<interfaces::Init> remote_init{protocol->connect(connect_fd, "test-connect")};
std::unique_ptr<interfaces::Echo> remote_echo{remote_init->makeEcho()};
BOOST_CHECK_EQUAL(remote_echo->echo("echo test"), "echo test");
CHECK(remote_echo->echo("echo test") == "echo test");
}};

// Need to specify explicit socket addresses outside the data directory, because the data
Expand Down
16 changes: 8 additions & 8 deletions src/ipc/test/ipc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@

#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
#include <test/util/framework.hpp>

BOOST_FIXTURE_TEST_SUITE(ipc_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(ipc_tests)
TEST_SUITE_BEGIN("ipc_tests")
FIXTURE_TEST_CASE("ipc_tests", BasicTestingSetup)
{
IpcPipeTest();
IpcSocketPairTest();
IpcSocketTest(m_args.GetDataDirNet());
}

// Test address parsing.
BOOST_AUTO_TEST_CASE(parse_address_test)
FIXTURE_TEST_CASE("parse_address_test", BasicTestingSetup)
{
std::unique_ptr<ipc::Process> process{ipc::MakeProcess()};
fs::path datadir{"/var/empty/notexist"};
auto check_notexist{[](const std::system_error& e) { return e.code() == std::errc::no_such_file_or_directory; }};
auto check_address{[&](std::string address, std::string expect_address, std::string expect_error) {
if (expect_error.empty()) {
BOOST_CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::system_error, check_notexist);
CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::system_error, check_notexist);
} else {
BOOST_CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::invalid_argument, HasReason(expect_error));
CHECK_EXCEPTION(process->connect(datadir, "test_bitcoin", address), std::invalid_argument, HasReason(expect_error));
}
BOOST_CHECK_EQUAL(address, expect_address);
CHECK(address == expect_address);
}};
check_address("unix", "unix:/var/empty/notexist/test_bitcoin.sock", "");
check_address("unix:", "unix:/var/empty/notexist/test_bitcoin.sock", "");
Expand All @@ -40,4 +40,4 @@ BOOST_AUTO_TEST_CASE(parse_address_test)
check_address("invalid", "invalid", "Unrecognized address 'invalid'");
}

BOOST_AUTO_TEST_SUITE_END()
TEST_SUITE_END()
4 changes: 2 additions & 2 deletions src/support/lockedpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ class LockedPool
* allocation and deallocation overhead. Setting it too high allocates
* more locked memory from the OS than strictly necessary.
*/
static const size_t ARENA_SIZE = 256*1024;
static constexpr size_t ARENA_SIZE = 256*1024;
/** Chunk alignment. Another compromise. Setting this too high will waste
* memory, setting it too low will facilitate fragmentation.
*/
static const size_t ARENA_ALIGN = 16;
static constexpr size_t ARENA_ALIGN = 16;

/** Callback when allocation succeeds but locking fails.
*/
Expand Down
14 changes: 6 additions & 8 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,28 +154,26 @@ target_link_libraries(test_bitcoin
bitcoin_consensus
minisketch
secp256k1
Boost::headers
$<TARGET_NAME_IF_EXISTS:USDT::headers>
)

add_subdirectory(${PROJECT_SOURCE_DIR}/src/ipc/test ipc)

function(add_boost_test source_file)
function(register_test_suite source_file)
if(NOT EXISTS ${source_file})
return()
endif()

file(READ "${source_file}" source_file_content)
string(REGEX
MATCHALL "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(([A-Za-z0-9_]+)"
MATCHALL "TEST_SUITE_BEGIN\\(\"[A-Za-z0-9_]+\""
test_suite_macro "${source_file_content}"
)
list(TRANSFORM test_suite_macro
REPLACE "(BOOST_FIXTURE_TEST_SUITE|BOOST_AUTO_TEST_SUITE)\\(" ""
)
list(TRANSFORM test_suite_macro REPLACE "^TEST_SUITE_BEGIN\\(\"" "")
list(TRANSFORM test_suite_macro REPLACE "\"$" "")
foreach(test_suite_name IN LISTS test_suite_macro)
add_test(NAME ${test_suite_name}
COMMAND test_bitcoin --run_test=${test_suite_name} --catch_system_error=no --log_level=test_suite -- -printtoconsole=1
COMMAND test_bitcoin --run_test=${test_suite_name} -- -printtoconsole=1
)
set_property(TEST ${test_suite_name} PROPERTY
SKIP_REGULAR_EXPRESSION
Expand All @@ -194,7 +192,7 @@ function(add_all_test_targets)
if(result)
cmake_path(APPEND test_source_dir ${test_source} OUTPUT_VARIABLE test_source)
endif()
add_boost_test(${test_source})
register_test_suite(${test_source})
endforeach()
endfunction()

Expand Down
Loading
Loading