mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
updated test runner
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -45,3 +45,5 @@ build_wrapper_output_directory/
|
||||
# other build files
|
||||
dump_entities.csv
|
||||
dump_entities.xls*
|
||||
scripts/run.sh
|
||||
test_results.txt
|
||||
|
||||
@@ -1,27 +1,43 @@
|
||||
import argparse
|
||||
import requests
|
||||
import time
|
||||
from termcolor import cprint
|
||||
|
||||
def run_test(ip, wait, name):
|
||||
def print_success(x): return cprint(x, 'green')
|
||||
def print_fail(x): return cprint(x, 'red')
|
||||
|
||||
def run_test(ip, wait, name, token):
|
||||
|
||||
WAIT_REBOOT = 20
|
||||
BASE_URL = "http://" + str(ip)
|
||||
INFO_URL = BASE_URL + "/api/system/info"
|
||||
RESTART_URL = BASE_URL + "/api/system/restart"
|
||||
TEST_URL = BASE_URL + "/api?device=system&cmd=test&data=" + name
|
||||
GET_HEADERS = { 'Content-Type': 'application/json'}
|
||||
GET_HEADERS_SECURE = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + str(token) }
|
||||
# BODY = json.dumps({ "value": 22.5 })
|
||||
|
||||
# example for POSTs:
|
||||
# BODY = json.dumps({ "value": 22.5 })
|
||||
# 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 welcome message
|
||||
print()
|
||||
print("Benchmarking EMS-ESP")
|
||||
print("Benchmarking EMS-ESP, memory profiling")
|
||||
print(" Base URL: " + BASE_URL)
|
||||
print(" Test Name: " + name)
|
||||
print(" 6 steps will run now:")
|
||||
print()
|
||||
|
||||
print("1. Getting initial stats", end="")
|
||||
# Restart EMS-ESP
|
||||
print("1. Doing a cold restart...", end="")
|
||||
response = requests.get(RESTART_URL, headers=GET_HEADERS_SECURE, verify=False)
|
||||
if (response.status_code != 200):
|
||||
print_fail("Failed.")
|
||||
return
|
||||
print_success("Success")
|
||||
|
||||
# Wait for EMS-ESP to come back up and reconnect to WiFi
|
||||
print("2. Waiting " + str(WAIT_REBOOT) + " seconds for EMS-ESP to come back up...")
|
||||
time.sleep(WAIT_REBOOT)
|
||||
|
||||
print("3. Getting initial memory stats", end="")
|
||||
response = requests.get(INFO_URL, headers=GET_HEADERS, verify=False)
|
||||
uptime_a = response.json()['System Info']['uptime (seconds)']
|
||||
freemem_a = response.json()['System Info']['free mem']
|
||||
@@ -29,21 +45,20 @@ def run_test(ip, wait, name):
|
||||
print(" -> uptime is " + str(uptime_a) + " secs, Free mem/Max alloc is " + str(freemem_a) + "/" + str(maxalloc_a) )
|
||||
|
||||
# run test
|
||||
print("2. Running test", end="")
|
||||
print("4. Running test", end="")
|
||||
response = requests.get(TEST_URL, headers=GET_HEADERS, verify=False)
|
||||
test_output = response.json()['message']
|
||||
if (test_output != 'OK'):
|
||||
print(" -> Test Failed!")
|
||||
print_fail(" -> Test Failed!")
|
||||
return
|
||||
|
||||
print(" -> Test ran successfully, output: " + response.json()['message'])
|
||||
print_success(" -> Test ran successfully")
|
||||
|
||||
# wait 10 seconds
|
||||
print("3. Waiting for " + str(wait) + " seconds...")
|
||||
print("5. Waiting for " + str(wait) + " seconds...")
|
||||
time.sleep(wait)
|
||||
|
||||
# get latest stats
|
||||
print("4. Getting refreshed stats", end="")
|
||||
print("6. Getting latest memory stats", end="")
|
||||
response = requests.get(INFO_URL, headers=GET_HEADERS, verify=False)
|
||||
uptime_b = response.json()['System Info']['uptime (seconds)']
|
||||
freemem_b = response.json()['System Info']['free mem']
|
||||
@@ -55,8 +70,13 @@ def run_test(ip, wait, name):
|
||||
if (uptime_b <= uptime_a):
|
||||
print(" Error! EMS-ESP crashed and restarted :-(")
|
||||
else:
|
||||
print(" Success! The delta's are: uptime " + str(uptime_b - uptime_a) + " secs, Free mem/Max alloc " + str(freemem_a - freemem_b) + "/" + str(maxalloc_a - maxalloc_b) )
|
||||
print_success("Success!")
|
||||
print("In the " + str(uptime_b - uptime_a) + " seconds, we have:")
|
||||
cprint("Free mem/Max alloc before=" + str(freemem_a) + "/" + str(maxalloc_a) +
|
||||
" after=" + str(freemem_b) + "/" + str(maxalloc_b) +
|
||||
" diff=" + str(freemem_a - freemem_b) + "/" + str(maxalloc_a - maxalloc_b), "cyan")
|
||||
|
||||
# finish
|
||||
print()
|
||||
|
||||
# main
|
||||
@@ -64,6 +84,6 @@ parser = argparse.ArgumentParser(description="Benchmark EMS-ESP, memory profiler
|
||||
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")
|
||||
parser.add_argument("-t", "--token", metavar="TOKEN", type=str, help="Bearer Token")
|
||||
args = parser.parse_args()
|
||||
run_test(args.ip, args.wait, args.name)
|
||||
|
||||
run_test(**vars(args))
|
||||
|
||||
Reference in New Issue
Block a user