Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emulation on host: minor updates #8454

Merged
merged 7 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}