Skip to content

Commit dd1ca9e

Browse files
committed
Merge #12926: Run unit tests in parallel
7ef9cd8 Increase entropy in test temp directory name (Pieter Wuille) f6dfb0f Reorder travis builds (Pieter Wuille) 156db42 tests: run tests in parallel (Cory Fields) 66f3255 tests: split up actual tests and helper files (Cory Fields) Pull request description: This runs the unit tests (`src/test/test_bitcoin`) in 4 separate simultaneous processes, significantly speeding up some Travis runs (over 2x for win32). This uses an approach by @theuni that relies on `make` as the mechanism for distributing tests over processes (through `-j`). For every test .cpp file, we search for `BOOST_FIXTURE_TEST_SUITE` or `BOOST_AUTO_TEST_SUITE`, and then invoke the test binary for just that suite (using `-t`). The (verbose) output is stored in a temporary file, and only shown in the case of failure. Some makefile reshuffling is necessary to avoid trying to run tests from `src/test/test_bitcoin.cpp` for example, which contains framework/utility code but no real tests. Finally, order the Travis jobs from slow to fast (apart from the arm/doc job which goes first, for fast failure). This should help reducing the total wall clock time before opening a PR and finishing Travis, in case where not all jobs are started simultaneously. This is an alternative to #12831. Tree-SHA512: 9f82eb4ade14ac859618da533c7d9df2aa9f5592a076dcc4939beeffd109eda33f7d5480d8f50c0d8b23bf3099759e9f3a2d4c78efb5b66b04569b39b354c185
2 parents 727175a + 7ef9cd8 commit dd1ca9e

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ env:
2525
- HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf python3-pip" DEP_OPTS="NO_QT=1" CHECK_DOC=1 GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports"
2626
# Win32
2727
- HOST=i686-w64-mingw32 DPKG_ADD_ARCH="i386" DEP_OPTS="NO_QT=1" PACKAGES="python3 nsis g++-mingw-w64-i686 wine1.6" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-reduce-exports"
28-
# Qt4 & system libs
29-
- HOST=x86_64-unknown-linux-gnu PACKAGES="python3-zmq qt4-dev-tools libssl-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev libdb5.1++-dev libminiupnpc-dev libzmq3-dev libprotobuf-dev protobuf-compiler libqrencode-dev xvfb" NO_DEPENDS=1 NEED_XVFB=1 RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --enable-glibc-back-compat --enable-reduce-exports --with-gui=qt4 CPPFLAGS=-DDEBUG_LOCKORDER"
30-
# 32-bit + dash
31-
- HOST=i686-pc-linux-gnu PACKAGES="g++-multilib python3-zmq" DEP_OPTS="NO_QT=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash"
3228
# Win64
3329
- HOST=x86_64-w64-mingw32 DPKG_ADD_ARCH="i386" DEP_OPTS="NO_QT=1" PACKAGES="python3 nsis g++-mingw-w64-x86-64 wine1.6" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-reduce-exports"
30+
# 32-bit + dash
31+
- HOST=i686-pc-linux-gnu PACKAGES="g++-multilib python3-zmq" DEP_OPTS="NO_QT=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --enable-glibc-back-compat --enable-reduce-exports LDFLAGS=-static-libstdc++" USE_SHELL="/bin/dash"
3432
# x86_64 Linux (uses qt5 dev package instead of depends Qt to speed up build and avoid timeout)
3533
- HOST=x86_64-unknown-linux-gnu PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools protobuf-compiler libdbus-1-dev libharfbuzz-dev" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-glibc-back-compat --enable-reduce-exports CPPFLAGS=-DDEBUG_LOCKORDER"
34+
# Qt4 & system libs
35+
- HOST=x86_64-unknown-linux-gnu PACKAGES="python3-zmq qt4-dev-tools libssl-dev libevent-dev bsdmainutils libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev libdb5.1++-dev libminiupnpc-dev libzmq3-dev libprotobuf-dev protobuf-compiler libqrencode-dev xvfb" NO_DEPENDS=1 NEED_XVFB=1 RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --enable-glibc-back-compat --enable-reduce-exports --with-gui=qt4 CPPFLAGS=-DDEBUG_LOCKORDER"
3636
# x86_64 Linux, No wallet
3737
- HOST=x86_64-unknown-linux-gnu PACKAGES="python3" DEP_OPTS="NO_WALLET=1" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports"
3838
# Cross-Mac

src/Makefile.test.include

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Distributed under the MIT software license, see the accompanying
33
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
TESTS += test/test_bitcoin
65
bin_PROGRAMS += test/test_bitcoin
76
noinst_PROGRAMS += test/test_bitcoin_fuzzy
87
TEST_SRCDIR = test
@@ -21,6 +20,11 @@ RAW_TEST_FILES =
2120

2221
GENERATED_TEST_FILES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h)
2322

23+
BITCOIN_TEST_SUITE = \
24+
test/test_bitcoin_main.cpp \
25+
test/test_bitcoin.h \
26+
test/test_bitcoin.cpp
27+
2428
# test_bitcoin binary #
2529
BITCOIN_TESTS =\
2630
test/arith_uint256_tests.cpp \
@@ -76,9 +80,6 @@ BITCOIN_TESTS =\
7680
test/sigopcount_tests.cpp \
7781
test/skiplist_tests.cpp \
7882
test/streams_tests.cpp \
79-
test/test_bitcoin.cpp \
80-
test/test_bitcoin.h \
81-
test/test_bitcoin_main.cpp \
8283
test/timedata_tests.cpp \
8384
test/torcontrol_tests.cpp \
8485
test/transaction_tests.cpp \
@@ -90,15 +91,17 @@ BITCOIN_TESTS =\
9091

9192
if ENABLE_WALLET
9293
BITCOIN_TESTS += \
93-
wallet/test/wallet_test_fixture.cpp \
94-
wallet/test/wallet_test_fixture.h \
9594
wallet/test/accounting_tests.cpp \
9695
wallet/test/wallet_tests.cpp \
9796
wallet/test/wallet_crypto_tests.cpp \
9897
wallet/test/coinselector_tests.cpp
98+
99+
BITCOIN_TEST_SUITE += \
100+
wallet/test/wallet_test_fixture.cpp \
101+
wallet/test/wallet_test_fixture.h
99102
endif
100103

101-
test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
104+
test_test_bitcoin_SOURCES = $(BITCOIN_TEST_SUITE) $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES)
102105
test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(TESTDEFS) $(EVENT_CFLAGS)
103106
test_test_bitcoin_LDADD =
104107
if ENABLE_WALLET
@@ -150,14 +153,18 @@ bitcoin_test_check: $(TEST_BINARY) FORCE
150153
bitcoin_test_clean : FORCE
151154
rm -f $(CLEAN_BITCOIN_TEST) $(test_test_bitcoin_OBJECTS) $(TEST_BINARY)
152155

153-
check-local:
156+
check-local: $(BITCOIN_TESTS:.cpp=.cpp.test)
154157
@echo "Running test/util/bitcoin-util-test.py..."
155158
$(PYTHON) $(top_builddir)/test/util/bitcoin-util-test.py
156159
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check
157160
if EMBEDDED_UNIVALUE
158161
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C univalue check
159162
endif
160163

164+
%.cpp.test: %.cpp
165+
@echo Running tests: `cat $< | grep "BOOST_FIXTURE_TEST_SUITE(\|BOOST_AUTO_TEST_SUITE(" | cut -d '(' -f 2 | cut -d ',' -f 1 | cut -d ')' -f 1` from $<
166+
$(AM_V_at)$(TEST_BINARY) -l test_suite -t "`cat $< | grep "BOOST_FIXTURE_TEST_SUITE(\|BOOST_AUTO_TEST_SUITE(" | cut -d '(' -f 2 | cut -d ',' -f 1 | cut -d ')' -f 1`" > $<.log 2>&1 || (cat $<.log && false)
167+
161168
%.json.h: %.json
162169
@$(MKDIR_P) $(@D)
163170
@{ \

src/test/test_bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
6666

6767
RegisterAllCoreRPCCommands(tableRPC);
6868
ClearDatadirCache();
69-
pathTemp = fs::temp_directory_path() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(100000)));
69+
pathTemp = fs::temp_directory_path() / strprintf("test_bitcoin_%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(1 << 30)));
7070
fs::create_directories(pathTemp);
7171
gArgs.ForceSetArg("-datadir", pathTemp.string());
7272

0 commit comments

Comments
 (0)