-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic unit testing using Travis + arduino_ci
- Loading branch information
1 parent
fd9c0b5
commit 7c69d18
Showing
5 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
compile: | ||
platforms: | ||
- due | ||
|
||
unittest: | ||
platforms: | ||
- due |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# arduino_ci unit test files | ||
*.bin | ||
*.bin.dSYM | ||
|
||
# arduino_ci ruby bundle lockfile | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
sudo: false | ||
language: ruby | ||
|
||
script: | ||
- bundle install | ||
- bundle exec arduino_ci_remote.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
source 'https://rubygems.org' | ||
gem 'arduino_ci', '~> 0.1.16' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
#include <ArduinoUnitTests.h> | ||
#include "../OneWire.h" | ||
|
||
#define PIN 10 | ||
|
||
unittest(crc8) | ||
{ | ||
byte seq1[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
byte seq2[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; | ||
byte seq3[8] = { 0, 10, 20, 30, 40, 50, 60, 70 }; | ||
|
||
assertEqual(0, (int)OneWire::crc8(seq1, 7)); | ||
|
||
assertEqual(216, (int)OneWire::crc8(seq2, 4)); | ||
assertEqual(244, (int)OneWire::crc8(seq2, 5)); | ||
assertEqual( 42, (int)OneWire::crc8(seq2, 6)); | ||
assertEqual(128, (int)OneWire::crc8(seq2, 7)); | ||
|
||
assertEqual( 63, (int)OneWire::crc8(seq3, 4)); | ||
assertEqual( 30, (int)OneWire::crc8(seq3, 5)); | ||
assertEqual(128, (int)OneWire::crc8(seq3, 6)); | ||
assertEqual(145, (int)OneWire::crc8(seq3, 7)); | ||
} | ||
|
||
unittest(crc16) | ||
{ | ||
byte seq1[16] = { | ||
0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0 | ||
}; | ||
|
||
byte seq2[16] = { | ||
0xF0, 0xF1, 0xF2, 0xF3, | ||
0xF4, 0xF5, 0xF6, 0xF7, | ||
0xF8, 0xF9, 0xFA, 0xFB, | ||
0xFC, 0xFD, 0xFE, 0xFF | ||
}; | ||
|
||
assertEqual(0, (int)OneWire::crc16(seq1, 11)); | ||
|
||
assertEqual(55581, (int)OneWire::crc16(seq2, 11)); | ||
assertEqual(35416, (int)OneWire::crc16(seq2, 12)); | ||
assertEqual(48011, (int)OneWire::crc16(seq2, 13)); | ||
assertEqual(58938, (int)OneWire::crc16(seq2, 14)); | ||
} | ||
|
||
unittest(no_pin_noise_on_init) | ||
{ | ||
GodmodeState* state = GODMODE(); | ||
state->reset(); | ||
|
||
int initalHistorySize = state->digitalPin[PIN].historySize(); | ||
OneWire ow(PIN); | ||
assertEqual(initalHistorySize, state->digitalPin[PIN].historySize()); | ||
} | ||
|
||
unittest(failed_search) | ||
{ | ||
GodmodeState* state = GODMODE(); | ||
state->reset(); | ||
|
||
OneWire ow(PIN); | ||
byte addr[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
assertFalse(ow.search(addr)); // this had better fail; we mocked nothing | ||
assertEqual(0, (int)OneWire::crc8(addr, 7)); // should take no data | ||
} | ||
|
||
unittest(write_a_0) | ||
{ | ||
GodmodeState* state = GODMODE(); | ||
bool actual[5]; // to store actual values written to pin | ||
|
||
state->reset(); | ||
|
||
// write a zero and verify | ||
OneWire ow(PIN); | ||
ow.write_bit(0); | ||
assertEqual(3, state->digitalPin[PIN].historySize()); | ||
state->digitalPin[PIN].toArray(actual, 5); | ||
assertEqual(LOW, actual[1]); | ||
assertEqual(HIGH, actual[2]); | ||
|
||
// same thing but for writing a 1 | ||
state->reset(); | ||
ow.write_bit(1); | ||
assertEqual(3, state->digitalPin[PIN].historySize()); | ||
state->digitalPin[PIN].toArray(actual, 5); | ||
assertEqual(LOW, actual[1]); | ||
assertEqual(HIGH, actual[2]); | ||
|
||
// in future versions of arduino_ci, we can add timestamps to the history queues | ||
// https://github.com/ianfixes/arduino_ci/issues/23 | ||
} | ||
|
||
unittest(write_a_byte_no_power) | ||
{ | ||
GodmodeState* state = GODMODE(); | ||
OneWire ow(PIN); | ||
|
||
// without power | ||
state->reset(); | ||
ow.write(0xAC, 0); | ||
assertEqual(18, state->digitalPin[PIN].historySize()); | ||
bool expected[18] = { | ||
LOW, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, // 8 of these | ||
LOW | ||
}; | ||
bool actual[18]; | ||
|
||
// convert history queue into an array so we can verify it. | ||
state->digitalPin[PIN].toArray(actual, 18); | ||
|
||
// verify each element | ||
for (int i = 0; i < 18; ++i) { | ||
assertEqual(expected[i], actual[i]); | ||
} | ||
} | ||
|
||
// and now a blatant copy-paste | ||
unittest(write_a_byte_with_power) | ||
{ | ||
GodmodeState* state = GODMODE(); | ||
OneWire ow(PIN); | ||
|
||
// without power | ||
state->reset(); | ||
ow.write(0xAC, 1); | ||
assertEqual(17, state->digitalPin[PIN].historySize()); | ||
bool expected[17] = { | ||
LOW, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, | ||
LOW, HIGH, // 8 of these. power stays on -- high | ||
}; | ||
bool actual[17]; | ||
|
||
// convert history queue into an array so we can verify it. | ||
int copied = state->digitalPin[PIN].toArray(actual, 17); | ||
assertEqual(17, copied); | ||
|
||
// verify each element | ||
for (int i = 0; i < copied; ++i) { | ||
assertEqual(expected[i], actual[i]); | ||
} | ||
} | ||
|
||
|
||
unittest_main() |