-
Notifications
You must be signed in to change notification settings - Fork 24
Use arduino_ci for unit testing #9
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
Open
ianfixes
wants to merge
1
commit into
SMFSW:master
Choose a base branch
from
ianfixes:2019-01-03_arduino_ci
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| compile: | ||
| platforms: | ||
| - uno | ||
|
|
||
| unittest: | ||
| platforms: | ||
| - uno |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| source 'https://rubygems.org' | ||
| gem 'arduino_ci', '~> 0.1.14' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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:
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 removedbuild_platformsrather 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 theafter_successsection 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 🎉).
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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.