From 0cda4b376a88f098c63f28aa59802ce764822d6b Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 18 Jan 2022 11:18:54 +0100 Subject: [PATCH 1/4] emulation on host: minor fixes merge MockDigital.cpp and HostWiring.cpp --- .../src/ESP8266HTTPUpdateServer-impl.h | 2 +- tests/host/Makefile | 1 - tests/host/common/HostWiring.cpp | 20 ++++++- tests/host/common/MockDigital.cpp | 56 ------------------- tests/host/common/MockEsp.cpp | 5 ++ tests/host/common/MockTools.cpp | 9 +++ 6 files changed, 33 insertions(+), 60 deletions(-) delete mode 100644 tests/host/common/MockDigital.cpp diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h index 39608934cd..844f74bbc9 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h @@ -111,7 +111,7 @@ void ESP8266HTTPUpdateServerTemplate::setup(ESP8266WebServerTemplate } } else if(_authenticated && upload.status == UPLOAD_FILE_END && !_updaterError.length()){ if(Update.end(true)){ //true to set the size to the current progress - if (_serial_output) Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize); + if (_serial_output) Serial.printf("Update Success: %zu\nRebooting...\n", upload.totalSize); } else { _setUpdaterError(); } diff --git a/tests/host/Makefile b/tests/host/Makefile index b7c8d1ce20..7a8ff9de2c 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -136,7 +136,6 @@ MOCK_CPP_FILES_COMMON := \ MockUART.cpp \ MockTools.cpp \ MocklwIP.cpp \ - MockDigital.cpp \ ) MOCK_CPP_FILES := $(MOCK_CPP_FILES_COMMON) \ diff --git a/tests/host/common/HostWiring.cpp b/tests/host/common/HostWiring.cpp index 765d4297b6..1b93d72ece 100644 --- a/tests/host/common/HostWiring.cpp +++ b/tests/host/common/HostWiring.cpp @@ -37,6 +37,11 @@ #define VERBOSE(x...) mockverbose(x) #endif +#define GPIONUM 17 + +static uint8_t _mode[GPIONUM]; +static uint8_t _gpio[GPIONUM]; + void pinMode (uint8_t pin, uint8_t mode) { #define xxx(mode) case mode: m=STRHELPER(mode); break @@ -53,11 +58,19 @@ void pinMode (uint8_t pin, uint8_t mode) default: m="(special)"; } VERBOSE("gpio%d: mode='%s'\n", pin, m); + + if (pin < GPIONUM) + { + _mode[pin] = mode; + } } void digitalWrite(uint8_t pin, uint8_t val) { VERBOSE("digitalWrite(pin=%d val=%d)\n", pin, val); + if (pin < GPIONUM) { + _gpio[pin] = val; + } } void analogWrite(uint8_t pin, int val) @@ -80,6 +93,9 @@ int digitalRead(uint8_t pin) { VERBOSE("digitalRead(%d)\n", pin); - // pin 0 is most likely a low active input - return pin ? 0 : 1; + if (pin < GPIONUM) { + return _gpio[pin] != 0; + } else { + return 0; + } } diff --git a/tests/host/common/MockDigital.cpp b/tests/host/common/MockDigital.cpp deleted file mode 100644 index aa04527ab5..0000000000 --- a/tests/host/common/MockDigital.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - digital.c - wiring digital implementation for esp8266 - - Copyright (c) 2015 Hristo Gochkov. All rights reserved. - This file is part of the esp8266 core for Arduino environment. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ -#define ARDUINO_MAIN -#include "wiring_private.h" -#include "pins_arduino.h" -#include "c_types.h" -#include "eagle_soc.h" -#include "ets_sys.h" -#include "user_interface.h" -#include "core_esp8266_waveform.h" -#include "interrupts.h" - -extern "C" { - -static uint8_t _mode[17]; -static uint8_t _gpio[17]; - -extern void pinMode(uint8_t pin, uint8_t mode) { - if (pin < 17) { - _mode[pin] = mode; - } -} - -extern void digitalWrite(uint8_t pin, uint8_t val) { - if (pin < 17) { - _gpio[pin] = val; - } -} - -extern int digitalRead(uint8_t pin) { - if (pin < 17) { - return _gpio[pin] != 0; - } else { - return 0; - } -} - -}; diff --git a/tests/host/common/MockEsp.cpp b/tests/host/common/MockEsp.cpp index f06d829f3e..5e00072f19 100644 --- a/tests/host/common/MockEsp.cpp +++ b/tests/host/common/MockEsp.cpp @@ -263,3 +263,8 @@ void EspClass::setExternalHeap() void EspClass::resetHeap() { } + +void EspClass::reset () +{ + abort(); +} diff --git a/tests/host/common/MockTools.cpp b/tests/host/common/MockTools.cpp index 5eb7969de7..eb2c41ed12 100644 --- a/tests/host/common/MockTools.cpp +++ b/tests/host/common/MockTools.cpp @@ -78,3 +78,12 @@ void configTime(int timezone, int daylightOffset_sec, mockverbose("configTime: TODO (tz=%dH offset=%dS) (time will be host's)\n", timezone, daylightOffset_sec); } + +void configTime(const char* tz, const char* server1, const char* server2, const char* server3) +{ + (void)server1; + (void)server2; + (void)server3; + + mockverbose("configTime: TODO (tz='%s') (time will be host's)\n", tz); +} From 6cabc329e4fc2e4c36599da2cafd413947baa890 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 18 Jan 2022 14:55:41 +0100 Subject: [PATCH 2/4] emulation: share mockverbose between CI-on-host and emulation --- tests/host/Makefile | 2 +- tests/host/common/Arduino.cpp | 7 +++++++ tests/host/common/ArduinoMain.cpp | 10 ---------- tests/host/common/mock.h | 1 + 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tests/host/Makefile b/tests/host/Makefile index 7a8ff9de2c..13c9feed52 100644 --- a/tests/host/Makefile +++ b/tests/host/Makefile @@ -136,6 +136,7 @@ MOCK_CPP_FILES_COMMON := \ MockUART.cpp \ MockTools.cpp \ MocklwIP.cpp \ + HostWiring.cpp \ ) MOCK_CPP_FILES := $(MOCK_CPP_FILES_COMMON) \ @@ -355,7 +356,6 @@ MOCK_ARDUINO_LIBS := \ MockWiFiServerSocket.cpp \ MockWiFiServer.cpp \ UdpContextSocket.cpp \ - HostWiring.cpp \ MockEsp.cpp \ MockEEPROM.cpp \ MockSPI.cpp \ diff --git a/tests/host/common/Arduino.cpp b/tests/host/common/Arduino.cpp index 1c651e7e1f..7445506fd9 100644 --- a/tests/host/common/Arduino.cpp +++ b/tests/host/common/Arduino.cpp @@ -22,6 +22,7 @@ #include static struct timeval gtod0 = { 0, 0 }; +bool mockdebug = false; extern "C" unsigned long millis() { @@ -111,3 +112,9 @@ cont_t* g_pcont = NULL; extern "C" void cont_suspend(cont_t*) { } + +int mockverbose (const char* fmt, ...) { va_list ap; va_start(ap, fmt); if + (mockdebug) + return fprintf(stderr, MOCK) + vfprintf(stderr, fmt, ap); + return 0; +} diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index ddda929d46..9aa041c653 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -48,7 +48,6 @@ size_t spiffs_kb = 1024; size_t littlefs_kb = 1024; bool ignore_sigint = false; bool restore_tty = false; -bool mockdebug = false; int mock_port_shifter = MOCK_PORT_SHIFTER; const char* fspath = nullptr; @@ -56,15 +55,6 @@ const char* fspath = nullptr; static struct termios initial_settings; -int mockverbose (const char* fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - if (mockdebug) - return fprintf(stderr, MOCK) + vfprintf(stderr, fmt, ap); - return 0; -} - static int mock_start_uart(void) { struct termios settings; diff --git a/tests/host/common/mock.h b/tests/host/common/mock.h index 56919ee60a..857c7911d3 100644 --- a/tests/host/common/mock.h +++ b/tests/host/common/mock.h @@ -112,6 +112,7 @@ extern bool serial_timestamp; extern int mock_port_shifter; extern bool blocking_uart; extern uint32_t global_source_address; // 0 = INADDR_ANY by default +extern bool mockdebug; #define NO_GLOBAL_BINDING 0xffffffff extern uint32_t global_ipv4_netfmt; // selected interface addresse to bind to From 22e7fe0bc5553772e35bc3f0dba90185f13cd837 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Tue, 18 Jan 2022 15:19:41 +0100 Subject: [PATCH 3/4] mock: add missing recently overridden method --- tests/host/common/MockEsp.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/host/common/MockEsp.cpp b/tests/host/common/MockEsp.cpp index b43c180aa9..293f6c5047 100644 --- a/tests/host/common/MockEsp.cpp +++ b/tests/host/common/MockEsp.cpp @@ -142,6 +142,15 @@ void EspClass::getHeapStats(uint32_t* hfree, uint16_t* hmax, uint8_t* hfrag) { if (hfrag) *hfrag = 100 - (sqrt(hm) * 100) / hf; } +void EspClass::getHeapStats(uint32_t* hfree, uint32_t* hmax, uint8_t* hfrag) { + uint32_t hf = 10 * 1024; + float hm = 1 * 1024; + + if (hfree) *hfree = hf; + if (hmax) *hmax = hm; + if (hfrag) *hfrag = 100 - (sqrt(hm) * 100) / hf; +} + bool EspClass::flashEraseSector(uint32_t sector) { (void) sector; From e819e7d93c8cbc758a104be30312b8b0ee015b23 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Fri, 28 Jan 2022 23:54:35 +0100 Subject: [PATCH 4/4] remove extern variable, use weak function --- tests/host/common/Arduino.cpp | 11 ++++++----- tests/host/common/ArduinoMain.cpp | 10 ++++++++++ tests/host/common/mock.h | 1 - 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/host/common/Arduino.cpp b/tests/host/common/Arduino.cpp index 7445506fd9..ffeeae05cd 100644 --- a/tests/host/common/Arduino.cpp +++ b/tests/host/common/Arduino.cpp @@ -22,7 +22,6 @@ #include static struct timeval gtod0 = { 0, 0 }; -bool mockdebug = false; extern "C" unsigned long millis() { @@ -113,8 +112,10 @@ extern "C" void cont_suspend(cont_t*) { } -int mockverbose (const char* fmt, ...) { va_list ap; va_start(ap, fmt); if - (mockdebug) - return fprintf(stderr, MOCK) + vfprintf(stderr, fmt, ap); - return 0; +extern "C" int __mockverbose (const char* fmt, ...) +{ + (void)fmt; + return 0; } + +int mockverbose (const char* fmt, ...) __attribute__ ((weak, alias("__mockverbose"), format (printf, 1, 2))); diff --git a/tests/host/common/ArduinoMain.cpp b/tests/host/common/ArduinoMain.cpp index 9aa041c653..ddda929d46 100644 --- a/tests/host/common/ArduinoMain.cpp +++ b/tests/host/common/ArduinoMain.cpp @@ -48,6 +48,7 @@ size_t spiffs_kb = 1024; size_t littlefs_kb = 1024; bool ignore_sigint = false; bool restore_tty = false; +bool mockdebug = false; int mock_port_shifter = MOCK_PORT_SHIFTER; const char* fspath = nullptr; @@ -55,6 +56,15 @@ const char* fspath = nullptr; static struct termios initial_settings; +int mockverbose (const char* fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + if (mockdebug) + return fprintf(stderr, MOCK) + vfprintf(stderr, fmt, ap); + return 0; +} + static int mock_start_uart(void) { struct termios settings; diff --git a/tests/host/common/mock.h b/tests/host/common/mock.h index 857c7911d3..56919ee60a 100644 --- a/tests/host/common/mock.h +++ b/tests/host/common/mock.h @@ -112,7 +112,6 @@ extern bool serial_timestamp; extern int mock_port_shifter; extern bool blocking_uart; extern uint32_t global_source_address; // 0 = INADDR_ANY by default -extern bool mockdebug; #define NO_GLOBAL_BINDING 0xffffffff extern uint32_t global_ipv4_netfmt; // selected interface addresse to bind to pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy