def testfunc(child): port = generate_port_number() shutdown_event = threading.Event() server_handle = threading.Thread(target=tcp_server, args=(port, shutdown_event)) server_handle.start() target_addr = get_host_ll_addr( get_host_tap_device()) + '%' + get_riot_if_id(child) # Setup RIOT Node to connect to host systems TCP Server child.sendline('gnrc_tcp_tcb_init') child.sendline('gnrc_tcp_open_active AF_INET6 ' + target_addr + ' ' + str(port) + ' 0') child.expect_exact('gnrc_tcp_open_active: returns 0') # Close connection and verify that pktbuf is cleared shutdown_event.set() child.sendline('gnrc_tcp_close') server_handle.join() verify_pktbuf_empty(child) print(os.path.basename(sys.argv[0]) + ': success')
def runner(child): tap = get_host_tap_device() host_ll = get_host_ll_addr(tap) dst_if = get_riot_if_id(child) dst_ll = get_riot_ll_addr(child) dst_l2 = get_riot_l2_addr(child) port = generate_port_number() # Setup RIOT Node wait for incoming connections from host system child.sendline('gnrc_tcp_tcb_init') child.expect_exact( 'gnrc_tcp_tcb_init: argc=1, argv[0] = gnrc_tcp_tcb_init') child.sendline('gnrc_tcp_open_passive [::]:{}'.format(port)) child.expect(r'gnrc_tcp_open_passive: argc=2, ' r'argv\[0\] = gnrc_tcp_open_passive, ' r'argv\[1\] = \[::\]:(\d+)\r\n') assert int(child.match.group(1)) == port try: print("- {} ".format(func.__name__), end="") if child.logfile == sys.stdout: func(child, tap, host_ll, dst_if, dst_l2, dst_ll, port) print("") else: try: func(child, tap, host_ll, dst_if, dst_l2, dst_ll, port) print("SUCCESS") except Exception as e: print("FAILED") raise e finally: child.sendline('gnrc_tcp_close')
def testfunc(child): port = generate_port_number() shutdown_event = threading.Event() # Try to receive 10 bytes sent from the Host System. data = 'test_data_' data_len = len(data) assert (data_len % 2) == 0 # Verify that RIOT Applications internal buffer can hold test data. assert setup_internal_buffer(child) >= data_len server_handle = threading.Thread(target=tcp_server, args=(port, shutdown_event, data)) server_handle.start() target_addr = get_host_ll_addr( get_host_tap_device()) + '%' + get_riot_if_id(child) # Setup RIOT Node to connect to Hostsystems TCP Server child.sendline('gnrc_tcp_tcb_init') child.sendline('gnrc_tcp_open_active [{}]:{} 0'.format( target_addr, str(port))) child.expect_exact('gnrc_tcp_open_active: returns 0') # Initiate connection teardown from test host shutdown_event.set() half_data_len = int(data_len / 2) # Read half the test data with timeout. Verify Buffer contents child.sendline('gnrc_tcp_recv 1000000 ' + str(half_data_len)) child.expect_exact('gnrc_tcp_recv: received ' + str(half_data_len)) assert read_data_from_internal_buffer( child, half_data_len) == data[:half_data_len] # Read half the test data without timeout. Verify Buffer contents child.sendline('gnrc_tcp_recv 0 ' + str(half_data_len)) child.expect_exact('gnrc_tcp_recv: received ' + str(half_data_len)) assert read_data_from_internal_buffer( child, half_data_len) == data[half_data_len:] # Buffer should have been read entirely and the connection was closed, there can be no new data. # Reading with a timeout must return 0 not -ETIMEOUT child.sendline('gnrc_tcp_recv 1000000 ' + str(half_data_len)) child.expect_exact('gnrc_tcp_recv: returns 0') # Reading without a timeout must return 0 not -EAGAIN. child.sendline('gnrc_tcp_recv 0 ' + str(half_data_len)) child.expect_exact('gnrc_tcp_recv: returns 0') # Close connection child.sendline('gnrc_tcp_close') server_handle.join() verify_pktbuf_empty(child) # Verify received Data print(os.path.basename(sys.argv[0]) + ': success')
def testfunc(child): port = generate_port_number() shutdown_event = threading.Event() # Try to send 2000 byte from RIOT to the Host System. data = '0123456789' * 200 data_len = len(data) # Verify that RIOT Applications internal buffer can hold test data. assert setup_internal_buffer(child) >= data_len server_handle = threading.Thread(target=tcp_server, args=(port, shutdown_event, data)) server_handle.start() target_addr = get_host_ll_addr(get_host_tap_device()) + '%' + get_riot_if_id(child) # Setup RIOT Node to connect to host systems TCP Server child.sendline('gnrc_tcp_tcb_init') child.sendline('gnrc_tcp_open_active AF_INET6 ' + target_addr + ' ' + str(port) + ' 0') child.expect_exact('gnrc_tcp_open_active: returns 0') # Send data from RIOT Node to Linux write_data_to_internal_buffer(child, data) child.sendline('gnrc_tcp_send 0') child.expect_exact('gnrc_tcp_send: sent ' + str(data_len)) # Close connection and verify that pktbuf is cleared shutdown_event.set() child.sendline('gnrc_tcp_close') server_handle.join() verify_pktbuf_empty(child) print(os.path.basename(sys.argv[0]) + ': success')
def testfunc(child): port = generate_port_number() shutdown_event = threading.Event() client_handle = threading.Thread(target=tcp_client, args=(get_riot_ll_addr(child), port, shutdown_event)) # Setup RIOT Node wait for incoming connections from host system child.sendline('gnrc_tcp_tcb_init') child.sendline('gnrc_tcp_open_passive [::]:{}'.format(str(port))) client_handle.start() child.expect_exact('gnrc_tcp_open_passive: returns 0') # Close connection and verify that pktbuf is cleared shutdown_event.set() child.sendline('gnrc_tcp_close') client_handle.join() verify_pktbuf_empty(child) print(os.path.basename(sys.argv[0]) + ': success')
def testfunc(child): port = generate_port_number() shutdown_event = threading.Event() # Try to receive 2000 bytes sent from the Host System. data = '0123456789' * 200 data_len = len(data) # Verify that RIOT Applications internal buffer can hold test data. assert setup_internal_buffer(child) >= data_len server_handle = threading.Thread(target=tcp_server, args=(port, shutdown_event, data)) server_handle.start() target_addr = get_host_ll_addr( get_host_tap_device()) + '%' + get_riot_if_id(child) # Setup RIOT Node to connect to Hostsystems TCP Server child.sendline('gnrc_tcp_tcb_init') child.sendline('gnrc_tcp_open_active [{}]:{} 0'.format( target_addr, str(port))) child.expect_exact('gnrc_tcp_open_active: returns 0') # Accept Data sent by the host system child.sendline('gnrc_tcp_recv 1000000 ' + str(data_len)) child.expect_exact('gnrc_tcp_recv: received ' + str(data_len), timeout=20) # Close connection and verify that pktbuf is cleared shutdown_event.set() child.sendline('gnrc_tcp_close') server_handle.join() verify_pktbuf_empty(child) # Verify received Data assert read_data_from_internal_buffer(child, data_len) == data print(os.path.basename(sys.argv[0]) + ': success')