Move src/test/bitcoin-util-test.py to test/util/bitcoin-util-test.py

This commit is contained in:
John Newbery 2017-03-08 17:46:18 -05:00
parent 5b0bff4581
commit 63d66ba20a
61 changed files with 146 additions and 152 deletions

6
.gitignore vendored
View file

@ -101,9 +101,9 @@ coverage_percent.txt
linux-coverage-build
linux-build
win32-build
qa/pull-tester/tests_config.py
qa/pull-tester/tests_config.ini
qa/cache/*
test/functional/config.ini
test/util/buildenv.py
test/cache/*
!src/leveldb*/Makefile

View file

@ -225,8 +225,64 @@ dist_noinst_SCRIPTS = autogen.sh
EXTRA_DIST = $(top_srcdir)/share/genbuild.sh test/functional/test_runner.py test/functional $(DIST_CONTRIB) $(DIST_DOCS) $(WINDOWS_PACKAGING) $(OSX_PACKAGING) $(BIN_CHECKS)
EXTRA_DIST += \
test/util/bctest.py \
test/util/bitcoin-util-test.py \
test/util/data/bitcoin-util-test.json \
test/util/data/blanktxv1.hex \
test/util/data/blanktxv1.json \
test/util/data/blanktxv2.hex \
test/util/data/blanktxv2.json \
test/util/data/tt-delin1-out.hex \
test/util/data/tt-delin1-out.json \
test/util/data/tt-delout1-out.hex \
test/util/data/tt-delout1-out.json \
test/util/data/tt-locktime317000-out.hex \
test/util/data/tt-locktime317000-out.json \
test/util/data/tx394b54bb.hex \
test/util/data/txcreate1.hex \
test/util/data/txcreate1.json \
test/util/data/txcreate2.hex \
test/util/data/txcreate2.json \
test/util/data/txcreatedata1.hex \
test/util/data/txcreatedata1.json \
test/util/data/txcreatedata2.hex \
test/util/data/txcreatedata2.json \
test/util/data/txcreatedata_seq0.hex \
test/util/data/txcreatedata_seq0.json \
test/util/data/txcreatedata_seq1.hex \
test/util/data/txcreatedata_seq1.json \
test/util/data/txcreatemultisig1.hex \
test/util/data/txcreatemultisig1.json \
test/util/data/txcreatemultisig2.hex \
test/util/data/txcreatemultisig2.json \
test/util/data/txcreatemultisig3.hex \
test/util/data/txcreatemultisig3.json \
test/util/data/txcreatemultisig4.hex \
test/util/data/txcreatemultisig4.json \
test/util/data/txcreateoutpubkey1.hex \
test/util/data/txcreateoutpubkey1.json \
test/util/data/txcreateoutpubkey2.hex \
test/util/data/txcreateoutpubkey2.json \
test/util/data/txcreateoutpubkey3.hex \
test/util/data/txcreateoutpubkey3.json \
test/util/data/txcreatescript1.hex \
test/util/data/txcreatescript1.json \
test/util/data/txcreatescript2.hex \
test/util/data/txcreatescript2.json \
test/util/data/txcreatescript3.hex \
test/util/data/txcreatescript3.json \
test/util/data/txcreatescript4.hex \
test/util/data/txcreatescript4.json \
test/util/data/txcreatesignv1.hex \
test/util/data/txcreatesignv1.json \
test/util/data/txcreatesignv2.hex
CLEANFILES = $(OSX_DMG) $(BITCOIN_WIN_INSTALLER)
# This file is problematic for out-of-tree builds if it exists.
DISTCLEANFILES = test/util/buildenv.pyc
.INTERMEDIATE: $(COVERAGE_INFO)
DISTCHECK_CONFIGURE_FLAGS = --enable-man

View file

@ -1147,9 +1147,12 @@ AC_SUBST(EVENT_PTHREADS_LIBS)
AC_SUBST(ZMQ_LIBS)
AC_SUBST(PROTOBUF_LIBS)
AC_SUBST(QR_LIBS)
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist src/test/buildenv.py test/functional/config.ini])
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/functional/config.ini])
AC_CONFIG_FILES([test/util/buildenv.py],[chmod +x test/util/buildenv.py])
AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
AC_CONFIG_LINKS([test/functional/test_runner.py:test/functional/test_runner.py])
AC_CONFIG_LINKS([test/util/bitcoin-util-test.py:test/util/bitcoin-util-test.py])
AC_CONFIG_LINKS([test/util/bctest.py:test/util/bctest.py])
dnl boost's m4 checks do something really nasty: they export these vars. As a
dnl result, they leak into secp256k1's configure and crazy things happen.
@ -1197,8 +1200,8 @@ esac
dnl Replace the BUILDDIR path with the correct Windows path if compiling on Native Windows
case ${OS} in
*Windows*)
sed 's/BUILDDIR="\/\([[a-z]]\)/BUILDDIR="\1:/' test/pull-tester/tests_config.py > test/pull-tester/tests_config-2.py
mv test/pull-tester/tests_config-2.py test/pull-tester/tests_config.py
sed 's/BUILDDIR="\/\([[a-z]]\)/BUILDDIR="\1:/' test/functional/config.ini > test/functional/config-2.ini
mv test/functional/config-2.ini test/functional/config.ini
;;
esac

View file

@ -311,9 +311,7 @@ rm -f %{buildroot}%{_bindir}/test_*
%check
make check
pushd src
srcdir=. test/bitcoin-util-test.py
popd
srcdir=src test/bitcoin-util-test.py
test/functional/test_runner.py --extended
%post libs -p /sbin/ldconfig

View file

@ -8,60 +8,6 @@ noinst_PROGRAMS += test/test_bitcoin_fuzzy
TEST_SRCDIR = test
TEST_BINARY=test/test_bitcoin$(EXEEXT)
EXTRA_DIST += \
test/bctest.py \
test/bitcoin-util-test.py \
test/data/bitcoin-util-test.json \
test/data/blanktxv1.hex \
test/data/blanktxv1.json \
test/data/blanktxv2.hex \
test/data/blanktxv2.json \
test/data/tt-delin1-out.hex \
test/data/tt-delin1-out.json \
test/data/tt-delout1-out.hex \
test/data/tt-delout1-out.json \
test/data/tt-locktime317000-out.hex \
test/data/tt-locktime317000-out.json \
test/data/tx394b54bb.hex \
test/data/txcreate1.hex \
test/data/txcreate1.json \
test/data/txcreate2.hex \
test/data/txcreate2.json \
test/data/txcreatedata1.hex \
test/data/txcreatedata1.json \
test/data/txcreatedata2.hex \
test/data/txcreatedata2.json \
test/data/txcreatedata_seq0.hex \
test/data/txcreatedata_seq0.json \
test/data/txcreatedata_seq1.hex \
test/data/txcreatedata_seq1.json \
test/data/txcreatemultisig1.hex \
test/data/txcreatemultisig1.json \
test/data/txcreatemultisig2.hex \
test/data/txcreatemultisig2.json \
test/data/txcreatemultisig3.hex \
test/data/txcreatemultisig3.json \
test/data/txcreatemultisig4.hex \
test/data/txcreatemultisig4.json \
test/data/txcreateoutpubkey1.hex \
test/data/txcreateoutpubkey1.json \
test/data/txcreateoutpubkey2.hex \
test/data/txcreateoutpubkey2.json \
test/data/txcreateoutpubkey3.hex \
test/data/txcreateoutpubkey3.json \
test/data/txcreatescript1.hex \
test/data/txcreatescript1.json \
test/data/txcreatescript2.hex \
test/data/txcreatescript2.json \
test/data/txcreatescript3.hex \
test/data/txcreatescript3.json \
test/data/txcreatescript4.hex \
test/data/txcreatescript4.json \
test/data/txcreatesignv1.hex \
test/data/txcreatesignv1.json \
test/data/txcreatesignv2.hex
JSON_TEST_FILES = \
test/data/script_tests.json \
test/data/base58_keys_valid.json \
@ -191,9 +137,6 @@ CLEAN_BITCOIN_TEST = test/*.gcda test/*.gcno $(GENERATED_TEST_FILES)
CLEANFILES += $(CLEAN_BITCOIN_TEST)
# This file is problematic for out-of-tree builds if it exists.
DISTCLEANFILES += test/buildenv.pyc
bitcoin_test: $(TEST_BINARY)
bitcoin_test_check: $(TEST_BINARY) FORCE
@ -203,8 +146,8 @@ bitcoin_test_clean : FORCE
rm -f $(CLEAN_BITCOIN_TEST) $(test_test_bitcoin_OBJECTS) $(TEST_BINARY)
check-local:
@echo "Running test/bitcoin-util-test.py..."
$(AM_V_at)srcdir=$(srcdir) PYTHONPATH=$(builddir)/test $(PYTHON) $(srcdir)/test/bitcoin-util-test.py
@echo "Running test/util/bitcoin-util-test.py..."
$(PYTHON) $(top_builddir)/test/util/bitcoin-util-test.py
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C secp256k1 check
if EMBEDDED_UNIVALUE
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C univalue check

View file

@ -50,12 +50,3 @@ examine `uint256_tests.cpp`.
For further reading, I found the following website to be helpful in
explaining how the boost unit test framework works:
[http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/](http://www.alittlemadness.com/2009/03/31/c-unit-testing-with-boosttest/).
### bitcoin-util-test.py
The test directory also contains the bitcoin-util-test.py tool, which tests bitcoin utils (currently just bitcoin-tx). This test gets run automatically during the `make check` build process. It is also possible to run the test manually from the src directory:
```
test/bitcoin-util-test.py --srcdir=[current directory]
```

View file

@ -1,45 +0,0 @@
#!/usr/bin/env python
# Copyright 2014 BitPay Inc.
# Copyright 2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
from __future__ import division,print_function,unicode_literals
import os
import bctest
import buildenv
import argparse
import logging
help_text="""Test framework for bitcoin utils.
Runs automatically during `make check`.
Can also be run manually from the src directory by specifying the source directory:
test/bitcoin-util-test.py --srcdir='srcdir' [--verbose]
"""
if __name__ == '__main__':
# Try to get the source directory from the environment variables. This will
# be set for `make check` automated runs. If environment variable is not set,
# then get the source directory from command line args.
try:
srcdir = os.environ["srcdir"]
verbose = False
except:
parser = argparse.ArgumentParser(description=help_text)
parser.add_argument('-s', '--srcdir')
parser.add_argument('-v', '--verbose', action='store_true')
args = parser.parse_args()
srcdir = args.srcdir
verbose = args.verbose
if verbose:
level = logging.DEBUG
else:
level = logging.ERROR
formatter = '%(asctime)s - %(levelname)s - %(message)s'
# Add the format/level to the logger
logging.basicConfig(format = formatter, level=level)
bctest.bctester(srcdir + "/test/data", "bitcoin-util-test.json", buildenv)

View file

@ -1,2 +0,0 @@
#!/usr/bin/env python
exeext="@EXEEXT@"

View file

@ -1,29 +1,32 @@
The [functional](/test/functional/) folder contains a script test_runner
to call multiple functional tests from its folder.
This directory contains integration tests that test bitcoind and its
utilities in their entirety. It does not contain unit tests, which
can be found in [/src/test](/src/test), [/src/wallet/test](/src/wallet/test),
etc.
Every pull request to the bitcoin repository is built and run through
the regression test suite. You can also run all or only individual
tests locally.
There are currently two sets of tests in this directory:
Test dependencies
=================
Before running the tests, the following must be installed.
- [functional](/test/functional) which test the functionality of
bitcoind and bitcoin-qt by interacting with them through the RPC and P2P
interfaces.
- [util](test/util) which tests the bitcoin utilities, currently only
bitcoin-tx.
Unix
----
The python3-zmq library is required. On Ubuntu or Debian it can be installed via:
```
sudo apt-get install python3-zmq
```
The util tests are run as part of `make check` target. The functional
tests are run by the travis continuous build process whenever a pull
request is opened. Both sets of tests can also be run locally.
OS X
------
```
pip3 install pyzmq
```
Functional Test dependencies
============================
The ZMQ functional test requires a python ZMQ library. To install it:
Running tests
=============
- on Unix, run `sudo apt-get install python3-zmq`
- on mac OS, run `pip3 install pyzmq`
Running tests locally
=====================
Functional tests
----------------
You can run any single test by calling
@ -80,8 +83,15 @@ rm -rf cache
killall bitcoind
```
Writing tests
=============
You are encouraged to write tests for new or existing features.
Further information about the test framework and individual functional
Util tests
----------
Util tests can be run locally by running `test/util/bitcoin-util-test.py`.
Use the `-v` option for verbose output.
Writing functional tests
========================
You are encouraged to write functional tests for new or existing features.
Further information about the functional test framework and individual
tests is found in [test/functional](/test/functional).

View file

@ -23,14 +23,14 @@ def parse_output(a, fmt):
else:
raise NotImplementedError("Don't know how to compare %s" % fmt)
def bctest(testDir, testObj, exeext):
def bctest(testDir, testObj, buildenv):
"""Runs a single test, comparing output and RC to expected output and RC.
Raises an error if input can't be read, executable fails, or output/RC
are not as expected. Error is caught by bctester() and reported.
"""
# Get the exec names and arguments
execprog = testObj['exec'] + exeext
execprog = buildenv.BUILDDIR + "/src/" + testObj['exec'] + buildenv.exeext
execargs = testObj['args']
execrun = [execprog] + execargs
@ -112,7 +112,7 @@ def bctester(testDir, input_basename, buildenv):
for testObj in input_data:
try:
bctest(testDir, testObj, buildenv.exeext)
bctest(testDir, testObj, buildenv)
logging.info("PASSED: " + testObj["description"])
except:
logging.info("FAILED: " + testObj["description"])

36
test/util/bitcoin-util-test.py Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python
# Copyright 2014 BitPay Inc.
# Copyright 2016 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
from __future__ import division,print_function,unicode_literals
import os
import sys
import argparse
import logging
help_text="""Test framework for bitcoin utils.
Runs automatically during `make check`.
Can also be run manually."""
if __name__ == '__main__':
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import buildenv
import bctest
parser = argparse.ArgumentParser(description=help_text)
parser.add_argument('-v', '--verbose', action='store_true')
args = parser.parse_args()
verbose = args.verbose
if verbose:
level = logging.DEBUG
else:
level = logging.ERROR
formatter = '%(asctime)s - %(levelname)s - %(message)s'
# Add the format/level to the logger
logging.basicConfig(format = formatter, level=level)
bctest.bctester(buildenv.SRCDIR + "/test/util/data", "bitcoin-util-test.json", buildenv)

4
test/util/buildenv.py.in Normal file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env python
exeext="@EXEEXT@"
SRCDIR="@abs_top_srcdir@"
BUILDDIR="@abs_top_builddir@"