included-tests: generate binary data from test files for inclusion into test binaries

This change moves test data into the binaries rather than reading them from
the disk at runtime.

Advantages:
- Tests become distributable
- Cross-compile friendly. Build on one machine and execute in an arbitrary
  location on another.
- Easier testing for backports. Users can verify that tests pass without having
  to track down corresponding test data.
- More trustworthy test results and easier quality assurance as tests make
  fewer assumptions about their environment.
- Tests could theoretically run at client/daemon startup and exit on failure.

Disadvantages:
- Required 'hexdump' build-dependency. This is a standard bsd tool that should
  be usable everywhere. It is likely already installed on all build-machines.
- Tests can no longer be fudged after build by altering test-data.
This commit is contained in:
Cory Fields
2013-09-10 15:18:09 -04:00
parent 08081e393b
commit 152e51c7af
11 changed files with 76 additions and 72 deletions

View File

@@ -10,19 +10,20 @@ bin_PROGRAMS = test_bitcoin
TESTS = test_bitcoin
TEST_DATA_DIR=$(srcdir)/data
JSON_TEST_FILES= data/script_valid.json \
data/base58_keys_valid.json data/sig_canonical.json \
data/sig_noncanonical.json \
data/base58_encode_decode.json \
data/base58_keys_invalid.json \
data/script_invalid.json data/tx_invalid.json \
data/tx_valid.json
TEST_DATA_FILES= $(TEST_DATA_DIR)/script_valid.json \
$(TEST_DATA_DIR)/base58_keys_valid.json $(TEST_DATA_DIR)/sig_canonical.json \
$(TEST_DATA_DIR)/sig_noncanonical.json \
$(TEST_DATA_DIR)/base58_encode_decode.json $(TEST_DATA_DIR)/alertTests \
$(TEST_DATA_DIR)/base58_keys_invalid.json \
$(TEST_DATA_DIR)/script_invalid.json $(TEST_DATA_DIR)/tx_invalid.json \
$(TEST_DATA_DIR)/tx_valid.json
RAW_TEST_FILES = data/alertTests.raw
BUILT_SOURCES = $(JSON_TEST_FILES:.json=.json.h) $(RAW_TEST_FILES:.raw=.raw.h)
# test_bitcoin binary #
test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(TESTDEFS) \
-DTEST_DATA_DIR=$(abs_srcdir)/data
test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(TESTDEFS)
test_bitcoin_LDADD = $(LIBBITCOIN) $(LIBLEVELDB) $(LIBMEMENV) \
$(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB)
test_bitcoin_SOURCES = accounting_tests.cpp alert_tests.cpp \
@@ -33,6 +34,8 @@ test_bitcoin_SOURCES = accounting_tests.cpp alert_tests.cpp \
netbase_tests.cpp pmt_tests.cpp rpc_tests.cpp script_P2SH_tests.cpp \
script_tests.cpp serialize_tests.cpp sigopcount_tests.cpp test_bitcoin.cpp \
transaction_tests.cpp uint160_tests.cpp uint256_tests.cpp util_tests.cpp \
wallet_tests.cpp $(TEST_DATA_FILES)
wallet_tests.cpp $(JSON_TEST_FILES) $(RAW_TEST_FILES)
CLEANFILES = *.gcda *.gcno
nodist_test_bitcoin_SOURCES = $(BUILT_SOURCES)
CLEANFILES = *.gcda *.gcno $(BUILT_SOURCES)