Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add GTest/GMock support for ESP32 #66

Merged

Conversation

ciband
Copy link
Contributor

@ciband ciband commented Feb 1, 2019

Proposed changes

Converts the IoT tests to use newly supported googletest and removes AUnit usage. This re-enables the unit test builds for ESP32.

Types of changes

  • Refactoring (improve a current implementation without adding a new feature or fixing a bug)
  • Build (changes that affect the build system)
  • Test (adding missing tests or fixing existing tests)
  • Other... Please describe: A lot of external to Ark work went into this feature (see details below)

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes

Further comments

This PR only supports ESP32, which is better than the current support of nothing. The next step is to support ESP8266. This is a work in progress.

googletest was not supported on our IoT platforms so I added support in googletest. Ark has the distinction of being the first project to use this new feature.

The following are all the commits required to make this happen:

Helps close #27

@ghost
Copy link

ghost commented Feb 1, 2019

@ciband Thanks for submitting this pull request, a maintainer will get back to you shortly!

@ghost
Copy link

ghost commented Feb 1, 2019

@faustbrian @air1one - please review this in the next few days. Be sure to explicitly select labels so I know what's going on.

If no reviewer appears after a week, a reminder will be sent out.

@ghost ghost added Status: Needs Review The issue or pull request needs a review by a developer of the team. Complexity: Medium Less than 256 lines changed. labels Feb 1, 2019
@ghost
Copy link

ghost commented Feb 1, 2019

@ciband Your pull request doesn't follow our contribution guidelines. Please review and correct it.

Let the project config handle it.
Since ESP32 is now supported by GTest, re-enable it.  Disable ESP8266 until it can be supported.
@ghost
Copy link

ghost commented Feb 1, 2019

@ciband The ci/circleci: build-linux-default job is failing as of 17c4de641710e88a599a43e17da1fdea8154b4f0. Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

@ciband
Copy link
Contributor Author

ciband commented Feb 1, 2019

Once google/googletest#2098 is merged, CI should completed and this PR will be good to go.

@ciband
Copy link
Contributor Author

ciband commented Feb 5, 2019

googletest PR has been merged and PIO appears to be updated but the actual downloaded library from PIO is still including the source file that is causing the duplicate symbols which cause the failing build.

Will continue to investigate.

@ciband
Copy link
Contributor Author

ciband commented Feb 5, 2019

There was an issue with the googletest PR.

This PR fixes it.

google/googletest#2107

Waiting on it to be merged.

@ciband
Copy link
Contributor Author

ciband commented Feb 13, 2019

PR has been merged and PIO library is updated but the build still failed like the PIO library was not updated. Will keep monitoring.

@ciband
Copy link
Contributor Author

ciband commented Feb 13, 2019

PIO library registry is updated and CI passes now. This PR should be good to go.

faustbrian
faustbrian previously approved these changes Feb 13, 2019
@ghost
Copy link

ghost commented Feb 13, 2019

@ciband A contributor has approved this PR. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait.

Thank you for your contribution!

@ghost ghost added the Status: Contributor Approved The pull request has been approved by a contributor. label Feb 13, 2019
@ciband ciband mentioned this pull request Feb 13, 2019
spkjp
spkjp previously approved these changes Feb 13, 2019
@sleepdefic1t
Copy link
Contributor

@ciband

macOS:

$ cd cpp-client/test

$ pio run -e esp32 -t upload

Processing esp32 (framework: arduino; platform: espressif32; board: esp32dev)
--------------------------------------------------------------------------------
LibraryManager: Installing id=64
Downloading...
Unpacking  [####################################]  100%
LibraryManager: Installing id=5976
Downloading...
Unpacking  [####################################]  100%
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz 320KB RAM (4MB Flash)
DEBUG: CURRENT(esp-prog) EXTERNAL(esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(deep) COMPATIBILITY(soft)
Collected 42 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ArduinoJson> 5.13.4
|-- <googletest> 1.8.1
|-- <src>
|   |-- <HTTPClient> 1.2
|   |   |-- <WiFi> 1.2.7
|   |   |   |-- <SPI> 1.0
|   |   |-- <WiFiClientSecure> 1.0
|   |   |   |-- <WiFi> 1.2.7
|   |   |   |   |-- <SPI> 1.0
|-- <HTTPClient> 1.2
|   |-- <WiFi> 1.2.7
|   |   |-- <SPI> 1.0
|   |-- <WiFiClientSecure> 1.0
|   |   |-- <WiFi> 1.2.7
|   |   |   |-- <SPI> 1.0
Compiling .pioenvs/esp32/src/src/api/blocks/blocks.cpp.o
Compiling .pioenvs/esp32/src/src/api/delegates/delegates.cpp.o
Compiling .pioenvs/esp32/src/src/api/node/node.cpp.o
Compiling .pioenvs/esp32/src/src/api/paths.cpp.o
Compiling .pioenvs/esp32/src/src/api/peers/peers.cpp.o
Compiling .pioenvs/esp32/src/src/api/transactions/transactions.cpp.o
Compiling .pioenvs/esp32/src/src/api/votes/votes.cpp.o
Compiling .pioenvs/esp32/src/src/api/wallets/wallets.cpp.o
Compiling .pioenvs/esp32/src/src/host/host.cpp.o
Compiling .pioenvs/esp32/src/src/http/iot/http.cpp.o
Compiling .pioenvs/esp32/src/src/http/iot/main.cpp.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googlemock/src/gmock-cardinalities.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googlemock/src/gmock-internal-utils.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googlemock/src/gmock-matchers.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googlemock/src/gmock-spec-builders.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googlemock/src/gmock.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googletest/src/gtest-death-test.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googletest/src/gtest-filepath.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googletest/src/gtest-matchers.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googletest/src/gtest-port.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googletest/src/gtest-printers.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googletest/src/gtest-test-part.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googletest/src/gtest-typed-test.cc.o
Compiling .pioenvs/esp32/src/test/.piolibdeps/googletest_ID5976/googletest/src/gtest.cc.o
Compiling .pioenvs/esp32/src/test/api/blocks.cpp.o
Compiling .pioenvs/esp32/src/test/api/delegates.cpp.o
Compiling .pioenvs/esp32/src/test/api/node.cpp.o
Compiling .pioenvs/esp32/src/test/api/paths.cpp.o
Compiling .pioenvs/esp32/src/test/api/peers.cpp.o
Compiling .pioenvs/esp32/src/test/api/transactions.cpp.o
Compiling .pioenvs/esp32/src/test/api/votes.cpp.o
Compiling .pioenvs/esp32/src/test/api/wallets.cpp.o
Compiling .pioenvs/esp32/src/test/connection/connection.cpp.o
Compiling .pioenvs/esp32/src/test/host/host.cpp.o
Compiling .pioenvs/esp32/src/test/iot/test_main.cpp.o
Generating partitions .pioenvs/esp32/partitions.bin
Archiving .pioenvs/esp32/lib622/libArduinoJson_ID64.a
Indexing .pioenvs/esp32/lib622/libArduinoJson_ID64.a
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googlemock/src/gmock-cardinalities.cc.o
iot/test_main.cpp: In function 'void loop()':
iot/test_main.cpp:17:18: warning: ignoring return value of 'int RUN_ALL_TESTS()', declared with attribute warn_unused_result [-Wunused-result]
RUN_ALL_TESTS();
^
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googlemock/src/gmock-internal-utils.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googlemock/src/gmock-matchers.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googlemock/src/gmock-spec-builders.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googlemock/src/gmock.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googletest/src/gtest-death-test.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googletest/src/gtest-filepath.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googletest/src/gtest-matchers.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googletest/src/gtest-port.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googletest/src/gtest-printers.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googletest/src/gtest-test-part.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googletest/src/gtest-typed-test.cc.o
Compiling .pioenvs/esp32/lib192/googletest_ID5976/googletest/src/gtest.cc.o
Compiling .pioenvs/esp32/lib60a/SPI/SPI.cpp.o
Compiling .pioenvs/esp32/lib518/WiFi_ID870/WiFi.cpp.o
Archiving .pioenvs/esp32/lib60a/libSPI.a
Indexing .pioenvs/esp32/lib60a/libSPI.a
Compiling .pioenvs/esp32/lib518/WiFi_ID870/WiFiClient.cpp.o
Compiling .pioenvs/esp32/lib518/WiFi_ID870/WiFiServer.cpp.o
Compiling .pioenvs/esp32/lib518/WiFi_ID870/WiFiUdp.cpp.o
Compiling .pioenvs/esp32/lib518/WiFi_ID870/utility/server_drv.cpp.o
Compiling .pioenvs/esp32/lib518/WiFi_ID870/utility/spi_drv.cpp.o
Compiling .pioenvs/esp32/lib518/WiFi_ID870/utility/wifi_drv.cpp.o
Compiling .pioenvs/esp32/lib5f3/WiFiClientSecure/WiFiClientSecure.cpp.o
.platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp: In static member function 'static char SpiDrv::spiTransfer(char)':
.platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp:36:78: warning: integer overflow in expression [-Woverflow]
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); } while (++ii < (X*F_CPU/16000000)); }
^
.platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp:37:26: note: in expansion of macro 'DELAY_SPI'
#define DELAY_TRANSFER() DELAY_SPI(10)
^
.platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp:76:5: note: in expansion of macro 'DELAY_TRANSFER'
DELAY_TRANSFER();
^
.platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp: In static member function 'static void SpiDrv::getParam(uint8_t*)':
.platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp:36:78: warning: integer overflow in expression [-Woverflow]
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); } while (++ii < (X*F_CPU/16000000)); }
^
.platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp:37:26: note: in expansion of macro 'DELAY_SPI'
#define DELAY_TRANSFER() DELAY_SPI(10)
^
.platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp:148:5: note: in expansion of macro 'DELAY_TRANSFER'
DELAY_TRANSFER();
^
.platformio/lib/WiFi_ID870/src/utility/wifi_drv.cpp: In static member function 'static uint8_t WiFiDrv::getEncTypeNetowrks(uint8_t)':
platformio/lib/WiFi_ID870/src/utility/wifi_drv.cpp:451:10: warning: converting to non-pointer type 'uint8_t {aka unsigned char}' from NULL [-Wconversion-null]
return NULL;
^
.platformio/lib/WiFi_ID870/src/utility/wifi_drv.cpp: In static member function 'static int32_t WiFiDrv::getRSSINetoworks(uint8_t)':
.platformio/lib/WiFi_ID870/src/utility/wifi_drv.cpp:476:10: warning: converting to non-pointer type 'int' from NULL [-Wconversion-null]
return NULL;
^
In file included from .platformio/lib/WiFi_ID870/src/utility/spi_drv.cpp:22:0:
.platformio/lib/WiFi_ID870/src/utility/spi_drv.h: At global scope:
.platformio/lib/WiFi_ID870/src/utility/spi_drv.h:41:13: warning: 'initialized' defined but not used [-Wunused-variable]
static bool initialized = false;
^
Compiling .pioenvs/esp32/lib5f3/WiFiClientSecure/ssl_client.cpp.o
Archiving .pioenvs/esp32/lib518/libWiFi_ID870.a
Indexing .pioenvs/esp32/lib518/libWiFi_ID870.a
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In constructor 'WiFiClientSecure::WiFiClientSecure()':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:33:5: error: '_connected' was not declared in this scope
_connected = false;
^
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In constructor 'WiFiClientSecure::WiFiClientSecure(int)':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:50:5: error: '_connected' was not declared in this scope
_connected = false;
^
platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In member function 'WiFiClientSecure& WiFiClientSecure::operator=(const WiFiClientSecure&)':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:79:5: error: '_connected' was not declared in this scope
_connected = other._connected;
^
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:79:24: error: 'const class WiFiClientSecure' has no member named '_connected'
_connected = other._connected;
^
platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In member function 'virtual void WiFiClientSecure::stop()':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:88:9: error: '_connected' was not declared in this scope
_connected = false;
^
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In member function 'int WiFiClientSecure::connect(const char*, uint16_t, const char*, const char*, const char*)':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:122:5: error: '_connected' was not declared in this scope
_connected = true;
^
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In member function 'int WiFiClientSecure::connect(const char*, uint16_t, const char*, const char*)':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:139:5: error: '_connected' was not declared in this scope
_connected = true;
^
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In member function 'virtual size_t WiFiClientSecure::write(const uint8_t*, size_t)':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:168:10: error: '_connected' was not declared in this scope
if (!_connected) {
^
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In member function 'virtual int WiFiClientSecure::available()':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:212:10: error: '_connected' was not declared in this scope
if (!_connected) {
^
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp: In member function 'virtual uint8_t WiFiClientSecure::connected()':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/WiFiClientSecure.cpp:228:12: error: '_connected' was not declared in this scope
return _connected;
^
*** [.pioenvs/esp32/lib5f3/WiFiClientSecure/WiFiClientSecure.cpp.o] Error 1
Compiling .pioenvs/esp32/libe28/HTTPClient/HTTPClient.cpp.o
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/ssl_client.cpp: In function 'int start_ssl_client(sslclient_context*, const char*, uint32_t, const char*, const char*, const char*, const char*, const char*)':
.platformio/packages/framework-arduinoespressif32/libraries/WiFiClientSecure/src/ssl_client.cpp:65:9: error: 'WiFiGenericClass' has not been declared
if(!WiFiGenericClass::hostByName(host, srv)){
^
*** [.pioenvs/esp32/lib5f3/WiFiClientSecure/ssl_client.cpp.o] Error 1
=========================================================================================================== [ERROR] Took 61.00 seconds ===========================================================================================================

@ciband
Copy link
Contributor Author

ciband commented Feb 13, 2019

Not sure what is going on there. PIO build should be the same on Windows,Mac,Linux. Works on Windows and Linux (via CI).

Do you have the latest PIO and platform updates installed?

@ciband
Copy link
Contributor Author

ciband commented Feb 13, 2019

You can try nuking the .pio* directories in the test directory and rebuild. Looks like something with the ESP32 platform is not happy.

@sleepdefic1t
Copy link
Contributor

@ciband
Looks like I had to empty ~/.platformio/lib 👍
Now it builds and flashes okay.

However, ESP32 loops tests with:

void setup() {
    Serial.begin(115200);
	while (!Serial); // for the Arduino Leonardo/Micro only
	delay(100);
  testing::InitGoogleMock();
	delay(1000);
}

void loop() {
  RUN_ALL_TESTS();
}

Changing to the following made tests run once on-board:

void setup() {
    Serial.begin(115200);
	while (!Serial); // for the Arduino Leonardo/Micro only
	delay(100);
  testing::InitGoogleMock();
	delay(1000);
  RUN_ALL_TESTS();
}

void loop() { }

Can you confirm this?

@ciband
Copy link
Contributor Author

ciband commented Feb 14, 2019 via email

@ciband ciband dismissed stale reviews from spkjp and faustbrian via 0d359e0 February 14, 2019 00:33
@sleepdefic1t
Copy link
Contributor

Thank you, @ciband !!
@kristjank @supaiku0 @faustbrian , this is ready to be merged 👍

@ghost
Copy link

ghost commented Feb 14, 2019

@ciband A contributor has approved this PR. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait.

Thank you for your contribution!

@faustbrian faustbrian merged commit baf8cbc into ArkEcosystemArchive:master Feb 14, 2019
@ghost
Copy link

ghost commented Feb 14, 2019

@ciband Your pull request has been merged but was not assigned a bounty tier. @air1one @faustbrian - please assign a bounty tier to this pull request in the next few days.

@ghost ghost removed the Status: Needs Review The issue or pull request needs a review by a developer of the team. label Feb 14, 2019
@faustbrian faustbrian added the Bounty: Tier 4 Awarded for small features, refactorings, improvements. This is valued at 20 USD. label Feb 14, 2019
@ghost
Copy link

ghost commented Feb 14, 2019

@ciband Your pull request has been merged and marked as tier 3. It will earn you $25 USD.

@boldninja boldninja added Bounty: Tier 3 Awarded for medium features, refactorings, improvements. This is valued at 50 USD. and removed Bounty: Tier 4 Awarded for small features, refactorings, improvements. This is valued at 20 USD. labels Mar 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bounty: Tier 3 Awarded for medium features, refactorings, improvements. This is valued at 50 USD. Complexity: Medium Less than 256 lines changed. Status: Contributor Approved The pull request has been approved by a contributor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use mocks for testing.
5 participants