Remove tiny_test_fw dependency from idf_http_server_test package

This commit is contained in:
Harshit Malpani
2022-05-10 16:16:58 +05:30
parent 2d244ded08
commit 767125a051
4 changed files with 109 additions and 136 deletions

View File

@@ -2284,8 +2284,6 @@ tools/ci/ci_get_mr_info.py
tools/ci/deploy_docs.py tools/ci/deploy_docs.py
tools/ci/envsubst.py tools/ci/envsubst.py
tools/ci/python_packages/gitlab_api.py tools/ci/python_packages/gitlab_api.py
tools/ci/python_packages/idf_http_server_test/adder.py
tools/ci/python_packages/idf_http_server_test/test.py
tools/ci/python_packages/idf_iperf_test_util/Attenuator.py tools/ci/python_packages/idf_iperf_test_util/Attenuator.py
tools/ci/python_packages/idf_iperf_test_util/IperfUtility.py tools/ci/python_packages/idf_iperf_test_util/IperfUtility.py
tools/ci/python_packages/idf_iperf_test_util/LineChart.py tools/ci/python_packages/idf_iperf_test_util/LineChart.py

View File

@@ -1,27 +1,15 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright 2018 Espressif Systems (Shanghai) PTE LTD # SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
# # SPDX-License-Identifier: Apache-2.0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import argparse import argparse
import http.client import http.client
import logging
from builtins import range, str from builtins import range, str
from tiny_test_fw import Utility
def start_session(ip, port): def start_session(ip, port):
return http.client.HTTPConnection(ip, int(port), timeout=15) return http.client.HTTPConnection(ip, int(port), timeout=15)
@@ -36,11 +24,11 @@ def getreq(conn, path, verbose=False):
resp = conn.getresponse() resp = conn.getresponse()
data = resp.read() data = resp.read()
if verbose: if verbose:
Utility.console_log('GET : ' + path) logging.info('GET : {}'.format(path))
Utility.console_log('Status : ' + resp.status) logging.info('Status : {}'.format(resp.status))
Utility.console_log('Reason : ' + resp.reason) logging.info('Reason : {}'.format(resp.reason))
Utility.console_log('Data length : ' + str(len(data))) logging.info('Data length : {}'.format(len(data)))
Utility.console_log('Data content : ' + data) logging.info('Data content : {}'.format(data))
return data return data
@@ -49,11 +37,11 @@ def postreq(conn, path, data, verbose=False):
resp = conn.getresponse() resp = conn.getresponse()
data = resp.read() data = resp.read()
if verbose: if verbose:
Utility.console_log('POST : ' + data) logging.info('POST : {}'.format(data))
Utility.console_log('Status : ' + resp.status) logging.info('Status : {}'.format(resp.status))
Utility.console_log('Reason : ' + resp.reason) logging.info('Reason : {}'.format(resp.reason))
Utility.console_log('Data length : ' + str(len(data))) logging.info('Data length : {}'.format(len(data)))
Utility.console_log('Data content : ' + data) logging.info('Data content : {}'.format(data))
return data return data
@@ -62,11 +50,11 @@ def putreq(conn, path, body, verbose=False):
resp = conn.getresponse() resp = conn.getresponse()
data = resp.read() data = resp.read()
if verbose: if verbose:
Utility.console_log('PUT : ' + path, body) logging.info('PUT : {} {}'.format(path, body))
Utility.console_log('Status : ' + resp.status) logging.info('Status : {}'.format(resp.status))
Utility.console_log('Reason : ' + resp.reason) logging.info('Reason : {}'.format(resp.reason))
Utility.console_log('Data length : ' + str(len(data))) logging.info('Data length : {}'.format(len(data)))
Utility.console_log('Data content : ' + data) logging.info('Data content : {}'.format(data))
return data return data
@@ -84,22 +72,22 @@ if __name__ == '__main__':
N = args['N'] N = args['N']
# Establish HTTP connection # Establish HTTP connection
Utility.console_log('Connecting to => ' + ip + ':' + port) logging.info('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
Utility.console_log('Reset the accumulator to 0') logging.info('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)
Utility.console_log('Summing numbers from 1 to ' + str(N)) logging.info('Summing numbers from 1 to {}'.format(N))
for i in range(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
Utility.console_log('Result :' + getreq(conn, '/adder')) logging.info('Result :{}'.format(getreq(conn, '/adder')))
# Close HTTP connection # Close HTTP connection
end_session(conn) end_session(conn)

View File

@@ -7,22 +7,21 @@ from __future__ import print_function, unicode_literals
import argparse import argparse
import http.client import http.client
import logging
from builtins import str from builtins import str
from tiny_test_fw import Utility
def verbose_print(verbosity, *args): def verbose_print(verbosity, *args):
if (verbosity): if (verbosity):
Utility.console_log(''.join(str(elems) for elems in args)) logging.info(''.join(str(elems) for elems in args))
def test_val(text, expected, received): def test_val(text, expected, received):
if expected != received: if expected != received:
Utility.console_log(' Fail!') logging.info(' Fail!')
Utility.console_log(' [reason] ' + text + ':') logging.info(' [reason] {} :'.format(text))
Utility.console_log(' expected: ' + str(expected)) logging.info(' expected: {}'.format(expected))
Utility.console_log(' received: ' + str(received)) logging.info(' received: {}'.format(received))
return False return False
return True return True
@@ -253,4 +252,4 @@ if __name__ == '__main__':
test_put_handler(ip, port, True) and test_put_handler(ip, port, True) and
test_post_handler(ip, port, msg, True) test_post_handler(ip, port, msg, True)
): ):
Utility.console_log('Failed!') logging.info('Failed!')

View File

@@ -1,18 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# #
# Copyright 2018 Espressif Systems (Shanghai) PTE LTD # SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
# # SPDX-License-Identifier: Apache-2.0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Utility for testing the web server. Test cases: # Utility for testing the web server. Test cases:
# Assume the device supports 'n' simultaneous open sockets # Assume the device supports 'n' simultaneous open sockets
@@ -133,6 +122,7 @@ from __future__ import division, print_function
import argparse import argparse
import http.client import http.client
import logging
import random import random
import socket import socket
import string import string
@@ -141,8 +131,6 @@ import threading
import time import time
from builtins import object, range, str from builtins import object, range, str
from tiny_test_fw import Utility
_verbose_ = False _verbose_ = False
@@ -163,7 +151,7 @@ class Session(object):
self.client.sendall(data.encode()) self.client.sendall(data.encode())
except socket.error as err: except socket.error as err:
self.client.close() self.client.close()
Utility.console_log('Socket Error in send :', err) logging.info('Socket Error in send :{}'.format(err))
rval = False rval = False
return rval return rval
@@ -232,7 +220,7 @@ class Session(object):
return headers return headers
except socket.error as err: except socket.error as err:
self.client.close() self.client.close()
Utility.console_log('Socket Error in recv :', err) logging.info('Socket Error in recv :{}'.format(err))
return None return None
def read_resp_data(self): def read_resp_data(self):
@@ -263,7 +251,7 @@ class Session(object):
# 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
Utility.console_log('Error in chunked data') logging.info('Error in chunked data')
return None return None
if not chunk_len: if not chunk_len:
# If last chunk # If last chunk
@@ -276,7 +264,7 @@ class Session(object):
return read_data return read_data
except socket.error as err: except socket.error as err:
self.client.close() self.client.close()
Utility.console_log('Socket Error in recv :', err) logging.info('Socket Error in recv :{}'.format(err))
return None return None
def close(self): def close(self):
@@ -285,10 +273,10 @@ class Session(object):
def test_val(text, expected, received): def test_val(text, expected, received):
if expected != received: if expected != received:
Utility.console_log(' Fail!') logging.info(' Fail!')
Utility.console_log(' [reason] ' + text + ':') logging.info(' [reason] {}:'.format(text))
Utility.console_log(' expected: ' + str(expected)) logging.info(' expected: {}'.format(expected))
Utility.console_log(' received: ' + str(received)) logging.info(' received: {}'.format(received))
return False return False
return True return True
@@ -306,7 +294,7 @@ class adder_thread (threading.Thread):
# Pipeline 3 requests # Pipeline 3 requests
if (_verbose_): if (_verbose_):
Utility.console_log(' Thread: Using adder start ' + str(self.id)) logging.info(' Thread: Using adder start {}'.format(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))
@@ -318,7 +306,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:
Utility.console_log('Error : missing response packets') logging.info('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) + ']',
@@ -332,7 +320,7 @@ 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!'
Utility.console_log("[test] GET /hello returns 'Hello World!' =>", end=' ') logging.info("[test] GET /hello returns 'Hello World!' =>")
conn = http.client.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()
@@ -345,42 +333,42 @@ def get_hello(dut, port):
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
Utility.console_log('Success') logging.info('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'
Utility.console_log('[test] PUT /hello returns 405 =>', end=' ') logging.info('[test] PUT /hello returns 405 =>')
conn = http.client.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
Utility.console_log('Success') logging.info('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'
Utility.console_log('[test] POST /hello returns 405 =>', end=' ') logging.info('[test] POST /hello returns 405 =>')
conn = http.client.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
Utility.console_log('Success') logging.info('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'
Utility.console_log('[test] POST /echo echoes data =>', end=' ') logging.info('[test] POST /echo echoes data =>')
conn = http.client.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()
@@ -390,14 +378,14 @@ def post_echo(dut, port):
if not test_val('data', 'Hello', resp.read().decode()): if not test_val('data', 'Hello', resp.read().decode()):
conn.close() conn.close()
return False return False
Utility.console_log('Success') logging.info('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'
Utility.console_log('[test] PUT /echo echoes data =>', end=' ') logging.info('[test] PUT /echo echoes data =>')
conn = http.client.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()
@@ -407,28 +395,28 @@ def put_echo(dut, port):
if not test_val('data', 'Hello', resp.read().decode()): if not test_val('data', 'Hello', resp.read().decode()):
conn.close() conn.close()
return False return False
Utility.console_log('Success') logging.info('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'
Utility.console_log('[test] GET /echo returns 405 =>', end=' ') logging.info('[test] GET /echo returns 405 =>')
conn = http.client.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
Utility.console_log('Success') logging.info('Success')
conn.close() conn.close()
return True return True
def get_test_headers(dut, port): def get_test_headers(dut, port):
# GET /test_header returns data of Header2' # GET /test_header returns data of Header2'
Utility.console_log('[test] GET /test_header =>', end=' ') logging.info('[test] GET /test_header =>')
conn = http.client.HTTPConnection(dut, int(port), timeout=15) conn = http.client.HTTPConnection(dut, int(port), timeout=15)
custom_header = {'Header1': 'Value1', 'Header3': 'Value3'} custom_header = {'Header1': 'Value1', 'Header3': 'Value3'}
header2_values = ['', ' ', 'Value2', ' Value2', 'Value2 ', ' Value2 '] header2_values = ['', ' ', 'Value2', ' Value2', 'Value2 ', ' Value2 ']
@@ -449,14 +437,14 @@ def get_test_headers(dut, port):
conn.close() conn.close()
return False return False
resp.read() resp.read()
Utility.console_log('Success') logging.info('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'
Utility.console_log('[test] GET /hello/type_html has Content-Type of text/html =>', end=' ') logging.info('[test] GET /hello/type_html has Content-Type of text/html =>')
conn = http.client.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()
@@ -469,42 +457,42 @@ def get_hello_type(dut, port):
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
Utility.console_log('Success') logging.info('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'
Utility.console_log('[test] GET /hello/status_500 returns status 500 =>', end=' ') logging.info('[test] GET /hello/status_500 returns status 500 =>')
conn = http.client.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
Utility.console_log('Success') logging.info('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'
Utility.console_log('[test] GET /false_uri returns status 404 =>', end=' ') logging.info('[test] GET /false_uri returns status 404 =>')
conn = http.client.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
Utility.console_log('Success') logging.info('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
Utility.console_log('[test] POST {pipelined} on /adder in ' + str(max_sessions) + ' sessions =>', end=' ') logging.info('[test] POST {pipelined} on /adder in ' + str(max_sessions) + ' sessions =>')
t = [] t = []
# Create all sessions # Create all sessions
for i in range(max_sessions): for i in range(max_sessions):
@@ -522,14 +510,14 @@ def parallel_sessions_adder(dut, port, max_sessions):
res = False res = False
t[i].close() t[i].close()
if (res): if (res):
Utility.console_log('Success') logging.info('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
Utility.console_log('[test] Test HTTPD Work Queue (Async response) =>', end=' ') logging.info('[test] Test HTTPD Work Queue (Async response) =>')
s = Session(dut, port) s = Session(dut, port)
s.send_get('/async_data') s.send_get('/async_data')
@@ -542,13 +530,13 @@ def async_response_test(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('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)
Utility.console_log('[test] Leftover data in POST is purged (valid and invalid URIs) =>', end=' ') logging.info('[test] Leftover data in POST is purged (valid and invalid URIs) =>')
s = http.client.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')
@@ -579,18 +567,18 @@ def leftover_data_test(dut, port):
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('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
Utility.console_log('[test] Session max_sess_sessions (' + str(max_sess) + ') + 1 is rejected =>', end=' ') logging.info('[test] Session max_sess_sessions ({}) + 1 is rejected =>'.format(max_sess))
s = [] s = []
_verbose_ = True _verbose_ = True
for i in range(max_sess + 1): for i in range(max_sess + 1):
if (_verbose_): if (_verbose_):
Utility.console_log('Executing ' + str(i)) logging.info('Executing {}'.format(i))
try: try:
a = http.client.HTTPConnection(dut + ':' + port, timeout=15) a = http.client.HTTPConnection(dut + ':' + port, timeout=15)
a.request('GET', url='/hello') a.request('GET', url='/hello')
@@ -601,7 +589,7 @@ def spillover_session(dut, port, max_sess):
s.append(a) s.append(a)
except Exception: except Exception:
if (_verbose_): if (_verbose_):
Utility.console_log('Connection ' + str(i) + ' rejected') logging.info('Connection {} rejected'.format(i))
a.close() a.close()
break break
@@ -610,12 +598,12 @@ 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
Utility.console_log(['Fail','Success'][len(s) == max_sess]) logging.info(['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):
Utility.console_log('[test] Timeout occurs if partial packet sent =>', end=' ') logging.info('[test] Timeout occurs if partial packet sent =>')
s = Session(dut, port) s = Session(dut, port)
s.client.sendall(b'GE') s.client.sendall(b'GE')
s.read_resp_hdrs() s.read_resp_hdrs()
@@ -624,16 +612,16 @@ def recv_timeout_test(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
def packet_size_limit_test(dut, port, test_size): def packet_size_limit_test(dut, port, test_size):
Utility.console_log('[test] send size limit test =>', end=' ') logging.info('[test] send size limit test =>')
retry = 5 retry = 5
while (retry): while (retry):
retry -= 1 retry -= 1
Utility.console_log('data size = ', test_size) logging.info('data size = {}'.format(test_size))
s = http.client.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 list(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'
@@ -641,29 +629,29 @@ def packet_size_limit_test(dut, port, test_size):
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', '500', str(resp.status)): if test_val('Error', '500', str(resp.status)):
Utility.console_log('Data too large to be allocated') logging.info('Data too large to be allocated')
test_size = test_size // 10 test_size = test_size // 10
else: else:
Utility.console_log('Unexpected error') logging.info('Unexpected error')
s.close() s.close()
Utility.console_log('Retry...') logging.info('Retry...')
continue continue
resp = resp.read().decode() 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()
Utility.console_log('Retry...') logging.info('Retry...')
continue continue
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
Utility.console_log('Failed') logging.info('Failed')
return False return False
def arbitrary_termination_test(dut, port): def arbitrary_termination_test(dut, port):
Utility.console_log('[test] Arbitrary termination test =>', end=' ') logging.info('[test] Arbitrary termination test =>')
cases = [ cases = [
{ {
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nCustom: SomeValue\r\n\r\n', 'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nCustom: SomeValue\r\n\r\n',
@@ -757,12 +745,12 @@ def arbitrary_termination_test(dut, port):
if 'body' in case.keys(): if 'body' in case.keys():
if not test_val('Response Body', case['body'], resp_body): if not test_val('Response Body', case['body'], resp_body):
return False return False
Utility.console_log('Success') logging.info('Success')
return True return True
def code_500_server_error_test(dut, port): def code_500_server_error_test(dut, port):
Utility.console_log('[test] 500 Server Error test =>', end=' ') logging.info('[test] 500 Server Error test =>')
s = Session(dut, port) s = Session(dut, port)
# Sending a very large content length will cause malloc to fail # Sending a very large content length will cause malloc to fail
content_len = 2**30 content_len = 2**30
@@ -773,12 +761,12 @@ def code_500_server_error_test(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
def code_501_method_not_impl(dut, port): def code_501_method_not_impl(dut, port):
Utility.console_log('[test] 501 Method Not Implemented =>', end=' ') logging.info('[test] 501 Method Not Implemented =>')
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').encode()) s.client.sendall(('ABC ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\n\r\n').encode())
@@ -792,12 +780,12 @@ def code_501_method_not_impl(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
def code_505_version_not_supported(dut, port): def code_505_version_not_supported(dut, port):
Utility.console_log('[test] 505 Version Not Supported =>', end=' ') logging.info('[test] 505 Version Not Supported =>')
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').encode()) s.client.sendall(('GET ' + path + ' HTTP/2.0\r\nHost: ' + dut + '\r\n\r\n').encode())
@@ -807,12 +795,12 @@ def code_505_version_not_supported(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
def code_400_bad_request(dut, port): def code_400_bad_request(dut, port):
Utility.console_log('[test] 400 Bad Request =>', end=' ') logging.info('[test] 400 Bad Request =>')
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').encode()) s.client.sendall(('XYZ ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\n\r\n').encode())
@@ -822,12 +810,12 @@ def code_400_bad_request(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
def code_404_not_found(dut, port): def code_404_not_found(dut, port):
Utility.console_log('[test] 404 Not Found =>', end=' ') logging.info('[test] 404 Not Found =>')
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').encode()) s.client.sendall(('GET ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\n\r\n').encode())
@@ -837,12 +825,12 @@ def code_404_not_found(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
def code_405_method_not_allowed(dut, port): def code_405_method_not_allowed(dut, port):
Utility.console_log('[test] 405 Method Not Allowed =>', end=' ') logging.info('[test] 405 Method Not Allowed =>')
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').encode()) s.client.sendall(('POST ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\n\r\n').encode())
@@ -852,12 +840,12 @@ def code_405_method_not_allowed(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
def code_408_req_timeout(dut, port): def code_408_req_timeout(dut, port):
Utility.console_log('[test] 408 Request Timeout =>', end=' ') logging.info('[test] 408 Request Timeout =>')
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').encode()) 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()
@@ -866,12 +854,12 @@ def code_408_req_timeout(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
def code_411_length_required(dut, port): def code_411_length_required(dut, port):
Utility.console_log('[test] 411 Length Required =>', end=' ') logging.info('[test] 411 Length Required =>')
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').encode()) 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())
@@ -885,7 +873,7 @@ def code_411_length_required(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
@@ -906,14 +894,14 @@ def send_getx_uri_len(dut, port, length):
def code_414_uri_too_long(dut, port, max_uri_len): def code_414_uri_too_long(dut, port, max_uri_len):
Utility.console_log('[test] 414 URI Too Long =>', end=' ') logging.info('[test] 414 URI Too Long =>')
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
Utility.console_log('Success') logging.info('Success')
return True return True
@@ -936,19 +924,19 @@ def send_postx_hdr_len(dut, port, length):
def code_431_hdr_too_long(dut, port, max_hdr_len): def code_431_hdr_too_long(dut, port, max_hdr_len):
Utility.console_log('[test] 431 Header Too Long =>', end=' ') logging.info('[test] 431 Header Too Long =>')
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
Utility.console_log('Success') logging.info('Success')
return True return True
def test_upgrade_not_supported(dut, port): def test_upgrade_not_supported(dut, port):
Utility.console_log('[test] Upgrade Not Supported =>', end=' ') logging.info('[test] Upgrade Not Supported =>')
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').encode()) s.client.sendall(('OPTIONS * HTTP/1.1\r\nHost:' + dut + '\r\nUpgrade: TLS/1.0\r\nConnection: Upgrade\r\n\r\n').encode())
@@ -958,7 +946,7 @@ def test_upgrade_not_supported(dut, port):
s.close() s.close()
return False return False
s.close() s.close()
Utility.console_log('Success') logging.info('Success')
return True return True
@@ -983,7 +971,7 @@ if __name__ == '__main__':
_verbose_ = True _verbose_ = True
Utility.console_log('### Basic HTTP Client Tests') logging.info('### 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)
@@ -995,7 +983,7 @@ if __name__ == '__main__':
get_false_uri(dut, port) get_false_uri(dut, port)
get_test_headers(dut, port) get_test_headers(dut, port)
Utility.console_log('### Error code tests') logging.info('### 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)
@@ -1010,7 +998,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)
Utility.console_log('### Sessions and Context Tests') logging.info('### 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)