예제 #1
0
def test_gnrc_tcp_recv_respects_GNRC_TCP_NO_TIMEOUT(child):
    """ gnrc_tcp_recv timeout mechanism must be disabled if GNRC_TCP_NO_TIMEOUT
        is set as timeout value.
    """

    pexpect_timeout_sec = _GNRC_TCP_NO_TIMEOUT + 1
    payload = "12345"

    # Setup Host as server
    with HostTcpServer(generate_port_number()) as host_srv:
        # Setup Riot as client
        with RiotTcpClient(child, host_srv):

            # Accept connection
            host_srv.accept()

            # Wait for incoming data blocking.
            # This gnrc_tcp_recv must not return until some Data was sent.
            child.sendline('gnrc_tcp_recv {} {}'.format(_GNRC_TCP_NO_TIMEOUT, len(payload)))
            returned = True
            try:
                child.expect_exact('gnrc_tcp_recv: re', timeout=pexpect_timeout_sec)
            except pexpect.TIMEOUT:
                returned = False
            finally:
                if returned:
                    raise RuntimeError('gnrc_tcp_recv returned')

            # Send data to unblock gnrc_tcp_recv and teardown the connection
            host_srv.send(payload)
            child.expect_exact('gnrc_tcp_recv: received {}'.format(len(payload)))
            host_srv.close()
예제 #2
0
파일: 01-run.py 프로젝트: aidiaz/RIOT
def test_connection_lifecycle_as_client(child):
    """ Open/close a single connection as tcp client """
    # Setup Host as server
    with HostTcpServer(generate_port_number()) as host_srv:
        # Setup Riot as client
        with RiotTcpClient(child, host_srv):
            # Accept and close connection
            host_srv.accept()
            host_srv.close()
예제 #3
0
파일: 01-run.py 프로젝트: aidiaz/RIOT
def test_send_data_from_riot_to_host(child):
    """ Send Data from RIOT Node to Host system """
    # Setup Host as server
    with HostTcpServer(generate_port_number()) as host_srv:
        # Setup Riot as client
        with RiotTcpClient(child, host_srv) as riot_cli:
            # Accept and close connection
            host_srv.accept()

            # Send Data from RIOT to Host system and verify reception
            data = '0123456789' * 200
            riot_cli.send(timeout_ms=0, payload_to_send=data)
            host_srv.receive(data)

            # Teardown connection
            host_srv.close()
예제 #4
0
파일: 01-run.py 프로젝트: aidiaz/RIOT
def test_gnrc_tcp_get_remote_returns_0(child):
    """ This test verifies that get_remote returns 0 in a connected state
        and the used endpoint contains the expected connection parameters
    """
    # Setup Host as server
    with HostTcpServer(generate_port_number()) as host_srv:
        # Setup Riot as client
        with RiotTcpClient(child, host_srv) as riot_cli:

            # Accept connection
            host_srv.accept()

            # Get and verify local endpoint
            riot_cli.get_remote()
            child.expect_exact('Endpoint: addr.ipv6={} netif=0 port={}'.format(
                host_srv.address, host_srv.listen_port))

            # Close connection
            host_srv.close()
예제 #5
0
def test_gnrc_tcp_send_behavior_on_zero_length_buffer_size(child):
    """ This test verifies that gnrc_tcp_send accepts zero length payload
        and returns 0.
    """
    with HostTcpServer(generate_port_number()) as host_srv:
        riot_cli = RiotTcpClient(child, host_srv)

        # Call gnrc_tcp_send with on data and no timeout on unconnected TCB
        # This must return -ENOTCONN
        child.sendline('gnrc_tcp_send 0 0')
        child.expect_exact('gnrc_tcp_send: returns -ENOTCONN')

        with riot_cli:
            host_srv.accept()

            # Call gnrc_tcp_send with on data and no timeout
            # This must return 0 not -EAGAIN
            child.sendline('gnrc_tcp_send 0 0')
            child.expect_exact('gnrc_tcp_send: returns 0')

            host_srv.close()
예제 #6
0
파일: 01-run.py 프로젝트: aidiaz/RIOT
def test_gnrc_tcp_recv_behavior_on_closed_connection(child):
    """ This test ensures that a gnrc_tcp_recv doesn't block if a connection
        was closed already.
    """
    # Setup Host as server
    with HostTcpServer(generate_port_number()) as host_srv:
        # Setup Riot as client
        with RiotTcpClient(child, host_srv) as riot_cli:
            # Accept connection
            host_srv.accept()

            # Transmit data to RIOT client and close connection from host side
            data = 'test_data_'
            host_srv.send(payload_to_send=data)
            host_srv.close()

            # Read half amount of data with huge timeout.
            # Expectency: direct with verified test data. Timeout doesn't matter
            half_data_len = int(len(data) / 2)
            huge_timeout_ms = 1000000000
            no_timeout_ms = 0
            riot_cli.receive(timeout_ms=huge_timeout_ms,
                             sent_payload=data[:half_data_len])

            # Read half amount of data without timeout.
            # Expectency: direct return with verified test data
            riot_cli.receive(timeout_ms=no_timeout_ms,
                             sent_payload=data[half_data_len:])

            # All received data is read, try to read 1 byte with timeout.
            # Expectency: fast return despite timeout since the connection is already closed
            child.sendline('gnrc_tcp_recv {} 1'.format(huge_timeout_ms))
            child.expect_exact('gnrc_tcp_recv: returns 0')

            # All received data is read, try to read 1 byte without timeout.
            # Expectency: fast return since the connection is already closed
            child.sendline('gnrc_tcp_recv {} 1'.format(no_timeout_ms))
            child.expect_exact('gnrc_tcp_recv: returns 0')