Skip to content

Suggested fixes #183

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 33 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a50d8a1
Increase clarity of command line tool
ianfixes Oct 16, 2020
4f6eb2a
Use proper 1.5 library format
ianfixes Oct 19, 2020
9b4f31f
Obey 1.0 / 1.5 library specification when finding C++ library source
ianfixes Oct 19, 2020
09b8cc2
Appease rubocop
ianfixes Oct 19, 2020
8a14ad1
avoid error when testing for membership in a nonexistent directory
ianfixes Oct 19, 2020
082ac95
Add library.properties parsing
ianfixes Oct 27, 2020
da1cef6
Add recursive library dependency compilation
ianfixes Oct 27, 2020
c2302ec
Fix unit tests for source directory exclusion
ianfixes Oct 27, 2020
34aa9f9
reorder changelog sections
ianfixes Oct 27, 2020
14a551b
Fix _SFR_IO8 macro definition -- use volatile keyword to prevent opti…
ianfixes Oct 27, 2020
2af1a4c
Add dummy test files to sample projects to ensure they aren't include…
ianfixes Oct 27, 2020
be95d0c
Print unit test stack traces if encountered
ianfixes Oct 27, 2020
42bc4fe
Show current platform while running unittests
matthijskooijman Aug 25, 2020
7d7d810
Make SPI.h work on non-AVR unittests
matthijskooijman Aug 25, 2020
2297661
Do not include SPI/Wire from Arduino.h
matthijskooijman Aug 26, 2020
97a499c
Complete and fix defines for various boards
matthijskooijman Aug 25, 2020
6bfa32c
Only include avr/io.h if __AVR__ is defined
matthijskooijman Aug 26, 2020
c4c753c
Allow specifying NUM_SERIAL_PORTS explicitly
matthijskooijman Aug 26, 2020
9eab3cd
Specify NUM_SERIAL_PORTS for non-AVR targets
matthijskooijman Aug 26, 2020
77d8737
Fix pgm_read_ptr_near/far
matthijskooijman Aug 26, 2020
614ffec
Replace _P macros with inline functions
matthijskooijman Aug 26, 2020
1df3995
Mock stdio.h progmem functions
matthijskooijman Aug 26, 2020
a83cb63
Remove some functions from pgmspace.h that break on cygwin
matthijskooijman Nov 6, 2020
cb67e90
Annotate matthijskooijman changes
ianfixes Nov 11, 2020
583f4a1
Remove hard-coded __AVR__ in favor of platform configured data
ianfixes Nov 11, 2020
7978af6
Support for EEPROM (squashed)
Nov 11, 2020
4199092
Fix EEPROM compilation
ianfixes Nov 11, 2020
cdecc40
Add files needed to compile Ethernet library (squashed)
Nov 11, 2020
a8eff6a
Fix custom ethernet library location
ianfixes Nov 13, 2020
7804730
Implement __ARDUNO_CI_SFR_MOCK (squashed)
Nov 11, 2020
cbccf6a
Don't test SFR on non-AVR
ianfixes Nov 11, 2020
ebfa6a7
Additional __ARDUINO_CI_SFR_MOCK commits (squashed)
Nov 13, 2020
b4ee115
Remove possible unnecessary preprocessor guard
ianfixes Nov 13, 2020
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
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Layout/ExtraSpacing:
Layout/EndOfLine:
EnforcedStyle: lf

Layout/EndAlignment:
EnforcedStyleAlignWith: start_of_line

Layout/CaseIndentation:
EnforcedStyle: end

Metrics/LineLength:
Description: Limit lines to 80 characters.
StyleGuide: https://github.com/bbatsov/ruby-style-guide#80-character-limits
Expand Down
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ script:
- cd SampleProjects/TestSomething
- bundle install
- bundle exec arduino_ci.rb
- cd ../NetworkLib
- cd scripts
- bash -x ./install.sh
- cd ..
- bundle install
- bundle exec arduino_ci.rb
23 changes: 19 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,36 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Add `__AVR__` to defines when compiling
- `arduino_ci_remote.rb` CLI switch `--skip-examples-compilation`
- Add support for `diditalPinToPort()`, `digitalPinToBitMask()`, and `portOutputRegister()`
- `CppLibrary.header_files` to find header files
- `LibraryProperties` to read metadata from Arduino libraries
- `CppLibrary.library_properties_path`, `CppLibrary.library_properties?`, `CppLibrary.library_properties` to expose library properties of a Cpp library
- `CppLibrary.arduino_library_dependencies` to list the dependent libraries specified by the library.properties file
- `CppLibrary.print_stack_dump` prints stack trace dumps (on Windows specifically) to the console if encountered
- Definitions for Arduino zero
- Support for mock EEPROM (but only if board supports it)
- Add stubs for `Client.h`, `IPAddress.h`, `Printable.h`, `Server.h`, and `Udp.h`

### 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
- `CppLibrary` functions returning C++ header or code files now respect the 1.0/1.5 library specification
- Mocks of built-in macros made more accurate
- NUM_SERIAL_PORTS can now be set explicitly
- Improve SPI header strategy

### Fixed
- Don't define `ostream& operator<<(nullptr_t)` if already defined by Apple
- `CppLibrary.in_tests_dir?` no longer produces an error if there is no tests directory
- The definition of the `_SFR_IO8` macro no longer produces errors about rvalues

### Deprecated
- `arduino_ci_remote.rb` CLI switch `--skip-compilation`
- Deprecated `arduino_ci_remote.rb` in favor of `arduino_ci.rb`

### Removed

### Fixed
- Don't define `ostream& operator<<(nullptr_t)` if already defined by Apple

### Security


Expand Down
50 changes: 46 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ When testing locally, it's often advantageous to limit the number of tests that
This completely skips the unit testing portion of the CI script.


### `--skip-compilation` option
### `--skip-compilation` option (deprecated)

This completely skips the compilation tests (of library examples) portion of the CI script.
This completely skips the compilation tests (of library examples) portion of the CI script. It does not skip the compilation of unit tests.


### `--skip-examples-compilation` option

This completely skips the compilation tests (of library examples) portion of the CI script. It does not skip the compilation of unit tests.


### `--testfile-select` option
Expand Down Expand Up @@ -90,8 +95,8 @@ platforms:
### Control How Examples Are Compiled
Put a file `.arduino-ci.yml` in each example directory where you require a different configuration than default.
The `compile:` section controls the platforms on which the compilation will be attempted, as well as any external libraries that must be installed and included.
Put a file `.arduino-ci.yml` in each example directory where you require a different configuration than default.
The `compile:` section controls the platforms on which the compilation will be attempted, as well as any external libraries that must be installed and included.

```yaml
compile:
Expand Down Expand Up @@ -581,3 +586,40 @@ unittest(spi) {
assertEqual("LMNOe", String(inBuf));
}
```

### EEPROM

`EEPROM` is a global with a simple API to read and write bytes to persistent memory (like a tiny hard disk) given an `int` location. Since the Arduino core already provides this as a global, and the core API is sufficient for basic testing (read/write), there is no direct tie to the `GODMODE` API. (If you need more, such as a log of intermediate values, enter a feature request.)

```C++
unittest(eeprom)
{
uint8_t a;
// size
assertEqual(EEPROM_SIZE, EEPROM.length());
// initial values
a = EEPROM.read(0);
assertEqual(255, a);
// write and read
EEPROM.write(0, 24);
a = EEPROM.read(0);
assertEqual(24, a);
// update
EEPROM.write(1, 14);
EEPROM.update(1, 22);
a = EEPROM.read(1);
assertEqual(22, a);
// put and get
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);
// array access
int val = 10;
EEPROM[2] = val;
a = EEPROM[2];
assertEqual(10, a);
}
```
1 change: 1 addition & 0 deletions SampleProjects/DependOnSomething/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
depends=OnePointOhDummy,OnePointFiveDummy
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions SampleProjects/DependOnSomething/test/null.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <ArduinoUnitTests.h>

unittest(nothing)
{
}

unittest_main()
3 changes: 3 additions & 0 deletions SampleProjects/ExcludeSomething/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
unittest:
exclude_dirs:
- src/excludeThis
3 changes: 3 additions & 0 deletions SampleProjects/ExcludeSomething/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ExcludeSomething

This example exists to test directory-exclusion code of ArduinoCI
10 changes: 10 additions & 0 deletions SampleProjects/ExcludeSomething/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=TestSomething
version=0.1.0
author=Ian Katz <[email protected]>
maintainer=Ian Katz <[email protected]>
sentence=Arduino CI unit test example
paragraph=A skeleton library demonstrating file exclusion
category=Other
url=https://github.com/Arduino-CI/arduino_ci/SampleProjects/ExcludeSomething
architectures=avr,esp8266
includes=do-something.h
4 changes: 4 additions & 0 deletions SampleProjects/ExcludeSomething/src/exclude-something.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "exclude-something.h"
int excludeSomething(void) {
return -1;
};
3 changes: 3 additions & 0 deletions SampleProjects/ExcludeSomething/src/exclude-something.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once
#include <Arduino.h>
int excludeSomething(void);
7 changes: 7 additions & 0 deletions SampleProjects/ExcludeSomething/test/null.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <ArduinoUnitTests.h>

unittest(nothing)
{
}

unittest_main()
11 changes: 11 additions & 0 deletions SampleProjects/NetworkLib/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
unittest:
platforms:
- mega2560
libraries:
- "Ethernet"

compile:
platforms:
- mega2560
libraries:
- "Ethernet"
1 change: 1 addition & 0 deletions SampleProjects/NetworkLib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.bundle
2 changes: 2 additions & 0 deletions SampleProjects/NetworkLib/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci', path: '../../'
3 changes: 3 additions & 0 deletions SampleProjects/NetworkLib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# NetworkLib

This is an example of a library that depends on Ethernet.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <NetworkLib.h>
// if it seems bare, that's because it's only meant to
// demonstrate compilation -- that references work
void setup() {}

void loop() {}
10 changes: 10 additions & 0 deletions SampleProjects/NetworkLib/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=Ethernet
version=0.1.0
author=James Foster <[email protected]>
maintainer=James Foster <[email protected]>
sentence=Sample Ethernet library to validate Client/Server mocks
paragraph=Sample Ethernet library to validate Client/Server mocks
category=Other
url=https://github.com/Arduino-CI/arduino_ci/SampleProjects/Ethernet
architectures=avr,esp8266
includes=NetworkLib.h
8 changes: 8 additions & 0 deletions SampleProjects/NetworkLib/scripts/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# if we don't have an Ethernet library already (say, in new install or for an automated test),
# then get the custom one we want to use for testing
cd $(bundle exec arduino_library_location.rb)
if [ ! -d ./Ethernet ] ; then
git clone https://github.com/Arduino-CI/Ethernet.git
fi
1 change: 1 addition & 0 deletions SampleProjects/NetworkLib/src/NetworkLib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Ethernet.h"
3 changes: 3 additions & 0 deletions SampleProjects/NetworkLib/src/NetworkLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#include <Arduino.h>
15 changes: 15 additions & 0 deletions SampleProjects/NetworkLib/test/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
cd SampleProjects/NetworkLib
bundle config --local path vendor/bundle
bundle install
bundle exec arduino_ci_remote.rb --skip-compilation
# bundle exec arduino_ci_remote.rb --skip-examples-compilation
*/

#include <Arduino.h>
#include <ArduinoUnitTests.h>
#include <Ethernet.h>

unittest(test) { assertEqual(EthernetNoHardware, Ethernet.hardwareStatus()); }

unittest_main()
Empty file.
Empty file.
1 change: 1 addition & 0 deletions SampleProjects/OnePointFiveDummy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This project resembles a "1.5 spec" library: it has `library.properties` and a `src/` directory that will be scanned recursively. `utility/`, if present, will be ignored.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions SampleProjects/OnePointFiveDummy/test/null.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <ArduinoUnitTests.h>

unittest(nothing)
{
}

unittest_main()
Empty file.
Empty file.
1 change: 1 addition & 0 deletions SampleProjects/OnePointFiveMalformed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This project lacks a `library.properties` and so should be treated as a "1.0 spec" library -- the base and `utility` directories will be scanned for code, non-recursively. `src/`, if present, will be ignored.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions SampleProjects/OnePointOhDummy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This project should resemble "1.0 spec" library -- the base and `utility` directories will be scanned for code, non-recursively. `src/`, if present, will be ignored.
Empty file.
Empty file.
Empty file.
Empty file.
7 changes: 7 additions & 0 deletions SampleProjects/OnePointOhDummy/test/null.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <ArduinoUnitTests.h>

unittest(nothing)
{
}

unittest_main()
Empty file.
Empty file.
14 changes: 11 additions & 3 deletions SampleProjects/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
Arduino Sample Projects
=======================

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).
This directory contains projects that are intended solely for testing the various features of this gem -- to test the testing framework itself. The RSpec tests refer specifically to these projects.

* "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.
Because of this, these projects include some intentional quirks that differ from what a well-formed an Arduino project for testing with `arduino_ci` might contain. See other projects in the "Arduino-CI" GitHub organization for practical examples.


* "TestSomething" contains a minimial library, but tests for all the C++ compilation feature-mocks 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. Because of this, it includes test files that are expected to fail -- they are prefixed with "bad-".
* "OnePointOhDummy" is a non-functional library meant to test file inclusion logic on libraries conforming to the "1.0" specification
* "OnePointFiveMalformed" is a non-functional library meant to test file inclusion logic on libraries that attempt to conform to the ["1.5" specfication](https://arduino.github.io/arduino-cli/latest/library-specification/) but fail to include a `src` directory
* "OnePointFiveDummy" is a non-functional library meant to test file inclusion logic on libraries conforming to the ["1.5" specfication](https://arduino.github.io/arduino-cli/latest/library-specification/)
* "DependOnSomething" is a non-functional library meant to test file inclusion logic with dependencies
* "ExcludeSomething" is a non-functional library meant to test directory exclusion logic
2 changes: 0 additions & 2 deletions SampleProjects/TestSomething/.arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
unittest:
exclude_dirs:
- excludeThis
platforms:
- uno
- due
Expand Down
87 changes: 87 additions & 0 deletions SampleProjects/TestSomething/test/clientServer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <Arduino.h>
#include <ArduinoUnitTests.h>
#include <Client.h>
#include <IPAddress.h>
#include <Printable.h>
#include <Server.h>
#include <Udp.h>

// Provide some rudamentary tests for these classes
// They get more thoroughly tested in SampleProjects/NetworkLib

unittest(Client) {
Client client;
assertEqual(0, client.available()); // subclass of Stream
assertEqual(0, client.availableForWrite()); // subclass of Print
String outData = "Hello, world!";
client.println(outData);
String inData = client.readString();
assertEqual(outData + "\r\n", inData);
}

unittest(IPAddress) {
IPAddress ipAddress0;
assertEqual(0, ipAddress0.asWord());
uint32_t one = 0x01020304;
IPAddress ipAddress1(one);
assertEqual(one, ipAddress1.asWord());
IPAddress ipAddress2(2, 3, 4, 5);
assertEqual(0x05040302, ipAddress2.asWord());
uint8_t bytes[] = {3, 4, 5, 6};
IPAddress ipAddress3(bytes);
assertEqual(0x06050403, ipAddress3.asWord());
uint8_t *pBytes = ipAddress1.raw_address();
assertEqual(*(pBytes + 0), 4);
assertEqual(*(pBytes + 1), 3);
assertEqual(*(pBytes + 2), 2);
assertEqual(*(pBytes + 3), 1);
IPAddress ipAddress1a(one);
assertTrue(ipAddress1 == ipAddress1a);
assertTrue(ipAddress1 != ipAddress2);
assertEqual(1, ipAddress1[3]);
ipAddress1[1] = 11;
assertEqual(11, ipAddress1[1]);
assertEqual(1, ipAddress0 + 1);
}

class TestPrintable : public Printable {
public:
virtual size_t printTo(Print &p) const {
p.print("TestPrintable");
return 13;
}
};

unittest(Printable) {
TestPrintable printable;
Client client;
client.print(printable);
assertEqual("TestPrintable", client.readString());
}

class TestServer : public Server {
public:
uint8_t data;
virtual size_t write(uint8_t value) {
data = value;
return 1;
};
};

unittest(Server) {
TestServer server;
server.write(67);
assertEqual(67, server.data);
}

unittest(Udp) {
UDP udp;
assertEqual(0, udp.available()); // subclass of Stream
assertEqual(0, udp.availableForWrite()); // subclass of Print
String outData = "Hello, world!";
udp.println(outData);
String inData = udp.readString();
assertEqual(outData + "\r\n", inData);
}

unittest_main()
Loading