mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Remove tiny_test_fw dependency from idf_http_server_test package
This commit is contained in:
parent
2d244ded08
commit
767125a051
@ -2284,8 +2284,6 @@ tools/ci/ci_get_mr_info.py
|
||||
tools/ci/deploy_docs.py
|
||||
tools/ci/envsubst.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/IperfUtility.py
|
||||
tools/ci/python_packages/idf_iperf_test_util/LineChart.py
|
||||
|
@ -1,27 +1,15 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
#
|
||||
# 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.
|
||||
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import argparse
|
||||
import http.client
|
||||
import logging
|
||||
from builtins import range, str
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
def start_session(ip, port):
|
||||
return http.client.HTTPConnection(ip, int(port), timeout=15)
|
||||
@ -36,11 +24,11 @@ def getreq(conn, path, verbose=False):
|
||||
resp = conn.getresponse()
|
||||
data = resp.read()
|
||||
if verbose:
|
||||
Utility.console_log('GET : ' + path)
|
||||
Utility.console_log('Status : ' + resp.status)
|
||||
Utility.console_log('Reason : ' + resp.reason)
|
||||
Utility.console_log('Data length : ' + str(len(data)))
|
||||
Utility.console_log('Data content : ' + data)
|
||||
logging.info('GET : {}'.format(path))
|
||||
logging.info('Status : {}'.format(resp.status))
|
||||
logging.info('Reason : {}'.format(resp.reason))
|
||||
logging.info('Data length : {}'.format(len(data)))
|
||||
logging.info('Data content : {}'.format(data))
|
||||
return data
|
||||
|
||||
|
||||
@ -49,11 +37,11 @@ def postreq(conn, path, data, verbose=False):
|
||||
resp = conn.getresponse()
|
||||
data = resp.read()
|
||||
if verbose:
|
||||
Utility.console_log('POST : ' + data)
|
||||
Utility.console_log('Status : ' + resp.status)
|
||||
Utility.console_log('Reason : ' + resp.reason)
|
||||
Utility.console_log('Data length : ' + str(len(data)))
|
||||
Utility.console_log('Data content : ' + data)
|
||||
logging.info('POST : {}'.format(data))
|
||||
logging.info('Status : {}'.format(resp.status))
|
||||
logging.info('Reason : {}'.format(resp.reason))
|
||||
logging.info('Data length : {}'.format(len(data)))
|
||||
logging.info('Data content : {}'.format(data))
|
||||
return data
|
||||
|
||||
|
||||
@ -62,11 +50,11 @@ def putreq(conn, path, body, verbose=False):
|
||||
resp = conn.getresponse()
|
||||
data = resp.read()
|
||||
if verbose:
|
||||
Utility.console_log('PUT : ' + path, body)
|
||||
Utility.console_log('Status : ' + resp.status)
|
||||
Utility.console_log('Reason : ' + resp.reason)
|
||||
Utility.console_log('Data length : ' + str(len(data)))
|
||||
Utility.console_log('Data content : ' + data)
|
||||
logging.info('PUT : {} {}'.format(path, body))
|
||||
logging.info('Status : {}'.format(resp.status))
|
||||
logging.info('Reason : {}'.format(resp.reason))
|
||||
logging.info('Data length : {}'.format(len(data)))
|
||||
logging.info('Data content : {}'.format(data))
|
||||
return data
|
||||
|
||||
|
||||
@ -84,22 +72,22 @@ if __name__ == '__main__':
|
||||
N = args['N']
|
||||
|
||||
# Establish HTTP connection
|
||||
Utility.console_log('Connecting to => ' + ip + ':' + port)
|
||||
logging.info('Connecting to => ' + ip + ':' + port)
|
||||
conn = start_session(ip, port)
|
||||
|
||||
# Reset adder context to specified value(0)
|
||||
# -- Not needed as new connection will always
|
||||
# -- have zero value of the accumulator
|
||||
Utility.console_log('Reset the accumulator to 0')
|
||||
logging.info('Reset the accumulator to 0')
|
||||
putreq(conn, '/adder', str(0))
|
||||
|
||||
# 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):
|
||||
postreq(conn, '/adder', str(i))
|
||||
|
||||
# Fetch the result
|
||||
Utility.console_log('Result :' + getreq(conn, '/adder'))
|
||||
logging.info('Result :{}'.format(getreq(conn, '/adder')))
|
||||
|
||||
# Close HTTP connection
|
||||
end_session(conn)
|
||||
|
@ -7,22 +7,21 @@ from __future__ import print_function, unicode_literals
|
||||
|
||||
import argparse
|
||||
import http.client
|
||||
import logging
|
||||
from builtins import str
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
def verbose_print(verbosity, *args):
|
||||
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):
|
||||
if expected != received:
|
||||
Utility.console_log(' Fail!')
|
||||
Utility.console_log(' [reason] ' + text + ':')
|
||||
Utility.console_log(' expected: ' + str(expected))
|
||||
Utility.console_log(' received: ' + str(received))
|
||||
logging.info(' Fail!')
|
||||
logging.info(' [reason] {} :'.format(text))
|
||||
logging.info(' expected: {}'.format(expected))
|
||||
logging.info(' received: {}'.format(received))
|
||||
return False
|
||||
return True
|
||||
|
||||
@ -253,4 +252,4 @@ if __name__ == '__main__':
|
||||
test_put_handler(ip, port, True) and
|
||||
test_post_handler(ip, port, msg, True)
|
||||
):
|
||||
Utility.console_log('Failed!')
|
||||
logging.info('Failed!')
|
||||
|
@ -1,18 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
||||
#
|
||||
# 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.
|
||||
# SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# Utility for testing the web server. Test cases:
|
||||
# Assume the device supports 'n' simultaneous open sockets
|
||||
@ -133,6 +122,7 @@ from __future__ import division, print_function
|
||||
|
||||
import argparse
|
||||
import http.client
|
||||
import logging
|
||||
import random
|
||||
import socket
|
||||
import string
|
||||
@ -141,8 +131,6 @@ import threading
|
||||
import time
|
||||
from builtins import object, range, str
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
_verbose_ = False
|
||||
|
||||
|
||||
@ -163,7 +151,7 @@ class Session(object):
|
||||
self.client.sendall(data.encode())
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
Utility.console_log('Socket Error in send :', err)
|
||||
logging.info('Socket Error in send :{}'.format(err))
|
||||
rval = False
|
||||
return rval
|
||||
|
||||
@ -232,7 +220,7 @@ class Session(object):
|
||||
return headers
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
Utility.console_log('Socket Error in recv :', err)
|
||||
logging.info('Socket Error in recv :{}'.format(err))
|
||||
return None
|
||||
|
||||
def read_resp_data(self):
|
||||
@ -263,7 +251,7 @@ class Session(object):
|
||||
# Fetch remaining CRLF
|
||||
if self.client.recv(2) != '\r\n':
|
||||
# Error in packet
|
||||
Utility.console_log('Error in chunked data')
|
||||
logging.info('Error in chunked data')
|
||||
return None
|
||||
if not chunk_len:
|
||||
# If last chunk
|
||||
@ -276,7 +264,7 @@ class Session(object):
|
||||
return read_data
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
Utility.console_log('Socket Error in recv :', err)
|
||||
logging.info('Socket Error in recv :{}'.format(err))
|
||||
return None
|
||||
|
||||
def close(self):
|
||||
@ -285,10 +273,10 @@ class Session(object):
|
||||
|
||||
def test_val(text, expected, received):
|
||||
if expected != received:
|
||||
Utility.console_log(' Fail!')
|
||||
Utility.console_log(' [reason] ' + text + ':')
|
||||
Utility.console_log(' expected: ' + str(expected))
|
||||
Utility.console_log(' received: ' + str(received))
|
||||
logging.info(' Fail!')
|
||||
logging.info(' [reason] {}:'.format(text))
|
||||
logging.info(' expected: {}'.format(expected))
|
||||
logging.info(' received: {}'.format(received))
|
||||
return False
|
||||
return True
|
||||
|
||||
@ -306,7 +294,7 @@ class adder_thread (threading.Thread):
|
||||
|
||||
# Pipeline 3 requests
|
||||
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):
|
||||
self.session.send_post('/adder', str(self.id))
|
||||
@ -318,7 +306,7 @@ class adder_thread (threading.Thread):
|
||||
|
||||
def adder_result(self):
|
||||
if len(self.response) != self.depth:
|
||||
Utility.console_log('Error : missing response packets')
|
||||
logging.info('Error : missing response packets')
|
||||
return False
|
||||
for i in range(len(self.response)):
|
||||
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):
|
||||
# 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.request('GET', '/hello')
|
||||
resp = conn.getresponse()
|
||||
@ -345,42 +333,42 @@ def get_hello(dut, port):
|
||||
if not test_val('data', 'text/html', resp.getheader('Content-Type')):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def put_hello(dut, port):
|
||||
# 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.request('PUT', '/hello', 'Hello')
|
||||
resp = conn.getresponse()
|
||||
if not test_val('status_code', 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def post_hello(dut, port):
|
||||
# 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.request('POST', '/hello', 'Hello')
|
||||
resp = conn.getresponse()
|
||||
if not test_val('status_code', 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def post_echo(dut, port):
|
||||
# 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.request('POST', '/echo', 'Hello')
|
||||
resp = conn.getresponse()
|
||||
@ -390,14 +378,14 @@ def post_echo(dut, port):
|
||||
if not test_val('data', 'Hello', resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def put_echo(dut, port):
|
||||
# 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.request('PUT', '/echo', 'Hello')
|
||||
resp = conn.getresponse()
|
||||
@ -407,28 +395,28 @@ def put_echo(dut, port):
|
||||
if not test_val('data', 'Hello', resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_echo(dut, port):
|
||||
# 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.request('GET', '/echo')
|
||||
resp = conn.getresponse()
|
||||
if not test_val('status_code', 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_test_headers(dut, port):
|
||||
# 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)
|
||||
custom_header = {'Header1': 'Value1', 'Header3': 'Value3'}
|
||||
header2_values = ['', ' ', 'Value2', ' Value2', 'Value2 ', ' Value2 ']
|
||||
@ -449,14 +437,14 @@ def get_test_headers(dut, port):
|
||||
conn.close()
|
||||
return False
|
||||
resp.read()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_hello_type(dut, port):
|
||||
# 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.request('GET', '/hello/type_html')
|
||||
resp = conn.getresponse()
|
||||
@ -469,42 +457,42 @@ def get_hello_type(dut, port):
|
||||
if not test_val('data', 'text/html', resp.getheader('Content-Type')):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_hello_status(dut, port):
|
||||
# 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.request('GET', '/hello/status_500')
|
||||
resp = conn.getresponse()
|
||||
if not test_val('status_code', 500, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_false_uri(dut, port):
|
||||
# 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.request('GET', '/false_uri')
|
||||
resp = conn.getresponse()
|
||||
if not test_val('status_code', 404, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def parallel_sessions_adder(dut, port, max_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 = []
|
||||
# Create all sessions
|
||||
for i in range(max_sessions):
|
||||
@ -522,14 +510,14 @@ def parallel_sessions_adder(dut, port, max_sessions):
|
||||
res = False
|
||||
t[i].close()
|
||||
if (res):
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return res
|
||||
|
||||
|
||||
def async_response_test(dut, port):
|
||||
# Test that an asynchronous work is executed in the HTTPD's context
|
||||
# This is tested by reading two responses over the same session
|
||||
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.send_get('/async_data')
|
||||
@ -542,13 +530,13 @@ def async_response_test(dut, port):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
def leftover_data_test(dut, port):
|
||||
# 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.request('POST', url='/leftover_data', body='abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz')
|
||||
@ -579,18 +567,18 @@ def leftover_data_test(dut, port):
|
||||
return False
|
||||
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
def spillover_session(dut, port, max_sess):
|
||||
# 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 = []
|
||||
_verbose_ = True
|
||||
for i in range(max_sess + 1):
|
||||
if (_verbose_):
|
||||
Utility.console_log('Executing ' + str(i))
|
||||
logging.info('Executing {}'.format(i))
|
||||
try:
|
||||
a = http.client.HTTPConnection(dut + ':' + port, timeout=15)
|
||||
a.request('GET', url='/hello')
|
||||
@ -601,7 +589,7 @@ def spillover_session(dut, port, max_sess):
|
||||
s.append(a)
|
||||
except Exception:
|
||||
if (_verbose_):
|
||||
Utility.console_log('Connection ' + str(i) + ' rejected')
|
||||
logging.info('Connection {} rejected'.format(i))
|
||||
a.close()
|
||||
break
|
||||
|
||||
@ -610,12 +598,12 @@ def spillover_session(dut, port, max_sess):
|
||||
a.close()
|
||||
|
||||
# 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)
|
||||
|
||||
|
||||
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.client.sendall(b'GE')
|
||||
s.read_resp_hdrs()
|
||||
@ -624,16 +612,16 @@ def recv_timeout_test(dut, port):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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
|
||||
while (retry):
|
||||
retry -= 1
|
||||
Utility.console_log('data size = ', test_size)
|
||||
logging.info('data size = {}'.format(test_size))
|
||||
s = http.client.HTTPConnection(dut + ':' + port, timeout=15)
|
||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable)) - 1] for _ in list(range(test_size)))
|
||||
path = '/echo'
|
||||
@ -641,29 +629,29 @@ def packet_size_limit_test(dut, port, test_size):
|
||||
resp = s.getresponse()
|
||||
if not test_val('Error', '200', str(resp.status)):
|
||||
if test_val('Error', '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
|
||||
else:
|
||||
Utility.console_log('Unexpected error')
|
||||
logging.info('Unexpected error')
|
||||
s.close()
|
||||
Utility.console_log('Retry...')
|
||||
logging.info('Retry...')
|
||||
continue
|
||||
resp = resp.read().decode()
|
||||
result = (resp == random_data)
|
||||
if not result:
|
||||
test_val('Data size', str(len(random_data)), str(len(resp)))
|
||||
s.close()
|
||||
Utility.console_log('Retry...')
|
||||
logging.info('Retry...')
|
||||
continue
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
Utility.console_log('Failed')
|
||||
logging.info('Failed')
|
||||
return False
|
||||
|
||||
|
||||
def arbitrary_termination_test(dut, port):
|
||||
Utility.console_log('[test] Arbitrary termination test =>', end=' ')
|
||||
logging.info('[test] Arbitrary termination test =>')
|
||||
cases = [
|
||||
{
|
||||
'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 not test_val('Response Body', case['body'], resp_body):
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
# Sending a very large content length will cause malloc to fail
|
||||
content_len = 2**30
|
||||
@ -773,12 +761,12 @@ def code_500_server_error_test(dut, port):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
path = '/hello'
|
||||
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()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
path = '/hello'
|
||||
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()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
path = '/hello'
|
||||
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()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
path = '/dummy'
|
||||
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()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
path = '/hello'
|
||||
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()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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.client.sendall(('POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nContent-Length: 10\r\n\r\nABCD').encode())
|
||||
s.read_resp_hdrs()
|
||||
@ -866,12 +854,12 @@ def code_408_req_timeout(dut, port):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
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())
|
||||
@ -885,7 +873,7 @@ def code_411_length_required(dut, port):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
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):
|
||||
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)
|
||||
if not test_val('Client Error', '404', status):
|
||||
return False
|
||||
status = send_getx_uri_len(dut, port, max_uri_len + 1)
|
||||
if not test_val('Client Error', '414', status):
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
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):
|
||||
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)
|
||||
if not res:
|
||||
return False
|
||||
res, status = send_postx_hdr_len(dut, port, max_hdr_len + 1)
|
||||
if not test_val('Client Error', '431', status):
|
||||
return False
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
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)
|
||||
# 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())
|
||||
@ -958,7 +946,7 @@ def test_upgrade_not_supported(dut, port):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log('Success')
|
||||
logging.info('Success')
|
||||
return True
|
||||
|
||||
|
||||
@ -983,7 +971,7 @@ if __name__ == '__main__':
|
||||
|
||||
_verbose_ = True
|
||||
|
||||
Utility.console_log('### Basic HTTP Client Tests')
|
||||
logging.info('### Basic HTTP Client Tests')
|
||||
get_hello(dut, port)
|
||||
post_hello(dut, port)
|
||||
put_hello(dut, port)
|
||||
@ -995,7 +983,7 @@ if __name__ == '__main__':
|
||||
get_false_uri(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_501_method_not_impl(dut, port)
|
||||
code_505_version_not_supported(dut, port)
|
||||
@ -1010,7 +998,7 @@ if __name__ == '__main__':
|
||||
# Not supported yet (Error on chunked request)
|
||||
# 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)
|
||||
leftover_data_test(dut, port)
|
||||
async_response_test(dut, port)
|
||||
|
Loading…
x
Reference in New Issue
Block a user