diff --git a/src/Makefile.am b/src/Makefile.am --- a/src/Makefile.am +++ b/src/Makefile.am @@ -681,3 +681,7 @@ if ENABLE_QT_TESTS include Makefile.qttest.include endif + +if BUILD_BITCOIN_SEEDER +include Makefile.seedertest.include +endif diff --git a/src/Makefile.seedertest.include b/src/Makefile.seedertest.include new file mode 100644 --- /dev/null +++ b/src/Makefile.seedertest.include @@ -0,0 +1,26 @@ +# Copyright (c) 2019 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +bin_PROGRAMS += seeder/test/test_bitcoin-seeder +TESTS += seeder/test/test_bitcoin-seeder + +seeder_test_test_bitcoin_seeder_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_SEEDER_INCLUDES) \ + $(SEEDER_INCLUDES) $(SEEDER_TEST_INCLUDES) $(TESTDEFS) + +seeder_test_test_bitcoin_seeder_SOURCES = \ + seeder/test/seeder_tests.cpp + +seeder_test_test_bitcoin_seeder_LDADD = $(LIBBITCOIN_SEEDER) +seeder_test_test_bitcoin_seeder_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBUNIVALUE) \ + $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) +seeder_test_test_bitcoin_seeder_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) +seeeder_test_test_bitcoin_seeder_CXXFLAGS = $(AM_CXXFLAGS) + +test_bitcoin_seeder : seeder/test/test_bitcoin-seeder$(EXEEXT) + +test_bitcoin_seeder_check : seeder/test/test_bitcoin-seeder$(EXEEXT) FORCE + $(MAKE) check-TESTS TESTS=$^ + +test_bitcoin_seeder_clean: FORCE + rm -f $(seeder_test_test_bitcoin_seeder_OBJECTS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -145,20 +145,12 @@ wallet/test/wallet_test_fixture.h endif -if BUILD_BITCOIN_SEEDER -BITCOIN_TESTS += \ - seeder/test/seeder_tests.cpp -endif - test_test_bitcoin_SOURCES = $(BITCOIN_TEST_SUITE) $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES) test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(EVENT_CFLAGS) test_test_bitcoin_LDADD = if ENABLE_WALLET test_test_bitcoin_LDADD += $(LIBBITCOIN_WALLET) endif -if BUILD_BITCOIN_SEEDER -test_test_bitcoin_LDADD += $(LIBBITCOIN_SEEDER) -endif test_test_bitcoin_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \ $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS) diff --git a/src/seeder/CMakeLists.txt b/src/seeder/CMakeLists.txt --- a/src/seeder/CMakeLists.txt +++ b/src/seeder/CMakeLists.txt @@ -2,16 +2,19 @@ project(bitcoin-seeder) -include_directories(.) - -add_executable(bitcoin-seeder - bitcoin.cpp - db.cpp - dns.cpp - main.cpp +add_library(seeder + bitcoin.cpp + db.cpp + dns.cpp ) -target_link_libraries(bitcoin-seeder common) +target_include_directories(seeder PUBLIC .) + +add_executable(bitcoin-seeder main.cpp) + +target_link_libraries(seeder + common +) include(BinaryTest) add_to_symbols_check(bitcoin-seeder) @@ -19,3 +22,5 @@ include(InstallationHelper) install_target(bitcoin-seeder) + +add_subdirectory(test) diff --git a/src/seeder/test/CMakeLists.txt b/src/seeder/test/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/seeder/test/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (c) 2019 The Bitcoin developers + +project(test_bitcoin-seeder) + +include(TestSuite) +create_test_suite(bitcoin-seeder-test) +add_dependencies(check check-bitcoin-seeder-test) + +add_test_to_suite(bitcoin-seeder-test test_bitcoin-seeder + seeder_tests.cpp +) + +find_package(Boost 1.58 REQUIRED unit_test_framework) + +target_link_libraries(test_bitcoin-seeder + Boost::unit_test_framework + seeder +) + +# We need to detect if the BOOST_TEST_DYN_LINK flag is required. +set(CMAKE_REQUIRED_LIBRARIES Boost::unit_test_framework) +check_cxx_source_compiles(" + #define BOOST_TEST_DYN_LINK + #define BOOST_TEST_MAIN + #include +" BOOST_TEST_DYN_LINK) + +if(BOOST_TEST_DYN_LINK) + target_compile_definitions(test_bitcoin-seeder PRIVATE BOOST_TEST_DYN_LINK) +endif(BOOST_TEST_DYN_LINK) diff --git a/src/seeder/test/seeder_tests.cpp b/src/seeder/test/seeder_tests.cpp --- a/src/seeder/test/seeder_tests.cpp +++ b/src/seeder/test/seeder_tests.cpp @@ -1,10 +1,10 @@ -// Copyright (c) 2016 The Bitcoin Core developers +// Copyright (c) 2019 The Bitcoin developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include +#define BOOST_TEST_MODULE Bitcoin Seeder Test Suite -#include +#include #include @@ -14,7 +14,7 @@ #include #include -BOOST_FIXTURE_TEST_SUITE(seeder_tests, BasicTestingSetup) +BOOST_AUTO_TEST_SUITE(seeder) const int BUFFER_LENGTH = 512; const int QNAME_BUFFER_LENGTH = 256; diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -183,10 +183,3 @@ ../wallet/test/coinselector_tests.cpp ) endif() - -if(BUILD_BITCOIN_SEEDER) - target_sources(test_bitcoin - PRIVATE - ../seeder/test/seeder_tests.cpp - ) -endif()