aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/feature_port.py60
-rwxr-xr-xtest/functional/interface_usdt_net.py7
-rwxr-xr-xtest/functional/test_framework/test_node.py5
-rwxr-xr-xtest/functional/test_runner.py1
4 files changed, 67 insertions, 6 deletions
diff --git a/test/functional/feature_port.py b/test/functional/feature_port.py
new file mode 100755
index 0000000000..2746d7d79c
--- /dev/null
+++ b/test/functional/feature_port.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python3
+# Copyright (c) 2024-present 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 the -port option and its interactions with
+-bind.
+"""
+
+from test_framework.test_framework import (
+ BitcoinTestFramework,
+)
+from test_framework.util import (
+ p2p_port,
+)
+
+
+class PortTest(BitcoinTestFramework):
+ def set_test_params(self):
+ self.setup_clean_chain = True
+ # Avoid any -bind= on the command line.
+ self.bind_to_localhost_only = False
+ self.num_nodes = 1
+
+ def run_test(self):
+ node = self.nodes[0]
+ node.has_explicit_bind = True
+ port1 = p2p_port(self.num_nodes)
+ port2 = p2p_port(self.num_nodes + 5)
+
+ self.log.info("When starting with -port, bitcoind binds to it and uses port + 1 for an onion bind")
+ with node.assert_debug_log(expected_msgs=[f'Bound to 0.0.0.0:{port1}', f'Bound to 127.0.0.1:{port1 + 1}']):
+ self.restart_node(0, extra_args=["-listen", f"-port={port1}"])
+
+ self.log.info("When specifying -port multiple times, only the last one is taken")
+ with node.assert_debug_log(expected_msgs=[f'Bound to 0.0.0.0:{port2}', f'Bound to 127.0.0.1:{port2 + 1}'], unexpected_msgs=[f'Bound to 0.0.0.0:{port1}']):
+ self.restart_node(0, extra_args=["-listen", f"-port={port1}", f"-port={port2}"])
+
+ self.log.info("When specifying ports with both -port and -bind, the one from -port is ignored")
+ with node.assert_debug_log(expected_msgs=[f'Bound to 0.0.0.0:{port2}'], unexpected_msgs=[f'Bound to 0.0.0.0:{port1}']):
+ self.restart_node(0, extra_args=["-listen", f"-port={port1}", f"-bind=0.0.0.0:{port2}"])
+
+ self.log.info("When -bind specifies no port, the values from -port and -bind are combined")
+ with self.nodes[0].assert_debug_log(expected_msgs=[f'Bound to 0.0.0.0:{port1}']):
+ self.restart_node(0, extra_args=["-listen", f"-port={port1}", "-bind=0.0.0.0"])
+
+ self.log.info("When an onion bind specifies no port, the value from -port, incremented by 1, is taken")
+ with self.nodes[0].assert_debug_log(expected_msgs=[f'Bound to 127.0.0.1:{port1 + 1}']):
+ self.restart_node(0, extra_args=["-listen", f"-port={port1}", "-bind=127.0.0.1=onion"])
+
+ self.log.info("Invalid values for -port raise errors")
+ self.stop_node(0)
+ node.extra_args = ["-listen", "-port=65536"]
+ node.assert_start_raises_init_error(expected_msg="Error: Invalid port specified in -port: '65536'")
+ node.extra_args = ["-listen", "-port=0"]
+ node.assert_start_raises_init_error(expected_msg="Error: Invalid port specified in -port: '0'")
+
+
+if __name__ == '__main__':
+ PortTest(__file__).main()
diff --git a/test/functional/interface_usdt_net.py b/test/functional/interface_usdt_net.py
index 7b55259b63..5468ddf858 100755
--- a/test/functional/interface_usdt_net.py
+++ b/test/functional/interface_usdt_net.py
@@ -40,7 +40,8 @@ net_tracepoints_program = """
MAX_MSG_TYPE_LENGTH,
MAX_MSG_DATA_LENGTH
) + """
-#define MIN(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
+// A min() macro. Prefixed with _TRACEPOINT_TEST to avoid collision with other MIN macros.
+#define _TRACEPOINT_TEST_MIN(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
struct p2p_message
{
@@ -60,7 +61,7 @@ int trace_inbound_message(struct pt_regs *ctx) {
bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH);
bpf_usdt_readarg(5, ctx, &msg.msg_size);
- bpf_usdt_readarg_p(6, ctx, &msg.msg, MIN(msg.msg_size, MAX_MSG_DATA_LENGTH));
+ bpf_usdt_readarg_p(6, ctx, &msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH));
inbound_messages.perf_submit(ctx, &msg, sizeof(msg));
return 0;
}
@@ -73,7 +74,7 @@ int trace_outbound_message(struct pt_regs *ctx) {
bpf_usdt_readarg_p(3, ctx, &msg.peer_conn_type, MAX_PEER_CONN_TYPE_LENGTH);
bpf_usdt_readarg_p(4, ctx, &msg.msg_type, MAX_MSG_TYPE_LENGTH);
bpf_usdt_readarg(5, ctx, &msg.msg_size);
- bpf_usdt_readarg_p(6, ctx, &msg.msg, MIN(msg.msg_size, MAX_MSG_DATA_LENGTH));
+ bpf_usdt_readarg_p(6, ctx, &msg.msg, _TRACEPOINT_TEST_MIN(msg.msg_size, MAX_MSG_DATA_LENGTH));
outbound_messages.perf_submit(ctx, &msg, sizeof(msg));
return 0;
};
diff --git a/test/functional/test_framework/test_node.py b/test/functional/test_framework/test_node.py
index 60ca9269a5..32a266586a 100755
--- a/test/functional/test_framework/test_node.py
+++ b/test/functional/test_framework/test_node.py
@@ -220,10 +220,9 @@ class TestNode():
extra_args = self.extra_args
# If listening and no -bind is given, then bitcoind would bind P2P ports on
- # 0.0.0.0:P and 127.0.0.1:18445 (for incoming Tor connections), where P is
+ # 0.0.0.0:P and 127.0.0.1:P+1 (for incoming Tor connections), where P is
# a unique port chosen by the test framework and configured as port=P in
- # bitcoin.conf. To avoid collisions on 127.0.0.1:18445, change it to
- # 127.0.0.1:tor_port().
+ # bitcoin.conf. To avoid collisions, change it to 127.0.0.1:tor_port().
will_listen = all(e != "-nolisten" and e != "-listen=0" for e in extra_args)
has_explicit_bind = self.has_explicit_bind or any(e.startswith("-bind=") for e in extra_args)
if will_listen and not has_explicit_bind:
diff --git a/test/functional/test_runner.py b/test/functional/test_runner.py
index b85bf1c668..842328e2cf 100755
--- a/test/functional/test_runner.py
+++ b/test/functional/test_runner.py
@@ -335,6 +335,7 @@ BASE_SCRIPTS = [
'feature_minchainwork.py',
'rpc_estimatefee.py',
'rpc_getblockstats.py',
+ 'feature_port.py',
'feature_bind_port_externalip.py',
'wallet_create_tx.py --legacy-wallet',
'wallet_send.py --legacy-wallet',