You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+155-3Lines changed: 155 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@ script:
28
28
29
29
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.
30
30
31
+
> **Note:** `arduino_ci_remote.rb` expects to be run from the root directory of your Arduino project library.
32
+
31
33
### Unit tests in `test/`
32
34
33
35
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.
state->resetClock(); // - you can reset just the clock (to zero)
62
64
state->resetPins(); // - or just the pins
63
65
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
65
67
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
67
69
state->analogPin[3] = 99; // analogRead(3) will now return 99
68
70
}
69
71
```
70
72
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:
// 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
+
71
137
A more complicated example: working with serial port IO. Let's say I have the following function:
72
138
73
139
```C++
@@ -125,6 +191,93 @@ unittest(two_flips)
125
191
}
126
192
```
127
193
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
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
+
128
281
## More Documentation
129
282
130
283
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
133
286
134
287
* The Arduino library is not fully mocked.
135
288
* I don't have preprocessor defines for all the Arduino board flavors
136
-
* Arduino Zero boards don't work in CI. I'm confused.
0 commit comments