Skip to content

Commit

Permalink
Merge branch 'master' into tdd
Browse files Browse the repository at this point in the history
  • Loading branch information
ianfixes authored Nov 10, 2020
2 parents 03e4168 + 972ad28 commit a5dc7b6
Show file tree
Hide file tree
Showing 12 changed files with 582 additions and 427 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ script:
- bundle exec rspec --backtrace
- cd SampleProjects/TestSomething
- bundle install
- bundle exec arduino_ci_remote.rb
- bundle exec arduino_ci.rb
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
### Added
- Add `__AVR__` to defines when compiling
- Add support for `diditalPinToPort()`, `digitalPinToBitMask()`, and `portOutputRegister()`
- Support for mock EEPROM (but only if board supports it)

### Changed
- Move repository from https://github.com/ianfixes/arduino_ci to https://github.com/Arduino-CI/arduino_ci
- Revise math macros to avoid name clashes

### Deprecated
- Deprecated `arduino_ci_remote.rb` in favor of `arduino_ci.rb`

### Removed

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ $ bundle install --path vendor/bundle # adds packages to local library
With that installed, just the following shell command each time you want the tests to execute:

```
$ bundle exec arduino_ci_remote.rb
$ bundle exec arduino_ci.rb
```

`arduino_ci_remote.rb` is the main entry point for this library. This command will iterate over all the library's `examples/` and attempt to compile them. If you set up unit tests, it will run those as well.
`arduino_ci.rb` is the main entry point for this library. This command will iterate over all the library's `examples/` and attempt to compile them. If you set up unit tests, it will run those as well.


### Reference

For more information on the usage of `arduino_ci_remote.rb`, see [REFERENCE.md](REFERENCE.md). It contains information such as:
For more information on the usage of `arduino_ci.rb`, see [REFERENCE.md](REFERENCE.md). It contains information such as:

* How to configure build options (platforms to test, Arduino library dependencies to install) with an `.arduino-ci.yml` file
* Where to put unit test files
Expand All @@ -121,7 +121,7 @@ The following prerequisites must be fulfilled:

### Testing with remote CI

> **Note:** `arduino_ci_remote.rb` expects to be run from the root directory of your Arduino project library.
> **Note:** `arduino_ci.rb` expects to be run from the root directory of your Arduino project library.

#### Travis CI
Expand All @@ -135,7 +135,7 @@ sudo: false
language: ruby
script:
- bundle install
- bundle exec arduino_ci_remote.rb
- bundle exec arduino_ci.rb
```
Expand All @@ -149,7 +149,7 @@ Next, you'll need this in `appveyor.yml` in your repo.
build: off
test_script:
- bundle install
- bundle exec arduino_ci_remote.rb
- bundle exec arduino_ci.rb
```

## Known Problems
Expand Down
10 changes: 5 additions & 5 deletions REFERENCE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Build / Test Behavior of Arduino CI

All tests are run via the same command: `bundle exec arduino_ci_remote.rb`.
All tests are run via the same command: `bundle exec arduino_ci.rb`.

This script is responsible for detecting and runing all unit tests, on every combination of Arduino platform and C++ compiler. This is followed by attempting to detect and build every example on every "default" Arduino platform.

Expand All @@ -11,7 +11,7 @@ These defaults are specified in [misc/default.yml](misc/default.yml). You are f

## Directly Overriding Build Behavior (short term use)

When testing locally, it's often advantageous to limit the number of tests that are performed to only those tests that relate to the work you're doing; you'll get a faster turnaround time in seeing the results. For a full listing, see `bundle exec arduino_ci_remote.rb --help`.
When testing locally, it's often advantageous to limit the number of tests that are performed to only those tests that relate to the work you're doing; you'll get a faster turnaround time in seeing the results. For a full listing, see `bundle exec arduino_ci.rb --help`.


### `--skip-unittests` option
Expand Down Expand Up @@ -233,14 +233,14 @@ For most build environments, the only script that need be executed by the CI sys
```shell
# simplest build script
bundle install
bundle exec arduino_ci_remote.rb
bundle exec arduino_ci.rb
```

However, more flexible usage is available:

### Custom Versions of external Arduino Libraries

Sometimes you need a fork of an Arduino library instead of the version that will be installed via their GUI. `arduino_ci_remote.rb` won't overwrite existing downloaded libraries with fresh downloads, but it won't fetch the custom versions for you either.
Sometimes you need a fork of an Arduino library instead of the version that will be installed via their GUI. `arduino_ci.rb` won't overwrite existing downloaded libraries with fresh downloads, but it won't fetch the custom versions for you either.

If this is the behavior you need, `ensure_arduino_installation.rb` is for you. It ensures that an Arduino binary is available on the system.

Expand All @@ -261,7 +261,7 @@ git clone https://repository.com/custom_library_repo.git
mv custom_library_repo $(bundle exec arduino_library_location.rb)
# now run CI
bundle exec arduino_ci_remote.rb
bundle exec arduino_ci.rb
```

Note the use of subshell to execute `bundle exec arduino_library_location.rb`. This command simply returns the directory in which Arduino Libraries are (or should be) installed.
Expand Down
2 changes: 1 addition & 1 deletion SampleProjects/DoSomething/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ sudo: false
language: ruby
script:
- bundle install
- bundle exec arduino_ci_remote.rb
- bundle exec arduino_ci.rb
2 changes: 1 addition & 1 deletion SampleProjects/DoSomething/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ At a minimum, you will need the following lines in your file:
language: ruby
script:
- bundle install
- bundle exec arduino_ci_remote.rb
- bundle exec arduino_ci.rb
```
This will install the necessary ruby gem, and run it. There are no command line arguments as of this writing, because all configuration is provided by...
Expand Down
26 changes: 26 additions & 0 deletions SampleProjects/TestSomething/test/outputRegister.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <ArduinoUnitTests.h>
#include <Arduino.h>

// added to fix https://github.com/Arduino-CI/arduino_ci/issues/193
// https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h#L337

#if defined(__AVR__)
unittest(portOutputRegister)
{
uint8_t ss_pin = 12;
uint8_t ss_port = digitalPinToPort(ss_pin);
assertEqual(12, ss_port);
uint8_t *ss_pin_reg = portOutputRegister(ss_port);
assertEqual(GODMODE()->pMmapPort(ss_port), ss_pin_reg);
uint8_t ss_pin_mask = digitalPinToBitMask(ss_pin);
assertEqual(1, ss_pin_mask);

assertEqual((int) 1, (int) *ss_pin_reg); // verify initial value
*(ss_pin_reg) &= ~ss_pin_mask; // set SS
assertEqual((int) 0, (int) *ss_pin_reg); // verify value
*(ss_pin_reg) |= ss_pin_mask; // clear SS
assertEqual((int) 1, (int) *ss_pin_reg); // verify value
}
#endif

unittest_main()
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ test_script:
- bundle exec rspec --backtrace
- cd SampleProjects\TestSomething
- bundle install
- bundle exec arduino_ci_remote.rb
- bundle exec arduino_ci.rb
134 changes: 117 additions & 17 deletions cpp/arduino/AvrMath.h
Original file line number Diff line number Diff line change
@@ -1,26 +1,126 @@
#pragma once
#include "ArduinoDefines.h"
#include <math.h>

#define constrain(x,l,h) ((x)<(l)?(l):((x)>(h)?(h):(x)))
#define map(x,inMin,inMax,outMin,outMax) (((x)-(inMin))*((outMax)-(outMin))/((inMax)-(inMin))+outMin)
#ifdef __cplusplus

#define sq(x) ((x)*(x))
template <class Amt, class Low, class High>
auto constrain(const Amt &amt, const Low &low, const High &high)
-> decltype(amt < low ? low : (amt > high ? high : amt)) {
return (amt < low ? low : (amt > high ? high : amt));
}

#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
template <class X, class InMin, class InMax, class OutMin, class OutMax>
auto map(const X &x, const InMin &inMin, const InMax &inMax,
const OutMin &outMin, const OutMax &outMax)
-> decltype((x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin) {
return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
}

#ifdef abs
#undef abs
#endif
#define abs(x) ((x)>0?(x):-(x))
template <class T> auto radians(const T &deg) -> decltype(deg * DEG_TO_RAD) {
return deg * DEG_TO_RAD;
}

#ifdef max
#undef max
#endif
#define max(a,b) ((a)>(b)?(a):(b))
template <class T> auto degrees(const T &rad) -> decltype(rad * RAD_TO_DEG) {
return rad * RAD_TO_DEG;
}

#ifdef min
#undef min
#endif
#define min(a,b) ((a)<(b)?(a):(b))
template <class T> auto sq(const T &x) -> decltype(x * x) { return x * x; }

template <class T> auto abs(const T &x) -> decltype(x > 0 ? x : -x) {
return x > 0 ? x : -x;
}

template <class T, class L>
auto min(const T &a, const L &b) -> decltype((b < a) ? b : a) {
return (b < a) ? b : a;
}

template <class T, class L>
auto max(const T &a, const L &b) -> decltype((b < a) ? b : a) {
return (a < b) ? b : a;
}

#else // __cplusplus

#ifdef constrain
#undef constrain
#endif
#define constrain(amt, low, high) \
({ \
__typeof__(amt) _amt = (amt); \
__typeof__(low) _low = (low); \
__typeof__(high) _high = (high); \
(amt < low ? low : (amt > high ? high : amt)); \
})

#ifdef map
#undef map
#endif
#define map(x, inMin, inMax, outMin, outMax) \
({ \
__typeof__(x) _x = (x); \
__typeof__(inMin) _inMin = (inMin); \
__typeof__(inMax) _inMax = (inMax); \
__typeof__(outMin) _outMin = (outMin); \
__typeof__(outMax) _outMax = (outMax); \
(_x - _inMin) * (_outMax - _outMin) / (_inMax - _inMin) + _outMin; \
})

#ifdef radians
#undef radians
#endif
#define radians(deg) \
({ \
__typeof__(deg) _deg = (deg); \
_deg *DEG_TO_RAD; \
})

#ifdef degrees
#undef degrees
#endif
#define degrees(rad) \
({ \
__typeof__(rad) _rad = (rad); \
_rad *RAD_TO_DEG; \
})

#ifdef sq
#undef sq
#endif
#define sq(x) \
({ \
__typeof__(x) _x = (x); \
_x *_x; \
})

#ifdef abs
#undef abs
#endif
#define abs(x) \
({ \
__typeof__(x) _x = (x); \
_x > 0 ? _x : -_x; \
})

#ifdef min
#undef min
#endif
#define min(a, b) \
({ \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a < _b ? _a : _b; \
})

#ifdef max
#undef max
#endif
#define max(a, b) \
({ \
__typeof__(a) _a = (a); \
__typeof__(b) _b = (b); \
_a > _b ? _a : _b; \
})

#endif
27 changes: 25 additions & 2 deletions cpp/arduino/Godmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class GodmodeState {
uint8_t mode;
};

uint8_t mmapPorts[MOCK_PINS_COUNT];

static GodmodeState* instance;

public:
Expand Down Expand Up @@ -99,9 +101,15 @@ class GodmodeState {
spi.readDelayMicros = 0;
}

void resetMmapPorts() {
for (int i = 0; i < MOCK_PINS_COUNT; ++i) {
mmapPorts[i] = 1;
}
}

void resetEEPROM() {
for(int i = 0; i < EEPROM_SIZE; ++i){
eeprom[i] = 255;
for(int i = 0; i < EEPROM_SIZE; ++i) {
eeprom[i] = 255;
}
}

Expand All @@ -111,6 +119,7 @@ class GodmodeState {
resetInterrupts();
resetPorts();
resetSPI();
resetMmapPorts();
resetEEPROM();
seed = 1;
}
Expand All @@ -131,6 +140,9 @@ class GodmodeState {
return instance->micros;
}

uint8_t* pMmapPort(uint8_t port) { return &mmapPorts[port]; }
uint8_t mmapPortValue(uint8_t port) { return mmapPorts[port]; }

// C++ 11, declare as public for better compiler error messages
GodmodeState(GodmodeState const&) = delete;
void operator=(GodmodeState const&) = delete;
Expand Down Expand Up @@ -158,5 +170,16 @@ void detachInterrupt(uint8_t interrupt);
inline void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0) {}
inline void noTone(uint8_t _pin) {}

// These definitions allow the following to compile (see issue #193):
// https://github.com/arduino-libraries/Ethernet/blob/master/src/utility/w5100.h:341
// we allow one byte per port which "wastes" 224 bytes, but makes the code easier
#if defined(__AVR__)
#define digitalPinToBitMask(pin) (1)
#define digitalPinToPort(pin) (pin)
#define portOutputRegister(port) (GODMODE()->pMmapPort(port))
#else
// we don't (yet) support other boards
#endif


GodmodeState* GODMODE();
Loading

0 comments on commit a5dc7b6

Please sign in to comment.