Skip to content

Commit 92930c5

Browse files
authored
Merge pull request #19 from ifreecarve/2018-02-19_mocks
More mocks
2 parents fceda77 + be84144 commit 92930c5

File tree

323 files changed

+1239
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

323 files changed

+1239
-236
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ vendor
1414

1515
# C++ stuff
1616
*.bin
17+
*.bin.dSYM

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ script:
1414
- bundle exec rubocop --version
1515
- bundle exec rubocop -D .
1616
- bundle exec rspec
17-
- cd SampleProjects/DoSomething
17+
- cd SampleProjects/TestSomething
1818
- bundle install
1919
- bundle exec arduino_ci_remote.rb

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,24 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
66

77
## [Unreleased]
88
### Added
9+
- Yaml files can have either `.yml` or `.yaml` extensions
10+
- Yaml files support select/reject critera for paths of unit tests for targeted testing
11+
- Pins now track history and can report it in Ascii (big- or little-endian) for digital sequences
12+
- Pins now accept an array (or string) of input bits for providing pin values across multiple reads
13+
- SoftwareSerial. That took a while.
914

1015
### Changed
16+
- Unit test executables print to STDERR just in case there are segfaults. Uh, just in case I ever write any.
1117

1218
### Deprecated
1319

1420
### Removed
1521

1622
### Fixed
23+
- OSX no longer experiences `javax.net.ssl.SSLKeyException: RSA premaster secret error` messages when downloading board package files
24+
- `arduino_ci_remote.rb` no longer makes unnecessary changes to the board being tested
25+
- Scripts no longer crash if there is no `test/` directory
26+
- Scripts no longer crash if there is no `examples/` directory
1727

1828
### Security
1929

README.md

Lines changed: 155 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ script:
2828
2929
That's literally all there is to it on the repository side. You'll need to go to https://travis-ci.org/profile/ and enable testing for your Arduino project. Once that happens, you should be all set. The script will test all example projects of the library and all unit tests.
3030
31+
> **Note:** `arduino_ci_remote.rb` expects to be run from the root directory of your Arduino project library.
32+
3133
### Unit tests in `test/`
3234

3335
All `.cpp` files in the `test/` directory of your Arduino library are assumed to contain unit tests. Each and every one will be compiled and executed on its own.
@@ -61,13 +63,77 @@ unittest(example_godmode_stuff)
6163
state->resetClock(); // - you can reset just the clock (to zero)
6264
state->resetPins(); // - or just the pins
6365
state->micros = 1; // manually set the clock such that micros() returns 1
64-
state->digitalPin[4]; // stores the commanded state of digital pin 4
66+
state->digitalPin[4]; // tells you the commanded state of digital pin 4
6567
state->digitalPin[4] = HIGH; // digitalRead(4) will now return HIGH
66-
state->analogPin[3]; // stores the commanded state of analog pin 3
68+
state->analogPin[3]; // tells you the commanded state of analog pin 3
6769
state->analogPin[3] = 99; // analogRead(3) will now return 99
6870
}
6971
```
7072

73+
Of course, it's possible that your code might flip the bit more than once in a function. For that scenario, you may want to examine the history of a pin's commanded outputs:
74+
75+
```C++
76+
unittest(pin_history)
77+
{
78+
GodmodeState* state = GODMODE();
79+
int myPin = 3;
80+
state->reset(); // pin will start LOW
81+
digitalWrite(myPin, HIGH);
82+
digitalWrite(myPin, LOW);
83+
digitalWrite(myPin, LOW);
84+
digitalWrite(myPin, HIGH);
85+
digitalWrite(myPin, HIGH);
86+
87+
assertEqual(6, state->digitalPin[1].size());
88+
bool expected[6] = {LOW, HIGH, LOW, LOW, HIGH, HIGH};
89+
bool actual[6];
90+
91+
// move history queue into an array because at the moment, reading
92+
// the history is destructive -- it's a linked-list queue. this
93+
// means that if toArray or hasElements fails, the queue will be in
94+
// an unknown state and you should reset it before continuing with
95+
// other tests
96+
int numMoved = state->digitalPin[myPin].toArray(actual, 6);
97+
assertEqual(6, numMoved);
98+
99+
// verify each element
100+
for (int i = 0; i < 6; ++i) {
101+
assertEqual(expected[i], actual[i]);
102+
}
103+
```
104+
105+
Reading the pin more than once per function is also a possibility. In that case, we want to queue up a few values for the `digitalRead` or `analogRead` to find.
106+
107+
```C++
108+
unittest(pin_read_history)
109+
{
110+
GodmodeState* state = GODMODE();
111+
state->reset();
112+
113+
int future[6] = {33, 22, 55, 11, 44, 66};
114+
state->analogPin[1].fromArray(future, 6);
115+
for (int i = 0; i < 6; ++i)
116+
{
117+
assertEqual(future[i], analogRead(1));
118+
}
119+
120+
// for digital pins, we have the added possibility of specifying
121+
// a stream of input bytes encoded as ASCII
122+
bool bigEndian = true;
123+
state->digitalPin[1].fromAscii("Yo", bigEndian);
124+
125+
// digitial history as serial data, big-endian
126+
bool expectedBits[16] = {
127+
0, 1, 0, 1, 1, 0, 0, 1, // Y
128+
0, 1, 1, 0, 1, 1, 1, 1 // o
129+
};
130+
131+
for (int i = 0; i < 16; ++i) {
132+
assertEqual(expectedBits[i], digitalRead(1));
133+
}
134+
}
135+
```
136+
71137
A more complicated example: working with serial port IO. Let's say I have the following function:
72138

73139
```C++
@@ -125,6 +191,93 @@ unittest(two_flips)
125191
}
126192
```
127193

194+
195+
196+
197+
Finally, there are some cases where you want to use a pin as a serial port. There are history functions for that too.
198+
199+
```C++
200+
int myPin = 3;
201+
202+
// digitial history as serial data, big-endian
203+
bool bigEndian = true;
204+
bool binaryAscii[24] = {
205+
0, 1, 0, 1, 1, 0, 0, 1, // Y
206+
0, 1, 1, 0, 0, 1, 0, 1, // e
207+
0, 1, 1, 1, 0, 0, 1, 1 // s
208+
};
209+
210+
// "send" these bits
211+
for (int i = 0; i < 24; digitalWrite(myPin, binaryAscii[i++]));
212+
213+
// The first bit in the history is the initial value, which we will ignore
214+
int offset = 1;
215+
216+
// We should be able to parse the bits as ascii
217+
assertEqual("Yes", state->digitalPin[myPin].toAscii(offset, bigEndian));
218+
```
219+
220+
## Overriding default build behavior
221+
222+
You can add `.arduino-ci.yml` files to the project directory (which will then apply to both `test/` and `examples/`), as well as to the `test/` directory and each example directory in `examples/`. All defined fields can be overridden.
223+
224+
You may define new platforms, or edit existing platform definitions:
225+
226+
```yaml
227+
platforms:
228+
bogo:
229+
board: fakeduino:beep:bogo
230+
package: potato:salad
231+
gcc:
232+
features:
233+
- omit-frame-pointer # becomes -fomit-frame-pointer flag
234+
defines:
235+
- HAVE_THING # becomes -DHAVE_THING flag
236+
warnings:
237+
- no-implicit # becomes -Wno-implicit flag
238+
flags:
239+
- -foobar # becomes -foobar flag
240+
241+
zero: ~ # undefines the `zero` board completely
242+
243+
esp8266: # redefines the existing esp8266
244+
board: esp8266:esp8266:booo
245+
package: esp8266:esp8266
246+
gcc:
247+
features:
248+
defines:
249+
warnings:
250+
flags:
251+
```
252+
253+
254+
For your example programs, you may set external libraries to be installed and included. You may also choose the platforms on which the compilation will be attempted:
255+
256+
```yaml
257+
compile:
258+
libraries:
259+
- "Adafruit FONA Library"
260+
platforms:
261+
- esp8266
262+
```
263+
264+
265+
For your unit tests, in addition to setting specific libraries and platforms, you may filter the list of test files that are compiled and tested. This may help speed up targeted testing.
266+
267+
```yaml
268+
unittest:
269+
testfiles:
270+
select:
271+
- "*-*.*"
272+
reject:
273+
- "sam-squamsh.*"
274+
libraries:
275+
- "abc123"
276+
- "def456"
277+
platforms:
278+
- bogo
279+
```
280+
128281
## More Documentation
129282
130283
This software is in alpha. But [SampleProjects/DoSomething](SampleProjects/DoSomething) has a decent writeup and is a good bare-bones example of all the features.
@@ -133,7 +286,6 @@ This software is in alpha. But [SampleProjects/DoSomething](SampleProjects/DoSo
133286
134287
* The Arduino library is not fully mocked.
135288
* I don't have preprocessor defines for all the Arduino board flavors
136-
* Arduino Zero boards don't work in CI. I'm confused.
137289
* https://github.com/ifreecarve/arduino_ci/issues
138290
139291
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
unittest:
2+
platforms:
3+
- uno
4+
- due

0 commit comments

Comments
 (0)