From 2c8ab3f18b2ed9fdc1742ec60b6e34248d04efe3 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Tue, 4 Dec 2018 21:44:39 -0600 Subject: [PATCH 1/4] feat: Add initial support for PlatformIO and Arduino --- .travis.yml | 9 +++++++++ ci/build-platformio.sh | 2 ++ ci/install-platformio.sh | 5 +++++ googlemock/src/gmock_main.cc | 16 ++++++++++++++++ googletest/src/gtest_main.cc | 14 ++++++++++++++ platformio.ini | 31 +++++++++++++++++++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 ci/build-platformio.sh create mode 100644 ci/install-platformio.sh create mode 100644 platformio.ini diff --git a/.travis.yml b/.travis.yml index 2b0ac21a..74e1b8f1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,12 @@ language: cpp # It is more tedious, but grants us far more flexibility. matrix: include: + - os: linux + dist: trusty + sudo: required + group: deprecated-2017Q3 + install: ./ci/install-platformio.sh + script: ./ci/build-platformio.sh - os: linux compiler: gcc sudo : true @@ -44,6 +50,9 @@ matrix: env: BUILD_TYPE=Release VERBOSE=1 CXX_FLAGS=-std=c++11 if: type != pull_request +before_install: + - chmod -R +x ./ci/*.sh + # These are the install and build (script) phases for the most common entries in the matrix. They could be included # in each entry in the matrix, but that is just repetitive. install: diff --git a/ci/build-platformio.sh b/ci/build-platformio.sh new file mode 100644 index 00000000..1d7658d8 --- /dev/null +++ b/ci/build-platformio.sh @@ -0,0 +1,2 @@ +# run PlatformIO builds +platformio run diff --git a/ci/install-platformio.sh b/ci/install-platformio.sh new file mode 100644 index 00000000..4d7860a5 --- /dev/null +++ b/ci/install-platformio.sh @@ -0,0 +1,5 @@ +# install PlatformIO +sudo pip install -U platformio + +# update PlatformIO +platformio update diff --git a/googlemock/src/gmock_main.cc b/googlemock/src/gmock_main.cc index a3a271e6..50d0b426 100644 --- a/googlemock/src/gmock_main.cc +++ b/googlemock/src/gmock_main.cc @@ -32,6 +32,20 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#ifdef ARDUINO +void setup() { + int argc = 0; + char** argv = nullptr; + // 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(&argc, argv); +} +void loop() { + RUN_ALL_TESTS(); +} +#else + // MS C++ compiler/linker has a bug on Windows (not on Windows CE), which // causes a link error when _tmain is defined in a static library and UNICODE // is enabled. For this reason instead of _tmain, main function is used on @@ -52,3 +66,5 @@ GTEST_API_ int main(int argc, char** argv) { testing::InitGoogleMock(&argc, argv); return RUN_ALL_TESTS(); } +#endif + diff --git a/googletest/src/gtest_main.cc b/googletest/src/gtest_main.cc index 2113f621..0d343ba9 100644 --- a/googletest/src/gtest_main.cc +++ b/googletest/src/gtest_main.cc @@ -30,8 +30,22 @@ #include #include "gtest/gtest.h" +#ifdef ARDUINO +void setup() { + int argc = 0; + char** argv = nullptr; + testing::InitGoogleTest(&argc, argv); +} + +void loop() { + RUN_ALL_TESTS(); +} + +#else + GTEST_API_ int main(int argc, char **argv) { printf("Running main() from %s\n", __FILE__); testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } +#endif diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 00000000..3910026b --- /dev/null +++ b/platformio.ini @@ -0,0 +1,31 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + + +[platformio] +#src_dir = ./googlemock +#src_dir = ./googletest +src_dir = . + +[env:googletest_esp32] +platform = espressif32 +board = esp32dev +framework = arduino +build_flags = -I./googletest/include -I./googletest +src_filter = +<*> -<.git/> - - - - - - + + +upload_speed = 921600 + +[env:googlemock_esp32] +platform = espressif32 +board = esp32dev +framework = arduino +build_flags = -I./googlemock/include -I./googletest/include -I./googletest -I./googlemock +src_filter = +<*> -<.git/> - - - + + + +upload_speed = 921600 From 39c09043b83ea6a46407468c4733271334cdf1b4 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Thu, 6 Dec 2018 12:35:06 -0600 Subject: [PATCH 2/4] chore: Add initial library.json config Added initial library.json config for PlatformIO Version will be synced to proper googletest version once the PIO library has been registered and proven out round trip. --- library.json | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 library.json diff --git a/library.json b/library.json new file mode 100644 index 00000000..0e35a61f --- /dev/null +++ b/library.json @@ -0,0 +1,51 @@ +{ + "name": "googletest", + "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.", + "license": "BSD-3-Clause", + "homepage": "https://github.com/abseil/googletest/blob/master/README.md", + "repository": { + "type": "git", + "url": "https://github.com/abseil/googletest.git" + }, + "version": "0.0.1", + "exclude": [ + "ci", + "googlemock/build-aux", + "googlemock/cmake", + "googlemock/make", + "googlemock/msvc", + "googlemock/scripts", + "googlemock/test", + "googlemock/CMakeLists.txt", + "googlemock/Makefile.am", + "googlemock/configure.ac", + "googletest/cmake", + "googletest/codegear", + "googletest/m4", + "googletest/make", + "googletest/msvc", + "googletest/scripts", + "googletest/test", + "googletest/xcode", + "googletest/CMakeLists.txt", + "googletest/Makefile.am", + "googletest/configure.ac", + ], + "frameworks": "arduino", + "platforms": [ + "espressif32" + ], + "export": { + "include": [ + "googlemock/include/*", + "googletest/include/*" + ] + }, + "build": { + "flags": [ + "-I googlemock/include", + "-I googletest/include" + ] + } +} From d9251df84951768fa74cc0e01c3a76dbc1b2b0b1 Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Thu, 6 Dec 2018 15:26:28 -0600 Subject: [PATCH 3/4] fix: Remove global chmod from Travis Removed global chmod +x for Travis scripts in favor of just applying it to PlatformIO builds. --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 74e1b8f1..fd8f7c65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ matrix: dist: trusty sudo: required group: deprecated-2017Q3 + before_install: chmod -R +x ./ci/*platformio.sh install: ./ci/install-platformio.sh script: ./ci/build-platformio.sh - os: linux @@ -50,9 +51,6 @@ matrix: env: BUILD_TYPE=Release VERBOSE=1 CXX_FLAGS=-std=c++11 if: type != pull_request -before_install: - - chmod -R +x ./ci/*.sh - # These are the install and build (script) phases for the most common entries in the matrix. They could be included # in each entry in the matrix, but that is just repetitive. install: From 31eb5e9b873af4b509be2f77616113007fa0de9d Mon Sep 17 00:00:00 2001 From: Chris Johnson Date: Fri, 7 Dec 2018 12:24:01 -0600 Subject: [PATCH 4/4] chore: Update version to latest release --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 0e35a61f..3104ec1e 100644 --- a/library.json +++ b/library.json @@ -8,7 +8,7 @@ "type": "git", "url": "https://github.com/abseil/googletest.git" }, - "version": "0.0.1", + "version": "1.8.1", "exclude": [ "ci", "googlemock/build-aux",