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

Use `arduino_ci` to run unit tests as part of git pull requests (not just tests of compilation) #91

Open
wants to merge 2 commits into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -0,0 +1,8 @@
compile:
platforms:
- uno
- leonardo

unittest:
platforms:
- uno
@@ -4,3 +4,4 @@
*.skip

examples/FONA_SMS_Response/.esp8266.test.skip
unittest*.bin
@@ -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
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci', '~> 0.1.6'
@@ -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
No changes.
No changes.
Binary file not shown.
No changes.
No changes.
@@ -30,7 +30,8 @@

#if (ARDUINO >= 100)
#include "Arduino.h"
#if !defined(__SAM3X8E__) && !defined(ARDUINO_ARCH_SAMD) // Arduino Due doesn't support #include <SoftwareSerial.h>
#if !defined(__SAM3X8E__) && !defined(ARDUINO_ARCH_SAMD) // Arduino Due doesn't support
#include <SoftwareSerial.h>
#endif
#else
#include "WProgram.h"
@@ -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()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.