diff --git a/interface/package.json b/interface/package.json index 227ea0665..f4b62ac32 100644 --- a/interface/package.json +++ b/interface/package.json @@ -58,7 +58,7 @@ "prettier": "^3.3.3", "rollup-plugin-visualizer": "^5.12.0", "terser": "^5.36.0", - "typescript-eslint": "8.14.0", + "typescript-eslint": "8.15.0", "vite": "^5.4.11", "vite-plugin-imagemin": "^0.6.1", "vite-tsconfig-paths": "^5.1.2" diff --git a/interface/yarn.lock b/interface/yarn.lock index 35e195d77..70d6b7ed9 100644 --- a/interface/yarn.lock +++ b/interface/yarn.lock @@ -1539,15 +1539,15 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:8.14.0": - version: 8.14.0 - resolution: "@typescript-eslint/eslint-plugin@npm:8.14.0" +"@typescript-eslint/eslint-plugin@npm:8.15.0": + version: 8.15.0 + resolution: "@typescript-eslint/eslint-plugin@npm:8.15.0" dependencies: "@eslint-community/regexpp": "npm:^4.10.0" - "@typescript-eslint/scope-manager": "npm:8.14.0" - "@typescript-eslint/type-utils": "npm:8.14.0" - "@typescript-eslint/utils": "npm:8.14.0" - "@typescript-eslint/visitor-keys": "npm:8.14.0" + "@typescript-eslint/scope-manager": "npm:8.15.0" + "@typescript-eslint/type-utils": "npm:8.15.0" + "@typescript-eslint/utils": "npm:8.15.0" + "@typescript-eslint/visitor-keys": "npm:8.15.0" graphemer: "npm:^1.4.0" ignore: "npm:^5.3.1" natural-compare: "npm:^1.4.0" @@ -1558,66 +1558,68 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 10c0/46c82eb45be82ffec0ab04728a5180691b1d17002c669864861a3044b6d2105a75ca23cc80d18721b40b5e7dff1eff4ed68a43d726e25d55f3e466a9fbeeb873 + checksum: 10c0/90ef10cc7d37a81abec4f4a3ffdfc3a0da8e99d949e03c75437e96e8ab2e896e34b85ab64718690180a7712581031b8611c5d8e7666d6ed4d60b9ace834d58e3 languageName: node linkType: hard -"@typescript-eslint/parser@npm:8.14.0": - version: 8.14.0 - resolution: "@typescript-eslint/parser@npm:8.14.0" +"@typescript-eslint/parser@npm:8.15.0": + version: 8.15.0 + resolution: "@typescript-eslint/parser@npm:8.15.0" dependencies: - "@typescript-eslint/scope-manager": "npm:8.14.0" - "@typescript-eslint/types": "npm:8.14.0" - "@typescript-eslint/typescript-estree": "npm:8.14.0" - "@typescript-eslint/visitor-keys": "npm:8.14.0" + "@typescript-eslint/scope-manager": "npm:8.15.0" + "@typescript-eslint/types": "npm:8.15.0" + "@typescript-eslint/typescript-estree": "npm:8.15.0" + "@typescript-eslint/visitor-keys": "npm:8.15.0" debug: "npm:^4.3.4" peerDependencies: eslint: ^8.57.0 || ^9.0.0 peerDependenciesMeta: typescript: optional: true - checksum: 10c0/522b7afd25cd302c0510cc71985ba55ff92ecc5dbe3fc74a76fefea0169252fdd4b8cad6291fef05f63dfc173951af450dca20859c7f23e387b2e7410e8b97b1 + checksum: 10c0/19c25aea0dc51faa758701a5319a89950fd30494d9d645db8ced84fb60714c5e7d4b51fc4ee8ccb07ddefec88c51ee307ee7e49addd6330ee8f3e7ee9ba329fc languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:8.14.0": - version: 8.14.0 - resolution: "@typescript-eslint/scope-manager@npm:8.14.0" +"@typescript-eslint/scope-manager@npm:8.15.0": + version: 8.15.0 + resolution: "@typescript-eslint/scope-manager@npm:8.15.0" dependencies: - "@typescript-eslint/types": "npm:8.14.0" - "@typescript-eslint/visitor-keys": "npm:8.14.0" - checksum: 10c0/1e1295c6f9febadf63559aad328b23d960510ce6b4c9f74e10d881c3858fa7f1db767cd1af5272d2fe7c9c5c7daebee71854e6f841e413e5d70af282f6616e26 + "@typescript-eslint/types": "npm:8.15.0" + "@typescript-eslint/visitor-keys": "npm:8.15.0" + checksum: 10c0/c27dfdcea4100cc2d6fa967f857067cbc93155b55e648f9f10887a1b9372bb76cf864f7c804f3fa48d7868d9461cdef10bcea3dab7637d5337e8aa8042dc08b9 languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:8.14.0": - version: 8.14.0 - resolution: "@typescript-eslint/type-utils@npm:8.14.0" +"@typescript-eslint/type-utils@npm:8.15.0": + version: 8.15.0 + resolution: "@typescript-eslint/type-utils@npm:8.15.0" dependencies: - "@typescript-eslint/typescript-estree": "npm:8.14.0" - "@typescript-eslint/utils": "npm:8.14.0" + "@typescript-eslint/typescript-estree": "npm:8.15.0" + "@typescript-eslint/utils": "npm:8.15.0" debug: "npm:^4.3.4" ts-api-utils: "npm:^1.3.0" + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 peerDependenciesMeta: typescript: optional: true - checksum: 10c0/42616a664b38ca418e13504247e5e1bad6ae85c045b48e5735ffab977d4bd58cc86fb9d2292bbb314fa408d78d4b0454c3a27dbf9f881f9921917a942825c806 + checksum: 10c0/20f09c79c83b38a962cf7eff10d47a2c01bcc0bab7bf6d762594221cd89023ef8c7aec26751c47b524f53f5c8d38bba55a282529b3df82d5f5ab4350496316f9 languageName: node linkType: hard -"@typescript-eslint/types@npm:8.14.0": - version: 8.14.0 - resolution: "@typescript-eslint/types@npm:8.14.0" - checksum: 10c0/7707f900e24e60e6780c5705f69627b7c0ef912cb3b095dfc8f4a0c84e866c66b1c4c10278cf99724560dc66985ec640750c4192786a09b853f9bb4c3ca5a7ce +"@typescript-eslint/types@npm:8.15.0": + version: 8.15.0 + resolution: "@typescript-eslint/types@npm:8.15.0" + checksum: 10c0/84abc6fd954aff13822a76ac49efdcb90a55c0025c20eee5d8cebcfb68faff33b79bbc711ea524e0209cecd90c5ee3a5f92babc7083c081d3a383a0710264a41 languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:8.14.0": - version: 8.14.0 - resolution: "@typescript-eslint/typescript-estree@npm:8.14.0" +"@typescript-eslint/typescript-estree@npm:8.15.0": + version: 8.15.0 + resolution: "@typescript-eslint/typescript-estree@npm:8.15.0" dependencies: - "@typescript-eslint/types": "npm:8.14.0" - "@typescript-eslint/visitor-keys": "npm:8.14.0" + "@typescript-eslint/types": "npm:8.15.0" + "@typescript-eslint/visitor-keys": "npm:8.15.0" debug: "npm:^4.3.4" fast-glob: "npm:^3.3.2" is-glob: "npm:^4.0.3" @@ -1627,31 +1629,34 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 10c0/5e890d22bd067095f871cf144907a8c302db5b5f014c58906ad58d7f23569951cba805042eac6844744e5abb0d3648c9cc221a91b0703da0a8d6345dc1f83e74 + checksum: 10c0/3af5c129532db3575349571bbf64d32aeccc4f4df924ac447f5d8f6af8b387148df51965eb2c9b99991951d3dadef4f2509d7ce69bf34a2885d013c040762412 languageName: node linkType: hard -"@typescript-eslint/utils@npm:8.14.0": - version: 8.14.0 - resolution: "@typescript-eslint/utils@npm:8.14.0" +"@typescript-eslint/utils@npm:8.15.0": + version: 8.15.0 + resolution: "@typescript-eslint/utils@npm:8.15.0" dependencies: "@eslint-community/eslint-utils": "npm:^4.4.0" - "@typescript-eslint/scope-manager": "npm:8.14.0" - "@typescript-eslint/types": "npm:8.14.0" - "@typescript-eslint/typescript-estree": "npm:8.14.0" + "@typescript-eslint/scope-manager": "npm:8.15.0" + "@typescript-eslint/types": "npm:8.15.0" + "@typescript-eslint/typescript-estree": "npm:8.15.0" peerDependencies: eslint: ^8.57.0 || ^9.0.0 - checksum: 10c0/1fcc2651d870832a799a5d1c85fc9421853508a006d6a6073c8316b012489dda77e123d13aea8f53eb9030a2da2c0eb273a6946a9941caa2519b99b33e89b720 + peerDependenciesMeta: + typescript: + optional: true + checksum: 10c0/65743f51845a1f6fd2d21f66ca56182ba33e966716bdca73d30b7a67c294e47889c322de7d7b90ab0818296cd33c628e5eeeb03cec7ef2f76c47de7a453eeda2 languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:8.14.0": - version: 8.14.0 - resolution: "@typescript-eslint/visitor-keys@npm:8.14.0" +"@typescript-eslint/visitor-keys@npm:8.15.0": + version: 8.15.0 + resolution: "@typescript-eslint/visitor-keys@npm:8.15.0" dependencies: - "@typescript-eslint/types": "npm:8.14.0" - eslint-visitor-keys: "npm:^3.4.3" - checksum: 10c0/d0faf70ed9ecff5e36694bbb161a90bea6db59e0e79a7d4f264d67d565c12b13733d664b736b2730935f013c87ce3155cea954a533d28e99987681bc5f6259c3 + "@typescript-eslint/types": "npm:8.15.0" + eslint-visitor-keys: "npm:^4.2.0" + checksum: 10c0/02a954c3752c4328482a884eb1da06ca8fb72ae78ef28f1d854b18f3779406ed47263af22321cf3f65a637ec7584e5f483e34a263b5c8cec60ec85aebc263574 languageName: node linkType: hard @@ -1694,7 +1699,7 @@ __metadata: terser: "npm:^5.36.0" typesafe-i18n: "npm:^5.26.2" typescript: "npm:^5.6.3" - typescript-eslint: "npm:8.14.0" + typescript-eslint: "npm:8.15.0" vite: "npm:^5.4.11" vite-plugin-imagemin: "npm:^0.6.1" vite-tsconfig-paths: "npm:^5.1.2" @@ -6774,17 +6779,19 @@ __metadata: languageName: node linkType: hard -"typescript-eslint@npm:8.14.0": - version: 8.14.0 - resolution: "typescript-eslint@npm:8.14.0" +"typescript-eslint@npm:8.15.0": + version: 8.15.0 + resolution: "typescript-eslint@npm:8.15.0" dependencies: - "@typescript-eslint/eslint-plugin": "npm:8.14.0" - "@typescript-eslint/parser": "npm:8.14.0" - "@typescript-eslint/utils": "npm:8.14.0" + "@typescript-eslint/eslint-plugin": "npm:8.15.0" + "@typescript-eslint/parser": "npm:8.15.0" + "@typescript-eslint/utils": "npm:8.15.0" + peerDependencies: + eslint: ^8.57.0 || ^9.0.0 peerDependenciesMeta: typescript: optional: true - checksum: 10c0/b9c2f32139d3df52057bfb80d4663fd5e440ccd0da75d92fe91582fe5216213e7012ef691e7d91c75e402e373b9aded6b128b005aaeeae32d7b9d7b39732bcc7 + checksum: 10c0/589aebf0d0b9b79db1cd0b7c2ea08c6b5727c1db095d39077d070c332066c7d549a0eb2ef60b0d41619720c317c1955236c5c8ee6320bc7c6ae475add7223b55 languageName: node linkType: hard diff --git a/scripts/cspell.sh b/scripts/cspell.sh old mode 100644 new mode 100755 diff --git a/scripts/memory_test.py b/scripts/memory_test.py new file mode 100755 index 000000000..4df00949d --- /dev/null +++ b/scripts/memory_test.py @@ -0,0 +1,174 @@ +# see run_memory_test.sh for usage + +import argparse +import requests +import time +from timeit import default_timer as timer +import platform # For getting the operating system type +import subprocess # For executing a shell command +from termcolor import cprint + + +def print_success(x): return cprint(x, 'green') +def print_fail(x): return cprint(x, 'red') + + +def ping_until_up(ip, text): + print(text + "...", flush=True, end="") + time.sleep(1) + param = '-n' if platform.system().lower() == 'windows' else '-c' + command = ["ping", param, "2", ip] + while True: + if (subprocess.run(args=command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0): + print_success("Connected") + time.sleep(1) + return + print(".", flush=True, end="") + time.sleep(1) + + +def run_test(skip, ip, wait, name, count, url, token): + BASE_URL = "http://" + str(ip) + + INFO_URL = BASE_URL + "/api/system/info" + RESTART_URL = BASE_URL + "/api/system/restart" + SYSTEMSTATUS_URL = BASE_URL + "/rest/systemStatus" + 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 }) + + start = timer() + + # Print welcome message + print() + print("Benchmarking EMS-ESP, memory profiling") + print(" Base URL: " + BASE_URL) + print(" Test Name: " + name) + print() + end = timer() + +# set this to True if you want to use the test API + using_test = False + + if not skip: + + # check if IP exists + ping_until_up(ip, "(" + str(round(end - start, 1)) + + ")\t1. Checking if EMS-ESP is reachable") + end = timer() + + # check if it has been compiled with test + response = requests.get( + SYSTEMSTATUS_URL, headers=GET_HEADERS, verify=False) + build_flags = response.json()['build_flags'] + # see if build_flags contains "TEST" + if "TEST" not in build_flags: + print_fail("Error! EMS-ESP not compiled with -DTEST flag") + exit(1) + + # Restart EMS-ESP + print("(" + str(round(end - start, 1)) + + ")\t2. 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") + end = timer() + + # Wait for EMS-ESP to come back up and reconnect to WiFi + ping_until_up(ip, "(" + str(round(end - start, 1)) + + ")\t3. Waiting for EMS-ESP to come back online") + end = timer() + + print("(" + str(round(end - start, 1)) + + ")\t4. Getting initial memory stats...", flush=True, end="") + time.sleep(1) + response = requests.get(INFO_URL, headers=GET_HEADERS, verify=False) + uptime_a = response.json()['system']['uptimeSec'] + freemem_a = response.json()['system']['freeMem'] + maxalloc_a = response.json()['system']['maxAlloc'] + print_success("Uptime is " + str(uptime_a) + + " secs, Free mem/Max alloc before=" + str(freemem_a) + "/" + str(maxalloc_a)) + end = timer() + + # run test count times + for i in range(count): + + print("(" + str(round(end - start, 1)) + + ")\t5. Running test (count #" + str(i+1) + " of " + str(count)+")...", end="") + + # check if name start with a / + if name[0] == "/": + # use URL + response = requests.get( + BASE_URL + url, headers=GET_HEADERS, verify=False) + print("Response: ", response.json()) + else: + # run a named test + response = requests.get( + TEST_URL, headers=GET_HEADERS, verify=False) + + if (response.status_code != 200): + print_fail("Test Failed!") + return + + print_success("Test ran successfully") + end = timer() + + # wait n seconds + print("(" + str(round(end - start, 1)) + ")\t6. Waiting for " + + str(wait) + " seconds...", flush=True, end="") + time.sleep(wait) + print_success("Done") + end = timer() + + # get latest stats + print("(" + str(round(end - start, 1)) + + ")\t7. Getting latest memory stats...", end="") + response = requests.get(INFO_URL, headers=GET_HEADERS, verify=False) + uptime_b = response.json()['system']['uptimeSec'] + freemem_b = response.json()['system']['freeMem'] + maxalloc_b = response.json()['system']['maxAlloc'] + print_success("Uptime is " + str(uptime_b) + + " secs, Free mem/Max alloc after=" + str(freemem_b) + "/" + str(maxalloc_b)) + print() + + if not skip: + # check if it worked and report back + if (uptime_b <= uptime_a): + print_fail("Error! EMS-ESP crashed and restarted :-(") + else: + print("In the " + str(uptime_b - uptime_a) + + " seconds elapsed, we have Free mem/Max alloc: ", end="") + cprint("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", attrs=["bold"]) + + # finish + print() + + +# main +parser = argparse.ArgumentParser( + description="Benchmark EMS-ESP, memory profiler") +parser.add_argument("-s", "--skip", metavar="SKIP", type=bool, + default=False, help="skip all checks and just run the test") +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="memory", help="Name of test to run") +parser.add_argument("-c", "--count", metavar="COUNT", type=int, + default="1", help="number of times to run the test") +parser.add_argument("-u", "--url", metavar="URL", type=str, + help="custom URL") +parser.add_argument("-t", "--token", metavar="TOKEN", type=str, + default="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWV9.2bHpWya2C7Q12WjNUBD6_7N3RCD7CMl-EGhyQVzFdDg", help="Bearer Token") +args = parser.parse_args() +run_test(**vars(args)) diff --git a/scripts/run_memory_test.py b/scripts/run_memory_test.py deleted file mode 100755 index 6fdafcba5..000000000 --- a/scripts/run_memory_test.py +++ /dev/null @@ -1,144 +0,0 @@ -# pre-reqs: -# 1a) via python3 standalone - (sudo apt install python3-pip) -# 1b) via PlatformIO's penv - (using the "PlatformIO Core CLI" menu option) -# 2) install termcolor (python3 -m pip install --upgrade termcolor) -# Run with (example): -# % python3 ./scripts/run_memory_test.py -i 10.10.10.20 -w 30 -t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFkbWluIiwiYWRtaW4iOnRydWV9.2bHpWya2C7Q12WjNUBD6_7N3RCD7CMl-EGhyQVzFdDg -# Note the bearer token is required for the Restart command - -import argparse -import requests -import time -from timeit import default_timer as timer -import platform # For getting the operating system type -import subprocess # For executing a shell command -from termcolor import cprint - - -def print_success(x): return cprint(x, 'green') -def print_fail(x): return cprint(x, 'red') - - -def ping_until_up(ip, text): - print(text + "...", flush=True, end="") - time.sleep(1) - param = '-n' if platform.system().lower() == 'windows' else '-c' - command = ["ping", param, "2", ip] - while True: - if (subprocess.run(args=command, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0): - print_success("Connected") - time.sleep(1) - return - print(".", flush=True, end="") - time.sleep(1) - - -def run_test(ip, wait, name, token): - 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 }) - - start = timer() - - # Print welcome message - print() - print("Benchmarking EMS-ESP, memory profiling") - print(" Base URL: " + BASE_URL) - print(" Test Name: " + name) - print(" 7 steps will run now:") - print() - end = timer() - - # check if IP exists - ping_until_up(ip, "(" + str(round(end - start, 1)) + - ")\t1. Checking if EMS-ESP is reachable") - end = timer() - - # Restart EMS-ESP - print("(" + str(round(end - start, 1)) + - ")\t2. 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") - end = timer() - - # Wait for EMS-ESP to come back up and reconnect to WiFi - ping_until_up(ip, "(" + str(round(end - start, 1)) + - ")\t3. Waiting for EMS-ESP to come back online") - end = timer() - - print("(" + str(round(end - start, 1)) + - ")\t4. Getting initial memory stats...", flush=True, end="") - time.sleep(1) - 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_success("Uptime is " + str(uptime_a) + - " secs, Free mem/Max alloc before=" + str(freemem_a) + "/" + str(maxalloc_a)) - end = timer() - - # run test - print("(" + str(round(end - start, 1)) + - ")\t5. Running test called '" + name + "'...", end="") - response = requests.get(TEST_URL, headers=GET_HEADERS, verify=False) - test_output = response.json()['message'] - if (test_output != 'OK'): - print_fail("Test Failed!") - return - print_success("Test ran successfully") - end = timer() - - # wait n seconds - print("(" + str(round(end - start, 1)) + ")\t6. Waiting for " + - str(wait) + " seconds...", flush=True, end="") - time.sleep(wait) - print_success("Done") - end = timer() - - # get latest stats - print("(" + str(round(end - start, 1)) + - ")\t7. 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'] - maxalloc_b = response.json()['System Info']['max alloc'] - print_success("Uptime is " + str(uptime_b) + - " secs, Free mem/Max alloc after=" + str(freemem_b) + "/" + str(maxalloc_b)) - print() - - # check if it worked and report back - if (uptime_b <= uptime_a): - print(" Error! EMS-ESP crashed and restarted :-(") - else: - print("In the " + str(uptime_b - uptime_a) + - " seconds elapsed, we have Free mem/Max alloc: ", end="") - cprint("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", attrs=["bold"]) - - # finish - print() - - -# main -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="memory", help="Name of test to run") -parser.add_argument("-t", "--token", metavar="TOKEN", - type=str, help="Bearer Token") -args = parser.parse_args() -run_test(**vars(args)) diff --git a/scripts/run_memory_test.sh b/scripts/run_memory_test.sh new file mode 100755 index 000000000..a7fb04a14 --- /dev/null +++ b/scripts/run_memory_test.sh @@ -0,0 +1,22 @@ +# pre-reqs: +# 1a) via python3 standalone - (sudo apt install python3-pip) +# 1b) via PlatformIO's penv - (using the "PlatformIO Core CLI" menu option) +# +# Setup with: +# cd scripts +# python3 -m venv venv +# source ./venv/bin/activate +# pip install -r requirements.txt + +# -s skip all checks, just run the test. default False. +# -i ip address of the device. default ems-esp.local. +# -w wait time in seconds between each test. default 10. +# -c count, the number of tests to run. default 1. +# -u url, custom URL to test against like "/api/boiler/info". optional. +# -t bearer token for the Restart command. optional. default is admin/admin's token. +# -h help + +python3 memory_test.py -s True -i 10.10.10.175 -w 5 -c 30 -u "/api/boiler/info" # V3 +# python3 memory_test.py -s True -i 10.10.10.175 -w 5 -c 30 -u "/api?device=boiler&cmd=info" # V2 + +# python3 memory_test.py -i 10.10.10.175 -n memory diff --git a/src/test/test.cpp b/src/test/test.cpp index 8c5eae5e9..83f837801 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -50,7 +50,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "general") { - EMSESP::logger().info("Testing general. Adding a Boiler and Thermostat"); + EMSESP::logger().notice("Testing general. Adding a Boiler and Thermostat"); // System::test_set_all_active(true); // uncomment if we want to show all entities and give them fake values @@ -77,6 +77,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { return true; } + // // the tests take a lot of memory when built for the ESP32 // so only including the full set in standalone, otherwise a limited selection of basic tests @@ -84,7 +85,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { #ifdef EMSESP_STANDALONE if (cmd == "heat_exchange") { - EMSESP::logger().info("Testing heating exchange..."); + EMSESP::logger().notice("Testing heating exchange..."); add_device(0x08, 219); // Greenstar HIU/Logamax kompakt WS170 @@ -96,7 +97,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "2thermostats") { - EMSESP::logger().info("Testing with multiple thermostats..."); + EMSESP::logger().notice("Testing with multiple thermostats..."); add_device(0x08, 123); // GB072 add_device(0x10, 158); // RC310 @@ -128,7 +129,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "310") { - EMSESP::logger().info("Adding a GB072/RC310 combo..."); + EMSESP::logger().notice("Adding a GB072/RC310 combo..."); add_device(0x08, 123); // GB072 add_device(0x10, 158); // RC310 @@ -155,7 +156,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "gateway") { - EMSESP::logger().info("Adding a Gateway..."); + EMSESP::logger().notice("Adding a Gateway..."); // add 0x48 KM200, via a version command rx_telegram({0x48, 0x0B, 0x02, 0x00, 0xBD, 0x04, 0x06, 00, 00, 00, 00, 00, 00, 00}); @@ -175,7 +176,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "mixer") { - EMSESP::logger().info("Adding a mixer..."); + EMSESP::logger().notice("Adding a mixer..."); // add controller add_device(0x09, 114); @@ -197,7 +198,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "boiler") { - EMSESP::logger().info("Adding boiler..."); + EMSESP::logger().notice("Adding boiler..."); add_device(0x08, 123); // Nefit Trendline // UBAuptime @@ -214,7 +215,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "thermostat") { - EMSESP::logger().info("Adding thermostat..."); + EMSESP::logger().notice("Adding thermostat..."); add_device(0x10, 192); // FW120 @@ -227,7 +228,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "solar") { - EMSESP::logger().info("Adding solar..."); + EMSESP::logger().notice("Adding solar..."); add_device(0x30, 163); // SM100 @@ -246,7 +247,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { } if (cmd == "heatpump") { - EMSESP::logger().info("Adding heatpump..."); + EMSESP::logger().notice("Adding heatpump..."); add_device(0x38, 200); // Enviline module add_device(0x10, 192); // FW120 thermostat @@ -263,7 +264,7 @@ bool Test::test(const std::string & cmd, int8_t id1, int8_t id2) { return false; } -// These next tests are run from the Consol via the test command, so inherit the Shell +// These next tests are run from the Console via the test command, so inherit the Shell void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const std::string & id1_s, const std::string & id2_s) { bool ok = false; // default tests fail @@ -323,15 +324,14 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const shell.printfln("Testing adding a boiler, thermostat, all sensors, scheduler and custom entities..."); // setup fake data - EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS + // EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS // add devices test("general"); - EMSESP::webCustomEntityService.test(); // add custom entities - EMSESP::webCustomizationService.test(); // set customizations - this will overwrite any settings in the FS - EMSESP::temperaturesensor_.test(); // add temperature sensors - EMSESP::webSchedulerService.test(); // add scheduler items + // EMSESP::webCustomEntityService.test(); // add custom entities + // EMSESP::temperaturesensor_.test(); // add temperature sensors + // EMSESP::webSchedulerService.test(); // add scheduler items // shell.invoke_command("show devices"); // shell.invoke_command("show values"); @@ -551,7 +551,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const } if (command == "620") { - EMSESP::logger().info("Testing 620..."); + EMSESP::logger().notice("Testing 620..."); // Version Controller uart_telegram({0x09, 0x0B, 0x02, 0x00, 0x5F, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}); @@ -2238,8 +2238,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const #endif if (!ok) { - shell.printfln("Unknown test command: %s", command.c_str()); - EMSESP::logger().notice("Unknown test command: %s", command.c_str()); + shell.printfln("Unknown test %s", command.c_str()); + EMSESP::logger().notice("Unknown test %s", command.c_str()); } } diff --git a/test/test_api/api_test.http b/test/test_api/api_test.http index e78f68b58..5243da61d 100755 --- a/test/test_api/api_test.http +++ b/test/test_api/api_test.http @@ -82,14 +82,14 @@ GET {{host}}/api/boiler/commands GET {{host_dev}}/api/system/info -# Run a test. EMS-ESP must be compiled with -DEMSESP_TEST -# Use this to load up a dummy thermostat and boiler with data - ### GET {{host_dev}}/api/system/restart Authorization: Bearer {{token}} +# Run a test. EMS-ESP must be compiled with -DEMSESP_TEST +# Use this to load up a dummy thermostat and boiler with data + ### GET {{host_dev}}/api?device=system&cmd=test&data=general @@ -98,6 +98,10 @@ GET {{host_dev}}/api?device=system&cmd=test&data=general GET {{host_dev}}/api/boiler/info +### + +GET {{host_dev}}/api/boiler/info + ### GET {{host_dev}}/api/boiler/values