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

@@ -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)