Changeset View
Changeset View
Standalone View
Standalone View
test/functional/test_framework/test_framework.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Base class for RPC testing.""" | """Base class for RPC testing.""" | ||||
import argparse | import argparse | ||||
import configparser | import configparser | ||||
from enum import Enum | from enum import Enum | ||||
import logging | import logging | ||||
import os | import os | ||||
import pdb | import pdb | ||||
import random | |||||
import shutil | import shutil | ||||
import sys | import sys | ||||
import tempfile | import tempfile | ||||
import time | import time | ||||
from .authproxy import JSONRPCException | from .authproxy import JSONRPCException | ||||
from . import coverage | from . import coverage | ||||
from .test_node import TestNode | from .test_node import TestNode | ||||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | def main(self): | ||||
parser.add_argument("--configfile", dest="configfile", default=os.path.abspath(os.path.dirname(os.path.realpath( | parser.add_argument("--configfile", dest="configfile", default=os.path.abspath(os.path.dirname(os.path.realpath( | ||||
__file__)) + "/../../config.ini"), help="Location of the test framework config file (default: %(default)s)") | __file__)) + "/../../config.ini"), help="Location of the test framework config file (default: %(default)s)") | ||||
parser.add_argument("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true", | parser.add_argument("--pdbonfailure", dest="pdbonfailure", default=False, action="store_true", | ||||
help="Attach a python debugger if test fails") | help="Attach a python debugger if test fails") | ||||
parser.add_argument("--usecli", dest="usecli", default=False, action="store_true", | parser.add_argument("--usecli", dest="usecli", default=False, action="store_true", | ||||
help="use bitcoin-cli instead of RPC for all commands") | help="use bitcoin-cli instead of RPC for all commands") | ||||
parser.add_argument("--perf", dest="perf", default=False, action="store_true", | parser.add_argument("--perf", dest="perf", default=False, action="store_true", | ||||
help="profile running nodes with perf for the duration of the test") | help="profile running nodes with perf for the duration of the test") | ||||
parser.add_argument("--randomseed", type=int, | |||||
help="set a random seed for deterministically reproducing a previous test run") | |||||
parser.add_argument("--with-axionactivation", dest="axionactivation", default=False, action="store_true", | parser.add_argument("--with-axionactivation", dest="axionactivation", default=False, action="store_true", | ||||
help="Activate axion update on timestamp {}".format(TIMESTAMP_IN_THE_PAST)) | help="Activate axion update on timestamp {}".format(TIMESTAMP_IN_THE_PAST)) | ||||
self.add_options(parser) | self.add_options(parser) | ||||
self.options = parser.parse_args() | self.options = parser.parse_args() | ||||
self.set_test_params() | self.set_test_params() | ||||
assert hasattr( | assert hasattr( | ||||
Show All 21 Lines | def main(self): | ||||
# Set up temp directory and start logging | # Set up temp directory and start logging | ||||
if self.options.tmpdir: | if self.options.tmpdir: | ||||
self.options.tmpdir = os.path.abspath(self.options.tmpdir) | self.options.tmpdir = os.path.abspath(self.options.tmpdir) | ||||
os.makedirs(self.options.tmpdir, exist_ok=False) | os.makedirs(self.options.tmpdir, exist_ok=False) | ||||
else: | else: | ||||
self.options.tmpdir = tempfile.mkdtemp(prefix="test") | self.options.tmpdir = tempfile.mkdtemp(prefix="test") | ||||
self._start_logging() | self._start_logging() | ||||
# Seed the PRNG. Note that test runs are reproducible if and only if | |||||
# a single thread accesses the PRNG. For more information, see | |||||
# https://docs.python.org/3/library/random.html#notes-on-reproducibility. | |||||
# The network thread shouldn't access random. If we need to change the | |||||
# network thread to access randomness, it should instantiate its own | |||||
# random.Random object. | |||||
seed = self.options.randomseed | |||||
if seed is None: | |||||
seed = random.randrange(sys.maxsize) | |||||
else: | |||||
self.log.debug("User supplied random seed {}".format(seed)) | |||||
random.seed(seed) | |||||
self.log.debug("PRNG seed is: {}".format(seed)) | |||||
self.log.debug('Setting up network thread') | self.log.debug('Setting up network thread') | ||||
self.network_thread = NetworkThread() | self.network_thread = NetworkThread() | ||||
self.network_thread.start() | self.network_thread.start() | ||||
success = TestStatus.FAILED | success = TestStatus.FAILED | ||||
try: | try: | ||||
if self.options.usecli: | if self.options.usecli: | ||||
▲ Show 20 Lines • Show All 464 Lines • Show Last 20 Lines |