From 97451d2b7a0664513688a0edf65a71c36ca312f8 Mon Sep 17 00:00:00 2001 From: proddy Date: Wed, 11 Jan 2023 20:47:36 +0100 Subject: [PATCH] enable API for test --- src/system.cpp | 3 +-- src/test/test.cpp | 36 ++++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/system.cpp b/src/system.cpp index 66730d9b0..969956567 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -1385,8 +1385,7 @@ bool System::command_info(const char * value, const int8_t id, JsonObject & outp #if defined(EMSESP_DEBUG) // run a test, e.g. http://ems-esp/api?device=system&cmd=test&data=boiler bool System::command_test(const char * value, const int8_t id) { - Test::run_test(value, id); - return true; + return Test::run_test(value, id); } #endif diff --git a/src/test/test.cpp b/src/test/test.cpp index cc68038df..c48160456 100644 --- a/src/test/test.cpp +++ b/src/test/test.cpp @@ -23,12 +23,24 @@ namespace emsesp { -// no shell +// no shell, called via the API or 'call system test' command bool Test::run_test(const char * command, int8_t id) { if ((command == nullptr) || (strlen(command) == 0)) { return false; } + if (strcmp(command, "memory") == 0) { + EMSESP::logger().notice("Testing memory by adding lots of devices and entities..."); + + System::test_set_all_active(true); // include all entities and give them fake values + + // 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(0x10, 158); // 62 entities - thermostat: RC300/RC310/Moduline 3000/1010H/CW400/Sense II/HPC410 + // add_device(0x38, 200); // 4 entities - thermostat: RC100H + return true; + } + if (strcmp(command, "general") == 0) { EMSESP::logger().info("Testing general. Adding a Boiler and Thermostat"); @@ -245,21 +257,6 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const command = cmd; } - // https://github.com/emsesp/EMS-ESP32/issues/869 - if (command == "memory") { - EMSESP::logger().notice("Testing memory by adding lots of devices and entities..."); - shell.printfln("Testing memory by adding lots of devices and entities..."); - - System::test_set_all_active(true); - - // 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(0x10, 158); // 62 entities - thermostat: RC300/RC310/Moduline 3000/1010H/CW400/Sense II/HPC410 - // add_device(0x38, 200); // 4 entities - thermostat: RC100H - - shell.invoke_command("show values"); - } - if (command == "general") { shell.printfln("Testing adding a general boiler & thermostat..."); run_test("general"); @@ -269,6 +266,13 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd, const shell.invoke_command("show mqtt"); } + // https://github.com/emsesp/EMS-ESP32/issues/869 + if (command == "memory") { + shell.printfln("Testing memory by adding lots of devices and entities..."); + run_test("memory"); + shell.invoke_command("show values"); + } + // // 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