diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3a5998697d4..3f47fc81f33 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -26,6 +26,7 @@ function(create_test_config) set_configure_variable(WITH_ZMQ ENABLE_ZMQ) set_configure_variable(ENABLE_EXTERNAL_SIGNER ENABLE_EXTERNAL_SIGNER) set_configure_variable(WITH_USDT ENABLE_USDT_TRACEPOINTS) + set_configure_variable(WITH_MULTIPROCESS WITH_MULTIPROCESS) configure_file(config.ini.in config.ini USE_SOURCE_PERMISSIONS @ONLY) endfunction() diff --git a/test/config.ini.in b/test/config.ini.in index 3bf79ef25d9..c431a381530 100644 --- a/test/config.ini.in +++ b/test/config.ini.in @@ -26,3 +26,4 @@ RPCAUTH=@abs_top_srcdir@/share/rpcauth/rpcauth.py @ENABLE_ZMQ_TRUE@ENABLE_ZMQ=true @ENABLE_EXTERNAL_SIGNER_TRUE@ENABLE_EXTERNAL_SIGNER=true @ENABLE_USDT_TRACEPOINTS_TRUE@ENABLE_USDT_TRACEPOINTS=true +@WITH_MULTIPROCESS_TRUE@WITH_MULTIPROCESS=true diff --git a/test/functional/interface_ipc_mining.py b/test/functional/interface_ipc_mining.py new file mode 100755 index 00000000000..2ef63f5f19a --- /dev/null +++ b/test/functional/interface_ipc_mining.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 +# Copyright (c) 2024 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. +"""Test bitcoin-cli""" + +from test_framework.test_framework import BitcoinTestFramework +from test_framework.util import ( + assert_equal, +) + +import subprocess +import tempfile + +class TestBitcoinMine(BitcoinTestFramework): + def set_test_params(self): + self.setup_clean_chain = True + self.num_nodes = 1 + + def skip_test_if_missing_module(self): + self.skip_if_no_multiprocess() + + def setup_nodes(self): + # Always run multiprocess binaries + self.options.bitcoind = self.options.bitcoin_node + + # Work around default CI path exceeding maximum socket path length + if len(self.options.tmpdir + "/node0/regtest/node.sock") < 108: + self.extra_args = [["-ipcbind=unix"]] + self.mine_args = [] + else: + sock_path = tempfile.mktemp() + self.extra_args = [[f"-ipcbind=unix:{sock_path}"]] + self.mine_args = [f"-ipcconnect=unix:{sock_path}"] + super().setup_nodes() + + def run_test(self): + args = [self.options.bitcoin_mine, f"-datadir={self.nodes[0].datadir_path}"] + self.mine_args + result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, check=True) + assert_equal(result.stdout, "Connected to bitcoin-node\nTip hash is 0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206.\n") + +if __name__ == '__main__': + TestBitcoinMine(__file__).main() diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index d5b338f2ba2..95d25386407 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -220,6 +220,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): config = configparser.ConfigParser() config.read_file(open(self.options.configfile)) self.config = config + self.set_binary_paths() if self.options.v1transport: self.options.v2transport=False @@ -252,13 +253,16 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): "bitcoin-util": ("bitcoinutil", "BITCOINUTIL"), "bitcoin-wallet": ("bitcoinwallet", "BITCOINWALLET"), } - for binary, [attribute_name, env_variable_name] in binaries.items(): - default_filename = os.path.join( + def binary_path(binary): + return os.path.join( self.config["environment"]["BUILDDIR"], "bin", binary + self.config["environment"]["EXEEXT"], ) - setattr(self.options, attribute_name, os.getenv(env_variable_name, default=default_filename)) + for binary, [attribute_name, env_variable_name] in binaries.items(): + setattr(self.options, attribute_name, os.getenv(env_variable_name) or binary_path(binary)) + self.options.bitcoin_mine = binary_path("bitcoin-mine") + self.options.bitcoin_node = binary_path("bitcoin-node") def setup(self): """Call this method to start up the test framework object with options set.""" @@ -269,8 +273,6 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): config = self.config - self.set_binary_paths() - os.environ['PATH'] = os.pathsep.join([ os.path.join(config['environment']['BUILDDIR'], 'bin'), os.environ['PATH'] @@ -996,6 +998,11 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): if not self.is_cli_compiled(): raise SkipTest("bitcoin-cli has not been compiled.") + def skip_if_no_multiprocess(self): + """Skip the running test if multiprocess binaries are not compiled.""" + if not self.is_multiprocess_compiled(): + raise SkipTest("multiprocess binaries have not been compiled.") + def skip_if_no_previous_releases(self): """Skip the running test if previous releases are not available.""" if not self.has_previous_releases(): @@ -1058,5 +1065,9 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): """Checks whether the wallet module was compiled with BDB support.""" return self.config["components"].getboolean("USE_BDB") + def is_multiprocess_compiled(self): + """Checks whether multiprocess binaries are compiled.""" + return self.config["components"].getboolean("WITH_MULTIPROCESS") + def has_blockfile(self, node, filenum: str): return (node.blocks_path/ f"blk{filenum}.dat").is_file() diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py index 1fa22b1cc61..b0478425cde 100755 --- a/test/functional/test_runner.py +++ b/test/functional/test_runner.py @@ -408,6 +408,7 @@ BASE_SCRIPTS = [ 'rpc_help.py', 'p2p_handshake.py', 'p2p_handshake.py --v2transport', + 'interface_ipc_mining.py', 'feature_dirsymlinks.py', 'feature_help.py', 'feature_shutdown.py',