Skip to content

Commit 778733f

Browse files
committed
feat: Add ESP8266 support
* Added support for ESP8266 * Removed previous Arduino defines in favor of GTEST_OS_* syntax * Improved PlatformIO library file to be more stable when consumed in client applications.
2 parents ba513d2 + 84a5ae8 commit 778733f

File tree

8 files changed

+84
-9
lines changed

8 files changed

+84
-9
lines changed

googlemock/src/gmock_main.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,21 @@
3232
#include "gmock/gmock.h"
3333
#include "gtest/gtest.h"
3434

35-
#ifdef ARDUINO
35+
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32
36+
# if GTEST_OS_ESP8266
37+
extern "C" {
38+
# endif
3639
void setup() {
3740
// Since Google Mock depends on Google Test, InitGoogleMock() is
3841
// also responsible for initializing Google Test. Therefore there's
3942
// no need for calling testing::InitGoogleTest() separately.
4043
testing::InitGoogleMock();
4144
}
4245
void loop() { RUN_ALL_TESTS(); }
46+
# if GTEST_OS_ESP8266
47+
}
48+
# endif
49+
4350
#else
4451

4552
// MS C++ compiler/linker has a bug on Windows (not on Windows CE), which

googletest/include/gtest/internal/gtest-port-arch.h

+4
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@
102102
# define GTEST_OS_QNX 1
103103
#elif defined(__HAIKU__)
104104
#define GTEST_OS_HAIKU 1
105+
#elif defined ESP8266
106+
# define GTEST_OS_ESP8266 1
107+
#elif defined ESP32
108+
# define GTEST_OS_ESP32 1
105109
#endif // __CYGWIN__
106110

107111
#endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_

googletest/include/gtest/internal/gtest-port.h

+19-3
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
449449
// no support for it at least as recent as Froyo (2.2).
450450
#define GTEST_HAS_STD_WSTRING \
451451
(!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
452-
GTEST_OS_HAIKU))
452+
GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266))
453453

454454
#endif // GTEST_HAS_STD_WSTRING
455455

@@ -573,7 +573,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
573573
#ifndef GTEST_HAS_STREAM_REDIRECTION
574574
// By default, we assume that stream redirection is supported on all
575575
// platforms except known mobile ones.
576-
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
576+
# if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266
577577
# define GTEST_HAS_STREAM_REDIRECTION 0
578578
# else
579579
# define GTEST_HAS_STREAM_REDIRECTION 1
@@ -1984,6 +1984,22 @@ inline bool IsDir(const StatStruct& st) {
19841984
}
19851985
# endif // GTEST_OS_WINDOWS_MOBILE
19861986

1987+
#elif GTEST_OS_ESP8266
1988+
typedef struct stat StatStruct;
1989+
1990+
inline int FileNo(FILE* file) { return fileno(file); }
1991+
inline int IsATTY(int fd) { return isatty(fd); }
1992+
inline int Stat(const char* path, StatStruct* buf) {
1993+
// stat function not implemented on ESP8266
1994+
return 0;
1995+
}
1996+
inline int StrCaseCmp(const char* s1, const char* s2) {
1997+
return strcasecmp(s1, s2);
1998+
}
1999+
inline char* StrDup(const char* src) { return strdup(src); }
2000+
inline int RmDir(const char* dir) { return rmdir(dir); }
2001+
inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
2002+
19872003
#else
19882004

19892005
typedef struct stat StatStruct;
@@ -2036,7 +2052,7 @@ inline int Close(int fd) { return close(fd); }
20362052
inline const char* StrError(int errnum) { return strerror(errnum); }
20372053
#endif
20382054
inline const char* GetEnv(const char* name) {
2039-
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
2055+
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266
20402056
// We are on Windows CE, which has no environment variables.
20412057
static_cast<void>(name); // To prevent 'unused argument' warning.
20422058
return nullptr;

googletest/src/gtest-filepath.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static bool IsPathSeparator(char c) {
9393
// Returns the current working directory, or "" if unsuccessful.
9494
FilePath FilePath::GetCurrentDir() {
9595
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
96-
GTEST_OS_WINDOWS_RT || ARDUINO || defined(ESP_PLATFORM)
96+
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_ESP32
9797
// These platforms do not have a current directory, so we just return
9898
// something reasonable.
9999
return FilePath(kCurrentDirectoryString);
@@ -236,7 +236,7 @@ bool FilePath::DirectoryExists() const {
236236
result = true;
237237
}
238238
#else
239-
posix::StatStruct file_stat;
239+
posix::StatStruct file_stat = {};
240240
result = posix::Stat(path.c_str(), &file_stat) == 0 &&
241241
posix::IsDir(file_stat);
242242
#endif // GTEST_OS_WINDOWS_MOBILE
@@ -323,6 +323,9 @@ bool FilePath::CreateFolder() const {
323323
delete [] unicode;
324324
#elif GTEST_OS_WINDOWS
325325
int result = _mkdir(pathname_.c_str());
326+
#elif GTEST_OS_ESP8266
327+
// do nothing
328+
int result = 0;
326329
#else
327330
int result = mkdir(pathname_.c_str(), 0777);
328331
#endif // GTEST_OS_WINDOWS_MOBILE

googletest/src/gtest.cc

+2
Original file line numberDiff line numberDiff line change
@@ -4508,6 +4508,7 @@ class ScopedPrematureExitFile {
45084508
}
45094509

45104510
~ScopedPrematureExitFile() {
4511+
#if !defined GTEST_OS_ESP8266
45114512
if (!premature_exit_filepath_.empty()) {
45124513
int retval = remove(premature_exit_filepath_.c_str());
45134514
if (retval) {
@@ -4516,6 +4517,7 @@ class ScopedPrematureExitFile {
45164517
<< retval;
45174518
}
45184519
}
4520+
#endif
45194521
}
45204522

45214523
private:

googletest/src/gtest_main.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,20 @@
3030
#include <cstdio>
3131
#include "gtest/gtest.h"
3232

33-
#ifdef ARDUINO
33+
#if GTEST_OS_ESP8266 || GTEST_OS_ESP32
34+
# if GTEST_OS_ESP8266
35+
extern "C" {
36+
# endif
3437
void setup() {
3538
testing::InitGoogleTest();
3639
}
3740

3841
void loop() { RUN_ALL_TESTS(); }
3942

43+
# if GTEST_OS_ESP8266
44+
}
45+
# endif
46+
4047
#else
4148

4249
GTEST_API_ int main(int argc, char **argv) {

library.json

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"version": "1.8.1",
1212
"frameworks": "arduino",
1313
"platforms": [
14-
"espressif32"
14+
"espressif32",
15+
"espressif8266"
1516
],
1617
"export": {
1718
"include": [
@@ -38,6 +39,7 @@
3839
"googletest/m4",
3940
"googletest/make",
4041
"googletest/msvc",
42+
"googletest/samples",
4143
"googletest/scripts",
4244
"googletest/src/gtest-all.cc",
4345
"googletest/src/gtest_main.cc",
@@ -54,6 +56,24 @@
5456
"-Igooglemock",
5557
"-Igoogletest/include",
5658
"-Igoogletest"
59+
],
60+
"srcFilter": [
61+
"+<*>",
62+
"-<.git/>",
63+
"-<googlemock>",
64+
"-<googlemock/test/>",
65+
"-<googlemock/src>",
66+
"+<googlemock/src/gmock-all.cc>",
67+
"+<googletest/src/gtest-all.cc>",
68+
"+<googlemock/src/gmock_main.cc>",
69+
"-<googletest>",
70+
"-<googletest/codegear/>",
71+
"-<googletest/samples>",
72+
"-<googletest/test/>",
73+
"-<googletest/xcode>",
74+
"-<googletest/src>",
75+
"+<googletest/src/gtest-all.cc>",
76+
"+<googletest/src/gtest_main.cc>"
5777
]
5878
}
5979
}

platformio.ini

+17-1
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,21 @@ platform = espressif32
2727
board = esp32dev
2828
framework = arduino
2929
build_flags = -I./googlemock/include -I./googletest/include -I./googletest -I./googlemock
30-
src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googlemock/src/gmock_main.cc> +<googletest/src/gtest-all.cc>
30+
src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googletest/src/gtest-all.cc> +<googlemock/src/gmock_main.cc>
3131
upload_speed = 921600
32+
33+
[env:googletest_esp8266]
34+
platform = espressif8266
35+
board = huzzah
36+
framework = arduino
37+
build_flags = -I./googletest/include -I./googletest
38+
src_filter = +<*> -<.git/> -<googlemock> -<googletest/codegear/> -<googletest/samples> -<googletest/test/> -<googletest/xcode> -<googletest/src> +<googletest/src/gtest-all.cc> +<googletest/src/gtest_main.cc>
39+
upload_speed = 921600
40+
41+
[env:googlemock_esp8266]
42+
platform = espressif8266
43+
board = huzzah
44+
framework = arduino
45+
build_flags = -I./googlemock/include -I./googletest/include -I./googletest -I./googlemock
46+
src_filter = +<*> -<.git/> -<googletest> -<googlemock/test/> -<googlemock/src> +<googlemock/src/gmock-all.cc> +<googletest/src/gtest-all.cc> +<googlemock/src/gmock_main.cc>
47+
upload_speed = 921600

0 commit comments

Comments
 (0)