Skip to content

Commit

Permalink
Merge pull request #2515 from ciband:feat/support_esp8266
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 276333426
  • Loading branch information
vslashg committed Oct 25, 2019
2 parents 37f3227 + 778733f commit 540835f
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 9 deletions.
9 changes: 8 additions & 1 deletion googlemock/src/gmock_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"

#ifdef ARDUINO
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32
#if GTEST_OS_ESP8266
extern "C" {
#endif
void setup() {
// Since Google Mock depends on Google Test, InitGoogleMock() is
// also responsible for initializing Google Test. Therefore there's
// no need for calling testing::InitGoogleTest() separately.
testing::InitGoogleMock();
}
void loop() { RUN_ALL_TESTS(); }
#if GTEST_OS_ESP8266
}
#endif

#else

// MS C++ compiler/linker has a bug on Windows (not on Windows CE), which
Expand Down
4 changes: 4 additions & 0 deletions googletest/include/gtest/internal/gtest-port-arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
# define GTEST_OS_QNX 1
#elif defined(__HAIKU__)
#define GTEST_OS_HAIKU 1
#elif defined ESP8266
#define GTEST_OS_ESP8266 1
#elif defined ESP32
#define GTEST_OS_ESP32 1
#endif // __CYGWIN__

#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_
26 changes: 22 additions & 4 deletions googletest/include/gtest/internal/gtest-port.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// no support for it at least as recent as Froyo (2.2).
#define GTEST_HAS_STD_WSTRING \
(!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
GTEST_OS_HAIKU))
GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266))

#endif // GTEST_HAS_STD_WSTRING

Expand Down Expand Up @@ -570,7 +570,8 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
#ifndef GTEST_HAS_STREAM_REDIRECTION
// By default, we assume that stream redirection is supported on all
// platforms except known mobile ones.
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266
# define GTEST_HAS_STREAM_REDIRECTION 0
# else
# define GTEST_HAS_STREAM_REDIRECTION 1
Expand Down Expand Up @@ -1975,6 +1976,22 @@ inline bool IsDir(const StatStruct& st) {
}
# endif // GTEST_OS_WINDOWS_MOBILE

#elif GTEST_OS_ESP8266
typedef struct stat StatStruct;

inline int FileNo(FILE* file) { return fileno(file); }
inline int IsATTY(int fd) { return isatty(fd); }
inline int Stat(const char* path, StatStruct* buf) {
// stat function not implemented on ESP8266
return 0;
}
inline int StrCaseCmp(const char* s1, const char* s2) {
return strcasecmp(s1, s2);
}
inline char* StrDup(const char* src) { return strdup(src); }
inline int RmDir(const char* dir) { return rmdir(dir); }
inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }

#else

typedef struct stat StatStruct;
Expand Down Expand Up @@ -2023,8 +2040,9 @@ inline int Close(int fd) { return close(fd); }
inline const char* StrError(int errnum) { return strerror(errnum); }
#endif
inline const char* GetEnv(const char* name) {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
// We are on Windows CE, which has no environment variables.
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266
// We are on an embedded platform, which has no environment variables.
static_cast<void>(name); // To prevent 'unused argument' warning.
return nullptr;
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)
Expand Down
5 changes: 4 additions & 1 deletion googletest/src/gtest-filepath.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static bool IsPathSeparator(char c) {
// Returns the current working directory, or "" if unsuccessful.
FilePath FilePath::GetCurrentDir() {
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
GTEST_OS_WINDOWS_RT || ARDUINO || defined(ESP_PLATFORM)
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32
// These platforms do not have a current directory, so we just return
// something reasonable.
return FilePath(kCurrentDirectoryString);
Expand Down Expand Up @@ -323,6 +323,9 @@ bool FilePath::CreateFolder() const {
delete [] unicode;
#elif GTEST_OS_WINDOWS
int result = _mkdir(pathname_.c_str());
#elif GTEST_OS_ESP8266
// do nothing
int result = 0;
#else
int result = mkdir(pathname_.c_str(), 0777);
#endif // GTEST_OS_WINDOWS_MOBILE
Expand Down
2 changes: 2 additions & 0 deletions googletest/src/gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4506,6 +4506,7 @@ class ScopedPrematureExitFile {
}

~ScopedPrematureExitFile() {
#if !defined GTEST_OS_ESP8266
if (!premature_exit_filepath_.empty()) {
int retval = remove(premature_exit_filepath_.c_str());
if (retval) {
Expand All @@ -4514,6 +4515,7 @@ class ScopedPrematureExitFile {
<< retval;
}
}
#endif
}

private:
Expand Down
9 changes: 8 additions & 1 deletion googletest/src/gtest_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@
#include <cstdio>
#include "gtest/gtest.h"

#ifdef ARDUINO
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32
#if GTEST_OS_ESP8266
extern "C" {
#endif
void setup() {
testing::InitGoogleTest();
}

void loop() { RUN_ALL_TESTS(); }

#if GTEST_OS_ESP8266
}
#endif

#else

GTEST_API_ int main(int argc, char **argv) {
Expand Down
21 changes: 20 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"version": "1.10.0",
"frameworks": "arduino",
"platforms": [
"espressif32"
"espressif32",
"espressif8266"
],
"export": {
"include": [
Expand Down Expand Up @@ -42,6 +43,24 @@
"-Igooglemock",
"-Igoogletest/include",
"-Igoogletest"
],
"srcFilter": [
"+<*>",
"-<.git/>",
"-<googlemock>",
"-<googlemock/test/>",
"-<googlemock/src>",
"+<googlemock/src/gmock-all.cc>",
"+<googletest/src/gtest-all.cc>",
"+<googlemock/src/gmock_main.cc>",
"-<googletest>",
"-<googletest/codegear/>",
"-<googletest/samples>",
"-<googletest/test/>",
"-<googletest/xcode>",
"-<googletest/src>",
"+<googletest/src/gtest-all.cc>",
"+<googletest/src/gtest_main.cc>"
]
}
}
18 changes: 17 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,21 @@ platform = espressif32
board = esp32dev
framework = arduino
build_flags = -I./googlemock/include -I./googletest/include -I./googletest -I./googlemock
src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googlemock/src/gmock_main.cc> +<googletest/src/gtest-all.cc>
src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googletest/src/gtest-all.cc> +<googlemock/src/gmock_main.cc>
upload_speed = 921600

[env:googletest_esp8266]
platform = espressif8266
board = huzzah
framework = arduino
build_flags = -I./googletest/include -I./googletest
src_filter = +<*> -<.git/> -<googlemock> -<googletest/codegear/> -<googletest/samples> -<googletest/test/> -<googletest/xcode> -<googletest/src> +<googletest/src/gtest-all.cc> +<googletest/src/gtest_main.cc>
upload_speed = 921600

[env:googlemock_esp8266]
platform = espressif8266
board = huzzah
framework = arduino
build_flags = -I./googlemock/include -I./googletest/include -I./googletest -I./googlemock
src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googletest/src/gtest-all.cc> +<googlemock/src/gmock_main.cc>
upload_speed = 921600

0 comments on commit 540835f

Please sign in to comment.