From 28b0525a35dd0d9614d6f20cf4374d4bf95d2b7c Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 5 Nov 2020 17:38:07 -0800 Subject: [PATCH 01/10] WIP: runs unit tests. --- SampleProjects/NetworkLib/.arduino-ci.yml | 11 ++++ SampleProjects/NetworkLib/.gitignore | 1 + SampleProjects/NetworkLib/Gemfile | 2 + SampleProjects/NetworkLib/README.md | 3 + SampleProjects/NetworkLib/library.properties | 10 ++++ SampleProjects/NetworkLib/scripts/install.sh | 7 +++ SampleProjects/NetworkLib/src/NetworkLib.cpp | 1 + SampleProjects/NetworkLib/src/NetworkLib.h | 3 + SampleProjects/NetworkLib/test/test.cpp | 16 ++++++ cpp/arduino/Arduino.h | 1 + cpp/arduino/Client.h | 14 +++++ cpp/arduino/Godmode.cpp | 3 + cpp/arduino/IPAddress.h | 60 ++++++++++++++++++++ cpp/arduino/Print.h | 21 +++---- cpp/arduino/Printable.h | 8 +++ cpp/arduino/Server.h | 5 ++ cpp/arduino/Udp.h | 9 +++ 17 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 SampleProjects/NetworkLib/.arduino-ci.yml create mode 100644 SampleProjects/NetworkLib/.gitignore create mode 100644 SampleProjects/NetworkLib/Gemfile create mode 100644 SampleProjects/NetworkLib/README.md create mode 100644 SampleProjects/NetworkLib/library.properties create mode 100755 SampleProjects/NetworkLib/scripts/install.sh create mode 100644 SampleProjects/NetworkLib/src/NetworkLib.cpp create mode 100644 SampleProjects/NetworkLib/src/NetworkLib.h create mode 100644 SampleProjects/NetworkLib/test/test.cpp create mode 100644 cpp/arduino/Client.h create mode 100644 cpp/arduino/IPAddress.h create mode 100644 cpp/arduino/Printable.h create mode 100644 cpp/arduino/Server.h create mode 100644 cpp/arduino/Udp.h diff --git a/SampleProjects/NetworkLib/.arduino-ci.yml b/SampleProjects/NetworkLib/.arduino-ci.yml new file mode 100644 index 00000000..3f4cf5bc --- /dev/null +++ b/SampleProjects/NetworkLib/.arduino-ci.yml @@ -0,0 +1,11 @@ +unittest: + platforms: + - mega2560 + # libraries: + # - "Ethernet" + +compile: + platforms: + - mega2560 + # libraries: + # - "Ethernet" diff --git a/SampleProjects/NetworkLib/.gitignore b/SampleProjects/NetworkLib/.gitignore new file mode 100644 index 00000000..06de90aa --- /dev/null +++ b/SampleProjects/NetworkLib/.gitignore @@ -0,0 +1 @@ +.bundle \ No newline at end of file diff --git a/SampleProjects/NetworkLib/Gemfile b/SampleProjects/NetworkLib/Gemfile new file mode 100644 index 00000000..b2b3b1fd --- /dev/null +++ b/SampleProjects/NetworkLib/Gemfile @@ -0,0 +1,2 @@ +source 'https://rubygems.org' +gem 'arduino_ci', path: '../../' diff --git a/SampleProjects/NetworkLib/README.md b/SampleProjects/NetworkLib/README.md new file mode 100644 index 00000000..b25d2e14 --- /dev/null +++ b/SampleProjects/NetworkLib/README.md @@ -0,0 +1,3 @@ +# NetworkLib + +This is an example of a library that depends on Ethernet. diff --git a/SampleProjects/NetworkLib/library.properties b/SampleProjects/NetworkLib/library.properties new file mode 100644 index 00000000..2efc89bd --- /dev/null +++ b/SampleProjects/NetworkLib/library.properties @@ -0,0 +1,10 @@ +name=Ethernet +version=0.1.0 +author=James Foster +maintainer=James Foster +sentence=Sample Ethernet library to validate Client/Server mocks +paragraph=Sample Ethernet library to validate Client/Server mocks +category=Other +url=https://github.com/Arduino-CI/arduino_ci/SampleProjects/Ethernet +architectures=avr,esp8266 +includes=NetworkLib.h diff --git a/SampleProjects/NetworkLib/scripts/install.sh b/SampleProjects/NetworkLib/scripts/install.sh new file mode 100755 index 00000000..3f704c82 --- /dev/null +++ b/SampleProjects/NetworkLib/scripts/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +cd "$( dirname "${BASH_SOURCE[0]}" )" +cd ../src +rm -rf Ethernet > /dev/null 2>&1 +# get Ethernet library +git clone https://github.com/arduino-libraries/Ethernet.git diff --git a/SampleProjects/NetworkLib/src/NetworkLib.cpp b/SampleProjects/NetworkLib/src/NetworkLib.cpp new file mode 100644 index 00000000..01e5d5b0 --- /dev/null +++ b/SampleProjects/NetworkLib/src/NetworkLib.cpp @@ -0,0 +1 @@ +#include "Ethernet.h" diff --git a/SampleProjects/NetworkLib/src/NetworkLib.h b/SampleProjects/NetworkLib/src/NetworkLib.h new file mode 100644 index 00000000..9ee81b24 --- /dev/null +++ b/SampleProjects/NetworkLib/src/NetworkLib.h @@ -0,0 +1,3 @@ +#pragma once + +#include diff --git a/SampleProjects/NetworkLib/test/test.cpp b/SampleProjects/NetworkLib/test/test.cpp new file mode 100644 index 00000000..b0c60b42 --- /dev/null +++ b/SampleProjects/NetworkLib/test/test.cpp @@ -0,0 +1,16 @@ +/* +cd SampleProjects/Ethernet +bundle config --local path vendor/bundle +bundle install +bundle exec arduino_ci_remote.rb --skip-compilation +# bundle exec arduino_ci_remote.rb --skip-examples-compilation +*/ + +#include +#include + +unittest(test) { + assertTrue(true); +} + +unittest_main() diff --git a/cpp/arduino/Arduino.h b/cpp/arduino/Arduino.h index e107126e..2c4f347e 100644 --- a/cpp/arduino/Arduino.h +++ b/cpp/arduino/Arduino.h @@ -9,6 +9,7 @@ Where possible, variable names from the Arduino library are used to avoid confli #include "ArduinoDefines.h" +#include "IPAddress.h" #include "WCharacter.h" #include "WString.h" #include "Print.h" diff --git a/cpp/arduino/Client.h b/cpp/arduino/Client.h new file mode 100644 index 00000000..037a2866 --- /dev/null +++ b/cpp/arduino/Client.h @@ -0,0 +1,14 @@ +#pragma once + +#include + +// https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h:341 +extern volatile uint8_t mmapPorts[MOCK_PINS_COUNT]; +#define portOutputRegister(port) (uint8_t *) (&mmapPorts[port]) +#define digitalPinToPort(pin) (pin) +#define digitalPinToBitMask(pin) (1) + +class Client : public Stream { +protected: + uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; +}; diff --git a/cpp/arduino/Godmode.cpp b/cpp/arduino/Godmode.cpp index 102afca6..e279815a 100644 --- a/cpp/arduino/Godmode.cpp +++ b/cpp/arduino/Godmode.cpp @@ -113,3 +113,6 @@ SPIClass SPI = SPIClass(&GODMODE()->spi.dataIn, &GODMODE()->spi.dataOut); // defined in Wire.h TwoWire Wire = TwoWire(); + +// Memory-mapped ports defined in Client.h +uint8_t volatile mmapPorts[MOCK_PINS_COUNT]; diff --git a/cpp/arduino/IPAddress.h b/cpp/arduino/IPAddress.h new file mode 100644 index 00000000..d00127ec --- /dev/null +++ b/cpp/arduino/IPAddress.h @@ -0,0 +1,60 @@ +#pragma once + +#include + +class IPAddress { +private: + union { + uint8_t bytes[4]; + uint32_t dword; + operator uint8_t* () const { return (uint8_t*) bytes; } + } _address; + +public: + // Constructors + IPAddress() { IPAddress(0, 0, 0, 0); } + IPAddress(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4) { + _address.bytes[0] = octet1; + _address.bytes[1] = octet2; + _address.bytes[2] = octet3; + _address.bytes[3] = octet4; + } + IPAddress(uint32_t dword) { _address.dword = dword; } + IPAddress(const uint8_t bytes[]) { + _address.bytes[0] = bytes[0]; + _address.bytes[1] = bytes[1]; + _address.bytes[2] = bytes[2]; + _address.bytes[3] = bytes[3]; + } + + IPAddress(unsigned long dword) { _address.dword = (uint32_t) dword; } + + // Accessors + uint32_t asWord() const { return _address.dword; } + uint8_t *raw_address() { return _address.bytes; }; + + // Comparisons + bool operator==(const IPAddress &rhs) const { + return _address.dword == rhs.asWord(); + } + + bool operator!=(const IPAddress &rhs) const { + return _address.dword != rhs.asWord(); + } + + // Indexing + uint8_t operator[](int index) const { return _address.bytes[index]; } + uint8_t &operator[](int index) { return _address.bytes[index]; } + + // Conversions + operator uint32_t() const { return _address.dword; }; + + friend class EthernetClass; + friend class UDP; + friend class Client; + friend class Server; + friend class DhcpClass; + friend class DNSClient; +}; + +const IPAddress INADDR_NONE(0, 0, 0, 0); diff --git a/cpp/arduino/Print.h b/cpp/arduino/Print.h index b7d8a522..261b116d 100644 --- a/cpp/arduino/Print.h +++ b/cpp/arduino/Print.h @@ -2,6 +2,8 @@ #include #include + +#include "Printable.h" #include "WString.h" #define DEC 10 @@ -12,22 +14,17 @@ #endif #define BIN 2 -class Print; - -class Printable -{ - public: - virtual size_t printTo(Print& p) const = 0; -}; - class Print { + private: + int write_error; + protected: + void setWriteError(int err = 1) { write_error = err; } public: - Print() {} + Print() : write_error(0) {} - // Arduino's version of this is richer but until I see an actual error case I'm not sure how to mock - int getWriteError() { return 0; } - void clearWriteError() { } + int getWriteError() { return write_error; } + void clearWriteError() { setWriteError(0); } virtual int availableForWrite() { return 0; } virtual size_t write(uint8_t) = 0; diff --git a/cpp/arduino/Printable.h b/cpp/arduino/Printable.h new file mode 100644 index 00000000..cdd361d3 --- /dev/null +++ b/cpp/arduino/Printable.h @@ -0,0 +1,8 @@ +#pragma once + +class Print; + +class Printable { +public: + virtual size_t printTo(Print &p) const = 0; +}; diff --git a/cpp/arduino/Server.h b/cpp/arduino/Server.h new file mode 100644 index 00000000..dd1993ff --- /dev/null +++ b/cpp/arduino/Server.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +class Server : public Print {}; diff --git a/cpp/arduino/Udp.h b/cpp/arduino/Udp.h new file mode 100644 index 00000000..50b99f57 --- /dev/null +++ b/cpp/arduino/Udp.h @@ -0,0 +1,9 @@ +#pragma once + +#include +#include + +class UDP : public Stream { +protected: + uint8_t *rawIPAddress(IPAddress &addr) { return addr.raw_address(); }; +}; From 42d49e6993c547c648d7d921ec36eaa9554c0c85 Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 5 Nov 2020 19:23:43 -0800 Subject: [PATCH 02/10] Now able to compile Ethernet library. --- CHANGELOG.md | 1 + SampleProjects/NetworkLib/.arduino-ci.yml | 8 ++++---- .../examples/EthernetExample/EthernetExample.ino | 6 ++++++ SampleProjects/NetworkLib/test/test.cpp | 9 ++++----- 4 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 SampleProjects/NetworkLib/examples/EthernetExample/EthernetExample.ino diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f44cc59..6fcc4b3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - Add `__AVR__` to defines when compiling - Add support for `diditalPinToPort()`, `digitalPinToBitMask()`, and `portOutputRegister()` +- Add stubs for `Client.h`, `IPAddress.h`, `Printable.h`, `Server.h`, and `Udp.h` ### Changed - Move repository from https://github.com/ianfixes/arduino_ci to https://github.com/Arduino-CI/arduino_ci diff --git a/SampleProjects/NetworkLib/.arduino-ci.yml b/SampleProjects/NetworkLib/.arduino-ci.yml index 3f4cf5bc..a242a79b 100644 --- a/SampleProjects/NetworkLib/.arduino-ci.yml +++ b/SampleProjects/NetworkLib/.arduino-ci.yml @@ -1,11 +1,11 @@ unittest: platforms: - mega2560 - # libraries: - # - "Ethernet" + libraries: + - "Ethernet" compile: platforms: - mega2560 - # libraries: - # - "Ethernet" + libraries: + - "Ethernet" diff --git a/SampleProjects/NetworkLib/examples/EthernetExample/EthernetExample.ino b/SampleProjects/NetworkLib/examples/EthernetExample/EthernetExample.ino new file mode 100644 index 00000000..127afc76 --- /dev/null +++ b/SampleProjects/NetworkLib/examples/EthernetExample/EthernetExample.ino @@ -0,0 +1,6 @@ +#include +// if it seems bare, that's because it's only meant to +// demonstrate compilation -- that references work +void setup() {} + +void loop() {} diff --git a/SampleProjects/NetworkLib/test/test.cpp b/SampleProjects/NetworkLib/test/test.cpp index b0c60b42..4c2d4eca 100644 --- a/SampleProjects/NetworkLib/test/test.cpp +++ b/SampleProjects/NetworkLib/test/test.cpp @@ -1,16 +1,15 @@ /* -cd SampleProjects/Ethernet +cd SampleProjects/NetworkLib bundle config --local path vendor/bundle bundle install bundle exec arduino_ci_remote.rb --skip-compilation # bundle exec arduino_ci_remote.rb --skip-examples-compilation */ -#include #include +#include +#include -unittest(test) { - assertTrue(true); -} +unittest(test) { assertEqual(EthernetNoHardware, Ethernet.hardwareStatus()); } unittest_main() From c85e1a083bde76f80d2750f8ef07caee0a3f769a Mon Sep 17 00:00:00 2001 From: James Foster Date: Thu, 5 Nov 2020 19:29:40 -0800 Subject: [PATCH 03/10] Add NetworkLib to tests. --- .travis.yml | 3 +++ appveyor.yml | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index bc5c137a..3fae3865 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,3 +27,6 @@ script: - cd SampleProjects/TestSomething - bundle install - bundle exec arduino_ci_remote.rb + - cd ../NetworkLib + - bundle install + - bundle exec arduino_ci_remote.rb diff --git a/appveyor.yml b/appveyor.yml index 23592ca0..f50a989b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -25,3 +25,6 @@ test_script: - cd SampleProjects\TestSomething - bundle install - bundle exec arduino_ci_remote.rb + - cd ../NetworkLib + - bundle install + - bundle exec arduino_ci_remote.rb From a986b2587ae7323e49b4f335b6d23f27d64b4918 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 7 Nov 2020 18:59:51 -0800 Subject: [PATCH 04/10] Add basic tests for new classes. --- .../TestSomething/test/clientServer.cpp | 84 +++++++++++++++++++ cpp/arduino/Client.h | 14 +++- cpp/arduino/IPAddress.h | 9 +- cpp/arduino/Udp.h | 12 +++ 4 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 SampleProjects/TestSomething/test/clientServer.cpp diff --git a/SampleProjects/TestSomething/test/clientServer.cpp b/SampleProjects/TestSomething/test/clientServer.cpp new file mode 100644 index 00000000..43e0e8c1 --- /dev/null +++ b/SampleProjects/TestSomething/test/clientServer.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include + +// Provide some rudamentary tests for these classes +// They get more thoroughly tested in SampleProjects/NetworkLib + +unittest(Client) { + Client client; + assertEqual(0, client.available()); // subclass of Stream + assertEqual(0, client.availableForWrite()); // subclass of Print + String outData = "Hello, world!"; + client.println(outData); + String inData = client.readString(); + assertEqual(outData + "\r\n", inData); +} + +unittest(IPAddress) { + IPAddress ipAddress0; + assertEqual(0, ipAddress0.asWord()); + uint32_t one = 0x01020304; + IPAddress ipAddress1(one); + assertEqual(one, ipAddress1.asWord()); + IPAddress ipAddress2(2, 3, 4, 5); + assertEqual(0x05040302, ipAddress2.asWord()); + uint8_t bytes[] = {3, 4, 5, 6}; + IPAddress ipAddress3(bytes); + assertEqual(0x06050403, ipAddress3.asWord()); + uint8_t *pBytes = ipAddress1.raw_address(); + assertEqual(*(pBytes + 0), 4); + assertEqual(*(pBytes + 1), 3); + assertEqual(*(pBytes + 2), 2); + assertEqual(*(pBytes + 3), 1); + IPAddress ipAddress1a(one); + assertTrue(ipAddress1 == ipAddress1a); + assertTrue(ipAddress1 != ipAddress2); + assertEqual(1, ipAddress1[3]); + ipAddress1[1] = 11; + assertEqual(11, ipAddress1[1]); + assertEqual(1, ipAddress0 + 1); +} + +class TestPrintable : public Printable { +public: + virtual size_t printTo(Print &p) const { + p.print("TestPrintable"); + return 13; + } +}; + +unittest(Printable) { + TestPrintable printable; + Client client; + client.print(printable); + assertEqual("TestPrintable", client.readString()); +} + +class TestServer : public Server { +public: + uint8_t data; + virtual size_t write(uint8_t value) { data = value; }; +}; + +unittest(Server) { + TestServer server; + server.write(67); + assertEqual(67, server.data); +} + +unittest(Udp) { + UDP udp; + assertEqual(0, udp.available()); // subclass of Stream + assertEqual(0, udp.availableForWrite()); // subclass of Print + String outData = "Hello, world!"; + udp.println(outData); + String inData = udp.readString(); + assertEqual(outData + "\r\n", inData); +} + +unittest_main() diff --git a/cpp/arduino/Client.h b/cpp/arduino/Client.h index 348bf073..7b0b16af 100644 --- a/cpp/arduino/Client.h +++ b/cpp/arduino/Client.h @@ -3,6 +3,18 @@ #include class Client : public Stream { +public: + Client() { + // The Stream mock defines a String buffer but never puts anyting in it! + if (!mGodmodeDataIn) { + mGodmodeDataIn = new String; + } + } + virtual size_t write(uint8_t value) { + mGodmodeDataIn->concat(value); + return 1; + } + protected: - uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; + uint8_t *rawIPAddress(IPAddress &addr) { return addr.raw_address(); } }; diff --git a/cpp/arduino/IPAddress.h b/cpp/arduino/IPAddress.h index d00127ec..89a343e1 100644 --- a/cpp/arduino/IPAddress.h +++ b/cpp/arduino/IPAddress.h @@ -7,12 +7,12 @@ class IPAddress { union { uint8_t bytes[4]; uint32_t dword; - operator uint8_t* () const { return (uint8_t*) bytes; } + operator uint8_t *() const { return (uint8_t *)bytes; } } _address; public: // Constructors - IPAddress() { IPAddress(0, 0, 0, 0); } + IPAddress() : IPAddress(0, 0, 0, 0) {} IPAddress(uint8_t octet1, uint8_t octet2, uint8_t octet3, uint8_t octet4) { _address.bytes[0] = octet1; _address.bytes[1] = octet2; @@ -26,12 +26,11 @@ class IPAddress { _address.bytes[2] = bytes[2]; _address.bytes[3] = bytes[3]; } - - IPAddress(unsigned long dword) { _address.dword = (uint32_t) dword; } + IPAddress(unsigned long dword) { _address.dword = (uint32_t)dword; } // Accessors uint32_t asWord() const { return _address.dword; } - uint8_t *raw_address() { return _address.bytes; }; + uint8_t *raw_address() { return _address.bytes; } // Comparisons bool operator==(const IPAddress &rhs) const { diff --git a/cpp/arduino/Udp.h b/cpp/arduino/Udp.h index 50b99f57..87619ff8 100644 --- a/cpp/arduino/Udp.h +++ b/cpp/arduino/Udp.h @@ -6,4 +6,16 @@ class UDP : public Stream { protected: uint8_t *rawIPAddress(IPAddress &addr) { return addr.raw_address(); }; + +public: + UDP() { + // The Stream mock defines a String buffer but never puts anyting in it! + if (!mGodmodeDataIn) { + mGodmodeDataIn = new String; + } + } + virtual size_t write(uint8_t value) { + mGodmodeDataIn->concat(value); + return 1; + } }; From 15f9c517a61247b7f6793c0da05311590347de14 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 7 Nov 2020 19:42:17 -0800 Subject: [PATCH 05/10] Try different install script to see if we can get the NetworkLib SampleProject to pass the test. --- .travis.yml | 1 + SampleProjects/NetworkLib/scripts/install.sh | 10 +++++----- appveyor.yml | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3fae3865..693ca844 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,4 +29,5 @@ script: - bundle exec arduino_ci_remote.rb - cd ../NetworkLib - bundle install + - ./scripts/install.sh - bundle exec arduino_ci_remote.rb diff --git a/SampleProjects/NetworkLib/scripts/install.sh b/SampleProjects/NetworkLib/scripts/install.sh index 3f704c82..b3de41b3 100755 --- a/SampleProjects/NetworkLib/scripts/install.sh +++ b/SampleProjects/NetworkLib/scripts/install.sh @@ -1,7 +1,7 @@ #!/bin/bash -cd "$( dirname "${BASH_SOURCE[0]}" )" -cd ../src -rm -rf Ethernet > /dev/null 2>&1 -# get Ethernet library -git clone https://github.com/arduino-libraries/Ethernet.git +# if we don't have an Ethernet library, then get the standard one +cd $(bundle exec arduino_library_location.rb) +if [ ! -d ./Ethernet ] ; then + git clone https://github.com/arduino-libraries/Ethernet.git +fi diff --git a/appveyor.yml b/appveyor.yml index f50a989b..18e0704f 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,4 +27,5 @@ test_script: - bundle exec arduino_ci_remote.rb - cd ../NetworkLib - bundle install + - ./scripts/install.sh - bundle exec arduino_ci_remote.rb From dbedc31dcace89e36ab4283ee5f5234be3b941b9 Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 7 Nov 2020 19:49:43 -0800 Subject: [PATCH 06/10] Changes to install script invocation from CI tests. --- .travis.yml | 2 +- appveyor.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 693ca844..e3eb1372 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,5 +29,5 @@ script: - bundle exec arduino_ci_remote.rb - cd ../NetworkLib - bundle install - - ./scripts/install.sh + - scripts/install.sh - bundle exec arduino_ci_remote.rb diff --git a/appveyor.yml b/appveyor.yml index 18e0704f..a8901551 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,5 +27,5 @@ test_script: - bundle exec arduino_ci_remote.rb - cd ../NetworkLib - bundle install - - ./scripts/install.sh + - scripts/install.sh - bundle exec arduino_ci_remote.rb From 89df2cd365f4153ca43ffc57793a08b255c7593d Mon Sep 17 00:00:00 2001 From: James Foster Date: Sat, 7 Nov 2020 21:15:00 -0800 Subject: [PATCH 07/10] Trying to get library install to be part of CI script. --- .travis.yml | 4 +++- appveyor.yml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e3eb1372..0c7a575d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,5 +29,7 @@ script: - bundle exec arduino_ci_remote.rb - cd ../NetworkLib - bundle install - - scripts/install.sh + - cd scripts + - install.sh + - cd .. - bundle exec arduino_ci_remote.rb diff --git a/appveyor.yml b/appveyor.yml index a8901551..e062a4a2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -27,5 +27,7 @@ test_script: - bundle exec arduino_ci_remote.rb - cd ../NetworkLib - bundle install - - scripts/install.sh + - cd scripts + - install.sh + - cd .. - bundle exec arduino_ci_remote.rb From 65dd5e945981d8a864f802a30f36fddbb8b9d73a Mon Sep 17 00:00:00 2001 From: James Foster Date: Sun, 8 Nov 2020 22:04:45 -0800 Subject: [PATCH 08/10] Delete object in destructor. Try to debug Travis CI error. --- .travis.yml | 2 +- cpp/arduino/Client.h | 6 ++++++ cpp/arduino/Udp.h | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0c7a575d..9494e805 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,6 @@ script: - cd ../NetworkLib - bundle install - cd scripts - - install.sh + - bash -x ./install.sh - cd .. - bundle exec arduino_ci_remote.rb diff --git a/cpp/arduino/Client.h b/cpp/arduino/Client.h index 7b0b16af..b08e183e 100644 --- a/cpp/arduino/Client.h +++ b/cpp/arduino/Client.h @@ -10,6 +10,12 @@ class Client : public Stream { mGodmodeDataIn = new String; } } + ~Client() { + if (mGodmodeDataIn) { + delete mGodmodeDataIn; + mGodmodeDataIn = nullptr; + } + } virtual size_t write(uint8_t value) { mGodmodeDataIn->concat(value); return 1; diff --git a/cpp/arduino/Udp.h b/cpp/arduino/Udp.h index 87619ff8..8352f7f6 100644 --- a/cpp/arduino/Udp.h +++ b/cpp/arduino/Udp.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include class UDP : public Stream { protected: @@ -14,6 +14,12 @@ class UDP : public Stream { mGodmodeDataIn = new String; } } + ~UDP() { + if (mGodmodeDataIn) { + delete mGodmodeDataIn; + mGodmodeDataIn = nullptr; + } + } virtual size_t write(uint8_t value) { mGodmodeDataIn->concat(value); return 1; From 7cc29d407a7d6bcb90febe59361d3fd81c159d8a Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 9 Nov 2020 02:29:13 -0800 Subject: [PATCH 09/10] Fix compiler warning such that non-void function now returns a value. --- SampleProjects/TestSomething/test/clientServer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SampleProjects/TestSomething/test/clientServer.cpp b/SampleProjects/TestSomething/test/clientServer.cpp index 43e0e8c1..f088c821 100644 --- a/SampleProjects/TestSomething/test/clientServer.cpp +++ b/SampleProjects/TestSomething/test/clientServer.cpp @@ -62,7 +62,10 @@ unittest(Printable) { class TestServer : public Server { public: uint8_t data; - virtual size_t write(uint8_t value) { data = value; }; + virtual size_t write(uint8_t value) { + data = value; + return 1; + }; }; unittest(Server) { From a892a17bb14ab30f854e0f87c8c18d53d599c491 Mon Sep 17 00:00:00 2001 From: James Foster Date: Tue, 10 Nov 2020 20:10:16 -0800 Subject: [PATCH 10/10] Update install.sh Clarify comment to explain why we want to install a customer library if one isn't present. --- SampleProjects/NetworkLib/scripts/install.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SampleProjects/NetworkLib/scripts/install.sh b/SampleProjects/NetworkLib/scripts/install.sh index b3de41b3..c4eb0517 100755 --- a/SampleProjects/NetworkLib/scripts/install.sh +++ b/SampleProjects/NetworkLib/scripts/install.sh @@ -1,6 +1,7 @@ #!/bin/bash -# if we don't have an Ethernet library, then get the standard one +# if we don't have an Ethernet library already (say, in new install or for an automated test), +# then get the custom one we want to use for testing cd $(bundle exec arduino_library_location.rb) if [ ! -d ./Ethernet ] ; then git clone https://github.com/arduino-libraries/Ethernet.git