From 53bd8a890a3505d4a92c3025156742271c94d068 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 13 Dec 2021 22:22:34 +0100 Subject: [PATCH 1/3] mock: +Hash, +scheduled functions --- tests/host/Makefile | 1 + tests/host/common/ArduinoMain.cpp | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/tests/host/Makefile b/tests/host/Makefile index a2353a0841..3a5979c312 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -345,6 +345,7 @@ OPT_ARDUINO_LIBS ?= \ DNSServer/src/DNSServer.cpp \ ESP8266AVRISP/src/ESP8266AVRISP.cpp \ ESP8266HTTPClient/src/ESP8266HTTPClient.cpp \ + Hash/src/Hash.cpp \ ) MOCK_ARDUINO_LIBS := \ diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index 051ca0dbc1..711587d767 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -39,6 +39,8 @@ #include #include +#include + #define MOCK_PORT_SHIFTER 9000 bool user_exit = false; @@ -309,6 +311,8 @@ int main (int argc, char* const argv []) usleep(1000); // not 100% cpu, ~1000 loops per second loop(); check_incoming_udp(); + run_scheduled_functions(); + run_scheduled_recurrent_functions(); if (run_once) user_exit = true; From 7c1d156481513fe70a31342bb127e53d759278fb Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 15 Dec 2021 11:24:01 +0100 Subject: [PATCH 2/3] emulation on host: call scheduled functions from yield() --- tests/host/common/Arduino.cpp | 8 ++++++-- tests/host/common/ArduinoMain.cpp | 5 +---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/host/common/Arduino.cpp b/tests/host/common/Arduino.cpp index c2c1fa10a2..02a8794edd 100644 --- a/tests/host/common/Arduino.cpp +++ b/tests/host/common/Arduino.cpp @@ -14,10 +14,12 @@ */ #include -#include "Arduino.h" +#include + #include -#include +#include +#include static struct timeval gtod0 = { 0, 0 }; @@ -42,6 +44,8 @@ extern "C" unsigned long micros() extern "C" void yield() { + run_scheduled_functions(); + run_scheduled_recurrent_functions(); } extern "C" bool can_yield() diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index 711587d767..f0e90f2def 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -39,8 +39,6 @@ #include #include -#include - #define MOCK_PORT_SHIFTER 9000 bool user_exit = false; @@ -311,8 +309,7 @@ int main (int argc, char* const argv []) usleep(1000); // not 100% cpu, ~1000 loops per second loop(); check_incoming_udp(); - run_scheduled_functions(); - run_scheduled_recurrent_functions(); + yield(); // call scheduled functions if (run_once) user_exit = true; From 3cec07e7ddc193706f08c9e3509316b84153bd1e Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 15 Dec 2021 17:32:50 +0100 Subject: [PATCH 3/3] emulation: correctly emulate scheduled functions (per review) --- tests/host/common/Arduino.cpp | 5 +++++ tests/host/common/ArduinoMain.cpp | 2 +- tests/host/common/mock.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/host/common/Arduino.cpp b/tests/host/common/Arduino.cpp index 02a8794edd..1c651e7e1f 100644 --- a/tests/host/common/Arduino.cpp +++ b/tests/host/common/Arduino.cpp @@ -43,6 +43,11 @@ extern "C" unsigned long micros() extern "C" void yield() +{ + run_scheduled_recurrent_functions(); +} + +extern "C" void loop_end() { run_scheduled_functions(); run_scheduled_recurrent_functions(); diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index f0e90f2def..ddda929d46 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -308,8 +308,8 @@ int main (int argc, char* const argv []) if (!fast) usleep(1000); // not 100% cpu, ~1000 loops per second loop(); + loop_end(); check_incoming_udp(); - yield(); // call scheduled functions if (run_once) user_exit = true; diff --git a/tests/host/common/mock.h b/tests/host/common/mock.h index 0194271d9a..56919ee60a 100644 --- a/tests/host/common/mock.h +++ b/tests/host/common/mock.h @@ -116,6 +116,8 @@ extern uint32_t global_source_address; // 0 = INADDR_ANY by default #define NO_GLOBAL_BINDING 0xffffffff extern uint32_t global_ipv4_netfmt; // selected interface addresse to bind to +void loop_end(); + #ifdef __cplusplus } #endif