mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
style: format python files with isort and double-quote-string-fixer
This commit is contained in:
@@ -1,16 +1,17 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import re
|
||||
import socket
|
||||
import subprocess
|
||||
import ttfw_idf
|
||||
import time
|
||||
from threading import Event, Thread
|
||||
|
||||
import netifaces
|
||||
from threading import Thread, Event
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
def run_server(server_stop, port, server_ip, client_ip):
|
||||
print("Starting PPP server on port: {}".format(port))
|
||||
print('Starting PPP server on port: {}'.format(port))
|
||||
try:
|
||||
arg_list = ['pppd', port, '115200', '{}:{}'.format(server_ip, client_ip), 'modem', 'local', 'noauth', 'debug', 'nocrtscts', 'nodetach', '+ipv6']
|
||||
p = subprocess.Popen(arg_list, stdout=subprocess.PIPE, bufsize=1)
|
||||
@@ -19,17 +20,17 @@ def run_server(server_stop, port, server_ip, client_ip):
|
||||
raise ValueError('ENV_TEST_FAILURE: PPP terminated unexpectedly with {}'.format(p.poll()))
|
||||
line = p.stdout.readline()
|
||||
if line:
|
||||
print("[PPPD:]{}".format(line.rstrip()))
|
||||
print('[PPPD:]{}'.format(line.rstrip()))
|
||||
time.sleep(0.1)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
raise ValueError('ENV_TEST_FAILURE: Error running PPP server')
|
||||
finally:
|
||||
p.terminate()
|
||||
print("PPP server stopped")
|
||||
print('PPP server stopped')
|
||||
|
||||
|
||||
@ttfw_idf.idf_custom_test(env_tag="Example_PPP", group="test-apps")
|
||||
@ttfw_idf.idf_custom_test(env_tag='Example_PPP', group='test-apps')
|
||||
def test_examples_protocol_pppos_connect(env, extra_data):
|
||||
"""
|
||||
steps:
|
||||
@@ -38,17 +39,17 @@ def test_examples_protocol_pppos_connect(env, extra_data):
|
||||
3. check TCP client-server connection between client-server
|
||||
"""
|
||||
|
||||
dut1 = env.get_dut("pppos_connect_test", "tools/test_apps/protocols/pppos", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('pppos_connect_test', 'tools/test_apps/protocols/pppos', dut_class=ttfw_idf.ESP32DUT)
|
||||
# Look for test case symbolic names
|
||||
try:
|
||||
server_ip = dut1.app.get_sdkconfig()["CONFIG_TEST_APP_PPP_SERVER_IP"].replace('"','')
|
||||
client_ip = dut1.app.get_sdkconfig()["CONFIG_TEST_APP_PPP_CLIENT_IP"].replace('"','')
|
||||
port_nr = dut1.app.get_sdkconfig()["CONFIG_TEST_APP_TCP_PORT"]
|
||||
server_ip = dut1.app.get_sdkconfig()['CONFIG_TEST_APP_PPP_SERVER_IP'].replace('"','')
|
||||
client_ip = dut1.app.get_sdkconfig()['CONFIG_TEST_APP_PPP_CLIENT_IP'].replace('"','')
|
||||
port_nr = dut1.app.get_sdkconfig()['CONFIG_TEST_APP_TCP_PORT']
|
||||
except Exception:
|
||||
print('ENV_TEST_FAILURE: Some mandatory configuration not found in sdkconfig')
|
||||
raise
|
||||
|
||||
print("Starting the test on {}".format(dut1))
|
||||
print('Starting the test on {}'.format(dut1))
|
||||
dut1.start_app()
|
||||
|
||||
# the PPP test env uses two ttyUSB's: one for ESP32 board, another one for ppp server
|
||||
@@ -60,29 +61,29 @@ def test_examples_protocol_pppos_connect(env, extra_data):
|
||||
t.start()
|
||||
try:
|
||||
ppp_server_timeout = time.time() + 30
|
||||
while "ppp0" not in netifaces.interfaces():
|
||||
while 'ppp0' not in netifaces.interfaces():
|
||||
print("PPP server haven't yet setup its netif, list of active netifs:{}".format(netifaces.interfaces()))
|
||||
time.sleep(0.5)
|
||||
if time.time() > ppp_server_timeout:
|
||||
raise ValueError("ENV_TEST_FAILURE: PPP server failed to setup ppp0 interface within timeout")
|
||||
ip6_addr = dut1.expect(re.compile(r"Got IPv6 address (\w{4}\:\w{4}\:\w{4}\:\w{4}\:\w{4}\:\w{4}\:\w{4}\:\w{4})"), timeout=30)[0]
|
||||
print("IPv6 address of ESP: {}".format(ip6_addr))
|
||||
raise ValueError('ENV_TEST_FAILURE: PPP server failed to setup ppp0 interface within timeout')
|
||||
ip6_addr = dut1.expect(re.compile(r'Got IPv6 address (\w{4}\:\w{4}\:\w{4}\:\w{4}\:\w{4}\:\w{4}\:\w{4}\:\w{4})'), timeout=30)[0]
|
||||
print('IPv6 address of ESP: {}'.format(ip6_addr))
|
||||
|
||||
dut1.expect(re.compile(r"Socket listening"))
|
||||
print("Starting the IPv6 test...")
|
||||
dut1.expect(re.compile(r'Socket listening'))
|
||||
print('Starting the IPv6 test...')
|
||||
# Connect to TCP server on ESP using IPv6 address
|
||||
for res in socket.getaddrinfo(ip6_addr + "%ppp0", int(port_nr), socket.AF_INET6,
|
||||
for res in socket.getaddrinfo(ip6_addr + '%ppp0', int(port_nr), socket.AF_INET6,
|
||||
socket.SOCK_STREAM, socket.SOL_TCP):
|
||||
af, socktype, proto, canonname, addr = res
|
||||
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
|
||||
sock.connect(addr)
|
||||
sock.sendall(b"Espressif")
|
||||
sock.sendall(b'Espressif')
|
||||
sock.close()
|
||||
|
||||
dut1.expect(re.compile(r"IPv6 test passed"))
|
||||
print("IPv6 test passed!")
|
||||
dut1.expect(re.compile(r'IPv6 test passed'))
|
||||
print('IPv6 test passed!')
|
||||
|
||||
print("Starting the IPv4 test...")
|
||||
print('Starting the IPv4 test...')
|
||||
# Start the TCP server and wait for the ESP to connect with IPv4 address
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@@ -103,8 +104,8 @@ def test_examples_protocol_pppos_connect(env, extra_data):
|
||||
conn.send(data.encode())
|
||||
break
|
||||
conn.close()
|
||||
dut1.expect(re.compile(r"IPv4 test passed"))
|
||||
print("IPv4 test passed!")
|
||||
dut1.expect(re.compile(r'IPv4 test passed'))
|
||||
print('IPv4 test passed!')
|
||||
finally:
|
||||
server_stop.set()
|
||||
t.join()
|
||||
|
Reference in New Issue
Block a user