mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'feature/py23_examples' into 'master'
Examples: Add Python 2&3 support See merge request idf/esp-idf!3237
This commit is contained in:
commit
607d899503
@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
from builtins import range
|
||||||
import os
|
import os
|
||||||
import wave
|
import wave
|
||||||
import struct
|
import struct
|
||||||
@ -13,7 +15,7 @@ def get_wave_array_str(filename, target_bits):
|
|||||||
cur_lim = (1 << sampwidth) - 1
|
cur_lim = (1 << sampwidth) - 1
|
||||||
#scale current data to 8-bit data
|
#scale current data to 8-bit data
|
||||||
val = val * scale_val / cur_lim
|
val = val * scale_val / cur_lim
|
||||||
val = (val + ((scale_val + 1) / 2)) & scale_val
|
val = int(val + ((scale_val + 1) // 2)) & scale_val
|
||||||
array_str += "0x%x, "%(val)
|
array_str += "0x%x, "%(val)
|
||||||
if (i + 1) % 16 == 0:
|
if (i + 1) % 16 == 0:
|
||||||
array_str += "\n"
|
array_str += "\n"
|
||||||
@ -21,12 +23,12 @@ def get_wave_array_str(filename, target_bits):
|
|||||||
|
|
||||||
def gen_wave_table(wav_file_list, target_file_name, scale_bits = 8):
|
def gen_wave_table(wav_file_list, target_file_name, scale_bits = 8):
|
||||||
with open(target_file_name, "w") as audio_table:
|
with open(target_file_name, "w") as audio_table:
|
||||||
print >> audio_table, '#include <stdio.h>'
|
print('#include <stdio.h>', file=audio_table)
|
||||||
print >> audio_table, 'const unsigned char audio_table[] = {'
|
print('const unsigned char audio_table[] = {', file=audio_table)
|
||||||
for wav in wav_file_list:
|
for wav in wav_file_list:
|
||||||
print("processing: {}".format(wav))
|
print("processing: {}".format(wav))
|
||||||
print >> audio_table, get_wave_array_str(filename = wav, target_bits = scale_bits)
|
print(get_wave_array_str(filename = wav, target_bits = scale_bits), file=audio_table)
|
||||||
print >>audio_table,'};\n'
|
print('};\n', file=audio_table)
|
||||||
print("Done...")
|
print("Done...")
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
import imp
|
import imp
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@ -34,6 +37,7 @@ if test_fw_path and test_fw_path not in sys.path:
|
|||||||
|
|
||||||
import TinyFW
|
import TinyFW
|
||||||
import IDF
|
import IDF
|
||||||
|
import Utility
|
||||||
|
|
||||||
# Import client module
|
# Import client module
|
||||||
expath = os.path.dirname(os.path.realpath(__file__))
|
expath = os.path.dirname(os.path.realpath(__file__))
|
||||||
@ -53,15 +57,15 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||||||
# Get binary file
|
# Get binary file
|
||||||
binary_file = os.path.join(dut1.app.binary_path, "tests.bin")
|
binary_file = os.path.join(dut1.app.binary_path, "tests.bin")
|
||||||
bin_size = os.path.getsize(binary_file)
|
bin_size = os.path.getsize(binary_file)
|
||||||
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size/1024))
|
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size//1024))
|
||||||
IDF.check_performance("http_server_bin_size", bin_size/1024)
|
IDF.check_performance("http_server_bin_size", bin_size//1024)
|
||||||
|
|
||||||
# Upload binary and start testing
|
# Upload binary and start testing
|
||||||
print "Starting http_server advanced test app"
|
Utility.console_log("Starting http_server advanced test app")
|
||||||
dut1.start_app()
|
dut1.start_app()
|
||||||
|
|
||||||
# Parse IP address of STA
|
# 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_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]
|
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Started HTTP server on port: '(\d+)'"), timeout=15)[0]
|
||||||
@ -72,18 +76,18 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||||||
max_uri_len = int(result[3])
|
max_uri_len = int(result[3])
|
||||||
max_stack_size = int(result[4])
|
max_stack_size = int(result[4])
|
||||||
|
|
||||||
print "Got IP : " + got_ip
|
Utility.console_log("Got IP : " + got_ip)
|
||||||
print "Got Port : " + got_port
|
Utility.console_log("Got Port : " + got_port)
|
||||||
|
|
||||||
# Run test script
|
# Run test script
|
||||||
# If failed raise appropriate exception
|
# If failed raise appropriate exception
|
||||||
failed = False
|
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):
|
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):
|
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):
|
if not client.leftover_data_test(got_ip, got_port):
|
||||||
failed = True
|
failed = True
|
||||||
if not client.async_response_test(got_ip, got_port):
|
if not client.async_response_test(got_ip, got_port):
|
||||||
@ -94,19 +98,19 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||||||
## This test fails a lot! Enable when connection is stable
|
## This test fails a lot! Enable when connection is stable
|
||||||
#test_size = 50*1024 # 50KB
|
#test_size = 50*1024 # 50KB
|
||||||
#if not client.packet_size_limit_test(got_ip, got_port, test_size):
|
#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):
|
if not client.get_hello(got_ip, got_port):
|
||||||
failed = True
|
failed = True
|
||||||
|
|
||||||
inital_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: '(\d+)'"), timeout=15)[0])
|
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:
|
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
|
failed = True
|
||||||
|
|
||||||
print "Basic HTTP Client Tests..."
|
Utility.console_log("Basic HTTP Client Tests...")
|
||||||
if not client.get_hello(got_ip, got_port):
|
if not client.get_hello(got_ip, got_port):
|
||||||
failed = True
|
failed = True
|
||||||
if not client.post_hello(got_ip, got_port):
|
if not client.post_hello(got_ip, got_port):
|
||||||
@ -126,7 +130,7 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||||||
if not client.get_false_uri(got_ip, got_port):
|
if not client.get_false_uri(got_ip, got_port):
|
||||||
failed = True
|
failed = True
|
||||||
|
|
||||||
print "Error code tests..."
|
Utility.console_log("Error code tests...")
|
||||||
if not client.code_500_server_error_test(got_ip, got_port):
|
if not client.code_500_server_error_test(got_ip, got_port):
|
||||||
failed = True
|
failed = True
|
||||||
if not client.code_501_method_not_impl(got_ip, got_port):
|
if not client.code_501_method_not_impl(got_ip, got_port):
|
||||||
@ -142,20 +146,20 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
|||||||
if not client.code_408_req_timeout(got_ip, got_port):
|
if not client.code_408_req_timeout(got_ip, got_port):
|
||||||
failed = True
|
failed = True
|
||||||
if not client.code_414_uri_too_long(got_ip, got_port, max_uri_len):
|
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):
|
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):
|
if not client.test_upgrade_not_supported(got_ip, got_port):
|
||||||
failed = True
|
failed = True
|
||||||
|
|
||||||
print "Getting final stack usage..."
|
Utility.console_log("Getting final stack usage...")
|
||||||
if not client.get_hello(got_ip, got_port):
|
if not client.get_hello(got_ip, got_port):
|
||||||
failed = True
|
failed = True
|
||||||
|
|
||||||
final_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: '(\d+)'"), timeout=15)[0])
|
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:
|
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
|
failed = True
|
||||||
|
|
||||||
if failed:
|
if failed:
|
||||||
|
@ -129,18 +129,26 @@
|
|||||||
# - Simple GET on /hello/restart_results (returns the leak results)
|
# - Simple GET on /hello/restart_results (returns the leak results)
|
||||||
|
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
from builtins import str
|
||||||
|
from builtins import range
|
||||||
|
from builtins import object
|
||||||
import threading
|
import threading
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
import argparse
|
import argparse
|
||||||
import httplib
|
import http.client
|
||||||
import sys
|
import sys
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
import Utility
|
||||||
|
|
||||||
_verbose_ = False
|
_verbose_ = False
|
||||||
|
|
||||||
class Session:
|
class Session(object):
|
||||||
def __init__(self, addr, port, timeout = 15):
|
def __init__(self, addr, port, timeout = 15):
|
||||||
self.client = socket.create_connection((addr, int(port)), timeout = timeout)
|
self.client = socket.create_connection((addr, int(port)), timeout = timeout)
|
||||||
self.target = addr
|
self.target = addr
|
||||||
@ -152,19 +160,19 @@ class Session:
|
|||||||
def send_err_check(self, request, data=None):
|
def send_err_check(self, request, data=None):
|
||||||
rval = True
|
rval = True
|
||||||
try:
|
try:
|
||||||
self.client.sendall(request);
|
self.client.sendall(request.encode());
|
||||||
if data:
|
if data:
|
||||||
self.client.sendall(data)
|
self.client.sendall(data.encode())
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
self.client.close()
|
self.client.close()
|
||||||
print "Socket Error in send :", err
|
Utility.console_log("Socket Error in send :", err)
|
||||||
rval = False
|
rval = False
|
||||||
return rval
|
return rval
|
||||||
|
|
||||||
def send_get(self, path, headers=None):
|
def send_get(self, path, headers=None):
|
||||||
request = "GET " + path + " HTTP/1.1\r\nHost: " + self.target
|
request = "GET " + path + " HTTP/1.1\r\nHost: " + self.target
|
||||||
if headers:
|
if headers:
|
||||||
for field, value in headers.iteritems():
|
for field, value in headers.items():
|
||||||
request += "\r\n"+field+": "+value
|
request += "\r\n"+field+": "+value
|
||||||
request += "\r\n\r\n"
|
request += "\r\n\r\n"
|
||||||
return self.send_err_check(request)
|
return self.send_err_check(request)
|
||||||
@ -172,7 +180,7 @@ class Session:
|
|||||||
def send_put(self, path, data, headers=None):
|
def send_put(self, path, data, headers=None):
|
||||||
request = "PUT " + path + " HTTP/1.1\r\nHost: " + self.target
|
request = "PUT " + path + " HTTP/1.1\r\nHost: " + self.target
|
||||||
if headers:
|
if headers:
|
||||||
for field, value in headers.iteritems():
|
for field, value in headers.items():
|
||||||
request += "\r\n"+field+": "+value
|
request += "\r\n"+field+": "+value
|
||||||
request += "\r\nContent-Length: " + str(len(data)) +"\r\n\r\n"
|
request += "\r\nContent-Length: " + str(len(data)) +"\r\n\r\n"
|
||||||
return self.send_err_check(request, data)
|
return self.send_err_check(request, data)
|
||||||
@ -180,7 +188,7 @@ class Session:
|
|||||||
def send_post(self, path, data, headers=None):
|
def send_post(self, path, data, headers=None):
|
||||||
request = "POST " + path + " HTTP/1.1\r\nHost: " + self.target
|
request = "POST " + path + " HTTP/1.1\r\nHost: " + self.target
|
||||||
if headers:
|
if headers:
|
||||||
for field, value in headers.iteritems():
|
for field, value in headers.items():
|
||||||
request += "\r\n"+field+": "+value
|
request += "\r\n"+field+": "+value
|
||||||
request += "\r\nContent-Length: " + str(len(data)) +"\r\n\r\n"
|
request += "\r\nContent-Length: " + str(len(data)) +"\r\n\r\n"
|
||||||
return self.send_err_check(request, data)
|
return self.send_err_check(request, data)
|
||||||
@ -190,7 +198,7 @@ class Session:
|
|||||||
state = 'nothing'
|
state = 'nothing'
|
||||||
resp_read = ''
|
resp_read = ''
|
||||||
while True:
|
while True:
|
||||||
char = self.client.recv(1)
|
char = self.client.recv(1).decode()
|
||||||
if char == '\r' and state == 'nothing':
|
if char == '\r' and state == 'nothing':
|
||||||
state = 'first_cr'
|
state = 'first_cr'
|
||||||
elif char == '\n' and state == 'first_cr':
|
elif char == '\n' and state == 'first_cr':
|
||||||
@ -226,7 +234,7 @@ class Session:
|
|||||||
return headers
|
return headers
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
self.client.close()
|
self.client.close()
|
||||||
print "Socket Error in recv :", err
|
Utility.console_log("Socket Error in recv :", err)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def read_resp_data(self):
|
def read_resp_data(self):
|
||||||
@ -234,7 +242,7 @@ class Session:
|
|||||||
read_data = ''
|
read_data = ''
|
||||||
if self.encoding != 'chunked':
|
if self.encoding != 'chunked':
|
||||||
while len(read_data) != self.content_len:
|
while len(read_data) != self.content_len:
|
||||||
read_data += self.client.recv(self.content_len)
|
read_data += self.client.recv(self.content_len).decode()
|
||||||
else:
|
else:
|
||||||
chunk_data_buf = ''
|
chunk_data_buf = ''
|
||||||
while (True):
|
while (True):
|
||||||
@ -242,7 +250,7 @@ class Session:
|
|||||||
read_ch = self.client.recv(1)
|
read_ch = self.client.recv(1)
|
||||||
# Check CRLF
|
# Check CRLF
|
||||||
if (read_ch == '\r'):
|
if (read_ch == '\r'):
|
||||||
read_ch = self.client.recv(1)
|
read_ch = self.client.recv(1).decode()
|
||||||
if (read_ch == '\n'):
|
if (read_ch == '\n'):
|
||||||
# If CRLF decode length of chunk
|
# If CRLF decode length of chunk
|
||||||
chunk_len = int(chunk_data_buf, 16)
|
chunk_len = int(chunk_data_buf, 16)
|
||||||
@ -257,7 +265,7 @@ class Session:
|
|||||||
# Fetch remaining CRLF
|
# Fetch remaining CRLF
|
||||||
if self.client.recv(2) != "\r\n":
|
if self.client.recv(2) != "\r\n":
|
||||||
# Error in packet
|
# Error in packet
|
||||||
print "Error in chunked data"
|
Utility.console_log("Error in chunked data")
|
||||||
return None
|
return None
|
||||||
if not chunk_len:
|
if not chunk_len:
|
||||||
# If last chunk
|
# If last chunk
|
||||||
@ -270,7 +278,7 @@ class Session:
|
|||||||
return read_data
|
return read_data
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
self.client.close()
|
self.client.close()
|
||||||
print "Socket Error in recv :", err
|
Utility.console_log("Socket Error in recv :", err)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
@ -278,10 +286,10 @@ class Session:
|
|||||||
|
|
||||||
def test_val(text, expected, received):
|
def test_val(text, expected, received):
|
||||||
if expected != received:
|
if expected != received:
|
||||||
print " Fail!"
|
Utility.console_log(" Fail!")
|
||||||
print " [reason] " + text + ":"
|
Utility.console_log(" [reason] " + text + ":")
|
||||||
print " expected: " + str(expected)
|
Utility.console_log(" expected: " + str(expected))
|
||||||
print " received: " + str(received)
|
Utility.console_log(" received: " + str(received))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -298,7 +306,7 @@ class adder_thread (threading.Thread):
|
|||||||
|
|
||||||
# Pipeline 3 requests
|
# Pipeline 3 requests
|
||||||
if (_verbose_):
|
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):
|
for _ in range(self.depth):
|
||||||
self.session.send_post('/adder', str(self.id))
|
self.session.send_post('/adder', str(self.id))
|
||||||
@ -310,7 +318,7 @@ class adder_thread (threading.Thread):
|
|||||||
|
|
||||||
def adder_result(self):
|
def adder_result(self):
|
||||||
if len(self.response) != self.depth:
|
if len(self.response) != self.depth:
|
||||||
print "Error : missing response packets"
|
Utility.console_log("Error : missing response packets")
|
||||||
return False
|
return False
|
||||||
for i in range(len(self.response)):
|
for i in range(len(self.response)):
|
||||||
if not test_val("Thread" + str(self.id) + " response[" + str(i) + "]",
|
if not test_val("Thread" + str(self.id) + " response[" + str(i) + "]",
|
||||||
@ -323,166 +331,166 @@ class adder_thread (threading.Thread):
|
|||||||
|
|
||||||
def get_hello(dut, port):
|
def get_hello(dut, port):
|
||||||
# GET /hello should return 'Hello World!'
|
# GET /hello should return 'Hello World!'
|
||||||
print "[test] GET /hello returns 'Hello World!' =>",
|
Utility.console_log("[test] GET /hello returns 'Hello World!' =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("GET", "/hello")
|
conn.request("GET", "/hello")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 200, resp.status):
|
if not test_val("status_code", 200, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
if not test_val("data", "Hello World!", resp.read()):
|
if not test_val("data", "Hello World!", resp.read().decode()):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
if not test_val("data", "application/json", resp.getheader('Content-Type')):
|
if not test_val("data", "application/json", resp.getheader('Content-Type')):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def put_hello(dut, port):
|
def put_hello(dut, port):
|
||||||
# PUT /hello returns 405'
|
# PUT /hello returns 405'
|
||||||
print "[test] PUT /hello returns 405' =>",
|
Utility.console_log("[test] PUT /hello returns 405' =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("PUT", "/hello", "Hello")
|
conn.request("PUT", "/hello", "Hello")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 405, resp.status):
|
if not test_val("status_code", 405, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def post_hello(dut, port):
|
def post_hello(dut, port):
|
||||||
# POST /hello returns 405'
|
# POST /hello returns 405'
|
||||||
print "[test] POST /hello returns 404' =>",
|
Utility.console_log("[test] POST /hello returns 404' =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("POST", "/hello", "Hello")
|
conn.request("POST", "/hello", "Hello")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 405, resp.status):
|
if not test_val("status_code", 405, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def post_echo(dut, port):
|
def post_echo(dut, port):
|
||||||
# POST /echo echoes data'
|
# POST /echo echoes data'
|
||||||
print "[test] POST /echo echoes data' =>",
|
Utility.console_log("[test] POST /echo echoes data' =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("POST", "/echo", "Hello")
|
conn.request("POST", "/echo", "Hello")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 200, resp.status):
|
if not test_val("status_code", 200, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
if not test_val("data", "Hello", resp.read()):
|
if not test_val("data", "Hello", resp.read().decode()):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def put_echo(dut, port):
|
def put_echo(dut, port):
|
||||||
# PUT /echo echoes data'
|
# PUT /echo echoes data'
|
||||||
print "[test] PUT /echo echoes data' =>",
|
Utility.console_log("[test] PUT /echo echoes data' =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("PUT", "/echo", "Hello")
|
conn.request("PUT", "/echo", "Hello")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 200, resp.status):
|
if not test_val("status_code", 200, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
if not test_val("data", "Hello", resp.read()):
|
if not test_val("data", "Hello", resp.read().decode()):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_echo(dut, port):
|
def get_echo(dut, port):
|
||||||
# GET /echo returns 404'
|
# GET /echo returns 404'
|
||||||
print "[test] GET /echo returns 405' =>",
|
Utility.console_log("[test] GET /echo returns 405' =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("GET", "/echo")
|
conn.request("GET", "/echo")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 405, resp.status):
|
if not test_val("status_code", 405, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_hello_type(dut, port):
|
def get_hello_type(dut, port):
|
||||||
# GET /hello/type_html returns text/html as Content-Type'
|
# GET /hello/type_html returns text/html as Content-Type'
|
||||||
print "[test] GET /hello/type_html has Content-Type of text/html =>",
|
Utility.console_log("[test] GET /hello/type_html has Content-Type of text/html =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("GET", "/hello/type_html")
|
conn.request("GET", "/hello/type_html")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 200, resp.status):
|
if not test_val("status_code", 200, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
if not test_val("data", "Hello World!", resp.read()):
|
if not test_val("data", "Hello World!", resp.read().decode()):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
if not test_val("data", "text/html", resp.getheader('Content-Type')):
|
if not test_val("data", "text/html", resp.getheader('Content-Type')):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_hello_status(dut, port):
|
def get_hello_status(dut, port):
|
||||||
# GET /hello/status_500 returns status 500'
|
# GET /hello/status_500 returns status 500'
|
||||||
print "[test] GET /hello/status_500 returns status 500 =>",
|
Utility.console_log("[test] GET /hello/status_500 returns status 500 =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("GET", "/hello/status_500")
|
conn.request("GET", "/hello/status_500")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 500, resp.status):
|
if not test_val("status_code", 500, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def get_false_uri(dut, port):
|
def get_false_uri(dut, port):
|
||||||
# GET /false_uri returns status 404'
|
# GET /false_uri returns status 404'
|
||||||
print "[test] GET /false_uri returns status 404 =>",
|
Utility.console_log("[test] GET /false_uri returns status 404 =>", end=' ')
|
||||||
conn = httplib.HTTPConnection(dut, int(port), timeout=15)
|
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||||
conn.request("GET", "/false_uri")
|
conn.request("GET", "/false_uri")
|
||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
if not test_val("status_code", 404, resp.status):
|
if not test_val("status_code", 404, resp.status):
|
||||||
conn.close()
|
conn.close()
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def parallel_sessions_adder(dut, port, max_sessions):
|
def parallel_sessions_adder(dut, port, max_sessions):
|
||||||
# POSTs on /adder in parallel sessions
|
# POSTs on /adder in parallel sessions
|
||||||
print "[test] POST {pipelined} on /adder in " + str(max_sessions) + " sessions =>",
|
Utility.console_log("[test] POST {pipelined} on /adder in " + str(max_sessions) + " sessions =>", end=' ')
|
||||||
t = []
|
t = []
|
||||||
# Create all sessions
|
# Create all sessions
|
||||||
for i in xrange(max_sessions):
|
for i in range(max_sessions):
|
||||||
t.append(adder_thread(i, dut, port))
|
t.append(adder_thread(i, dut, port))
|
||||||
|
|
||||||
for i in xrange(len(t)):
|
for i in range(len(t)):
|
||||||
t[i].start()
|
t[i].start()
|
||||||
|
|
||||||
for i in xrange(len(t)):
|
for i in range(len(t)):
|
||||||
t[i].join()
|
t[i].join()
|
||||||
|
|
||||||
res = True
|
res = True
|
||||||
for i in xrange(len(t)):
|
for i in range(len(t)):
|
||||||
if not test_val("Thread" + str(i) + " Failed", t[i].adder_result(), True):
|
if not test_val("Thread" + str(i) + " Failed", t[i].adder_result(), True):
|
||||||
res = False
|
res = False
|
||||||
t[i].close()
|
t[i].close()
|
||||||
if (res):
|
if (res):
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def async_response_test(dut, port):
|
def async_response_test(dut, port):
|
||||||
# Test that an asynchronous work is executed in the HTTPD's context
|
# Test that an asynchronous work is executed in the HTTPD's context
|
||||||
# This is tested by reading two responses over the same session
|
# This is tested by reading two responses over the same session
|
||||||
print "[test] Test HTTPD Work Queue (Async response) =>",
|
Utility.console_log("[test] Test HTTPD Work Queue (Async response) =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
|
|
||||||
s.send_get('/async_data')
|
s.send_get('/async_data')
|
||||||
@ -495,23 +503,23 @@ def async_response_test(dut, port):
|
|||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def leftover_data_test(dut, port):
|
def leftover_data_test(dut, port):
|
||||||
# Leftover data in POST is purged (valid and invalid URIs)
|
# Leftover data in POST is purged (valid and invalid URIs)
|
||||||
print "[test] Leftover data in POST is purged (valid and invalid URIs) =>",
|
Utility.console_log("[test] Leftover data in POST is purged (valid and invalid URIs) =>", end=' ')
|
||||||
s = httplib.HTTPConnection(dut + ":" + port, timeout=15)
|
s = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||||
|
|
||||||
s.request("POST", url='/leftover_data', body="abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz")
|
s.request("POST", url='/leftover_data', body="abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz")
|
||||||
resp = s.getresponse()
|
resp = s.getresponse()
|
||||||
if not test_val("Partial data", "abcdefghij", resp.read()):
|
if not test_val("Partial data", "abcdefghij", resp.read().decode()):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
s.request("GET", url='/hello')
|
s.request("GET", url='/hello')
|
||||||
resp = s.getresponse()
|
resp = s.getresponse()
|
||||||
if not test_val("Hello World Data", "Hello World!", resp.read()):
|
if not test_val("Hello World Data", "Hello World!", resp.read().decode()):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -524,33 +532,33 @@ def leftover_data_test(dut, port):
|
|||||||
|
|
||||||
s.request("GET", url='/hello')
|
s.request("GET", url='/hello')
|
||||||
resp = s.getresponse()
|
resp = s.getresponse()
|
||||||
if not test_val("Hello World Data", "Hello World!", resp.read()):
|
if not test_val("Hello World Data", "Hello World!", resp.read().decode()):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def spillover_session(dut, port, max_sess):
|
def spillover_session(dut, port, max_sess):
|
||||||
# Session max_sess_sessions + 1 is rejected
|
# Session max_sess_sessions + 1 is rejected
|
||||||
print "[test] Session max_sess_sessions (" + str(max_sess) + ") + 1 is rejected =>",
|
Utility.console_log("[test] Session max_sess_sessions (" + str(max_sess) + ") + 1 is rejected =>", end=' ')
|
||||||
s = []
|
s = []
|
||||||
_verbose_ = True
|
_verbose_ = True
|
||||||
for i in xrange(max_sess + 1):
|
for i in range(max_sess + 1):
|
||||||
if (_verbose_):
|
if (_verbose_):
|
||||||
print "Executing " + str(i)
|
Utility.console_log("Executing " + str(i))
|
||||||
try:
|
try:
|
||||||
a = httplib.HTTPConnection(dut + ":" + port, timeout=15)
|
a = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||||
a.request("GET", url='/hello')
|
a.request("GET", url='/hello')
|
||||||
resp = a.getresponse()
|
resp = a.getresponse()
|
||||||
if not test_val("Connection " + str(i), "Hello World!", resp.read()):
|
if not test_val("Connection " + str(i), "Hello World!", resp.read().decode()):
|
||||||
a.close()
|
a.close()
|
||||||
break
|
break
|
||||||
s.append(a)
|
s.append(a)
|
||||||
except:
|
except:
|
||||||
if (_verbose_):
|
if (_verbose_):
|
||||||
print "Connection " + str(i) + " rejected"
|
Utility.console_log("Connection " + str(i) + " rejected")
|
||||||
a.close()
|
a.close()
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -559,59 +567,59 @@ def spillover_session(dut, port, max_sess):
|
|||||||
a.close()
|
a.close()
|
||||||
|
|
||||||
# Check if number of connections is equal to max_sess
|
# 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)
|
return (len(s) == max_sess)
|
||||||
|
|
||||||
def recv_timeout_test(dut, port):
|
def recv_timeout_test(dut, port):
|
||||||
print "[test] Timeout occurs if partial packet sent =>",
|
Utility.console_log("[test] Timeout occurs if partial packet sent =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
s.client.sendall("GE")
|
s.client.sendall(b"GE")
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
if not test_val("Request Timeout", "Server closed this connection", resp):
|
if not test_val("Request Timeout", "Server closed this connection", resp):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def packet_size_limit_test(dut, port, test_size):
|
def packet_size_limit_test(dut, port, test_size):
|
||||||
print "[test] send size limit test =>",
|
Utility.console_log("[test] send size limit test =>", end=' ')
|
||||||
retry = 5
|
retry = 5
|
||||||
while (retry):
|
while (retry):
|
||||||
retry -= 1
|
retry -= 1
|
||||||
print "data size = ", test_size
|
Utility.console_log("data size = ", test_size)
|
||||||
s = httplib.HTTPConnection(dut + ":" + port, timeout=15)
|
s = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable))-1] for _ in range(test_size))
|
random_data = ''.join(string.printable[random.randint(0,len(string.printable))-1] for _ in list(range(test_size)))
|
||||||
path = "/echo"
|
path = "/echo"
|
||||||
s.request("POST", url=path, body=random_data)
|
s.request("POST", url=path, body=random_data)
|
||||||
resp = s.getresponse()
|
resp = s.getresponse()
|
||||||
if not test_val("Error", "200", str(resp.status)):
|
if not test_val("Error", "200", str(resp.status)):
|
||||||
if test_val("Error", "408", 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
|
test_size = test_size//10
|
||||||
else:
|
else:
|
||||||
print "Unexpected error"
|
Utility.console_log("Unexpected error")
|
||||||
s.close()
|
s.close()
|
||||||
print "Retry..."
|
Utility.console_log("Retry...")
|
||||||
continue
|
continue
|
||||||
resp = resp.read()
|
resp = resp.read().decode()
|
||||||
result = (resp == random_data)
|
result = (resp == random_data)
|
||||||
if not result:
|
if not result:
|
||||||
test_val("Data size", str(len(random_data)), str(len(resp)))
|
test_val("Data size", str(len(random_data)), str(len(resp)))
|
||||||
s.close()
|
s.close()
|
||||||
print "Retry..."
|
Utility.console_log("Retry...")
|
||||||
continue
|
continue
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
print "Failed"
|
Utility.console_log("Failed")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def code_500_server_error_test(dut, port):
|
def code_500_server_error_test(dut, port):
|
||||||
print "[test] 500 Server Error test =>",
|
Utility.console_log("[test] 500 Server Error test =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
s.client.sendall("abcdefgh\0")
|
s.client.sendall(b"abcdefgh\0")
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
# Presently server sends back 400 Bad Request
|
# Presently server sends back 400 Bad Request
|
||||||
@ -622,14 +630,14 @@ def code_500_server_error_test(dut, port):
|
|||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def code_501_method_not_impl(dut, port):
|
def code_501_method_not_impl(dut, port):
|
||||||
print "[test] 501 Method Not Implemented =>",
|
Utility.console_log("[test] 501 Method Not Implemented =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
path = "/hello"
|
path = "/hello"
|
||||||
s.client.sendall("ABC " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n")
|
s.client.sendall(("ABC " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
# Presently server sends back 400 Bad Request
|
# Presently server sends back 400 Bad Request
|
||||||
@ -640,83 +648,83 @@ def code_501_method_not_impl(dut, port):
|
|||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def code_505_version_not_supported(dut, port):
|
def code_505_version_not_supported(dut, port):
|
||||||
print "[test] 505 Version Not Supported =>",
|
Utility.console_log("[test] 505 Version Not Supported =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
path = "/hello"
|
path = "/hello"
|
||||||
s.client.sendall("GET " + path + " HTTP/2.0\r\nHost: " + dut + "\r\n\r\n")
|
s.client.sendall(("GET " + path + " HTTP/2.0\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
if not test_val("Server Error", "505", s.status):
|
if not test_val("Server Error", "505", s.status):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def code_400_bad_request(dut, port):
|
def code_400_bad_request(dut, port):
|
||||||
print "[test] 400 Bad Request =>",
|
Utility.console_log("[test] 400 Bad Request =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
path = "/hello"
|
path = "/hello"
|
||||||
s.client.sendall("XYZ " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n")
|
s.client.sendall(("XYZ " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
if not test_val("Client Error", "400", s.status):
|
if not test_val("Client Error", "400", s.status):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def code_404_not_found(dut, port):
|
def code_404_not_found(dut, port):
|
||||||
print "[test] 404 Not Found =>",
|
Utility.console_log("[test] 404 Not Found =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
path = "/dummy"
|
path = "/dummy"
|
||||||
s.client.sendall("GET " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n")
|
s.client.sendall(("GET " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
if not test_val("Client Error", "404", s.status):
|
if not test_val("Client Error", "404", s.status):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def code_405_method_not_allowed(dut, port):
|
def code_405_method_not_allowed(dut, port):
|
||||||
print "[test] 405 Method Not Allowed =>",
|
Utility.console_log("[test] 405 Method Not Allowed =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
path = "/hello"
|
path = "/hello"
|
||||||
s.client.sendall("POST " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n")
|
s.client.sendall(("POST " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
if not test_val("Client Error", "405", s.status):
|
if not test_val("Client Error", "405", s.status):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def code_408_req_timeout(dut, port):
|
def code_408_req_timeout(dut, port):
|
||||||
print "[test] 408 Request Timeout =>",
|
Utility.console_log("[test] 408 Request Timeout =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
s.client.sendall("POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: 10\r\n\r\nABCD")
|
s.client.sendall(("POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: 10\r\n\r\nABCD").encode())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
if not test_val("Client Error", "408", s.status):
|
if not test_val("Client Error", "408", s.status):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def code_411_length_required(dut, port):
|
def code_411_length_required(dut, port):
|
||||||
print "[test] 411 Length Required =>",
|
Utility.console_log("[test] 411 Length Required =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
path = "/echo"
|
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")
|
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())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
# Presently server sends back 400 Bad Request
|
# Presently server sends back 400 Bad Request
|
||||||
@ -727,7 +735,7 @@ def code_411_length_required(dut, port):
|
|||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def send_getx_uri_len(dut, port, length):
|
def send_getx_uri_len(dut, port, length):
|
||||||
@ -735,25 +743,25 @@ def send_getx_uri_len(dut, port, length):
|
|||||||
method = "GET "
|
method = "GET "
|
||||||
version = " HTTP/1.1\r\n"
|
version = " HTTP/1.1\r\n"
|
||||||
path = "/"+"x"*(length - len(method) - len(version) - len("/"))
|
path = "/"+"x"*(length - len(method) - len(version) - len("/"))
|
||||||
s.client.sendall(method)
|
s.client.sendall(method.encode())
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
s.client.sendall(path)
|
s.client.sendall(path.encode())
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
s.client.sendall(version + "Host: " + dut + "\r\n\r\n")
|
s.client.sendall((version + "Host: " + dut + "\r\n\r\n").encode())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
s.close()
|
s.close()
|
||||||
return s.status
|
return s.status
|
||||||
|
|
||||||
def code_414_uri_too_long(dut, port, max_uri_len):
|
def code_414_uri_too_long(dut, port, max_uri_len):
|
||||||
print "[test] 414 URI Too Long =>",
|
Utility.console_log("[test] 414 URI Too Long =>", end=' ')
|
||||||
status = send_getx_uri_len(dut, port, max_uri_len)
|
status = send_getx_uri_len(dut, port, max_uri_len)
|
||||||
if not test_val("Client Error", "404", status):
|
if not test_val("Client Error", "404", status):
|
||||||
return False
|
return False
|
||||||
status = send_getx_uri_len(dut, port, max_uri_len + 1)
|
status = send_getx_uri_len(dut, port, max_uri_len + 1)
|
||||||
if not test_val("Client Error", "414", status):
|
if not test_val("Client Error", "414", status):
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def send_postx_hdr_len(dut, port, length):
|
def send_postx_hdr_len(dut, port, length):
|
||||||
@ -762,10 +770,10 @@ def send_postx_hdr_len(dut, port, length):
|
|||||||
host = "Host: " + dut
|
host = "Host: " + dut
|
||||||
custom_hdr_field = "\r\nCustom: "
|
custom_hdr_field = "\r\nCustom: "
|
||||||
custom_hdr_val = "x"*(length - len(host) - len(custom_hdr_field) - len("\r\n\r\n") + len("0"))
|
custom_hdr_val = "x"*(length - len(host) - len(custom_hdr_field) - len("\r\n\r\n") + len("0"))
|
||||||
request = "POST " + path + " HTTP/1.1\r\n" + host + custom_hdr_field + custom_hdr_val + "\r\n\r\n"
|
request = ("POST " + path + " HTTP/1.1\r\n" + host + custom_hdr_field + custom_hdr_val + "\r\n\r\n").encode()
|
||||||
s.client.sendall(request[:length/2])
|
s.client.sendall(request[:length//2])
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
s.client.sendall(request[length/2:])
|
s.client.sendall(request[length//2:])
|
||||||
hdr = s.read_resp_hdrs()
|
hdr = s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
s.close()
|
s.close()
|
||||||
@ -774,28 +782,28 @@ def send_postx_hdr_len(dut, port, length):
|
|||||||
return False, s.status
|
return False, s.status
|
||||||
|
|
||||||
def code_431_hdr_too_long(dut, port, max_hdr_len):
|
def code_431_hdr_too_long(dut, port, max_hdr_len):
|
||||||
print "[test] 431 Header Too Long =>",
|
Utility.console_log("[test] 431 Header Too Long =>", end=' ')
|
||||||
res, status = send_postx_hdr_len(dut, port, max_hdr_len)
|
res, status = send_postx_hdr_len(dut, port, max_hdr_len)
|
||||||
if not res:
|
if not res:
|
||||||
return False
|
return False
|
||||||
res, status = send_postx_hdr_len(dut, port, max_hdr_len + 1)
|
res, status = send_postx_hdr_len(dut, port, max_hdr_len + 1)
|
||||||
if not test_val("Client Error", "431", status):
|
if not test_val("Client Error", "431", status):
|
||||||
return False
|
return False
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def test_upgrade_not_supported(dut, port):
|
def test_upgrade_not_supported(dut, port):
|
||||||
print "[test] Upgrade Not Supported =>",
|
Utility.console_log("[test] Upgrade Not Supported =>", end=' ')
|
||||||
s = Session(dut, port)
|
s = Session(dut, port)
|
||||||
path = "/hello"
|
path = "/hello"
|
||||||
s.client.sendall("OPTIONS * HTTP/1.1\r\nHost:" + dut + "\r\nUpgrade: TLS/1.0\r\nConnection: Upgrade\r\n\r\n");
|
s.client.sendall(("OPTIONS * HTTP/1.1\r\nHost:" + dut + "\r\nUpgrade: TLS/1.0\r\nConnection: Upgrade\r\n\r\n").encode())
|
||||||
s.read_resp_hdrs()
|
s.read_resp_hdrs()
|
||||||
resp = s.read_resp_data()
|
resp = s.read_resp_data()
|
||||||
if not test_val("Client Error", "200", s.status):
|
if not test_val("Client Error", "200", s.status):
|
||||||
s.close()
|
s.close()
|
||||||
return False
|
return False
|
||||||
s.close()
|
s.close()
|
||||||
print "Success"
|
Utility.console_log("Success")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -819,7 +827,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
_verbose_ = True
|
_verbose_ = True
|
||||||
|
|
||||||
print "### Basic HTTP Client Tests"
|
Utility.console_log("### Basic HTTP Client Tests")
|
||||||
get_hello(dut, port)
|
get_hello(dut, port)
|
||||||
post_hello(dut, port)
|
post_hello(dut, port)
|
||||||
put_hello(dut, port)
|
put_hello(dut, port)
|
||||||
@ -830,7 +838,7 @@ if __name__ == '__main__':
|
|||||||
get_hello_status(dut, port)
|
get_hello_status(dut, port)
|
||||||
get_false_uri(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_500_server_error_test(dut, port)
|
||||||
code_501_method_not_impl(dut, port)
|
code_501_method_not_impl(dut, port)
|
||||||
code_505_version_not_supported(dut, port)
|
code_505_version_not_supported(dut, port)
|
||||||
@ -845,7 +853,7 @@ if __name__ == '__main__':
|
|||||||
# Not supported yet (Error on chunked request)
|
# Not supported yet (Error on chunked request)
|
||||||
###code_411_length_required(dut, port)
|
###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)
|
parallel_sessions_adder(dut, port, max_sessions)
|
||||||
leftover_data_test(dut, port)
|
leftover_data_test(dut, port)
|
||||||
async_response_test(dut, port)
|
async_response_test(dut, port)
|
||||||
|
@ -14,6 +14,11 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from builtins import str
|
||||||
|
from builtins import range
|
||||||
import imp
|
import imp
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@ -34,6 +39,7 @@ if test_fw_path and test_fw_path not in sys.path:
|
|||||||
|
|
||||||
import TinyFW
|
import TinyFW
|
||||||
import IDF
|
import IDF
|
||||||
|
import Utility
|
||||||
|
|
||||||
# Import client module
|
# Import client module
|
||||||
expath = os.path.dirname(os.path.realpath(__file__))
|
expath = os.path.dirname(os.path.realpath(__file__))
|
||||||
@ -47,20 +53,20 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
|||||||
# Get binary file
|
# Get binary file
|
||||||
binary_file = os.path.join(dut1.app.binary_path, "persistent_sockets.bin")
|
binary_file = os.path.join(dut1.app.binary_path, "persistent_sockets.bin")
|
||||||
bin_size = os.path.getsize(binary_file)
|
bin_size = os.path.getsize(binary_file)
|
||||||
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size/1024))
|
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size//1024))
|
||||||
IDF.check_performance("http_server_bin_size", bin_size/1024)
|
IDF.check_performance("http_server_bin_size", bin_size//1024)
|
||||||
|
|
||||||
# Upload binary and start testing
|
# Upload binary and start testing
|
||||||
print "Starting http_server persistance test app"
|
Utility.console_log("Starting http_server persistance test app")
|
||||||
dut1.start_app()
|
dut1.start_app()
|
||||||
|
|
||||||
# Parse IP address of STA
|
# 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_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]
|
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Starting server on port: '(\d+)'"), timeout=30)[0]
|
||||||
|
|
||||||
print "Got IP : " + got_ip
|
Utility.console_log("Got IP : " + got_ip)
|
||||||
print "Got Port : " + got_port
|
Utility.console_log("Got Port : " + got_port)
|
||||||
|
|
||||||
# Expected Logs
|
# Expected Logs
|
||||||
dut1.expect("Registering URI handlers", timeout=30)
|
dut1.expect("Registering URI handlers", timeout=30)
|
||||||
@ -80,7 +86,7 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
|||||||
|
|
||||||
# Retest PUT request and change session context value
|
# Retest PUT request and change session context value
|
||||||
num = random.randint(0,100)
|
num = random.randint(0,100)
|
||||||
print "Adding :", num
|
Utility.console_log("Adding: " + str(num))
|
||||||
client.putreq(conn, "/adder", str(num))
|
client.putreq(conn, "/adder", str(num))
|
||||||
visitor += 1
|
visitor += 1
|
||||||
adder += num
|
adder += num
|
||||||
@ -98,7 +104,7 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
|||||||
# Test POST request and session persistence
|
# Test POST request and session persistence
|
||||||
random_nums = [random.randint(0,100) for _ in range(100)]
|
random_nums = [random.randint(0,100) for _ in range(100)]
|
||||||
for num in random_nums:
|
for num in random_nums:
|
||||||
print "Adding :", num
|
Utility.console_log("Adding: " + str(num))
|
||||||
client.postreq(conn, "/adder", str(num))
|
client.postreq(conn, "/adder", str(num))
|
||||||
visitor += 1
|
visitor += 1
|
||||||
adder += num
|
adder += num
|
||||||
@ -106,19 +112,19 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
|||||||
dut1.expect("/adder handler read " + str(num), timeout=30)
|
dut1.expect("/adder handler read " + str(num), timeout=30)
|
||||||
|
|
||||||
# Test GET request and session persistence
|
# Test GET request and session persistence
|
||||||
print "Matching final sum :", adder
|
Utility.console_log("Matching final sum: " + str(adder))
|
||||||
if client.getreq(conn, "/adder") != str(adder):
|
if client.getreq(conn, "/adder").decode() != str(adder):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
visitor += 1
|
visitor += 1
|
||||||
dut1.expect("/adder visitor count = " + str(visitor), timeout=30)
|
dut1.expect("/adder visitor count = " + str(visitor), timeout=30)
|
||||||
dut1.expect("/adder GET handler send " + str(adder), 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
|
# Close connection and check for invocation of context "Free" function
|
||||||
client.end_session(conn)
|
client.end_session(conn)
|
||||||
dut1.expect("/adder Free Context function called", timeout=30)
|
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
|
# Start another session to check user context data
|
||||||
conn2 = client.start_session(got_ip, got_port)
|
conn2 = client.start_session(got_ip, got_port)
|
||||||
num = random.randint(0,100)
|
num = random.randint(0,100)
|
||||||
|
@ -14,11 +14,17 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import httplib
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
from builtins import str
|
||||||
|
from builtins import range
|
||||||
|
import http.client
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
def start_session (ip, port):
|
def start_session (ip, port):
|
||||||
return httplib.HTTPConnection(ip, int(port), timeout=15)
|
return http.client.HTTPConnection(ip, int(port), timeout=15)
|
||||||
|
|
||||||
def end_session (conn):
|
def end_session (conn):
|
||||||
conn.close()
|
conn.close()
|
||||||
@ -28,11 +34,11 @@ def getreq (conn, path, verbose = False):
|
|||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
data = resp.read()
|
data = resp.read()
|
||||||
if verbose:
|
if verbose:
|
||||||
print "GET : ", path
|
Utility.console_log("GET : " + path)
|
||||||
print "Status : ", resp.status
|
Utility.console_log("Status : " + resp.status)
|
||||||
print "Reason : ", resp.reason
|
Utility.console_log("Reason : " + resp.reason)
|
||||||
print "Data length : ", len(data)
|
Utility.console_log("Data length : " + str(len(data)))
|
||||||
print "Data content : ", data
|
Utility.console_log("Data content : " + data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def postreq (conn, path, data, verbose = False):
|
def postreq (conn, path, data, verbose = False):
|
||||||
@ -40,11 +46,11 @@ def postreq (conn, path, data, verbose = False):
|
|||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
data = resp.read()
|
data = resp.read()
|
||||||
if verbose:
|
if verbose:
|
||||||
print "POST : ", data
|
Utility.console_log("POST : " + data)
|
||||||
print "Status : ", resp.status
|
Utility.console_log("Status : " + resp.status)
|
||||||
print "Reason : ", resp.reason
|
Utility.console_log("Reason : " + resp.reason)
|
||||||
print "Data length : ", len(data)
|
Utility.console_log("Data length : " + str(len(data)))
|
||||||
print "Data content : ", data
|
Utility.console_log("Data content : " + data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def putreq (conn, path, body, verbose = False):
|
def putreq (conn, path, body, verbose = False):
|
||||||
@ -52,11 +58,11 @@ def putreq (conn, path, body, verbose = False):
|
|||||||
resp = conn.getresponse()
|
resp = conn.getresponse()
|
||||||
data = resp.read()
|
data = resp.read()
|
||||||
if verbose:
|
if verbose:
|
||||||
print "PUT : ", path, body
|
Utility.console_log("PUT : " + path, body)
|
||||||
print "Status : ", resp.status
|
Utility.console_log("Status : " + resp.status)
|
||||||
print "Reason : ", resp.reason
|
Utility.console_log("Reason : " + resp.reason)
|
||||||
print "Data length : ", len(data)
|
Utility.console_log("Data length : " + str(len(data)))
|
||||||
print "Data content : ", data
|
Utility.console_log("Data content : " + data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -73,22 +79,22 @@ if __name__ == '__main__':
|
|||||||
N = args['N']
|
N = args['N']
|
||||||
|
|
||||||
# Establish HTTP connection
|
# Establish HTTP connection
|
||||||
print "Connecting to => " + ip + ":" + port
|
Utility.console_log("Connecting to => " + ip + ":" + port)
|
||||||
conn = start_session (ip, port)
|
conn = start_session (ip, port)
|
||||||
|
|
||||||
# Reset adder context to specified value(0)
|
# Reset adder context to specified value(0)
|
||||||
# -- Not needed as new connection will always
|
# -- Not needed as new connection will always
|
||||||
# -- have zero value of the accumulator
|
# -- 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))
|
putreq (conn, "/adder", str(0))
|
||||||
|
|
||||||
# Sum numbers from 1 to specified value(N)
|
# 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 xrange(1, N+1):
|
for i in range(1, N+1):
|
||||||
postreq (conn, "/adder", str(i))
|
postreq (conn, "/adder", str(i))
|
||||||
|
|
||||||
# Fetch the result
|
# Fetch the result
|
||||||
print "Result :", getreq (conn, "/adder")
|
Utility.console_log("Result :" + getreq (conn, "/adder"))
|
||||||
|
|
||||||
# Close HTTP connection
|
# Close HTTP connection
|
||||||
end_session (conn)
|
end_session (conn)
|
||||||
|
@ -14,6 +14,10 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from builtins import range
|
||||||
import imp
|
import imp
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@ -34,6 +38,7 @@ if test_fw_path and test_fw_path not in sys.path:
|
|||||||
|
|
||||||
import TinyFW
|
import TinyFW
|
||||||
import IDF
|
import IDF
|
||||||
|
import Utility
|
||||||
|
|
||||||
# Import client module
|
# Import client module
|
||||||
expath = os.path.dirname(os.path.realpath(__file__))
|
expath = os.path.dirname(os.path.realpath(__file__))
|
||||||
@ -47,27 +52,27 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
|||||||
# Get binary file
|
# Get binary file
|
||||||
binary_file = os.path.join(dut1.app.binary_path, "simple.bin")
|
binary_file = os.path.join(dut1.app.binary_path, "simple.bin")
|
||||||
bin_size = os.path.getsize(binary_file)
|
bin_size = os.path.getsize(binary_file)
|
||||||
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size/1024))
|
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size//1024))
|
||||||
IDF.check_performance("http_server_bin_size", bin_size/1024)
|
IDF.check_performance("http_server_bin_size", bin_size//1024)
|
||||||
|
|
||||||
# Upload binary and start testing
|
# Upload binary and start testing
|
||||||
print "Starting http_server simple test app"
|
Utility.console_log("Starting http_server simple test app")
|
||||||
dut1.start_app()
|
dut1.start_app()
|
||||||
|
|
||||||
# Parse IP address of STA
|
# 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_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]
|
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Starting server on port: '(\d+)'"), timeout=30)[0]
|
||||||
|
|
||||||
print "Got IP : " + got_ip
|
Utility.console_log("Got IP : " + got_ip)
|
||||||
print "Got Port : " + got_port
|
Utility.console_log("Got Port : " + got_port)
|
||||||
|
|
||||||
# Expected Logs
|
# Expected Logs
|
||||||
dut1.expect("Registering URI handlers", timeout=30)
|
dut1.expect("Registering URI handlers", timeout=30)
|
||||||
|
|
||||||
# Run test script
|
# Run test script
|
||||||
# If failed raise appropriate exception
|
# 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):
|
if not client.test_get_handler(got_ip, got_port):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
@ -82,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("Found URL query parameter => query2=value2", timeout=30)
|
||||||
dut1.expect("Request headers lost", 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):
|
if not client.test_put_handler(got_ip, got_port):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
dut1.expect("Unregistering /hello and /echo URIs", timeout=30)
|
dut1.expect("Unregistering /hello and /echo URIs", timeout=30)
|
||||||
@ -90,24 +95,24 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
|||||||
|
|
||||||
# Generate random data of 10KB
|
# Generate random data of 10KB
|
||||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable))-1] for _ in range(10*1024))
|
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):
|
if not client.test_post_handler(got_ip, got_port, random_data):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
query = "http://foobar"
|
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):
|
if not client.test_custom_uri_query(got_ip, got_port, query):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
dut1.expect("Found URL query => " + query, timeout=30)
|
dut1.expect("Found URL query => " + query, timeout=30)
|
||||||
|
|
||||||
query = "abcd+1234%20xyz"
|
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):
|
if not client.test_custom_uri_query(got_ip, got_port, query):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
dut1.expect("Found URL query => " + query, timeout=30)
|
dut1.expect("Found URL query => " + query, timeout=30)
|
||||||
|
|
||||||
query = "abcd\nyz"
|
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):
|
if client.test_custom_uri_query(got_ip, got_port, query):
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
dut1.expect("400 Bad Request - Server unable to understand request due to invalid syntax", timeout=30)
|
dut1.expect("400 Bad Request - Server unable to understand request due to invalid syntax", timeout=30)
|
||||||
|
@ -14,30 +14,35 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import httplib
|
from __future__ import print_function
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
from builtins import str
|
||||||
|
import http.client
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
def verbose_print(verbosity, *args):
|
def verbose_print(verbosity, *args):
|
||||||
if (verbosity):
|
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):
|
def test_get_handler(ip, port, verbosity = False):
|
||||||
verbose_print(verbosity, "======== GET HANDLER TEST =============")
|
verbose_print(verbosity, "======== GET HANDLER TEST =============")
|
||||||
# Establish HTTP connection
|
# Establish HTTP connection
|
||||||
verbose_print(verbosity, "Connecting to => " + ip + ":" + port)
|
verbose_print(verbosity, "Connecting to => " + ip + ":" + port)
|
||||||
sess = httplib.HTTPConnection(ip + ":" + port, timeout = 15)
|
sess = http.client.HTTPConnection(ip + ":" + port, timeout = 15)
|
||||||
|
|
||||||
uri = "/hello?query1=value1&query2=value2&query3=value3"
|
uri = "/hello?query1=value1&query2=value2&query3=value3"
|
||||||
# GET hello response
|
# GET hello response
|
||||||
test_headers = {"Test-Header-1":"Test-Value-1", "Test-Header-2":"Test-Value-2"}
|
test_headers = {"Test-Header-1":"Test-Value-1", "Test-Header-2":"Test-Value-2"}
|
||||||
verbose_print(verbosity, "Sending GET to URI : ", uri)
|
verbose_print(verbosity, "Sending GET to URI : ", uri)
|
||||||
verbose_print(verbosity, "Sending additional headers : ")
|
verbose_print(verbosity, "Sending additional headers : ")
|
||||||
for k, v in test_headers.iteritems():
|
for k, v in test_headers.items():
|
||||||
verbose_print(verbosity, "\t", k, ": ", v)
|
verbose_print(verbosity, "\t", k, ": ", v)
|
||||||
sess.request("GET", url=uri, headers=test_headers)
|
sess.request("GET", url=uri, headers=test_headers)
|
||||||
resp = sess.getresponse()
|
resp = sess.getresponse()
|
||||||
resp_hdrs = resp.getheaders()
|
resp_hdrs = resp.getheaders()
|
||||||
resp_data = resp.read()
|
resp_data = resp.read().decode()
|
||||||
try:
|
try:
|
||||||
if resp.getheader("Custom-Header-1") != "Custom-Value-1":
|
if resp.getheader("Custom-Header-1") != "Custom-Value-1":
|
||||||
return False
|
return False
|
||||||
@ -62,12 +67,12 @@ def test_post_handler(ip, port, msg, verbosity = False):
|
|||||||
verbose_print(verbosity, "======== POST HANDLER TEST ============")
|
verbose_print(verbosity, "======== POST HANDLER TEST ============")
|
||||||
# Establish HTTP connection
|
# Establish HTTP connection
|
||||||
verbose_print(verbosity, "Connecting to => " + ip + ":" + port)
|
verbose_print(verbosity, "Connecting to => " + ip + ":" + port)
|
||||||
sess = httplib.HTTPConnection(ip + ":" + port, timeout = 15)
|
sess = http.client.HTTPConnection(ip + ":" + port, timeout = 15)
|
||||||
|
|
||||||
# POST message to /echo and get back response
|
# POST message to /echo and get back response
|
||||||
sess.request("POST", url="/echo", body=msg)
|
sess.request("POST", url="/echo", body=msg)
|
||||||
resp = sess.getresponse()
|
resp = sess.getresponse()
|
||||||
resp_data = resp.read()
|
resp_data = resp.read().decode()
|
||||||
verbose_print(verbosity, "Server response to POST /echo (" + msg + ")")
|
verbose_print(verbosity, "Server response to POST /echo (" + msg + ")")
|
||||||
verbose_print(verbosity, "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
|
verbose_print(verbosity, "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
|
||||||
verbose_print(verbosity, resp_data)
|
verbose_print(verbosity, resp_data)
|
||||||
@ -81,7 +86,7 @@ def test_put_handler(ip, port, verbosity = False):
|
|||||||
verbose_print(verbosity, "======== PUT HANDLER TEST =============")
|
verbose_print(verbosity, "======== PUT HANDLER TEST =============")
|
||||||
# Establish HTTP connection
|
# Establish HTTP connection
|
||||||
verbose_print(verbosity, "Connecting to => " + ip + ":" + port)
|
verbose_print(verbosity, "Connecting to => " + ip + ":" + port)
|
||||||
sess = httplib.HTTPConnection(ip + ":" + port, timeout = 15)
|
sess = http.client.HTTPConnection(ip + ":" + port, timeout = 15)
|
||||||
|
|
||||||
# PUT message to /ctrl to disable /hello URI handler
|
# PUT message to /ctrl to disable /hello URI handler
|
||||||
verbose_print(verbosity, "Disabling /hello handler")
|
verbose_print(verbosity, "Disabling /hello handler")
|
||||||
@ -91,7 +96,7 @@ def test_put_handler(ip, port, verbosity = False):
|
|||||||
|
|
||||||
sess.request("GET", url="/hello")
|
sess.request("GET", url="/hello")
|
||||||
resp = sess.getresponse()
|
resp = sess.getresponse()
|
||||||
resp_data1 = resp.read()
|
resp_data1 = resp.read().decode()
|
||||||
verbose_print(verbosity, "Response on GET /hello : " + resp_data1)
|
verbose_print(verbosity, "Response on GET /hello : " + resp_data1)
|
||||||
|
|
||||||
# PUT message to /ctrl to enable /hello URI handler
|
# PUT message to /ctrl to enable /hello URI handler
|
||||||
@ -102,7 +107,7 @@ def test_put_handler(ip, port, verbosity = False):
|
|||||||
|
|
||||||
sess.request("GET", url="/hello")
|
sess.request("GET", url="/hello")
|
||||||
resp = sess.getresponse()
|
resp = sess.getresponse()
|
||||||
resp_data2 = resp.read()
|
resp_data2 = resp.read().decode()
|
||||||
verbose_print(verbosity, "Response on GET /hello : " + resp_data2)
|
verbose_print(verbosity, "Response on GET /hello : " + resp_data2)
|
||||||
|
|
||||||
# Close HTTP connection
|
# Close HTTP connection
|
||||||
@ -113,14 +118,14 @@ def test_custom_uri_query(ip, port, query, verbosity = False):
|
|||||||
verbose_print(verbosity, "======== GET HANDLER TEST =============")
|
verbose_print(verbosity, "======== GET HANDLER TEST =============")
|
||||||
# Establish HTTP connection
|
# Establish HTTP connection
|
||||||
verbose_print(verbosity, "Connecting to => " + ip + ":" + port)
|
verbose_print(verbosity, "Connecting to => " + ip + ":" + port)
|
||||||
sess = httplib.HTTPConnection(ip + ":" + port, timeout = 15)
|
sess = http.client.HTTPConnection(ip + ":" + port, timeout = 15)
|
||||||
|
|
||||||
uri = "/hello?" + query
|
uri = "/hello?" + query
|
||||||
# GET hello response
|
# GET hello response
|
||||||
verbose_print(verbosity, "Sending GET to URI : ", uri)
|
verbose_print(verbosity, "Sending GET to URI : ", uri)
|
||||||
sess.request("GET", url=uri, headers={})
|
sess.request("GET", url=uri, headers={})
|
||||||
resp = sess.getresponse()
|
resp = sess.getresponse()
|
||||||
resp_data = resp.read()
|
resp_data = resp.read().decode()
|
||||||
|
|
||||||
verbose_print(verbosity, "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
|
verbose_print(verbosity, "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
|
||||||
verbose_print(verbosity, "Server response to GET /hello")
|
verbose_print(verbosity, "Server response to GET /hello")
|
||||||
@ -145,8 +150,8 @@ if __name__ == '__main__':
|
|||||||
msg = args['msg']
|
msg = args['msg']
|
||||||
|
|
||||||
if not test_get_handler (ip, port, True):
|
if not test_get_handler (ip, port, True):
|
||||||
print "Failed!"
|
Utility.console_log("Failed!")
|
||||||
if not test_post_handler(ip, port, msg, True):
|
if not test_post_handler(ip, port, msg, True):
|
||||||
print "Failed!"
|
Utility.console_log("Failed!")
|
||||||
if not test_put_handler (ip, port, True):
|
if not test_put_handler (ip, port, True):
|
||||||
print "Failed!"
|
Utility.console_log("Failed!")
|
||||||
|
@ -19,6 +19,11 @@ The test env Example_ShieldBox do need the following config::
|
|||||||
apc_ip: "192.168.1.88"
|
apc_ip: "192.168.1.88"
|
||||||
pc_nic: "eth0"
|
pc_nic: "eth0"
|
||||||
"""
|
"""
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
from builtins import str
|
||||||
|
from builtins import range
|
||||||
|
from builtins import object
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
@ -75,7 +80,7 @@ class TestResult(object):
|
|||||||
BAD_POINT_PERCENTAGE_THRESHOLD = 0.3
|
BAD_POINT_PERCENTAGE_THRESHOLD = 0.3
|
||||||
|
|
||||||
# we need at least 1/2 valid points to qualify the test result
|
# we need at least 1/2 valid points to qualify the test result
|
||||||
THROUGHPUT_QUALIFY_COUNT = TEST_TIME / 2
|
THROUGHPUT_QUALIFY_COUNT = TEST_TIME//2
|
||||||
|
|
||||||
def __init__(self, proto, direction, config_name):
|
def __init__(self, proto, direction, config_name):
|
||||||
self.proto = proto
|
self.proto = proto
|
||||||
@ -169,7 +174,7 @@ class TestResult(object):
|
|||||||
def analysis_bad_point(data, index_type):
|
def analysis_bad_point(data, index_type):
|
||||||
for ap_ssid in data:
|
for ap_ssid in data:
|
||||||
result_dict = data[ap_ssid]
|
result_dict = data[ap_ssid]
|
||||||
index_list = result_dict.keys()
|
index_list = list(result_dict.keys())
|
||||||
index_list.sort()
|
index_list.sort()
|
||||||
if index_type == "att":
|
if index_type == "att":
|
||||||
index_list.reverse()
|
index_list.reverse()
|
||||||
|
@ -37,6 +37,7 @@ User should implement their DUTTool classes.
|
|||||||
If they using different port then need to implement their DUTPort class as well.
|
If they using different port then need to implement their DUTPort class as well.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import time
|
import time
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
@ -402,6 +403,21 @@ class BaseDUT(object):
|
|||||||
self._port_close()
|
self._port_close()
|
||||||
self.LOG_THREAD.flush_data()
|
self.LOG_THREAD.flush_data()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def u_to_bytearray(data):
|
||||||
|
"""
|
||||||
|
if data is not bytearray then it tries to convert it
|
||||||
|
|
||||||
|
:param data: data which needs to be checked and maybe transformed
|
||||||
|
"""
|
||||||
|
if type(data) is type(u''):
|
||||||
|
try:
|
||||||
|
data = data.encode('utf-8')
|
||||||
|
except:
|
||||||
|
print(u'Cannot encode {} of type {}'.format(data, type(data)))
|
||||||
|
raise
|
||||||
|
return data
|
||||||
|
|
||||||
def write(self, data, eol="\r\n", flush=True):
|
def write(self, data, eol="\r\n", flush=True):
|
||||||
"""
|
"""
|
||||||
:param data: data
|
:param data: data
|
||||||
@ -416,7 +432,7 @@ class BaseDUT(object):
|
|||||||
self.data_cache.flush()
|
self.data_cache.flush()
|
||||||
# do write if cache
|
# do write if cache
|
||||||
if data is not None:
|
if data is not None:
|
||||||
self._port_write(data + eol if eol else data)
|
self._port_write(self.u_to_bytearray(data) + self.u_to_bytearray(eol) if eol else self.u_to_bytearray(data))
|
||||||
|
|
||||||
@_expect_lock
|
@_expect_lock
|
||||||
def read(self, size=0xFFFFFFFF):
|
def read(self, size=0xFFFFFFFF):
|
||||||
@ -461,9 +477,13 @@ class BaseDUT(object):
|
|||||||
:return: match groups if match succeed otherwise None
|
:return: match groups if match succeed otherwise None
|
||||||
"""
|
"""
|
||||||
ret = None
|
ret = None
|
||||||
|
if type(pattern.pattern) is type(u''):
|
||||||
|
pattern = re.compile(BaseDUT.u_to_bytearray(pattern.pattern))
|
||||||
|
if type(data) is type(u''):
|
||||||
|
data = BaseDUT.u_to_bytearray(data)
|
||||||
match = pattern.search(data)
|
match = pattern.search(data)
|
||||||
if match:
|
if match:
|
||||||
ret = match.groups()
|
ret = tuple(x.decode() for x in match.groups())
|
||||||
index = match.end()
|
index = match.end()
|
||||||
else:
|
else:
|
||||||
index = -1
|
index = -1
|
||||||
@ -471,7 +491,8 @@ class BaseDUT(object):
|
|||||||
|
|
||||||
EXPECT_METHOD = [
|
EXPECT_METHOD = [
|
||||||
[type(re.compile("")), "_expect_re"],
|
[type(re.compile("")), "_expect_re"],
|
||||||
[str, "_expect_str"],
|
[type(b''), "_expect_str"], # Python 2 & 3 hook to work without 'from builtins import str' from future
|
||||||
|
[type(u''), "_expect_str"],
|
||||||
]
|
]
|
||||||
|
|
||||||
def _get_expect_method(self, pattern):
|
def _get_expect_method(self, pattern):
|
||||||
|
@ -89,7 +89,7 @@ class IDFDUT(DUT.SerialDUT):
|
|||||||
address = self.partition_table["nvs"]["offset"]
|
address = self.partition_table["nvs"]["offset"]
|
||||||
size = self.partition_table["nvs"]["size"]
|
size = self.partition_table["nvs"]["size"]
|
||||||
nvs_file = tempfile.NamedTemporaryFile()
|
nvs_file = tempfile.NamedTemporaryFile()
|
||||||
nvs_file.write(chr(0xFF) * size)
|
nvs_file.write(b'\xff' * size)
|
||||||
nvs_file.flush()
|
nvs_file.flush()
|
||||||
download_config = self.download_config + [address, nvs_file.name]
|
download_config = self.download_config + [address, nvs_file.name]
|
||||||
else:
|
else:
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import print_function
|
||||||
import sys
|
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.
|
log data to console.
|
||||||
(if not flush console log, Gitlab-CI won't update logs during job execution)
|
(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:
|
if color not in _COLOR_CODES:
|
||||||
color = "white"
|
color = "white"
|
||||||
color_codes = _COLOR_CODES[color]
|
color_codes = _COLOR_CODES[color]
|
||||||
print(color_codes + data)
|
print(color_codes + data, end=end)
|
||||||
if color not in ["white", "W"]:
|
if color not in ["white", "W"]:
|
||||||
# reset color to white for later logs
|
# reset color to white for later logs
|
||||||
print(_COLOR_CODES["white"] + "\r")
|
print(_COLOR_CODES["white"] + "\r")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user