Merge bitcoin/bitcoin#35216: qa: Improve functional test support on illumos and *BSD

f4a6d079c4 qa: Support `get_bind_addrs` and `feature_bind_extra` on illumos (Hennadii Stepanov)
5e96a8fd5a doc: Add `lsof` to Test Suite Dependencies on NetBSD (Hennadii Stepanov)
5d01aa4772 qa: Ignore `lsof` warnings on NetBSD (Hennadii Stepanov)
70352fda03 qa: Strip prefix length from NetBSD `ifconfig` output (Hennadii Stepanov)
1c1735567e doc: Add `lsof` to Test Suite Dependencies on FreeBSD (Hennadii Stepanov)
4cb7f39c2c qa: Drop OpenBSD from supported platforms in `get_bind_addrs` function (Hennadii Stepanov)
8a982eea85 qa: Add `skip_if_no_lsof_on_nonlinux` helper and use it where needed (Hennadii Stepanov)

Pull request description:

  This PR is a follow-up to #34256. It extends functional test support to illumos-based OSes and fixes several related issues on the *BSDs.

  Changes:
  - Make `lsof` an optional functional test dependency via a new `skip_if_no_lsof` helper, consistent with other optional test deps.
  - Strip the CIDR prefix length from NetBSD `ifconfig` output (no-op on other platforms).
  - Suppress spurious `lsof` warnings on NetBSD.
  - Drop OpenBSD from the platforms supported by `get_bind_addrs`.
  - Document the `lsof` Test Suite Dependency for FreeBSD and NetBSD.
  - Add support for `get_bind_addrs` and `feature_bind_extra` on illumos.

  CI runs: https://github.com/hebasto/bitcoin-core-nightly/pull/280.

  Addresses https://github.com/bitcoin/bitcoin/pull/34256#issuecomment-4361855749.

ACKs for top commit:
  l0rinc:
    Lightly tested code review ACK f4a6d079c4
  sedited:
    utACK f4a6d079c4

Tree-SHA512: 24d943d059f5fa3f5626017eff744836177a41724544355f34b3a31fdf287bd1916bc6e903b598c1c55b61da2ff0f931b4455542d9cff6cf399ef7963096dff4
This commit is contained in:
merge-script
2026-08-04 17:23:26 +02:00
6 changed files with 23 additions and 7 deletions

View File

@@ -33,6 +33,7 @@ class BindExtraTest(BitcoinTestFramework):
def skip_test_if_missing_module(self):
self.skip_if_platform_not_posix()
self.skip_if_no_lsof_on_nonlinux()
def setup_network(self):
loopback_ipv4 = addr_to_hex("127.0.0.1")

View File

@@ -17,6 +17,7 @@ class RPCBindTest(BitcoinTestFramework):
def skip_test_if_missing_module(self):
self.skip_if_platform_not_posix()
self.skip_if_no_lsof_on_nonlinux()
def setup_network(self):
self.add_nodes(self.num_nodes, None)

View File

@@ -2,7 +2,7 @@
# Copyright (c) 2014-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.
"""Linux, macOS, and BSD network utilities.
"""Linux, macOS, BSD and illumos network utilities.
Roughly based on https://web.archive.org/web/20190424172231/http://voorloopnul.com/blog/a-python-netstat-in-less-than-100-lines-of-code/ by Ricardo Pascal
"""
@@ -105,11 +105,13 @@ def get_bind_addrs(pid):
if conn[3] == STATE_LISTEN and conn[4] in inodes:
bind_addrs.append(conn[1])
return bind_addrs
elif sys.platform.startswith(("darwin", "freebsd", "netbsd", "openbsd")):
# OpenBSD is not included, as it does not ship the lsof utility.
elif sys.platform.startswith(("darwin", "freebsd", "netbsd", "sunos5")):
import re
import subprocess
output = subprocess.check_output(["lsof",
*(["-Di"] if sys.platform.startswith("freebsd") else []), # Ignore device cache to avoid stderr warnings.
*(["-Di"] if sys.platform.startswith(("freebsd", "netbsd", "sunos5")) else []), # Ignore device cache to avoid stderr warnings.
*(["-w"] if sys.platform.startswith("netbsd") else []), # Ignore point release mismatch warnings.
"-nP", # Keep hosts and ports numeric.
"-a", # Require all filters to match.
"-p", str(pid), # Limit results to the target pid.
@@ -151,14 +153,14 @@ def all_interfaces():
return [(namestr[i:i+16].split(b'\0', 1)[0],
socket.inet_ntoa(namestr[i+20:i+24]))
for i in range(0, outbytes, struct_size)]
elif sys.platform.startswith(("darwin", "freebsd", "netbsd", "openbsd")):
elif sys.platform.startswith(("darwin", "freebsd", "netbsd", "openbsd", "sunos5")):
import re
import subprocess
output = subprocess.check_output(["ifconfig", "-au"], text=True)
return [
(m["iface"].encode(), ip)
for m in re.finditer(r"(?m)^(?P<iface>\S+):(?P<block>[^\n]*(?:\n[ \t]+[^\n]*)*)", output)
for ip in re.findall(r"inet (\S+)", m["block"])
for ip in re.findall(r"inet ([^\s/]+)", m["block"])
]
else:
raise NotImplementedError(f"all_interfaces is not supported on {sys.platform}")

View File

@@ -1027,6 +1027,11 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
if platform.system() != "Linux":
raise SkipTest("not on a Linux system")
def skip_if_no_lsof_on_nonlinux(self):
"""Skip the running test if the lsof utility is not available on non-Linux platforms."""
if sys.platform != "linux" and shutil.which("lsof") is None:
raise SkipTest("lsof not available")
def skip_if_platform_not_posix(self):
"""Skip the running test if we are not on a POSIX platform"""
if os.name != 'posix':