Skip to content

Commit

Permalink
Merge pull request #2 from bxparks/develop
Browse files Browse the repository at this point in the history
version v0.1.1
  • Loading branch information
bxparks committed Mar 16, 2018
2 parents fd8c4a7 + 207d9e3 commit 838ea16
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 32 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
@@ -1,4 +1,9 @@
# Changelog

* 0.1.0 (2018-03-12)
* v0.1.1 (2018-03-15)
* Fix small bug with Test::setPassOrFail() which caused assertXxx()
macros which returned true to terminate the testing() test cases.
* v0.1.0 (2018-03-15)
* First merge into 'master' branch and tagged.
* (2018-03-12)
* Initial upload to GitHub.
18 changes: 14 additions & 4 deletions README.md
Expand Up @@ -456,6 +456,16 @@ The following methods from ArduinoUnit are not yet implemented:
* `assertTestSkip(name)`
* `assertTestNotSkip(name)`

### Smaller Test Runner Loop Chunks

In ArduinoUnit, each call to `Test::run()` will process the entire list of
currently active test cases. In AUnit, each call to `TestRunner::run()` will
process just one test case and return. I chose to break up the
`TestRunner::run()` method into smaller pieces to allow the `loop()` method to
return to the system more frequently. This is especially important on the
ESP8266 platform where system must get some periodic CPU cycles to perform its
own tasks.

### Assertion Parameters Omitted in Messages

The various `assertXxx()` macros in AUnit print a slightly shorter
Expand Down Expand Up @@ -541,19 +551,19 @@ microcontrollers:
```
Platform (resource) | Max | ArduinoUnit | AUnit |
---------------------------+---------+-------------+-------------|
Arduino Nano (flash) | 30720 | 54038 | 18412 |
Arduino Nano (flash) | 30720 | 54038 | 18418 |
Arduino Nano (static) | 2048 | 1061 | 908 |
---------------------------+---------+-------------+-------------|
Teensy LC (flash) | 63488 | 36196 | 25104 |
Teensy LC (flash) | 63488 | 36196 | 25096 |
Teensy LC (static) | 8192 | 2980 | 2768 |
---------------------------+---------+-------------+-------------|
Teensy 3.2 (flash) | 262144 | 51236 | 36136 |
Teensy 3.2 (static) | 65536 | 5328 | 5224 |
---------------------------+---------+-------------+-------------|
ESP8266 - ESP-12E (flash) | 1044464 | does not | 267375 |
ESP8266 - ESP-12E (flash) | 1044464 | does not | 267359 |
ESP8266 - ESP-12E (static) | 81920 | compile | 34564 |
---------------------------+---------+-------------+-------------|
ESP8266 - ESP-01 (flash) | 499696 | does not | 267375 |
ESP8266 - ESP-01 (flash) | 499696 | does not | 267359 |
ESP8266 - ESP-01 (static) | 47356 | compile | 34564 |
---------------------------+---------+-------------+-------------|
```
Expand Down
2 changes: 1 addition & 1 deletion library.properties
@@ -1,5 +1,5 @@
name=AUnit
version=0.1.0
version=0.1.1
author=Brian T. Park
maintainer=Brian T. Park <brian@xparks.net>
sentence=A unit testing framework for Arduino platforms inspired by ArduinoUnit.
Expand Down
2 changes: 1 addition & 1 deletion src/AUnit.h
Expand Up @@ -33,6 +33,6 @@ SOFTWARE.
#include "aunit/Assertion.h"

// Version format: 010203 == "1.2.3"
#define AUNIT_VERSION 000100
#define AUNIT_VERSION 000101

#endif
30 changes: 12 additions & 18 deletions src/aunit/Compare.cpp
Expand Up @@ -171,20 +171,17 @@ int compareString(const __FlashStringHelper* a, const char* b) {
return -strcmp_P(b, (const char*) a);
}

// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
// optimizing for 4-byte alignment here.
int compareString(const __FlashStringHelper* a, const __FlashStringHelper* b) {
const char* aa = reinterpret_cast<const char*>(a);
const char* bb = reinterpret_cast<const char*>(b);

// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
// optimizing for 4-byte alignment here.
while (true) {
char ca = pgm_read_byte(aa);
char cb = pgm_read_byte(bb);
if (ca < cb) return -1;
if (ca > cb) return 1;
// we hit this condition only if both strings are the same length,
// so no need to check both strings for '\0'
uint8_t ca = pgm_read_byte(aa);
uint8_t cb = pgm_read_byte(bb);
if (ca != cb) return (int) ca - (int) cb;
if (ca == '\0') return 0;
aa++;
bb++;
Expand Down Expand Up @@ -225,21 +222,18 @@ int compareStringN(const __FlashStringHelper* a, const char* b, size_t n) {
return -strncmp_P(b, (const char*)a, n);
}

// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
// optimizing for 4-byte alignment here.
int compareStringN(const __FlashStringHelper* a, const __FlashStringHelper* b,
size_t n) {
const char* aa = reinterpret_cast<const char*>(a);
const char* bb = reinterpret_cast<const char*>(b);

// On ESP8266, pgm_read_byte() already takes care of 4-byte alignment, and
// memcpy_P(s, p, 4) makes 4 calls to pgm_read_byte() anyway, so don't bother
// optimizing for 4-byte alignment here.
while (n > 0) {
char ca = pgm_read_byte(aa);
char cb = pgm_read_byte(bb);
if (ca < cb) return -1;
if (ca > cb) return 1;
// we hit this condition only if both strings are the same length,
// so no need to check both strings for '\0'
uint8_t ca = pgm_read_byte(aa);
uint8_t cb = pgm_read_byte(bb);
if (ca != cb) return (int) ca - (int) cb;
if (ca == '\0') return 0;
aa++;
bb++;
Expand Down
8 changes: 8 additions & 0 deletions src/aunit/FCString.h
Expand Up @@ -38,6 +38,14 @@ namespace aunit {
* outside a function, it can only be used inside a function, so we are forced
* to use normal c-strings instead of F() strings when manually creating Test or
* TestOnce instances.
*
* I deliberately decided not to inherit from Printable. While it is convenient
* to be able to call Print::print() with an instance of this class, the cost
* is 2 (AVR) or 4 (Teensy-ARM or ESP8266) extra bytes of static memory for the
* v-table pointer for each instance. But each instance is only 3 (AVR) or 5
* (Teensy-ARM or ESP8266) bytes big, so the cost of 50-100 bytes of static
* memory for a large suite of 25 unit tests does not seem worth the minor
* convenience.
*/
class FCString {
public:
Expand Down
6 changes: 5 additions & 1 deletion src/aunit/Test.cpp
Expand Up @@ -49,8 +49,12 @@ Test::Test(const __FlashStringHelper* name):
insert();
}

// Resolve the status as kStatusFailed only if ok == false. Otherwise, keep the
// status as kStatusSetup to allow testing() test cases to continue.
void Test::setPassOrFail(bool ok) {
mStatus = (ok) ? kStatusPassed : kStatusFailed;
if (!ok) {
mStatus = kStatusFailed;
}
}

// Insert the current test case into the singly linked list, sorted by
Expand Down
12 changes: 6 additions & 6 deletions tests/AUnitTest/AUnitTest.ino
Expand Up @@ -325,29 +325,29 @@ test(flashString) {

testing(looping_skip) {
static int count = 0;
// a successful assetXxx() should not terminate a testing() early
assertLess(count, 3);
count++;
Serial.print(F("looping_skip: iteration "));
Serial.println(count);
if (count >= 3) {
skip();
}
}

testing(looping_fail) {
static int count = 0;
// a successful assetXxx() should not terminate a testing() early
assertLess(count, 3);
count++;
Serial.print(F("looping_fail: iteration "));
Serial.println(count);
if (count >= 3) {
fail();
}
}

testing(looping_pass) {
static int count = 0;
// a successful assetXxx() should not terminate a testing() early
assertLess(count, 3);
count++;
Serial.print(F("looping_pass: iteration "));
Serial.println(count);
if (count >= 3) {
pass();
}
Expand Down

0 comments on commit 838ea16

Please sign in to comment.