Examples: Add Python 2&3 support

This commit is contained in:
Roland Dobai
2018-09-10 15:13:47 +02:00
parent 96cd3b75cd
commit 17b7959de9
10 changed files with 274 additions and 216 deletions

View File

@@ -14,6 +14,10 @@
# See the License for the specific language governing permissions and
# 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 re
import os
@@ -47,27 +51,27 @@ 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"
print("Starting http_server simple test app")
dut1.start_app()
# Parse IP address of STA
print "Waiting to connect with AP"
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
print("Got IP : " + got_ip)
print("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"
print("Test /hello GET handler")
if not client.test_get_handler(got_ip, got_port):
raise RuntimeError
@@ -82,7 +86,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"
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", timeout=30)
@@ -90,24 +94,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"
print("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
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, timeout=30)
query = "abcd+1234%20xyz"
print "Test /hello with custom query : " + query
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, timeout=30)
query = "abcd\nyz"
print "Test /hello with invalid query"
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", timeout=30)