Skip to content

Commit 99ae632

Browse files
committed
Add support of Zephyr OS
Although Zephyr has it own test suite, it doesn't work well with C++. gtest and gmock seem more adapted. This adds support of Zephyr OS in order to test C++ libraries and applications. Signed-off-by: Alexandre Bailon <[email protected]>
1 parent a866428 commit 99ae632

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
#define GTEST_OS_GNU_HURD 1
8585
#elif defined(__GLIBC__) && defined(__FreeBSD_kernel__)
8686
#define GTEST_OS_GNU_KFREEBSD 1
87+
#elif defined(__ZEPHYR__)
88+
// Define it before linux as it could be built as a linux application
89+
#define GTEST_OS_ZEPHYR 1
8790
#elif defined __linux__
8891
#define GTEST_OS_LINUX 1
8992
#if defined __ANDROID__

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

+17
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
// GTEST_OS_WINDOWS_PHONE - Windows Phone
142142
// GTEST_OS_WINDOWS_RT - Windows Store App/WinRT
143143
// GTEST_OS_ZOS - z/OS
144+
// GTEST_OS_ZEPHYR - Zephyr OS
144145
//
145146
// Among the platforms, Cygwin, Linux, Mac OS X, and Windows have the
146147
// most stable support. Since core members of the Google Test project
@@ -525,6 +526,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
525526
#endif
526527
#endif // GTEST_HAS_STD_WSTRING
527528

529+
#ifdef GTEST_OS_ZEPHYR
530+
#define GTEST_HAS_FILE_SYSTEM 0
531+
#endif
532+
528533
#ifndef GTEST_HAS_FILE_SYSTEM
529534
// Most platforms support a file system.
530535
#define GTEST_HAS_FILE_SYSTEM 1
@@ -2060,6 +2065,18 @@ inline int RmDir(const char* dir) { return rmdir(dir); }
20602065
inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); }
20612066
#endif
20622067

2068+
#elif defined(GTEST_OS_ZEPHYR)
2069+
static inline int FileNo(FILE* file) {
2070+
if (file == stdin)
2071+
return 1;
2072+
else if (file == stdout)
2073+
return 2;
2074+
else if (file == stderr)
2075+
return 3;
2076+
return -EINVAL;
2077+
}
2078+
2079+
static inline int isatty(int fd) { return true; }
20632080
#else
20642081

20652082
typedef struct stat StatStruct;

googletest/src/gtest.cc

+2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
#include <algorithm>
4444
#include <chrono> // NOLINT
4545
#include <cmath>
46+
#ifndef GTEST_OS_ZEPHYR
4647
#include <csignal> // NOLINT: raise(3) is used on some platforms
48+
#endif
4749
#include <cstdint>
4850
#include <cstdlib>
4951
#include <cstring>

googletest/src/gtest_main.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ void loop() { RUN_ALL_TESTS(); }
4747
}
4848
#endif
4949

50-
#elif defined(GTEST_OS_QURT)
50+
#elif defined(GTEST_OS_QURT) || defined(GTEST_OS_ZEPHYR)
5151
// QuRT: program entry point is main, but argc/argv are unusable.
5252

53+
#if defined(GTEST_OS_ZEPHYR)
54+
#undef GTEST_API_
55+
#define GTEST_API_
56+
#endif
57+
5358
GTEST_API_ int main() {
5459
printf("Running main() from %s\n", __FILE__);
5560
testing::InitGoogleTest();

0 commit comments

Comments
 (0)