Skip to content

Commit e074097

Browse files
committed
Merge #13051: qa: Normalize executable location
fa811b0 qa: Normalize executable location (MarcoFalke) Pull request description: This removes the need to override the executable locations by just reading them from the config file. Beside making the code easier to read, running individual test on Windows is now possible by default (without providing further command line arguments). Note: Of course, it is still possible to manually specify the location through the `BITCOIND` environment variable, e.g. `bitcoin-qt`. Tree-SHA512: bee6d22246796242d747120ca18aaab089f73067de213c9111182561985c5912228a0b0f7f9eec025ecfdb44db031f15652f30d67c489d481c995bb3232a7ac7
2 parents a0079d4 + fa811b0 commit e074097

File tree

5 files changed

+21
-30
lines changed

5 files changed

+21
-30
lines changed

test/functional/interface_zmq.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the ZMQ notification interface."""
66
import configparser
7-
import os
87
import struct
98

109
from test_framework.test_framework import BitcoinTestFramework, SkipTest
@@ -47,8 +46,6 @@ def setup_nodes(self):
4746

4847
# Check that bitcoin has been built with ZMQ enabled.
4948
config = configparser.ConfigParser()
50-
if not self.options.configfile:
51-
self.options.configfile = os.path.abspath(os.path.join(os.path.dirname(__file__), "../config.ini"))
5249
config.read_file(open(self.options.configfile))
5350

5451
if not config["components"].getboolean("ENABLE_ZMQ"):

test/functional/p2p_unrequested_blocks.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@
5757
import time
5858
from test_framework.blocktools import create_block, create_coinbase, create_transaction
5959

60-
class AcceptBlockTest(BitcoinTestFramework):
61-
def add_options(self, parser):
62-
parser.add_option("--testbinary", dest="testbinary",
63-
default=os.getenv("BITCOIND", "bitcoind"),
64-
help="bitcoind binary to test")
6560

61+
class AcceptBlockTest(BitcoinTestFramework):
6662
def set_test_params(self):
6763
self.setup_clean_chain = True
6864
self.num_nodes = 2

test/functional/test_framework/test_framework.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Base class for RPC testing."""
66

7+
import configparser
78
from enum import Enum
89
import logging
910
import optparse
@@ -97,10 +98,10 @@ def main(self):
9798
help="Leave bitcoinds and test.* datadir on exit or error")
9899
parser.add_option("--noshutdown", dest="noshutdown", default=False, action="store_true",
99100
help="Don't stop bitcoinds after the test execution")
100-
parser.add_option("--srcdir", dest="srcdir", default=os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../../../src"),
101+
parser.add_option("--srcdir", dest="srcdir", default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../../src"),
101102
help="Source directory containing bitcoind/bitcoin-cli (default: %default)")
102-
parser.add_option("--cachedir", dest="cachedir", default=os.path.normpath(os.path.dirname(os.path.realpath(__file__)) + "/../../cache"),
103-
help="Directory for caching pregenerated datadirs")
103+
parser.add_option("--cachedir", dest="cachedir", default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../cache"),
104+
help="Directory for caching pregenerated datadirs (default: %default)")
104105
parser.add_option("--tmpdir", dest="tmpdir", help="Root directory for datadirs")
105106
parser.add_option("-l", "--loglevel", dest="loglevel", default="INFO",
106107
help="log events at this level and higher to the console. Can be set to DEBUG, INFO, WARNING, ERROR or CRITICAL. Passing --loglevel DEBUG will output all logs to console. Note that logs at all levels are always written to the test_framework.log file in the temporary test directory.")
@@ -111,7 +112,8 @@ def main(self):
111112
parser.add_option("--coveragedir", dest="coveragedir",
112113
help="Write tested RPC commands into this directory")
113114
parser.add_option("--configfile", dest="configfile",
114-
help="Location of the test framework config file")
115+
default=os.path.abspath(os.path.dirname(os.path.realpath(__file__)) + "/../../config.ini"),
116+
help="Location of the test framework config file (default: %default)")
115117
parser.add_option("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true",
116118
help="Attach a python debugger if test fails")
117119
parser.add_option("--usecli", dest="usecli", default=False, action="store_true",
@@ -129,6 +131,11 @@ def main(self):
129131

130132
self.options.cachedir = os.path.abspath(self.options.cachedir)
131133

134+
config = configparser.ConfigParser()
135+
config.read_file(open(self.options.configfile))
136+
self.options.bitcoind = os.getenv("BITCOIND", default=config["environment"]["BUILDDIR"] + '/src/bitcoind' + config["environment"]["EXEEXT"])
137+
self.options.bitcoincli = os.getenv("BITCOINCLI", default=config["environment"]["BUILDDIR"] + '/src/bitcoin-cli' + config["environment"]["EXEEXT"])
138+
132139
# Set up temp directory and start logging
133140
if self.options.tmpdir:
134141
self.options.tmpdir = os.path.abspath(self.options.tmpdir)
@@ -246,12 +253,12 @@ def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, bin
246253
if extra_args is None:
247254
extra_args = [[]] * num_nodes
248255
if binary is None:
249-
binary = [None] * num_nodes
256+
binary = [self.options.bitcoind] * num_nodes
250257
assert_equal(len(extra_confs), num_nodes)
251258
assert_equal(len(extra_args), num_nodes)
252259
assert_equal(len(binary), num_nodes)
253260
for i in range(num_nodes):
254-
self.nodes.append(TestNode(i, get_datadir_path(self.options.tmpdir, i), rpchost=rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli))
261+
self.nodes.append(TestNode(i, get_datadir_path(self.options.tmpdir, i), rpchost=rpchost, timewait=timewait, bitcoind=binary[i], bitcoin_cli=self.options.bitcoincli, stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir, extra_conf=extra_confs[i], extra_args=extra_args[i], use_cli=self.options.usecli))
255262

256263
def start_node(self, i, *args, **kwargs):
257264
"""Start a bitcoind"""
@@ -399,10 +406,10 @@ def _initialize_chain(self):
399406
# Create cache directories, run bitcoinds:
400407
for i in range(MAX_NODES):
401408
datadir = initialize_datadir(self.options.cachedir, i)
402-
args = [os.getenv("BITCOIND", "bitcoind"), "-datadir=" + datadir]
409+
args = [self.options.bitcoind, "-datadir=" + datadir]
403410
if i > 0:
404411
args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
405-
self.nodes.append(TestNode(i, get_datadir_path(self.options.cachedir, i), extra_conf=["bind=127.0.0.1"], extra_args=[],rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
412+
self.nodes.append(TestNode(i, get_datadir_path(self.options.cachedir, i), extra_conf=["bind=127.0.0.1"], extra_args=[], rpchost=None, timewait=None, bitcoind=self.options.bitcoind, bitcoin_cli=self.options.bitcoincli, stderr=None, mocktime=self.mocktime, coverage_dir=None))
406413
self.nodes[i].args = args
407414
self.start_node(i)
408415

test/functional/test_framework/test_node.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import http.client
1111
import json
1212
import logging
13-
import os
1413
import re
1514
import subprocess
1615
import tempfile
@@ -56,7 +55,7 @@ class TestNode():
5655
To make things easier for the test writer, any unrecognised messages will
5756
be dispatched to the RPC connection."""
5857

59-
def __init__(self, i, datadir, rpchost, timewait, binary, stderr, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False):
58+
def __init__(self, i, datadir, rpchost, timewait, bitcoind, bitcoin_cli, stderr, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False):
6059
self.index = i
6160
self.datadir = datadir
6261
self.rpchost = rpchost
@@ -65,10 +64,7 @@ def __init__(self, i, datadir, rpchost, timewait, binary, stderr, mocktime, cove
6564
else:
6665
# Wait for up to 60 seconds for the RPC server to respond
6766
self.rpc_timeout = 60
68-
if binary is None:
69-
self.binary = os.getenv("BITCOIND", "bitcoind")
70-
else:
71-
self.binary = binary
67+
self.binary = bitcoind
7268
self.stderr = stderr
7369
self.coverage_dir = coverage_dir
7470
if extra_conf != None:
@@ -89,7 +85,7 @@ def __init__(self, i, datadir, rpchost, timewait, binary, stderr, mocktime, cove
8985
"-noprinttoconsole"
9086
]
9187

92-
self.cli = TestNodeCLI(os.getenv("BITCOINCLI", "bitcoin-cli"), self.datadir)
88+
self.cli = TestNodeCLI(bitcoin_cli, self.datadir)
9389
self.use_cli = use_cli
9490

9591
self.running = False

test/functional/test_runner.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,9 @@ def main():
283283
if not args.keepcache:
284284
shutil.rmtree("%s/test/cache" % config["environment"]["BUILDDIR"], ignore_errors=True)
285285

286-
run_tests(test_list, config["environment"]["SRCDIR"], config["environment"]["BUILDDIR"], config["environment"]["EXEEXT"], tmpdir, args.jobs, args.coverage, passon_args, args.combinedlogslen)
286+
run_tests(test_list, config["environment"]["SRCDIR"], config["environment"]["BUILDDIR"], tmpdir, args.jobs, args.coverage, passon_args, args.combinedlogslen)
287287

288-
def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_coverage=False, args=[], combined_logs_len=0):
288+
def run_tests(test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=False, args=[], combined_logs_len=0):
289289
# Warn if bitcoind is already running (unix only)
290290
try:
291291
if subprocess.check_output(["pidof", "bitcoind"]) is not None:
@@ -298,11 +298,6 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
298298
if os.path.isdir(cache_dir):
299299
print("%sWARNING!%s There is a cache directory here: %s. If tests fail unexpectedly, try deleting the cache directory." % (BOLD[1], BOLD[0], cache_dir))
300300

301-
#Set env vars
302-
if "BITCOIND" not in os.environ:
303-
os.environ["BITCOIND"] = build_dir + '/src/bitcoind' + exeext
304-
os.environ["BITCOINCLI"] = build_dir + '/src/bitcoin-cli' + exeext
305-
306301
tests_dir = src_dir + '/test/functional/'
307302

308303
flags = ["--srcdir={}/src".format(build_dir)] + args

0 commit comments

Comments
 (0)