Skip to content

android: test_socket fails #71123

Closed
Closed

Description

@xdegaye
mannequin
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']

    Activity

    1. xdegaye commented on May 3, 2016

      xdegayemannequin
      MannequinAuthor

      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

    2. added
      stdlib
      build
      type-bug
      on May 3, 2016
    3. xdegaye commented on May 7, 2016

      xdegayemannequin
      MannequinAuthor

      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
      >>>
    4. xdegaye commented on May 10, 2016

      xdegayemannequin
      MannequinAuthor

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

    5. xdegaye commented on May 25, 2016

      xdegayemannequin
      MannequinAuthor

      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.

    6. xdegaye commented on May 25, 2016

      xdegayemannequin
      MannequinAuthor

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

    7. xdegaye commented on May 25, 2016

      xdegayemannequin
      MannequinAuthor

      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.

    8. xdegaye commented on Oct 30, 2016

      xdegayemannequin
      MannequinAuthor

      This patch simply skips the statements that fail on Android.

    9. added
      tests
      3.7 (EOL)
      and removed
      stdlib
      build
      on Oct 30, 2016
    10. self-assigned this
      on Oct 30, 2016
    11. xdegaye commented on Oct 31, 2016

      xdegayemannequin
      MannequinAuthor
    12. xdegaye commented on Nov 18, 2016

      xdegayemannequin
      MannequinAuthor

      New patch using support.less_than_android_api(level).

    13. xdegaye commented on Dec 12, 2016

      xdegayemannequin
      MannequinAuthor

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

    14. python-dev commented on Dec 13, 2016

      python-devmannequin
      Mannequin

      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

    15. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.7 (EOL)teststype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions