Merge #12063: [Trivial] Update license year range to 2018
[bitcoinplatinum.git] / test / README.md
blob868eb667ae206e1509e3f4043639706136af2ce6
1 This directory contains integration tests that test bitcoind and its
2 utilities in their entirety. It does not contain unit tests, which
3 can be found in [/src/test](/src/test), [/src/wallet/test](/src/wallet/test),
4 etc.
6 There are currently two sets of tests in this directory:
8 - [functional](/test/functional) which test the functionality of 
9 bitcoind and bitcoin-qt by interacting with them through the RPC and P2P
10 interfaces.
11 - [util](test/util) which tests the bitcoin utilities, currently only
12 bitcoin-tx.
14 The util tests are run as part of `make check` target. The functional
15 tests are run by the travis continuous build process whenever a pull
16 request is opened. Both sets of tests can also be run locally.
18 # Running tests locally
20 Build for your system first. Be sure to enable wallet, utils and daemon when you configure. Tests will not run otherwise.
22 ### Functional tests
24 #### Dependencies
26 The ZMQ functional test requires a python ZMQ library. To install it:
28 - on Unix, run `sudo apt-get install python3-zmq`
29 - on mac OS, run `pip3 install pyzmq`
31 #### Running the tests
33 Individual tests can be run by directly calling the test script, eg:
35 ```
36 test/functional/replace-by-fee.py
37 ```
39 or can be run through the test_runner harness, eg:
41 ```
42 test/functional/test_runner.py replace-by-fee.py
43 ```
45 You can run any combination (incl. duplicates) of tests by calling:
47 ```
48 test/functional/test_runner.py <testname1> <testname2> <testname3> ...
49 ```
51 Run the regression test suite with:
53 ```
54 test/functional/test_runner.py
55 ```
57 Run all possible tests with
59 ```
60 test/functional/test_runner.py --extended
61 ```
63 By default, up to 4 tests will be run in parallel by test_runner. To specify
64 how many jobs to run, append `--jobs=n`
66 The individual tests and the test_runner harness have many command-line
67 options. Run `test_runner.py -h` to see them all.
69 #### Troubleshooting and debugging test failures
71 ##### Resource contention
73 The P2P and RPC ports used by the bitcoind nodes-under-test are chosen to make
74 conflicts with other processes unlikely. However, if there is another bitcoind
75 process running on the system (perhaps from a previous test which hasn't successfully
76 killed all its bitcoind nodes), then there may be a port conflict which will
77 cause the test to fail. It is recommended that you run the tests on a system
78 where no other bitcoind processes are running.
80 On linux, the test_framework will warn if there is another
81 bitcoind process running when the tests are started.
83 If there are zombie bitcoind processes after test failure, you can kill them
84 by running the following commands. **Note that these commands will kill all
85 bitcoind processes running on the system, so should not be used if any non-test
86 bitcoind processes are being run.**
88 ```bash
89 killall bitcoind
90 ```
94 ```bash
95 pkill -9 bitcoind
96 ```
99 ##### Data directory cache
101 A pre-mined blockchain with 200 blocks is generated the first time a
102 functional test is run and is stored in test/cache. This speeds up
103 test startup times since new blockchains don't need to be generated for
104 each test. However, the cache may get into a bad state, in which case
105 tests will fail. If this happens, remove the cache directory (and make
106 sure bitcoind processes are stopped as above):
108 ```bash
109 rm -rf cache
110 killall bitcoind
113 ##### Test logging
115 The tests contain logging at different levels (debug, info, warning, etc). By
116 default:
118 - when run through the test_runner harness, *all* logs are written to
119   `test_framework.log` and no logs are output to the console.
120 - when run directly, *all* logs are written to `test_framework.log` and INFO
121   level and above are output to the console.
122 - when run on Travis, no logs are output to the console. However, if a test
123   fails, the `test_framework.log` and bitcoind `debug.log`s will all be dumped
124   to the console to help troubleshooting.
126 To change the level of logs output to the console, use the `-l` command line
127 argument.
129 `test_framework.log` and bitcoind `debug.log`s can be combined into a single
130 aggregate log by running the `combine_logs.py` script. The output can be plain
131 text, colorized text or html. For example:
134 combine_logs.py -c <test data directory> | less -r
137 will pipe the colorized logs from the test into less.
139 Use `--tracerpc` to trace out all the RPC calls and responses to the console. For
140 some tests (eg any that use `submitblock` to submit a full block over RPC),
141 this can result in a lot of screen output.
143 By default, the test data directory will be deleted after a successful run.
144 Use `--nocleanup` to leave the test data directory intact. The test data
145 directory is never deleted after a failed test.
147 ##### Attaching a debugger
149 A python debugger can be attached to tests at any point. Just add the line:
151 ```py
152 import pdb; pdb.set_trace()
155 anywhere in the test. You will then be able to inspect variables, as well as
156 call methods that interact with the bitcoind nodes-under-test.
158 If further introspection of the bitcoind instances themselves becomes
159 necessary, this can be accomplished by first setting a pdb breakpoint
160 at an appropriate location, running the test to that point, then using
161 `gdb` to attach to the process and debug.
163 For instance, to attach to `self.node[1]` during a run:
165 ```bash
166 2017-06-27 14:13:56.686000 TestFramework (INFO): Initializing test directory /tmp/user/1000/testo9vsdjo3
169 use the directory path to get the pid from the pid file:
171 ```bash
172 cat /tmp/user/1000/testo9vsdjo3/node1/regtest/bitcoind.pid
173 gdb /home/example/bitcoind <pid>
176 Note: gdb attach step may require `sudo`
178 ### Util tests
180 Util tests can be run locally by running `test/util/bitcoin-util-test.py`. 
181 Use the `-v` option for verbose output.
183 # Writing functional tests
185 You are encouraged to write functional tests for new or existing features.
186 Further information about the functional test framework and individual 
187 tests is found in [test/functional](/test/functional).