examples: Use flushed print to see logs on the CI server
This commit is contained in:
parent
17b7959de9
commit
975688b97f
7 changed files with 139 additions and 134 deletions
|
@ -37,6 +37,7 @@ if test_fw_path and test_fw_path not in sys.path:
|
|||
|
||||
import TinyFW
|
||||
import IDF
|
||||
import Utility
|
||||
|
||||
# Import client module
|
||||
expath = os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -60,11 +61,11 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||
IDF.check_performance("http_server_bin_size", bin_size//1024)
|
||||
|
||||
# Upload binary and start testing
|
||||
print("Starting http_server advanced test app")
|
||||
Utility.console_log("Starting http_server advanced test app")
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
print("Waiting to connect with AP")
|
||||
Utility.console_log("Waiting to connect with AP")
|
||||
got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)Got IP: '(\d+.\d+.\d+.\d+)'"), timeout=30)[0]
|
||||
|
||||
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Started HTTP server on port: '(\d+)'"), timeout=15)[0]
|
||||
|
@ -75,18 +76,18 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||
max_uri_len = int(result[3])
|
||||
max_stack_size = int(result[4])
|
||||
|
||||
print("Got IP : " + got_ip)
|
||||
print("Got Port : " + got_port)
|
||||
Utility.console_log("Got IP : " + got_ip)
|
||||
Utility.console_log("Got Port : " + got_port)
|
||||
|
||||
# Run test script
|
||||
# If failed raise appropriate exception
|
||||
failed = False
|
||||
|
||||
print("Sessions and Context Tests...")
|
||||
Utility.console_log("Sessions and Context Tests...")
|
||||
if not client.spillover_session(got_ip, got_port, max_sessions):
|
||||
print("Ignoring failure")
|
||||
Utility.console_log("Ignoring failure")
|
||||
if not client.parallel_sessions_adder(got_ip, got_port, max_sessions):
|
||||
print("Ignoring failure")
|
||||
Utility.console_log("Ignoring failure")
|
||||
if not client.leftover_data_test(got_ip, got_port):
|
||||
failed = True
|
||||
if not client.async_response_test(got_ip, got_port):
|
||||
|
@ -97,19 +98,19 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||
## This test fails a lot! Enable when connection is stable
|
||||
#test_size = 50*1024 # 50KB
|
||||
#if not client.packet_size_limit_test(got_ip, got_port, test_size):
|
||||
# print "Ignoring failure"
|
||||
# Utility.console_log("Ignoring failure")
|
||||
|
||||
print("Getting initial stack usage...")
|
||||
Utility.console_log("Getting initial stack usage...")
|
||||
if not client.get_hello(got_ip, got_port):
|
||||
failed = True
|
||||
|
||||
inital_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: '(\d+)'"), timeout=15)[0])
|
||||
|
||||
if inital_stack < 0.1*max_stack_size:
|
||||
print("More than 90% of stack being used on server start")
|
||||
Utility.console_log("More than 90% of stack being used on server start")
|
||||
failed = True
|
||||
|
||||
print("Basic HTTP Client Tests...")
|
||||
Utility.console_log("Basic HTTP Client Tests...")
|
||||
if not client.get_hello(got_ip, got_port):
|
||||
failed = True
|
||||
if not client.post_hello(got_ip, got_port):
|
||||
|
@ -129,7 +130,7 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||
if not client.get_false_uri(got_ip, got_port):
|
||||
failed = True
|
||||
|
||||
print("Error code tests...")
|
||||
Utility.console_log("Error code tests...")
|
||||
if not client.code_500_server_error_test(got_ip, got_port):
|
||||
failed = True
|
||||
if not client.code_501_method_not_impl(got_ip, got_port):
|
||||
|
@ -145,20 +146,20 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||
if not client.code_408_req_timeout(got_ip, got_port):
|
||||
failed = True
|
||||
if not client.code_414_uri_too_long(got_ip, got_port, max_uri_len):
|
||||
print("Ignoring failure")
|
||||
Utility.console_log("Ignoring failure")
|
||||
if not client.code_431_hdr_too_long(got_ip, got_port, max_hdr_len):
|
||||
print("Ignoring failure")
|
||||
Utility.console_log("Ignoring failure")
|
||||
if not client.test_upgrade_not_supported(got_ip, got_port):
|
||||
failed = True
|
||||
|
||||
print("Getting final stack usage...")
|
||||
Utility.console_log("Getting final stack usage...")
|
||||
if not client.get_hello(got_ip, got_port):
|
||||
failed = True
|
||||
|
||||
final_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: '(\d+)'"), timeout=15)[0])
|
||||
|
||||
if final_stack < 0.05*max_stack_size:
|
||||
print("More than 95% of stack got used during tests")
|
||||
Utility.console_log("More than 95% of stack got used during tests")
|
||||
failed = True
|
||||
|
||||
if failed:
|
||||
|
|
|
@ -144,6 +144,7 @@ import http.client
|
|||
import sys
|
||||
import string
|
||||
import random
|
||||
import Utility
|
||||
|
||||
_verbose_ = False
|
||||
|
||||
|
@ -164,7 +165,7 @@ class Session(object):
|
|||
self.client.sendall(data.encode())
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
print("Socket Error in send :", err)
|
||||
Utility.console_log("Socket Error in send :", err)
|
||||
rval = False
|
||||
return rval
|
||||
|
||||
|
@ -233,7 +234,7 @@ class Session(object):
|
|||
return headers
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
print("Socket Error in recv :", err)
|
||||
Utility.console_log("Socket Error in recv :", err)
|
||||
return None
|
||||
|
||||
def read_resp_data(self):
|
||||
|
@ -264,7 +265,7 @@ class Session(object):
|
|||
# Fetch remaining CRLF
|
||||
if self.client.recv(2) != "\r\n":
|
||||
# Error in packet
|
||||
print("Error in chunked data")
|
||||
Utility.console_log("Error in chunked data")
|
||||
return None
|
||||
if not chunk_len:
|
||||
# If last chunk
|
||||
|
@ -277,7 +278,7 @@ class Session(object):
|
|||
return read_data
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
print("Socket Error in recv :", err)
|
||||
Utility.console_log("Socket Error in recv :", err)
|
||||
return None
|
||||
|
||||
def close(self):
|
||||
|
@ -285,10 +286,10 @@ class Session(object):
|
|||
|
||||
def test_val(text, expected, received):
|
||||
if expected != received:
|
||||
print(" Fail!")
|
||||
print(" [reason] " + text + ":")
|
||||
print(" expected: " + str(expected))
|
||||
print(" received: " + str(received))
|
||||
Utility.console_log(" Fail!")
|
||||
Utility.console_log(" [reason] " + text + ":")
|
||||
Utility.console_log(" expected: " + str(expected))
|
||||
Utility.console_log(" received: " + str(received))
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -305,7 +306,7 @@ class adder_thread (threading.Thread):
|
|||
|
||||
# Pipeline 3 requests
|
||||
if (_verbose_):
|
||||
print(" Thread: Using adder start " + str(self.id))
|
||||
Utility.console_log(" Thread: Using adder start " + str(self.id))
|
||||
|
||||
for _ in range(self.depth):
|
||||
self.session.send_post('/adder', str(self.id))
|
||||
|
@ -317,7 +318,7 @@ class adder_thread (threading.Thread):
|
|||
|
||||
def adder_result(self):
|
||||
if len(self.response) != self.depth:
|
||||
print("Error : missing response packets")
|
||||
Utility.console_log("Error : missing response packets")
|
||||
return False
|
||||
for i in range(len(self.response)):
|
||||
if not test_val("Thread" + str(self.id) + " response[" + str(i) + "]",
|
||||
|
@ -330,7 +331,7 @@ class adder_thread (threading.Thread):
|
|||
|
||||
def get_hello(dut, port):
|
||||
# GET /hello should return 'Hello World!'
|
||||
print("[test] GET /hello returns 'Hello World!' =>", end=' ')
|
||||
Utility.console_log("[test] GET /hello returns 'Hello World!' =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/hello")
|
||||
resp = conn.getresponse()
|
||||
|
@ -343,39 +344,39 @@ def get_hello(dut, port):
|
|||
if not test_val("data", "application/json", resp.getheader('Content-Type')):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def put_hello(dut, port):
|
||||
# PUT /hello returns 405'
|
||||
print("[test] PUT /hello returns 405' =>", end=' ')
|
||||
Utility.console_log("[test] PUT /hello returns 405' =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("PUT", "/hello", "Hello")
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def post_hello(dut, port):
|
||||
# POST /hello returns 405'
|
||||
print("[test] POST /hello returns 404' =>", end=' ')
|
||||
Utility.console_log("[test] POST /hello returns 404' =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("POST", "/hello", "Hello")
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def post_echo(dut, port):
|
||||
# POST /echo echoes data'
|
||||
print("[test] POST /echo echoes data' =>", end=' ')
|
||||
Utility.console_log("[test] POST /echo echoes data' =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("POST", "/echo", "Hello")
|
||||
resp = conn.getresponse()
|
||||
|
@ -385,13 +386,13 @@ def post_echo(dut, port):
|
|||
if not test_val("data", "Hello", resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def put_echo(dut, port):
|
||||
# PUT /echo echoes data'
|
||||
print("[test] PUT /echo echoes data' =>", end=' ')
|
||||
Utility.console_log("[test] PUT /echo echoes data' =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("PUT", "/echo", "Hello")
|
||||
resp = conn.getresponse()
|
||||
|
@ -401,26 +402,26 @@ def put_echo(dut, port):
|
|||
if not test_val("data", "Hello", resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def get_echo(dut, port):
|
||||
# GET /echo returns 404'
|
||||
print("[test] GET /echo returns 405' =>", end=' ')
|
||||
Utility.console_log("[test] GET /echo returns 405' =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/echo")
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def get_hello_type(dut, port):
|
||||
# GET /hello/type_html returns text/html as Content-Type'
|
||||
print("[test] GET /hello/type_html has Content-Type of text/html =>", end=' ')
|
||||
Utility.console_log("[test] GET /hello/type_html has Content-Type of text/html =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/hello/type_html")
|
||||
resp = conn.getresponse()
|
||||
|
@ -433,39 +434,39 @@ def get_hello_type(dut, port):
|
|||
if not test_val("data", "text/html", resp.getheader('Content-Type')):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def get_hello_status(dut, port):
|
||||
# GET /hello/status_500 returns status 500'
|
||||
print("[test] GET /hello/status_500 returns status 500 =>", end=' ')
|
||||
Utility.console_log("[test] GET /hello/status_500 returns status 500 =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/hello/status_500")
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 500, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def get_false_uri(dut, port):
|
||||
# GET /false_uri returns status 404'
|
||||
print("[test] GET /false_uri returns status 404 =>", end=' ')
|
||||
Utility.console_log("[test] GET /false_uri returns status 404 =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/false_uri")
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 404, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
def parallel_sessions_adder(dut, port, max_sessions):
|
||||
# POSTs on /adder in parallel sessions
|
||||
print("[test] POST {pipelined} on /adder in " + str(max_sessions) + " sessions =>", end=' ')
|
||||
Utility.console_log("[test] POST {pipelined} on /adder in " + str(max_sessions) + " sessions =>", end=' ')
|
||||
t = []
|
||||
# Create all sessions
|
||||
for i in range(max_sessions):
|
||||
|
@ -483,13 +484,13 @@ def parallel_sessions_adder(dut, port, max_sessions):
|
|||
res = False
|
||||
t[i].close()
|
||||
if (res):
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return res
|
||||
|
||||
def async_response_test(dut, port):
|
||||
# Test that an asynchronous work is executed in the HTTPD's context
|
||||
# This is tested by reading two responses over the same session
|
||||
print("[test] Test HTTPD Work Queue (Async response) =>", end=' ')
|
||||
Utility.console_log("[test] Test HTTPD Work Queue (Async response) =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
|
||||
s.send_get('/async_data')
|
||||
|
@ -502,12 +503,12 @@ def async_response_test(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def leftover_data_test(dut, port):
|
||||
# Leftover data in POST is purged (valid and invalid URIs)
|
||||
print("[test] Leftover data in POST is purged (valid and invalid URIs) =>", end=' ')
|
||||
Utility.console_log("[test] Leftover data in POST is purged (valid and invalid URIs) =>", end=' ')
|
||||
s = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||
|
||||
s.request("POST", url='/leftover_data', body="abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz")
|
||||
|
@ -536,17 +537,17 @@ def leftover_data_test(dut, port):
|
|||
return False
|
||||
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def spillover_session(dut, port, max_sess):
|
||||
# Session max_sess_sessions + 1 is rejected
|
||||
print("[test] Session max_sess_sessions (" + str(max_sess) + ") + 1 is rejected =>", end=' ')
|
||||
Utility.console_log("[test] Session max_sess_sessions (" + str(max_sess) + ") + 1 is rejected =>", end=' ')
|
||||
s = []
|
||||
_verbose_ = True
|
||||
for i in range(max_sess + 1):
|
||||
if (_verbose_):
|
||||
print("Executing " + str(i))
|
||||
Utility.console_log("Executing " + str(i))
|
||||
try:
|
||||
a = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||
a.request("GET", url='/hello')
|
||||
|
@ -557,7 +558,7 @@ def spillover_session(dut, port, max_sess):
|
|||
s.append(a)
|
||||
except:
|
||||
if (_verbose_):
|
||||
print("Connection " + str(i) + " rejected")
|
||||
Utility.console_log("Connection " + str(i) + " rejected")
|
||||
a.close()
|
||||
break
|
||||
|
||||
|
@ -566,11 +567,11 @@ def spillover_session(dut, port, max_sess):
|
|||
a.close()
|
||||
|
||||
# Check if number of connections is equal to max_sess
|
||||
print(["Fail","Success"][len(s) == max_sess])
|
||||
Utility.console_log(["Fail","Success"][len(s) == max_sess])
|
||||
return (len(s) == max_sess)
|
||||
|
||||
def recv_timeout_test(dut, port):
|
||||
print("[test] Timeout occurs if partial packet sent =>", end=' ')
|
||||
Utility.console_log("[test] Timeout occurs if partial packet sent =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
s.client.sendall(b"GE")
|
||||
s.read_resp_hdrs()
|
||||
|
@ -579,15 +580,15 @@ def recv_timeout_test(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def packet_size_limit_test(dut, port, test_size):
|
||||
print("[test] send size limit test =>", end=' ')
|
||||
Utility.console_log("[test] send size limit test =>", end=' ')
|
||||
retry = 5
|
||||
while (retry):
|
||||
retry -= 1
|
||||
print("data size = ", test_size)
|
||||
Utility.console_log("data size = ", test_size)
|
||||
s = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable))-1] for _ in list(range(test_size)))
|
||||
path = "/echo"
|
||||
|
@ -595,28 +596,28 @@ def packet_size_limit_test(dut, port, test_size):
|
|||
resp = s.getresponse()
|
||||
if not test_val("Error", "200", str(resp.status)):
|
||||
if test_val("Error", "408", str(resp.status)):
|
||||
print("Data too large to be allocated")
|
||||
Utility.console_log("Data too large to be allocated")
|
||||
test_size = test_size//10
|
||||
else:
|
||||
print("Unexpected error")
|
||||
Utility.console_log("Unexpected error")
|
||||
s.close()
|
||||
print("Retry...")
|
||||
Utility.console_log("Retry...")
|
||||
continue
|
||||
resp = resp.read().decode()
|
||||
result = (resp == random_data)
|
||||
if not result:
|
||||
test_val("Data size", str(len(random_data)), str(len(resp)))
|
||||
s.close()
|
||||
print("Retry...")
|
||||
Utility.console_log("Retry...")
|
||||
continue
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
print("Failed")
|
||||
Utility.console_log("Failed")
|
||||
return False
|
||||
|
||||
def code_500_server_error_test(dut, port):
|
||||
print("[test] 500 Server Error test =>", end=' ')
|
||||
Utility.console_log("[test] 500 Server Error test =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
s.client.sendall(b"abcdefgh\0")
|
||||
s.read_resp_hdrs()
|
||||
|
@ -629,11 +630,11 @@ def code_500_server_error_test(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def code_501_method_not_impl(dut, port):
|
||||
print("[test] 501 Method Not Implemented =>", end=' ')
|
||||
Utility.console_log("[test] 501 Method Not Implemented =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("ABC " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
|
@ -647,11 +648,11 @@ def code_501_method_not_impl(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def code_505_version_not_supported(dut, port):
|
||||
print("[test] 505 Version Not Supported =>", end=' ')
|
||||
Utility.console_log("[test] 505 Version Not Supported =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("GET " + path + " HTTP/2.0\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
|
@ -661,11 +662,11 @@ def code_505_version_not_supported(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def code_400_bad_request(dut, port):
|
||||
print("[test] 400 Bad Request =>", end=' ')
|
||||
Utility.console_log("[test] 400 Bad Request =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("XYZ " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
|
@ -675,11 +676,11 @@ def code_400_bad_request(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def code_404_not_found(dut, port):
|
||||
print("[test] 404 Not Found =>", end=' ')
|
||||
Utility.console_log("[test] 404 Not Found =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/dummy"
|
||||
s.client.sendall(("GET " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
|
@ -689,11 +690,11 @@ def code_404_not_found(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def code_405_method_not_allowed(dut, port):
|
||||
print("[test] 405 Method Not Allowed =>", end=' ')
|
||||
Utility.console_log("[test] 405 Method Not Allowed =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("POST " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
|
@ -703,11 +704,11 @@ def code_405_method_not_allowed(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def code_408_req_timeout(dut, port):
|
||||
print("[test] 408 Request Timeout =>", end=' ')
|
||||
Utility.console_log("[test] 408 Request Timeout =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
s.client.sendall(("POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: 10\r\n\r\nABCD").encode())
|
||||
s.read_resp_hdrs()
|
||||
|
@ -716,11 +717,11 @@ def code_408_req_timeout(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def code_411_length_required(dut, port):
|
||||
print("[test] 411 Length Required =>", end=' ')
|
||||
Utility.console_log("[test] 411 Length Required =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/echo"
|
||||
s.client.sendall(("POST " + path + " HTTP/1.1\r\nHost: " + dut + "\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n").encode())
|
||||
|
@ -734,7 +735,7 @@ def code_411_length_required(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def send_getx_uri_len(dut, port, length):
|
||||
|
@ -753,14 +754,14 @@ def send_getx_uri_len(dut, port, length):
|
|||
return s.status
|
||||
|
||||
def code_414_uri_too_long(dut, port, max_uri_len):
|
||||
print("[test] 414 URI Too Long =>", end=' ')
|
||||
Utility.console_log("[test] 414 URI Too Long =>", end=' ')
|
||||
status = send_getx_uri_len(dut, port, max_uri_len)
|
||||
if not test_val("Client Error", "404", status):
|
||||
return False
|
||||
status = send_getx_uri_len(dut, port, max_uri_len + 1)
|
||||
if not test_val("Client Error", "414", status):
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def send_postx_hdr_len(dut, port, length):
|
||||
|
@ -781,18 +782,18 @@ def send_postx_hdr_len(dut, port, length):
|
|||
return False, s.status
|
||||
|
||||
def code_431_hdr_too_long(dut, port, max_hdr_len):
|
||||
print("[test] 431 Header Too Long =>", end=' ')
|
||||
Utility.console_log("[test] 431 Header Too Long =>", end=' ')
|
||||
res, status = send_postx_hdr_len(dut, port, max_hdr_len)
|
||||
if not res:
|
||||
return False
|
||||
res, status = send_postx_hdr_len(dut, port, max_hdr_len + 1)
|
||||
if not test_val("Client Error", "431", status):
|
||||
return False
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
def test_upgrade_not_supported(dut, port):
|
||||
print("[test] Upgrade Not Supported =>", end=' ')
|
||||
Utility.console_log("[test] Upgrade Not Supported =>", end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("OPTIONS * HTTP/1.1\r\nHost:" + dut + "\r\nUpgrade: TLS/1.0\r\nConnection: Upgrade\r\n\r\n").encode())
|
||||
|
@ -802,7 +803,7 @@ def test_upgrade_not_supported(dut, port):
|
|||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
print("Success")
|
||||
Utility.console_log("Success")
|
||||
return True
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -826,7 +827,7 @@ if __name__ == '__main__':
|
|||
|
||||
_verbose_ = True
|
||||
|
||||
print("### Basic HTTP Client Tests")
|
||||
Utility.console_log("### Basic HTTP Client Tests")
|
||||
get_hello(dut, port)
|
||||
post_hello(dut, port)
|
||||
put_hello(dut, port)
|
||||
|
@ -837,7 +838,7 @@ if __name__ == '__main__':
|
|||
get_hello_status(dut, port)
|
||||
get_false_uri(dut, port)
|
||||
|
||||
print("### Error code tests")
|
||||
Utility.console_log("### Error code tests")
|
||||
code_500_server_error_test(dut, port)
|
||||
code_501_method_not_impl(dut, port)
|
||||
code_505_version_not_supported(dut, port)
|
||||
|
@ -852,7 +853,7 @@ if __name__ == '__main__':
|
|||
# Not supported yet (Error on chunked request)
|
||||
###code_411_length_required(dut, port)
|
||||
|
||||
print("### Sessions and Context Tests")
|
||||
Utility.console_log("### Sessions and Context Tests")
|
||||
parallel_sessions_adder(dut, port, max_sessions)
|
||||
leftover_data_test(dut, port)
|
||||
async_response_test(dut, port)
|
||||
|
|
|
@ -39,6 +39,7 @@ if test_fw_path and test_fw_path not in sys.path:
|
|||
|
||||
import TinyFW
|
||||
import IDF
|
||||
import Utility
|
||||
|
||||
# Import client module
|
||||
expath = os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -56,16 +57,16 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
|||
IDF.check_performance("http_server_bin_size", bin_size//1024)
|
||||
|
||||
# Upload binary and start testing
|
||||
print("Starting http_server persistance test app")
|
||||
Utility.console_log("Starting http_server persistance test app")
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
print("Waiting to connect with AP")
|
||||
Utility.console_log("Waiting to connect with AP")
|
||||
got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)Got IP: '(\d+.\d+.\d+.\d+)'"), timeout=120)[0]
|
||||
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Starting server on port: '(\d+)'"), timeout=30)[0]
|
||||
|
||||
print("Got IP : " + got_ip)
|
||||
print("Got Port : " + got_port)
|
||||
Utility.console_log("Got IP : " + got_ip)
|
||||
Utility.console_log("Got Port : " + got_port)
|
||||
|
||||
# Expected Logs
|
||||
dut1.expect("Registering URI handlers", timeout=30)
|
||||
|
@ -85,7 +86,7 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
|||
|
||||
# Retest PUT request and change session context value
|
||||
num = random.randint(0,100)
|
||||
print("Adding :", num)
|
||||
Utility.console_log("Adding: " + str(num))
|
||||
client.putreq(conn, "/adder", str(num))
|
||||
visitor += 1
|
||||
adder += num
|
||||
|
@ -103,7 +104,7 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
|||
# Test POST request and session persistence
|
||||
random_nums = [random.randint(0,100) for _ in range(100)]
|
||||
for num in random_nums:
|
||||
print("Adding :", num)
|
||||
Utility.console_log("Adding: " + str(num))
|
||||
client.postreq(conn, "/adder", str(num))
|
||||
visitor += 1
|
||||
adder += num
|
||||
|
@ -111,19 +112,19 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
|||
dut1.expect("/adder handler read " + str(num), timeout=30)
|
||||
|
||||
# Test GET request and session persistence
|
||||
print("Matching final sum :", adder)
|
||||
Utility.console_log("Matching final sum: " + str(adder))
|
||||
if client.getreq(conn, "/adder").decode() != str(adder):
|
||||
raise RuntimeError
|
||||
visitor += 1
|
||||
dut1.expect("/adder visitor count = " + str(visitor), timeout=30)
|
||||
dut1.expect("/adder GET handler send " + str(adder), timeout=30)
|
||||
|
||||
print("Ending session")
|
||||
Utility.console_log("Ending session")
|
||||
# Close connection and check for invocation of context "Free" function
|
||||
client.end_session(conn)
|
||||
dut1.expect("/adder Free Context function called", timeout=30)
|
||||
|
||||
print("Validating user context data")
|
||||
Utility.console_log("Validating user context data")
|
||||
# Start another session to check user context data
|
||||
conn2 = client.start_session(got_ip, got_port)
|
||||
num = random.randint(0,100)
|
||||
|
|
|
@ -34,11 +34,11 @@ def getreq (conn, path, verbose = False):
|
|||
resp = conn.getresponse()
|
||||
data = resp.read()
|
||||
if verbose:
|
||||
print("GET : ", path)
|
||||
print("Status : ", resp.status)
|
||||
print("Reason : ", resp.reason)
|
||||
print("Data length : ", len(data))
|
||||
print("Data content : ", data)
|
||||
Utility.console_log("GET : " + path)
|
||||
Utility.console_log("Status : " + resp.status)
|
||||
Utility.console_log("Reason : " + resp.reason)
|
||||
Utility.console_log("Data length : " + str(len(data)))
|
||||
Utility.console_log("Data content : " + data)
|
||||
return data
|
||||
|
||||
def postreq (conn, path, data, verbose = False):
|
||||
|
@ -46,11 +46,11 @@ def postreq (conn, path, data, verbose = False):
|
|||
resp = conn.getresponse()
|
||||
data = resp.read()
|
||||
if verbose:
|
||||
print("POST : ", data)
|
||||
print("Status : ", resp.status)
|
||||
print("Reason : ", resp.reason)
|
||||
print("Data length : ", len(data))
|
||||
print("Data content : ", data)
|
||||
Utility.console_log("POST : " + data)
|
||||
Utility.console_log("Status : " + resp.status)
|
||||
Utility.console_log("Reason : " + resp.reason)
|
||||
Utility.console_log("Data length : " + str(len(data)))
|
||||
Utility.console_log("Data content : " + data)
|
||||
return data
|
||||
|
||||
def putreq (conn, path, body, verbose = False):
|
||||
|
@ -58,11 +58,11 @@ def putreq (conn, path, body, verbose = False):
|
|||
resp = conn.getresponse()
|
||||
data = resp.read()
|
||||
if verbose:
|
||||
print("PUT : ", path, body)
|
||||
print("Status : ", resp.status)
|
||||
print("Reason : ", resp.reason)
|
||||
print("Data length : ", len(data))
|
||||
print("Data content : ", data)
|
||||
Utility.console_log("PUT : " + path, body)
|
||||
Utility.console_log("Status : " + resp.status)
|
||||
Utility.console_log("Reason : " + resp.reason)
|
||||
Utility.console_log("Data length : " + str(len(data)))
|
||||
Utility.console_log("Data content : " + data)
|
||||
return data
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -79,22 +79,22 @@ if __name__ == '__main__':
|
|||
N = args['N']
|
||||
|
||||
# Establish HTTP connection
|
||||
print("Connecting to => " + ip + ":" + port)
|
||||
Utility.console_log("Connecting to => " + ip + ":" + port)
|
||||
conn = start_session (ip, port)
|
||||
|
||||
# Reset adder context to specified value(0)
|
||||
# -- Not needed as new connection will always
|
||||
# -- have zero value of the accumulator
|
||||
print("Reset the accumulator to 0")
|
||||
Utility.console_log("Reset the accumulator to 0")
|
||||
putreq (conn, "/adder", str(0))
|
||||
|
||||
# Sum numbers from 1 to specified value(N)
|
||||
print("Summing numbers from 1 to " + str(N))
|
||||
Utility.console_log("Summing numbers from 1 to " + str(N))
|
||||
for i in range(1, N+1):
|
||||
postreq (conn, "/adder", str(i))
|
||||
|
||||
# Fetch the result
|
||||
print("Result :", getreq (conn, "/adder"))
|
||||
Utility.console_log("Result :" + getreq (conn, "/adder"))
|
||||
|
||||
# Close HTTP connection
|
||||
end_session (conn)
|
||||
|
|
|
@ -38,6 +38,7 @@ if test_fw_path and test_fw_path not in sys.path:
|
|||
|
||||
import TinyFW
|
||||
import IDF
|
||||
import Utility
|
||||
|
||||
# Import client module
|
||||
expath = os.path.dirname(os.path.realpath(__file__))
|
||||
|
@ -55,23 +56,23 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
|||
IDF.check_performance("http_server_bin_size", bin_size//1024)
|
||||
|
||||
# Upload binary and start testing
|
||||
print("Starting http_server simple test app")
|
||||
Utility.console_log("Starting http_server simple test app")
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
print("Waiting to connect with AP")
|
||||
Utility.console_log("Waiting to connect with AP")
|
||||
got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)Got IP: '(\d+.\d+.\d+.\d+)'"), timeout=120)[0]
|
||||
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Starting server on port: '(\d+)'"), timeout=30)[0]
|
||||
|
||||
print("Got IP : " + got_ip)
|
||||
print("Got Port : " + got_port)
|
||||
Utility.console_log("Got IP : " + got_ip)
|
||||
Utility.console_log("Got Port : " + got_port)
|
||||
|
||||
# Expected Logs
|
||||
dut1.expect("Registering URI handlers", timeout=30)
|
||||
|
||||
# Run test script
|
||||
# If failed raise appropriate exception
|
||||
print("Test /hello GET handler")
|
||||
Utility.console_log("Test /hello GET handler")
|
||||
if not client.test_get_handler(got_ip, got_port):
|
||||
raise RuntimeError
|
||||
|
||||
|
@ -86,7 +87,7 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
|||
dut1.expect("Found URL query parameter => query2=value2", timeout=30)
|
||||
dut1.expect("Request headers lost", timeout=30)
|
||||
|
||||
print("Test /ctrl PUT handler and realtime handler de/registration")
|
||||
Utility.console_log("Test /ctrl PUT handler and realtime handler de/registration")
|
||||
if not client.test_put_handler(got_ip, got_port):
|
||||
raise RuntimeError
|
||||
dut1.expect("Unregistering /hello and /echo URIs", timeout=30)
|
||||
|
@ -94,24 +95,24 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
|||
|
||||
# Generate random data of 10KB
|
||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable))-1] for _ in range(10*1024))
|
||||
print("Test /echo POST handler with random data")
|
||||
Utility.console_log("Test /echo POST handler with random data")
|
||||
if not client.test_post_handler(got_ip, got_port, random_data):
|
||||
raise RuntimeError
|
||||
|
||||
query = "http://foobar"
|
||||
print("Test /hello with custom query : " + query)
|
||||
Utility.console_log("Test /hello with custom query : " + query)
|
||||
if not client.test_custom_uri_query(got_ip, got_port, query):
|
||||
raise RuntimeError
|
||||
dut1.expect("Found URL query => " + query, timeout=30)
|
||||
|
||||
query = "abcd+1234%20xyz"
|
||||
print("Test /hello with custom query : " + query)
|
||||
Utility.console_log("Test /hello with custom query : " + query)
|
||||
if not client.test_custom_uri_query(got_ip, got_port, query):
|
||||
raise RuntimeError
|
||||
dut1.expect("Found URL query => " + query, timeout=30)
|
||||
|
||||
query = "abcd\nyz"
|
||||
print("Test /hello with invalid query")
|
||||
Utility.console_log("Test /hello with invalid query")
|
||||
if client.test_custom_uri_query(got_ip, got_port, query):
|
||||
raise RuntimeError
|
||||
dut1.expect("400 Bad Request - Server unable to understand request due to invalid syntax", timeout=30)
|
||||
|
|
|
@ -24,7 +24,7 @@ import argparse
|
|||
|
||||
def verbose_print(verbosity, *args):
|
||||
if (verbosity):
|
||||
print(''.join(str(elems) for elems in args))
|
||||
Utility.console_log(''.join(str(elems) for elems in args))
|
||||
|
||||
def test_get_handler(ip, port, verbosity = False):
|
||||
verbose_print(verbosity, "======== GET HANDLER TEST =============")
|
||||
|
@ -150,8 +150,8 @@ if __name__ == '__main__':
|
|||
msg = args['msg']
|
||||
|
||||
if not test_get_handler (ip, port, True):
|
||||
print("Failed!")
|
||||
Utility.console_log("Failed!")
|
||||
if not test_post_handler(ip, port, msg, True):
|
||||
print("Failed!")
|
||||
Utility.console_log("Failed!")
|
||||
if not test_put_handler (ip, port, True):
|
||||
print("Failed!")
|
||||
Utility.console_log("Failed!")
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
from __future__ import print_function
|
||||
import sys
|
||||
|
||||
|
||||
|
@ -17,7 +18,7 @@ _COLOR_CODES = {
|
|||
}
|
||||
|
||||
|
||||
def console_log(data, color="white"):
|
||||
def console_log(data, color="white", end="\n"):
|
||||
"""
|
||||
log data to console.
|
||||
(if not flush console log, Gitlab-CI won't update logs during job execution)
|
||||
|
@ -28,8 +29,8 @@ def console_log(data, color="white"):
|
|||
if color not in _COLOR_CODES:
|
||||
color = "white"
|
||||
color_codes = _COLOR_CODES[color]
|
||||
print(color_codes + data)
|
||||
print(color_codes + data, end=end)
|
||||
if color not in ["white", "W"]:
|
||||
# reset color to white for later logs
|
||||
print(_COLOR_CODES["white"] + "\r")
|
||||
sys.stdout.flush()
|
||||
sys.stdout.flush()
|
||||
|
|
Loading…
Reference in a new issue