Skip to content

Commit 540835f

Browse files
committed
Merge pull request google#2515 from ciband:feat/support_esp8266
PiperOrigin-RevId: 276333426
2 parents 37f3227 + 778733f commit 540835f

File tree

8 files changed

+85
-9
lines changed

8 files changed

+85
-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

+22-4
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
446446
// no support for it at least as recent as Froyo (2.2).
447447
#define GTEST_HAS_STD_WSTRING \
448448
(!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
449-
GTEST_OS_HAIKU))
449+
GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266))
450450

451451
#endif // GTEST_HAS_STD_WSTRING
452452

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

1979+
#elif GTEST_OS_ESP8266
1980+
typedef struct stat StatStruct;
1981+
1982+
inline int FileNo(FILE* file) { return fileno(file); }
1983+
inline int IsATTY(int fd) { return isatty(fd); }
1984+
inline int Stat(const char* path, StatStruct* buf) {
1985+
// stat function not implemented on ESP8266
1986+
return 0;
1987+
}
1988+
inline int StrCaseCmp(const char* s1, const char* s2) {
1989+
return strcasecmp(s1, s2);
1990+
}
1991+
inline char* StrDup(const char* src) { return strdup(src); }
1992+
inline int RmDir(const char* dir) { return rmdir(dir); }
1993+
inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
1994+
19781995
#else
19791996

19801997
typedef struct stat StatStruct;
@@ -2023,8 +2040,9 @@ inline int Close(int fd) { return close(fd); }
20232040
inline const char* StrError(int errnum) { return strerror(errnum); }
20242041
#endif
20252042
inline const char* GetEnv(const char* name) {
2026-
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || GTEST_OS_WINDOWS_RT
2027-
// We are on Windows CE, which has no environment variables.
2043+
#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \
2044+
GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266
2045+
// We are on an embedded platform, which has no environment variables.
20282046
static_cast<void>(name); // To prevent 'unused argument' warning.
20292047
return nullptr;
20302048
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9)

googletest/src/gtest-filepath.cc

+4-1
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);
@@ -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
@@ -4506,6 +4506,7 @@ class ScopedPrematureExitFile {
45064506
}
45074507

45084508
~ScopedPrematureExitFile() {
4509+
#if !defined GTEST_OS_ESP8266
45094510
if (!premature_exit_filepath_.empty()) {
45104511
int retval = remove(premature_exit_filepath_.c_str());
45114512
if (retval) {
@@ -4514,6 +4515,7 @@ class ScopedPrematureExitFile {
45144515
<< retval;
45154516
}
45164517
}
4518+
#endif
45174519
}
45184520

45194521
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

+20-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"version": "1.10.0",
1212
"frameworks": "arduino",
1313
"platforms": [
14-
"espressif32"
14+
"espressif32",
15+
"espressif8266"
1516
],
1617
"export": {
1718
"include": [
@@ -42,6 +43,24 @@
4243
"-Igooglemock",
4344
"-Igoogletest/include",
4445
"-Igoogletest"
46+
],
47+
"srcFilter": [
48+
"+<*>",
49+
"-<.git/>",
50+
"-<googlemock>",
51+
"-<googlemock/test/>",
52+
"-<googlemock/src>",
53+
"+<googlemock/src/gmock-all.cc>",
54+
"+<googletest/src/gtest-all.cc>",
55+
"+<googlemock/src/gmock_main.cc>",
56+
"-<googletest>",
57+
"-<googletest/codegear/>",
58+
"-<googletest/samples>",
59+
"-<googletest/test/>",
60+
"-<googletest/xcode>",
61+
"-<googletest/src>",
62+
"+<googletest/src/gtest-all.cc>",
63+
"+<googletest/src/gtest_main.cc>"
4564
]
4665
}
4766
}

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)