Skip to content

gh-91960: Add FreeBSD build and test using Cirrus-CI [DEBUG PR] #108972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
freebsd_task:
freebsd_instance:
matrix:
- image: freebsd-13-2-release-amd64
build_script:
- mkdir build
- cd build
- ../configure
- make -j$(sysctl -n hw.ncpu)
- make pythoninfo
test_script:
- cd build
# dtrace fails to build on FreeBSD - see gh-73263
- make buildbottest TESTOPTS="-j0 -u-network -x test_dtrace"
50 changes: 50 additions & 0 deletions Lib/test/support/socket_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os.path
import socket
import sys
import subprocess
import tempfile
import unittest

Expand Down Expand Up @@ -277,3 +278,52 @@ def create_unix_domain_name():
"""
return tempfile.mktemp(prefix="test_python_", suffix='.sock',
dir=os.path.curdir)


# consider that sysctl values should not change while tests are running
_sysctl_cache = {}

def _get_sysctl(name):
"""Get a sysctl value as an integer."""
try:
return _sysctl_cache[name]
except KeyError:
pass

cmd = ['sysctl', name]
proc = subprocess.run(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True)
if proc.returncode:
return None
# Parse 'net.inet.tcp.blackhole: 0\n' to get '0'
value = proc.stdout.rstrip().split(': ')[-1]
try:
value = int(value)
except ValueError:
return None

_sysctl_cache[name] = value
return value


def tcp_blackhole():
if not sys.platform.startswith('freebsd'):
return False

# gh-91960: test if FreeBSD TCP blackhost is enabled
value = _get_sysctl('net.inet.tcp.blackhole')
if value is None:
# don't skip if we fail to get the sysctl value
return False
return (value != 0)


def skip_if_tcp_blackhole(test):
"""Decorator for tests requiring a functional bind() for unix sockets."""
skip_if = unittest.skipIf(
tcp_blackhole(),
"TCP blackhost is enabled (sysctl net.inet.tcp.blackhole)"
)
return skip_if(test)
1 change: 1 addition & 0 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,7 @@ def connection_made(self, transport):

server.close()

@socket_helper.skip_if_tcp_blackhole
def test_server_close(self):
f = self.loop.create_server(MyProto, '0.0.0.0', 0)
server = self.loop.run_until_complete(f)
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_asyncio/test_sock_lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from test import support
from test.support import socket_helper

if socket_helper.tcp_blackhole():
raise unittest.SkipTest('Not relevant to ProactorEventLoop')



def tearDownModule():
asyncio.set_event_loop_policy(None)

Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_asyncio/test_sslproto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
import weakref
from test import support
from test.support import socket_helper
from unittest import mock
try:
import ssl
Expand Down Expand Up @@ -350,6 +351,7 @@ async def client(addr):
support.gc_collect()
self.assertIsNone(client_context())

@socket_helper.skip_if_tcp_blackhole
def test_start_tls_client_buf_proto_1(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE

Expand Down Expand Up @@ -502,6 +504,7 @@ async def client(addr):
asyncio.wait_for(client(srv.addr),
timeout=support.SHORT_TIMEOUT))

@socket_helper.skip_if_tcp_blackhole
def test_start_tls_server_1(self):
HELLO_MSG = b'1' * self.PAYLOAD_SIZE
ANSWER = b'answer'
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_imaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def test_that_Time2Internaldate_returns_a_result(self):
for t in self.timevalues():
imaplib.Time2Internaldate(t)

@socket_helper.skip_if_tcp_blackhole
def test_imap4_host_default_value(self):
# Check whether the IMAP4_PORT is truly unavailable.
with socket.socket() as s:
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -5288,6 +5288,7 @@ def mocked_socket_module(self):
finally:
socket.socket = old_socket

@socket_helper.skip_if_tcp_blackhole
def test_connect(self):
port = socket_helper.find_unused_port()
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand All @@ -5296,6 +5297,7 @@ def test_connect(self):
cli.connect((HOST, port))
self.assertEqual(cm.exception.errno, errno.ECONNREFUSED)

@socket_helper.skip_if_tcp_blackhole
def test_create_connection(self):
# Issue #9792: errors raised by create_connection() should have
# a proper errno attribute.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FreeBSD 13.2 CI coverage for pull requests is now provided by Cirrus-CI (a hosted CI service that supports Linux, macOS, Windows, and FreeBSD).