Skip to content
Open
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
7 changes: 7 additions & 0 deletions .arduino-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
compile:
platforms:
- uno

unittest:
platforms:
- uno
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@

#Doxygen
doxygen_sqlite3.db
html
html

# arduino_ci unit test files
*.bin
*.bin.dSYM

# arduino_ci ruby bundle lockfile
Gemfile.lock
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: c
sudo: false
language: ruby

addons:
apt:
Expand All @@ -17,13 +18,12 @@ env:
- GH_REPO_REF: github.com/SMFSW/Queue.git
- DOXYFILE: $TRAVIS_BUILD_DIR/Doxyfile.auto

before_install:
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/install.sh)

script:
- build_main_platforms
- bundle install
- bundle exec arduino_ci_remote.rb

# Generate and deploy documentation
after_success:
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/install.sh)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line might not be necessary. It will save some build time if not, but I can't tell for sure since the behavior seems to be different for PR tests vs merges into a branch (and I can only trigger the PR tests as a contributor).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, I'm not sure what you did with .travis.yml file.
I just checked, after_succes doesn't call install.sh script, but check (if needed to be implemented later, then doxygen deploy script).

About saving some build time, I recently moved on to travis-ci.com and it caches parts of the VM installation (like boards for example), so it doesn't take so long now to execute everyhting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies for lack of context here. An energetic discussion in arduino/Arduino#7567 this morning brought up #4, because it related to automated testing.

I noticed that in #4 you had said

The idea of having unit testing is seducing and as long as it remains free, I'm welcoming it, for this lib,

So I took some time this morning to attempt that seduction :) But since it's coming to you as noise from another thread, I apologize for the abrupt and unsolicited contribution.

To your question:

I'm not sure what you did with .travis.yml file

The 2 lines I added (bundle install && bundle exec arduino_ci_remote.rb) invoke the unit test & compilation library that I wrote -- replacing the need for the Adafruit script to do this. As such, I removed build_platforms rather than have the Adafruit script repeat it. However, my library doesn't do anything with documentation so I moved the installation of that library to the after_success section in case it was needed for the 2 commands that follow it.

We can close this PR as-is; it has illustrated what I was hoping to show: functional CI that includes unit tests an compilation tests on an Arduino library (and they all pass 🎉).

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not so familiar with such scripts and I'm pretty happy with my fork of bash travis-ci-arduino.
At the moment, I have more time to spend developping my libs and improving them, rather than changing these scripts that actually works fine for the purpose intended (check that compilation works on various platforms, and most of all, deploying the documentation).

About Queue library itself, the examples and LibTst are good ways to verify for me that the lib works fine.... And even with all unit testing, the lib will still fail if anyone doesn't follow the doxygen warnings (disabling interrupts when popping an entry from a queue filled in some interrupt routine).

Thanks for the tips anyways, I will look about all this when I have some time, and thanks for your interest in Queue library!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And thanks for the effort, I'll have a better look at is soon!
I'm happy to know that you managed to made this lib pass some unit testing without issues :)!

I saw about the discussion, scls19fr included me in it!

I'm sorry if my words seems (maybe) rude, this was not my intention at all, but I can agree with ladyada on her answers about unit testing, mostly when it comes to hardware related code.
Also, about unit testing, I tried it some at work too years ago, but nothing replaces a good debugger and proper means of manual testing when possible in my opinion. I mean, you generally can test some isolated functions with unit tests (which are abstracts), but for procedures, you can get serious headaches to manage testing them, if even it's possible ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No offense taken on my end 😄it was good practice for me and I appreciate your comments. Please don't hesitate to close this if it's not right for the project at this time.

- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/library_check.sh)
- source <(curl -SLs https://raw.githubusercontent.com/SMFSW/travis-ci-arduino/master/doxy_gen_and_deploy.sh)
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'arduino_ci', '~> 0.1.14'
71 changes: 71 additions & 0 deletions test/libtst.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include <ArduinoUnitTests.h>
#include "../src/cppQueue.h"

#define IMPLEMENTATION FIFO
#define OVERWRITE true

#define NB_PUSH 14
#define NB_PULL 11
#define Q_SIZE 10

typedef struct strRec {
uint16_t entry1;
uint16_t entry2;
} Rec;

unittest(LibTst)
{
Rec tab[6] = {
{ 0x1234, 0x3456 },
{ 0x5678, 0x7890 },
{ 0x90AB, 0xABCD },
{ 0xCDEF, 0xEFDC },
{ 0xDCBA, 0xBA09 },
{ 0x0987, 0x8765 }
};

Queue q(sizeof(Rec), Q_SIZE, IMPLEMENTATION, OVERWRITE); // Instantiate queue
assertEqual(40, q.sizeOf());
assertEqual(0, q.getCount());

int i;
for (i = 0 ; i < NB_PUSH ; i++)
{
Rec rec = tab[i % (sizeof(tab)/sizeof(Rec))];
q.push(&rec);
assertEqual(min(Q_SIZE, i + 1), q.getCount());
assertEqual(max(0, (Q_SIZE - 1) - i), q.getRemainingCount());
assertEqual((i + 1) >= Q_SIZE, q.isFull());
}

assertFalse(q.isEmpty());
assertEqual(10, q.getCount());

for (i = 0 ; i < NB_PULL+1 ; i++)
{
// account for the behavior of the test in the example,
// where at an odd spot we peek instead of pop.
bool canPop = i <= Q_SIZE; // note allowance for the peek -- 'i' can be 10
bool didPeek = i <= NB_PULL / 2; // matches logic of conditional
int offset = didPeek ? 4 : 3; // adjust offset in tab
int idx = (i + offset) % (sizeof(tab)/sizeof(Rec)); // index of tab
Rec rec = {0xffff,0xffff};
if (i != NB_PULL / 2)
{
assertEqual(canPop, q.pop(&rec));
}
else
{
assertTrue(q.peek(&rec));
}

assertEqual(canPop ? tab[idx].entry1 : 0xffff, rec.entry1);
assertEqual(canPop ? tab[idx].entry2 : 0xffff, rec.entry2);
}

assertTrue(q.isEmpty());
assertEqual(0, q.getCount());
}


unittest_main()