mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
http_server : Fix and enable example tests
This introduces the following changes in the example test scripts : * Dependency on python requests library removed in favor of httplib * Bug fixed in the logic responsible for receiving and processing http chunked responses * Default timeouts increased Note : Due to connectivity issues (between runner host and DUT) in the runner environment, some of the advanced_tests are being ignored. These tests are intended for verifying the expected limits of the http_server capabilities, and implement sending and receiving of large HTTP packets and malformed requests, running multiple parallel sessions, etc. It is advised that all these tests be run locally, when making changes or adding new features to this component.
This commit is contained in:
@@ -28,9 +28,9 @@ if test_fw_path and test_fw_path not in sys.path:
|
||||
sys.path.insert(0, test_fw_path)
|
||||
|
||||
# When running on local machine execute the following before running this script
|
||||
# > export TEST_FW_PATH='~/esp/esp-idf/tools/tiny-test-fw'
|
||||
# > make print_flash_cmd | tail -n 1 > build/download.config
|
||||
# > make app bootloader
|
||||
# > make print_flash_cmd | tail -n 1 > build/download.config
|
||||
# > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw
|
||||
|
||||
import TinyFW
|
||||
import IDF
|
||||
@@ -39,7 +39,7 @@ import IDF
|
||||
expath = os.path.dirname(os.path.realpath(__file__))
|
||||
client = imp.load_source("client", expath + "/scripts/client.py")
|
||||
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI", ignore=True)
|
||||
@IDF.idf_example_test(env_tag="Example_WIFI")
|
||||
def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("http_server", "examples/protocols/http_server/simple")
|
||||
@@ -47,21 +47,23 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "simple.bin")
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
IDF.log_performance("http_server_bin_size", "{}KB".format(bin_size//1024))
|
||||
IDF.check_performance("http_server_bin_size", 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)
|
||||
|
||||
# Upload binary and start testing
|
||||
print "Starting http_server simple test app"
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
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]*)Starting server on port: (\d+)"))[0]
|
||||
print "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
|
||||
|
||||
# Expected Logs
|
||||
dut1.expect("Registering URI handlers")
|
||||
dut1.expect("Registering URI handlers", timeout=30)
|
||||
|
||||
# Run test script
|
||||
# If failed raise appropriate exception
|
||||
@@ -70,24 +72,24 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
raise RuntimeError
|
||||
|
||||
# Acquire host IP. Need a way to check it
|
||||
host_ip = dut1.expect(re.compile(r"(?:[\s\S]*)Found header => Host: (\d+.\d+.\d+.\d+)"))[0]
|
||||
host_ip = dut1.expect(re.compile(r"(?:[\s\S]*)Found header => Host: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
|
||||
|
||||
# Match additional headers sent in the request
|
||||
dut1.expect("Found header => Test-Header-2: Test-Value-2")
|
||||
dut1.expect("Found header => Test-Header-1: Test-Value-1")
|
||||
dut1.expect("Found URL query parameter => query1=value1")
|
||||
dut1.expect("Found URL query parameter => query3=value3")
|
||||
dut1.expect("Found URL query parameter => query2=value2")
|
||||
dut1.expect("Request headers lost")
|
||||
dut1.expect("Found header => Test-Header-2: Test-Value-2", timeout=30)
|
||||
dut1.expect("Found header => Test-Header-1: Test-Value-1", timeout=30)
|
||||
dut1.expect("Found URL query parameter => query1=value1", timeout=30)
|
||||
dut1.expect("Found URL query parameter => query3=value3", timeout=30)
|
||||
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"
|
||||
if not client.test_put_handler(got_ip, got_port):
|
||||
raise RuntimeError
|
||||
dut1.expect("Unregistering /hello and /echo URIs")
|
||||
dut1.expect("Registering /hello and /echo URIs")
|
||||
dut1.expect("Unregistering /hello and /echo URIs", timeout=30)
|
||||
dut1.expect("Registering /hello and /echo URIs", timeout=30)
|
||||
|
||||
# Generate random data of 10KB
|
||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable))-1] for _ in range(1024*10))
|
||||
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"
|
||||
if not client.test_post_handler(got_ip, got_port, random_data):
|
||||
raise RuntimeError
|
||||
@@ -96,19 +98,19 @@ def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
print "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)
|
||||
dut1.expect("Found URL query => " + query, timeout=30)
|
||||
|
||||
query = "abcd+1234%20xyz"
|
||||
print "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)
|
||||
dut1.expect("Found URL query => " + query, timeout=30)
|
||||
|
||||
query = "abcd\nyz"
|
||||
print "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")
|
||||
dut1.expect("400 Bad Request - Server unable to understand request due to invalid syntax", timeout=30)
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_examples_protocol_http_server_simple()
|
||||
|
Reference in New Issue
Block a user