Skip to content

Commit fa811b0

Browse files
author
MarcoFalke
committed
qa: Normalize executable location
1 parent 39cf27f commit fa811b0

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
@@ -57,7 +56,7 @@ class TestNode():
5756
To make things easier for the test writer, any unrecognised messages will
5857
be dispatched to the RPC connection."""
5958

60-
def __init__(self, i, datadir, rpchost, timewait, binary, stderr, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False):
59+
def __init__(self, i, datadir, rpchost, timewait, bitcoind, bitcoin_cli, stderr, mocktime, coverage_dir, extra_conf=None, extra_args=None, use_cli=False):
6160
self.index = i
6261
self.datadir = datadir
6362
self.rpchost = rpchost
@@ -66,10 +65,7 @@ def __init__(self, i, datadir, rpchost, timewait, binary, stderr, mocktime, cove
6665
else:
6766
# Wait for up to 60 seconds for the RPC server to respond
6867
self.rpc_timeout = 60
69-
if binary is None:
70-
self.binary = os.getenv("BITCOIND", "bitcoind")
71-
else:
72-
self.binary = binary
68+
self.binary = bitcoind
7369
self.stderr = stderr
7470
self.coverage_dir = coverage_dir
7571
if extra_conf != None:
@@ -90,7 +86,7 @@ def __init__(self, i, datadir, rpchost, timewait, binary, stderr, mocktime, cove
9086
"-noprinttoconsole"
9187
]
9288

93-
self.cli = TestNodeCLI(os.getenv("BITCOINCLI", "bitcoin-cli"), self.datadir)
89+
self.cli = TestNodeCLI(bitcoin_cli, self.datadir)
9490
self.use_cli = use_cli
9591

9692
self.running = False

test/functional/test_runner.py

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

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

286-
def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_coverage=False, args=[], combined_logs_len=0):
286+
def run_tests(test_list, src_dir, build_dir, tmpdir, jobs=1, enable_coverage=False, args=[], combined_logs_len=0):
287287
# Warn if bitcoind is already running (unix only)
288288
try:
289289
if subprocess.check_output(["pidof", "bitcoind"]) is not None:
@@ -296,11 +296,6 @@ def run_tests(test_list, src_dir, build_dir, exeext, tmpdir, jobs=1, enable_cove
296296
if os.path.isdir(cache_dir):
297297
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))
298298

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

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

0 commit comments

Comments
 (0)