Fix Python 3 compatibility issues

* Original commit: espressif/esp-idf@9daf51e6be
This commit is contained in:
Roland Dobai
2018-10-10 13:19:31 +02:00
committed by gabsuren
parent 86d107635b
commit a96c890f97
4 changed files with 11 additions and 10 deletions

View File

@ -19,8 +19,8 @@ import IDF
global g_client_response; global g_client_response;
global g_msg_to_client; global g_msg_to_client;
g_client_response = "" g_client_response = b""
g_msg_to_client = " 3XYZ" g_msg_to_client = b" 3XYZ"
def get_my_ip(): def get_my_ip():
s1 = socket(AF_INET, SOCK_DGRAM) s1 = socket(AF_INET, SOCK_DGRAM)
@ -81,11 +81,12 @@ def test_examples_protocol_asio_chat_client(env, extra_data):
# 3. send host's IP to the client i.e. the `dut1` # 3. send host's IP to the client i.e. the `dut1`
dut1.write(host_ip) dut1.write(host_ip)
# 4. client `dut1` should receive a message # 4. client `dut1` should receive a message
dut1.expect(g_msg_to_client[4:]) # Strip out the front 4 bytes of message len (see chat_message protocol) dut1.expect(g_msg_to_client[4:].decode()) # Strip out the front 4 bytes of message len (see chat_message protocol)
# 5. write test message from `dut1` chat_client to the server # 5. write test message from `dut1` chat_client to the server
dut1.write(test_msg) dut1.write(test_msg)
while g_client_response == "": while len(g_client_response) == 0:
time.sleep(1) time.sleep(1)
g_client_response = g_client_response.decode()
print(g_client_response) print(g_client_response)
# 6. evaluate host_server received this message # 6. evaluate host_server received this message
if (g_client_response[4:7] == test_msg): if (g_client_response[4:7] == test_msg):
@ -93,7 +94,7 @@ def test_examples_protocol_asio_chat_client(env, extra_data):
pass pass
else: else:
print("Failure!") print("Failure!")
raise ValueError('Wrong data received from asi tcp server: {} (expected:{})'.format(g_client_response, test_msg)) raise ValueError('Wrong data received from asi tcp server: {} (expected:{})'.format(g_client_response[4:7], test_msg))
thread1.join() thread1.join()
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -27,7 +27,7 @@ def test_examples_protocol_asio_chat_server(env, extra_data):
3. Test connects to server and sends a test message 3. Test connects to server and sends a test message
4. Test evaluates received test message from server 4. Test evaluates received test message from server
""" """
test_msg=" 4ABC\n" test_msg=b" 4ABC\n"
dut1 = env.get_dut("chat_server", "examples/protocols/asio/chat_server") dut1 = env.get_dut("chat_server", "examples/protocols/asio/chat_server")
# check and log bin size # check and log bin size
binary_file = os.path.join(dut1.app.binary_path, "asio_chat_server.bin") binary_file = os.path.join(dut1.app.binary_path, "asio_chat_server.bin")

View File

@ -28,7 +28,7 @@ def test_examples_protocol_asio_tcp_server(env, extra_data):
4. Test evaluates received test message from server 4. Test evaluates received test message from server
5. Test evaluates received test message on server stdout 5. Test evaluates received test message on server stdout
""" """
test_msg="echo message from client to server" test_msg=b"echo message from client to server"
dut1 = env.get_dut("tcp_echo_server", "examples/protocols/asio/tcp_echo_server") dut1 = env.get_dut("tcp_echo_server", "examples/protocols/asio/tcp_echo_server")
# check and log bin size # check and log bin size
binary_file = os.path.join(dut1.app.binary_path, "asio_tcp_echo_server.bin") binary_file = os.path.join(dut1.app.binary_path, "asio_tcp_echo_server.bin")
@ -53,7 +53,7 @@ def test_examples_protocol_asio_tcp_server(env, extra_data):
print("Failure!") print("Failure!")
raise ValueError('Wrong data received from asi tcp server: {} (expoected:{})'.format(data, test_msg)) raise ValueError('Wrong data received from asi tcp server: {} (expoected:{})'.format(data, test_msg))
# 5. check the client message appears also on server terminal # 5. check the client message appears also on server terminal
dut1.expect(test_msg) dut1.expect(test_msg.decode())
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -28,7 +28,7 @@ def test_examples_protocol_asio_udp_server(env, extra_data):
4. Test evaluates received test message from server 4. Test evaluates received test message from server
5. Test evaluates received test message on server stdout 5. Test evaluates received test message on server stdout
""" """
test_msg="echo message from client to server" test_msg=b"echo message from client to server"
dut1 = env.get_dut("udp_echo_server", "examples/protocols/asio/udp_echo_server") dut1 = env.get_dut("udp_echo_server", "examples/protocols/asio/udp_echo_server")
# check and log bin size # check and log bin size
binary_file = os.path.join(dut1.app.binary_path, "asio_udp_echo_server.bin") binary_file = os.path.join(dut1.app.binary_path, "asio_udp_echo_server.bin")
@ -53,7 +53,7 @@ def test_examples_protocol_asio_udp_server(env, extra_data):
print("Failure!") print("Failure!")
raise ValueError('Wrong data received from asi udp server: {} (expoected:{})'.format(data, test_msg)) raise ValueError('Wrong data received from asi udp server: {} (expoected:{})'.format(data, test_msg))
# 5. check the client message appears also on server terminal # 5. check the client message appears also on server terminal
dut1.expect(test_msg) dut1.expect(test_msg.decode())
if __name__ == '__main__': if __name__ == '__main__':
test_examples_protocol_asio_udp_server() test_examples_protocol_asio_udp_server()