Skip to content

Commit d79667e

Browse files
authored
Merge pull request #52 from bxparks/develop
1.3.1 - support SAMD21 and ATmega2560 boards; split off UnixHostDuino; set exit status code
2 parents 546ca73 + d55ca82 commit d79667e

Some content is hidden

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

46 files changed

+313
-2967
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22

33
* Unreleased
4+
* Add `examples/AUnitPlatformIO` to verify that AUnit works on PlatformIO.
5+
* Rename unitduino to UnixHostDuino and move to its own repository at
6+
`https://github.com/bxparks/UnixHostDuino`.
7+
* Add UnixHostDuino Makefile to all unit tests.
8+
* Support SAMD21 and ATmega2560 boards.
9+
* Call `exit(1)` upon failure or timeout, `exit(0)` upon success when using
10+
UnixHostDuino (#51).
411
* 1.3 (2019-06-15)
512
* Remove direct creation of `String` object, removing last remaining dynamic
613
allocation of heap memory from library.

README.md

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,39 @@ The AUniter tools have been integrated into the [Jenkins](https://jenkins.io)
12831283
continuous integration service. See details in
12841284
[Continuous Integration with Jenkins](https://github.com/bxparks/AUniter/tree/develop/jenkins).
12851285

1286+
### UnixHostDuino
1287+
1288+
AUnit unit tests can often be compiled and executed natively on Linux or MacOS
1289+
machines using the [UnixHostDuino](https://github.com/bxparks/UnixHostDuino)
1290+
library because most unit tests depend on just the `Serial` port (which
1291+
UnixHostDuino binds to `stdout` and `stdin`).
1292+
1293+
The [unit tests for AUnit itself](tests) have all been upgraded to run
1294+
under UnixHostDuino. Here are a few tips when writing unit tests
1295+
to run under UnixHostDuino:
1296+
1297+
**Delay(1000)**
1298+
1299+
For real Arduino boards, you get more reliable unit tests if you add a
1300+
`delay(1000)` at the start of the program. For UnixHostDuino, this is not
1301+
necessary, so I recommend calling this only on real Arduino boards, like this:
1302+
```C++
1303+
void setup() {
1304+
#ifdef ARDUINO
1305+
delay(1000); // Wait for stability on some boards, otherwise garage on Serial
1306+
#endif
1307+
...
1308+
```
1309+
1310+
**Exit() Status Code**
1311+
1312+
On real Arduino boards, the unit test (or any program for that matter) never
1313+
terminates. The `loop()` function executes forever. On Linux or MacOS using
1314+
UnixHostDuino, the test program will terminate at the end through the
1315+
`exit()` function. If the tests are successful (i.e. passing or skipped), it
1316+
will call `exit(0)`. If there are any failing tests (i.e. failed or timed out),
1317+
it will call `exit(1)`.
1318+
12861319
## Tips
12871320
12881321
Collection of useful tidbits.
@@ -1500,28 +1533,40 @@ See [CHANGELOG.md](CHANGELOG.md).
15001533
15011534
## System Requirements
15021535
1536+
### Tool Chain
1537+
15031538
This library was developed and tested using:
1504-
* [Arduino IDE 1.8.5](https://www.arduino.cc/en/Main/Software)
1505-
* [Teensyduino 1.41](https://www.pjrc.com/teensy/td_download.html)
1506-
* [ESP8266 Arduino Core 2.4.1](https://arduino-esp8266.readthedocs.io/en/2.4.1/)
1507-
* [arduino-esp32](https://github.com/espressif/arduino-esp32)
1539+
* [Arduino IDE 1.8.9](https://www.arduino.cc/en/Main/Software)
1540+
* [Arduino AVR Boards 1.6.23](https://github.com/arduino/ArduinoCore-avr)
1541+
* [Arduino SAMD Boards 1.8.3](https://github.com/arduino/ArduinoCore-samd)
1542+
* [SparkFun AVR Boards 1.1.12](https://github.com/sparkfun/Arduino_Boards)
1543+
* [SparkFun SAMD Boards 1.6.2](https://github.com/sparkfun/Arduino_Boards)
1544+
* [ESP8266 Arduino 2.5.2](https://github.com/esp8266/Arduino)
1545+
* [ESP32 Arduino 1.0.2](https://github.com/espressif/arduino-esp32)
1546+
* [Teensydino 1.46](https://www.pjrc.com/teensy/td_download.html)
1547+
1548+
It should work with [PlatformIO](https://platformio.org/) but I have
1549+
not tested it extensively.
15081550
1509-
I used MacOS 10.13.3 and Ubuntu 17.10 for most of my development.
1551+
### Operating System
15101552
1511-
The library is tested on the following hardware before each release:
1553+
I used MacOS 10.13.3 and Ubuntu 18.04 for most of my development.
1554+
1555+
### Hardware
1556+
1557+
The library is tested extensively on the following boards:
15121558
15131559
* Arduino Nano clone (16 MHz ATmega328P)
15141560
* SparkFun Pro Micro clone (16 MHz ATmega32U4)
1515-
* Teensy 3.2 (72 MHz ARM Cortex-M4)
15161561
* NodeMCU 1.0 clone (ESP-12E module, 80 MHz ESP8266)
1562+
* WeMos D1 Mini clone (ESP-12E module, 80 MHz ESP8266)
15171563
* ESP32 dev board (ESP-WROOM-32 module, 240 MHz dual core Tensilica LX6)
1564+
* SAMD21 M0 Mini board (Arduino Zero compatible, 48 MHz ARM Cortex-M0+)
15181565
15191566
I will occasionally test on the following hardware as a sanity check:
15201567
1521-
* Arduino UNO R3 clone (16 MHz ATmega328P)
1522-
* Arduino Pro Mini clone (16 MHz ATmega328P)
1523-
* Teensy LC (48 MHz ARM Cortex-M0+)
1524-
* ESP-01 (ESP-01 module, 80 MHz ESP8266)
1568+
* Teensy 3.2 (72 MHz ARM Cortex-M4)
1569+
* Mini Mega 2560 (Arduino Mega 2560 compatible, 16 MHz ATmega2560)
15251570
15261571
## License
15271572
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#line 2 "AUnitPlatformIO.ino"
2+
3+
#include <AUnit.h>
4+
5+
test(exampleTest) {
6+
assertEqual(3, 3);
7+
}
8+
9+
void setup() {
10+
#if ARDUINO
11+
delay(1000); // wait for stability on some boards to prevent garbage Serial
12+
#endif
13+
Serial.begin(115200); // ESP8266 default of 74880 not supported on Linux
14+
while(!Serial); // for the Arduino Leonardo/Micro only
15+
}
16+
17+
void loop() {
18+
aunit::TestRunner::run();
19+
}

examples/AUnitPlatformIO/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# See https://github.com/bxparks/UnixHostDuino for documentation about this
2+
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
3+
4+
APP_NAME := AUnitPlatformIO
5+
ARDUINO_LIBS := AUnit
6+
include ../../../UnixHostDuino/UnixHostDuino.mk

examples/AUnitPlatformIO/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# AUnit on PlatformIO
2+
3+
This is an example unit test that runs on the PlatformIO environment. Created to
4+
track down [AUnit#50](https://github.com/bxparks/AUnit/issues/50) where
5+
`UnixHostDuino/` directory seems to break PlatformIO because it tries to compile
6+
it. Unfortunately, I cannot reproduce it. This seems to work fine on my machine.
7+
8+
## Updating PlatformIO
9+
10+
Here are the various pio commands that I had to run to update
11+
PlatformIO:
12+
13+
```
14+
$ pio upgrade
15+
$ pio update
16+
$ pio lib update
17+
```
18+
19+
## Compile on All Environments
20+
21+
```
22+
$ pio run -t clean
23+
$ pio run
24+
```
25+
26+
## Upload and Monitor
27+
Here is the commnad to compile, upload and monitor the test to an Arduino Nano
28+
on /dev/ttyUSB0:
29+
30+
```
31+
$ pio run -e nano -t upload --upload-port /dev/ttyUSB0 && \
32+
pio device monitor -b 115200 -p /dev/ttyUSB0
33+
```
34+
35+
Here is the commnad to compile, upload and monitor the test to an ESP32
36+
on /dev/ttyUSB1:
37+
38+
```
39+
$ pio run -e esp32 -t upload --upload-port /dev/ttyUSB1 && \
40+
pio device monitor -b 115200 -p /dev/ttyUSB1
41+
```
42+
43+
## Compile and Run on Linux or MacOS
44+
45+
```
46+
$ make clean
47+
$ make
48+
$ ./AUnitPlatformIO.out
49+
```
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; http://docs.platformio.org/page/projectconf.html
10+
11+
[env:nano]
12+
platform = atmelavr
13+
board = nanoatmega328
14+
framework = arduino
15+
lib_deps = AUnit
16+
17+
[env:micro]
18+
platform = atmelavr
19+
board = leonardo
20+
framework = arduino
21+
lib_deps = AUnit
22+
23+
[env:esp32]
24+
platform = espressif32
25+
board = esp32dev
26+
framework = arduino
27+
lib_deps = AUnit
28+
upload_speed = 921600
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../AUnitPlatformIO.ino

src/aunit/Flash.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,29 @@ class __FlashStringHelper;
9595
#error Unsupported platform
9696
#endif
9797

98+
// Define SERIAL_PORT_MONITOR consistently. We should also rename this file to
99+
// something like "compat.h".
100+
#if defined(ARDUINO_SAMD_ZERO)
101+
// If have a real Arduino Zero and using the "Arduino/Genuino Zero (Native
102+
// USB Port)" configuration on the Arduino IDE, you may need to uncomment
103+
// the following to clobber SERIAL_PORT_MONITOR to point to the correct
104+
// SerialUSB.
105+
//
106+
// On the other hand, if you are using a SparkFun breakout board, or one of
107+
// the "SAMD21 M0 Mini" clones, you should be using the SparkFun SAMD Boards,
108+
// and selecting the "SparkFun SAMD21 Dev Breakout" or the "SparkFun SAMD21
109+
// Mini Breakout" settings, which will set the SERIAL_PORT_MONITOR macro
110+
// correctly to SerialUSB.
111+
#if 0
112+
#undef SERIAL_PORT_MONITOR
113+
#define SERIAL_PORT_MONITOR SerialUSB
114+
#endif
115+
#elif defined(ESP32)
116+
#if ! defined(SERIAL_PORT_MONITOR)
117+
#define SERIAL_PORT_MONITOR Serial
118+
#endif
119+
#elif defined(__linux__) or defined(__APPLE__)
120+
#define SERIAL_PORT_MONITOR Serial
121+
#endif
122+
98123
#endif

src/aunit/Printer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ SOFTWARE.
2323
*/
2424

2525
#include <Arduino.h> // Serial
26+
#include "Flash.h"
2627
#include "Printer.h"
2728

2829
namespace aunit {
2930

30-
Print* Printer::sPrinter = &Serial;
31+
Print* Printer::sPrinter = &SERIAL_PORT_MONITOR;
3132

3233
}

src/aunit/TestRunner.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,7 @@ void TestRunner::setLifeCycleMatchingPattern(const char* testClass,
8181
setLifeCycleMatchingPattern(fullPattern, lifeCycle);
8282
}
8383

84-
TestRunner::TestRunner():
85-
mCurrent(nullptr),
86-
mIsResolved(false),
87-
mIsSetup(false),
88-
mIsRunning(false),
89-
mVerbosity(Verbosity::kDefault),
90-
mCount(0),
91-
mPassedCount(0),
92-
mFailedCount(0),
93-
mSkippedCount(0),
94-
mStatusErrorCount(0),
95-
mTimeout(kTimeoutDefault) {}
84+
TestRunner::TestRunner() {}
9685

9786
void TestRunner::runTest() {
9887
setupRunner();
@@ -109,9 +98,9 @@ void TestRunner::runTest() {
10998
mEndTime = millis();
11099
resolveRun();
111100
mIsResolved = true;
112-
#ifndef ARDUINO
113-
exit(0);
114-
#endif
101+
#if UNIX_HOST_DUINO
102+
exit((mFailedCount || mExpiredCount) ? 1 : 0);
103+
#endif
115104
}
116105
return;
117106
}

0 commit comments

Comments
 (0)