Commit Graph

525 Commits

Author SHA1 Message Date
Serhiy Storchaka 4265854d96
gh-132987: Support __index__() in the socket module (GH-133093)
ntohl(), htonl(), if_indextoname(), getaddrinfo() now use __index__() if
available.

Also fix the Argument Clinic names for module-level functions (although
this does not affect the user).
2025-04-29 19:27:07 +03:00
Serhiy Storchaka d7be26a71e
gh-132734: Fix build on FreeBSD and old Linux (GH-132829) 2025-04-23 14:08:30 +03:00
Serhiy Storchaka e84624450d
gh-132734: Add new constants for Bluetooth sockets (GH-132735) 2025-04-22 11:02:13 +00:00
Serhiy Storchaka 8cb177d09b
gh-132099: Accept an integer as the address for BTPROTO_HCI on Linux (GH-132525)
Previously only an integer packed in a tuple was accepted, while
getsockname() could return a raw integer.
Now the result of getsockname() is always acceptable as an address.
2025-04-16 13:02:51 +03:00
Serhiy Storchaka 61638418a7
gh-70145: Add support for channels in Bluetooth HCI protocol (GH-132481) 2025-04-14 20:09:16 +03:00
Serhiy Storchaka 1fc1df8dcc
gh-132099: Harmonize Bluetooth address handling (GH-132486)
Now all protocols always accept the Bluetooth address as string and
getsockname() always returns the Bluetooth address as string.

* BTPROTO_SCO now accepts not only bytes, but str.
* BTPROTO_SCO now checks address for embedded null.
* On *BSD, BTPROTO_HCI now accepts str instead of bytes.
* On FreeBSD, getsockname() for BTPROTO_HCI now returns str instead of bytes.
* On NetBSD and DragonFly BDS, BTPROTO_HCI now checks address for embedded null.
2025-04-14 08:58:56 +03:00
Serhiy Storchaka 718d234e40
gh-132429: Remove not working test for Bluetooth socket (GH-132459) 2025-04-12 22:35:28 +00:00
Serhiy Storchaka f2f86d3f45
gh-132429: Fix support of Bluetooth sockets on NetBSD and DragonFly BSD (GH-132431)
* Also add support for cid and bdaddr_type in the BTPROTO_L2CAP address on FreeBSD.
* Return cid in getsockname() for BTPROTO_L2CAP if it is not zero.
* Fix a compiler warning on FreeBSD.
2025-04-12 23:57:34 +03:00
Serhiy Storchaka e5f8b2c703
gh-85302: Add support for BTPROTO_SCO on FreeBSD (GH-131981)
BTPROTO_SCO has been supported on FreeBSD since 2008.
2025-04-11 19:38:17 +03:00
Serhiy Storchaka ef70f02925
Skip a test for Bluetooth HCI socket (added in GH-132023) if it fails (GH-132072) 2025-04-05 16:41:57 +03:00
Serhiy Storchaka 2ccd6aae4d
Add tests for Bluetooth RFCOMM, HCI and SCO (GH-132023) 2025-04-04 14:33:09 +03:00
Thomas Grainger 8a00c9a4d2
gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings, and internal test warnings that are now logged (#128973)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-03-27 21:06:52 +02:00
Max Bachmann 3453b5c1d6
gh-114917: add support for AI_NUMERICSERV in getaddrinfo emulation (#114918) 2025-03-18 11:26:51 +01:00
Fredrik Ahlberg 45a24f54af
gh-129288: Add optional l2_cid and l2_bdaddr_type in BTPROTO_L2CAP socket address tuple (#129293)
Add two optional, traling elements in the AF_BLUETOOTH socket address tuple:

- l2_cid, to allow e.g raw LE ATT connections
- l2_bdaddr_type. To be able to connect L2CAP sockets to Bluetooth LE devices,
  the l2_bdaddr_type must be set to BDADDR_LE_PUBLIC or BDADDR_LE_RANDOM.
2025-02-27 12:51:47 +00:00
Gregory P. Smith e1006ce1de
gh-119461: Restore the testSocket VSOCK skipUnless removed by PR #119465 (#129561)
Restore the skipUnless removed by #119465.

This test can only pass on virtual machines, not actual machines.

actual machines see:

```
    self.cli.connect((cid, VSOCKPORT))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
OSError: [Errno 19] No such device
```

Reproduced on (Linux) Ubuntu 24.04.1 running 6.8.0-52-generic.
2025-02-01 20:46:56 -08:00
Hugo van Kemenade 76856ae165
Revert "gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings (#128726)" (#128936) 2025-01-17 15:16:10 +02:00
Thomas Grainger 7807b40730
gh-128770: raise warnings as errors in test suite - except for test_socket which still logs warnings (#128726)
Co-authored-by: sobolevn <mail@sobolevn.me>
Co-authored-by: Brett Cannon <brett@python.org>
2025-01-17 13:39:16 +02:00
Kumar Aditya bb9d955e16
gh-128277: remove unnecessary critical section from `socket.close` (#128305)
Remove unnecessary critical section from `socket.close` as it now uses relaxed atomics for `sock_fd`.
2025-01-01 18:00:47 +05:30
Victor Stinner cbfe3023e4
gh-128116: Skip test_socket VSOCK testStream() on PermissionError (#128120) 2024-12-20 13:38:00 +01:00
Victor Stinner c46acd3588
gh-126876: Fix test_socket.testLargeTimeout() for missing _testcapi (#127517) 2024-12-02 16:51:50 +01:00
Victor Stinner b3687ad454
gh-126876: Fix socket internal_select() for large timeout (#126968)
If the timeout is larger than INT_MAX, replace it with INT_MAX, in
the poll() code path.

Add an unit test.
2024-11-19 09:08:42 +01:00
CF Bolz-Tereick 0f6bb28ff3
Skip test in test_socket.py if `sys.getrefcount` isn't available (#126640)
Skip `testMakefileCloseSocketDestroy` test if `sys.getrefcount` isn't available. This is necessary for  PyPy and other Python implementations that do not have `sys.getrefcount`.
2024-11-10 17:16:36 +02:00
Malcolm Smith c51b56038b
Android: Update tests for newly-available functions affected by SELinux (#126015)
Skip tests on Android that involve use of SELinux-protected methods.
2024-10-27 10:35:53 +08:00
algonell 9017b95ff2
Fix typos (#123775) 2024-09-09 14:58:26 +02:00
Nadeshiko Manju 8a46a2ec50
gh-117657: Fix file descriptor race in test_socket.py (#123697) 2024-09-06 15:00:28 -04:00
nkinnan b5aa271f86
gh-123476: Add support for TCP_QUICKACK socket setting to Windows (#123478)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Steve Dower <steve.dower@microsoft.com>
2024-09-05 22:59:48 +02:00
Russell Keith-Magee f071f01b7b
gh-122133: Rework pure Python socketpair tests to avoid use of importlib.reload. (#122493)
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-07-31 10:24:15 +02:00
Seth Michael Larson 78df1043db
gh-122133: Authenticate socket connection for `socket.socketpair()` fallback (GH-122134)
* Authenticate socket connection for `socket.socketpair()` fallback when the platform does not have a native `socketpair` C API.  We authenticate in-process using `getsocketname` and `getpeername` (thanks to Nathaniel J Smith for that suggestion).

Co-authored-by: Gregory P. Smith <greg@krypto.org>
2024-07-29 14:44:35 -07:00
Victor Stinner e94dbe4ed8
gh-119461: Fix ThreadedVSOCKSocketStreamTest (#119465)
Add socket.VMADDR_CID_LOCAL constant.

Fix ThreadedVSOCKSocketStreamTest: if get_cid() returns the host
address or the "any" address, use the local communication address
(loopback): VMADDR_CID_LOCAL.

On Linux 6.9, apparently, the /dev/vsock device is now available but
get_cid() returns VMADDR_CID_ANY (-1).
2024-05-23 23:26:09 +02:00
Erlend E. Aasland ea94b3b149
gh-116303: Skip test module dependent tests if test modules are unavailable (#117341) 2024-04-03 15:11:36 +02:00
Malcolm Smith 74c8568d07
gh-71042: Add `platform.android_ver` (#116674) 2024-03-27 17:53:27 +01:00
Malcolm Smith 872c0714fc
gh-71052: Change Android's `sys.platform` from "linux" to "android"
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2024-03-11 19:25:39 +00:00
Peter Jiping Xie 9fd420f53d
gh-101384: Add socket timeout to ThreadedVSOCKSocketStreamTest and skip it on WSL (GH-101419) 2024-02-17 09:12:12 +00:00
Russell Keith-Magee 391659b3da
gh-114099: Add test exclusions to support running the test suite on iOS (#114889)
Add test annotations required to run the test suite on iOS (PEP 730).

The majority of the change involve annotating tests that use subprocess,
but are skipped on Emscripten/WASI for other reasons, and including
iOS/tvOS/watchOS under the same umbrella as macOS/darwin checks.

`is_apple` and `is_apple_mobile` test helpers have been added to
identify *any* Apple platform, and "any Apple platform except macOS",
respectively.
2024-02-05 01:04:57 +01:00
Ronald Oussoren 5adff3f86f
gh-80931: Skip some socket tests while hunting for refleaks on macOS (#114057)
Some socket tests related to sending file descriptors cause a file descriptor leak on macOS, all of them tests that send one or more descriptors than cannot be received on the read end.  This appears to be a platform bug.

This PR skips those tests when doing a refleak test run to avoid hiding other problems.
2024-01-21 11:25:15 +01:00
Zackery Spytz 0daf555c6f
bpo-37013: Fix the error handling in socket.if_indextoname() (GH-13503)
* Fix a crash when pass UINT_MAX.
* Fix an integer overflow on 64-bit non-Windows platforms.
2023-12-01 15:16:49 +00:00
Serhiy Storchaka f27b830907
gh-76106: Remove the cleanup lock in test_socket (GH-110539)
It does not already work (because it locks only addCleanup(), not doCleanups()),
and it is no longer needed since the clean up procedure waits for all test threads to join.
2023-10-11 13:52:06 +03:00
Victor Stinner 318f5df271
gh-110167: Fix test_socket deadlock in doCleanups() (#110416)
Fix a deadlock in test_socket when server fails with a timeout but
the client is still running in its thread. Don't hold a lock to call
cleanup functions in doCleanups(). One of the cleanup function waits
until the client completes, whereas the client could deadlock if it
called addCleanup() in such situation.

doCleanups() is called when the server completed, but the client can
still be running in its thread especially if the server failed with a
timeout. Don't put a lock on doCleanups() to prevent deadlock between
addCleanup() called in the client and doCleanups() waiting for
self.done.wait of ThreadableTest._setUp().
2023-10-05 20:53:03 +02:00
Victor Stinner e37d4557c3
gh-110391: socket NetworkConnectionAttributesTest always declare cli (#110401)
NetworkConnectionAttributesTest of test_socket now always declare the
'cli' attribute, so clientTearDown() cannot fail with AttributeError.
2023-10-05 18:31:02 +02:00
Victor Stinner e091b9f20f
gh-109396: Fix test_socket.test_hmac_sha1() in FIPS mode (#109423)
Use a longer key: FIPS mode requires at least of at least 112 bits.
The previous key was only 32 bits.
2023-09-14 21:24:11 +00:00
Victor Stinner a52a350977
gh-109015: Add test.support.socket_helper.tcp_blackhole() (#109016)
Skip test_asyncio, test_imaplib and test_socket tests if FreeBSD TCP
blackhole is enabled (net.inet.tcp.blackhole=2).
2023-09-07 01:58:03 +02:00
Nikita Sobolev 3907de12b5
gh-92658: Fix typo in docs and tests for `HV_GUID_PARENT` (GH-105267) 2023-06-06 17:11:19 +01:00
Jakub Kulík 2c863b3871
gh-74895: adjust tests to work on Solaris (#104326)
Solaris is unusual here, but apparently everyone is happy when SOCK_STREAM is explicitly specified.
2023-05-09 16:49:55 -07:00
Erlend E. Aasland f329a8bc1e
gh-103092: Isolate `socket` module (#103094) 2023-04-09 06:33:52 +05:30
AN Long bf42eb8722
gh-102943: Stop checking localized error text in socket tests on Windows (GH-102944) 2023-03-23 16:34:48 +00:00
Irit Katriel b3cc11a08e
gh-102799: remove unnecessary calls to sys.exc_info() in tests (#102800) 2023-03-18 07:19:38 +00:00
Radek Smejkal 928752ce4c
gh-74895: getaddrinfo no longer raises OverflowError (#2435)
`socket.getaddrinfo()` no longer raises `OverflowError` based on the **port** argument. Error reporting (or not) for its value is left up to the underlying C library `getaddrinfo()` implementation.
2023-02-13 17:37:34 -08:00
Dominic Socular 12be23cf3c
gh-100374: Fixed a bug in socket.getfqdn() (gh-100375) 2022-12-21 22:25:04 +09:00
Ross Burton df11012697
gh-95243: Mitigate the race condition in testSockName (#96173)
find_unused_port() has an inherent race condition, but we can't use
bind_port() as that uses .getsockname() which this test is exercising.

Try binding to unused ports a few times before failing.

Signed-off-by: Ross Burton <ross.burton@arm.com>
2022-08-24 18:37:18 -07:00
Christian Heimes 8b24d60f1b
gh-95174: WASI: skip missing sockets functions (GH-95179) 2022-07-27 08:19:23 +02:00