Skip to content

Add timestamps to pin histories (extensible to all settable items) #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
* `release-new-version.sh` script
* outputs for `PinHistory` can now report timestamps
* Fibonacci Clock for clock testing purposes (internal to this library)

### Changed
* Shortened `ArduinoQueue` push and pop operations
* `ci/Queue.h` is now `MockEventQueue.h`, with timing data
* `MockEventQueue::Node` now contains struct `MockEventQueue::Event`, which contains both the templated type `T` and a field for a timestamp.
* Construction of `MockEventQueue` now includes a constructor argument for the time-fetching function
* Construction of `PinHistory` now includes a constructor argument for the time-fetching function
* `PinHistory` can now return an array of timestamps for its events
* `GodmodeState` is now a singleton pattern, which is necessary to support the globality of Arduino functions
* `GodmodeState` now uses timestamped PinHistory for Analog and Digital

### Deprecated

### Removed

### Fixed
* `ArduinoQueue` no longer leaks memory

### Security

Expand Down
25 changes: 13 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ ARDUINO_CI_SKIP_RUBY_RSPEC_TESTS=1 bundle exec rspec
## Packaging the Gem

* Merge pull request with new features
* `git stash save` (at least before the gem build step, but easiest here).
* `git pull --rebase`
* Update the sections of `CHANGELOG.md` by running `bundle exec keepachangelog_manager.rb --increment-patch`
* Bump the version in lib/arduino_ci/version.rb and change it in README.md (since rubydoc.info doesn't always redirect to the latest version)
* `git add README.md CHANGELOG.md lib/arduino_ci/version.rb`
* `git commit -m "vVERSION bump"`
* `git tag -a vVERSION -m "Released version VERSION"`
* `gem build arduino_ci.gemspec`
* `git stash pop`
* `gem push arduino_ci-VERSION.gem`
* `git push upstream`
* `git push upstream --tags`
* Execute `release-new-version.sh` with the appropriate argument (e.g. `--increment-patch`), which does the following:
* `git stash save` (at least before the gem build step, but easiest here).
* `git pull --rebase`
* Update the sections of `CHANGELOG.md` by running `bundle exec keepachangelog_manager.rb --increment-patch`
* Bump the version in lib/arduino_ci/version.rb and change it in README.md (since rubydoc.info doesn't always redirect to the latest version)
* `git add README.md CHANGELOG.md lib/arduino_ci/version.rb`
* `git commit -m "vVERSION bump"`
* `git tag -a vVERSION -m "Released version VERSION"`
* `gem build arduino_ci.gemspec`
* `git stash pop`
* `gem push arduino_ci-VERSION.gem`
* `git push upstream`
* `git push upstream --tags`
* Visit http://www.rubydoc.info/gems/arduino_ci/VERSION to initiate the doc generation process
7 changes: 7 additions & 0 deletions SampleProjects/DoSomething/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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/`).

## 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.
17 changes: 17 additions & 0 deletions SampleProjects/TestSomething/test/fibonacciClock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

// fibbonacci clock
unsigned long lastFakeMicros = 1;
unsigned long fakeMicros = 0;

void resetFibClock() {
lastFakeMicros = 1;
fakeMicros = 0;
}

unsigned long fibMicros() {
unsigned long ret = lastFakeMicros + fakeMicros;
lastFakeMicros = fakeMicros;
fakeMicros = ret;
return ret;
}
25 changes: 25 additions & 0 deletions SampleProjects/TestSomething/test/fibonacciclock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <ArduinoUnitTests.h>
#include <Arduino.h>
#include "fibonacciClock.h"

unittest(my_fib_clock)
{
resetFibClock();
assertEqual(1, fibMicros());
assertEqual(1, fibMicros());
assertEqual(2, fibMicros());
assertEqual(3, fibMicros());
assertEqual(5, fibMicros());
assertEqual(8, fibMicros());
assertEqual(13, fibMicros());
assertEqual(21, fibMicros());

// and again
resetFibClock();
assertEqual(1, fibMicros());
assertEqual(1, fibMicros());
assertEqual(2, fibMicros());
}


unittest_main()
67 changes: 37 additions & 30 deletions SampleProjects/TestSomething/test/godmode.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#include <ArduinoUnitTests.h>
#include <Arduino.h>
#include "fibonacciClock.h"

GodmodeState* state = GODMODE();

unittest_setup()
{
unittest_setup() {
resetFibClock();
state->reset();
}

unittest(millis_micros_and_delay)
{
unittest(millis_micros_and_delay) {
assertEqual(0, millis());
assertEqual(0, micros());
delay(3);
Expand All @@ -20,8 +20,7 @@ unittest(millis_micros_and_delay)
assertEqual(14000, micros());
}

unittest(random)
{
unittest(random) {
randomSeed(1);
assertEqual(state->seed, 1);

Expand All @@ -37,8 +36,7 @@ unittest(random)
assertEqual(state->seed, 4294967282);
}

unittest(pins)
{
unittest(pins) {
pinMode(1, OUTPUT); // this is a no-op in unit tests. it's just here to prove compilation
digitalWrite(1, HIGH);
assertEqual(HIGH, state->digitalPin[1]);
Expand All @@ -64,8 +62,7 @@ unittest(pins)
assertEqual(56, analogRead(1));
}

unittest(pin_read_history)
{
unittest(pin_read_history) {
int future[6] = {33, 22, 55, 11, 44, 66};
state->analogPin[1].fromArray(future, 6);
for (int i = 0; i < 6; ++i)
Expand All @@ -88,20 +85,20 @@ unittest(pin_read_history)
}
}

unittest(pin_write_history)
{
unittest(digital_pin_write_history_with_timing) {
int numMoved;
bool expectedD[6] = {LOW, HIGH, LOW, LOW, HIGH, HIGH};
bool actualD[6];
unsigned long expectedT[6] = {0, 1, 1, 2, 3, 5};
unsigned long actualT[6];

// history for digital pin
digitalWrite(1, HIGH);
digitalWrite(1, LOW);
digitalWrite(1, LOW);
digitalWrite(1, HIGH);
digitalWrite(1, HIGH);
// history for digital pin. start from 1 since LOW is the initial value
for (int i = 1; i < 6; ++i) {
state->micros = fibMicros();
digitalWrite(1, expectedD[i]);
}

assertEqual(6, state->digitalPin[1].historySize());
bool expectedD[6] = {LOW, HIGH, LOW, LOW, HIGH, HIGH};
bool actualD[6];
numMoved = state->digitalPin[1].toArray(actualD, 6);
assertEqual(6, numMoved);
// assert non-destructive
Expand All @@ -113,6 +110,19 @@ unittest(pin_write_history)
assertEqual(expectedD[i], actualD[i]);
}

numMoved = state->digitalPin[1].toTimestampArray(actualT, 6);
assertEqual(6, numMoved);
for (int i = 0; i < numMoved; ++i)
{
assertEqual(expectedT[i], actualT[i]);
}
}

unittest(analog_pin_write_history) {
int numMoved;
int expectedA[6] = {0, 11, 22, 33, 44, 55};
int actualA[6];

// history for analog pin
analogWrite(1, 11);
analogWrite(1, 22);
Expand All @@ -121,8 +131,7 @@ unittest(pin_write_history)
analogWrite(1, 55);

assertEqual(6, state->analogPin[1].historySize());
int expectedA[6] = {0, 11, 22, 33, 44, 55};
int actualA[6];

numMoved = state->analogPin[1].toArray(actualA, 6);
assertEqual(6, numMoved);
// assert non-destructive
Expand All @@ -133,7 +142,9 @@ unittest(pin_write_history)
{
assertEqual(expectedA[i], actualA[i]);
}
}

unittest(ascii_pin_write_history) {
// digitial history as serial data, big-endian
bool binaryAscii[24] = {
0, 1, 0, 1, 1, 0, 0, 1,
Expand Down Expand Up @@ -207,8 +218,7 @@ unittest(spi) {
}
}

unittest(does_nothing_if_no_data)
{
unittest(does_nothing_if_no_data) {
int myPin = 3;
state->serialPort[0].dataIn = "";
state->serialPort[0].dataOut = "";
Expand All @@ -218,8 +228,7 @@ unittest(spi) {
assertEqual("", state->serialPort[0].dataOut);
}

unittest(keeps_pin_low_and_acks)
{
unittest(keeps_pin_low_and_acks) {
int myPin = 3;
state->serialPort[0].dataIn = "0";
state->serialPort[0].dataOut = "";
Expand All @@ -230,8 +239,7 @@ unittest(spi) {
assertEqual("Ack 3 0", state->serialPort[0].dataOut);
}

unittest(flips_pin_high_and_acks)
{
unittest(flips_pin_high_and_acks) {
int myPin = 3;
state->serialPort[0].dataIn = "1";
state->serialPort[0].dataOut = "";
Expand All @@ -242,8 +250,7 @@ unittest(spi) {
assertEqual("Ack 3 1", state->serialPort[0].dataOut);
}

unittest(two_flips)
{
unittest(two_flips) {
int myPin = 3;
state->serialPort[0].dataIn = "10junk";
state->serialPort[0].dataOut = "";
Expand Down
Loading