Skip to content

Commit

Permalink
emulation on host: minor updates (#8454)
Browse files Browse the repository at this point in the history
* emulation on host: minor fixes
merge MockDigital.cpp and HostWiring.cpp

* emulation: share mockverbose between CI-on-host and emulation

* mock: add missing recently overridden method

* remove extern variable, use weak function
  • Loading branch information
d-a-v authored Feb 20, 2022
1 parent 7356cd1 commit 15e7d35
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::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();
}
Expand Down
3 changes: 1 addition & 2 deletions tests/host/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ MOCK_CPP_FILES_COMMON := \
MockUART.cpp \
MockTools.cpp \
MocklwIP.cpp \
MockDigital.cpp \
HostWiring.cpp \
)

MOCK_CPP_FILES := $(MOCK_CPP_FILES_COMMON) \
Expand Down Expand Up @@ -356,7 +356,6 @@ MOCK_ARDUINO_LIBS := \
MockWiFiServerSocket.cpp \
MockWiFiServer.cpp \
UdpContextSocket.cpp \
HostWiring.cpp \
MockEsp.cpp \
MockEEPROM.cpp \
MockSPI.cpp \
Expand Down
8 changes: 8 additions & 0 deletions tests/host/common/Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ cont_t* g_pcont = NULL;
extern "C" void cont_suspend(cont_t*)
{
}

extern "C" int __mockverbose (const char* fmt, ...)
{
(void)fmt;
return 0;
}

int mockverbose (const char* fmt, ...) __attribute__ ((weak, alias("__mockverbose"), format (printf, 1, 2)));
20 changes: 18 additions & 2 deletions tests/host/common/HostWiring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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;
}
}
56 changes: 0 additions & 56 deletions tests/host/common/MockDigital.cpp

This file was deleted.

14 changes: 14 additions & 0 deletions tests/host/common/MockEsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -263,3 +272,8 @@ void EspClass::setExternalHeap()
void EspClass::resetHeap()
{
}

void EspClass::reset ()
{
abort();
}
9 changes: 9 additions & 0 deletions tests/host/common/MockTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 15e7d35

Please sign in to comment.