Skip to content

test_ioctl fails on macOS #119770

Description

@Eclips4

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    testsTests in the Lib/test dir
    on May 30, 2024
  2. Eclips4 commented on May 30, 2024

    @Eclips4
    MemberAuthor

    Bisected to 92fab33
    cc @vstinner

  3. sobolevn commented on May 30, 2024

    @sobolevn
    Member

    Yes, the same happens for me on m2

  4. Eclips4 commented on May 30, 2024

    @Eclips4
    MemberAuthor

    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.

  5. vstinner commented on May 30, 2024

    @vstinner
    Member

    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

  6. Eclips4 commented on May 30, 2024

    @Eclips4
    MemberAuthor

    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.

  7. Eclips4 commented on May 30, 2024

    @Eclips4
    MemberAuthor

    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?

  8. vstinner commented on May 31, 2024

    @vstinner
    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.

  9. added 5 commits that reference this issue on May 31, 2024
  10. vstinner commented on May 31, 2024

    @vstinner
    Member

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

  11. added a commit that references this issue on May 31, 2024
  12. added 2 commits that reference this issue on May 31, 2024
  13. vstinner commented on May 31, 2024

    @vstinner
    Member

    Fixed by 64ff1e2

  14. added a commit that references this issue on Jul 11, 2024
  15. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-mactestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions