From 6eee41a5fedc100afb8bfb32a433e860940d0336 Mon Sep 17 00:00:00 2001 From: James Foster Date: Mon, 5 Oct 2020 19:14:04 -0700 Subject: [PATCH 1/4] Update docs to explain purpose of SampleProjects (#156) - Update docs to explain purpose of SampleProjects and avoid impression that they are templates to be followed too closely. - Provide alternative `bundle install` command (the original one doesn't work on macOS 10.16). - Correct location for your project. --- README.md | 6 +++--- SampleProjects/DoSomething/test/README.md | 8 +++++--- SampleProjects/README.md | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 423a8c03..27b8ce5e 100644 --- a/README.md +++ b/README.md @@ -82,10 +82,10 @@ vendor ### Installing the Dependencies -Fulfilling the `arduino_ci` library dependency is as easy as running this command: - +Fulfilling the `arduino_ci` library dependency is as easy as running either of these two commands: ``` -$ bundle install +$ bundle install # adds packages to global library (may require admin rights) +$ bundle install --path vendor/bundle # adds packages to local library ``` diff --git a/SampleProjects/DoSomething/test/README.md b/SampleProjects/DoSomething/test/README.md index 6e099ec6..1c958086 100644 --- a/SampleProjects/DoSomething/test/README.md +++ b/SampleProjects/DoSomething/test/README.md @@ -1,7 +1,9 @@ -# Purpose +## Purpose -These files are designed to test the Ruby gem itself, such that its basic tasks of library installation and compilation can be verified. (i.e., use minimal C++ files -- feature tests for C++ unittest/arduino code belong in `../TestSomething/test/`). +These files are designed to test the testing framework (the Ruby gem) itself, library installation and compilation. (Feature tests for C++ unittest/arduino code belong in `../TestSomething/test/`.) ## Naming convention -Files in this directory are expected to have names that either contains "bad" if it is expected to fail or "good" if it is expected to pass. This provides a signal to `rspec` for how the code is expected to perform. +Files in this directory are given names that either contains "bad" (if it is expected to fail) or "good" (if it is expected to pass). This provides a signal to `rspec` for how the code is expected to perform (see `spec/cpp_library_spec.rb`). + +When writing your own tests you should not follow this ("bad" and "good") naming convention. You should write all your tests expecting them to pass (relying on this `DoSomething` test to ensure that failures are actually noticed!). diff --git a/SampleProjects/README.md b/SampleProjects/README.md index 8e4e3405..6b7ed569 100644 --- a/SampleProjects/README.md +++ b/SampleProjects/README.md @@ -1,7 +1,7 @@ Arduino Sample Projects ======================= -This directory contains example projects that are meant to be built with this gem. +This directory contains projects that are meant to be built with and tested by this gem. Although this directory is named `SampleProjects`, it is by no means optional. These project test the testing framework itself, but also provide examples of how you might write your own tests (which should be placed in your system's Arduino `libraries` directory). -* "DoSomething" is a bare implementation of a library with a test. Test files prefixed with "bad-" are expected to fail; this is checked as part of the testing on arduino_ci itself. -* "TestSomething" contains a minimial library, but tests for all the mock features of arduino_ci. +* "DoSomething" is a simple test of the testing framework (arduino_ci) itself to verfy that passes and failures are properly identified and reported. +* "TestSomething" contains tests for all the mock features of arduino_ci. From 2ad01315aeaa9087a8a030c1a43e7ba501edd05b Mon Sep 17 00:00:00 2001 From: Elizabeth Ventura Date: Sun, 11 Oct 2020 15:07:59 -0700 Subject: [PATCH 2/4] adding tests for EEPROM --- SampleProjects/TestSomething/test/eeprom.cpp | 49 ++++++++++++++++++++ cpp/arduino/Godmode.h | 8 ++++ 2 files changed, 57 insertions(+) diff --git a/SampleProjects/TestSomething/test/eeprom.cpp b/SampleProjects/TestSomething/test/eeprom.cpp index 440d6f1c..f2f9faed 100644 --- a/SampleProjects/TestSomething/test/eeprom.cpp +++ b/SampleProjects/TestSomething/test/eeprom.cpp @@ -10,6 +10,55 @@ unittest(length) assertEqual(EEPROM_SIZE, EEPROM.length()); } +unittest(firstRead) +{ + uint8_t a = EEPROM.read(0); + assertEqual(255, a); +} + +unittest(writeRead) +{ + EEPROM.write(0, 24); + uint8_t a = EEPROM.read(0); + assertEqual(24, a); + + EEPROM.write(0, 128); + uint8_t b = EEPROM.read(0); + assertEqual(128, b); + +// this will fail since it is out of bound (0 - 255) + EEPROM.write(0, 256); + uint8_t c = EEPROM.read(0); + assertEqual(256, c); + +} + +unittest(updateWrite) +{ + EEPROM.write(1, 14); + EEPROM.update(1, 22); + uint8_t a = EEPROM.read(1); + assertEqual(22, a); +} + +unittest(putGet) +{ + const float f1 = 0.025f; + float f2 = 0.0f; + EEPROM.put(5, f1); + assertEqual(0.0f, f2); + EEPROM.get(5, f2); + assertEqual(0.025f, f2); +} + +unittest(array) +{ + int val = 10; + EEPROM[2] = val; + uint8_t a = EEPROM.read(2); + assertEqual(10, a); +} + #endif unittest_main() diff --git a/cpp/arduino/Godmode.h b/cpp/arduino/Godmode.h index 12fa1b51..0cc16514 100644 --- a/cpp/arduino/Godmode.h +++ b/cpp/arduino/Godmode.h @@ -3,6 +3,7 @@ #include #include "WString.h" #include "PinHistory.h" +#include "EEPROM.h" // random void randomSeed(unsigned long seed); @@ -87,12 +88,19 @@ class GodmodeState { spi.readDelayMicros = 0; } + void resetEEPROM() { + for(int i = 0; i < EEPROM.length(); ++i){ + EEPROM.update(i, 255); + } + } + void reset() { resetClock(); resetPins(); resetInterrupts(); resetPorts(); resetSPI(); + resetEEPROM(); seed = 1; } From 5c26abdae24dad53c8552f415546bb7231d183b0 Mon Sep 17 00:00:00 2001 From: Elizabeth Ventura Date: Sun, 11 Oct 2020 18:34:28 -0700 Subject: [PATCH 3/4] test high memory and array read. --- SampleProjects/TestSomething/test/eeprom.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/SampleProjects/TestSomething/test/eeprom.cpp b/SampleProjects/TestSomething/test/eeprom.cpp index f2f9faed..7abed1cc 100644 --- a/SampleProjects/TestSomething/test/eeprom.cpp +++ b/SampleProjects/TestSomething/test/eeprom.cpp @@ -23,14 +23,22 @@ unittest(writeRead) assertEqual(24, a); EEPROM.write(0, 128); - uint8_t b = EEPROM.read(0); - assertEqual(128, b); + a = EEPROM.read(0); + assertEqual(128, a); -// this will fail since it is out of bound (0 - 255) EEPROM.write(0, 256); - uint8_t c = EEPROM.read(0); - assertEqual(256, c); + a = EEPROM.read(0); + assertEqual(0, a); + int addr = EEPROM_SIZE / 2; + EEPROM.write(addr, 63); + a = EEPROM.read(addr); + assertEqual(63, a); + + addr = EEPROM_SIZE - 1; + EEPROM.write(addr, 188); + a = EEPROM.read(addr); + assertEqual(188, a); } unittest(updateWrite) @@ -55,7 +63,7 @@ unittest(array) { int val = 10; EEPROM[2] = val; - uint8_t a = EEPROM.read(2); + uint8_t a = EEPROM[2]; assertEqual(10, a); } From f923a7fbbdbce3d67c7dc9d13fd77299cd603f0e Mon Sep 17 00:00:00 2001 From: Elizabeth Ventura Date: Mon, 12 Oct 2020 09:22:07 -0700 Subject: [PATCH 4/4] add setup to reset memory before each test --- SampleProjects/TestSomething/test/eeprom.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/SampleProjects/TestSomething/test/eeprom.cpp b/SampleProjects/TestSomething/test/eeprom.cpp index 7abed1cc..5e2e7a6e 100644 --- a/SampleProjects/TestSomething/test/eeprom.cpp +++ b/SampleProjects/TestSomething/test/eeprom.cpp @@ -5,6 +5,12 @@ #if defined(EEPROM_SIZE) || (defined(E2END) && E2END) #include +GodmodeState* state = GODMODE(); +unittest_setup() +{ + state->reset(); +} + unittest(length) { assertEqual(EEPROM_SIZE, EEPROM.length());