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

android: test_socket fails #71123

Closed
xdegaye mannequin opened this issue May 3, 2016 · 11 comments
Closed

android: test_socket fails #71123

xdegaye mannequin opened this issue May 3, 2016 · 11 comments
Assignees
Labels
3.7 tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@xdegaye
Copy link
Mannequin

xdegaye mannequin commented May 3, 2016

BPO 26936
Nosy @xdegaye, @moreati
PRs
  • [Do Not Merge] Convert Misc/NEWS so that it is managed by towncrier #552
  • Dependencies
  • bpo-27027: add the 'is_android' attribute to test.support
  • Files
  • null-proto.patch
  • test-getaddrinfo.patch
  • test_socket.patch
  • test_socket_2.patch
  • test_socket_3.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/xdegaye'
    closed_at = <Date 2016-12-13.09:12:57.274>
    created_at = <Date 2016-05-03.15:10:46.345>
    labels = ['3.7', 'type-bug', 'tests']
    title = 'android: test_socket fails'
    updated_at = <Date 2017-03-31.16:36:29.571>
    user = 'https://github.com/xdegaye'

    bugs.python.org fields:

    activity = <Date 2017-03-31.16:36:29.571>
    actor = 'dstufft'
    assignee = 'xdegaye'
    closed = True
    closed_date = <Date 2016-12-13.09:12:57.274>
    closer = 'xdegaye'
    components = ['Tests']
    creation = <Date 2016-05-03.15:10:46.345>
    creator = 'xdegaye'
    dependencies = ['27027']
    files = ['43000', '43001', '45278', '45534', '45858']
    hgrepos = []
    issue_num = 26936
    keywords = ['patch']
    message_count = 11.0
    messages = ['264737', '265078', '265250', '266362', '266363', '266365', '279730', '279773', '281130', '283009', '283084']
    nosy_count = 3.0
    nosy_names = ['xdegaye', 'python-dev', 'Alex.Willmer']
    pr_nums = ['552']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue26936'
    versions = ['Python 3.7']

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 3, 2016

    test_socket fails on an android emulator running an x86 system image at API level 21.

    ======================================================================
    ERROR: testGetServBy (test.test_socket.GeneralModuleTests)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/sdcard/org.bitbucket.pyona/lib/python3.6/test/test_socket.py", line 913, in testGetServBy
        port2 = socket.getservbyname(service)
    OSError: service/proto not found

    ======================================================================
    ERROR: testGetaddrinfo (test.test_socket.GeneralModuleTests)
    ----------------------------------------------------------------------

    Traceback (most recent call last):
      File "/sdcard/org.bitbucket.pyona/lib/python3.6/test/test_socket.py", line 1240, in testGetaddrinfo
        socket.getaddrinfo(HOST, "http")
      File "/sdcard/org.bitbucket.pyona/lib/python3.6/socket.py", line 732, in getaddrinfo
        for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno 9] servname not supported for ai_socktype

    Ran 530 tests in 26.702s

    FAILED (errors=2, skipped=75)
    test test_socket failed
    1 test failed:
    test_socket
    Total duration: 0:00:27

    @xdegaye xdegaye mannequin added stdlib Python modules in the Lib dir build The build process and cross-build type-bug An unexpected behavior, bug, or error labels May 3, 2016
    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 7, 2016

    On android getservbyname(const char *NAME, const char *PROTO) returns NULL when PROTO is NULL:

    root@generic_x86:/data/local/tmp # python
    Python 3.6.0a0 (default:811ccdee6f87+, May  7 2016, 17:56:37) 
    [GCC 4.9 20140827 (prerelease)] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import socket
    >>> socket.getservbyname('daytime', 'tcp')
    13
    >>> socket.getservbyname('daytime', 'udp')
    13
    >>> socket.getservbyname('daytime')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: service/proto not found
    >>> 

    On android socket.getaddrinfo() raises an exception when port is not a number:

    >>> socket.getaddrinfo('127.0.0.1', 80)
    [(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>, 17, '', ('127.0.0.1', 80)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('127.0.0.1', 80))]
    >>> socket.getaddrinfo('127.0.0.1', 'http')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/sdcard/org.bitbucket.pyona/lib/python3.6/socket.py", line 732, in getaddrinfo
        for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
    socket.gaierror: [Errno 9] servname not supported for ai_socktype
    >>>

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 10, 2016

    testGetaddrinfo does not fail anymore on an emulator running an android-23-x86, i.e. Android 6.0 or API 23.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 25, 2016

    Problems with the socket module on Android:
    API 21:
    a) Both getservbyname() and getservbyport() fail when the optional 'protocolname' parameter is not set to 'tcp' or 'udp'.
    b) getservbyname() fails when 'servicename' is set to 'http'.
    getaddrinfo() fails either when:
    c) 'port' is 'http'.
    d) Or the optional 'type' is not set to socket.SOCK_STREAM or socket.SOCK_DGRAM and 'port' is a string.

    API 23:
    e) getservbyport() fails when the optional 'protocolname' parameter is not set to 'tcp' or 'udp'.

    IMHO case b) and c) are difficult to fix.
    For case d), one could use the Python implementation of getaddrinfo, but Android does not have the deprecated getipnodebyaddr(), so it is necessary to disable ipv6 in this case. Not sure if this is worth it.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 25, 2016

    This patch fixes the testGetServBy test for API 21 and 23 (fixing the cases a) and e) of my previous msg).

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented May 25, 2016

    This patch fixes the testGetaddrinfo test for API 21 (the test runs fine on API 23):
    The failing statement 'socket.getaddrinfo(HOST, "http")' in testGetaddrinfo does not test explicitly for "http" and for the absence of the optional 'type' parameter.
    When is_android is True, the 'socket.getaddrinfo('127.0.0.1', "echo", type=socket.SOCK_DGRAM)' statement is run instead and the test is ok.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Oct 30, 2016

    This patch simply skips the statements that fail on Android.

    @xdegaye xdegaye mannequin added tests Tests in the Lib/test dir 3.7 and removed stdlib Python modules in the Lib dir build The build process and cross-build labels Oct 30, 2016
    @xdegaye xdegaye mannequin self-assigned this Oct 30, 2016
    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Oct 31, 2016

    Entered https://code.google.com/p/android/issues/detail?id=226677 on the AOSP issue tracker.

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Nov 18, 2016

    New patch using support.less_than_android_api(level).

    @xdegaye
    Copy link
    Mannequin Author

    xdegaye mannequin commented Dec 12, 2016

    New patch using sys.getandroidapilevel().
    getandroidapilevel() is only available in 3.7, so only 3.7 is being fixed.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 13, 2016

    New changeset 95140ff32239 by Xavier de Gaye in branch 'default':
    Issue bpo-26936: Fix the test_socket failures on Android - getservbyname(),
    https://hg.python.org/cpython/rev/95140ff32239

    @xdegaye xdegaye mannequin closed this as completed Dec 13, 2016
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants