update test runner

This commit is contained in:
Proddy
2023-01-12 11:04:24 +01:00
parent 9b7b5ebfa8
commit a2925011ed
2 changed files with 56 additions and 27 deletions

View File

@@ -1,39 +1,66 @@
import argparse
import requests import requests
import json
import time import time
WAIT_TIME = 10 # in seconds # Setting go here
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
# url = "http://ems-esp.local/api/thermostat/temp" # fixed variables
# token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ8.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWUsInZlcnNpb24iOiIzLjEuMWIwIn0.qeGT53Aom4rDYeIT1Pr4BSMdeWyf4_zN9ue2c51ZnM0" INFO_URL = "http://" + EMSESP_IP + "/api/system/info"
# body = json.dumps({ "value": 22.5 }) TEST_URL = "http://" + EMSESP_IP + "/api?device=system&cmd=test&data="
# headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token } GET_HEADERS = { 'Content-Type': 'application/json'}
# response = requests.post(url, headers=headers, data=body, verify=False) TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ8.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWUsInZlcnNpb24iOiIzLjEuMWIwIn0.qeGT53Aom4rDYeIT1Pr4BSMdeWyf4_zN9ue2c51ZnM0"
POST_HEADERS = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + TOKEN }
# curl http://10.10.10.20/api/system/info def run_test(test_name):
response = requests.get("http://10.10.10.20/api/system/info", headers={ 'Content-Type': 'application/json'}, verify=False)
uptime_now = response.json()['System Info']['uptime (seconds)'] # example for POSTs:
# BODY = json.dumps({ "value": 22.5 })
# response = requests.post(url, headers=HEADERS, data=BODY, verify=False)
print("Before test: uptime=" + str(uptime_now) + " secs, Free mem/Max alloc= " + str(response.json()['System Info']['free mem']) + "/" + str(response.json()['System Info']['max alloc']) ) print()
print("* Getting initial 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']
maxalloc_a = response.json()['System Info']['max alloc']
print(" -> uptime is " + str(uptime_a) + " secs, Free mem/Max alloc is " + str(freemem_a) + "/" + str(maxalloc_a) )
# run test # run test
# curl http://10.10.10.20/api\?device\=system\&cmd\=test\&data\=memory print("* Running test '" + test_name + "'", end="")
response = requests.get("http://10.10.10.20/api?device=system&cmd=test&data=memory", headers={ 'Content-Type': 'application/json'}, verify=False) response = requests.get(TEST_URL + test_name, headers=GET_HEADERS, verify=False)
print("Running test, output: " + response.json()['message']) test_output = response.json()['message']
if (test_output != 'OK'):
print(" -> Test Failed!")
return
# wait 10 seconds print(" -> Test ran successfully, output: " + response.json()['message'])
print("Waiting " + str(WAIT_TIME) + " seconds...")
time.sleep(WAIT_TIME)
response = requests.get("http://10.10.10.20/api/system/info", headers={ 'Content-Type': 'application/json'}, verify=False) # wait 10 seconds
print("* Waiting for " + str(WAIT_TIME) + " seconds...")
time.sleep(WAIT_TIME)
new_uptime = response.json()['System Info']['uptime (seconds)'] # get latest stats
print("* Getting refreshed 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']
maxalloc_b = response.json()['System Info']['max alloc']
print(" -> uptime is " + str(uptime_b) + " secs, Free mem/Max alloc is " + str(freemem_b) + "/" + str(maxalloc_b) )
print()
print(" After test: uptime=" + str(new_uptime) + " secs, Free mem/Max alloc= " + str(response.json()['System Info']['free mem']) + "/" + str(response.json()['System Info']['max alloc']) ) # check if it worked and report back
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) )
if (new_uptime < uptime_now): print()
print("It crashed!")
else:
print("Success!")
# main
parser = argparse.ArgumentParser()
parser.add_argument('test name', type=str, default=DEFAULT_TEST_NAME, help='Name of test to run')
args = parser.parse_args()
run_test(args.test)

View File

@@ -37,8 +37,10 @@ bool Test::run_test(const char * command, int8_t id) {
// simulate HansRemmerswaal's setup - see https://github.com/emsesp/EMS-ESP32/issues/859 // simulate HansRemmerswaal's setup - see https://github.com/emsesp/EMS-ESP32/issues/859
add_device(0x08, 172); // 160 entities - boiler: Enviline/Compress 6000AW/Hybrid 3000-7000iAW/SupraEco/Geo 5xx/WLW196i add_device(0x08, 172); // 160 entities - boiler: Enviline/Compress 6000AW/Hybrid 3000-7000iAW/SupraEco/Geo 5xx/WLW196i
// add_device(0x10, 158); // 62 entities - thermostat: RC300/RC310/Moduline 3000/1010H/CW400/Sense II/HPC410 // add_device(0x10, 158); // 62 entities - thermostat: RC300/RC310/Moduline 3000/1010H/CW400/Sense II/HPC410
// add_device(0x38, 200); // 4 entities - thermostat: RC100H // add_device(0x38, 200); // 4 entities - thermostat: RC100H
return true; return true;
} }