mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
add arguments for test runner
This commit is contained in:
@@ -2,26 +2,26 @@ import argparse
|
|||||||
import requests
|
import requests
|
||||||
import time
|
import time
|
||||||
|
|
||||||
# Setting go here
|
def run_test(ip, wait, name):
|
||||||
EMSESP_IP = "10.10.10.20" # IP or hostname.local of EMS-ESP
|
|
||||||
DEFAULT_TEST_NAME = "general" # default name of test
|
|
||||||
WAIT_TIME = 1 # in seconds
|
|
||||||
|
|
||||||
# fixed variables
|
BASE_URL = "http://" + str(ip)
|
||||||
INFO_URL = "http://" + EMSESP_IP + "/api/system/info"
|
INFO_URL = BASE_URL + "/api/system/info"
|
||||||
TEST_URL = "http://" + EMSESP_IP + "/api?device=system&cmd=test&data="
|
TEST_URL = BASE_URL + "/api?device=system&cmd=test&data=" + name
|
||||||
GET_HEADERS = { 'Content-Type': 'application/json'}
|
GET_HEADERS = { 'Content-Type': 'application/json'}
|
||||||
TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ8.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWUsInZlcnNpb24iOiIzLjEuMWIwIn0.qeGT53Aom4rDYeIT1Pr4BSMdeWyf4_zN9ue2c51ZnM0"
|
|
||||||
POST_HEADERS = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + TOKEN }
|
|
||||||
|
|
||||||
def run_test(test_name):
|
|
||||||
|
|
||||||
# example for POSTs:
|
# example for POSTs:
|
||||||
# BODY = json.dumps({ "value": 22.5 })
|
# BODY = json.dumps({ "value": 22.5 })
|
||||||
# response = requests.post(url, headers=HEADERS, data=BODY, verify=False)
|
# response = requests.post(url, headers=HEADERS, data=BODY, verify=False)
|
||||||
|
# TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ8.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWUsInZlcnNpb24iOiIzLjEuMWIwIn0.qeGT53Aom4rDYeIT1Pr4BSMdeWyf4_zN9ue2c51ZnM0"
|
||||||
|
# POST_HEADERS = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + TOKEN }
|
||||||
|
|
||||||
print()
|
print()
|
||||||
print("* Getting initial stats", end="")
|
print("Benchmarking EMS-ESP")
|
||||||
|
print(" Base URL: " + BASE_URL)
|
||||||
|
print(" Test Name: " + name)
|
||||||
|
print()
|
||||||
|
|
||||||
|
print("1. Getting initial stats", end="")
|
||||||
response = requests.get(INFO_URL, headers=GET_HEADERS, verify=False)
|
response = requests.get(INFO_URL, headers=GET_HEADERS, verify=False)
|
||||||
uptime_a = response.json()['System Info']['uptime (seconds)']
|
uptime_a = response.json()['System Info']['uptime (seconds)']
|
||||||
freemem_a = response.json()['System Info']['free mem']
|
freemem_a = response.json()['System Info']['free mem']
|
||||||
@@ -29,8 +29,8 @@ def run_test(test_name):
|
|||||||
print(" -> uptime is " + str(uptime_a) + " secs, Free mem/Max alloc is " + str(freemem_a) + "/" + str(maxalloc_a) )
|
print(" -> uptime is " + str(uptime_a) + " secs, Free mem/Max alloc is " + str(freemem_a) + "/" + str(maxalloc_a) )
|
||||||
|
|
||||||
# run test
|
# run test
|
||||||
print("* Running test '" + test_name + "'", end="")
|
print("2. Running test", end="")
|
||||||
response = requests.get(TEST_URL + test_name, headers=GET_HEADERS, verify=False)
|
response = requests.get(TEST_URL, headers=GET_HEADERS, verify=False)
|
||||||
test_output = response.json()['message']
|
test_output = response.json()['message']
|
||||||
if (test_output != 'OK'):
|
if (test_output != 'OK'):
|
||||||
print(" -> Test Failed!")
|
print(" -> Test Failed!")
|
||||||
@@ -39,11 +39,11 @@ def run_test(test_name):
|
|||||||
print(" -> Test ran successfully, output: " + response.json()['message'])
|
print(" -> Test ran successfully, output: " + response.json()['message'])
|
||||||
|
|
||||||
# wait 10 seconds
|
# wait 10 seconds
|
||||||
print("* Waiting for " + str(WAIT_TIME) + " seconds...")
|
print("3. Waiting for " + str(wait) + " seconds...")
|
||||||
time.sleep(WAIT_TIME)
|
time.sleep(wait)
|
||||||
|
|
||||||
# get latest stats
|
# get latest stats
|
||||||
print("* Getting refreshed stats", end="")
|
print("4. Getting refreshed stats", end="")
|
||||||
response = requests.get(INFO_URL, headers=GET_HEADERS, verify=False)
|
response = requests.get(INFO_URL, headers=GET_HEADERS, verify=False)
|
||||||
uptime_b = response.json()['System Info']['uptime (seconds)']
|
uptime_b = response.json()['System Info']['uptime (seconds)']
|
||||||
freemem_b = response.json()['System Info']['free mem']
|
freemem_b = response.json()['System Info']['free mem']
|
||||||
@@ -60,7 +60,10 @@ def run_test(test_name):
|
|||||||
print()
|
print()
|
||||||
|
|
||||||
# main
|
# main
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser(description="Benchmark EMS-ESP, memory profiler")
|
||||||
parser.add_argument('test name', type=str, default=DEFAULT_TEST_NAME, help='Name of test to run')
|
parser.add_argument("-i", "--ip", metavar="IP", type=str, default="ems-esp.local", help="IP address of EMS-ESP")
|
||||||
|
parser.add_argument("-w", "--wait", metavar="WAIT", type=int, default="10", help="time to wait between test")
|
||||||
|
parser.add_argument("-n", "--name", metavar="NAME", type=str, default="general", help="Name of test to run")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
run_test(args.test)
|
run_test(args.ip, args.wait, args.name)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user