Skip to content

Commit

Permalink
convert CI to arduino_ci module
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfixes committed Mar 7, 2018
1 parent df5b995 commit 1bb592b
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
compile:
platforms:
- uno
- leonardo

unittest:
platforms:
- uno
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.skip

examples/FONA_SMS_Response/.esp8266.test.skip
unittest*.bin
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: c
sudo: false
before_install:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
language: ruby
script:
- build_main_platforms
- bundle install
- bundle exec arduino_ci_remote.rb
notifications:
email:
on_success: change
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci', '~> 0.1.6'
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
GEM
remote: https://rubygems.org/
specs:
arduino_ci (0.1.6)
os (~> 1.0)
os (1.0.0)

PLATFORMS
ruby

DEPENDENCIES
arduino_ci (~> 0.1.6)

BUNDLED WITH
1.16.0
Empty file.
Empty file.
Binary file removed examples/FONAtest_KEY_mod.zip
Binary file not shown.
Empty file removed examples/GPS/.esp8266.test.skip
Empty file.
Empty file.
113 changes: 113 additions & 0 deletions test/comms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <ArduinoUnitTests.h>
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <ci/DeviceUsingBytes.h>
#include "../Adafruit_FONA.h"

#define FONA_RX 2
#define FONA_TX 3
#define FONA_RST 4

bool bigEndian = false; // RS232 says so

// DeviceUsingBytes extends DataStreamObserver,
// so we will be able to attach this class to an
// ObservableDataStream object, of which the pin
// history (soft-serial) and HardwareSerial
// objects are.
class FakeFona : public DeviceUsingBytes {
public:
String mLast;

FakeFona() : DeviceUsingBytes() {
mLast = "";
addResponseCRLF("AT", "OK");
addResponseCRLF("ATE0", "OK");
addResponseCRLF("AT+CVHU=0", "OK");
addResponseCRLF("ATI", "OK");
addResponseCRLF("AT+CPMS=\"SM\",\"SM\",\"SM\"", "OK");
addResponseCRLF("AT+GSN", "1234567890abcde\r\nOK");
}

virtual ~FakeFona() {}

virtual void onMatchInput(String output) {
mLast = output;
state->digitalPin[FONA_TX].fromAscii(output, bigEndian);
}
};


class Adafruit_FONA_debug : public Adafruit_FONA {
public:
Adafruit_FONA_debug(int8_t r) : Adafruit_FONA(r) {}


String debug_replybuffer() const {
return String(replybuffer);
}

uint8_t debug_readline(uint16_t timeout = FONA_DEFAULT_TIMEOUT_MS, boolean multiline = false) { return readline(timeout, multiline); }

};

unittest(ARDUINO_100)
{
assertEqual(100, ARDUINO);
}

// basic test of the readline capability
unittest(fona_readline) {

GodmodeState* state = GODMODE();
state->reset();

Adafruit_FONA_debug fona = Adafruit_FONA_debug(FONA_RST);
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
fonaSerial->begin(115200);
fona.begin(*fonaSerial);

assertTrue(fonaSS.isListening());

assertEqual(0, fonaSS.available());
state->digitalPin[FONA_TX].fromAscii("You were over the line, Smokey\nMark it 8, Dude", bigEndian);
assertNotEqual(0, fonaSS.available());

uint8_t rl = fona.debug_readline(300, false);
assertNotEqual(0, rl);
assertEqual("You were over the line, Smokey", fona.debug_replybuffer());
}

// retrieve the IMEI from a serial device faked by the FakeFona class
unittest(fona_imei) {

GodmodeState* state = GODMODE();
state->reset();

// set up FONA on serial port
Adafruit_FONA_debug fona = Adafruit_FONA_debug(FONA_RST);
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
fonaSerial->begin(115200);

// set up our fake modem on the other end.
// note that the digitalPin we attach to is an ObservableDataStream
FakeFona fakeFona;
fakeFona.attach(&state->digitalPin[FONA_RX]);

// fire it up
assertTrue(fona.begin(*fonaSerial));

// These asserts will just dump out the input/output log as a test failure
// assertEqual("", state->digitalPin[FONA_RX].toAscii(1, bigEndian));
// assertEqual("", state->digitalPin[FONA_TX].toAscii(1, bigEndian));

char imei[16] = {0}; // MUST use a 16 character buffer for IMEI!
uint8_t imeiLen = fona.getIMEI(imei);
assertNotEqual(0, imeiLen);
//assertEqual("AT+GSN\n", state->digitalPin[FONA_RX].toAscii(1, bigEndian));
assertEqual("1234567890abcde", imei);
}

unittest_main()

0 comments on commit 1bb592b

Please sign in to comment.