Skip to content
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

test_ioctl fails on macOS #119770

Closed
Eclips4 opened this issue May 30, 2024 · 9 comments
Closed

test_ioctl fails on macOS #119770

Eclips4 opened this issue May 30, 2024 · 9 comments
Labels
OS-mac tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@Eclips4
Copy link
Member

Eclips4 commented May 30, 2024

Bug report

Bug description:

./python.exe -m test -v test_ioctl
== CPython 3.14.0a0 (heads/main:a5fef800d3, May 30 2024, 09:48:26) [Clang 15.0.0 (clang-1500.3.9.4)]
== macOS-14.5-arm64-arm-64bit-Mach-O little-endian
== Python build: debug
== cwd: /Users/admin/Projects/cpython/build/test_python_worker_4187æ
== CPU count: 8
== encodings: locale=UTF-8 FS=utf-8
== resources: all test resources are disabled, use -u option to unskip tests

Using random seed: 2309191984
0:00:00 load avg: 63.19 Run 1 test sequentially
0:00:00 load avg: 63.19 [1/1] test_ioctl
test_ioctl (test.test_ioctl.IoctlTests.test_ioctl) ... ok
test_ioctl_mutate (test.test_ioctl.IoctlTests.test_ioctl_mutate) ... ok
test_ioctl_mutate_1024 (test.test_ioctl.IoctlTests.test_ioctl_mutate_1024) ... ok
test_ioctl_mutate_2048 (test.test_ioctl.IoctlTests.test_ioctl_mutate_2048) ... ok
test_ioctl_signed_unsigned_code_param (test.test_ioctl.IoctlTests.test_ioctl_signed_unsigned_code_param) ... ERROR

======================================================================
ERROR: test_ioctl_signed_unsigned_code_param (test.test_ioctl.IoctlTests.test_ioctl_signed_unsigned_code_param)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/admin/Projects/cpython/Lib/test/test_ioctl.py", line 85, in test_ioctl_signed_unsigned_code_param
    new_winsz = fcntl.ioctl(mfd, set_winsz_opcode_maybe_neg, our_winsz)
OSError: [Errno 25] Inappropriate ioctl for device

----------------------------------------------------------------------
Ran 5 tests in 0.003s

FAILED (errors=1)
test test_ioctl failed
test_ioctl failed (1 error)

== Tests result: FAILURE ==

1 test failed:
    test_ioctl

Total duration: 96 ms
Total tests: run=5
Total test files: run=1/1 failed=1
Result: FAILURE

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

@Eclips4 Eclips4 added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels May 30, 2024
@Eclips4
Copy link
Member Author

Eclips4 commented May 30, 2024

Bisected to 92fab33
cc @vstinner

@sobolevn
Copy link
Member

Yes, the same happens for me on m2

@Eclips4
Copy link
Member Author

Eclips4 commented May 30, 2024

Unfortunately, this commit breaks backward compatibility. Previously, it was allowed to pass negative values for the request parameter and then they were converted to positive values. However, now, due to a change in the type from unsigned int to unsigned long, this is not working.

@vstinner
Copy link
Member

vstinner commented May 30, 2024

This test is strange. Why passing negative request if its type is unsigned long? The value should be positive.

test_ioctl was always skipped until recently. I fixed regrtest to test it: #119275

@Eclips4
Copy link
Member Author

Eclips4 commented May 30, 2024

This test is strange. Why passing negative request if its type is unsigned long? The value should be positive.

test_ioctl was always skipped until recently. I fixed regrtest to test it: #119275

Yes, I agree with you that this is strange. Our documentation does not mention that the ioctl request parameter can be negative. I think this test was broken by design.

@Eclips4
Copy link
Member Author

Eclips4 commented May 30, 2024

This line from the test_ioctl_signed_unsigned_code_param is confused me:

if termios.TIOCSWINSZ < 0:

Is there any chance that TIOCSWINSZ can be negative?

@vstinner
Copy link
Member

Is there any chance that TIOCSWINSZ can be negative?

darwin-xnu uses uint32_t with the MSB bit set:

#define IOC_IN          (__uint32_t)0x80000000
#define _IOC(inout, group, num, len) \
	(inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
#define _IOW(g, n, t)     _IOC(IOC_IN,	(g), (n), sizeof(t))
#define TIOCSWINSZ      _IOW('t', 103, struct winsize)  /* set window size */

Source:

Python termios module stores the constant as long in termios_constants array, and then create an object using PyLong_FromLong()`.

The value may be negative or not depending on how C treats the integers. I would prefer to have a more reliable value.

vstinner added a commit to vstinner/cpython that referenced this issue May 31, 2024
vstinner added a commit to vstinner/cpython that referenced this issue May 31, 2024
vstinner added a commit to vstinner/cpython that referenced this issue May 31, 2024
vstinner added a commit to vstinner/cpython that referenced this issue May 31, 2024
vstinner added a commit to vstinner/cpython that referenced this issue May 31, 2024
@vstinner
Copy link
Member

I wrote PR gh-119840 to make termios ioctl() constants positive and to update test_ioctl.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 31, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 31, 2024
@vstinner
Copy link
Member

Fixed by 64ff1e2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants