From 40a6b9662199890b20ccbac3b964ce04713d8ede Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Wed, 28 Aug 2019 09:39:35 -0500 Subject: [PATCH 1/3] feat: Add support for ESP8266 platform Added support for ESP8266 Arduino platform. Refactored Arduino defines to use the GTEST_OS_* model. --- googlemock/src/gmock_main.cc | 2 +- googletest/include/gtest/internal/gtest-port-arch.h | 4 ++++ googletest/src/gtest-filepath.cc | 2 +- googletest/src/gtest.cc | 2 ++ googletest/src/gtest_main.cc | 2 +- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc index 98611b93..4d4f48b7 100644 --- a/googlemock/src/gmock_main.cc +++ b/googlemock/src/gmock_main.cc @@ -32,7 +32,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#ifdef ARDUINO +#if defined GTEST_OS_ESP8266 || defined GTEST_OS_ESP32 void setup() { // Since Google Mock depends on Google Test, InitGoogleMock() is // also responsible for initializing Google Test. Therefore there's diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index cece93db..e2acad35 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -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_ diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index bd7b99ff..eb1024e4 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -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); diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index a5b4e5ac..a11ce184 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -4508,6 +4508,7 @@ class ScopedPrematureExitFile { } ~ScopedPrematureExitFile() { + #if !defined GTEST_OS_ESP8266 if (!premature_exit_filepath_.empty()) { int retval = remove(premature_exit_filepath_.c_str()); if (retval) { @@ -4516,6 +4517,7 @@ class ScopedPrematureExitFile { << retval; } } + #endif } private: diff --git a/googletest/src/gtest_main.cc b/googletest/src/gtest_main.cc index f6e1dd96..361cb739 100644 --- a/googletest/src/gtest_main.cc +++ b/googletest/src/gtest_main.cc @@ -30,7 +30,7 @@ #include #include "gtest/gtest.h" -#ifdef ARDUINO +#if defined GTEST_OS_ESP8266 || defined GTEST_OS_ESP32 void setup() { testing::InitGoogleTest(); } From c2206b05aa0f2fbdf5b353b32cd565b0e89d3fa6 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Thu, 29 Aug 2019 12:34:26 -0500 Subject: [PATCH 2/3] Add ESP8266 configs to PlatformIO build Added various conditional compliations for ESP8266 to stub out missing functionality. --- googlemock/src/gmock_main.cc | 9 ++++++++- googletest/include/gtest/internal/gtest-port.h | 16 ++++++++++++++++ googletest/src/gtest-filepath.cc | 5 ++++- googletest/src/gtest_main.cc | 9 ++++++++- platformio.ini | 18 +++++++++++++++++- 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc index 4d4f48b7..16f97b0a 100644 --- a/googlemock/src/gmock_main.cc +++ b/googlemock/src/gmock_main.cc @@ -32,7 +32,10 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" -#if defined GTEST_OS_ESP8266 || defined GTEST_OS_ESP32 +#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 @@ -40,6 +43,10 @@ void setup() { 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 diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index f6433c58..f24afe7e 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1984,6 +1984,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; diff --git a/googletest/src/gtest-filepath.cc b/googletest/src/gtest-filepath.cc index eb1024e4..7e03e817 100644 --- a/googletest/src/gtest-filepath.cc +++ b/googletest/src/gtest-filepath.cc @@ -236,7 +236,7 @@ bool FilePath::DirectoryExists() const { result = true; } #else - posix::StatStruct file_stat; + posix::StatStruct file_stat = {}; result = posix::Stat(path.c_str(), &file_stat) == 0 && posix::IsDir(file_stat); #endif // GTEST_OS_WINDOWS_MOBILE @@ -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 diff --git a/googletest/src/gtest_main.cc b/googletest/src/gtest_main.cc index 361cb739..37479252 100644 --- a/googletest/src/gtest_main.cc +++ b/googletest/src/gtest_main.cc @@ -30,13 +30,20 @@ #include #include "gtest/gtest.h" -#if defined GTEST_OS_ESP8266 || defined GTEST_OS_ESP32 +#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) { diff --git a/platformio.ini b/platformio.ini index 3910026b..31c7ec16 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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/> - - - + + + +src_filter = +<*> -<.git/> - - - + + + upload_speed = 921600 + +[env:googletest_esp8266] +platform = espressif8266 +board = huzzah +framework = arduino +build_flags = -I./googletest/include -I./googletest +src_filter = +<*> -<.git/> - - - - - - + + +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/> - - - + + + +upload_speed = 921600 \ No newline at end of file From 84a5ae8b85605fd51cf3d0107315670d3cf00fa4 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Mon, 7 Oct 2019 09:23:59 -0500 Subject: [PATCH 3/3] Update to distinguish prelease purpose of this fork. --- .../include/gtest/internal/gtest-port.h | 10 +++--- library.json | 32 +++++++++++++++---- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index f24afe7e..761b493f 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -449,7 +449,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_ESP8266)) #endif // GTEST_HAS_STD_WSTRING @@ -573,7 +573,7 @@ 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 @@ -1989,9 +1989,9 @@ 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) { +inline int Stat(const char* path, StatStruct* buf) { // stat function not implemented on ESP8266 - return 0; + return 0; } inline int StrCaseCmp(const char* s1, const char* s2) { return strcasecmp(s1, s2); @@ -2052,7 +2052,7 @@ 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 +#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 // We are on Windows CE, which has no environment variables. static_cast(name); // To prevent 'unused argument' warning. return nullptr; diff --git a/library.json b/library.json index e46fcbda..e8f0d6cf 100644 --- a/library.json +++ b/library.json @@ -1,17 +1,18 @@ { - "name": "googletest", + "name": "googletest-ciband-prelease", "keywords": "unittest, unit, test, gtest, gmock", - "description": "googletest is a testing framework developed by the Testing Technology team with Google's specific requirements and constraints in mind. No matter whether you work on Linux, Windows, or a Mac, if you write C++ code, googletest can help you. And it supports any kind of tests, not just unit tests.", + "description": "***This is a prelease repo to use new features before they are added to googletest.*** googletest is a testing framework developed by the Testing Technology team with Google's specific requirements and constraints in mind. No matter whether you work on Linux, Windows, or a Mac, if you write C++ code, googletest can help you. And it supports any kind of tests, not just unit tests.", "license": "BSD-3-Clause", "homepage": "https://github.com/google/googletest/blob/master/README.md", "repository": { "type": "git", - "url": "https://github.com/google/googletest.git" + "url": "https://github.com/ciband/googletest.git" }, "version": "1.8.1", "frameworks": "arduino", "platforms": [ - "espressif32" + "espressif32", + "espressif8266" ], "export": { "include": [ @@ -29,7 +30,7 @@ "googlemock/scripts", "googlemock/src/gmock-all.cc", "googlemock/src/gmock_main.cc", - "googlemock/test", + "googlemock/test/*", "googlemock/CMakeLists.txt", "googlemock/Makefile.am", "googlemock/configure.ac", @@ -38,10 +39,11 @@ "googletest/m4", "googletest/make", "googletest/msvc", + "googletest/samples", "googletest/scripts", "googletest/src/gtest-all.cc", "googletest/src/gtest_main.cc", - "googletest/test", + "googletest/test/*", "googletest/xcode", "googletest/CMakeLists.txt", "googletest/Makefile.am", @@ -54,6 +56,24 @@ "-Igooglemock", "-Igoogletest/include", "-Igoogletest" + ], + "srcFilter": [ + "+<*>", + "-<.git/>", + "-", + "-", + "-", + "+", + "+", + "+", + "-", + "-", + "-", + "-", + "-", + "-", + "+", + "+" ] } }