From ca893e9e7346b34f972a29e9e89350d076fe3b86 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 25 Jun 2019 10:01:27 -0700 Subject: [PATCH 1/6] Fix device test environment variables Device tests were not connecting properly to WiFi because the environment variables were not set when WiFi.connect was called. This would result in tests sometimes working *if* the prior sketch run on the ESP saved WiFi connection information and auto-connect was enabled. But, in most cases, the tests would simply never connect to any WiFi and fail. getenv() works only after BS_RUN is called (because BS_RUN handles the actual parsing of environment variables sent from the host). Add a "pretest" function to all tests which is called by the host test controller only after all environment variables are set. Move all WiFi/etc. operations that were in each separate test's setup() into it. So the order of operations for tests now is: ESP: setup() -> Set serial baud -> Call BS_RUN() HOST: Send environment Send "do pretest" ESP: pretest() -> Set Wifi using env. ariables, etc. return "true" on success HOST: Send "run test 1" ESP: Run 1st test, return result HOST: Send "run test 2" ESP: Run 2nd test, return result If nothing is needed to be set up, just return true from the pretest function. All tests now run and at least connect to WiFi. There still seem to be some actual test errors, but not because of the WiFi/environment variables anymore. --- tests/device/libraries/BSTest/runner.py | 23 +++++++++++++++++-- .../device/libraries/BSTest/src/BSProtocol.h | 17 ++++++++++++++ tests/device/test_BearSSL/test_BearSSL.ino | 9 ++++++-- .../test_ClientContext/test_ClientContext.ino | 7 +++++- tests/device/test_FS/test_FS.ino | 4 ++++ .../test_Print_printf/test_Print_printf.ino | 5 ++++ .../test_WiFiClient/test_WiFiClient.ino | 9 ++++++-- .../test_WiFiServer/test_WiFiServer.ino | 7 +++++- .../test_WiFi_events/test_WiFi_events.ino | 7 +++++- .../test_http_client/test_http_client.ino | 7 +++++- .../test_http_server/test_http_server.ino | 7 +++++- tests/device/test_iostream/test_iostream.ino | 5 ++++ tests/device/test_libc/test_libc.ino | 5 ++++ .../device/test_millis_mm/test_millis_mm.ino | 10 ++++++-- tests/device/test_newlib/test_newlib.ino | 5 ++++ .../device/test_overrides/test_overrides.ino | 7 +++++- tests/device/test_ping/test_ping.ino | 7 +++++- tests/device/test_random/test_random.ino | 5 ++++ tests/device/test_schedule/test_schedule.ino | 4 ++++ tests/device/test_serial/test_serial.ino | 5 ++++ .../test_stack_in_heap/test_stack_in_heap.ino | 5 ++++ .../test_stack_in_sys/test_stack_in_sys.ino | 5 ++++ tests/device/test_tests/test_tests.ino | 5 ++++ tests/device/test_time/test_time.ino | 7 +++++- .../test_umm_malloc/test_umm_malloc.ino | 5 ++++ 25 files changed, 166 insertions(+), 16 deletions(-) diff --git a/tests/device/libraries/BSTest/runner.py b/tests/device/libraries/BSTest/runner.py index 808d910a2b..b376c1ff8e 100644 --- a/tests/device/libraries/BSTest/runner.py +++ b/tests/device/libraries/BSTest/runner.py @@ -103,6 +103,10 @@ def run_tests(self): if res != BSTestRunner.SUCCESS: print('failed to set environment variables') break; + res = self.pretest() + if res != BSTestRunner.SUCCESS: + print('failed to run pretest init') + break; should_update_env = False if name in self.mocks: debug_print('setting up mocks') @@ -126,7 +130,7 @@ def run_tests(self): debug_print('test output was:') debug_print(test_output.getvalue()) if result == BSTestRunner.SUCCESS: - test_case.stdout = test_output.getvalue() + test_case.stdout = filter(lambda c: ord(c) < 128, test_output.getvalue()) print('test "{}" passed'.format(name)) else: print('test "{}" failed'.format(name)) @@ -197,6 +201,21 @@ def update_env(self, env_to_set): return BSTestRunner.TIMEOUT return BSTestRunner.SUCCESS + def pretest(self): + # Environment now set up, call the pretest init (wifi connect, etc.) + self.sp.sendline('pretest'); + timeout = 10 + while timeout > 0: + res = self.sp.expect(['>>>>>bs_test_pretest result=1', EOF, TIMEOUT]) # Only expect a pass, abort testing if failure + if res == 0: + break + time.sleep(0.1) + timeout -= 0.1 + if res != 0: + return BSTestRunner.TIMEOUT + else: + return BSTestRunner.SUCCESS + def request_env(self, key): self.sp.sendline('getenv "{}"'.format(key)) timeout = 10 @@ -269,7 +288,7 @@ def main(): ts = run_tests(sp, name, mocks, env_vars) if args.output: with open(args.output, "w") as f: - TestSuite.to_file(f, [ts]) + TestSuite.to_file(f, [ts], encoding='raw_unicode_escape') return 0 if __name__ == '__main__': diff --git a/tests/device/libraries/BSTest/src/BSProtocol.h b/tests/device/libraries/BSTest/src/BSProtocol.h index f4ed73bd7a..51deb41ebe 100644 --- a/tests/device/libraries/BSTest/src/BSProtocol.h +++ b/tests/device/libraries/BSTest/src/BSProtocol.h @@ -5,6 +5,8 @@ #define BS_LINE_PREFIX ">>>>>bs_test_" +extern bool pretest(); + namespace bs { namespace protocol @@ -58,6 +60,12 @@ void output_getenv_result(IO& io, const char* key, const char* value) io.printf(BS_LINE_PREFIX "getenv value=\"%s\"\n", value); } +template +void output_pretest_result(IO& io, bool res) +{ + io.printf(BS_LINE_PREFIX "pretest result=%d\n", res?1:0); +} + template bool input_handle(IO& io, char* line_buf, size_t line_buf_size, int& test_num) { @@ -87,6 +95,15 @@ bool input_handle(IO& io, char* line_buf, size_t line_buf_size, int& test_num) output_getenv_result(io, argv[1], (value != NULL) ? value : ""); return false; } + if (strcmp(argv[0], "pretest") == 0) { + if (argc != 1) { + return false; + } + io.printf("pretest started\n"); + bool res = ::pretest(); + output_pretest_result(io, res); + return res; + } /* not one of the commands, try to parse as test number */ char* endptr; test_num = (int) strtol(argv[0], &endptr, 10); diff --git a/tests/device/test_BearSSL/test_BearSSL.ino b/tests/device/test_BearSSL/test_BearSSL.ino index 675c24de60..cd1bd9d62f 100644 --- a/tests/device/test_BearSSL/test_BearSSL.ino +++ b/tests/device/test_BearSSL/test_BearSSL.ino @@ -33,6 +33,11 @@ void setup() { Serial.begin(115200); Serial.setDebugOutput(true); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.mode(WIFI_STA); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); @@ -45,9 +50,9 @@ void setup() Serial.printf("Number of CA certs read: %d\n", numCerts); if (numCerts == 0) { Serial.printf("No certs found. Did you run certs-from-mozill.py and upload the SPIFFS directory before running?\n"); - REQUIRE(1==0); + return false; } - BS_RUN(Serial); + return true; } static void stopAll() diff --git a/tests/device/test_ClientContext/test_ClientContext.ino b/tests/device/test_ClientContext/test_ClientContext.ino index 10cedf1076..25f4db2cf5 100644 --- a/tests/device/test_ClientContext/test_ClientContext.ino +++ b/tests/device/test_ClientContext/test_ClientContext.ino @@ -23,13 +23,18 @@ void setup() { Serial.begin(115200); Serial.setDebugOutput(true); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.mode(WIFI_STA); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); while (WiFi.status() != WL_CONNECTED) { delay(500); } - BS_RUN(Serial); + return true; } TEST_CASE("WiFi release ClientContext", "[clientcontext]") diff --git a/tests/device/test_FS/test_FS.ino b/tests/device/test_FS/test_FS.ino index b516c8b16f..0a33dc8586 100644 --- a/tests/device/test_FS/test_FS.ino +++ b/tests/device/test_FS/test_FS.ino @@ -10,6 +10,10 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} TEST_CASE("read-write test","[fs]") diff --git a/tests/device/test_Print_printf/test_Print_printf.ino b/tests/device/test_Print_printf/test_Print_printf.ino index 7396572625..9cf3a60d02 100644 --- a/tests/device/test_Print_printf/test_Print_printf.ino +++ b/tests/device/test_Print_printf/test_Print_printf.ino @@ -9,6 +9,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("Print::printf works for any reasonable output length", "[Print]") { diff --git a/tests/device/test_WiFiClient/test_WiFiClient.ino b/tests/device/test_WiFiClient/test_WiFiClient.ino index 4d7eb73913..239d44e35d 100644 --- a/tests/device/test_WiFiClient/test_WiFiClient.ino +++ b/tests/device/test_WiFiClient/test_WiFiClient.ino @@ -13,13 +13,18 @@ void setup() { Serial.begin(115200); Serial.setDebugOutput(true); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.mode(WIFI_STA); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); while (WiFi.status() != WL_CONNECTED) { delay(500); } - BS_RUN(Serial); + return true; } static void stopAll() @@ -53,4 +58,4 @@ TEST_CASE("WiFi disconnect during WiFiClient::connect", "[wificlient]") void loop() { -} \ No newline at end of file +} diff --git a/tests/device/test_WiFiServer/test_WiFiServer.ino b/tests/device/test_WiFiServer/test_WiFiServer.ino index 2040df54c8..5af9cfce27 100644 --- a/tests/device/test_WiFiServer/test_WiFiServer.ino +++ b/tests/device/test_WiFiServer/test_WiFiServer.ino @@ -10,13 +10,18 @@ BS_ENV_DECLARE(); void setup() { Serial.begin(115200); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); while (WiFi.status() != WL_CONNECTED) { delay(500); } MDNS.begin("esp8266-wfs-test"); - BS_RUN(Serial); + return true; } TEST_CASE("Simple echo server", "[WiFiServer]") diff --git a/tests/device/test_WiFi_events/test_WiFi_events.ino b/tests/device/test_WiFi_events/test_WiFi_events.ino index 704f3c3c7d..e70b9baecc 100644 --- a/tests/device/test_WiFi_events/test_WiFi_events.ino +++ b/tests/device/test_WiFi_events/test_WiFi_events.ino @@ -11,9 +11,14 @@ void setup() { Serial.begin(115200); Serial.setDebugOutput(false); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.mode(WIFI_OFF); - BS_RUN(Serial); + return true; } static std::map sEventsReceived; diff --git a/tests/device/test_http_client/test_http_client.ino b/tests/device/test_http_client/test_http_client.ino index c2c9b60e54..ee8b8c8115 100644 --- a/tests/device/test_http_client/test_http_client.ino +++ b/tests/device/test_http_client/test_http_client.ino @@ -11,12 +11,17 @@ void setup() { Serial.begin(115200); Serial.setDebugOutput(true); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); while (WiFi.status() != WL_CONNECTED) { delay(500); } - BS_RUN(Serial); + return true; } const char* fp = "44 40 9E 34 92 2D E4 61 A4 89 A8 D5 7F 71 B7 62 B3 FD DD E1"; diff --git a/tests/device/test_http_server/test_http_server.ino b/tests/device/test_http_server/test_http_server.ino index c408555822..e9f8bda923 100644 --- a/tests/device/test_http_server/test_http_server.ino +++ b/tests/device/test_http_server/test_http_server.ino @@ -16,6 +16,11 @@ void setup() { Serial.begin(115200); Serial.setDebugOutput(true); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); while (WiFi.status() != WL_CONNECTED) { @@ -24,7 +29,7 @@ void setup() MDNS.begin("etd"); server.onNotFound([](){ server.send(404); }); server.begin(); - BS_RUN(Serial); + return true; } void handle_request() diff --git a/tests/device/test_iostream/test_iostream.ino b/tests/device/test_iostream/test_iostream.ino index b644882bf2..db803ffe82 100644 --- a/tests/device/test_iostream/test_iostream.ino +++ b/tests/device/test_iostream/test_iostream.ino @@ -11,6 +11,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("can print to std::cout", "[iostream]") { std::stringstream test_stream(""); diff --git a/tests/device/test_libc/test_libc.ino b/tests/device/test_libc/test_libc.ino index f4490fa2f9..a3ab6c223d 100644 --- a/tests/device/test_libc/test_libc.ino +++ b/tests/device/test_libc/test_libc.ino @@ -9,6 +9,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + extern "C" { extern void memmove_main(void); extern void memcpy_main(void); diff --git a/tests/device/test_millis_mm/test_millis_mm.ino b/tests/device/test_millis_mm/test_millis_mm.ino index e7cb59cea7..7a8e8a17bc 100644 --- a/tests/device/test_millis_mm/test_millis_mm.ino +++ b/tests/device/test_millis_mm/test_millis_mm.ino @@ -461,11 +461,17 @@ void setup () { Serial.begin(115200); WiFi.mode( WIFI_OFF ); - us_count_init(); // Start up timer overflow sampling BS_RUN(Serial); - } //setup + +//--------------------------------------------------------------------------- +bool pretest () +{ + us_count_init(); // Start up timer overflow sampling + return true; +} //pretest + //--------------------------------------------------------------------------- void loop(void) { diff --git a/tests/device/test_newlib/test_newlib.ino b/tests/device/test_newlib/test_newlib.ino index 46e9167347..32abbb9141 100644 --- a/tests/device/test_newlib/test_newlib.ino +++ b/tests/device/test_newlib/test_newlib.ino @@ -8,6 +8,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("Floating point formatting works", "[newlib]") { char buf[16]; diff --git a/tests/device/test_overrides/test_overrides.ino b/tests/device/test_overrides/test_overrides.ino index 655f12084d..e8737f7cb7 100644 --- a/tests/device/test_overrides/test_overrides.ino +++ b/tests/device/test_overrides/test_overrides.ino @@ -15,11 +15,16 @@ static unsigned setup_micros; void setup() { - setup_micros = micros(); + setup_micros = micros(); Serial.begin(115200); BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("ADC_MODE override works", "[core]") { auto vcc = ESP.getVcc(); diff --git a/tests/device/test_ping/test_ping.ino b/tests/device/test_ping/test_ping.ino index 1ac7c82699..a5bb98afff 100644 --- a/tests/device/test_ping/test_ping.ino +++ b/tests/device/test_ping/test_ping.ino @@ -10,13 +10,18 @@ void setup() { Serial.begin(115200); Serial.setDebugOutput(true); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.mode(WIFI_STA); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); while (WiFi.status() != WL_CONNECTED) { delay(500); } - BS_RUN(Serial); + return true; } static struct ping_option po; diff --git a/tests/device/test_random/test_random.ino b/tests/device/test_random/test_random.ino index 5d71350d5e..1e8efea266 100644 --- a/tests/device/test_random/test_random.ino +++ b/tests/device/test_random/test_random.ino @@ -8,6 +8,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("If randomSeed is not called, random() uses hardware PRNG", "[random]") { diff --git a/tests/device/test_schedule/test_schedule.ino b/tests/device/test_schedule/test_schedule.ino index 963635a681..26c7d114db 100644 --- a/tests/device/test_schedule/test_schedule.ino +++ b/tests/device/test_schedule/test_schedule.ino @@ -9,6 +9,10 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} TEST_CASE("scheduled functions are executed", "[schedule]") { diff --git a/tests/device/test_serial/test_serial.ino b/tests/device/test_serial/test_serial.ino index 19481f91ff..6cdf2b2673 100644 --- a/tests/device/test_serial/test_serial.ino +++ b/tests/device/test_serial/test_serial.ino @@ -55,6 +55,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + void test_setup() { Serial.begin(BAUD); diff --git a/tests/device/test_stack_in_heap/test_stack_in_heap.ino b/tests/device/test_stack_in_heap/test_stack_in_heap.ino index 02cb11e9f1..79b513c9b3 100644 --- a/tests/device/test_stack_in_heap/test_stack_in_heap.ino +++ b/tests/device/test_stack_in_heap/test_stack_in_heap.ino @@ -11,6 +11,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("stack in user's HEAP ram", "[bs]") { bool sysstack = (((unsigned long)g_pcont) >> 16) == 0x3fff; diff --git a/tests/device/test_stack_in_sys/test_stack_in_sys.ino b/tests/device/test_stack_in_sys/test_stack_in_sys.ino index 6a1595c5ad..09270e9666 100644 --- a/tests/device/test_stack_in_sys/test_stack_in_sys.ino +++ b/tests/device/test_stack_in_sys/test_stack_in_sys.ino @@ -10,6 +10,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("stack in SYS ram", "[bs]") { bool sysstack = (((unsigned long)g_pcont) >> 16) == 0x3fff; diff --git a/tests/device/test_tests/test_tests.ino b/tests/device/test_tests/test_tests.ino index 2420805fc0..62110126b6 100644 --- a/tests/device/test_tests/test_tests.ino +++ b/tests/device/test_tests/test_tests.ino @@ -8,6 +8,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("this test runs successfully", "[bs]") { diff --git a/tests/device/test_time/test_time.ino b/tests/device/test_time/test_time.ino index 6642d3687c..006ba3fa41 100644 --- a/tests/device/test_time/test_time.ino +++ b/tests/device/test_time/test_time.ino @@ -8,12 +8,17 @@ BS_ENV_DECLARE(); void setup() { Serial.begin(115200); + BS_RUN(Serial); +} + +bool pretest() +{ WiFi.persistent(false); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); while (WiFi.status() != WL_CONNECTED) { delay(500); } - BS_RUN(Serial); + return true; } diff --git a/tests/device/test_umm_malloc/test_umm_malloc.ino b/tests/device/test_umm_malloc/test_umm_malloc.ino index b805f73f7d..419b23c3c0 100644 --- a/tests/device/test_umm_malloc/test_umm_malloc.ino +++ b/tests/device/test_umm_malloc/test_umm_malloc.ino @@ -11,6 +11,11 @@ void setup() BS_RUN(Serial); } +bool pretest() +{ + return true; +} + TEST_CASE("umm_info can be called", "[umm_malloc]") { umm_info(NULL, 1); From 3183a7accbe7a617ec41c19c11ce9d55693731c8 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 25 Jun 2019 10:22:43 -0700 Subject: [PATCH 2/6] Remove unneeded debug prints --- tests/device/libraries/BSTest/src/BSProtocol.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/device/libraries/BSTest/src/BSProtocol.h b/tests/device/libraries/BSTest/src/BSProtocol.h index 51deb41ebe..05a874f956 100644 --- a/tests/device/libraries/BSTest/src/BSProtocol.h +++ b/tests/device/libraries/BSTest/src/BSProtocol.h @@ -99,10 +99,9 @@ bool input_handle(IO& io, char* line_buf, size_t line_buf_size, int& test_num) if (argc != 1) { return false; } - io.printf("pretest started\n"); bool res = ::pretest(); output_pretest_result(io, res); - return res; + return false; } /* not one of the commands, try to parse as test number */ char* endptr; From 6d15d7d30e51a4f068d9dd7e53f8ee7d0a082b3b Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 25 Jun 2019 10:38:04 -0700 Subject: [PATCH 3/6] Silence esptool.py output when not in V=1 mode Esptool-ck.exe had an option to be silent, but esptool.py doesn't so the output is very chatty and makes looking a the run logs hard (60 lines of esptool.py output, 3 lines of actual test reports). Redirect esptool.py STDOUT to /dev/null unless V=1 to clear this up. --- tests/device/Makefile | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/device/Makefile b/tests/device/Makefile index 2d2c80fa8b..35e1864439 100644 --- a/tests/device/Makefile +++ b/tests/device/Makefile @@ -23,6 +23,7 @@ TEST_REPORT_HTML := test_report.html ifneq ("$(V)","1") SILENT = @ + REDIR = >& /dev/null else BUILDER_DEBUG_FLAG = -verbose RUNNER_DEBUG_FLAG = -d @@ -58,16 +59,17 @@ ifneq ("$(NO_BUILD)","1") endif ifneq ("$(NO_UPLOAD)","1") @test -n "$(UPLOAD_PORT)" || (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1) - @test -e $(dir $@)/make_spiffs.py && (echo "Generating and uploading SPIFFS" && \ - (cd $(dir $@) && $(PYTHON) ./make_spiffs.py) && \ + @test -e $(dir $@)/make_spiffs.py && ( \ + echo "Generating and uploading SPIFFS" && \ + (cd $(dir $@) && $(PYTHON) ./make_spiffs.py $(REDIR) ) && \ $(MKSPIFFS) --create $(dir $@)data/ --size 0xFB000 \ - --block 8192 --page 256 $(LOCAL_BUILD_DIR)/spiffs.img && \ + --block 8192 --page 256 $(LOCAL_BUILD_DIR)/spiffs.img $(REDIR) && \ $(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) \ --chip esp8266 \ --port $(UPLOAD_PORT) \ --baud $(UPLOAD_BAUD) \ --after no_reset \ - write_flash 0x300000 $(LOCAL_BUILD_DIR)/spiffs.img ) \ + write_flash 0x300000 $(LOCAL_BUILD_DIR)/spiffs.img $(REDIR) ) \ || (echo "No SPIFFS to upload") @echo Uploading binary $(SILENT)$(ESPTOOL) $(UPLOAD_VERBOSE_FLAG) \ @@ -75,7 +77,7 @@ ifneq ("$(NO_UPLOAD)","1") --port $(UPLOAD_PORT) \ --baud $(UPLOAD_BAUD) \ --after no_reset \ - write_flash 0x0 $(LOCAL_BUILD_DIR)/$(notdir $@).bin # no reset + write_flash 0x0 $(LOCAL_BUILD_DIR)/$(notdir $@).bin $(REDIR) # no reset endif ifneq ("$(NO_RUN)","1") @test -n "$(UPLOAD_PORT)" || (echo "Failed to detect upload port, please export UPLOAD_PORT manually" && exit 1) @@ -84,7 +86,7 @@ ifneq ("$(NO_RUN)","1") --chip esp8266 \ --port $(UPLOAD_PORT) \ --baud $(UPLOAD_BAUD) \ - read_flash_status # reset + read_flash_status $(REDIR) # reset @source $(BS_DIR)/virtualenv/bin/activate && \ $(PYTHON) $(BS_DIR)/runner.py \ $(RUNNER_DEBUG_FLAG) \ From a4f0537f05b66c5fa904c3e89ae6af8f78e32eb5 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 25 Jun 2019 10:54:53 -0700 Subject: [PATCH 4/6] Speed up builds massively by removing old JSON arduino-builder checks the build.options.json file and then goes off and pegs my CPU at 100% for over a minute on each test compile checking if files have been modified. Simply deleting any pre-existing options.json file causes this step to be skipped and a quick, clean recompile is done in siginificantly less time. --- tests/device/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/device/Makefile b/tests/device/Makefile index 35e1864439..e117e56e67 100644 --- a/tests/device/Makefile +++ b/tests/device/Makefile @@ -45,6 +45,7 @@ $(TEST_LIST): ifneq ("$(NO_BUILD)","1") @test -n "$(ARDUINO_IDE_PATH)" || (echo "Please export ARDUINO_IDE_PATH" && exit 1) @echo Compiling $(notdir $@) + @rm -f $(LOCAL_BUILD_DIR)/build.options.json $(SILENT)$(BUILD_TOOL) -compile -logger=human \ -libraries "$(PWD)/libraries" \ -core-api-version="10608" \ From c42eb8d5c7e855b731d9f6e6261d3feb252270c9 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 25 Jun 2019 11:12:12 -0700 Subject: [PATCH 5/6] Enable compile warnings, fix any that show up Enable all GCC warnings when building the tests and fix any that came up (mostly signed/unsigned, unused, and deprecated ones). --- tests/device/Makefile | 2 +- tests/device/libraries/BSTest/src/BSArgs.h | 4 ++-- tests/device/test_BearSSL/test_BearSSL.ino | 13 +------------ .../device/test_Print_printf/test_Print_printf.ino | 2 +- tests/device/test_WiFi_events/test_WiFi_events.ino | 12 ++++++++++++ tests/device/test_http_client/test_http_client.ino | 12 +++++++++--- tests/device/test_millis_mm/test_millis_mm.ino | 2 ++ tests/device/test_random/test_random.ino | 6 +++--- tests/device/test_time/test_time.ino | 5 +---- 9 files changed, 32 insertions(+), 26 deletions(-) diff --git a/tests/device/Makefile b/tests/device/Makefile index e117e56e67..a44079ffdb 100644 --- a/tests/device/Makefile +++ b/tests/device/Makefile @@ -49,7 +49,7 @@ ifneq ("$(NO_BUILD)","1") $(SILENT)$(BUILD_TOOL) -compile -logger=human \ -libraries "$(PWD)/libraries" \ -core-api-version="10608" \ - -warnings=none \ + -warnings=all \ $(BUILDER_DEBUG_FLAG) \ -build-path $(LOCAL_BUILD_DIR) \ -tools $(ARDUINO_IDE_PATH)/tools-builder \ diff --git a/tests/device/libraries/BSTest/src/BSArgs.h b/tests/device/libraries/BSTest/src/BSArgs.h index e4a7008f15..060bcdf18c 100644 --- a/tests/device/libraries/BSTest/src/BSArgs.h +++ b/tests/device/libraries/BSTest/src/BSArgs.h @@ -69,7 +69,7 @@ inline size_t split_args(char *line, char **argv, size_t argv_size) const int ESCAPE = '\\'; const int SPACE = ' '; split_state_t state = SS_SPACE; - int argc = 0; + size_t argc = 0; char *next_arg_start = line; char *out_ptr = line; for (char *in_ptr = line; argc < argv_size - 1; ++in_ptr) { @@ -148,4 +148,4 @@ inline size_t split_args(char *line, char **argv, size_t argv_size) } // namespace protocol -#endif //BS_ARGS_H \ No newline at end of file +#endif //BS_ARGS_H diff --git a/tests/device/test_BearSSL/test_BearSSL.ino b/tests/device/test_BearSSL/test_BearSSL.ino index cd1bd9d62f..e4db2fdc0e 100644 --- a/tests/device/test_BearSSL/test_BearSSL.ino +++ b/tests/device/test_BearSSL/test_BearSSL.ino @@ -55,17 +55,6 @@ bool pretest() return true; } -static void stopAll() -{ - WiFiClient::stopAll(); -} - -static void disconnectWiFI() -{ - wifi_station_disconnect(); -} - - // Set time via NTP, as required for x.509 validation void setClock() { configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov"); @@ -148,7 +137,7 @@ int run(const char *str) return maxUsage; } -#define TC(x) TEST_CASE("BearSSL - Maximum stack usage < 5600 bytes @ "x".badssl.org", "[bearssl]") { REQUIRE(run(x) < 5600); } +#define TC(x) TEST_CASE("BearSSL - Maximum stack usage < 5600 bytes @ " x ".badssl.org", "[bearssl]") { REQUIRE(run(x) < 5600); } TC("expired") TC("wrong.host") diff --git a/tests/device/test_Print_printf/test_Print_printf.ino b/tests/device/test_Print_printf/test_Print_printf.ino index 9cf3a60d02..1411467f9f 100644 --- a/tests/device/test_Print_printf/test_Print_printf.ino +++ b/tests/device/test_Print_printf/test_Print_printf.ino @@ -20,7 +20,7 @@ TEST_CASE("Print::printf works for any reasonable output length", "[Print]") auto test_printf = [](size_t size) { StreamString str; auto buf = new char[size + 1]; - for (int i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) { buf[i] = 'a'; } buf[size] = 0; diff --git a/tests/device/test_WiFi_events/test_WiFi_events.ino b/tests/device/test_WiFi_events/test_WiFi_events.ino index e70b9baecc..88777b61ab 100644 --- a/tests/device/test_WiFi_events/test_WiFi_events.ino +++ b/tests/device/test_WiFi_events/test_WiFi_events.ino @@ -34,10 +34,13 @@ TEST_CASE("WiFi.onEvent is called for specific events", "[wifi][events]") sEventsReceived[WIFI_EVENT_STAMODE_DISCONNECTED] = 0; sEventsReceived[WIFI_EVENT_STAMODE_GOT_IP] = 0; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" WiFi.onEvent(onWiFiEvent, WIFI_EVENT_STAMODE_CONNECTED); WiFi.onEvent(onWiFiEvent, WIFI_EVENT_STAMODE_DISCONNECTED); WiFi.onEvent(onWiFiEvent, WIFI_EVENT_STAMODE_GOT_IP); WiFi.onEvent(onWiFiEvent, WIFI_EVENT_ANY); +#pragma GCC diagnostic pop WiFi.mode(WIFI_STA); WiFi.begin(getenv("STA_SSID"), getenv("STA_PASS")); @@ -49,9 +52,12 @@ TEST_CASE("WiFi.onEvent is called for specific events", "[wifi][events]") WiFi.disconnect(); delay(100); WiFi.mode(WIFI_OFF); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" REQUIRE(sEventsReceived[WIFI_EVENT_STAMODE_CONNECTED] == 2); REQUIRE(sEventsReceived[WIFI_EVENT_STAMODE_DISCONNECTED] >= 2 && sEventsReceived[WIFI_EVENT_STAMODE_DISCONNECTED] % 2 == 0); REQUIRE(sEventsReceived[WIFI_EVENT_STAMODE_GOT_IP] == 2); +#pragma GCC diagnostic pop } TEST_CASE("STA mode events are called both when using DHCP and static config", "[wifi][events]") @@ -59,14 +65,17 @@ TEST_CASE("STA mode events are called both when using DHCP and static config", " String events; auto handler1 = WiFi.onStationModeConnected([&](const WiFiEventStationModeConnected& evt){ + (void) evt; events += "connected,"; }); auto handler2 = WiFi.onStationModeDisconnected([&](const WiFiEventStationModeDisconnected& evt){ + (void) evt; if (events.length()) { events += "disconnected,"; } }); auto handler3 = WiFi.onStationModeGotIP([&](const WiFiEventStationModeGotIP& evt){ + (void) evt; events += "got_ip,"; }); @@ -109,12 +118,15 @@ TEST_CASE("Events are not called if handler is deleted", "[wifi][events]") String events; WiFi.onStationModeConnected([&](const WiFiEventStationModeConnected& evt){ + (void) evt; events += "connected,"; }); WiFi.onStationModeDisconnected([&](const WiFiEventStationModeDisconnected& evt){ + (void) evt; events += "disconnected,"; }); WiFi.onStationModeGotIP([&](const WiFiEventStationModeGotIP& evt){ + (void) evt; events += "got_ip,"; }); diff --git a/tests/device/test_http_client/test_http_client.ino b/tests/device/test_http_client/test_http_client.ino index ee8b8c8115..4757fdb4fe 100644 --- a/tests/device/test_http_client/test_http_client.ino +++ b/tests/device/test_http_client/test_http_client.ino @@ -48,7 +48,7 @@ TEST_CASE("HTTP GET & POST requests", "[HTTPClient]") String payload = http.getString(); auto len = payload.length(); REQUIRE(len == 8000); - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { if (payload[i] != 'a') { REQUIRE(false); } @@ -201,7 +201,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") String payload = http.getString(); auto len = payload.length(); REQUIRE(len == 4000); - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { if (payload[i] != 'a') { REQUIRE(false); } @@ -212,7 +212,10 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") // { // small request +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" axTLS::WiFiClientSecure client; +#pragma GCC diagnostic pop HTTPClient http; http.begin(client, getenv("SERVER_IP"), 8088, "/", fp); auto httpCode = http.GET(); @@ -222,7 +225,10 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") } { // request which returns 4000 bytes +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" axTLS::WiFiClientSecure client; +#pragma GCC diagnostic pop HTTPClient http; http.begin(client, getenv("SERVER_IP"), 8088, "/data?size=4000", fp); auto httpCode = http.GET(); @@ -230,7 +236,7 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") String payload = http.getString(); auto len = payload.length(); REQUIRE(len == 4000); - for (int i = 0; i < len; ++i) { + for (size_t i = 0; i < len; ++i) { if (payload[i] != 'a') { REQUIRE(false); } diff --git a/tests/device/test_millis_mm/test_millis_mm.ino b/tests/device/test_millis_mm/test_millis_mm.ino index 7a8e8a17bc..c5e25bdcdc 100644 --- a/tests/device/test_millis_mm/test_millis_mm.ino +++ b/tests/device/test_millis_mm/test_millis_mm.ino @@ -40,6 +40,8 @@ static uint32_t cntref = 0; // Ref. comparision count // Callback for usec counter overflow timer interrupt void us_overflow_tick ( void* arg ) { + (void) arg; + us_cnt = system_get_time(); // Check for usec counter overflow diff --git a/tests/device/test_random/test_random.ino b/tests/device/test_random/test_random.ino index 1e8efea266..39563b221c 100644 --- a/tests/device/test_random/test_random.ino +++ b/tests/device/test_random/test_random.ino @@ -18,11 +18,11 @@ TEST_CASE("If randomSeed is not called, random() uses hardware PRNG", "[random]" { int32_t data[32]; srand(10); - for (int i = 0; i < sizeof(data)/sizeof(data[0]); ++i) { + for (size_t i = 0; i < sizeof(data)/sizeof(data[0]); ++i) { data[i] = random(0x7fffffff); } srand(10); - for (int i = 0; i < sizeof(data)/sizeof(data[0]); ++i) { + for (size_t i = 0; i < sizeof(data)/sizeof(data[0]); ++i) { CHECK(random(0x7fffffff) != data[i]); } } @@ -49,7 +49,7 @@ TEST_CASE("If randomSeed is called, we get same random sequence every time", "[r 730240988, 786466794, 1411137128, 1680096093, }; randomSeed(42); - for (int i = 0; i < sizeof(reference_sequence)/sizeof(reference_sequence[0]); ++i) { + for (size_t i = 0; i < sizeof(reference_sequence)/sizeof(reference_sequence[0]); ++i) { CHECK(random(0x7fffffff) == reference_sequence[i]); } } diff --git a/tests/device/test_time/test_time.ino b/tests/device/test_time/test_time.ino index 006ba3fa41..a79c0c247f 100644 --- a/tests/device/test_time/test_time.ino +++ b/tests/device/test_time/test_time.ino @@ -24,9 +24,6 @@ bool pretest() TEST_CASE("Can sync time", "[time]") { - int timezone = 3; - int dst = 0; - configTime(3 * 3600, 0, "pool.ntp.org", "time.nist.gov"); Serial.println("\nWaiting for time"); unsigned timeout = 5000; @@ -53,7 +50,7 @@ TEST_CASE("#1745 mktime and localtime", "[time]") const int years[] = {2012, 2013, 2014}; const time_t timestamps[] = {1332640800, 1364176800, 1395712800}; - for (int i = 0; i < sizeof(years)/sizeof(years[0]); ++i) { + for (size_t i = 0; i < sizeof(years)/sizeof(years[0]); ++i) { tm_in.tm_year = years[i] - 1900; tm_in.tm_mon = 2; tm_in.tm_mday = 25; From fa5eb53b23c6d9a296da0391c7d32a4e544eb251 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 25 Jun 2019 15:41:28 -0700 Subject: [PATCH 6/6] Fix UMM_MALLOC printf crash, umm_test Printf can now handle PROGMEM addresses, so simplify and correct the debug printouts in umm_info and elsewhere. --- cores/esp8266/umm_malloc/umm_malloc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/umm_malloc/umm_malloc.cpp b/cores/esp8266/umm_malloc/umm_malloc.cpp index 8314c5ec60..09cfbdda71 100644 --- a/cores/esp8266/umm_malloc/umm_malloc.cpp +++ b/cores/esp8266/umm_malloc/umm_malloc.cpp @@ -520,7 +520,7 @@ extern int umm_last_fail_alloc_size; #endif // Macro to place constant strings into PROGMEM and print them properly -#define printf(fmt, ...) do { static const char fstr[] PROGMEM = fmt; char rstr[sizeof(fmt)]; for (size_t i=0; i